23 #include "ns3/boolean.h"
24 #include "ns3/icmpv6-l4-protocol.h"
25 #include "ns3/inet6-socket-address.h"
26 #include "ns3/internet-stack-helper.h"
27 #include "ns3/ipv6-address-helper.h"
28 #include "ns3/ipv6-l3-protocol.h"
29 #include "ns3/ipv6-list-routing.h"
30 #include "ns3/ipv6-raw-socket-factory.h"
31 #include "ns3/ipv6-static-routing.h"
33 #include "ns3/node-container.h"
35 #include "ns3/simple-channel.h"
36 #include "ns3/simple-net-device-helper.h"
37 #include "ns3/simple-net-device.h"
38 #include "ns3/simulator.h"
39 #include "ns3/socket-factory.h"
40 #include "ns3/socket.h"
42 #include "ns3/uinteger.h"
45 #include "ns3/win32-internet.h"
47 #include <netinet/in.h>
48 #include <sys/socket.h>
53 #include <sys/types.h>
72 void DoSendData(
Ptr<Socket> socket, std::string to);
81 void DoRun()
override;
111 :
TestCase(
"Ipv6 Raw socket implementation")
130 uint32_t availableData;
137 "Received packet size is not equal to Rx buffer size");
143 uint32_t availableData;
151 "Received packet size is not equal to Rx buffer size");
168 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
213 device = net1.
Get(0);
214 ifIndex = ipv6->GetInterfaceForDevice(device);
216 ipv6->AddAddress(ifIndex, ipv6Addr);
218 device = net2.
Get(0);
219 ifIndex = ipv6->GetInterfaceForDevice(device);
221 ipv6->AddAddress(ifIndex, ipv6Addr);
224 device = net1.
Get(1);
225 ifIndex = ipv6->GetInterfaceForDevice(device);
227 ipv6->AddAddress(ifIndex, ipv6Addr);
228 ipv6->SetForwarding(ifIndex,
true);
230 device = net2.
Get(1);
231 ifIndex = ipv6->GetInterfaceForDevice(device);
233 ipv6->AddAddress(ifIndex, ipv6Addr);
234 ipv6->SetForwarding(ifIndex,
true);
238 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
242 rxSocket->SetAttribute(
"Protocol",
UintegerValue(Ipv6Header::IPV6_ICMPV6));
245 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
253 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
254 txSocket->SetAttribute(
"Protocol",
UintegerValue(Ipv6Header::IPV6_ICMPV6));
264 "second interface should not receive it");
275 "second socket should not receive it (it is bound specifically to the "
276 "second interface's address");
287 rxSocket2 = rxSocketFactory->CreateSocket();
304 int err = txSocket->GetPeerName(peerAddress);
307 Socket::ERROR_NOTCONN,
308 "socket error code should be ERROR_NOTCONN");
311 err = txSocket->Connect(peer);
314 err = txSocket->GetPeerName(peerAddress);
319 "address from socket GetPeerName() should equal the connected address");
321 Simulator::Destroy();
Ptr< Packet > m_receivedPacket2
Received packet (2).
Ptr< Packet > m_receivedPacket
Received packet (1).
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive data.
void ReceivePkt2(Ptr< Socket > socket)
Receive data.
void DoRun() override
Implementation to actually run this TestCase.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive data.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
IPv6 RAW Socket TestSuite.
a polymophic address class
An implementation of the ICMPv6 protocol.
void SetPort(uint16_t port)
Set the port.
Ipv6Address GetIpv6() const
Get the IPv6 address.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 address associated with an interface.
Keep track of a set of IPv6 interfaces.
Describes an IPv6 prefix.
API to create IPv6 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.
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 Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
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.
Hold an unsigned integer type.
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 Ipv6RawTestSuite g_ipv6rawTestSuite
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...