Hello,
Thank you for proposing your help.
Before pasting the full script I currently use, I would like to say
that, after a fiew experiements using "V4ping" application, the idea I
mentionned in my previous message (changing routing protocols priority
on gateways) is not convenient.
I believe the problem comes from the fact that gateways take into
account HNA messages sent from other gateways whereas they should not
(because they announce the same network themselves)...
Thank you for investigating this.
********************************
My script:
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/global-routing-module.h"
#include "ns3/ipv4-list-routing-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/ipv4-list-routing.h"
#include "ns3/olsr-helper.h"
#include "ns3/olsr-routing-protocol.h"
#include "ns3/v4ping.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("MeshScenario");
class MeshScenario { // = specification in MeshScenario.h
// Declaration of public constructor and methods
public:
// Init scenario
MeshScenario(); // Constructor
// Other methods
// Configure scenario from command line arguments
void Configure(int argc, char ** argv);
// Run scenario
int Run();
static void PingRttResult(Time rtt);
// Declaration of private attributes
private:
// Grid parameters
int m_xSize;
int m_ySize;
double m_step;
// Node parameters
bool m_pcap;
// OLSR configuration parameters
bool hnaAssocMethod1;
bool hnaAssocMethod2;
//Simulation and application parameters
double m_totalTime;
double m_packetInterval;
uint16_t m_packetSize;
// List of mesh routers
NodeContainer meshRouters;
// List of mesh gateways
NodeContainer meshGateways;
// List of nodes that are part of the Internet
NodeContainer internetNodes;
// List of nodes for Internet link 1
NodeContainer internetLink1Nodes;
// List of nodes for Internet link 2
NodeContainer internetLink2Nodes;
// List of nodes for Internet link 3
NodeContainer internetLink3Nodes;
// List of nodes for Internet link 4
NodeContainer internetLink4Nodes;
// List of all mesh routers devices
NetDeviceContainer meshDevices;
// List of all Internet nodes' devices
NetDeviceContainer internetDevices;
// List of all devices connecting GW1 to the Internet
NetDeviceContainer gateway1InternetLinkDevices;
// List of all devices connecting GW2 to the Internet
NetDeviceContainer gateway2InternetLinkDevices;
// List of all devices connecting GW3 to the Internet
NetDeviceContainer gateway3InternetLinkDevices;
// List of all devices connecting GW4 to the Internet
NetDeviceContainer gateway4InternetLinkDevices;
//IP addresses of wifi interfaces
Ipv4InterfaceContainer wifiInterfaces;
//IP addresses of internet interfaces
Ipv4InterfaceContainer internetInterfaces;
//IP addresses of devices' interfaces that connect GW1 to the
Internet
Ipv4InterfaceContainer gateway1InternetLinkInterfaces;
//IP addresses of devices' interfaces that connect GW2 to the
Internet
Ipv4InterfaceContainer gateway2InternetLinkInterfaces;
//IP addresses of devices' interfaces that connect GW3 to the
Internet
Ipv4InterfaceContainer gateway3InternetLinkInterfaces;
//IP addresses of devices' interfaces that connect GW4 to the
Internet
Ipv4InterfaceContainer gateway4InternetLinkInterfaces;
// WifiHelper and CsmaHelper. Report is not static methods
WifiHelper wifi;
YansWifiPhyHelper wifiPhy;
CsmaHelper internet;
PointToPointHelper p2pGW1;
PointToPointHelper p2pGW2;
PointToPointHelper p2pGW3;
PointToPointHelper p2pGW4;
// Helpers to deal with IP and routing configuration
InternetStackHelper internetStack;
InternetStackHelper olsrStack;
Ipv4StaticRoutingHelper ipv4StaticRoutingHelper;
Ipv4ListRoutingHelper meshRoutersListRoutingHelper;
Ipv4ListRoutingHelper meshGatewaysListRoutingHelper;
OlsrHelper meshRoutersOlsrHelper;
OlsrHelper meshGatewaysOlsrHelper;
// Declaration of private methods
private:
// Create nodes, channels and configures mobility
void CreateTopology();
// Called by CreateTopology()
void CreateMeshNodesAndGateways();
void CreateInternetNodes();
void LinkGatewaysToInternet();
// Install internet stack on nodes
void InstallInternetStacks();
// Configures routing on nodes
void ConfigureRouting();
// Creates a default static route for the specified node,
// using the specified next hop and output interface.
void CreateDefaultRoute(Ptr<Node> node, char const *address,
uint32_t interface);
// Install applications
void InstallApplication();
void InstallUdpEcho();
void InstallPing();
// Enable captures for some nodes
void EnablePcapCaptures();
// Print mesh devices diagnostics
void Report();
}; // End of MeshScenario.h specification.
MeshScenario::MeshScenario() {
m_xSize = 4;
m_ySize = 4;
m_step = 100.0;
hnaAssocMethod1 = false;
hnaAssocMethod2 = false;
m_pcap = true;
m_totalTime = 50.0;
m_packetInterval = 2.0;
m_packetSize = 1024;
}
void MeshScenario::CreateTopology() {
CreateMeshNodesAndGateways();
CreateInternetNodes();
LinkGatewaysToInternet();
}
void MeshScenario::CreateMeshNodesAndGateways() {
int nbMeshNodes = m_ySize*m_xSize;
NS_LOG_INFO("Creating " << nbMeshNodes << " mesh nodes (including
gateways)");
// Create m_ySize*m_xSize stations to form a grid topology
meshRouters.Create(m_ySize*m_xSize);
// Add gateways to the gateway nodes container
meshGateways.Add(meshRouters.Get(0));
meshGateways.Add(meshRouters.Get(m_xSize - 1));
meshGateways.Add(meshRouters.Get(nbMeshNodes - m_xSize) );
meshGateways.Add(meshRouters.Get(nbMeshNodes - 1));
// Configure YansWifiChannel (802.11a)
NS_LOG_INFO ("Creating WifiChannel.");
// PHY layer
wifiPhy = YansWifiPhyHelper::Default();
// Creates a WifiChannel with a propagation delay equal to a
constant,
// the speed of light, and a propagation loss based on a log distance
model
// with a reference loss of 46.6777 dB at reference distance of 1m.
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
// Associates the physical medium and the channel
wifiPhy.SetChannel (wifiChannel.Create());
// MAC layer
// WifiHelper helps to create WifiNetDevices with the same
configuration parameters.
// The default state is defined as being an Adhoc MAC layer with an
ARF rate control algorithm
// and both objects using their default attribute values. By default,
configure MAC and PHY for 802.11a.
wifi = WifiHelper::Default();
// Changes the control rate from ARF to AARF.
// wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
// Creates a Wifi MAC layer without QoS (default type = AdHocMac)
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default();
// Configures SSID and sets it and other parameters to the type of
MAC
Ssid ssid = Ssid("meshScenario");
wifiMac.SetType("ns3::AdhocWifiMac",
"Ssid", SsidValue(ssid)//,
/*"ActiveProbing", BooleanValue(false)*/);
// Install devices in mesh nodes
NS_LOG_INFO ("Installing devices in Mesh Routers");
meshDevices = wifi.Install(wifiPhy, wifiMac, meshRouters);
NS_LOG_INFO ("Setting ConstantPositionMobilityModel to mesh
routers");
// 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(meshRouters);
}
void MeshScenario::CreateInternetNodes() {
int nbInternetNodes = 2;
NS_LOG_INFO ("Creating " << nbInternetNodes << " Internet nodes");
internetNodes.Create(nbInternetNodes);
NS_LOG_INFO ("Creating CsmaChannel for the Internet");
internet.SetChannelAttribute ("DataRate", StringValue ("10Mbps"));
internet.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(10)));
NS_LOG_INFO ("Installing devices in Internet nodes");
internetDevices = internet.Install(internetNodes);
}
void MeshScenario::LinkGatewaysToInternet() {
NS_LOG_INFO("Adding nodes to the node container of their respective
internet link");
internetLink1Nodes.Add(meshGateways.Get(0));
internetLink1Nodes.Add(internetNodes.Get(0));
internetLink2Nodes.Add(meshGateways.Get(1));
internetLink2Nodes.Add(internetNodes.Get(0));
internetLink3Nodes.Add(meshGateways.Get(2));
internetLink3Nodes.Add(internetNodes.Get(0));
internetLink4Nodes.Add(meshGateways.Get(3));
internetLink4Nodes.Add(internetNodes.Get(0));
NS_LOG_INFO ("Creating P2P connection and installing devices between
gateways and the Internet");
p2pGW1.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2pGW1.SetChannelAttribute("Delay", StringValue("2ms"));
gateway1InternetLinkDevices = p2pGW1.Install(internetLink1Nodes);
p2pGW2.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2pGW2.SetChannelAttribute("Delay", StringValue("2ms"));
gateway2InternetLinkDevices = p2pGW2.Install(internetLink2Nodes);
p2pGW3.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2pGW3.SetChannelAttribute("Delay", StringValue("2ms"));
gateway3InternetLinkDevices = p2pGW3.Install(internetLink3Nodes);
p2pGW4.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2pGW4.SetChannelAttribute("Delay", StringValue("2ms"));
gateway4InternetLinkDevices = p2pGW4.Install(internetLink4Nodes);
}
void MeshScenario::InstallInternetStacks() {
// Install standard Internet stack on Internet nodes
NS_LOG_INFO("Installing standard Internet stack on Internet nodes");
internetStack.Install(internetNodes);
// internetStack.Install(meshRouters);
meshGatewaysListRoutingHelper.Add(ipv4StaticRoutingHelper, 1);
meshGatewaysListRoutingHelper.Add(meshGatewaysOlsrHelper, 0);
void MeshScenario::ConfigureRouting() {
// The following instruction does not work with wireless networks.
// Explanations can be found here:
http://www.nsnam.org/doxygen/group__globalrouting.html
// Ipv4GlobalRoutingHelper::PopulateRoutingTables();
// Add a default route on the destination node
Ptr<Node> dest = internetNodes.Get(1);
// The index of the outbound interface (last parameter) for this
route
// is 1 (first created interface after loopback, whose index is 0)
CreateDefaultRoute(dest, "10.0.0.1", 1);
// Add a default route on each gateway
//GW1
Ptr<Node> gw1 = meshGateways.Get(0);
CreateDefaultRoute(gw1, "172.16.1.2", 2);
//GW2
Ptr<Node> gw2 = meshGateways.Get(1);
CreateDefaultRoute(gw2, "172.16.2.2", 2);
//GW3
Ptr<Node> gw3 = meshGateways.Get(2);
CreateDefaultRoute(gw3, "172.16.3.2", 2);
//GW4
Ptr<Node> gw4 = meshGateways.Get(3);
CreateDefaultRoute(gw4, "172.16.4.2", 2);
// On each gateway, configure OLSR to announce a default route
// via HNA (Host and Network Association) messages
int nbMeshGateways = meshGateways.GetN();
for (int i=0; i<nbMeshGateways; i++) {
// //Single GW announces HNA messages
Ipv4Mask::GetZero(), uint32_t(2), uint32_t(1));
// Ptr<OutputStreamWrapper> hnaStaticRoutes =
Create<OutputStreamWrapper>("hna.routes", std::ios::out);
// hnaEntries->PrintRoutingTable(hnaStaticRoutes);
NS_LOG_INFO("Associating the created routing table to OLSR for HNA
announcements");
olsr->SetRoutingTableAssociation(hnaEntries);
// // Associating the existing static routing table has the same
effect...
//// Ptr<OutputStreamWrapper> hnaStaticRoutes =
Create<OutputStreamWrapper>("hna.routes", std::ios::out);
//// staticRouting->PrintRoutingTable(hnaStaticRoutes);
// NS_LOG_INFO("Associating static routing table to OLSR for HNA
announcements");
// olsr->SetRoutingTableAssociation(staticRouting);
}
else if (hnaAssocMethod2) {
// Specify the association to announce
NS_LOG_INFO("Associating a default route to OLSR for HNA
announcements");
olsr->AddHostNetworkAssociation(Ipv4Address("0.0.0.0"),
Ipv4Mask::GetZero());
}
else NS_LOG_INFO("No HNA association method defined");
}
//TODO NAT on each GW
// En attendant, route statique (0.0.0.0 vers GW1) sur point d'entrée
Internet.
Ptr<Node> net = internetNodes.Get(0);
// The index of the outbound interface (last parameter) for this
route
// is 2 (first p2p link, 1 being the index of the csma device's
address)
CreateDefaultRoute(net, "172.16.1.1", 2);
// Trace routing tables
Ipv4GlobalRoutingHelper g;
Ptr<OutputStreamWrapper> routingStream1 =
Create<OutputStreamWrapper>("routing_1.routes", std::ios::out);
g.PrintRoutingTableAllAt(Seconds(7), routingStream1);
Ptr<OutputStreamWrapper> routingStream2 =
Create<OutputStreamWrapper>("routing_2.routes", std::ios::out);
g.PrintRoutingTableAllAt(Seconds(30), routingStream2);
}
void MeshScenario::CreateDefaultRoute(Ptr<Node> node, char const
*nextHop, uint32_t interface) {
// Get the IP stack
Ptr<Ipv4> ipStack = node->GetObject<Ipv4>();
// Get the static routing elements in this stack
Ptr<Ipv4StaticRouting> staticRouting =
ipv4StaticRoutingHelper.GetStaticRouting(ipStack);
// Configure the default route entry
staticRouting->SetDefaultRoute(Ipv4Address(nextHop), interface, 0);
}
void MeshScenario::InstallApplication() {
InstallPing();
// InstallUdpEcho();
}
void MeshScenario::InstallPing() {
NS_LOG_INFO ("Install \"V4Ping\" Application");
V4PingHelper pingHelper =
V4PingHelper(internetInterfaces.GetAddress(1));
// V4PingHelper pingHelper =
V4PingHelper(wifiInterfaces.GetAddress(12));
pingHelper.SetAttribute("Verbose", BooleanValue(true));
ApplicationContainer appContainer =
pingHelper.Install(meshRouters.Get(1));
Ptr<V4Ping> app = DynamicCast<V4Ping>(appContainer.Get(0));
// Hook a trace to print RTT when the response comes back
app->TraceConnectWithoutContext("Rtt",
MakeCallback(&MeshScenario::PingRttResult));
}
void MeshScenario::PingRttResult(Time rtt) {
NS_LOG_UNCOND("RTT = " << rtt);
}
void MeshScenario::InstallUdpEcho() {
UdpEchoServerHelper echoServer(9);
// ApplicationContainer serverApps =
echoServer.Install(meshRouters.Get(1));
ApplicationContainer serverApps =
echoServer.Install(internetNodes.Get(1));
serverApps.Start (Seconds (31.0));
serverApps.Stop (Seconds (m_totalTime));
// UdpEchoClientHelper echoClient(wifiInterfaces.GetAddress(1), 9);
UdpEchoClientHelper echoClient(internetInterfaces.GetAddress(1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)
(m_totalTime*(1/m_packetInterval))));
echoClient.SetAttribute ("Interval", TimeValue (Seconds
(m_packetInterval)));
echoClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
// ApplicationContainer clientApps =
echoClient.Install(internetNodes.Get(1));
ApplicationContainer clientApps =
echoClient.Install(meshRouters.Get(1));
clientApps.Start (Seconds (31.0));
clientApps.Stop (Seconds (m_totalTime));
}
void MeshScenario::EnablePcapCaptures() {
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(0), false);
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(1), false);
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(2), false);
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(3), false);
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(5), false);
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(6), false);
wifiPhy.EnablePcap("pcapMesh", meshDevices.Get(10), false);
p2pGW1.EnablePcap("pcapP2P", gateway1InternetLinkDevices.Get(0),
false);
internet.EnablePcap("pcapInternet",internetDevices.Get(0), false);
internet.EnablePcap("pcapInternet",internetDevices.Get(1), false);
}
void MeshScenario::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;
// }
// wifi.Report (*i, of);
// of.close ();
// }
}
void MeshScenario::Configure(int argc, char *argv[]) {
CommandLine cmd;
cmd.AddValue("x-size", "Number of nodes in a row grid. [4]",
m_xSize);
cmd.AddValue("y-size", "Number of rows in a grid. [4]", m_ySize);
cmd.AddValue("step", "Size of edge in our grid, in meters. [100
m]", m_step);
cmd.AddValue ("hnaAssocMethod1", "Use SetRoutingTableAssociation ()
method", hnaAssocMethod1);
cmd.AddValue ("hnaAssocMethod2", "Use AddHostNetworkAssociation ()
method", hnaAssocMethod2);
cmd.AddValue("pcap", "Enable PCAP traces on interfaces. [0]",
m_pcap);
cmd.AddValue("time", "Simulation time, in seconds [100 s]",
m_totalTime);
cmd.AddValue("packet-interval", "Interval between packets in UDP
ping, in seconds [0.001 s]", m_packetInterval);
cmd.AddValue("packet-size", "Size of packets in UDP ping",
m_packetSize);
cmd.Parse(argc, argv);
NS_LOG_DEBUG("Grid:" << m_xSize << "*" << m_ySize);
NS_LOG_DEBUG("Simulation time: " << m_totalTime << " s");
LogComponentEnable("MeshScenario", LOG_INFO);
// LogComponentEnable("OlsrRoutingProtocol", LOG_DEBUG);
LogComponentEnable("UdpEchoClientApplication", LOG_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_INFO);
}
int MeshScenario::Run() {
CreateTopology();
InstallInternetStacks();
ConfigureRouting();
InstallApplication();
if (m_pcap) EnablePcapCaptures();
Simulator::Schedule(Seconds(m_totalTime), & MeshScenario::Report,
this);
Simulator::Stop(Seconds (m_totalTime));
Simulator::Run();
Simulator::Destroy();
return 0;
}
int main(int argc, char *argv[]) {
MeshScenario t;
t.Configure(argc, argv);
return t.Run();
}
********************************
On 30 jan, 12:38, Lalith Suresh <
suresh.lal...@gmail.com> wrote:
> Hello,
>
> Can you attach the full script so that I can investigate this?
>
> --
> Lalith Suresh
> Department of Computer Science and Engineering
> *Instituto Superior Técnico*
www.lalith.in