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/drop-tail-queue.h" 
   30 #include "ns3/config.h" 
   31 #include "ns3/ipv4-static-routing.h" 
   32 #include "ns3/ipv4-list-routing.h" 
   33 #include "ns3/ipv6-static-routing.h" 
   34 #include "ns3/ipv6-list-routing.h" 
   36 #include "ns3/inet-socket-address.h" 
   37 #include "ns3/inet6-socket-address.h" 
   38 #include "ns3/uinteger.h" 
   41 #include "ns3/arp-l3-protocol.h" 
   42 #include "ns3/ipv4-l3-protocol.h" 
   43 #include "ns3/ipv6-l3-protocol.h" 
   44 #include "ns3/icmpv4-l4-protocol.h" 
   45 #include "ns3/icmpv6-l4-protocol.h" 
   46 #include "ns3/udp-l4-protocol.h" 
   47 #include "ns3/tcp-l4-protocol.h" 
   48 #include "ns3/traffic-control-layer.h" 
   60                uint32_t sourceWriteSize,
 
   61                uint32_t sourceReadSize,
 
   62                uint32_t serverWriteSize,
 
   63                uint32_t serverReadSize,
 
   66   virtual void DoRun (
void);
 
   67   virtual void DoTeardown (
void);
 
   68   void SetupDefaultSim (
void);
 
   69   void SetupDefaultSim6 (
void);
 
   77   void ServerHandleSend (
Ptr<Socket> sock, uint32_t available);
 
   78   void SourceHandleSend (
Ptr<Socket> sock, uint32_t available);
 
   97 static std::string 
Name (std::string str, uint32_t totalStreamSize,
 
   98                          uint32_t sourceWriteSize,
 
   99                          uint32_t serverReadSize,
 
  100                          uint32_t serverWriteSize,
 
  101                          uint32_t sourceReadSize,
 
  104   std::ostringstream oss;
 
  105   oss << str << 
" total=" << totalStreamSize << 
" sourceWrite=" << sourceWriteSize
 
  106       << 
" sourceRead=" << sourceReadSize << 
" serverRead=" << serverReadSize
 
  107       << 
" serverWrite=" << serverWriteSize << 
" useIpv6=" << useIpv6;
 
  113   std::ostringstream oss;
 
  119                           uint32_t sourceWriteSize,
 
  120                           uint32_t sourceReadSize,
 
  121                           uint32_t serverWriteSize,
 
  122                           uint32_t serverReadSize,
 
  124   : 
TestCase (
Name (
"Send string data from client to server and back",
 
  131     m_totalBytes (totalStreamSize),
 
  132     m_sourceWriteSize (sourceWriteSize),
 
  133     m_sourceReadSize (sourceReadSize),
 
  134     m_serverWriteSize (serverWriteSize),
 
  135     m_serverReadSize (serverReadSize),
 
  152       uint8_t m = (uint8_t)(97 + (i % 26));
 
  173                          "Server received expected data buffers");
 
  175                          "Source received back expected data buffers");
 
  183   Simulator::Destroy ();
 
  200       if (p == 0 && sock->
GetErrno () != Socket::ERROR_NOTERROR)
 
  205                              "Server received too many bytes");
 
  208       m_currentServerRxBytes += p->GetSize ();
 
  223       int sent = sock->
Send (p);
 
  225       m_currentServerTxBytes += sent;
 
  243       int sent = sock->
Send (p);
 
  245       m_currentSourceTxBytes += sent;
 
  256       if (p == 0 && sock->
GetErrno () != Socket::ERROR_NOTERROR)
 
  261                              "Source received too many bytes");
 
  264       m_currentSourceRxBytes += p->GetSize ();
 
  285   ipv4Routing->AddRoutingProtocol (ipv4staticRouting, 0);
 
  306   dev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
 
  319   const char* netmask = 
"255.255.255.0";
 
  320   const char* ipaddr0 = 
"192.168.1.1";
 
  321   const char* ipaddr1 = 
"192.168.1.2";
 
  337   uint16_t 
port = 50000;
 
  341   server->Bind (serverlocaladdr);
 
  354   err = source->
Connect (serverremoteaddr);
 
  359   NS_TEST_EXPECT_MSG_EQ (peerAddress, serverremoteaddr, 
"address from socket GetPeerName() should equal the connected address");
 
  383   uint16_t 
port = 50000;
 
  387   server->Bind (serverlocaladdr);
 
  400   err = source->
Connect (serverremoteaddr);
 
  405   NS_TEST_EXPECT_MSG_EQ (peerAddress, serverremoteaddr, 
"address from socket GetPeerName() should equal the connected address");
 
  416   ipv6->SetRoutingProtocol (ipv6Routing);
 
  418   ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
 
  424   ipv6->RegisterExtensions ();
 
  425   ipv6->RegisterOptions ();
 
  442   dev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
 
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
 
Ptr< T > GetObject(void) const 
Get a pointer to the requested aggregated Object. 
 
Access to the IPv6 forwarding table, interfaces, and configuration. 
 
uint32_t m_currentServerTxBytes
 
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 
 
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together. 
 
uint32_t m_sourceReadSize
 
uint32_t m_currentServerRxBytes
 
uint8_t * m_serverRxPayload
 
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase. 
 
virtual void DoRun(void)
Implementation to actually run this TestCase. 
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
 
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. 
 
uint32_t GetSize(void) const 
Returns the the size in bytes of the packet (including the zero-filled initial payload). 
 
TcpTestSuite g_tcpTestSuite
 
virtual Ptr< Socket > CreateSocket(void)=0
 
void SourceHandleRecv(Ptr< Socket > sock)
 
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate. 
 
Callback< R > MakeNullCallback(void)
 
This test suite implements a Unit Test. 
 
uint32_t m_serverWriteSize
 
uint32_t m_serverReadSize
 
void SetupDefaultSim(void)
 
virtual enum Socket::SocketErrno GetErrno(void) const =0
Get last error number. 
 
a polymophic address class 
 
TcpTestCase(uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t sourceReadSize, uint32_t serverWriteSize, uint32_t serverReadSize, bool useIpv6)
 
uint8_t * m_sourceTxPayload
 
void SourceHandleSend(Ptr< Socket > sock, uint32_t available)
 
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
 
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite. 
 
virtual void SetUp(uint32_t interface)=0
 
uint32_t m_currentSourceTxBytes
 
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
 
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read. 
 
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...
 
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host. 
 
Access to the IPv4 forwarding table, interfaces, and configuration. 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
uint32_t m_sourceWriteSize
 
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket. 
 
uint8_t * m_sourceRxPayload
 
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added. 
 
Ptr< Node > CreateInternetNode6(void)
 
Ptr< SimpleNetDevice > AddSimpleNetDevice(Ptr< Node > node, const char *ipaddr, const char *netmask)
 
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface. 
 
void ServerHandleRecv(Ptr< Socket > sock)
 
static std::string GetString(Ptr< Packet > p)
 
Describes an IPv6 address. 
 
Ipv4 addresses are stored in host order in this class. 
 
Ptr< SimpleNetDevice > AddSimpleNetDevice6(Ptr< Node > node, Ipv6Address ipaddr, Ipv6Prefix prefix)
 
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node. 
 
a class to store IPv4 address information on an interface 
 
void SetupDefaultSim6(void)
 
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. 
 
Describes an IPv6 prefix. 
 
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
 
void ServerHandleConnectionCreated(Ptr< Socket > s, const Address &addr)
 
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address)=0
Add an address on the specified IPv6 interface. 
 
uint32_t CopyData(uint8_t *buffer, uint32_t size) const 
Copy the packet contents to a byte buffer. 
 
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected socket. 
 
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. 
 
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state. 
 
void ServerHandleSend(Ptr< Socket > sock, uint32_t available)
 
uint32_t m_currentSourceRxBytes
 
Ptr< Node > CreateInternetNode(void)
 
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.