36 #include <iostream> |
35 #include <iostream> |
37 |
36 |
38 using namespace ns3; |
37 using namespace ns3; |
39 |
38 |
40 static Ptr<Node> |
39 static Ptr<Node> |
41 CreateAdhocNode (Ptr<WifiNetDeviceFactory> factory, Ptr<WifiChannel> channel, |
40 CreateAdhocNode (Ptr<WifiChannel> channel, |
42 Position position, const char *address) |
41 Position position, const char *address) |
43 { |
42 { |
44 Ptr<Node> node = Create<InternetNode> (); |
43 Ptr<Node> node = Create<InternetNode> (); |
45 Ptr<AdhocWifiNetDevice> device = factory->CreateAdhoc (node); |
44 Ptr<AdhocWifiNetDevice> device = Create<AdhocWifiNetDevice> (node); |
46 device->ConnectTo (channel); |
45 device->ConnectTo (channel); |
47 Ptr<MobilityModel> mobility = Create<StaticMobilityModel> (); |
46 Ptr<MobilityModel> mobility = Create<StaticMobilityModel> (); |
48 mobility->Set (position); |
47 mobility->Set (position); |
49 node->AddInterface (mobility); |
48 node->AddInterface (mobility); |
50 |
49 |
89 Simulator::SetLinkedList (); |
88 Simulator::SetLinkedList (); |
90 |
89 |
91 //Simulator::EnableLogTo ("80211.log"); |
90 //Simulator::EnableLogTo ("80211.log"); |
92 |
91 |
93 |
92 |
94 Ptr<WifiNetDeviceFactory> factory = Create<WifiNetDeviceFactory> (); |
93 // enable rts cts all the time. |
95 // force rts/cts on all the time. |
94 DefaultValue::Bind ("WifiRtsCtsThreshold", "0"); |
96 factory->SetMacRtsCtsThreshold (2200); |
95 // disable fragmentation |
97 factory->SetMacFragmentationThreshold (2200); |
96 DefaultValue::Bind ("WifiFragmentationThreshold", "2200"); |
98 //factory->SetCr (5, 5); |
97 DefaultValue::Bind ("WifiRateControlAlgorithm", "Aarf"); |
99 //factory->SetIdeal (1e-5); |
98 //DefaultValue::Bind ("WifiRateControlAlgorithm", "Arf"); |
100 factory->SetAarf (); |
99 |
101 //factory->SetArf (); |
|
102 Ptr<WifiChannel> channel = Create<WifiChannel> (); |
100 Ptr<WifiChannel> channel = Create<WifiChannel> (); |
103 |
101 |
104 Ptr<Node> a = CreateAdhocNode (factory, channel, |
102 Ptr<Node> a = CreateAdhocNode (channel, |
105 Position (5.0,0.0,0.0), |
103 Position (5.0,0.0,0.0), |
106 "192.168.0.1"); |
104 "192.168.0.1"); |
107 Simulator::Schedule (Seconds (1.0), &AdvancePosition, a); |
105 Simulator::Schedule (Seconds (1.0), &AdvancePosition, a); |
108 |
106 |
109 Ptr<Node> b = CreateAdhocNode (factory, channel, |
107 Ptr<Node> b = CreateAdhocNode (channel, |
110 Position (0.0, 0.0, 0.0), |
108 Position (0.0, 0.0, 0.0), |
111 "192.168.0.2"); |
109 "192.168.0.2"); |
112 |
110 |
113 Ptr<Application> app = Create<OnOffApplication> (a, InetSocketAddress ("192.168.0.2", 10), |
111 Ptr<Application> app = Create<OnOffApplication> (a, InetSocketAddress ("192.168.0.2", 10), |
114 "Udp", |
112 "Udp", |
115 ConstantVariable (42), |
113 ConstantVariable (42), |
116 ConstantVariable (0)); |
114 ConstantVariable (0)); |
117 app->Start (Seconds (0.5)); |
115 app->Start (Seconds (0.5)); |
118 app->Stop (Seconds (43.0)); |
116 app->Stop (Seconds (43.0)); |
119 |
117 |
120 #if 0 |
|
121 TraceContainer container = TraceContainer (); |
|
122 wifiServer->RegisterTraces (&container); |
|
123 container.SetCallback ("80211-packet-rx", |
|
124 MakeCallback (&ThroughputPrinter::Receive, printer)); |
|
125 #endif |
|
126 |
|
127 Simulator::Run (); |
118 Simulator::Run (); |
128 |
119 |
129 Simulator::Destroy (); |
120 Simulator::Destroy (); |
130 |
121 |
131 return 0; |
122 return 0; |