22 #include "ns3/socket-factory.h"
23 #include "ns3/udp-socket-factory.h"
24 #include "ns3/simulator.h"
25 #include "ns3/simple-channel.h"
26 #include "ns3/simple-net-device.h"
27 #include "ns3/socket.h"
28 #include "ns3/boolean.h"
32 #include "ns3/inet-socket-address.h"
34 #include "ns3/arp-l3-protocol.h"
35 #include "ns3/ipv4-l3-protocol.h"
36 #include "ns3/icmpv4-l4-protocol.h"
37 #include "ns3/udp-l4-protocol.h"
38 #include "ns3/ipv4-static-routing.h"
39 #include "ns3/internet-stack-helper.h"
40 #include "ns3/ipv4-routing-helper.h"
42 #include "ns3/traffic-control-layer.h"
65 void DoSendData (
Ptr<Socket> socket, std::string to);
74 virtual void DoRun (
void);
85 :
TestCase (
"UDP socket implementation")
91 uint32_t availableData;
120 Ptr<Node> rxNode = CreateObject<Node> ();
128 rxDev = CreateObject<SimpleNetDevice> ();
129 rxDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
132 uint32_t netdev_idx = ipv4->AddInterface (rxDev);
134 ipv4->AddAddress (netdev_idx, ipv4Addr);
135 ipv4->SetUp (netdev_idx);
139 Ptr<Node> fwNode = CreateObject<Node> ();
144 fwDev1 = CreateObject<SimpleNetDevice> ();
145 fwDev1->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
148 uint32_t netdev_idx = ipv4->AddInterface (fwDev1);
150 ipv4->AddAddress (netdev_idx, ipv4Addr);
151 ipv4->SetUp (netdev_idx);
155 fwDev2 = CreateObject<SimpleNetDevice> ();
156 fwDev2->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
159 uint32_t netdev_idx = ipv4->AddInterface (fwDev2);
161 ipv4->AddAddress (netdev_idx, ipv4Addr);
162 ipv4->SetUp (netdev_idx);
166 Ptr<Node> txNode = CreateObject<Node> ();
171 txDev = CreateObject<SimpleNetDevice> ();
172 txDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
175 uint32_t netdev_idx = ipv4->AddInterface (txDev);
177 ipv4->AddAddress (netdev_idx, ipv4Addr);
178 ipv4->SetUp (netdev_idx);
180 ipv4StaticRouting->SetDefaultRoute(
Ipv4Address(
"10.1.0.1"), netdev_idx);
185 rxDev->SetChannel (channel1);
186 fwDev1->SetChannel (channel1);
189 fwDev2->SetChannel (channel2);
190 txDev->SetChannel (channel2);
194 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
199 Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
200 txSocket->SetAllowBroadcast (
true);
216 Simulator::Destroy ();
Ptr< Packet > m_receivedPacket
Received packet.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
IPv4 Forwarding TestSuite.
Ipv4ForwardingTestSuite()
a polymophic address class
AttributeValue implementation for Boolean.
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...
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const =0
Get the routing protocol to be used by this Ipv4 stack.
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
uint32_t GetId(void) const
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
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 Ipv4ForwardingTestSuite g_ipv4forwardingTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...