|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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"
35 #include "ns3/inet-socket-address.h"
36 #include "ns3/inet6-socket-address.h"
37 #include "ns3/uinteger.h"
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"
75 uint32_t sourceWriteSize,
76 uint32_t sourceReadSize,
77 uint32_t serverWriteSize,
78 uint32_t serverReadSize,
81 virtual void DoRun (
void);
82 virtual void DoTeardown (
void);
87 void SetupDefaultSim (
void);
91 void SetupDefaultSim6 (
void);
137 void ServerHandleSend (
Ptr<Socket> sock, uint32_t available);
143 void SourceHandleSend (
Ptr<Socket> sock, uint32_t available);
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,
173 std::ostringstream oss;
174 oss << str <<
" total=" << totalStreamSize <<
" sourceWrite=" << sourceWriteSize
175 <<
" sourceRead=" << sourceReadSize <<
" serverRead=" << serverReadSize
176 <<
" serverWrite=" << serverWriteSize <<
" useIpv6=" << useIpv6;
182 std::ostringstream oss;
188 uint32_t sourceWriteSize,
189 uint32_t sourceReadSize,
190 uint32_t serverWriteSize,
191 uint32_t serverReadSize,
193 :
TestCase (
Name (
"Send string data from client to server and back",
200 m_totalBytes (totalStreamSize),
201 m_sourceWriteSize (sourceWriteSize),
202 m_sourceReadSize (sourceReadSize),
203 m_serverWriteSize (serverWriteSize),
204 m_serverReadSize (serverReadSize),
221 uint8_t m = (uint8_t)(97 + (i % 26));
242 "Server received expected data buffers");
244 "Source received back expected data buffers");
252 Simulator::Destroy ();
269 if (p == 0 && sock->
GetErrno () != Socket::ERROR_NOTERROR)
274 "Server received too many bytes");
292 int sent = sock->
Send (p);
312 int sent = sock->
Send (p);
325 if (p == 0 && sock->
GetErrno () != Socket::ERROR_NOTERROR)
330 "Source received too many bytes");
376 dev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
389 const char* netmask =
"255.255.255.0";
390 const char* ipaddr0 =
"192.168.1.1";
391 const char* ipaddr1 =
"192.168.1.2";
407 uint16_t
port = 50000;
411 server->Bind (serverlocaladdr);
424 err = source->
Connect (serverremoteaddr);
429 NS_TEST_EXPECT_MSG_EQ (peerAddress, serverremoteaddr,
"address from socket GetPeerName() should equal the connected address");
453 uint16_t
port = 50000;
457 server->Bind (serverlocaladdr);
470 err = source->
Connect (serverremoteaddr);
475 NS_TEST_EXPECT_MSG_EQ (peerAddress, serverremoteaddr,
"address from socket GetPeerName() should equal the connected address");
512 dev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
IPv6 address associated with an interface.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
virtual void AddRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
TCP TestSuite - send string data from client to server and back.
void ServerHandleSend(Ptr< Socket > sock, uint32_t available)
Server: Send data.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual void RegisterOptions()
Register the IPv6 Options.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
static std::string GetString(Ptr< Packet > p)
uint32_t m_currentServerRxBytes
Server Tx bytes.
virtual void SetUp(uint32_t interface)=0
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
bool m_useIpv6
Use IPv6 instead of IPv4.
uint8_t * m_sourceTxPayload
Client Tx payload.
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
void SourceHandleSend(Ptr< Socket > sock, uint32_t available)
Client: Send data.
API to create TCP socket instances.
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address, bool addOnLinkRoute=true)=0
Add an address on the specified IPv6 interface.
virtual void SetAddress(Address address)
Set the address of this interface.
virtual void RegisterExtensions()
Register the IPv6 Extensions.
Callback< R, Ts... > MakeNullCallback(void)
void SetupDefaultSim(void)
Setup the test (IPv4 version).
void ServerHandleRecv(Ptr< Socket > sock)
Server: Receive data.
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
uint32_t m_currentServerTxBytes
Server Rx bytes.
Access to the IPv4 forwarding table, interfaces, and configuration.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
uint32_t m_serverWriteSize
Server data size when sending.
uint32_t m_serverReadSize
Server data size when receiving.
uint32_t m_currentSourceTxBytes
Client Tx bytes.
a polymophic address class
a class to store IPv4 address information on an interface
uint32_t m_sourceWriteSize
Client data size when sending.
void SourceHandleRecv(Ptr< Socket > sock)
Client: Receive data.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
TcpTestCase(uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t sourceReadSize, uint32_t serverWriteSize, uint32_t serverReadSize, bool useIpv6)
Constructor.
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
virtual void AddRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
virtual int Close(void)=0
Close a socket.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Ptr< SimpleNetDevice > AddSimpleNetDevice6(Ptr< Node > node, Ipv6Address ipaddr, Ipv6Prefix prefix)
Add a SimpleNetDevice to a node (IPv6 version).
virtual uint32_t GetTxAvailable(void) const =0
Returns the number of bytes which can be sent in a single call to Send.
virtual Ptr< Socket > CreateSocket(void)=0
uint32_t m_currentSourceRxBytes
Client Rx bytes.
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...
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected socket.
Ptr< SimpleNetDevice > AddSimpleNetDevice(Ptr< Node > node, Ipv4Address v4Addr, Ipv4Mask v4Mask, Ipv6Address v6Addr, Ipv6Prefix v6Prefix)
Ptr< Node > CreateInternetNode6(void)
Create a node with the Internet stack (IPv6 version).
void ServerHandleConnectionCreated(Ptr< Socket > s, const Address &addr)
Server: Handle connection created.
static TcpTestSuite g_tcpTestSuite
Static variable for test initialization.
Ptr< SimpleNetDevice > AddSimpleNetDevice(Ptr< Node > node, const char *ipaddr, const char *netmask)
Add a SimpleNetDevice to a node (IPv4 version).
virtual enum Socket::SocketErrno GetErrno(void) const =0
Get last error number.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
@ UNIT
This test suite implements a Unit Test.
uint8_t * m_sourceRxPayload
Client Rx payload.
void SetTrafficControl(Ptr< TrafficControlLayer > tc)
Set the TrafficControlLayer.
a class to represent an Ipv4 address mask
Access to the IPv6 forwarding table, interfaces, and configuration.
uint8_t * m_serverRxPayload
Server Rx payload.
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...
void SetupDefaultSim6(void)
Setup the test (IPv6 version).
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
TCP Test - send string data from client to server and back.
Describes an IPv6 prefix.
uint32_t m_totalBytes
Total stream size (in bytes).
Ptr< Node > CreateInternetNode(void)
Create a node with the Internet stack (IPv4 version).
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
uint32_t m_sourceReadSize
Client data size when receiving.