A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bug780-test.cc
Go to the documentation of this file.
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2 as
3 * published by the Free Software Foundation;
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * You should have received a copy of the GNU General Public License
11 * along with this program; if not, write to the Free Software
12 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
13 * USA
14 *
15 */
16
17// OLSR was observed to not converge in simple 3-nodes varying topology.
18// https://www.nsnam.org/bugzilla/show_bug.cgi?id=780
19// tcpdump -r bug780-0-0.pcap -nn -tt icmp | wc
20// should show about 395 packets; there is a ping outage from time
21// 123-127 due to the mobility.
22
23#include "bug780-test.h"
24
25#include "ns3/boolean.h"
26#include "ns3/double.h"
27#include "ns3/icmpv4.h"
28#include "ns3/internet-stack-helper.h"
29#include "ns3/ipv4-address-helper.h"
30#include "ns3/ipv4-interface-container.h"
31#include "ns3/ipv4-list-routing-helper.h"
32#include "ns3/log.h"
33#include "ns3/olsr-helper.h"
34#include "ns3/olsr-routing-protocol.h"
35#include "ns3/rng-seed-manager.h"
36#include "ns3/simple-net-device-helper.h"
37#include "ns3/simple-net-device.h"
38#include "ns3/string.h"
39#include "ns3/test.h"
40#include "ns3/uinteger.h"
41
42namespace ns3
43{
44namespace olsr
45{
46
48 : TestCase("Test OLSR bug 780"),
49 m_time(Seconds(200.0)),
50 m_seq(0),
51 m_recvCount(0)
52{
53}
54
56{
57}
58
59void
61{
65
68
69 NS_TEST_EXPECT_MSG_EQ(m_recvCount, 192, "192 out of 200 ping received.");
70
72}
73
74void
76{
78 c.Create(3);
79
80 // install TCP/IP & OLSR
82 InternetStackHelper internet;
83 internet.SetRoutingHelper(olsr);
84 internet.Install(c);
85 int64_t streamsUsed = olsr.AssignStreams(c, 0);
86 NS_TEST_EXPECT_MSG_EQ(streamsUsed, 3, "Should have assigned 3 streams");
87
88 // create channel & devices
89 SimpleNetDeviceHelper simpleNetHelper;
90 simpleNetHelper.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
91 simpleNetHelper.SetChannelAttribute("Delay", StringValue("2ms"));
92 NetDeviceContainer nd = simpleNetHelper.Install(c);
93
94 Ipv4AddressHelper addressAdhoc;
95 addressAdhoc.SetBase("10.1.1.0", "255.255.255.0");
96 Ipv4InterfaceContainer adhocInterfaces;
97 adhocInterfaces = addressAdhoc.Assign(nd);
98
99 // Blacklist some devices (equivalent to Wireless out of range)
100 Ptr<SimpleNetDevice> nd0 = DynamicCast<SimpleNetDevice>(nd.Get(0));
101 Ptr<SimpleNetDevice> nd2 = DynamicCast<SimpleNetDevice>(nd.Get(2));
102 Ptr<SimpleChannel> ch = DynamicCast<SimpleChannel>(nd.Get(0)->GetChannel());
103
106
107 // 3. Setup ping
108 m_socket = Socket::CreateSocket(c.Get(0), TypeId::LookupByName("ns3::Ipv4RawSocketFactory"));
109 m_socket->SetAttribute("Protocol", UintegerValue(1)); // icmp
112 m_socket->Bind(src);
113 InetSocketAddress dst = InetSocketAddress(adhocInterfaces.GetAddress(2), 0);
114 m_socket->Connect(dst);
115
116 SendPing();
117}
118
119void
121{
122 if (Simulator::Now() >= m_time)
123 {
124 return;
125 }
126
127 Ptr<Packet> p = Create<Packet>();
128 Icmpv4Echo echo;
130 m_seq++;
131 echo.SetIdentifier(0);
132
133 Ptr<Packet> dataPacket = Create<Packet>(56);
134 echo.SetData(dataPacket);
135 p->AddHeader(echo);
136 Icmpv4Header header;
138 header.SetCode(0);
140 {
141 header.EnableChecksum();
142 }
143 p->AddHeader(header);
144 m_socket->Send(p, 0);
146}
147
148void
150{
151 while (m_socket->GetRxAvailable() > 0)
152 {
153 Address from;
154 Ptr<Packet> p = m_socket->RecvFrom(0xffffffff, 0, from);
155
158 NS_ASSERT(realFrom.GetPort() == 1); // protocol should be icmp.
159 Ipv4Header ipv4;
160 p->RemoveHeader(ipv4);
161 NS_ASSERT(ipv4.GetProtocol() == 1); // protocol should be icmp.
162 Icmpv4Header icmp;
163 p->RemoveHeader(icmp);
165 {
166 m_recvCount++;
167 }
168 }
169}
170
171} // namespace olsr
172} // namespace ns3
a polymophic address class
Definition: address.h:101
ICMP Echo header.
Definition: icmpv4.h:110
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition: icmpv4.cc:150
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition: icmpv4.cc:164
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition: icmpv4.cc:157
Base class for all the ICMP packet headers.
Definition: icmpv4.h:43
void SetCode(uint8_t code)
Set ICMP code.
Definition: icmpv4.cc:123
void SetType(uint8_t type)
Set ICMP type.
Definition: icmpv4.cc:116
void EnableChecksum()
Enables ICMP Checksum calculation.
Definition: icmpv4.cc:60
uint8_t GetType() const
Get ICMP type.
Definition: icmpv4.cc:130
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:34
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:278
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:211
Helper class that adds OLSR routing to nodes.
Definition: olsr-helper.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
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: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:72
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1061
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:836
Hold an unsigned integer type.
Definition: uinteger.h:45
uint16_t m_recvCount
Received ECHO Reply counter.
Definition: bug780-test.h:64
void DoRun() override
Implementation to actually run this TestCase.
Definition: bug780-test.cc:60
const Time m_time
Total simulation time.
Definition: bug780-test.h:48
void Receive(Ptr< Socket > socket)
Receive echo reply.
Definition: bug780-test.cc:149
void CreateNodes()
Create & configure test network.
Definition: bug780-test.cc:75
uint16_t m_seq
Sequence number.
Definition: bug780-test.h:62
Ptr< Socket > m_socket
Socket.
Definition: bug780-test.h:60
void SendPing()
Send one ping.
Definition: bug780-test.cc:120
~Bug780Test() override
Definition: bug780-test.cc:55
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:252
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
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:704
Definition: olsr.py:1