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-static-routing-helper.h"
24 #include "ns3/node-container.h"
26 #include "ns3/packet.h"
27 #include "ns3/pointer.h"
28 #include "ns3/simple-channel.h"
29 #include "ns3/simple-net-device-helper.h"
30 #include "ns3/simple-net-device.h"
31 #include "ns3/simulator.h"
32 #include "ns3/socket-factory.h"
33 #include "ns3/string.h"
35 #include "ns3/udp-socket-factory.h"
36 #include "ns3/uinteger.h"
58 void DoSendData(
Ptr<Socket> socket, std::string to);
73 void DoRun()
override;
78 :
TestCase(
"Slash 32 static routing example")
89 uint32_t availableData [[maybe_unused]] = socket->
GetRxAvailable();
93 "Received packet size is not equal to Rx buffer size");
107 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
140 deviceA->SetAddress(Mac48Address::Allocate());
147 deviceC->SetAddress(Mac48Address::Allocate());
152 ipv4.SetBase(
"10.1.1.0",
"255.255.255.252");
155 ipv4.SetBase(
"10.1.1.4",
"255.255.255.252");
162 int32_t ifIndexA = ipv4A->AddInterface(deviceA);
163 int32_t ifIndexC = ipv4C->AddInterface(deviceC);
167 ipv4A->AddAddress(ifIndexA, ifInAddrA);
168 ipv4A->SetMetric(ifIndexA, 1);
169 ipv4A->SetUp(ifIndexA);
173 ipv4C->AddAddress(ifIndexC, ifInAddrC);
174 ipv4C->SetMetric(ifIndexC, 1);
175 ipv4C->SetUp(ifIndexC);
189 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
196 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
197 txSocket->SetAllowBroadcast(
true);
205 "Static routing with /32 did not deliver all packets.");
207 Simulator::Destroy();
IPv4 StaticRouting /32 Test.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoRun() override
Implementation to actually run this TestCase.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ipv4StaticRoutingSlash32TestCase()
~Ipv4StaticRoutingSlash32TestCase() override
Ptr< Packet > m_receivedPacket
Received packet.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
IPv4 StaticRouting /32 TestSuite.
Ipv4StaticRoutingTestSuite()
a polymophic address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
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.
a class to represent an Ipv4 address mask
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
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).
build a set of SimpleNetDevice objects
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
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.
API to create UDP socket instances.
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
static Ipv4StaticRoutingTestSuite ipv4StaticRoutingTestSuite
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...