diff --git a/ns-3.29/src/csma/examples/csma-ping.cc b/ns-3.29/src/csma/examples/csma-ping.cc index aa2fb29..05954dc 100644 --- a/ns-3.29/src/csma/examples/csma-ping.cc +++ b/ns-3.29/src/csma/examples/csma-ping.cc @@ -121,6 +121,8 @@ main (int argc, char *argv[]) Packet::EnablePrinting (); + // Connect channel tracing + csma.ConnectChannelWireStateTrace (); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); diff --git a/ns-3.29/src/csma/helper/csma-helper.cc b/ns-3.29/src/csma/helper/csma-helper.cc index cb73da6..3df4b5c 100644 --- a/ns-3.29/src/csma/helper/csma-helper.cc +++ b/ns-3.29/src/csma/helper/csma-helper.cc @@ -112,6 +112,12 @@ CsmaHelper::EnablePcapInternal (std::string prefix, Ptr nd, bool prom } } +void +CsmaHelper::ChannelWireStateTrace ( std::string context, const WireState oldValue, const WireState newValue ) +{ + std::cout << Simulator::Now() << " Old value " << oldValue << " New " << newValue << std::endl; +} + void CsmaHelper::EnableAsciiInternal ( Ptr stream, @@ -300,6 +306,13 @@ CsmaHelper::AssignStreams (NetDeviceContainer c, int64_t stream) return (currentStream - stream); } +void +CsmaHelper::ConnectChannelWireStateTrace ( void ) +{ + Config::Connect ("/ChannelList/*/$ns3::CsmaChannel/ChannelWireState", + MakeCallback(&CsmaHelper::ChannelWireStateTrace, this)); +} + Ptr CsmaHelper::InstallPriv (Ptr node, Ptr channel) const { diff --git a/ns-3.29/src/csma/helper/csma-helper.h b/ns-3.29/src/csma/helper/csma-helper.h index 42c8b5c..4ba2d5a 100644 --- a/ns-3.29/src/csma/helper/csma-helper.h +++ b/ns-3.29/src/csma/helper/csma-helper.h @@ -205,6 +205,12 @@ public: */ int64_t AssignStreams (NetDeviceContainer c, int64_t stream); + /** + * Connect channel's WireState trace and direct it to given file. + * + */ + void ConnectChannelWireStateTrace ( void ); + private: /** @@ -218,6 +224,20 @@ private: */ Ptr InstallPriv (Ptr node, Ptr channel) const; + /** + * \brief Traces channel wirestate. + * + * CsmaChannel-specific implementation mechanism for hooking the trace and + * writing to the trace file + *. + * \param contect Tbd + * \param oldValue Old wirestate value + * \param newValue New wirestate value + */ + void ChannelWireStateTrace (std::string context, + const WireState oldValue, + const WireState newValue ); + /** * \brief Enable pcap output on the indicated net device. * diff --git a/ns-3.29/src/csma/model/csma-channel.cc b/ns-3.29/src/csma/model/csma-channel.cc index 70f0a1a..b94e6ca 100644 --- a/ns-3.29/src/csma/model/csma-channel.cc +++ b/ns-3.29/src/csma/model/csma-channel.cc @@ -46,6 +46,10 @@ CsmaChannel::GetTypeId (void) TimeValue (Seconds (0)), MakeTimeAccessor (&CsmaChannel::m_delay), MakeTimeChecker ()) + .AddTraceSource ("ChannelWireState", "Channel wirestate", + MakeTraceSourceAccessor (&CsmaChannel::m_state), + "ns3::CsmaChannel::CsmaChannelStateTracedValueCallback") + ; return tid; } diff --git a/ns-3.29/src/csma/model/csma-channel.h b/ns-3.29/src/csma/model/csma-channel.h index 0098ed9..dfb4681 100644 --- a/ns-3.29/src/csma/model/csma-channel.h +++ b/ns-3.29/src/csma/model/csma-channel.h @@ -25,6 +25,8 @@ #include "ns3/ptr.h" #include "ns3/nstime.h" #include "ns3/data-rate.h" +#include "ns3/traced-value.h" +#include "ns3/trace-source-accessor.h" namespace ns3 { @@ -69,13 +71,13 @@ public: /** * Current state of the channel - */ -enum WireState + */ +typedef enum { IDLE, /**< Channel is IDLE, no packet is being transmitted */ TRANSMITTING, /**< Channel is BUSY, a packet is being written by a net device */ PROPAGATING /**< Channel is BUSY, packet is propagating to all attached net devices */ -}; +} WireState; /** * \ingroup csma @@ -292,6 +294,17 @@ public: */ Time GetDelay (void); + /** + * \brief Common callback signature for channel Wirestate changes + * + * \param oldValue Old wirestate value + * \param newValue New wirestate value + */ + + typedef void (* CsmaChannelStateTracedValueCallback)(const WireState oldValue, + const WireState newValue); + + private: /** * Copy constructor is declared but not implemented. This disables the @@ -348,7 +361,7 @@ private: /** * Current state of the channel */ - WireState m_state; + TracedValue m_state; }; } // namespace ns3 diff --git a/ns-3.29/src/internet-apps/model/v4ping.cc b/ns-3.29/src/internet-apps/model/v4ping.cc index 4e428d4..871021d 100644 --- a/ns-3.29/src/internet-apps/model/v4ping.cc +++ b/ns-3.29/src/internet-apps/model/v4ping.cc @@ -49,8 +49,8 @@ V4Ping::GetTypeId (void) BooleanValue (false), MakeBooleanAccessor (&V4Ping::m_verbose), MakeBooleanChecker ()) - .AddAttribute ("Interval", "Wait interval seconds between sending each packet.", - TimeValue (Seconds (1)), + .AddAttribute ("Interval", "Wait interval milliseconds between sending each packet.", + TimeValue (MilliSeconds (1000)), MakeTimeAccessor (&V4Ping::m_interval), MakeTimeChecker ()) .AddAttribute ("Size", "The number of data bytes to be sent, real packet will be 8 (ICMP) + 20 (IP) bytes longer.", @@ -246,7 +246,7 @@ V4Ping::StartApplication (void) m_started = Simulator::Now (); if (m_verbose) { - std::cout << "PING " << m_remote << " 56(84) bytes of data.\n"; + std::cout << "PING " << m_remote << " " << m_size << "(" << (m_size + 28) << ") bytes of data.\n"; } m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory"));