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