A Discrete-Event Network Simulator
API
tcp-test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Georgia Tech Research Corporation
3  * Copyright (c) 2009 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Raj Bhattacharjea <raj.b@gatech.edu>
20  */
21 
22 #include "ns3/arp-l3-protocol.h"
23 #include "ns3/config.h"
24 #include "ns3/icmpv4-l4-protocol.h"
25 #include "ns3/icmpv6-l4-protocol.h"
26 #include "ns3/inet-socket-address.h"
27 #include "ns3/inet6-socket-address.h"
28 #include "ns3/ipv4-l3-protocol.h"
29 #include "ns3/ipv4-list-routing.h"
30 #include "ns3/ipv4-static-routing.h"
31 #include "ns3/ipv6-l3-protocol.h"
32 #include "ns3/ipv6-list-routing.h"
33 #include "ns3/ipv6-static-routing.h"
34 #include "ns3/log.h"
35 #include "ns3/node.h"
36 #include "ns3/simple-channel.h"
37 #include "ns3/simple-net-device.h"
38 #include "ns3/simulator.h"
39 #include "ns3/socket-factory.h"
40 #include "ns3/tcp-l4-protocol.h"
41 #include "ns3/tcp-socket-factory.h"
42 #include "ns3/test.h"
43 #include "ns3/traffic-control-layer.h"
44 #include "ns3/udp-l4-protocol.h"
45 #include "ns3/uinteger.h"
46 
47 #include <string>
48 
49 using namespace ns3;
50 
51 NS_LOG_COMPONENT_DEFINE("TcpTestSuite");
52 
58 class TcpTestCase : public TestCase
59 {
60  public:
70  TcpTestCase(uint32_t totalStreamSize,
71  uint32_t sourceWriteSize,
72  uint32_t sourceReadSize,
73  uint32_t serverWriteSize,
74  uint32_t serverReadSize,
75  bool useIpv6);
76 
77  private:
78  void DoRun() override;
79  void DoTeardown() override;
80 
84  void SetupDefaultSim();
88  void SetupDefaultSim6();
89 
94  Ptr<Node> CreateInternetNode();
99  Ptr<Node> CreateInternetNode6();
100 
109  const char* ipaddr,
110  const char* netmask);
118  Ptr<SimpleNetDevice> AddSimpleNetDevice6(Ptr<Node> node, Ipv6Address ipaddr, Ipv6Prefix prefix);
119 
125  void ServerHandleConnectionCreated(Ptr<Socket> s, const Address& addr);
130  void ServerHandleRecv(Ptr<Socket> sock);
136  void ServerHandleSend(Ptr<Socket> sock, uint32_t available);
142  void SourceHandleSend(Ptr<Socket> sock, uint32_t available);
147  void SourceHandleRecv(Ptr<Socket> sock);
148 
149  uint32_t m_totalBytes;
150  uint32_t m_sourceWriteSize;
151  uint32_t m_sourceReadSize;
152  uint32_t m_serverWriteSize;
153  uint32_t m_serverReadSize;
158  uint8_t* m_sourceTxPayload;
159  uint8_t* m_sourceRxPayload;
160  uint8_t* m_serverRxPayload;
161 
162  bool m_useIpv6;
163 };
164 
165 static std::string
166 Name(std::string str,
167  uint32_t totalStreamSize,
168  uint32_t sourceWriteSize,
169  uint32_t serverReadSize,
170  uint32_t serverWriteSize,
171  uint32_t sourceReadSize,
172  bool useIpv6)
173 {
174  std::ostringstream oss;
175  oss << str << " total=" << totalStreamSize << " sourceWrite=" << sourceWriteSize
176  << " sourceRead=" << sourceReadSize << " serverRead=" << serverReadSize
177  << " serverWrite=" << serverWriteSize << " useIpv6=" << useIpv6;
178  return oss.str();
179 }
180 
181 static inline std::string
183 {
184  std::ostringstream oss;
185  p->CopyData(&oss, p->GetSize());
186  return oss.str();
187 }
188 
189 TcpTestCase::TcpTestCase(uint32_t totalStreamSize,
190  uint32_t sourceWriteSize,
191  uint32_t sourceReadSize,
192  uint32_t serverWriteSize,
193  uint32_t serverReadSize,
194  bool useIpv6)
195  : TestCase(Name("Send string data from client to server and back",
196  totalStreamSize,
197  sourceWriteSize,
198  serverReadSize,
199  serverWriteSize,
200  sourceReadSize,
201  useIpv6)),
202  m_totalBytes(totalStreamSize),
203  m_sourceWriteSize(sourceWriteSize),
204  m_sourceReadSize(sourceReadSize),
205  m_serverWriteSize(serverWriteSize),
206  m_serverReadSize(serverReadSize),
207  m_useIpv6(useIpv6)
208 {
209 }
210 
211 void
213 {
218  m_sourceTxPayload = new uint8_t[m_totalBytes];
219  m_sourceRxPayload = new uint8_t[m_totalBytes];
220  m_serverRxPayload = new uint8_t[m_totalBytes];
221  for (uint32_t i = 0; i < m_totalBytes; ++i)
222  {
223  auto m = (uint8_t)(97 + (i % 26));
224  m_sourceTxPayload[i] = m;
225  }
226  memset(m_sourceRxPayload, 0, m_totalBytes);
227  memset(m_serverRxPayload, 0, m_totalBytes);
228 
229  if (m_useIpv6)
230  {
232  }
233  else
234  {
235  SetupDefaultSim();
236  }
237 
238  Simulator::Run();
239 
240  NS_TEST_EXPECT_MSG_EQ(m_currentSourceTxBytes, m_totalBytes, "Source sent all bytes");
241  NS_TEST_EXPECT_MSG_EQ(m_currentServerRxBytes, m_totalBytes, "Server received all bytes");
242  NS_TEST_EXPECT_MSG_EQ(m_currentSourceRxBytes, m_totalBytes, "Source received all bytes");
244  0,
245  "Server received expected data buffers");
247  0,
248  "Source received back expected data buffers");
249 }
250 
251 void
253 {
254  delete[] m_sourceTxPayload;
255  delete[] m_sourceRxPayload;
256  delete[] m_serverRxPayload;
257  Simulator::Destroy();
258 }
259 
260 void
262 {
265 }
266 
267 void
269 {
270  while (sock->GetRxAvailable() > 0)
271  {
272  uint32_t toRead = std::min(m_serverReadSize, sock->GetRxAvailable());
273  Ptr<Packet> p = sock->Recv(toRead, 0);
274  if (!p && sock->GetErrno() != Socket::ERROR_NOTERROR)
275  {
276  NS_FATAL_ERROR("Server could not read stream at byte " << m_currentServerRxBytes);
277  }
279  true,
280  "Server received too many bytes");
281  NS_LOG_DEBUG("Server recv data=\"" << GetString(p) << "\"");
284  ServerHandleSend(sock, sock->GetTxAvailable());
285  }
286 }
287 
288 void
290 {
292  {
294  uint32_t toSend = std::min(left, sock->GetTxAvailable());
295  toSend = std::min(toSend, m_serverWriteSize);
296  Ptr<Packet> p = Create<Packet>(&m_serverRxPayload[m_currentServerTxBytes], toSend);
297  NS_LOG_DEBUG("Server send data=\"" << GetString(p) << "\"");
298  int sent = sock->Send(p);
299  NS_TEST_EXPECT_MSG_EQ((sent != -1), true, "Server error during send ?");
300  m_currentServerTxBytes += sent;
301  }
303  {
304  sock->Close();
305  }
306 }
307 
308 void
310 {
311  while (sock->GetTxAvailable() > 0 && m_currentSourceTxBytes < m_totalBytes)
312  {
313  uint32_t left = m_totalBytes - m_currentSourceTxBytes;
314  uint32_t toSend = std::min(left, sock->GetTxAvailable());
315  toSend = std::min(toSend, m_sourceWriteSize);
316  Ptr<Packet> p = Create<Packet>(&m_sourceTxPayload[m_currentSourceTxBytes], toSend);
317  NS_LOG_DEBUG("Source send data=\"" << GetString(p) << "\"");
318  int sent = sock->Send(p);
319  NS_TEST_EXPECT_MSG_EQ((sent != -1), true, "Error during send ?");
320  m_currentSourceTxBytes += sent;
321  }
322 }
323 
324 void
326 {
327  while (sock->GetRxAvailable() > 0 && m_currentSourceRxBytes < m_totalBytes)
328  {
329  uint32_t toRead = std::min(m_sourceReadSize, sock->GetRxAvailable());
330  Ptr<Packet> p = sock->Recv(toRead, 0);
331  if (!p && sock->GetErrno() != Socket::ERROR_NOTERROR)
332  {
333  NS_FATAL_ERROR("Source could not read stream at byte " << m_currentSourceRxBytes);
334  }
336  true,
337  "Source received too many bytes");
338  NS_LOG_DEBUG("Source recv data=\"" << GetString(p) << "\"");
341  }
343  {
344  sock->Close();
345  }
346 }
347 
348 Ptr<Node>
350 {
351  Ptr<Node> node = CreateObject<Node>();
352  // Traffic Control
353  Ptr<TrafficControlLayer> tc = CreateObject<TrafficControlLayer>();
354  node->AggregateObject(tc);
355  // ARP
356  Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol>();
357  node->AggregateObject(arp);
358  arp->SetTrafficControl(tc);
359  // IPV4
360  Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol>();
361  // Routing for Ipv4
362  Ptr<Ipv4ListRouting> ipv4Routing = CreateObject<Ipv4ListRouting>();
363  ipv4->SetRoutingProtocol(ipv4Routing);
364  Ptr<Ipv4StaticRouting> ipv4staticRouting = CreateObject<Ipv4StaticRouting>();
365  ipv4Routing->AddRoutingProtocol(ipv4staticRouting, 0);
366  node->AggregateObject(ipv4);
367  // ICMP
368  Ptr<Icmpv4L4Protocol> icmp = CreateObject<Icmpv4L4Protocol>();
369  node->AggregateObject(icmp);
370  // UDP
371  Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol>();
372  node->AggregateObject(udp);
373  // TCP
374  Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol>();
375  node->AggregateObject(tcp);
376  return node;
377 }
378 
380 TcpTestCase::AddSimpleNetDevice(Ptr<Node> node, const char* ipaddr, const char* netmask)
381 {
382  Ptr<SimpleNetDevice> dev = CreateObject<SimpleNetDevice>();
383  dev->SetAddress(Mac48Address::ConvertFrom(Mac48Address::Allocate()));
384  node->AddDevice(dev);
385  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
386  uint32_t ndid = ipv4->AddInterface(dev);
387  Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress(Ipv4Address(ipaddr), Ipv4Mask(netmask));
388  ipv4->AddAddress(ndid, ipv4Addr);
389  ipv4->SetUp(ndid);
390  return dev;
391 }
392 
393 void
395 {
396  const char* netmask = "255.255.255.0";
397  const char* ipaddr0 = "192.168.1.1";
398  const char* ipaddr1 = "192.168.1.2";
399  Ptr<Node> node0 = CreateInternetNode();
400  Ptr<Node> node1 = CreateInternetNode();
401  Ptr<SimpleNetDevice> dev0 = AddSimpleNetDevice(node0, ipaddr0, netmask);
402  Ptr<SimpleNetDevice> dev1 = AddSimpleNetDevice(node1, ipaddr1, netmask);
403 
404  Ptr<SimpleChannel> channel = CreateObject<SimpleChannel>();
405  dev0->SetChannel(channel);
406  dev1->SetChannel(channel);
407 
408  Ptr<SocketFactory> sockFactory0 = node0->GetObject<TcpSocketFactory>();
409  Ptr<SocketFactory> sockFactory1 = node1->GetObject<TcpSocketFactory>();
410 
411  Ptr<Socket> server = sockFactory0->CreateSocket();
412  Ptr<Socket> source = sockFactory1->CreateSocket();
413 
414  uint16_t port = 50000;
415  InetSocketAddress serverlocaladdr(Ipv4Address::GetAny(), port);
416  InetSocketAddress serverremoteaddr(Ipv4Address(ipaddr0), port);
417 
418  server->Bind(serverlocaladdr);
419  server->Listen();
420  server->SetAcceptCallback(MakeNullCallback<bool, Ptr<Socket>, const Address&>(),
422 
425 
426  Address peerAddress;
427  int err = source->GetPeerName(peerAddress);
428  NS_TEST_EXPECT_MSG_EQ(err, -1, "socket GetPeerName() should fail when socket is not connected");
430  Socket::ERROR_NOTCONN,
431  "socket error code should be ERROR_NOTCONN");
432 
433  err = source->Connect(serverremoteaddr);
434  NS_TEST_EXPECT_MSG_EQ(err, 0, "socket Connect() should succeed");
435 
436  err = source->GetPeerName(peerAddress);
437  NS_TEST_EXPECT_MSG_EQ(err, 0, "socket GetPeerName() should succeed when socket is connected");
438  NS_TEST_EXPECT_MSG_EQ(peerAddress,
439  serverremoteaddr,
440  "address from socket GetPeerName() should equal the connected address");
441 }
442 
443 void
445 {
446  Ipv6Prefix prefix = Ipv6Prefix(64);
447  Ipv6Address ipaddr0 = Ipv6Address("2001:0100:f00d:cafe::1");
448  Ipv6Address ipaddr1 = Ipv6Address("2001:0100:f00d:cafe::2");
449  Ptr<Node> node0 = CreateInternetNode6();
450  Ptr<Node> node1 = CreateInternetNode6();
451  Ptr<SimpleNetDevice> dev0 = AddSimpleNetDevice6(node0, ipaddr0, prefix);
452  Ptr<SimpleNetDevice> dev1 = AddSimpleNetDevice6(node1, ipaddr1, prefix);
453 
454  Ptr<SimpleChannel> channel = CreateObject<SimpleChannel>();
455  dev0->SetChannel(channel);
456  dev1->SetChannel(channel);
457 
458  Ptr<SocketFactory> sockFactory0 = node0->GetObject<TcpSocketFactory>();
459  Ptr<SocketFactory> sockFactory1 = node1->GetObject<TcpSocketFactory>();
460 
461  Ptr<Socket> server = sockFactory0->CreateSocket();
462  Ptr<Socket> source = sockFactory1->CreateSocket();
463 
464  uint16_t port = 50000;
465  Inet6SocketAddress serverlocaladdr(Ipv6Address::GetAny(), port);
466  Inet6SocketAddress serverremoteaddr(ipaddr0, port);
467 
468  server->Bind(serverlocaladdr);
469  server->Listen();
470  server->SetAcceptCallback(MakeNullCallback<bool, Ptr<Socket>, const Address&>(),
472 
475 
476  Address peerAddress;
477  int err = source->GetPeerName(peerAddress);
478  NS_TEST_EXPECT_MSG_EQ(err, -1, "socket GetPeerName() should fail when socket is not connected");
480  Socket::ERROR_NOTCONN,
481  "socket error code should be ERROR_NOTCONN");
482 
483  err = source->Connect(serverremoteaddr);
484  NS_TEST_EXPECT_MSG_EQ(err, 0, "socket Connect() should succeed");
485 
486  err = source->GetPeerName(peerAddress);
487  NS_TEST_EXPECT_MSG_EQ(err, 0, "socket GetPeerName() should succeed when socket is connected");
488  NS_TEST_EXPECT_MSG_EQ(peerAddress,
489  serverremoteaddr,
490  "address from socket GetPeerName() should equal the connected address");
491 }
492 
493 Ptr<Node>
495 {
496  Ptr<Node> node = CreateObject<Node>();
497  // IPV6
498  Ptr<Ipv6L3Protocol> ipv6 = CreateObject<Ipv6L3Protocol>();
499  // Routing for Ipv6
500  Ptr<Ipv6ListRouting> ipv6Routing = CreateObject<Ipv6ListRouting>();
501  ipv6->SetRoutingProtocol(ipv6Routing);
502  Ptr<Ipv6StaticRouting> ipv6staticRouting = CreateObject<Ipv6StaticRouting>();
503  ipv6Routing->AddRoutingProtocol(ipv6staticRouting, 0);
504  node->AggregateObject(ipv6);
505  // ICMP
506  Ptr<Icmpv6L4Protocol> icmp = CreateObject<Icmpv6L4Protocol>();
507  node->AggregateObject(icmp);
508  // Ipv6 Extensions
509  ipv6->RegisterExtensions();
510  ipv6->RegisterOptions();
511  // UDP
512  Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol>();
513  node->AggregateObject(udp);
514  // TCP
515  Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol>();
516  node->AggregateObject(tcp);
517  // Traffic Control
518  Ptr<TrafficControlLayer> tc = CreateObject<TrafficControlLayer>();
519  node->AggregateObject(tc);
520  return node;
521 }
522 
525 {
526  Ptr<SimpleNetDevice> dev = CreateObject<SimpleNetDevice>();
527  dev->SetAddress(Mac48Address::ConvertFrom(Mac48Address::Allocate()));
528  node->AddDevice(dev);
529  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
530  uint32_t ndid = ipv6->AddInterface(dev);
531  Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress(ipaddr, prefix);
532  ipv6->AddAddress(ndid, ipv6Addr);
533  ipv6->SetUp(ndid);
534  return dev;
535 }
536 
542 class TcpTestSuite : public TestSuite
543 {
544  public:
546  : TestSuite("tcp", UNIT)
547  {
548  // Arguments to these test cases are 1) totalStreamSize,
549  // 2) source write size, 3) source read size
550  // 4) server write size, and 5) server read size
551  // with units of bytes
552  AddTestCase(new TcpTestCase(13, 200, 200, 200, 200, false), TestCase::QUICK);
553  AddTestCase(new TcpTestCase(13, 1, 1, 1, 1, false), TestCase::QUICK);
554  AddTestCase(new TcpTestCase(100000, 100, 50, 100, 20, false), TestCase::QUICK);
555 
556  AddTestCase(new TcpTestCase(13, 200, 200, 200, 200, true), TestCase::QUICK);
557  AddTestCase(new TcpTestCase(13, 1, 1, 1, 1, true), TestCase::QUICK);
558  AddTestCase(new TcpTestCase(100000, 100, 50, 100, 20, true), TestCase::QUICK);
559  }
560 };
561 
#define min(a, b)
Definition: 80211b.c:41
TCP Test - send string data from client to server and back.
Definition: tcp-test.cc:59
uint32_t m_serverReadSize
Server data size when receiving.
Definition: tcp-test.cc:153
uint8_t * m_sourceTxPayload
Client Tx payload.
Definition: tcp-test.cc:158
Ptr< SimpleNetDevice > AddSimpleNetDevice(Ptr< Node > node, const char *ipaddr, const char *netmask)
Add a SimpleNetDevice to a node (IPv4 version).
Definition: tcp-test.cc:380
bool m_useIpv6
Use IPv6 instead of IPv4.
Definition: tcp-test.cc:162
void ServerHandleSend(Ptr< Socket > sock, uint32_t available)
Server: Send data.
Definition: tcp-test.cc:289
uint32_t m_currentServerTxBytes
Server Rx bytes.
Definition: tcp-test.cc:157
void DoRun() override
Implementation to actually run this TestCase.
Definition: tcp-test.cc:212
uint32_t m_currentSourceTxBytes
Client Tx bytes.
Definition: tcp-test.cc:154
void ServerHandleRecv(Ptr< Socket > sock)
Server: Receive data.
Definition: tcp-test.cc:268
Ptr< SimpleNetDevice > AddSimpleNetDevice6(Ptr< Node > node, Ipv6Address ipaddr, Ipv6Prefix prefix)
Add a SimpleNetDevice to a node (IPv6 version).
Definition: tcp-test.cc:524
Ptr< Node > CreateInternetNode()
Create a node with the Internet stack (IPv4 version).
Definition: tcp-test.cc:349
Ptr< Node > CreateInternetNode6()
Create a node with the Internet stack (IPv6 version).
Definition: tcp-test.cc:494
void SourceHandleRecv(Ptr< Socket > sock)
Client: Receive data.
Definition: tcp-test.cc:325
void ServerHandleConnectionCreated(Ptr< Socket > s, const Address &addr)
Server: Handle connection created.
Definition: tcp-test.cc:261
TcpTestCase(uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t sourceReadSize, uint32_t serverWriteSize, uint32_t serverReadSize, bool useIpv6)
Constructor.
Definition: tcp-test.cc:189
uint32_t m_currentSourceRxBytes
Client Rx bytes.
Definition: tcp-test.cc:155
uint32_t m_totalBytes
Total stream size (in bytes).
Definition: tcp-test.cc:149
uint32_t m_sourceReadSize
Client data size when receiving.
Definition: tcp-test.cc:151
void SetupDefaultSim6()
Setup the test (IPv6 version).
Definition: tcp-test.cc:444
uint8_t * m_sourceRxPayload
Client Rx payload.
Definition: tcp-test.cc:159
uint32_t m_serverWriteSize
Server data size when sending.
Definition: tcp-test.cc:152
void SourceHandleSend(Ptr< Socket > sock, uint32_t available)
Client: Send data.
Definition: tcp-test.cc:309
void SetupDefaultSim()
Setup the test (IPv4 version).
Definition: tcp-test.cc:394
uint32_t m_currentServerRxBytes
Server Tx bytes.
Definition: tcp-test.cc:156
uint8_t * m_serverRxPayload
Server Rx payload.
Definition: tcp-test.cc:160
uint32_t m_sourceWriteSize
Client data size when sending.
Definition: tcp-test.cc:150
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Definition: tcp-test.cc:252
TCP TestSuite - send string data from client to server and back.
Definition: tcp-test.cc:543
a polymophic address class
Definition: address.h:101
An Inet6 address class.
an Inet address class
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
Describes an IPv6 address.
Definition: ipv6-address.h:49
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
IPv6 address associated with an interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:400
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual Socket::SocketErrno GetErrno() const =0
Get last error number.
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.
Definition: socket.cc:128
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected socket.
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
Definition: socket.cc:121
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:72
virtual int Close()=0
Close a socket.
virtual uint32_t GetTxAvailable() const =0
Returns the number of bytes which can be sent in a single call to Send.
API to create TCP socket instances.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
uint16_t port
Definition: dsdv-manet.cc:44
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:747
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:251
Ptr< SimpleNetDevice > AddSimpleNetDevice(Ptr< Node > node, Ipv4Address v4Addr, Ipv4Mask v4Mask, Ipv6Address v6Addr, Ipv6Prefix v6Prefix)
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...
Definition: callback.h:704
channel
Definition: third.py:88
static TcpTestSuite g_tcpTestSuite
Static variable for test initialization.
Definition: tcp-test.cc:562
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
Definition: tcp-test.cc:166
static std::string GetString(Ptr< Packet > p)
Definition: tcp-test.cc:182