Help, routing table for mesh device with multi interface

1,205 views
Skip to first unread message

Chen

unread,
Mar 11, 2012, 3:27:31 AM3/11/12
to ns-3-users
Hi,
I'm trying to apply static routing for a mesh network.
I have set the number of interface for mesh device as 3.
I'm using
"ns3::Ipv4StaticRouting Class
void AddHostRouteTo (Ipv4Address dest, Ipv4Address nextHop, uint32_t
interface, uint32_t metric=0)"
to build the routing table.
The problem is, it only works when interface=1.
If I change all the interface=2 or others, the program can be build
but fail during processing.
My program is based on mesh.cc
add a static routing function and change the application into onoff
application.
using visualizer to check the performance.

Any idea about how to build static routing table using different
interface of mesh device?

here is my code
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008,2009 IITP RAS
*
* This program is free software; you can redistribute it and/or
modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*
* Author: Kirill Andreev <and...@iitp.ru>
*
*
* By default this script creates m_xSize * m_ySize square grid
topology with
* IEEE802.11s stack installed at each node with peering management
* and HWMP protocol.
* The side of the square cell is defined by m_step parameter.
* When topology is created, UDP ping is installed to opposite corners
* by diagonals. packet size of the UDP ping and interval between two
* successive packets is configurable.
*
* m_xSize * step
* |<--------->|
* step
* |<--->|
* * --- * --- * <---Ping sink _
* | \ | / | ^
* | \ | / | |
* * --- * --- * m_ySize * step |
* | / | \ | |
* | / | \ | |
* * --- * --- * _
* ^ Ping source
*
* See also MeshTest::Configure to read more about configurable
* parameters.
*/


#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mesh-module.h"
#include "ns3/mobility-module.h"
#include "ns3/mesh-helper.h"
#include "ns3/ipv4-static-routing.h"
#include "ns3/ipv4-static-routing-helper.h"

#include <iostream>
#include <sstream>
#include <fstream>

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
class MeshTest
{
public:
/// Init test
MeshTest ();
/// Configure test from command line arguments
void Configure (int argc, char ** argv);
/// Run test
int Run ();
private:
int m_xSize;
int m_ySize;
double m_step;
double m_randomStart;
double m_totalTime;
double m_packetInterval;
uint16_t m_packetSize;
uint32_t m_nIfaces;
bool m_chan;
bool m_pcap;
std::string m_stack;
std::string m_root;
/// List of network nodes
NodeContainer nodes;
/// List of all mesh point devices
NetDeviceContainer meshDevices;
//Addresses of interfaces:
Ipv4InterfaceContainer interfaces;
// MeshHelper. Report is not static methods
MeshHelper mesh;
private:
/// Create nodes and setup their mobility
void CreateNodes ();
/// Install internet m_stack on nodes
void InstallInternetStack ();
/// Install applications
void InstallApplication ();
/// Print mesh devices diagnostics
void Report ();
void SetStaticRoute(Ptr<Node> n, Ipv4Address destination,Ipv4Address
nextHop, uint32_t interface);
};
MeshTest::MeshTest () :
m_xSize (3),
m_ySize (3),
m_step (100.0),
m_randomStart (0.1),
m_totalTime (100.0),
m_packetInterval (0.1),
m_packetSize (1024),
m_nIfaces (3),
m_chan (true),
m_pcap (false),
m_stack ("ns3::Dot11sStack"),
m_root ("ff:ff:ff:ff:ff:ff")
{
}
void
MeshTest::Configure (int argc, char *argv[])
{
CommandLine cmd;
cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]",
m_xSize);
cmd.AddValue ("y-size", "Number of rows in a grid. [6]", m_ySize);
cmd.AddValue ("step", "Size of edge in our grid, meters. [100 m]",
m_step);
/*
* As soon as starting node means that it sends a beacon,
* simultaneous start is not good.
*/
cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1
s]", m_randomStart);
cmd.AddValue ("time", "Simulation time, seconds [100 s]",
m_totalTime);
cmd.AddValue ("packet-interval", "Interval between packets in UDP
ping, seconds [0.001 s]", m_packetInterval);
cmd.AddValue ("packet-size", "Size of packets in UDP ping",
m_packetSize);
cmd.AddValue ("interfaces", "Number of radio interfaces used by each
mesh point. [1]", m_nIfaces);
cmd.AddValue ("channels", "Use different frequency channels for
different interfaces. [0]", m_chan);
cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]",
m_pcap);
cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by
default", m_stack);
cmd.AddValue ("root", "Mac address of root mesh point in HWMP",
m_root);

cmd.Parse (argc, argv);
NS_LOG_DEBUG ("Grid:" << m_xSize << "*" << m_ySize);
NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s");
}
void
MeshTest::CreateNodes ()
{
/*
* Create m_ySize*m_xSize stations to form a grid topology
*/
nodes.Create (m_ySize*m_xSize);
// Configure YansWifiChannel
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default
();
wifiPhy.SetChannel (wifiChannel.Create ());
/*
* Create mesh helper and set stack installer to it
* Stack installer creates all needed protocols and install them to
* mesh point device
*/
mesh = MeshHelper::Default ();
if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
{
mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue
(Mac48Address (m_root.c_str ())));
}
else
{
//If root is not set, we do not use "Root" attribute, because it
//is specified only for 11s
mesh.SetStackInstaller (m_stack);
}
if (m_chan)
{
mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
}
else
{
mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
}
mesh.SetMacType ("RandomStart", TimeValue (Seconds
(m_randomStart)));
// Set number of interfaces - default is single-interface mesh point
mesh.SetNumberOfInterfaces (m_nIfaces);
// Install protocols and return container if MeshPointDevices
meshDevices = mesh.Install (wifiPhy, nodes);
// Setup mobility - static grid topology
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (m_xSize),
"LayoutType", StringValue
("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
if (m_pcap)
wifiPhy.EnablePcapAll (std::string ("mp-"));
}
void
MeshTest::InstallInternetStack ()
{
InternetStackHelper internetStack;
internetStack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
interfaces = address.Assign (meshDevices);
}
void
MeshTest::SetStaticRoute(Ptr<Node> n, Ipv4Address
destination,Ipv4Address nextHop, uint32_t interface)
{
Ipv4StaticRoutingHelper staticRouting;
Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> a = staticRouting.GetStaticRouting (ipv4);
a->AddHostRouteTo ( destination, nextHop, interface);
}
void
MeshTest::InstallApplication ()
{
OnOffHelper onoff ("ns3::UdpSocketFactory",
Address (InetSocketAddress (interfaces.GetAddress(0), 80)));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable
(1)));
onoff.SetAttribute ("OffTime", RandomVariableValue
(ConstantVariable (0)));
char srate[500];
sprintf (srate,"%fkb/s",10000.0);
onoff.SetAttribute ("DataRate", StringValue (srate));
ApplicationContainer apps = onoff.Install (nodes.Get (1));
apps.Start (MilliSeconds (500+rand()%100));
apps.Stop (Seconds (15.0));
PacketSinkHelper sink ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address::GetAny (), 80)));
apps = sink.Install (nodes.Get (0));
apps.Start (Seconds (0));
apps.Stop (Seconds (15.0));

}
int
MeshTest::Run ()
{
CreateNodes ();
InstallInternetStack ();
InstallApplication ();
SetStaticRoute(nodes.Get(1),nodes.Get(0)->GetObject<Ipv4>()-
>GetAddress(1,0).GetLocal(),nodes.Get(0)->GetObject<Ipv4>()-
>GetAddress(1,0).GetLocal(),1);
Simulator::Stop (Seconds (m_totalTime));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
void
MeshTest::Report ()
{
unsigned n (0);
for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i !=
meshDevices.End (); ++i, ++n)
{
std::ostringstream os;
os << "mp-report-" << n << ".xml";
std::cerr << "Printing mesh point device #" << n << "
diagnostics to " << os.str () << "\n";
std::ofstream of;
of.open (os.str ().c_str ());
if (!of.is_open ())
{
std::cerr << "Error: Can't open file " << os.str () << "\n";
return;
}
mesh.Report (*i, of);
of.close ();
}
}
int
main (int argc, char *argv[])
{Packet::EnablePrinting();
MeshTest t;
t.Configure (argc, argv);
return t.Run ();
}

Simbarashe Dzinamarira

unread,
Jul 18, 2012, 4:52:54 AM7/18/12
to ns-3-...@googlegroups.com
The interface you are specifying is from the interfaces of the node. A meshpoint device is one interface within the nodes. The individual antennas of the mesh routers can be reached by nodes.Get(i)->GetDevice(0)->GetObject<MeshPointDevice> ()->GetInterfaces (); But then these are layer 2 devices. The use of the term "interference" is rather ambiguous. What you see as 3 are the number of antennas inside each meshpoint device. Hope this helps

Craig

unread,
Aug 17, 2012, 11:59:23 AM8/17/12
to ns-3-...@googlegroups.com
Hi Simba

I am new to NS-3 and have been trying to modify this code to emulate a mesh network between two devices... I am very new to coding and I am not sure about the fix you explained... Could you elaborate please? Please find attached code... 

I am able to get the code running etc, I have added routes to both computers (route add 192.168.30.107 MASK 255...etc.) I am able to ping the node that each device is connected to but unable to ping over the meshed network. Thank you for any help in advance
Mesh network.cc

Simba

unread,
Aug 17, 2012, 12:27:35 PM8/17/12
to ns-3-...@googlegroups.com
In network, routing can be at the IP layer using IP address or at the datalink layer using MAC addresses.

1) void AddHostRouteTo (Ipv4Address dest, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0) ;
This line of code does routing with IP addresses.

2) In a mesh network in NS3, a mesh router has only one IP address even though it may have several antennas. The antennas have the same IP but have different MAC addresses. The routing in mesh networks also has to be done using MAC addresses as this link shows.  http://en.wikipedia.org/wiki/Hybrid_Wireless_Mesh_Protocol . I'm not sure if NS3 automatically does the MAC layer routing.

3) On each mesh router, at the IP layer, interfaces 0 is the loopback which points to itself. (eg. 127.0.0.1 on a PC) Interface 1 is that router's IP within the network. Your mesh routers only have these 2 interfaces/IP addresses.

4) The routing which you want to do it not with IP addresses but at the datalink layer with MAC address.

The antennas as this layer are also being referred to as interfaces which is rather confusing but keep the layers in mind will help. I hope this points you in the right direction to solve your problem.

Simba

unread,
Aug 17, 2012, 12:31:17 PM8/17/12
to ns-3-...@googlegroups.com
Craig your code always uses interface 1, which is the one it is supposed to be using.

Craig

unread,
Aug 20, 2012, 7:54:00 AM8/20/12
to ns-3-...@googlegroups.com
Simba

Thank you for taking the time to explain this for me, it is very much appreciated. 

Taking on board what you have said, I noticed that my Pcap files of the wifi nodes all go to interface 1 with exception to the emulated nodes which point to interface 2 according to the file names... Your advice has helped me understand that this is where I am going wrong. Now I will need to work on my C++ skills to help direct it to the correct interface.

Regards

Craig
Reply all
Reply to author
Forward
0 new messages