22 #include "ns3/abort.h"
24 #include "ns3/pcap-file.h"
25 #include "ns3/config.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/inet-socket-address.h"
29 #include "ns3/point-to-point-helper.h"
30 #include "ns3/internet-stack-helper.h"
31 #include "ns3/ipv4-address-helper.h"
32 #include "ns3/ipv4-header.h"
33 #include "ns3/packet-sink-helper.h"
34 #include "ns3/on-off-helper.h"
35 #include "ns3/simulator.h"
41 const bool WRITE_VECTORS =
false;
42 const uint32_t PCAP_LINK_TYPE = 1187373553;
43 const uint32_t PCAP_SNAPLEN = 64;
88 virtual void DoSetup (
void);
89 virtual void DoRun (
void);
90 virtual void DoTeardown (
void);
94 std::string m_pcapFilename;
99 Ns3TcpInteroperabilityTestCase::Ns3TcpInteroperabilityTestCase ()
100 :
TestCase (
"Check to see that the ns-3 TCP can work with liblinux2.6.26.so"), m_writeVectors (WRITE_VECTORS)
104 Ns3TcpInteroperabilityTestCase::~Ns3TcpInteroperabilityTestCase ()
115 m_pcapFilename =
static_cast<std::string
> (NS_TEST_SOURCEDIR) +
116 static_cast<std::string> (
"/response-vectors/ns3tcp-interop-response-vectors.pcap");
120 m_pcapFile.
Open (m_pcapFilename, std::ios::out|std::ios::binary);
121 m_pcapFile.
Init (PCAP_LINK_TYPE, PCAP_SNAPLEN);
125 m_pcapFile.
Open (m_pcapFilename, std::ios::in|std::ios::binary);
126 NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE,
"Wrong response vectors in directory");
157 Time tNow = Simulator::Now ();
161 uint8_t *buf =
new uint8_t[size];
164 m_pcapFile.
Write (uint32_t (tMicroSeconds / 1000000),
165 uint32_t (tMicroSeconds % 1000000),
176 uint8_t expected[PCAP_SNAPLEN];
177 uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
178 m_pcapFile.
Read (expected,
sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
180 uint8_t *actual =
new uint8_t[readLen];
183 uint32_t result = memcmp (actual, expected, readLen);
192 NS_TEST_EXPECT_MSG_EQ (result, 0,
"Expected data comparison error");
222 devices = pointToPoint.
Install (nodes);
235 std::string nscStack =
"liblinux2.6.26.so";
236 stack.
SetTcp (
"ns3::NscTcpL4Protocol",
"Library",
StringValue (
"liblinux2.6.26.so"));
244 address.
SetBase (
"10.1.1.0",
"255.255.255.252");
251 uint16_t sinkPort = 8080;
263 OnOffHelper onOffHelper (
"ns3::TcpSocketFactory", sinkAddress);
278 Config::Connect (
"/NodeList/0/$ns3::Ipv4L3Protocol/Tx",
279 MakeCallback (&Ns3TcpInteroperabilityTestCase::Ipv4L3Tx,
this));
300 Simulator::Stop (
Seconds (20));
302 Simulator::Destroy ();
311 Ns3TcpInteroperabilityTestSuite::Ns3TcpInteroperabilityTestSuite ()
312 :
TestSuite (
"ns3-tcp-interoperability", SYSTEM)
virtual void DoRun(void)
Implementation to actually run this test case.
uint32_t RemoveHeader(Header &header)
holds a vector of ns3::Application pointers.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
hold variables of type string
NetDeviceContainer Install(NodeContainer c)
#define NS_LOG_COMPONENT_DEFINE(name)
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetSize(void) const
virtual void DoSetup(void)
Implementation to do any local setup required for this test case.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
a polymophic address class
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
int64_t GetMicroSeconds(void) const
void Read(uint8_t *const data, uint32_t maxBytes, uint32_t &tsSec, uint32_t &tsUsec, uint32_t &inclLen, uint32_t &origLen, uint32_t &readLen)
Read next packet from file.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Ptr< Packet > Copy(void) const
keep track of a set of node pointers.
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter.
void Install(std::string nodeName) const
void Init(uint32_t dataLinkType, uint32_t snapLen=SNAPLEN_DEFAULT, int32_t timeZoneCorrection=ZONE_DEFAULT, bool swapMode=false)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
bool IsStatusSuccess(void) const
void Open(std::string const &filename, std::ios::openmode mode)
void SetChannelAttribute(std::string name, const AttributeValue &value)
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
virtual void DoTeardown(void)
Implementation to do any local setup required for this test case.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
ApplicationContainer Install(NodeContainer c) const
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Write(uint32_t tsSec, uint32_t tsUsec, uint8_t const *const data, uint32_t totalLen)
Write next packet to file.
ApplicationContainer Install(NodeContainer c) const
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const