24 #include "ns3/address.h" 
   25 #include "ns3/application-container.h" 
   26 #include "ns3/bridge-helper.h" 
   27 #include "ns3/callback.h" 
   28 #include "ns3/config.h" 
   29 #include "ns3/csma-helper.h" 
   30 #include "ns3/csma-star-helper.h" 
   31 #include "ns3/inet-socket-address.h" 
   32 #include "ns3/internet-stack-helper.h" 
   33 #include "ns3/ipv4-address-helper.h" 
   34 #include "ns3/ipv4-global-routing-helper.h" 
   35 #include "ns3/ipv4-static-routing-helper.h" 
   37 #include "ns3/data-rate.h" 
   38 #include "ns3/node-container.h" 
   39 #include "ns3/on-off-helper.h" 
   40 #include "ns3/packet.h" 
   41 #include "ns3/packet-sink-helper.h" 
   42 #include "ns3/packet-socket-helper.h" 
   43 #include "ns3/packet-socket-address.h" 
   44 #include "ns3/pointer.h" 
   45 #include "ns3/simple-channel.h" 
   46 #include "ns3/simulator.h" 
   47 #include "ns3/string.h" 
   49 #include "ns3/uinteger.h" 
   50 #include "ns3/v4ping-helper.h" 
   61   virtual void DoRun (
void);
 
   67 CsmaBridgeTestCase::CsmaBridgeTestCase ()
 
   68   : 
TestCase (
"Bridge example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0)
 
   72 CsmaBridgeTestCase::~CsmaBridgeTestCase ()
 
  110   for (
int i = 0; i < 4; i++)
 
  113       terminalDevices.
Add (link.
Get (0));
 
  114       switchDevices.
Add (link.
Get (1));
 
  120   bridge.
Install (switchNode, switchDevices);
 
  126   ipv4.
SetBase (
"10.1.1.0", 
"255.255.255.0");
 
  127   ipv4.
Assign (terminalDevices);
 
  149   Config::ConnectWithoutContext (
"/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", 
MakeCallback (&CsmaBridgeTestCase::SinkRx, 
this));
 
  152   Simulator::Destroy ();
 
  155   NS_TEST_ASSERT_MSG_EQ (m_count, 10, 
"Bridge should have passed 10 packets");
 
  165   virtual void DoRun (
void);
 
  169   uint32_t m_countNode1;
 
  170   uint32_t m_countNode2;
 
  175 CsmaBroadcastTestCase::CsmaBroadcastTestCase ()
 
  176   : 
TestCase (
"Broadcast example for Carrier Sense Multiple Access (CSMA) networks"), m_countNode1 (0), m_countNode2 (0), m_drops (0)
 
  180 CsmaBroadcastTestCase::~CsmaBroadcastTestCase ()
 
  234   ipv4.
SetBase (
"10.1.0.0", 
"255.255.255.0");
 
  236   ipv4.
SetBase (
"192.168.1.0", 
"255.255.255.0");
 
  267   Config::ConnectWithoutContext (
"/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", 
MakeCallback (&CsmaBroadcastTestCase::SinkRxNode1, 
this));
 
  268   Config::ConnectWithoutContext (
"/NodeList/2/ApplicationList/0/$ns3::PacketSink/Rx", 
MakeCallback (&CsmaBroadcastTestCase::SinkRxNode2, 
this));
 
  271   Simulator::Destroy ();
 
  274   NS_TEST_ASSERT_MSG_EQ (m_countNode1, 10, 
"Node 1 should have received 10 packets");
 
  275   NS_TEST_ASSERT_MSG_EQ (m_countNode2, 10, 
"Node 2 should have received 10 packets");
 
  285   virtual void DoRun (
void);
 
  293 CsmaMulticastTestCase::CsmaMulticastTestCase ()
 
  294   : 
TestCase (
"Multicast example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
 
  298 CsmaMulticastTestCase::~CsmaMulticastTestCase ()
 
  336   Config::SetDefault (
"ns3::CsmaNetDevice::EncapsulationMode", 
StringValue (
"Dix"));
 
  356   ipv4Addr.
SetBase (
"10.1.1.0", 
"255.255.255.0");
 
  358   ipv4Addr.
SetBase (
"10.1.2.0", 
"255.255.255.0");
 
  383   outputDevices.
Add (nd1.
Get (0));  
 
  386                                multicastGroup, inputIf, outputDevices);
 
  398   uint16_t multicastPort = 9;   
 
  426   Config::ConnectWithoutContext (
"/NodeList/4/ApplicationList/0/$ns3::PacketSink/Rx", 
MakeCallback (&CsmaMulticastTestCase::SinkRx, 
this));
 
  432   Simulator::Destroy ();
 
  435   NS_TEST_ASSERT_MSG_EQ (m_count, 10, 
"Node 4 should have received 10 packets");
 
  445   virtual void DoRun (
void);
 
  449   uint32_t m_countNode0;
 
  450   uint32_t m_countNode1;
 
  455 CsmaOneSubnetTestCase::CsmaOneSubnetTestCase ()
 
  456   : 
TestCase (
"One subnet example for Carrier Sense Multiple Access (CSMA) networks"), m_countNode0 (0), m_countNode1 (0), m_drops (0)
 
  460 CsmaOneSubnetTestCase::~CsmaOneSubnetTestCase ()
 
  513   ipv4.
SetBase (
"10.1.1.0", 
"255.255.255.0");
 
  542   onoff.SetAttribute (
"Remote", 
 
  544   app = onoff.Install (nodes.
Get (3));
 
  552   Config::ConnectWithoutContext (
"/NodeList/0/ApplicationList/1/$ns3::PacketSink/Rx", 
MakeCallback (&CsmaOneSubnetTestCase::SinkRxNode0, 
this));
 
  553   Config::ConnectWithoutContext (
"/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", 
MakeCallback (&CsmaOneSubnetTestCase::SinkRxNode1, 
this));
 
  559   Simulator::Destroy ();
 
  562   NS_TEST_ASSERT_MSG_EQ (m_countNode0, 10, 
"Node 0 should have received 10 packets");
 
  563   NS_TEST_ASSERT_MSG_EQ (m_countNode1, 10, 
"Node 1 should have received 10 packets");
 
  573   virtual void DoRun (
void);
 
  581 CsmaPacketSocketTestCase::CsmaPacketSocketTestCase ()
 
  582   : 
TestCase (
"Packet socket example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
 
  586 CsmaPacketSocketTestCase::~CsmaPacketSocketTestCase ()
 
  638   socket.SetSingleDevice (devs.
Get (0)->GetIfIndex ());
 
  639   socket.SetPhysicalAddress (devs.
Get (1)->GetAddress ());
 
  640   socket.SetProtocol (2);
 
  647   socket.SetSingleDevice (devs.
Get (3)->GetIfIndex ());
 
  648   socket.SetPhysicalAddress (devs.
Get (0)->GetAddress ());
 
  649   socket.SetProtocol (3);
 
  662   Config::Connect (
"/NodeList/0/ApplicationList/*/$ns3::PacketSink/Rx",
 
  663                    MakeCallback (&CsmaPacketSocketTestCase::SinkRx, 
this));
 
  666   Simulator::Destroy ();
 
  669   NS_TEST_ASSERT_MSG_EQ (m_count, 10, 
"Node 0 should have received 10 packets");
 
  679   virtual void DoRun (
void);
 
  681   void PingRtt (std::string context, 
Time rtt);
 
  683   uint32_t m_countSinkRx;
 
  684   uint32_t m_countPingRtt;
 
  689 CsmaPingTestCase::CsmaPingTestCase ()
 
  690   : 
TestCase (
"Ping example for Carrier Sense Multiple Access (CSMA) networks"), m_countSinkRx (0), m_countPingRtt (0), m_drops (0)
 
  694 CsmaPingTestCase::~CsmaPingTestCase ()
 
  705 CsmaPingTestCase::PingRtt (std::string context, 
Time rtt)
 
  745   ip.
SetBase (
"192.168.1.0", 
"255.255.255.0");
 
  752   Config::SetDefault (
"ns3::Ipv4RawSocketImpl::Protocol", 
StringValue (
"2"));
 
  755   onoff.SetConstantRate (
DataRate (5000));
 
  769   pingers.Add (c.
Get (1));
 
  770   pingers.Add (c.
Get (3));
 
  776   Config::ConnectWithoutContext (
"/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", 
 
  780   Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt",
 
  784   Simulator::Destroy ();
 
  787   NS_TEST_ASSERT_MSG_EQ (m_countSinkRx, 10, 
"Node 3 should have received 10 packets");
 
  790   NS_TEST_ASSERT_MSG_EQ (m_countPingRtt, 9, 
"Node 2 should have been pinged 9 times");
 
  800   virtual void DoRun (
void);
 
  808 CsmaRawIpSocketTestCase::CsmaRawIpSocketTestCase ()
 
  809   : 
TestCase (
"Raw internet protocol socket example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
 
  813 CsmaRawIpSocketTestCase::~CsmaRawIpSocketTestCase ()
 
  859   ip.
SetBase (
"192.168.1.0", 
"255.255.255.0");
 
  866   Config::SetDefault (
"ns3::Ipv4RawSocketImpl::Protocol", 
StringValue (
"2"));
 
  869   onoff.SetConstantRate (
DataRate (5000));
 
  881   Config::ConnectWithoutContext (
"/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", 
 
  885   Simulator::Destroy ();
 
  888   NS_TEST_ASSERT_MSG_EQ (m_count, 10, 
"Node 3 should have received 10 packets");
 
  898   virtual void DoRun (
void);
 
  906 CsmaStarTestCase::CsmaStarTestCase ()
 
  907   : 
TestCase (
"Star example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
 
  911 CsmaStarTestCase::~CsmaStarTestCase ()
 
  950   uint32_t nSpokes = 7;
 
  973       fillNodes.
Add (newNodes);
 
  974       fillDevices.
Add (csma.
Install (newNodes, csmaChannel));
 
  994   for(uint32_t i = 0; i < star.
SpokeCount (); ++i)
 
  996       std::ostringstream subnet;
 
  997       subnet << 
"10.1." << i << 
".0";
 
  998       address.
SetBase (subnet.str ().c_str (), 
"255.255.255.0", 
"0.0.0.3");
 
 1000       for (uint32_t j = 0; j < nFill; ++j)
 
 1002           address.
Assign (fillDevices.
Get (i * nFill + j));
 
 1009   uint16_t port = 50000;
 
 1011   PacketSinkHelper packetSinkHelper (
"ns3::TcpSocketFactory", hubLocalAddress);
 
 1026   for (uint32_t i = 0; i < star.
SpokeCount (); ++i)
 
 1046   for (uint32_t i = 0; i < fillNodes.
GetN (); ++i)
 
 1059   Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
 
 1062   Config::ConnectWithoutContext (
"/NodeList/0/ApplicationList/*/$ns3::PacketSink/Rx", 
 
 1066   Simulator::Destroy ();
 
 1070   NS_TEST_ASSERT_MSG_EQ (m_count, 10 * ( nSpokes * (nFill + 1)), 
"Hub node did not receive the proper number of packets");
 
 1079 CsmaSystemTestSuite::CsmaSystemTestSuite ()
 
virtual void DoRun(void)
Implementation to actually run this test case. 
void AssignIpv4Addresses(Ipv4AddressHelper address)
holds a vector of ns3::Application pointers. 
virtual void DoRun(void)
Implementation to actually run this test case. 
void InstallStack(InternetStackHelper stack)
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
virtual void DoRun(void)
Implementation to actually run this test case. 
holds a vector of std::pair of Ptr<Ipv4> and interface index. 
hold variables of type string 
Ptr< NetDevice > Get(uint32_t i) const 
Get the Ptr<NetDevice> stored in this container at a given index. 
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
an address for a packet socket 
Ipv4Address GetHubIpv4Address(uint32_t i) const 
aggregate IP/TCP/UDP functionality to existing Nodes. 
NetDeviceContainer Install(Ptr< Node > node) const 
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
virtual void DoRun(void)
Implementation to actually run this test case. 
ApplicationContainer Install(NodeContainer nodes) const 
void SetDefaultMulticastRoute(Ptr< Node > n, Ptr< NetDevice > nd)
Add a default route to the static routing protocol to forward packets out a particular interface...
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes. 
Give ns3::PacketSocket powers to ns3::Node. 
a polymophic address class 
void AddMulticastRoute(Ptr< Node > n, Ipv4Address source, Ipv4Address group, Ptr< NetDevice > input, NetDeviceContainer output)
Add a multicast route to a node and net device using explicit Ptr<Node> and Ptr<NetDevice> ...
uint32_t GetN(void) const 
Get the number of Ptr<Node> stored in this container. 
NetDeviceContainer GetSpokeDevices() const 
uint32_t GetN(void) const 
Get the number of Ptr<NetDevice> stored in this container. 
Class for representing data rates. 
virtual void DoRun(void)
Implementation to actually run this test case. 
hold objects of type ns3::Time 
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container. 
virtual void DoRun(void)
Implementation to actually run this test case. 
holds a vector of ns3::NetDevice pointers 
Ptr< Node > GetSpokeNode(uint32_t i) const 
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging) 
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
virtual void DoRun(void)
Implementation to actually run this test case. 
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
keep track of a set of node pointers. 
void Install(std::string nodeName) const 
void Install(Ptr< Node > node) const 
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite. 
build a set of CsmaNetDevice objects 
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
Ipv4 addresses are stored in host order in this class. 
hold objects of type ns3::Address 
virtual void DoRun(void)
Implementation to actually run this test case. 
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds. 
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container. 
uint32_t SpokeCount() const 
Helper class that adds ns3::Ipv4StaticRouting objects. 
hold objects of type ns3::DataRate 
Ptr< Node > Get(uint32_t i) const 
Get the Ptr<Node> stored in this container at a given index. 
ApplicationContainer Install(NodeContainer c) const 
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds. 
A helper class to make life easier while doing simple IPv4 address assignment in scripts. 
A helper to make it easier to create a star topology with Csma links. 
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer. 
Ptr< Node > GetHub() const 
Ptr< T > GetObject(void) const 
ApplicationContainer Install(NodeContainer c) const 
create a pinger application and associate it to a node 
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address. 
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const