From cacb2cabb078e5fd4e4ba140bc2d596760fedc70 Mon Sep 17 00:00:00 2001 From: Nicola Baldo Date: Wed, 17 Nov 2010 17:12:55 +0100 Subject: [PATCH] fixed bug 1031 --- examples/wireless/wifi-hidden-terminal.cc | 71 ++++++++++++++++++----- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/examples/wireless/wifi-hidden-terminal.cc b/examples/wireless/wifi-hidden-terminal.cc index 873eae94b..68ede5b0d 100644 --- a/examples/wireless/wifi-hidden-terminal.cc +++ b/examples/wireless/wifi-hidden-terminal.cc @@ -68,6 +68,7 @@ void experiment (bool enableCtsRts) // 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 @@ void experiment (bool enableCtsRts) 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 @@ void experiment (bool enableCtsRts) 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 @@ void experiment (bool enableCtsRts) std::map stats = monitor->GetFlowStats (); for (std::map::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