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"
123 virtual void DoSetup (
void);
124 virtual void DoRun (
void);
131 :
TestCase (
"Global routing on point-to-point link")
153 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
160 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
174 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
183 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
186 route = globalRouting1->
GetRoute (0);
195 Simulator::Destroy ();
202 virtual void DoRun (
void);
209 :
TestCase (
"Global routing on broadcast link")
230 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
237 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
251 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
254 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
261 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
264 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
270 Simulator::Destroy ();
277 virtual void DoRun (
void);
284 :
TestCase (
"Global routing across two hops (point-to-point links)")
303 net2.
Add (simpleHelper2.Install (
m_nodes.
Get (2), channel2));
313 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
315 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.252");
322 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
342 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
353 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
355 route = globalRouting1->
GetRoute (0);
359 route = globalRouting1->
GetRoute (1);
360 NS_LOG_DEBUG (
"TwoLinkTest entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
363 route = globalRouting1->
GetRoute (2);
364 NS_LOG_DEBUG (
"TwoLinkTest entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
367 route = globalRouting1->
GetRoute (3);
368 NS_LOG_DEBUG (
"TwoLinkTest entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
374 uint32_t nRoutes2 = globalRouting2->
GetNRoutes ();
378 route = globalRouting2->
GetRoute (0);
379 NS_LOG_DEBUG (
"entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
383 Simulator::Destroy ();
390 virtual void DoRun (
void);
397 :
TestCase (
"Global routing across two hops (broadcast links)")
414 net2.
Add (simpleHelper2.Install (
m_nodes.
Get (2), channel2));
424 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
426 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
433 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
452 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
459 route = globalRouting0->
GetRoute (1);
460 NS_LOG_DEBUG (
"entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
465 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
468 route = globalRouting1->
GetRoute (0);
469 NS_LOG_DEBUG (
"TwoLanTest entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
472 route = globalRouting1->
GetRoute (1);
473 NS_LOG_DEBUG (
"TwoLanTest entry dest " << route->GetDest () <<
" gw " << route->GetGateway ());
477 Simulator::Destroy ();
484 virtual void DoRun (
void);
491 :
TestCase (
"Global routing across bridging topology (bug 2102)")
513 net2.
Add (simpleHelper2.Install (
m_nodes.
Get (2), channel2));
514 bridgeFacingDevices.
Add (net2.
Get (0));
515 switchDevices.
Add (net2.
Get (1));
521 net3.
Add (simpleHelper3.Install (
m_nodes.
Get (3), channel3));
522 bridgeFacingDevices.
Add (net3.
Get (1));
523 switchDevices.
Add (net3.
Get (0));
529 net4.
Add (simpleHelper4.Install (
m_nodes.
Get (4), channel4));
533 bridge.
Install (switchNode, switchDevices);
548 address.
SetBase (
"10.1.1.0",
"255.255.255.0");
551 address.
SetBase (
"10.1.2.0",
"255.255.255.0");
552 address.
Assign (bridgeFacingDevices);
554 address.
SetBase (
"10.1.3.0",
"255.255.255.0");
562 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
589 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
592 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
594 route = globalRouting0->
GetRoute (i);
607 uint32_t nRoutes1 = globalRouting1->
GetNRoutes ();
610 for (uint32_t i = 0; i < globalRouting1->
GetNRoutes (); i++)
612 route = globalRouting1->
GetRoute (i);
623 NS_LOG_DEBUG (
"BridgeTest skip print out of n2 and n3, go next to node n4");
628 uint32_t nRoutes4 = globalRouting4->
GetNRoutes ();
631 for (uint32_t i = 0; i < globalRouting4->
GetNRoutes (); i++)
633 route = globalRouting4->
GetRoute (i);
643 Simulator::Destroy ();
650 virtual void DoRun (
void);
657 :
TestCase (
"Global routing across two bridges")
680 net2.
Add (simpleHelper2.Install (
m_nodes.
Get (2), channel2));
681 bridgeFacingDevices.
Add (net2.
Get (0));
682 switchn2Devices.
Add (net2.
Get (1));
688 net3.
Add (simpleHelper3.Install (
m_nodes.
Get (3), channel3));
689 switchn2Devices.
Add (net3.
Get (0));
690 switchn3Devices.
Add (net3.
Get (1));
696 net4.
Add (simpleHelper4.Install (
m_nodes.
Get (4), channel4));
697 switchn3Devices.
Add (net4.
Get (0));
698 bridgeFacingDevices.
Add (net4.
Get (1));
702 bridgen2Helper.
Install (switchn2Node, switchn2Devices);
706 bridgen3Helper.
Install (switchn3Node, switchn3Devices);
721 address.
SetBase (
"10.1.1.0",
"255.255.255.0");
724 address.
SetBase (
"10.1.2.0",
"255.255.255.0");
725 address.
Assign (bridgeFacingDevices);
732 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
752 uint32_t nRoutes0 = globalRouting0->
GetNRoutes ();
755 for (uint32_t i = 0; i < globalRouting0->
GetNRoutes (); i++)
757 route = globalRouting0->
GetRoute (i);
767 NS_LOG_DEBUG (
"BridgeTest skip print out of n1-n3, go next to node n4");
772 uint32_t nRoutes4 = globalRouting4->
GetNRoutes ();
775 for (uint32_t i = 0; i < globalRouting4->
GetNRoutes (); i++)
777 route = globalRouting4->
GetRoute (i);
787 Simulator::Destroy ();
800 virtual void DoRun (
void);
812 :
TestCase (
"Dynamic global routing example"), m_count (0)
822 std::vector<std::pair<Ptr<Socket>,
bool> >::iterator iter;
828 iter->second =
false;
829 iter->first->Close ();
840 while ((packet = socket->
RecvFrom (from)))
938 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
941 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
944 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
947 ipv4.
SetBase (
"10.250.1.0",
"255.255.255.0");
950 ipv4.
SetBase (
"172.16.1.0",
"255.255.255.0");
955 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
959 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
962 std::pair<Ptr<Socket>,
bool> sendSockA;
963 sendSockA.first = Socket::CreateSocket (c.
Get (1), tid);
964 sendSockA.first->Bind ();
966 sendSockA.second =
true;
971 std::pair<Ptr<Socket>,
bool> sendSockB;
972 sendSockB.first = Socket::CreateSocket (c.
Get (1), tid);
973 sendSockB.first->Bind ();
975 sendSockB.second =
true;
994 uint32_t ipv4ifIndex1 = 2;
996 Simulator::Schedule (
Seconds (2), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
1003 uint32_t ipv4ifIndex6 = 2;
1004 Simulator::Schedule (
Seconds (6), &Ipv4::SetDown,ipv46, ipv4ifIndex6);
1007 Simulator::Schedule (
Seconds (12), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
1031 Simulator::Destroy ();
1046 virtual void DoRun (
void);
1051 :
TestCase (
"Slash 32 global routing example")
1062 uint32_t availableData;
1068 (void) availableData;
1085 Simulator::Stop (
Seconds (66));
1112 deviceA->
SetAddress (Mac48Address::Allocate ());
1119 deviceC->
SetAddress (Mac48Address::Allocate ());
1120 nC->AddDevice (deviceC);
1124 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
1127 ipv4.
SetBase (
"10.1.1.4",
"255.255.255.252");
1135 int32_t ifIndexC = ipv4C->AddInterface (deviceC);
1140 ipv4A->
SetUp (ifIndexA);
1143 ipv4C->AddAddress (ifIndexC, ifInAddrC);
1144 ipv4C->SetMetric (ifIndexC, 1);
1145 ipv4C->SetUp (ifIndexC);
1149 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
1164 SendData (txSocket,
"192.168.1.1");
1167 Simulator::Destroy ();
1177 :
TestSuite (
"ipv4-global-routing", UNIT)
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Simulation virtual time values and global simulation resolution.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Smart pointer class similar to boost::intrusive_ptr.
Ptr< Packet > m_receivedPacket
AttributeValue implementation for Boolean.
virtual void DoRun(void)
Implementation to actually run this TestCase.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
holds a vector of std::pair of Ptr and interface index.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
a class to represent an Ipv4 address mask
virtual int ShutdownSend(void)=0
#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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual Ptr< Socket > CreateSocket(void)=0
Ipv4DynamicGlobalRoutingTestCase()
Ipv4RoutingTableEntry * GetRoute(uint32_t i) const
Get a route from the global unicast routing table.
a polymophic address class
Ipv4GlobalRoutingSlash32TestCase()
void SetUp(char *deviceName)
std::vector< uint8_t > m_secondInterface
virtual int Listen(void)=0
Listen for incoming connections.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Class for representing data rates.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void SetUp(uint32_t interface)=0
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
Global routing protocol for IPv4 stacks.
#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.
void DoSendData(Ptr< Socket > socket, std::string to)
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
void SendData(uint8_t index)
void ReceivePkt(Ptr< Socket > socket)
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
Access to the IPv4 forwarding table, interfaces, and configuration.
Implement the IPv4 layer.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
uint64_t GetBitRate() const
Get the underlying bitrate.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SendData(Ptr< Socket > socket, std::string to)
Ipv4Address GetDest(void) const
static Ipv4GlobalRoutingTestSuite globalRoutingTestSuite
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~Ipv4DynamicGlobalRoutingTestCase()
virtual ~Ipv4GlobalRoutingSlash32TestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
Ipv4 addresses are stored in host order in this class.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
uint32_t GetId(void) const
#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...
a class to store IPv4 address information on an interface
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
void HandleRead(Ptr< Socket >)
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Ipv4Address GetGateway(void) const
virtual void SetAddress(Address address)
Set the address of this interface.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
Helper class that adds ns3::Ipv4GlobalRouting objects.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
API to create UDP socket instances.
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 ShutDownSock(uint8_t index)
build a set of SimpleNetDevice objects
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const
Get the routing protocol to be used by this Ipv4 stack.
a unique identifier for an interface.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
std::vector< uint8_t > m_firstInterface
Ipv4GlobalRoutingTestSuite()
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
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
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.