16#include "ns3/boolean.h"
17#include "ns3/bridge-helper.h"
18#include "ns3/config.h"
19#include "ns3/inet-socket-address.h"
20#include "ns3/internet-stack-helper.h"
21#include "ns3/ipv4-address-helper.h"
22#include "ns3/ipv4-global-routing-helper.h"
23#include "ns3/ipv4-global-routing.h"
24#include "ns3/ipv4-l3-protocol.h"
25#include "ns3/ipv4-packet-info-tag.h"
26#include "ns3/ipv4-routing-protocol.h"
27#include "ns3/ipv4-routing-table-entry.h"
28#include "ns3/ipv4-static-routing-helper.h"
30#include "ns3/node-container.h"
32#include "ns3/packet.h"
33#include "ns3/pointer.h"
34#include "ns3/simple-channel.h"
35#include "ns3/simple-net-device-helper.h"
36#include "ns3/simple-net-device.h"
37#include "ns3/simulator.h"
38#include "ns3/socket-factory.h"
39#include "ns3/string.h"
41#include "ns3/udp-socket-factory.h"
42#include "ns3/uinteger.h"
129 void DoRun()
override;
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 void DoRun()
override;
222 :
TestCase(
"Global routing on broadcast link")
243 ipv4.
SetBase(
"10.1.1.0",
"255.255.255.0");
250 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
264 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
267 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
274 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
277 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
283 Simulator::Destroy();
296 void DoRun()
override;
304 :
TestCase(
"Global routing across two hops (point-to-point links)")
333 ipv4.
SetBase(
"10.1.1.0",
"255.255.255.252");
335 ipv4.
SetBase(
"10.1.2.0",
"255.255.255.252");
342 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
362 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
373 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
375 route = globalRouting1->GetRoute(0);
379 route = globalRouting1->GetRoute(1);
383 route = globalRouting1->GetRoute(2);
387 route = globalRouting1->GetRoute(3);
394 uint32_t nRoutes2 = globalRouting2->GetNRoutes();
398 route = globalRouting2->GetRoute(0);
403 Simulator::Destroy();
416 void DoRun()
override;
424 :
TestCase(
"Global routing across two hops (broadcast links)")
451 ipv4.
SetBase(
"10.1.1.0",
"255.255.255.0");
453 ipv4.
SetBase(
"10.1.2.0",
"255.255.255.0");
460 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
479 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
486 route = globalRouting0->GetRoute(1);
492 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
495 route = globalRouting1->GetRoute(0);
499 route = globalRouting1->GetRoute(1);
504 Simulator::Destroy();
517 void DoRun()
override;
525 :
TestCase(
"Global routing across bridging topology (bug 2102)")
548 bridgeFacingDevices.
Add(net2.
Get(0));
549 switchDevices.
Add(net2.
Get(1));
556 bridgeFacingDevices.
Add(net3.
Get(1));
557 switchDevices.
Add(net3.
Get(0));
567 bridge.
Install(switchNode, switchDevices);
582 address.SetBase(
"10.1.1.0",
"255.255.255.0");
585 address.SetBase(
"10.1.2.0",
"255.255.255.0");
586 address.Assign(bridgeFacingDevices);
588 address.SetBase(
"10.1.3.0",
"255.255.255.0");
595 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
622 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
625 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
627 route = globalRouting0->GetRoute(i);
635 "Error-- wrong destination");
638 "Error-- wrong gateway");
644 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
647 for (
uint32_t i = 0; i < globalRouting1->GetNRoutes(); i++)
649 route = globalRouting1->GetRoute(i);
657 "Error-- wrong destination");
660 "Error-- wrong gateway");
664 NS_LOG_DEBUG(
"BridgeTest skip print out of n2 and n3, go next to node n4");
669 uint32_t nRoutes4 = globalRouting4->GetNRoutes();
672 for (
uint32_t i = 0; i < globalRouting4->GetNRoutes(); i++)
674 route = globalRouting4->GetRoute(i);
682 "Error-- wrong destination");
685 "Error-- wrong gateway");
688 Simulator::Destroy();
701 void DoRun()
override;
709 :
TestCase(
"Global routing across two bridges")
733 bridgeFacingDevices.
Add(net2.
Get(0));
734 switchn2Devices.
Add(net2.
Get(1));
741 switchn2Devices.
Add(net3.
Get(0));
742 switchn3Devices.
Add(net3.
Get(1));
749 switchn3Devices.
Add(net4.
Get(0));
750 bridgeFacingDevices.
Add(net4.
Get(1));
754 bridgen2Helper.
Install(switchn2Node, switchn2Devices);
758 bridgen3Helper.
Install(switchn3Node, switchn3Devices);
773 address.SetBase(
"10.1.1.0",
"255.255.255.0");
776 address.SetBase(
"10.1.2.0",
"255.255.255.0");
777 address.Assign(bridgeFacingDevices);
783 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
803 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
806 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
808 route = globalRouting0->GetRoute(i);
816 "Error-- wrong destination");
819 "Error-- wrong gateway");
822 NS_LOG_DEBUG(
"BridgeTest skip print out of n1-n3, go next to node n4");
827 uint32_t nRoutes4 = globalRouting4->GetNRoutes();
830 for (
uint32_t i = 0; i < globalRouting4->GetNRoutes(); i++)
832 route = globalRouting4->GetRoute(i);
840 "Error-- wrong destination");
843 "Error-- wrong gateway");
846 Simulator::Destroy();
879 void DoRun()
override;
893 :
TestCase(
"Dynamic global routing example"),
904 std::vector<std::pair<Ptr<Socket>,
bool>>::iterator iter;
910 iter->second =
false;
911 iter->first->Close();
912 iter->first =
nullptr;
922 while ((packet = socket->
RecvFrom(from)))
1020 ipv4.
SetBase(
"10.1.1.0",
"255.255.255.0");
1023 ipv4.
SetBase(
"10.1.2.0",
"255.255.255.0");
1026 ipv4.
SetBase(
"10.1.3.0",
"255.255.255.0");
1029 ipv4.
SetBase(
"10.250.1.0",
"255.255.255.0");
1032 ipv4.
SetBase(
"172.16.1.0",
"255.255.255.0");
1037 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
1041 TypeId tid = TypeId::LookupByName(
"ns3::UdpSocketFactory");
1044 std::pair<Ptr<Socket>,
bool> sendSockA;
1045 sendSockA.first = Socket::CreateSocket(c.
Get(1), tid);
1046 sendSockA.first->Bind();
1048 sendSockA.second =
true;
1053 std::pair<Ptr<Socket>,
bool> sendSockB;
1054 sendSockB.first = Socket::CreateSocket(c.
Get(1), tid);
1055 sendSockB.first->Bind();
1057 sendSockB.second =
true;
1077 Simulator::Schedule(
Seconds(2), &Ipv4::SetDown, ipv41, ipv4ifIndex1);
1085 Simulator::Schedule(
Seconds(6), &Ipv4::SetDown, ipv46, ipv4ifIndex6);
1088 Simulator::Schedule(
Seconds(12), &Ipv4::SetDown, ipv41, ipv4ifIndex1);
1099 "Dynamic global routing did not deliver all packets "
1103 "Dynamic global routing did not deliver all packets "
1107 "Dynamic global routing did not deliver all packets "
1111 "Dynamic global routing did not deliver all packets "
1115 "Dynamic global routing did not deliver all packets "
1119 "Dynamic global routing did not deliver all packets "
1123 "Dynamic global routing did not deliver all packets "
1127 "Dynamic global routing did not deliver all packets "
1131 "Dynamic global routing did not deliver all packets "
1135 "Dynamic global routing did not deliver all packets "
1139 "Dynamic global routing did not deliver all packets "
1143 "Dynamic global routing did not deliver all packets "
1147 "Dynamic global routing did not deliver all packets "
1151 "Dynamic global routing did not deliver all packets "
1155 "Dynamic global routing did not deliver all packets "
1157 Simulator::Destroy();
1193 void DoRun()
override;
1198 :
TestCase(
"Slash 32 global routing example")
1213 "Received packet size is not equal to Rx buffer size");
1227 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
1260 deviceA->SetAddress(Mac48Address::Allocate());
1267 deviceC->SetAddress(Mac48Address::Allocate());
1272 ipv4.
SetBase(
"10.1.1.0",
"255.255.255.252");
1275 ipv4.
SetBase(
"10.1.1.4",
"255.255.255.252");
1282 int32_t ifIndexA = ipv4A->AddInterface(deviceA);
1283 int32_t ifIndexC = ipv4C->AddInterface(deviceC);
1287 ipv4A->AddAddress(ifIndexA, ifInAddrA);
1288 ipv4A->SetMetric(ifIndexA, 1);
1289 ipv4A->SetUp(ifIndexA);
1293 ipv4C->AddAddress(ifIndexC, ifInAddrC);
1294 ipv4C->SetMetric(ifIndexC, 1);
1295 ipv4C->SetUp(ifIndexC);
1299 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
1303 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
1310 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
1311 txSocket->SetAllowBroadcast(
true);
1319 "Static routing with /32 did not deliver all packets.");
1321 Simulator::Destroy();
1337 :
TestSuite(
"ipv4-global-routing", UNIT)
NodeContainer n1n2
Nodecontainer n1 + n2.
NodeContainer n0n2
Nodecontainer n0 + n2.
IPv4 GlobalRouting Bridge test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
IPv4 Dynamic GlobalRouting test.
void DoRun() override
Implementation to actually run this TestCase.
uint16_t m_packetSize
Packet size.
~Ipv4DynamicGlobalRoutingTestCase() override
std::vector< uint8_t > m_secondInterface
Packets received on the 2nd interface at a given time.
Ipv4DynamicGlobalRoutingTestCase()
void HandleRead(Ptr< Socket > socket)
Handle an incoming packet.
uint16_t m_count
Number of packets received.
DataRate m_dataRate
Data rate.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Sending sockets.
std::vector< uint8_t > m_firstInterface
Packets received on the 1st interface at a given time.
void ShutDownSock(uint8_t index)
Shutdown a socket.
void SendData(uint8_t index)
Send some data.
IPv4 Dynamic GlobalRouting /32 test.
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
void SendData(Ptr< Socket > socket, std::string to)
Send a packet.
~Ipv4GlobalRoutingSlash32TestCase() override
void DoRun() override
Implementation to actually run this TestCase.
Ipv4GlobalRoutingSlash32TestCase()
void DoSendData(Ptr< Socket > socket, std::string to)
Send a packet.
Ptr< Packet > m_receivedPacket
number of received packets
IPv4 GlobalRouting TestSuite.
Ipv4GlobalRoutingTestSuite()
IPv4 GlobalRouting LAN test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
IPv4 GlobalRouting Link test.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
IPv4 GlobalRouting Two bridges test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
IPv4 GlobalRouting Two LAN test.
NodeContainer m_nodes
Nodes used in the test.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
IPv4 GlobalRouting Two Link test.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
a polymophic address class
AttributeValue implementation for Boolean.
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
Class for representing data rates.
uint64_t GetBitRate() const
Get the underlying bitrate.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Helper class that adds ns3::Ipv4GlobalRouting objects.
Global routing protocol for IPv4 stacks.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Implement the IPv4 layer.
a class to represent an Ipv4 address mask
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
uint32_t GetRecvIf() const
Get the tag's receiving interface.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Smart pointer class similar to boost::intrusive_ptr.
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
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.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int ShutdownSend()=0
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
virtual int Listen()=0
Listen for incoming connections.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
API to create UDP socket instances.
void SetDefault(std::string name, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Now()
create an ns3::Time instance which contains the current simulation time.
#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.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#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.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
static Ipv4GlobalRoutingTestSuite g_globalRoutingTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void SetUp(char *deviceName)