|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
18 #include "ns3/boolean.h"
19 #include "ns3/config.h"
20 #include "ns3/inet-socket-address.h"
21 #include "ns3/internet-stack-helper.h"
22 #include "ns3/ipv4-address-helper.h"
23 #include "ns3/ipv4-global-routing-helper.h"
24 #include "ns3/ipv4-static-routing-helper.h"
27 #include "ns3/node-container.h"
28 #include "ns3/packet.h"
29 #include "ns3/simple-net-device-helper.h"
30 #include "ns3/pointer.h"
31 #include "ns3/simulator.h"
32 #include "ns3/string.h"
34 #include "ns3/uinteger.h"
35 #include "ns3/ipv4-packet-info-tag.h"
36 #include "ns3/simple-net-device.h"
37 #include "ns3/simple-channel.h"
38 #include "ns3/socket-factory.h"
39 #include "ns3/udp-socket-factory.h"
40 #include "ns3/ipv4-l3-protocol.h"
41 #include "ns3/ipv4-routing-protocol.h"
42 #include "ns3/ipv4-routing-table-entry.h"
43 #include "ns3/ipv4-global-routing.h"
44 #include "ns3/bridge-helper.h"
129 virtual void DoSetup (
void);
130 virtual void DoRun (
void);
137 :
TestCase (
"Global routing on point-to-point link")
159 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
166 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
180 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
189 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
192 route = globalRouting1->
GetRoute (0);
201 Simulator::Destroy ();
214 virtual void DoRun (
void);
221 :
TestCase (
"Global routing on broadcast link")
242 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
249 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
263 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
266 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
273 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
276 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
282 Simulator::Destroy ();
295 virtual void DoRun (
void);
302 :
TestCase (
"Global routing across two hops (point-to-point links)")
331 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
333 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.252");
340 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
360 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
371 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
373 route = globalRouting1->
GetRoute (0);
377 route = globalRouting1->
GetRoute (1);
381 route = globalRouting1->
GetRoute (2);
385 route = globalRouting1->
GetRoute (3);
392 uint32_t nRoutes2 = globalRouting2->
GetNRoutes ();
396 route = globalRouting2->
GetRoute (0);
401 Simulator::Destroy ();
414 virtual void DoRun (
void);
421 :
TestCase (
"Global routing across two hops (broadcast links)")
448 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
450 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
457 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
476 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
483 route = globalRouting0->
GetRoute (1);
489 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
492 route = globalRouting1->
GetRoute (0);
496 route = globalRouting1->
GetRoute (1);
501 Simulator::Destroy ();
514 virtual void DoRun (
void);
521 :
TestCase (
"Global routing across bridging topology (bug 2102)")
544 bridgeFacingDevices.
Add (net2.
Get (0));
545 switchDevices.
Add (net2.
Get (1));
552 bridgeFacingDevices.
Add (net3.
Get (1));
553 switchDevices.
Add (net3.
Get (0));
563 bridge.
Install (switchNode, switchDevices);
578 address.SetBase (
"10.1.1.0",
"255.255.255.0");
581 address.SetBase (
"10.1.2.0",
"255.255.255.0");
582 address.Assign (bridgeFacingDevices);
584 address.SetBase (
"10.1.3.0",
"255.255.255.0");
592 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
619 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
622 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
624 route = globalRouting0->
GetRoute (i);
637 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
640 for (uint32_t i = 0; i < globalRouting1->
GetNRoutes (); i++)
642 route = globalRouting1->
GetRoute (i);
653 NS_LOG_DEBUG (
"BridgeTest skip print out of n2 and n3, go next to node n4");
658 uint32_t nRoutes4 = globalRouting4->
GetNRoutes ();
661 for (uint32_t i = 0; i < globalRouting4->
GetNRoutes (); i++)
663 route = globalRouting4->
GetRoute (i);
673 Simulator::Destroy ();
686 virtual void DoRun (
void);
693 :
TestCase (
"Global routing across two bridges")
717 bridgeFacingDevices.
Add (net2.
Get (0));
718 switchn2Devices.
Add (net2.
Get (1));
725 switchn2Devices.
Add (net3.
Get (0));
726 switchn3Devices.
Add (net3.
Get (1));
733 switchn3Devices.
Add (net4.
Get (0));
734 bridgeFacingDevices.
Add (net4.
Get (1));
738 bridgen2Helper.
Install (switchn2Node, switchn2Devices);
742 bridgen3Helper.
Install (switchn3Node, switchn3Devices);
757 address.SetBase (
"10.1.1.0",
"255.255.255.0");
760 address.SetBase (
"10.1.2.0",
"255.255.255.0");
761 address.Assign (bridgeFacingDevices);
768 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
788 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
791 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
793 route = globalRouting0->
GetRoute (i);
803 NS_LOG_DEBUG (
"BridgeTest skip print out of n1-n3, go next to node n4");
808 uint32_t nRoutes4 = globalRouting4->
GetNRoutes ();
811 for (uint32_t i = 0; i < globalRouting4->
GetNRoutes (); i++)
813 route = globalRouting4->
GetRoute (i);
823 Simulator::Destroy ();
856 virtual void DoRun (
void);
868 :
TestCase (
"Dynamic global routing example"), m_count (0)
878 std::vector<std::pair<Ptr<Socket>,
bool> >::iterator iter;
884 iter->second =
false;
885 iter->first->Close ();
896 while ((packet = socket->
RecvFrom (from)))
994 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
997 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
1000 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
1003 ipv4.
SetBase (
"10.250.1.0",
"255.255.255.0");
1006 ipv4.
SetBase (
"172.16.1.0",
"255.255.255.0");
1011 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
1015 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
1018 std::pair<Ptr<Socket>,
bool> sendSockA;
1019 sendSockA.first = Socket::CreateSocket (c.
Get (1), tid);
1020 sendSockA.first->Bind ();
1022 sendSockA.second =
true;
1027 std::pair<Ptr<Socket>,
bool> sendSockB;
1028 sendSockB.first = Socket::CreateSocket (c.
Get (1), tid);
1029 sendSockB.first->Bind ();
1031 sendSockB.second =
true;
1050 uint32_t ipv4ifIndex1 = 2;
1052 Simulator::Schedule (
Seconds (2), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
1059 uint32_t ipv4ifIndex6 = 2;
1060 Simulator::Schedule (
Seconds (6), &Ipv4::SetDown,ipv46, ipv4ifIndex6);
1063 Simulator::Schedule (
Seconds (12), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
1087 Simulator::Destroy ();
1123 virtual void DoRun (
void);
1128 :
TestCase (
"Slash 32 global routing example")
1139 uint32_t availableData;
1145 (void) availableData;
1162 Simulator::Stop (
Seconds (66));
1189 deviceA->
SetAddress (Mac48Address::Allocate ());
1196 deviceC->
SetAddress (Mac48Address::Allocate ());
1201 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
1204 ipv4.
SetBase (
"10.1.1.4",
"255.255.255.252");
1212 int32_t ifIndexC = ipv4C->AddInterface (deviceC);
1217 ipv4A->
SetUp (ifIndexA);
1220 ipv4C->AddAddress (ifIndexC, ifInAddrC);
1221 ipv4C->SetMetric (ifIndexC, 1);
1222 ipv4C->SetUp (ifIndexC);
1226 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
1241 SendData (txSocket,
"192.168.1.1");
1244 Simulator::Destroy ();
1260 :
TestSuite (
"ipv4-global-routing", UNIT)
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
holds a vector of ns3::NetDevice pointers
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
API to create UDP socket instances.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
virtual void DoRun(void)
Implementation to actually run this TestCase.
AttributeValue implementation for Boolean.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::vector< uint8_t > m_firstInterface
Packets received on the 1st interface at a given time.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t GetId(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv4GlobalRoutingSlash32TestCase()
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
virtual void SetUp(uint32_t interface)=0
uint16_t m_count
Number of packets received.
uint16_t m_packetSize
Packet size.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ipv4DynamicGlobalRoutingTestCase()
NodeContainer m_nodes
Nodes used in the test.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
void HandleRead(Ptr< Socket > socket)
Handle an incoming packet.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ipv4 addresses are stored in host order in this class.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< Packet > m_receivedPacket
number of received packets
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
virtual void DoRun(void)
Implementation to actually run this TestCase.
IPv4 GlobalRouting LAN test.
IPv4 Dynamic GlobalRouting test.
void SetUp(char *deviceName)
Ipv4Address GetGateway(void) const
Ipv4GlobalRoutingTestSuite()
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
virtual void SetAddress(Address address)
Set the address of this interface.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Global routing protocol for IPv4 stacks.
void DoSendData(Ptr< Socket > socket, std::string to)
Send a packet.
NodeContainer m_nodes
Nodes used in the test.
void SendData(uint8_t index)
Send some data.
Ipv4RoutingTableEntry * GetRoute(uint32_t i) const
Get a route from the global unicast routing table.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Access to the IPv4 forwarding table, interfaces, and configuration.
DataRate m_dataRate
Data rate.
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
IPv4 GlobalRouting Link test.
Smart pointer class similar to boost::intrusive_ptr.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Class for representing data rates.
Ipv4Address GetDest(void) const
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Sending sockets.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
a polymophic address class
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
a class to store IPv4 address information on an interface
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const
Get the routing protocol to be used by this Ipv4 stack.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
virtual void DoRun(void)
Implementation to actually run this TestCase.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
build a set of SimpleNetDevice objects
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
IPv4 GlobalRouting Two LAN test.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Simulation virtual time values and global simulation resolution.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
virtual int ShutdownSend(void)=0
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
IPv4 GlobalRouting Two Link test.
uint64_t GetBitRate() const
Get the underlying bitrate.
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
virtual Ptr< Socket > CreateSocket(void)=0
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
NodeContainer m_nodes
Nodes used in the test.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
virtual int Listen(void)=0
Listen for incoming connections.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
IPv4 Dynamic GlobalRouting /32 test.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
NodeContainer m_nodes
Nodes used in the test.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Implement the IPv4 layer.
static Ipv4GlobalRoutingTestSuite g_globalRoutingTestSuite
Static variable for test initialization.
IPv4 GlobalRouting TestSuite.
keep track of a set of node pointers.
a class to represent an Ipv4 address mask
Helper class that adds ns3::Ipv4GlobalRouting objects.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
virtual ~Ipv4GlobalRoutingSlash32TestCase()
void SetDefault(std::string name, const AttributeValue &value)
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
NodeContainer m_nodes
Nodes used in the test.
IPv4 GlobalRouting Bridge test.
void ShutDownSock(uint8_t index)
Shutdown a socket.
NodeContainer m_nodes
Nodes used in the test.
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
IPv4 GlobalRouting Two bridges test.
aggregate IP/TCP/UDP functionality to existing Nodes.
std::vector< uint8_t > m_secondInterface
Packets received on the 2nd interface at a given time.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
void SendData(Ptr< Socket > socket, std::string to)
Send a packet.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
virtual ~Ipv4DynamicGlobalRoutingTestCase()
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.