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"
26 #include "ns3/node-container.h"
27 #include "ns3/packet.h"
28 #include "ns3/simple-net-device-helper.h"
29 #include "ns3/pointer.h"
30 #include "ns3/simulator.h"
31 #include "ns3/string.h"
33 #include "ns3/uinteger.h"
34 #include "ns3/ipv4-packet-info-tag.h"
35 #include "ns3/simple-net-device.h"
36 #include "ns3/simple-channel.h"
37 #include "ns3/socket-factory.h"
38 #include "ns3/udp-socket-factory.h"
49 void SendData (uint8_t index);
50 void ShutDownSock (uint8_t index);
53 virtual void DoRun (
void);
65 :
TestCase (
"Dynamic global routing example"), m_count (0)
75 std::vector<std::pair<Ptr<Socket>,
bool> >::iterator iter;
82 iter->first->Close ();
108 while ((packet = socket->
RecvFrom (from)))
206 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
209 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
212 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
215 ipv4.
SetBase (
"10.250.1.0",
"255.255.255.0");
218 ipv4.
SetBase (
"172.16.1.0",
"255.255.255.0");
223 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
227 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
230 std::pair<Ptr<Socket>,
bool> sendSockA;
231 sendSockA.first = Socket::CreateSocket (c.
Get (1), tid);
232 sendSockA.first->Bind ();
234 sendSockA.second =
true;
239 std::pair<Ptr<Socket>,
bool> sendSockB;
240 sendSockB.first = Socket::CreateSocket (c.
Get (1), tid);
241 sendSockB.first->Bind ();
243 sendSockB.second =
true;
262 uint32_t ipv4ifIndex1 = 2;
268 Simulator::Schedule (
Seconds (2), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
275 uint32_t ipv4ifIndex6 = 2;
276 Simulator::Schedule (
Seconds (6), &Ipv4::SetDown,ipv46, ipv4ifIndex6);
279 Simulator::Schedule (
Seconds (12), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
303 Simulator::Destroy ();
318 virtual void DoRun (
void);
323 :
TestCase (
"Slash 32 global routing example")
334 uint32_t availableData;
340 (void) availableData;
357 Simulator::Stop (
Seconds (66));
384 deviceA->
SetAddress (Mac48Address::Allocate ());
391 deviceC->
SetAddress (Mac48Address::Allocate ());
392 nC->AddDevice (deviceC);
396 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
399 ipv4.
SetBase (
"10.1.1.4",
"255.255.255.252");
407 int32_t ifIndexC = ipv4C->AddInterface (deviceC);
412 ipv4A->
SetUp (ifIndexA);
415 ipv4C->AddAddress (ifIndexC, ifInAddrC);
416 ipv4C->SetMetric (ifIndexC, 1);
417 ipv4C->SetUp (ifIndexC);
421 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
439 Simulator::Destroy ();
450 :
TestSuite (
"ipv4-global-routing", UNIT)
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Simulation virtual time values and global simulation resolution.
Ptr< Packet > m_receivedPacket
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.
void SinkRx(std::string path, Ptr< const Packet > p, const Address &address)
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
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...
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()
void Connect(std::string path, const CallbackBase &cb)
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.
virtual void SetUp(uint32_t interface)=0
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
#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)
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.
void SendData(uint8_t index)
void ReceivePkt(Ptr< Socket > socket)
Access to the Ipv4 forwarding table, interfaces, and configuration.
void SetDefault(std::string name, const AttributeValue &value)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
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)
static Ipv4GlobalRoutingTestSuite globalRoutingTestSuite
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~Ipv4DynamicGlobalRoutingTestCase()
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
virtual ~Ipv4GlobalRoutingSlash32TestCase()
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
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...
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
uint32_t GetId(void) const
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 >)
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
virtual void SetAddress(Address address)
Set the address of this interface.
Time Seconds(double value)
Construct a Time in the indicated unit.
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
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.
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
static void SinkRx(std::string path, Ptr< const Packet > p, const Address &address)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
std::vector< uint8_t > m_firstInterface
Ipv4GlobalRoutingTestSuite()
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.