11#include "ns3/arp-l3-protocol.h"
12#include "ns3/config.h"
13#include "ns3/icmpv4-l4-protocol.h"
14#include "ns3/icmpv6-l4-protocol.h"
15#include "ns3/inet-socket-address.h"
16#include "ns3/inet6-socket-address.h"
17#include "ns3/ipv4-l3-protocol.h"
18#include "ns3/ipv4-list-routing.h"
19#include "ns3/ipv4-static-routing.h"
20#include "ns3/ipv6-l3-protocol.h"
21#include "ns3/ipv6-list-routing.h"
22#include "ns3/ipv6-static-routing.h"
25#include "ns3/simple-channel.h"
26#include "ns3/simple-net-device.h"
27#include "ns3/simulator.h"
28#include "ns3/socket-factory.h"
29#include "ns3/tcp-l4-protocol.h"
30#include "ns3/tcp-socket-factory.h"
32#include "ns3/traffic-control-layer.h"
33#include "ns3/udp-l4-protocol.h"
34#include "ns3/uinteger.h"
67 void DoRun()
override;
163 std::ostringstream oss;
164 oss << str <<
" total=" << totalStreamSize <<
" sourceWrite=" << sourceWriteSize
165 <<
" sourceRead=" << sourceReadSize <<
" serverRead=" << serverReadSize
166 <<
" serverWrite=" << serverWriteSize <<
" useIpv6=" << useIpv6;
170static inline std::string
173 std::ostringstream oss;
174 p->CopyData(&oss, p->GetSize());
184 :
TestCase(
Name(
"Send string data from client to server and back",
191 m_totalBytes(totalStreamSize),
192 m_sourceWriteSize(sourceWriteSize),
193 m_sourceReadSize(sourceReadSize),
194 m_serverWriteSize(serverWriteSize),
195 m_serverReadSize(serverReadSize),
212 auto m = (uint8_t)(97 + (i % 26));
234 "Server received expected data buffers");
237 "Source received back expected data buffers");
259 while (sock->GetRxAvailable() > 0)
269 "Server received too many bytes");
283 uint32_t toSend = std::min(left, sock->GetTxAvailable());
287 int sent = sock->Send(p);
303 uint32_t toSend = std::min(left, sock->GetTxAvailable());
307 int sent = sock->Send(p);
326 "Source received too many bytes");
343 node->AggregateObject(tc);
346 node->AggregateObject(arp);
347 arp->SetTrafficControl(tc);
352 ipv4->SetRoutingProtocol(ipv4Routing);
354 ipv4Routing->AddRoutingProtocol(ipv4staticRouting, 0);
355 node->AggregateObject(ipv4);
358 node->AggregateObject(icmp);
361 node->AggregateObject(udp);
364 node->AggregateObject(tcp);
373 node->AddDevice(dev);
375 uint32_t ndid = ipv4->AddInterface(dev);
377 ipv4->AddAddress(ndid, ipv4Addr);
385 const char* netmask =
"255.255.255.0";
386 const char* ipaddr0 =
"192.168.1.1";
387 const char* ipaddr1 =
"192.168.1.2";
394 dev0->SetChannel(channel);
395 dev1->SetChannel(channel);
403 uint16_t
port = 50000;
407 server->Bind(serverlocaladdr);
416 int err = source->GetPeerName(peerAddress);
420 "socket error code should be ERROR_NOTCONN");
422 err = source->Connect(serverremoteaddr);
425 err = source->GetPeerName(peerAddress);
429 "address from socket GetPeerName() should equal the connected address");
444 dev0->SetChannel(channel);
445 dev1->SetChannel(channel);
453 uint16_t
port = 50000;
457 server->Bind(serverlocaladdr);
466 int err = source->GetPeerName(peerAddress);
470 "socket error code should be ERROR_NOTCONN");
472 err = source->Connect(serverremoteaddr);
475 err = source->GetPeerName(peerAddress);
479 "address from socket GetPeerName() should equal the connected address");
490 ipv6->SetRoutingProtocol(ipv6Routing);
492 ipv6Routing->AddRoutingProtocol(ipv6staticRouting, 0);
493 node->AggregateObject(ipv6);
496 node->AggregateObject(icmp);
498 ipv6->RegisterExtensions();
499 ipv6->RegisterOptions();
502 node->AggregateObject(udp);
505 node->AggregateObject(tcp);
508 node->AggregateObject(tc);
517 node->AddDevice(dev);
519 uint32_t ndid = ipv6->AddInterface(dev);
521 ipv6->AddAddress(ndid, ipv6Addr);
TCP Test - send string data from client to server and back.
uint32_t m_serverReadSize
Server data size when receiving.
uint8_t * m_sourceTxPayload
Client Tx payload.
Ptr< SimpleNetDevice > AddSimpleNetDevice(Ptr< Node > node, const char *ipaddr, const char *netmask)
Add a SimpleNetDevice to a node (IPv4 version).
bool m_useIpv6
Use IPv6 instead of IPv4.
void ServerHandleSend(Ptr< Socket > sock, uint32_t available)
Server: Send data.
uint32_t m_currentServerTxBytes
Server Rx bytes.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_currentSourceTxBytes
Client Tx bytes.
void ServerHandleRecv(Ptr< Socket > sock)
Server: Receive data.
Ptr< SimpleNetDevice > AddSimpleNetDevice6(Ptr< Node > node, Ipv6Address ipaddr, Ipv6Prefix prefix)
Add a SimpleNetDevice to a node (IPv6 version).
Ptr< Node > CreateInternetNode()
Create a node with the Internet stack (IPv4 version).
Ptr< Node > CreateInternetNode6()
Create a node with the Internet stack (IPv6 version).
void SourceHandleRecv(Ptr< Socket > sock)
Client: Receive data.
void ServerHandleConnectionCreated(Ptr< Socket > s, const Address &addr)
Server: Handle connection created.
TcpTestCase(uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t sourceReadSize, uint32_t serverWriteSize, uint32_t serverReadSize, bool useIpv6)
Constructor.
uint32_t m_currentSourceRxBytes
Client Rx bytes.
uint32_t m_totalBytes
Total stream size (in bytes).
uint32_t m_sourceReadSize
Client data size when receiving.
void SetupDefaultSim6()
Setup the test (IPv6 version).
uint8_t * m_sourceRxPayload
Client Rx payload.
uint32_t m_serverWriteSize
Server data size when sending.
void SourceHandleSend(Ptr< Socket > sock, uint32_t available)
Client: Send data.
void SetupDefaultSim()
Setup the test (IPv4 version).
uint32_t m_currentServerRxBytes
Server Tx bytes.
uint8_t * m_serverRxPayload
Server Rx payload.
uint32_t m_sourceWriteSize
Client data size when sending.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
TCP TestSuite - send string data from client to server and back.
a polymophic address class
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
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
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 address associated with an interface.
Describes an IPv6 prefix.
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address Allocate()
Allocate a new Mac48Address.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
API to create TCP socket instances.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
static constexpr auto UNIT
Callback< R, Args... > MakeNullCallback()
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
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...
static TcpTestSuite g_tcpTestSuite
Static variable for test initialization.
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
static std::string GetString(Ptr< Packet > p)