A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bug780-test.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5// OLSR was observed to not converge in simple 3-nodes varying topology.
6// https://www.nsnam.org/bugzilla/show_bug.cgi?id=780
7// tcpdump -r bug780-0-0.pcap -nn -tt icmp | wc
8// should show about 395 packets; there is a ping outage from time
9// 123-127 due to the mobility.
10
11#include "bug780-test.h"
12
13#include "ns3/boolean.h"
14#include "ns3/double.h"
15#include "ns3/icmpv4.h"
16#include "ns3/internet-stack-helper.h"
17#include "ns3/ipv4-address-helper.h"
18#include "ns3/ipv4-interface-container.h"
19#include "ns3/ipv4-list-routing-helper.h"
20#include "ns3/log.h"
21#include "ns3/olsr-helper.h"
22#include "ns3/olsr-routing-protocol.h"
23#include "ns3/rng-seed-manager.h"
24#include "ns3/simple-net-device-helper.h"
25#include "ns3/simple-net-device.h"
26#include "ns3/string.h"
27#include "ns3/test.h"
28#include "ns3/uinteger.h"
29
30namespace ns3
31{
32namespace olsr
33{
34
36 : TestCase("Test OLSR bug 780"),
37 m_time(Seconds(200.0)),
38 m_seq(0),
39 m_recvCount(0)
40{
41}
42
46
47void
49{
53
56
57 NS_TEST_EXPECT_MSG_EQ(m_recvCount, 192, "192 out of 200 ping received.");
58
60}
61
62void
64{
66 c.Create(3);
67
68 // install TCP/IP & OLSR
70 InternetStackHelper internet;
71 internet.SetRoutingHelper(olsr);
72 internet.Install(c);
73 int64_t streamsUsed = olsr.AssignStreams(c, 0);
74 NS_TEST_EXPECT_MSG_EQ(streamsUsed, 3, "Should have assigned 3 streams");
75
76 // create channel & devices
77 SimpleNetDeviceHelper simpleNetHelper;
78 simpleNetHelper.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
79 simpleNetHelper.SetChannelAttribute("Delay", StringValue("2ms"));
80 NetDeviceContainer nd = simpleNetHelper.Install(c);
81
82 Ipv4AddressHelper addressAdhoc;
83 addressAdhoc.SetBase("10.1.1.0", "255.255.255.0");
84 Ipv4InterfaceContainer adhocInterfaces;
85 adhocInterfaces = addressAdhoc.Assign(nd);
86
87 // Blacklist some devices (equivalent to Wireless out of range)
90 Ptr<SimpleChannel> ch = DynamicCast<SimpleChannel>(nd.Get(0)->GetChannel());
91
94
95 // 3. Setup ping
96 m_socket = Socket::CreateSocket(c.Get(0), TypeId::LookupByName("ns3::Ipv4RawSocketFactory"));
97 m_socket->SetAttribute("Protocol", UintegerValue(1)); // icmp
100 m_socket->Bind(src);
101 InetSocketAddress dst = InetSocketAddress(adhocInterfaces.GetAddress(2), 0);
102 m_socket->Connect(dst);
103
104 SendPing();
105}
106
107void
109{
110 if (Simulator::Now() >= m_time)
111 {
112 return;
113 }
114
116 Icmpv4Echo echo;
118 m_seq++;
119 echo.SetIdentifier(0);
120
121 Ptr<Packet> dataPacket = Create<Packet>(56);
122 echo.SetData(dataPacket);
123 p->AddHeader(echo);
124 Icmpv4Header header;
126 header.SetCode(0);
128 {
129 header.EnableChecksum();
130 }
131 p->AddHeader(header);
132 m_socket->Send(p, 0);
134}
135
136void
138{
139 while (m_socket->GetRxAvailable() > 0)
140 {
141 Address from;
142 Ptr<Packet> p = m_socket->RecvFrom(0xffffffff, 0, from);
143
146 NS_ASSERT(realFrom.GetPort() == 1); // protocol should be icmp.
147 Ipv4Header ipv4;
148 p->RemoveHeader(ipv4);
149 NS_ASSERT(ipv4.GetProtocol() == 1); // protocol should be icmp.
150 Icmpv4Header icmp;
151 p->RemoveHeader(icmp);
153 {
154 m_recvCount++;
155 }
156 }
157}
158
159} // namespace olsr
160} // namespace ns3
a polymophic address class
Definition address.h:90
ICMP Echo header.
Definition icmpv4.h:99
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition icmpv4.cc:139
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition icmpv4.cc:153
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition icmpv4.cc:146
Base class for all the ICMP packet headers.
Definition icmpv4.h:32
void SetCode(uint8_t code)
Set ICMP code.
Definition icmpv4.cc:112
void SetType(uint8_t type)
Set ICMP type.
Definition icmpv4.cc:105
void EnableChecksum()
Enables ICMP Checksum calculation.
Definition icmpv4.cc:49
uint8_t GetType() const
Get ICMP type.
Definition icmpv4.cc:119
an Inet address class
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static Ipv4Address GetAny()
Packet header for IPv4.
Definition ipv4-header.h:23
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static bool ChecksumEnabled()
Definition node.cc:267
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Helper class that adds OLSR routing to nodes.
Definition olsr-helper.h:31
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
virtual void BlackList(Ptr< SimpleNetDevice > from, Ptr< SimpleNetDevice > to)
Blocks the communications from a NetDevice to another NetDevice.
build a set of SimpleNetDevice objects
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition socket.cc:117
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:61
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:872
Hold an unsigned integer type.
Definition uinteger.h:34
uint16_t m_recvCount
Received ECHO Reply counter.
Definition bug780-test.h:53
void DoRun() override
Implementation to actually run this TestCase.
const Time m_time
Total simulation time.
Definition bug780-test.h:37
void Receive(Ptr< Socket > socket)
Receive echo reply.
void CreateNodes()
Create & configure test network.
uint16_t m_seq
Sequence number.
Definition bug780-test.h:51
Ptr< Socket > m_socket
Socket.
Definition bug780-test.h:49
void SendPing()
Send one ping.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
Definition olsr.py:1