Problems: Range Propagation Loss Model and Data Rate on ad hoc network

836 views
Skip to first unread message

Ignacio Catrileo

unread,
Nov 5, 2012, 2:19:13 PM11/5/12
to ns-3-...@googlegroups.com
Hi guys, I have 2 problems.

1.- I have an ad hoc network made by 2 nodes, separated 250 [m] from each other, and I'm using RangePropagationLossModel. The thing is no matter which is the value of MaxRange, I always have the same throughput between the nodes. I tried using low values and large values and I tried with other models too. The model is simply not working.

2.- The throughput is giving me more packets that are sent!! I think that is a problem involving link data rate, phyMode or something.

The code is a modification of "matrix-topology.cc" located in the examples folder.

I'm kind of newbie with NS-3, I would really appreciate any hand on this. Thank you very much in advance.

Code:

int main (int argc, char *argv[])

{


  // ---------- Simulation Variables ------------------------------------------


  double SimTime        = 130.0;

  double SinkStartTime  = 30.0;

  double SinkStopTime   = 130.0;

  double AppStartTime   = 30.0;

  double AppStopTime    = 130.0;


  string AppPacketRate ("2Mbps");

  Config::SetDefault  ("ns3::OnOffApplication::PacketSize",StringValue ("1000"));

  Config::SetDefault ("ns3::OnOffApplication::DataRate",  StringValue (AppPacketRate));

  string LinkRate ("11Mbps");

  string LinkDelay ("0ms");

  string phyMode ("ErpOfdmRate12Mbps");


  // ---------- Nodes --------------------------------------------------------


  int n_nodes = 2;

  int sinkNode = n_nodes-1;

  int sourceNode = 0;

  

  NodeContainer nodes;

  nodes.Create (n_nodes);

  

  // ---------- Network Setup ------------------------------------------------


  PointToPointHelper p2p;

  p2p.SetDeviceAttribute ("DataRate", StringValue (LinkRate));

  p2p.SetChannelAttribute ("Delay", StringValue (LinkDelay));

    

  OlsrHelper olsr;

    

  Ipv4ListRoutingHelper list;

  list.Add (olsr, 10);

    

  InternetStackHelper internet;

  internet.SetRoutingHelper (list);

  internet.Install (NodeContainer::GetGlobal ());


  Ipv4AddressHelper ipv4_n;

  ipv4_n.SetBase ("192.168.1.0", "255.255.255.0");


  NodeContainer n_links = NodeContainer (nodes.Get (sourceNode), nodes.Get (sinkNode));

  NetDeviceContainer n_devs = p2p.Install (n_links);

  ipv4_n.Assign (n_devs);

  ipv4_n.NewNetwork ();


  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

    

  // ---------- Wifi setup ---------------------------------------------------

    

    WifiHelper wifi;


    wifi.SetStandard (WIFI_PHY_STANDARD_80211g);

    

    YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();

    wifiPhy.Set ("RxGain", DoubleValue (0) );

    wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);

    

    YansWifiChannelHelper wifiChannel;

    wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");

    wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel"

                                    ,"MaxRange", DoubleValue (50.0)

                                    );

     

    wifiPhy.SetChannel (wifiChannel.Create ());

    

    NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();

    wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",

                                  "DataMode",StringValue (phyMode),

                                  "ControlMode",StringValue (phyMode)

                                  );


    wifiMac.SetType ("ns3::AdhocWifiMac");

    NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, nodes);


  // ---------- Allocate Node Positions --------------------------------------


  MobilityHelper mobility_n;


  Ptr<ListPositionAllocator> positionAlloc_n = CreateObject<ListPositionAllocator> ();

  positionAlloc_n->Add (Vector (0.0, 0.0, 0.0));

  positionAlloc_n->Add (Vector (250.0, 0.0, 0.0));

  mobility_n.SetPositionAllocator (positionAlloc_n);

  

  mobility_n.SetMobilityModel ("ns3::ConstantPositionMobilityModel");


  mobility_n.Install (nodes);


  // ---------- Create CBR Flow -------------------------------------


  uint16_t port = 80;


  PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));

  ApplicationContainer apps_sink = sink.Install (nodes.Get (sinkNode));   // sink is installed on last node

  apps_sink.Start (Seconds (SinkStartTime));

  apps_sink.Stop (Seconds (SinkStopTime));


  Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();

  x->SetAttribute ("Min", DoubleValue (0));

  x->SetAttribute ("Max", DoubleValue (1));

  double rn = x->GetValue ();

                

  Ptr<Node> n = nodes.Get (sinkNode);

  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();

  Ipv4InterfaceAddress ipv4_int_addr = ipv4->GetAddress (1, 0);

  Ipv4Address ip_addr = ipv4_int_addr.GetLocal ();

  OnOffHelper onoff ("ns3::TcpSocketFactory", InetSocketAddress (ip_addr, port)); // traffic flows from node[i] to node[j]

  onoff.SetConstantRate (DataRate (AppPacketRate));

  ApplicationContainer apps = onoff.Install (nodes.Get (sourceNode));  // traffic sources are installed on all nodes

  apps.Start (Seconds (AppStartTime + rn));

  apps.Stop (Seconds (AppStopTime));


  // ---------- Simulation Monitoring ----------------------------------------


  FlowMonitorHelper flow;

  Ptr<FlowMonitor> flow_nodes = flow.InstallAll();

    

  Simulator::Stop (Seconds (SimTime));

  Simulator::Run ();


  flow_nodes->CheckForLostPackets ();

  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flow.GetClassifier ());

  std::map<FlowId, FlowMonitor::FlowStats> stats = flow_nodes->GetFlowStats ();

  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)

  {

        Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);

        std::cout.precision(8);

std::cout << "Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";

std::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";

std::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";

std::cout << "  Throughput: " << i->second.rxBytes * 8.0 / (AppStopTime - AppStartTime) / 1000 << " Kbps\n";

std::cout << "  Rx Segments: " << i->second.rxPackets << "\n";

std::cout << "  Lost packets: " << i->second.lostPackets << "\n";

        std::cout << "  Packet Delivery Fraction: " << (float) i->second.rxBytes / i->second.txBytes * 100 << " %\n";

        std::cout << "  Average End-to-end Delay: " << i->second.delaySum / i->second.rxPackets / 1000 << " us\n";

        

}


    

  Simulator::Destroy ();

  return 0;

}

Jue Jiang

unread,
May 21, 2016, 2:38:54 AM5/21/16
to ns-3-users
From your code, you are actually using p2p device to communicate rather than wifi device.
Add a little code,includes the following, the effect of range propogation loss model can be seen.

1. assign addresses to wifi devce
ipv4_N.Assign(devices)
2.connect to wifi destination
Ipv4Address ip_addr2 = Ipv4Address("192.168.2.2");

  OnOffHelper onoff ("ns3::TcpSocketFactory", InetSocketAddress (ip_addr2, port)); // traffic flows from node[i] to node[j]



在 2012年11月6日星期二 UTC+8上午3:19:13,Nacho Catrileo写道:
Reply all
Reply to author
Forward
0 new messages