|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
26 #include "ns3/socket-factory.h"
27 #include "ns3/udp-socket-factory.h"
28 #include "ns3/simulator.h"
29 #include "ns3/simple-channel.h"
30 #include "ns3/simple-net-device.h"
31 #include "ns3/simple-net-device-helper.h"
32 #include "ns3/socket.h"
33 #include "ns3/traffic-control-helper.h"
35 #include "ns3/boolean.h"
38 #include "ns3/inet-socket-address.h"
39 #include "ns3/inet6-socket-address.h"
40 #include "ns3/internet-stack-helper.h"
42 #include "ns3/arp-l3-protocol.h"
43 #include "ns3/ipv4-l3-protocol.h"
44 #include "ns3/ipv4-queue-disc-item.h"
45 #include "ns3/ipv6-l3-protocol.h"
46 #include "ns3/icmpv4-l4-protocol.h"
47 #include "ns3/icmpv6-l4-protocol.h"
48 #include "ns3/udp-l4-protocol.h"
49 #include "ns3/tcp-l4-protocol.h"
50 #include "ns3/ipv4-list-routing.h"
51 #include "ns3/ipv4-static-routing.h"
52 #include "ns3/ipv6-list-routing.h"
53 #include "ns3/ipv6-static-routing.h"
54 #include "ns3/ipv6-address-helper.h"
72 virtual void DoRun (
void);
89 uint32_t availableData;
110 Simulator::Destroy ();
124 virtual void DoRun (
void);
141 uint32_t availableData;
147 (void) availableData;
153 Ptr<Node> rxNode = CreateObject<Node> ();
165 Simulator::Destroy ();
217 virtual void DoRun (
void);
239 :
TestCase (
"UDP socket implementation")
245 uint32_t availableData;
253 uint32_t availableData;
277 return static_cast<uint32_t
> (priorityTag.
GetPriority ());
318 Ptr<Node> rxNode = CreateObject<Node> ();
320 Ptr<Node> txNode = CreateObject<Node> ();
347 ipv4->
SetUp (netdev_idx);
352 ipv4->
SetUp (netdev_idx);
359 ipv4->
SetUp (netdev_idx);
364 ipv4->
SetUp (netdev_idx);
419 txSocket->BindToNetDevice (net1.
Get (1));
430 int err = txSocket->GetPeerName (peerAddress);
432 NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN,
"socket error code should be ERROR_NOTCONN");
435 err = txSocket->Connect (peer);
438 err = txSocket->GetPeerName (peerAddress);
440 NS_TEST_EXPECT_MSG_EQ (peerAddress, peer,
"address from socket GetPeerName() should equal the connected address");
451 txSocket->SetIpTos (0x28);
452 txSocket->SetPriority (6);
477 Simulator::Destroy ();
506 virtual void DoRun (
void);
536 :
TestCase (
"UDP6 socket implementation")
552 uint32_t availableData;
558 (void) availableData;
563 uint32_t availableData;
569 (void) availableData;
596 Ptr<Node> rxNode = CreateObject<Node> ();
598 Ptr<Node> txNode = CreateObject<Node> ();
626 device = net1.
Get (0);
630 ipv6->
SetUp (ifIndex);
632 device = net2.
Get (0);
636 ipv6->
SetUp (ifIndex);
639 device = net1.
Get (1);
643 ipv6->
SetUp (ifIndex);
645 device = net2.
Get (1);
649 ipv6->
SetUp (ifIndex);
684 txSocket->BindToNetDevice (net1.
Get (1));
694 int err = txSocket->GetPeerName (peerAddress);
696 NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN,
"socket error code should be ERROR_NOTCONN");
699 err = txSocket->Connect (peer);
702 err = txSocket->GetPeerName (peerAddress);
704 NS_TEST_EXPECT_MSG_EQ (peerAddress, peer,
"address from socket GetPeerName() should equal the connected address");
706 Simulator::Destroy ();
holds a vector of ns3::NetDevice pointers
IPv6 address associated with an interface.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
API to create UDP socket instances.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
void Dispose(void)
Dispose of this Object.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
AttributeValue implementation for Boolean.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Ptr< Packet > m_receivedPacket
Received packet (1).
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t GetId(void) const
UDP Socket over IPv4 Test.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void SetUp(uint32_t interface)=0
uint32_t GetPriority(void)
Get the priority of the received packet.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
UDP Socket Loopback over IPv4 Test.
void SentPkt(Ptr< const QueueDiscItem > item)
Adds a packet to the list of sent packets.
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
Get the interface index of the specified NetDevice.
Ipv4 addresses are stored in host order in this class.
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Describes an IPv6 address.
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
const Ipv4Header & GetHeader(void) const
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Helper class to auto-assign global IPv6 unicast addresses.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address, bool addOnLinkRoute=true)=0
Add an address on the specified IPv6 interface.
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
Ptr< Packet > m_receivedPacket2
Received packet (2).
static UdpTestSuite g_udpTestSuite
Static variable for test initialization.
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (2).
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< Packet > m_receivedPacket
Received packet.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
UDP Socket Loopback over IPv6 Test.
void SendData(Ptr< Socket > socket)
Send data.
QueueDiscContainer Install(NetDeviceContainer c)
a polymophic address class
uint8_t GetPriority(void) const
Get the tag's priority.
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
a class to store IPv4 address information on an interface
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Holds a vector of ns3::QueueDisc pointers.
Ptr< Packet > m_receivedPacket
Received packet (1).
Keep track of a set of IPv6 interfaces.
build a set of SimpleNetDevice objects
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
virtual Ptr< Socket > CreateSocket(void)=0
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
virtual void DoRun(void)
Implementation to actually run this TestCase.
indicates whether the socket has a priority set.
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetTos(void)
Get the TOS of the received packet.
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< Packet > GetPacket(void) const
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (1).
@ UNIT
This test suite implements a Unit Test.
Time Seconds(double value)
Construct a Time in the indicated unit.
Build a set of QueueDisc objects.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
keep track of a set of node pointers.
a class to represent an Ipv4 address mask
Access to the IPv6 forwarding table, interfaces, and configuration.
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Ptr< Ipv4QueueDiscItem > m_sentPacket
Sent packet.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
UDP Socket over IPv6 Test.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
void DoSendData(Ptr< Socket > socket)
Send data.
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
Describes an IPv6 prefix.
aggregate IP/TCP/UDP functionality to existing Nodes.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
An implementation of the ICMPv6 protocol.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.
Ptr< Packet > m_receivedPacket2
Received packet (2).
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Ptr< Packet > m_receivedPacket
Received packet.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.