Wired to wireless routing (OLSR-HNA)

314 views
Skip to first unread message

HARDY

unread,
Feb 16, 2012, 9:14:08 PM2/16/12
to ns-3-users
Hi all,

I modify olsr-hna.cc example as shown below

// Network Topology:
//
// |------------ OLSR ------------| |---- non-OLSR ----|
// (Rx) D)))) (((( A )))) (((( B -------------------
C (Tx)
// 10.1.1.1 10.1.1.2 10.1.1.3 172.16.1.2
172.16.1.1

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/olsr-routing-protocol.h"
#include "ns3/olsr-helper.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>

NS_LOG_COMPONENT_DEFINE ("OlsrHna");

using namespace ns3;

void ReceivePacket (Ptr<Socket> socket)
{
NS_LOG_UNCOND ("Received one packet!");
}

static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
socket->Send (Create<Packet> (pktSize));
Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount-1, pktInterval);
}
else
{
socket->Close ();
}
}

int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
double rss = -80; // -dBm
uint32_t packetSize = 1000; // bytes
uint32_t numPackets = 1;
double interval = 1.0; // seconds
bool verbose = false;
bool assocMethod1 = false;
bool assocMethod2 = false;

CommandLine cmd;

cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("rss", "received signal strength", rss);
cmd.AddValue ("packetSize", "size of application packet sent",
packetSize);
cmd.AddValue ("numPackets", "number of packets generated",
numPackets);
cmd.AddValue ("interval", "interval (seconds) between packets",
interval);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components",
verbose);
cmd.AddValue ("assocMethod1", "Use SetRoutingTableAssociation ()
method", assocMethod1);
cmd.AddValue ("assocMethod2", "Use AddHostNetworkAssociation ()
method", assocMethod2);

cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);

// disable fragmentation for frames below 2200 bytes
Config::SetDefault
("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue
("2200"));
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault
("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue
("2200"));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault
("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue (phyMode));

NodeContainer olsrNodes;
olsrNodes.Create (3);

NodeContainer csmaNodes;
csmaNodes.Create (1);

// The below set of helpers will help us to put together the wifi
NICs we want
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// This is one parameter that matters when using FixedRssLossModel
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (0) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType
(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);

YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay
("ns3::ConstantSpeedPropagationDelayModel");
// The below FixedRssLossModel will cause the rss to be fixed
regardless
// of the distance between the two stations, and the transmit power
//wifiChannel.AddPropagationLoss
("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel",
"MaxRange", DoubleValue (500));
wifiPhy.SetChannel (wifiChannel.Create ());

// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac,
olsrNodes);

CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate
(5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
NetDeviceContainer csmaDevices = csma.Install (NodeContainer
(csmaNodes.Get (0), olsrNodes.Get (2)));

// Note that with FixedRssLossModel, the positions below are not
// used for received signal strength.
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc =
CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (1.0, 0.0, 0.0));
positionAlloc->Add (Vector (501.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (olsrNodes);

OlsrHelper olsr;

// Specify Node B's csma device as a non-OLSR device.
olsr.ExcludeInterface (olsrNodes.Get (2), 3);

Ipv4StaticRoutingHelper staticRouting;

Ipv4ListRoutingHelper list;
list.Add (staticRouting, 0);
list.Add (olsr, 10);

InternetStackHelper internet_olsr;
internet_olsr.SetRoutingHelper (list); // has effect on the next
Install ()
internet_olsr.Install (olsrNodes);

InternetStackHelper internet_csma;
internet_csma.Install (csmaNodes);

Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
ipv4.Assign (devices);

ipv4.SetBase ("172.16.1.0", "255.255.255.0");
ipv4.Assign (csmaDevices);

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (olsrNodes.Get (0),
tid);
//InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny
(), 80);
//InetSocketAddress local = InetSocketAddress (Ipv4Address
("172.16.1.1"), 80);
InetSocketAddress local = InetSocketAddress (Ipv4Address
("10.1.1.3"), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

Ptr<Socket> source = Socket::CreateSocket (csmaNodes.Get (0), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address
("172.16.1.1"), 80);
//InetSocketAddress remote = InetSocketAddress (Ipv4Address
("10.1.1.3"), 80);
//InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetAny
(), 80);
source->Connect (remote);

// Obtain olsr::RoutingProtocol instance of gateway node
// (namely, node B) and add the required association
Ptr<Ipv4> stack = olsrNodes.Get (2)->GetObject<Ipv4> ();
Ptr<Ipv4RoutingProtocol> rp_Gw = (stack->GetRoutingProtocol ());
Ptr<Ipv4ListRouting> lrp_Gw = DynamicCast<Ipv4ListRouting> (rp_Gw);

Ptr<olsr::RoutingProtocol> olsrrp_Gw;

for (uint32_t i = 0; i < lrp_Gw->GetNRoutingProtocols (); i++)
{
int16_t priority;
Ptr<Ipv4RoutingProtocol> temp = lrp_Gw->GetRoutingProtocol (i,
priority);
if (DynamicCast<olsr::RoutingProtocol> (temp))
{
olsrrp_Gw = DynamicCast<olsr::RoutingProtocol> (temp);
}
}

if (assocMethod1)
{
// Create a special Ipv4StaticRouting instance for
RoutingTableAssociation
// Even the Ipv4StaticRouting instance added to list may be used
Ptr<Ipv4StaticRouting> hnaEntries = Create<Ipv4StaticRouting>
();

// Add the required routes into the Ipv4StaticRouting Protocol
instance
// and have the node generate HNA messages for all these routes
// which are associated with non-OLSR interfaces specified
above.
// hnaEntries->AddNetworkRouteTo (Ipv4Address ("172.16.1.0"),
Ipv4Mask ("255.255.255.0"), Ipv4Address ("10.1.1.2"), uint32_t (3),
uint32_t (0));
hnaEntries->AddNetworkRouteTo (Ipv4Address ("172.16.1.0"),
Ipv4Mask ("255.255.255.0"), uint32_t (3), uint32_t (0));
olsrrp_Gw->SetRoutingTableAssociation (hnaEntries);
}

if (assocMethod2)
{
// Specify the required associations directly.
olsrrp_Gw->AddHostNetworkAssociation (Ipv4Address
("172.16.1.0"), Ipv4Mask ("255.255.255.0"));
}

//Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Tracing
wifiPhy.EnablePcap ("olsr-hna", devices);
csma.EnablePcap ("olsr-hna", csmaDevices, false);
AsciiTraceHelper ascii;
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("olsr-
hna_traffic.tr");
wifiPhy.EnableAsciiAll (stream);
csma.EnableAsciiAll (stream);
internet_olsr.EnableAsciiIpv4All (stream);
internet_csma.EnableAsciiIpv4All (stream);

// Trace routing tables
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>
("olsr-hna_traffic.routes", std::ios::out);
olsr.PrintRoutingTableAllEvery (Seconds (2), routingStream);

// Tracing
wifiPhy.EnablePcap ("olsr-hna", devices);
csma.EnablePcap ("olsr-hna", csmaDevices, false);

Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
Seconds (15.0), &GenerateTraffic,
source, packetSize, numPackets,
interPacketInterval);

Simulator::Stop (Seconds (20.0));
Simulator::Run ();
Simulator::Destroy ();

return 0;
}

this is work from D to C (wireless to wired), but doesn't work from C
to D (wired to wireless),

I don't know what the problem is,

is API setting wrong or something?

Thanks

Lalith Suresh

unread,
Feb 19, 2012, 9:00:57 AM2/19/12
to ns-3-...@googlegroups.com
I didn't go through your simulation file, but OSLR-HNA is only meant to disseminate routing information about the wired network into the wireless network, via an HNA gateway. For routes from the wired network into the wireless one, you'd need to configure static routes on the wired nodes at the very least.
 
Thanks

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Lalith Suresh

HARDY

unread,
Feb 27, 2012, 5:31:08 AM2/27/12
to ns-3-users, suresh...@gmail.com
Hi, Lalith Suresh

Thanks for replying,

I fixed some errors in my code,
although it's transmit packets from wired to wireless successfully,
it's can't transmit packet from wireless(10.1.1.1) to
wired(172.16.1.1) through HNA gateway, i think the problem is HNA
setting.

I try to understand ns3 olsr-hna.cc example, but it seems doesn't not
work either.

any suggestions?

Thanks

On Feb 19, 10:00 pm, Lalith Suresh <suresh.lal...@gmail.com> wrote:

Lalith Suresh

unread,
Feb 28, 2012, 6:16:39 AM2/28/12
to HARDY, ns-3-users
On Mon, Feb 27, 2012 at 11:31 AM, HARDY <tripl...@gmail.com> wrote:
> Hi, Lalith Suresh
>
> Thanks for replying,
>
> I fixed some errors in my code,
> although it's transmit packets from wired to wireless successfully,
> it's can't transmit packet from wireless(10.1.1.1) to
> wired(172.16.1.1) through HNA gateway, i think the problem is HNA
> setting.
>
> I try to understand ns3 olsr-hna.cc example, but it seems doesn't not
> work either.
>

No work around than to debug this closely I guess. Try using NS_LOG on
the Olsr protocol and see at which node RouteInput() or RouteOutput()
fails.

--
Lalith Suresh
www.lalith.in

Reply all
Reply to author
Forward
0 new messages