23 #include "ns3/arp-l3-protocol.h"
24 #include "ns3/boolean.h"
25 #include "ns3/icmpv4-l4-protocol.h"
26 #include "ns3/inet-socket-address.h"
27 #include "ns3/internet-stack-helper.h"
28 #include "ns3/ipv4-l3-protocol.h"
29 #include "ns3/ipv4-list-routing.h"
30 #include "ns3/ipv4-raw-socket-factory.h"
31 #include "ns3/ipv4-static-routing.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/socket.h"
43 #include "ns3/win32-internet.h"
45 #include <netinet/in.h>
46 #include <sys/socket.h>
51 #include <sys/types.h>
70 void DoSendData(
Ptr<Socket> socket, std::string to);
82 void DoSendData_IpHdr(
Ptr<Socket> socket, std::string to);
88 void SendData_IpHdr(
Ptr<Socket> socket, std::string to);
91 void DoRun()
override;
121 :
TestCase(
"IPv4 Raw socket implementation")
140 uint32_t availableData;
147 "Received packet size is not equal to Rx buffer size");
153 uint32_t availableData;
160 "Received packet size is not equal to Rx buffer size");
175 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
207 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
245 netdev_idx =
ipv4->AddInterface(net1.
Get(0));
247 ipv4->AddAddress(netdev_idx, ipv4Addr);
248 ipv4->SetUp(netdev_idx);
250 netdev_idx =
ipv4->AddInterface(net2.
Get(0));
252 ipv4->AddAddress(netdev_idx, ipv4Addr);
253 ipv4->SetUp(netdev_idx);
257 netdev_idx =
ipv4->AddInterface(net1.
Get(1));
259 ipv4->AddAddress(netdev_idx, ipv4Addr);
260 ipv4->SetUp(netdev_idx);
262 netdev_idx =
ipv4->AddInterface(net2.
Get(1));
264 ipv4->AddAddress(netdev_idx, ipv4Addr);
265 ipv4->SetUp(netdev_idx);
269 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
275 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
282 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
291 "second interface should not receive it");
301 "second interface should not receive it");
309 SendData (txSocket,
"255.255.255.255");
324 "second socket should not receive it (it is bound specifically to the "
325 "second interface's address");
337 rxSocket2 = rxSocketFactory->CreateSocket ();
341 SendData (txSocket,
"255.255.255.255");
352 int err = txSocket->GetPeerName(peerAddress);
355 Socket::ERROR_NOTCONN,
356 "socket error code should be ERROR_NOTCONN");
359 err = txSocket->Connect(peer);
362 err = txSocket->GetPeerName(peerAddress);
367 "address from socket GetPeerName() should equal the connected address");
369 Simulator::Destroy();
void SendData_IpHdr(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ptr< Packet > m_receivedPacket
Received packet (1).
void DoRun() override
Implementation to actually run this TestCase.
Ptr< Packet > m_receivedPacket2
Received packet (2).
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData_IpHdr(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive data.
void ReceivePkt2(Ptr< Socket > socket)
Receive data.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive data.
IPv4 RAW Socket TestSuite.
a polymophic address class
void SetPort(uint16_t port)
aggregate IP/TCP/UDP functionality to existing Nodes.
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
a class to represent an Ipv4 address mask
API to create RAW socket instances.
holds a vector of ns3::NetDevice pointers
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 SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
void Dispose()
Dispose of this Object.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void RemoveAllByteTags()
Remove all byte tags stored in this packet.
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 uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
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 Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
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.
@ UNIT
This test suite implements a Unit Test.
void ReceivePacket(Ptr< Socket > socket)
#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 Ipv4RawTestSuite g_ipv4rawTestSuite
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...