fixed bug 1031
authorNicola Baldo <nbaldo@cttc.es>
Wed, 17 Nov 2010 17:12:55 +0100
changeset 6664 ec5336f1f710
parent 6663 44dd167118c4
child 6665 27dab861cb2a
fixed bug 1031
examples/wireless/wifi-hidden-terminal.cc
--- a/examples/wireless/wifi-hidden-terminal.cc	Wed Nov 17 11:03:07 2010 +0300
+++ b/examples/wireless/wifi-hidden-terminal.cc	Wed Nov 17 17:12:55 2010 +0100
@@ -68,6 +68,7 @@
    
   // 5. Install wireless devices
   WifiHelper wifi;
+  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
   wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", 
                                 "DataMode",StringValue ("DsssRate2Mbps"), 
                                 "ControlMode",StringValue ("DsssRate1Mbps"));
@@ -76,7 +77,15 @@
   NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
   wifiMac.SetType ("ns3::AdhocWifiMac"); // use ad-hoc MAC
   NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, nodes);
-  
+
+  // uncomment the following to have athstats output
+  // AthstatsHelper athstats;
+  // athstats.EnableAthstats(enableCtsRts ? "basic-athstats-node" : "rtscts-athstats-node", nodes);
+
+  // uncomment the following to have pcap output
+  //wifiPhy.EnablePcap (enableCtsRts ? "basic-pcap-node" : "rtscts-pcap-node", nodes);
+
+
   // 6. Install TCP/IP stack & assign IP addresses
   InternetStackHelper internet;
   internet.Install (nodes);
@@ -84,17 +93,48 @@
   ipv4.SetBase ("10.0.0.0", "255.0.0.0");
   ipv4.Assign (devices);
   
-  // 7. Install applications: two dense CBR streams  node 0 -> node 1 and node 2 -> node 1 
-  ApplicationContainer apps;
-  OnOffHelper onOffHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ("10.0.0.2"), 9));
-  onOffHelper.SetAttribute ("DataRate", StringValue ("10Mbps"));
+  // 7. Install applications: two CBR streams each saturating the channel 
+  ApplicationContainer cbrApps;
+  uint16_t cbrPort = 12345;
+  OnOffHelper onOffHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ("10.0.0.2"), cbrPort));
   onOffHelper.SetAttribute ("PacketSize", UintegerValue (200));
   onOffHelper.SetAttribute ("OnTime",  RandomVariableValue (ConstantVariable (1)));
   onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-  for (size_t i = 0; i < 3; i += 2)
-    {
-      apps.Add (onOffHelper.Install (nodes.Get (i)));
-    }
+
+  // flow 1:  node 0 -> node 1
+  onOffHelper.SetAttribute ("DataRate", StringValue ("3000000bps"));
+  onOffHelper.SetAttribute ("StartTime", TimeValue (Seconds (1.000000)));
+  cbrApps.Add (onOffHelper.Install (nodes.Get (0))); 
+
+  // flow 2:  node 2 -> node 1
+  // The slightly different start times and data rates are a workround
+  // for Bug 388 and Bug 912
+  // http://www.nsnam.org/bugzilla/show_bug.cgi?id=912
+  // http://www.nsnam.org/bugzilla/show_bug.cgi?id=388
+  onOffHelper.SetAttribute ("DataRate", StringValue ("3001100bps"));
+  onOffHelper.SetAttribute ("StartTime", TimeValue (Seconds (1.001)));
+  cbrApps.Add (onOffHelper.Install (nodes.Get (2))); 
+
+  // we also use separate UDP applications that will send a single
+  // packet before the CBR flows start. 
+  // This is a workround for the lack of perfect ARP, see Bug 187
+  // http://www.nsnam.org/bugzilla/show_bug.cgi?id=187   
+
+  uint16_t  echoPort = 9;
+  UdpEchoClientHelper echoClientHelper (Ipv4Address ("10.0.0.2"), echoPort);
+  echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (0.1)));
+  echoClientHelper.SetAttribute ("PacketSize", UintegerValue (10));
+  ApplicationContainer pingApps;
+  
+  // again using different start times to workaround Bug 388 and Bug 912
+  echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (0.001)));
+  pingApps.Add (echoClientHelper.Install (nodes.Get (0))); 
+  echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (0.006)));
+  pingApps.Add (echoClientHelper.Install (nodes.Get (2)));   
+
+
+
   
   // 8. Install FlowMonitor on all nodes
   FlowMonitorHelper flowmon;
@@ -110,11 +150,14 @@
   std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->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 << "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 / 10.0 / 1024 / 1024  << " Mbps\n";
+      // first 2 FlowIds are for ECHO apps, we don't want to display them
+      if (i->first > 2)
+        {
+          Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
+          std::cout << "Flow " << i->first - 2 << " (" << 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 / 10.0 / 1024 / 1024  << " Mbps\n";
+        }
     }
   
   // 11. Cleanup