1.1 --- a/examples/multi-rate-first.cc Mon Aug 24 19:03:58 2009 -0700
1.2 +++ b/examples/multi-rate-first.cc Mon Aug 24 19:11:41 2009 -0700
1.3 @@ -1,10 +1,16 @@
1.4 /**
1.5 *
1.6 * Instructions:
1.7 - * ./waf --run multi-rate-first > m.data
1.8 - * gnuplot m.data
1.9 - * eog *.png
1.10 + * ./waf --run multi-rate-first
1.11 + * gnuplot multi-rate-first-scen*.plt
1.12 *
1.13 + * Output:
1.14 + * multi-rate-first-scen1.eps
1.15 + * multi-rate-first-scen2.eps
1.16 + * multi-rate-first-scen3.eps
1.17 + * multi-rate-first-scen4.eps
1.18 + *
1.19 + * Side Note: It may take some time.
1.20 */
1.21
1.22 #include "ns3/core-module.h"
1.23 @@ -15,6 +21,7 @@
1.24 #include "ns3/contrib-module.h"
1.25
1.26 #include <iostream>
1.27 +#include <fstream>
1.28
1.29 NS_LOG_COMPONENT_DEFINE ("Main");
1.30
1.31 @@ -34,6 +41,7 @@
1.32 void AdvancePosition (Ptr<Node> node);
1.33 void BackTrackPosition (Ptr<Node> node);
1.34 void StationaryPosition (Ptr<Node> node);
1.35 + void MultiPosition (Ptr<Node> node1, Ptr<Node> node2);
1.36 Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
1.37
1.38 uint32_t m_bytesTotal;
1.39 @@ -108,6 +116,26 @@
1.40 m_output.Add ((Simulator::Now()).GetSeconds(), mbs);
1.41
1.42 }
1.43 +void
1.44 +Experiment::MultiPosition (Ptr<Node> n1, Ptr<Node> n2)
1.45 +{
1.46 + Vector pos1 = GetPosition(n1);
1.47 + Vector pos2 = GetPosition(n2);
1.48 + double mbs = ((m_bytesTotal * 8.0) / 1000000);
1.49 + m_bytesTotal = 0;
1.50 + m_output.Add ((Simulator::Now()).GetSeconds(), mbs);
1.51 +
1.52 + if( pos1.x < 230)
1.53 + {
1.54 + pos1.x += 1.0;
1.55 + SetPosition (n1, pos1);
1.56 + }
1.57 + if( pos2.x > 0)
1.58 + {
1.59 + pos2.x -= 1.0;
1.60 + SetPosition (n2, pos2);
1.61 + }
1.62 +}
1.63
1.64 void
1.65 Experiment::ReceivePacket (Ptr<Socket> socket)
1.66 @@ -169,21 +197,30 @@
1.67
1.68 Ptr<Socket> recvSink = SetupPacketReceive (c.Get (1));
1.69
1.70 - if(positionStep == 1)
1.71 + if (positionStep == 1)
1.72 {
1.73 Simulator::Schedule (Seconds (1.5), &Experiment::AdvancePosition, this, c.Get (1));
1.74 }
1.75 - else if(positionStep == -1)
1.76 + else if (positionStep == -1)
1.77 {
1.78 Simulator::Schedule (Seconds (1.5), &Experiment::BackTrackPosition, this, c.Get (1));
1.79 }
1.80 - else if(positionStep == 0)
1.81 + else if (positionStep == 0)
1.82 {
1.83 for(int i = 1; i <= 210; i++)
1.84 {
1.85 Simulator::Schedule (Seconds (i), &Experiment::StationaryPosition, this, c.Get (1));
1.86 }
1.87 }
1.88 + else if (positionStep == 2)
1.89 + {
1.90 + for(int i = 1; i <= 210; i++)
1.91 + {
1.92 + Simulator::Schedule (Seconds (i), &Experiment::MultiPosition, this, c.Get(0), c.Get (1));
1.93 + }
1.94 + }
1.95 +
1.96 +
1.97 Simulator::Run ();
1.98 Simulator::Destroy ();
1.99
1.100 @@ -192,6 +229,11 @@
1.101
1.102 int main (int argc, char *argv[])
1.103 {
1.104 + std::ofstream outfile ("multi-rate-first-scen1.plt");
1.105 + std::ofstream outfile2 ("multi-rate-first-scen2.plt");
1.106 + std::ofstream outfile3 ("multi-rate-first-scen3.plt");
1.107 + std::ofstream outfile4 ("multi-rate-first-scen4.plt");
1.108 +
1.109 // disable fragmentation
1.110 Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
1.111 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
1.112 @@ -199,119 +241,158 @@
1.113 CommandLine cmd;
1.114 cmd.Parse (argc, argv);
1.115
1.116 - Gnuplot gnuplot = Gnuplot ("multi-rate-first.png");
1.117 +
1.118 + MobilityHelper mobility;
1.119 Experiment experiment;
1.120 + Gnuplot gnuplot;
1.121 + int myPositionStep;
1.122 + Ptr<ListPositionAllocator> positionAlloc;
1.123 + Gnuplot2dDataset dataset;
1.124 WifiHelper wifi = WifiHelper::Default ();
1.125 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
1.126 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
1.127 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
1.128 - Gnuplot2dDataset dataset;
1.129 - int myPositionStep = 0;
1.130
1.131 -/*
1.132 + // Scenario 1: two nodes within transmission range about 5 meters apart
1.133 + // Fix a node stationary, move the second node away from it
1.134
1.135 - // Scenario 1: moving away from one another
1.136 - // Initially set them 5 meters apart
1.137 - // Set positionStep parameter of Experiment::Run to 1
1.138 - // Set RateErrorModel of Experiment::Run to 0
1.139 + // moving forward
1.140 myPositionStep = 1;
1.141
1.142 - MobilityHelper mobility;
1.143 - Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1.144 + gnuplot = Gnuplot ("multi-rate-first-scen1.eps");
1.145 +
1.146 + positionAlloc = CreateObject<ListPositionAllocator> ();
1.147 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1.148 positionAlloc->Add (Vector (5.0, 0.0, 0.0));
1.149 mobility.SetPositionAllocator (positionAlloc);
1.150 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1.151
1.152 wifiMac.SetType ("ns3::AdhocWifiMac");
1.153 -
1.154 - gnuplot = Gnuplot ("multi-rate-first.png");
1.155 wifi.SetStandard (WIFI_PHY_STANDARD_holland);
1.156
1.157 - NS_LOG_DEBUG ("minstrel");
1.158 experiment = Experiment ("minstrel");
1.159 wifi.SetRemoteStationManager ("ns3::MinstrelWifiManager");
1.160 dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.161 gnuplot.AddDataset (dataset);
1.162
1.163 - NS_LOG_DEBUG ("ideal");
1.164 experiment = Experiment ("ideal");
1.165 wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1.166 dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.167 gnuplot.AddDataset (dataset);
1.168
1.169 - gnuplot.GenerateOutput (std::cout);
1.170 - */
1.171 + gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
1.172 + gnuplot.SetLegend ("Time (Seconds)", "Throughput(Mbps)");
1.173 + gnuplot.SetExtra ("set xrange [0:250]");
1.174 + gnuplot.SetTitle ("Throughput vs Time");
1.175 + gnuplot.GenerateOutput (outfile);
1.176 + outfile.close ();
1.177
1.178
1.179 - // Scenario 2: two nodes out of range, moving into transmission range range
1.180 - // Initially set them 230 meters apart
1.181 - // Set positionStep parameter of Experiment::Rung to -1
1.182 - // set RateErrorModel of Experiment::Run to 0
1.183 + // Scenario 2: two nodes out of transmission range about 230 meters apart
1.184 + // Fix a node stationary, move the second node into transmission range
1.185
1.186 + // moving backward
1.187 myPositionStep = -1;
1.188
1.189 - MobilityHelper mobility;
1.190 - Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1.191 + gnuplot = Gnuplot ("multi-rate-first-scen2.eps");
1.192 +
1.193 + positionAlloc = CreateObject<ListPositionAllocator> ();
1.194 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1.195 positionAlloc->Add (Vector (230.0, 0.0, 0.0));
1.196 mobility.SetPositionAllocator (positionAlloc);
1.197 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1.198
1.199 wifiMac.SetType ("ns3::AdhocWifiMac");
1.200 -
1.201 - gnuplot = Gnuplot ("multi-rate-first.png");
1.202 wifi.SetStandard (WIFI_PHY_STANDARD_holland);
1.203
1.204 - NS_LOG_DEBUG ("minstrel");
1.205 experiment = Experiment ("minstrel");
1.206 wifi.SetRemoteStationManager ("ns3::MinstrelWifiManager");
1.207 - dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.208 + dataset= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.209 gnuplot.AddDataset (dataset);
1.210
1.211 - NS_LOG_DEBUG ("ideal");
1.212 experiment = Experiment ("ideal");
1.213 wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1.214 - dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.215 + dataset= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.216 gnuplot.AddDataset (dataset);
1.217
1.218 - gnuplot.GenerateOutput (std::cout);
1.219
1.220 + gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
1.221 + gnuplot.SetLegend ("Time (Seconds)", "Throughput(Mbps)");
1.222 + gnuplot.SetExtra ("set xrange [0:250]");
1.223 + gnuplot.SetTitle ("Throughput vs Time");
1.224 + gnuplot.GenerateOutput (outfile2);
1.225 + outfile2.close ();
1.226
1.227
1.228 -/*
1.229 - // Scenario 3:
1.230 - // Initially set them 25 meters apart, stationary
1.231 - // Set positionStep parameter of Experiment::Rung to 0
1.232 - // This is a sanity check
1.233 + // Scenario 3: two nodes within transmission range 25 meters part
1.234 + // Set both nodes stationary
1.235 + // this is more like a sanity check
1.236
1.237 + // Set position stationary
1.238 myPositionStep = 0;
1.239 - MobilityHelper mobility;
1.240 - Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1.241 +
1.242 + gnuplot = Gnuplot ("multi-rate-first-scen3.eps");
1.243 +
1.244 + positionAlloc = CreateObject<ListPositionAllocator> ();
1.245 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1.246 positionAlloc->Add (Vector (25.0, 0.0, 0.0));
1.247 mobility.SetPositionAllocator (positionAlloc);
1.248 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1.249
1.250 wifiMac.SetType ("ns3::AdhocWifiMac");
1.251 -
1.252 - gnuplot = Gnuplot ("multi-rate-first.png");
1.253 wifi.SetStandard (WIFI_PHY_STANDARD_holland);
1.254
1.255 - NS_LOG_DEBUG ("minstrel");
1.256 experiment = Experiment ("minstrel");
1.257 wifi.SetRemoteStationManager ("ns3::MinstrelWifiManager");
1.258 - dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.259 + dataset= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.260 gnuplot.AddDataset (dataset);
1.261
1.262 - NS_LOG_DEBUG ("ideal");
1.263 experiment = Experiment ("ideal");
1.264 wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1.265 - dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.266 + dataset= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.267 gnuplot.AddDataset (dataset);
1.268
1.269 - gnuplot.GenerateOutput (std::cout);
1.270 - */
1.271 + gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
1.272 + gnuplot.SetLegend ("Time (Seconds)", "Throughput(Mbps)");
1.273 + gnuplot.SetExtra ("set xrange [0:250]");
1.274 + gnuplot.SetTitle ("Throughput vs Time");
1.275 + gnuplot.GenerateOutput (outfile3);
1.276 + outfile3.close ();
1.277 +
1.278 + // Scenario 4: Two nodes in opposite direction about 230 meters apart
1.279 + // moving into transmission range and out of transmission range
1.280 + myPositionStep = 2;
1.281 +
1.282 + gnuplot = Gnuplot ("multi-rate-first-scen4.eps");
1.283 +
1.284 + positionAlloc = CreateObject<ListPositionAllocator> ();
1.285 + // initial position of node 1
1.286 + positionAlloc->Add (Vector (0.0, 25.0, 0.0));
1.287 + // initial position of node 2
1.288 + positionAlloc->Add (Vector (230.0, 0.0, 0.0));
1.289 + mobility.SetPositionAllocator (positionAlloc);
1.290 + mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1.291 +
1.292 + wifiMac.SetType ("ns3::AdhocWifiMac");
1.293 + wifi.SetStandard (WIFI_PHY_STANDARD_holland);
1.294 +
1.295 + experiment = Experiment ("minstrel");
1.296 + wifi.SetRemoteStationManager ("ns3::MinstrelWifiManager");
1.297 + dataset= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.298 + gnuplot.AddDataset (dataset);
1.299 +
1.300 + experiment = Experiment ("ideal");
1.301 + wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1.302 + dataset= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility, myPositionStep);
1.303 + gnuplot.AddDataset (dataset);
1.304 +
1.305 + gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
1.306 + gnuplot.SetLegend ("Time (Seconds)", "Throughput(Mbps)");
1.307 + gnuplot.SetExtra ("set xrange [0:250]");
1.308 + gnuplot.SetTitle ("Throughput vs Time");
1.309 + gnuplot.GenerateOutput (outfile4);
1.310 + outfile4.close ();
1.311 +
1.312
1.313 return 0;
1.314 }
2.1 --- a/examples/multi-rate-second.cc Mon Aug 24 19:03:58 2009 -0700
2.2 +++ b/examples/multi-rate-second.cc Mon Aug 24 19:11:41 2009 -0700
2.3 @@ -95,13 +95,10 @@
2.4 {
2.5 Vector pos = GetPosition(node);
2.6
2.7 - ///to offset the start time
2.8 - double offSetTime = 100;
2.9 -
2.10 if (pktCount > 0)
2.11 {
2.12 ///To simulate nodes moving in and out of transmission constantly
2.13 - if(pos.x <= 305 && advanceStep)
2.14 + if(pos.x <= 230 && advanceStep)
2.15 {
2.16 ///keep moving away
2.17 pos.x += .1;
2.18 @@ -110,7 +107,7 @@
2.19 else
2.20 {
2.21 if(pos.x < 150)
2.22 - {
2.23 + {
2.24 advanceStep=true;
2.25 }
2.26 else
2.27 @@ -128,7 +125,7 @@
2.28 }
2.29 else
2.30 {
2.31 - m_output.Add((Simulator::Now()).GetSeconds() - offSetTime , m_pktsTotal);
2.32 + m_output.Add((Simulator::Now()).GetSeconds(), m_pktsTotal);
2.33 }
2.34 }
2.35
2.36 @@ -172,32 +169,30 @@
2.37 source->Connect (remote);
2.38 uint32_t packetSize = 1014;
2.39 uint32_t maxPacketCount = 1000;
2.40 - Time interPacketInterval = Seconds (.1);
2.41 + Time interPacketInterval = Seconds (1.);
2.42
2.43 Ptr<Node> n1 = c.Get(0);
2.44 Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();
2.45 + // parameters for Ipv4::SetDown and SetUp
2.46 + // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
2.47 + // then the next p2p is numbered 2
2.48
2.49 -
2.50 -
2.51 + double downTime = 0.0;
2.52 for (int i= 1; i <= 100; i++)
2.53 {
2.54
2.55 Simulator::Schedule (Seconds (i), &Experiment::GenerateTraffic,
2.56 this, source, packetSize, maxPacketCount,interPacketInterval, c.Get(1));
2.57 -
2.58 - if( i % 5 == 0 )
2.59 + if ( i % 10 == 0 )
2.60 {
2.61 ///bring a network interface down
2.62 - Simulator::Schedule (Seconds (i+.5), &Ipv4::SetDown, ipv41, 1);
2.63 - i++;
2.64 - Simulator::Schedule (Seconds (i), &Experiment::GenerateTraffic,
2.65 - this, source, packetSize, maxPacketCount,interPacketInterval, c.Get(1));
2.66 + Simulator::Schedule (Seconds (i+.1), &Ipv4::SetDown, ipv41, 1);
2.67
2.68 + //duration of the down time
2.69 + downTime += .1;
2.70 +
2.71 ///bring a network interface up
2.72 - Simulator::Schedule (Seconds (i+.2), &Ipv4::SetUp, ipv41, 1);
2.73 - i++;
2.74 - Simulator::Schedule (Seconds (i), &Experiment::GenerateTraffic,
2.75 - this, source, packetSize, maxPacketCount,interPacketInterval, c.Get(1));
2.76 + Simulator::Schedule (Seconds (i + downTime), &Ipv4::SetUp, ipv41, 1);
2.77 }
2.78 }
2.79
2.80 @@ -209,13 +204,15 @@
2.81
2.82 int main (int argc, char *argv[])
2.83 {
2.84 + std::ofstream outfile ("multi-rate-second.plt");
2.85 +
2.86 std::vector <std::string> ratesControl;
2.87 + ratesControl.push_back ("Minstrel");
2.88 ratesControl.push_back ("Ideal");
2.89 - ratesControl.push_back ("Minstrel");
2.90
2.91 std::vector <std::string> wifiManager;
2.92 + wifiManager.push_back("ns3::MinstrelWifiManager");
2.93 wifiManager.push_back("ns3::IdealWifiManager");
2.94 - wifiManager.push_back("ns3::MinstrelWifiManager");
2.95
2.96 // disable fragmentation
2.97 Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
2.98 @@ -228,12 +225,13 @@
2.99
2.100 for (uint32_t i = 0; i < ratesControl.size(); i++)
2.101 {
2.102 + std::cout << ratesControl[i] << std::endl;
2.103 + std::cout << wifiManager[i] << std::endl;
2.104 Gnuplot2dDataset dataset (ratesControl[i]);
2.105 dataset.SetStyle (Gnuplot2dDataset::LINES);
2.106 Experiment experiment;
2.107
2.108 -
2.109 - WifiHelper wifi = WifiHelper::Default ();
2.110 + WifiHelper wifi;
2.111 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
2.112 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
2.113 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
2.114 @@ -243,14 +241,18 @@
2.115 NS_LOG_DEBUG (ratesControl[i]);
2.116
2.117 experiment = Experiment (ratesControl[i]);
2.118 + wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
2.119 + wifi.SetRemoteStationManager (wifiManager[i]);
2.120 dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2.121 gnuplot.AddDataset (dataset);
2.122
2.123 }
2.124 gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
2.125 - gnuplot.SetLegend ("Time (Seconds)", "Number of packets received");
2.126 - gnuplot.SetExtra ("set xrange [0:100]");
2.127 - gnuplot.GenerateOutput (std::cout);
2.128 + gnuplot.SetLegend ("Time ", "Number of packets received");
2.129 + gnuplot.SetExtra ("set xrange [1000:1100]");
2.130 + gnuplot.SetTitle ("Number of Packets Received vs Time");
2.131 + gnuplot.GenerateOutput (outfile);
2.132 + outfile.close ();
2.133
2.134 return 0;
2.135 }