28 #include "ns3/ipv4-packet-info-tag.h"
29 #include "ns3/ipv4-address.h"
31 #include "ns3/abort.h"
32 #include "ns3/attribute.h"
33 #include "ns3/simple-net-device.h"
34 #include "ns3/object-factory.h"
35 #include "ns3/socket-factory.h"
36 #include "ns3/udp-socket-factory.h"
37 #include "ns3/udp-socket.h"
38 #include "ns3/inet-socket-address.h"
39 #include "ns3/ipv4-l3-protocol.h"
40 #include "ns3/ipv4-raw-socket-factory.h"
41 #include "ns3/ipv4-interface.h"
42 #include "ns3/arp-l3-protocol.h"
43 #include "ns3/icmpv4-l4-protocol.h"
44 #include "ns3/ipv4-static-routing.h"
45 #include "ns3/ipv4-list-routing.h"
46 #include "ns3/udp-l4-protocol.h"
47 #include "ns3/tcp-l4-protocol.h"
48 #include "ns3/simulator.h"
67 ipv4Routing->AddRoutingProtocol (ipv4staticRouting, 0);
84 virtual void DoRun (
void);
86 void DoSendData (
Ptr<Socket> socket, std::string to);
89 Ipv4PacketInfoTagTest::Ipv4PacketInfoTagTest ()
97 uint32_t availableData;
101 m_receivedPacket = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
102 NS_TEST_ASSERT_MSG_EQ (availableData, m_receivedPacket->
GetSize (),
"Did not read expected data");
107 NS_TEST_ASSERT_MSG_EQ (found,
true,
"Could not find tag");
111 Ipv4PacketInfoTagTest::DoSendData (
Ptr<Socket> socket, std::string to)
114 if (DynamicCast<UdpSocket> (socket) != 0)
116 NS_TEST_EXPECT_MSG_EQ (socket->
SendTo (Create<Packet> (123), 0, realTo),
122 socket->
SendTo (Create<Packet> (123), 0, realTo);
137 AddInternetStack (node0);
148 node1->AddDevice (device2);
149 AddInternetStack (node1);
163 socket->Bind (local);
164 socket->SetRecvPktInfo (
true);
165 socket->SetRecvCallback (
MakeCallback (&Ipv4PacketInfoTagTest::RxCb,
this));
168 Simulator::ScheduleWithContext (socket->GetNode ()->GetId (),
Seconds (0),
169 &Ipv4PacketInfoTagTest::DoSendData,
this, socket,
"127.0.0.1");
174 Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (),
Seconds (0),
175 &Ipv4PacketInfoTagTest::DoSendData,
this, socket,
"10.1.1.1");
182 socket->Bind (local);
183 socket->SetRecvPktInfo (
true);
184 socket->SetRecvCallback (
MakeCallback (&Ipv4PacketInfoTagTest::RxCb,
this));
187 Simulator::ScheduleWithContext (socket->GetNode ()->GetId (),
Seconds (0),
188 &Ipv4PacketInfoTagTest::DoSendData,
this, socket,
"127.0.0.1");
193 Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (),
Seconds (0),
194 &Ipv4PacketInfoTagTest::DoSendData,
this, socket,
"10.1.1.1");
196 Simulator::Destroy ();
204 } g_packetinfotagTests;
206 Ipv4PacketInfoTagTestSuite::Ipv4PacketInfoTagTestSuite ()
207 :
TestSuite (
"ipv4-packet-info-tag", UNIT)
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
uint32_t GetSize(void) const
virtual Ptr< Socket > CreateSocket(void)=0
Object to create transport layer instances that provide a socket API to applications.
a polymophic address class
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void SetUp(uint32_t interface)=0
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void AggregateObject(Ptr< Object > other)
Access to the Ipv4 forwarding table, interfaces, and configuration.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
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.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
uint32_t AddDevice(Ptr< NetDevice > device)
a class to store IPv4 address information on an interface
bool RemovePacketTag(Tag &tag)
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.
Ptr< T > GetObject(void) const
virtual uint32_t GetRxAvailable(void) const =0
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.