ns3-inet-validation-e7d4665.patch 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. diff --git a/examples/wireless/inet-wireless-udp.cc b/examples/wireless/inet-wireless-udp.cc
  2. new file mode 100644
  3. index 0000000..25f9280
  4. --- /dev/null
  5. +++ b/examples/wireless/inet-wireless-udp.cc
  6. @@ -0,0 +1,239 @@
  7. +#include "ns3/core-module.h"
  8. +#include "ns3/network-module.h"
  9. +#include "ns3/applications-module.h"
  10. +#include "ns3/wifi-module.h"
  11. +#include "ns3/mobility-module.h"
  12. +#include "ns3/ipv4-global-routing-helper.h"
  13. +#include "ns3/internet-module.h"
  14. +
  15. +using namespace ns3;
  16. +
  17. +NS_LOG_COMPONENT_DEFINE("inet-wireless-udp");
  18. +
  19. +static int lastSeq = -1;
  20. +static int lastAC = 5;
  21. +static const char *AC[] = {"AC_BE", "AC_BK", "AC_VI", "AC_VO", "AC_BE_NQOS", "NA"};
  22. +
  23. +void TagMarker(uint8_t tid, Ptr<const Packet> packet)
  24. +{
  25. + QosTag qosTag;
  26. + qosTag.SetTid(tid);
  27. + packet->AddPacketTag(qosTag);
  28. +}
  29. +
  30. +void PhyTxTrace(std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
  31. +{
  32. + lastSeq = -1;
  33. + lastAC = 5;
  34. + PacketMetadata::ItemIterator i = packet->BeginItem();
  35. + while (i.HasNext()) {
  36. + PacketMetadata::Item item = i.Next();
  37. + if (!item.isFragment && item.type == PacketMetadata::Item::HEADER) {
  38. + if (item.tid == SeqTsHeader::GetTypeId()) {
  39. + SeqTsHeader header;
  40. + header.Deserialize(item.current);
  41. + lastSeq = header.GetSeq();
  42. + }
  43. + else if (item.tid == WifiMacHeader::GetTypeId()) {
  44. + WifiMacHeader header;
  45. + header.Deserialize(item.current);
  46. + if (header.IsQosData())
  47. + lastAC = QosUtilsMapTidToAc(header.GetQosTid());
  48. + else
  49. + lastAC = 5;
  50. + }
  51. + }
  52. + }
  53. +}
  54. +
  55. +void PhyStateTrace(std::string context, Time start, Time duration, enum WifiPhy::State state)
  56. +{
  57. + if (state == WifiPhy::TX)
  58. + std::cout << "TX: node = " << context.at(10) << ", ac = " << AC[lastAC] << ", seq = " << lastSeq << ", start = " << start.GetPicoSeconds() << ", duration = " << duration.GetPicoSeconds() << std::endl;
  59. +}
  60. +
  61. +void PopulateArpCache()
  62. +{
  63. + Ptr<ArpCache> arp = CreateObject<ArpCache>();
  64. + arp->SetAliveTimeout(Seconds(3600 * 24 * 365));
  65. + for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) {
  66. + Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol>();
  67. + NS_ASSERT(ip != 0);
  68. + ObjectVectorValue interfaces;
  69. + ip->GetAttribute("InterfaceList", interfaces);
  70. + for (ObjectVectorValue::Iterator j = interfaces.Begin(); j != interfaces.End(); j++) {
  71. + Ptr<Ipv4Interface> ipIface = StaticCast<Ipv4Interface, Object>((*j).second);
  72. + NS_ASSERT(ipIface != 0);
  73. + Ptr<NetDevice> device = ipIface->GetDevice();
  74. + NS_ASSERT(device != 0);
  75. + Mac48Address addr = Mac48Address::ConvertFrom(device->GetAddress());
  76. + for (uint32_t k = 0; k < ipIface->GetNAddresses(); k++) {
  77. + Ipv4Address ipAddr = ipIface->GetAddress(k).GetLocal();
  78. + if (ipAddr == Ipv4Address::GetLoopback())
  79. + continue;
  80. + ArpCache::Entry * entry = arp->Add(ipAddr);
  81. + entry->SetMacAddresss(addr);
  82. + entry->MarkPermanent();
  83. + std::cout << "Added ARP cache entry, ip = " << ipAddr << ", mac = " << addr << std::endl;
  84. + }
  85. + }
  86. + }
  87. + for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) {
  88. + Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol>();
  89. + NS_ASSERT(ip != 0);
  90. + ObjectVectorValue interfaces;
  91. + ip->GetAttribute("InterfaceList", interfaces);
  92. + for (ObjectVectorValue::Iterator j = interfaces.Begin(); j != interfaces.End(); j++) {
  93. + Ptr<Ipv4Interface> ipIface = StaticCast<Ipv4Interface, Object>((*j).second);
  94. + ipIface->SetAttribute("ArpCache", PointerValue(arp));
  95. + }
  96. + }
  97. +}
  98. +
  99. +int main(int argc, char *argv[])
  100. +{
  101. + Time::SetResolution(Time::PS);
  102. + Packet::EnableChecking();
  103. +
  104. + // parameters
  105. + int numClients = 1;
  106. + double simulationTime = 1.0; //seconds
  107. + uint32_t messageLength = 1000; //byte
  108. + double sendInterval = 0.0001; //seconds
  109. + double cliAppStartTime = 0.5; //seconds
  110. + double cliAppStartDelta = 0.001; //seconds
  111. + double serverYPos = 3000;
  112. + bool qosEnabled = false;
  113. + int numApps = 1;
  114. + CommandLine cmd;
  115. + cmd.AddValue("withQos", "With QOS", qosEnabled);
  116. + cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime);
  117. + cmd.AddValue("numClients", "Number of client nodes", numClients);
  118. + cmd.AddValue("numApps", "Number of applications [1..4]", numApps);
  119. + cmd.AddValue("serverYPos", "Server node Y position", serverYPos);
  120. + cmd.AddValue("appStartTime", "Application start time in first client", cliAppStartTime);
  121. + cmd.AddValue("appStartDelta", "Application start time delta for other clients", cliAppStartDelta);
  122. + cmd.AddValue("sendInterval", "Send interval in seconds", sendInterval);
  123. + cmd.Parse(argc, argv);
  124. + NS_ASSERT(numApps >= 1 && numApps <= 4);
  125. + int ports[4] = { 5000, 4000, 80, 21 };
  126. + uint8_t tagVector[4] = { UP_VO, UP_VI, UP_BE, UP_BK };
  127. +
  128. + // node
  129. + NodeContainer wifiSrvNode;
  130. + NodeContainer wifiCliNode;
  131. + wifiSrvNode.Create(1);
  132. + wifiCliNode.Create(numClients);
  133. +
  134. + // phy
  135. + YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
  136. + YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
  137. +// phy.Set("TxPowerStart", DoubleValue(200));
  138. +// phy.Set("TxPowerEnd", DoubleValue(200));
  139. + phy.SetChannel(channel.Create());
  140. + phy.SetPcapDataLinkType(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
  141. +
  142. + WifiHelper wifi = WifiHelper::Default();
  143. + wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
  144. + wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
  145. + "DataMode", StringValue("OfdmRate54Mbps"),
  146. + "ControlMode", StringValue("OfdmRate6Mbps"));
  147. +
  148. + Config::SetDefault("ns3::WifiMacQueue::MaxPacketNumber", UintegerValue(10000));
  149. +
  150. + Ssid ssid = Ssid("ns3-80211a");
  151. + WifiMacHelper *macPtr = NULL;
  152. +
  153. + // mac
  154. + QosWifiMacHelper macQ = QosWifiMacHelper::Default();
  155. + NqosWifiMacHelper macNq = NqosWifiMacHelper::Default();
  156. +
  157. + if (qosEnabled) {
  158. + macQ.SetType("ns3::AdhocWifiMac", "Ssid", SsidValue(ssid));
  159. + macPtr = &macQ;
  160. + }
  161. + else {
  162. + macNq.SetType("ns3::AdhocWifiMac", "Ssid", SsidValue(ssid));
  163. + macPtr = &macNq;
  164. + }
  165. +
  166. + // device
  167. + NetDeviceContainer srvDevice = wifi.Install(phy, *macPtr, wifiSrvNode);
  168. + NetDeviceContainer cliDevice = wifi.Install(phy, *macPtr, wifiCliNode);
  169. + NetDeviceContainer devices;
  170. + devices.Add(srvDevice);
  171. + devices.Add(cliDevice);
  172. +
  173. + // random sequences must be the same as in INET
  174. + wifi.AssignStreams(srvDevice, 0);
  175. + wifi.AssignStreams(cliDevice, 6);
  176. +
  177. + // mobility
  178. + MobilityHelper mobility;
  179. + Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
  180. + positionAlloc->Add(Vector(15.0, serverYPos, 0.0)); // server
  181. + for (int i = 0; i < numClients; i++) {
  182. + positionAlloc->Add(Vector(10.0 + i * 10.0, 10.0, 0.0)); // clients
  183. + }
  184. + mobility.SetPositionAllocator(positionAlloc);
  185. + mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  186. + mobility.Install(wifiSrvNode);
  187. + mobility.Install(wifiCliNode);
  188. +
  189. + // internet stack
  190. + InternetStackHelper stack;
  191. + stack.Install(wifiSrvNode);
  192. + stack.Install(wifiCliNode);
  193. +
  194. + // IP addresses
  195. + Ipv4AddressHelper address;
  196. + address.SetBase("192.168.1.0", "255.255.255.0");
  197. +
  198. + Ipv4InterfaceContainer srvNodeInterface = address.Assign(srvDevice);
  199. + Ipv4InterfaceContainer cliNodesInterface = address.Assign(cliDevice);
  200. +
  201. + // server apps
  202. + ApplicationContainer serverApp;
  203. + for (int i = 0; i < numApps; i++) {
  204. + UdpServerHelper myServer(ports[i]);
  205. + serverApp.Add(myServer.Install(wifiSrvNode.Get(0)));
  206. + }
  207. + serverApp.Start(Seconds(0.0));
  208. + serverApp.Stop(Seconds(simulationTime));
  209. +
  210. + // client apps
  211. + ApplicationContainer clientApps;
  212. + for (int i = 0; i < numApps; i++) {
  213. + UdpClientHelper myClient(srvNodeInterface.GetAddress(0), ports[i]);
  214. + myClient.SetAttribute("MaxPackets", UintegerValue(400000u));
  215. + myClient.SetAttribute("Interval", TimeValue(Seconds(sendInterval))); //packets/s
  216. + myClient.SetAttribute("PacketSize", UintegerValue(messageLength));
  217. + ApplicationContainer c = myClient.Install(wifiCliNode);
  218. + for (int j = 0; j < (int) c.GetN(); j++) {
  219. + Ptr<Application> app = c.Get(j);
  220. + app->SetStartTime(Seconds(cliAppStartTime + j * cliAppStartDelta));
  221. + }
  222. + for (int j = 0; j < (int) c.GetN(); j++) {
  223. + Ptr<UdpClient> udpclientapp;
  224. + udpclientapp = DynamicCast<UdpClient>(c.Get(j));
  225. + udpclientapp->TraceConnectWithoutContext("Tx", MakeBoundCallback(&TagMarker, tagVector[i]));
  226. + }
  227. + clientApps.Add(c);
  228. + }
  229. + clientApps.Stop(Seconds(simulationTime));
  230. +
  231. + // global routing and arp cache
  232. + PopulateArpCache();
  233. + Ipv4GlobalRoutingHelper::PopulateRoutingTables();
  234. +
  235. + Config::Connect("/NodeList/*/DeviceList/*/Phy/State/State", MakeCallback(&PhyStateTrace));
  236. + Config::Connect("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback(&PhyTxTrace));
  237. +
  238. + // simulation
  239. + Simulator::Stop(Seconds(simulationTime));
  240. + Simulator::Run();
  241. + Simulator::Destroy();
  242. +
  243. + return 0;
  244. +}
  245. +
  246. diff --git a/examples/wireless/wifi-backoff.cc b/examples/wireless/wifi-backoff.cc
  247. new file mode 100644
  248. index 0000000..68bc0fb
  249. --- /dev/null
  250. +++ b/examples/wireless/wifi-backoff.cc
  251. @@ -0,0 +1,162 @@
  252. +#include "ns3/applications-module.h"
  253. +#include "ns3/core-module.h"
  254. +#include "ns3/internet-module.h"
  255. +#include "ns3/ipv4-global-routing-helper.h"
  256. +#include "ns3/mobility-module.h"
  257. +#include "ns3/network-module.h"
  258. +#include "ns3/wifi-module.h"
  259. +
  260. +using namespace ns3;
  261. +
  262. +NS_LOG_COMPONENT_DEFINE("wifi-backoff");
  263. +
  264. +void TagMarker(uint8_t tid, Ptr<const Packet> packet)
  265. +{
  266. + QosTag qosTag;
  267. + qosTag.SetTid(tid);
  268. + packet->AddPacketTag(qosTag);
  269. +}
  270. +
  271. +void PhyStateTrace(std::string context, Time start, Time duration, enum WifiPhy::State state)
  272. +{
  273. + if (state == WifiPhy::TX)
  274. + std::cout << "START = " << start << std::endl;
  275. +}
  276. +
  277. +void PopulateArpCache()
  278. +{
  279. + Ptr<ArpCache> arp = CreateObject<ArpCache>();
  280. + arp->SetAliveTimeout(Seconds(3600 * 24 * 365));
  281. + for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) {
  282. + Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol>();
  283. + NS_ASSERT(ip != 0);
  284. + ObjectVectorValue interfaces;
  285. + ip->GetAttribute("InterfaceList", interfaces);
  286. + for (ObjectVectorValue::Iterator j = interfaces.Begin(); j != interfaces.End(); j++) {
  287. + Ptr<Ipv4Interface> ipIface = StaticCast<Ipv4Interface, Object>((*j).second);
  288. + NS_ASSERT(ipIface != 0);
  289. + Ptr<NetDevice> device = ipIface->GetDevice();
  290. + NS_ASSERT(device != 0);
  291. + Mac48Address addr = Mac48Address::ConvertFrom(device->GetAddress());
  292. + for (uint32_t k = 0; k < ipIface->GetNAddresses(); k++) {
  293. + Ipv4Address ipAddr = ipIface->GetAddress(k).GetLocal();
  294. + if (ipAddr == Ipv4Address::GetLoopback())
  295. + continue;
  296. + ArpCache::Entry * entry = arp->Add(ipAddr);
  297. + entry->SetMacAddresss(addr);
  298. + entry->MarkPermanent();
  299. + }
  300. + }
  301. + }
  302. + for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) {
  303. + Ptr<Ipv4L3Protocol> ip = (*i)->GetObject<Ipv4L3Protocol>();
  304. + NS_ASSERT(ip != 0);
  305. + ObjectVectorValue interfaces;
  306. + ip->GetAttribute("InterfaceList", interfaces);
  307. + for (ObjectVectorValue::Iterator j = interfaces.Begin(); j != interfaces.End(); j++) {
  308. + Ptr<Ipv4Interface> ipIface = StaticCast<Ipv4Interface, Object>((*j).second);
  309. + ipIface->SetAttribute("ArpCache", PointerValue(arp));
  310. + }
  311. + }
  312. +}
  313. +
  314. +void test(bool separateClients)
  315. +{
  316. + std::cout << "Separate clients: " << separateClients << std::endl;
  317. + // Nodes
  318. + NodeContainer wifiSrvNode;
  319. + NodeContainer wifiCliNode1;
  320. + NodeContainer wifiCliNode2;
  321. + wifiSrvNode.Create(1);
  322. + wifiCliNode1.Create(1);
  323. + wifiCliNode2.Create(1);
  324. +
  325. + // Wifi
  326. + YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
  327. + YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
  328. + phy.SetChannel(channel.Create());
  329. + phy.SetPcapDataLinkType(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
  330. +
  331. + WifiHelper wifi = WifiHelper::Default();
  332. + wifi.SetStandard(WIFI_PHY_STANDARD_80211a); // WIFI_PHY_STANDARD_80211g
  333. + wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
  334. + "DataMode", StringValue("OfdmRate54Mbps"), // ErpOfdmRate54Mbps
  335. + "ControlMode", StringValue("OfdmRate6Mbps")); // ErpOfdmRate6Mbps
  336. +
  337. + QosWifiMacHelper mac = QosWifiMacHelper::Default();
  338. + Config::SetDefault("ns3::WifiRemoteStationManager::MaxSlrc", UintegerValue(1));
  339. +
  340. + Ssid ssid = Ssid("ns3-80211a");
  341. + mac.SetType("ns3::AdhocWifiMac", "Ssid", SsidValue(ssid));
  342. + NetDeviceContainer srvDevice = wifi.Install(phy, mac, wifiSrvNode);
  343. + NetDeviceContainer cli1Device = wifi.Install(phy, mac, wifiCliNode1);
  344. + NetDeviceContainer cli2Device = wifi.Install(phy, mac, wifiCliNode2);
  345. +
  346. + // Assign the same random streams so that they draw the same backoff periods
  347. + wifi.AssignStreams(cli1Device, 666);
  348. + wifi.AssignStreams(cli2Device, 666);
  349. +
  350. + // Mobility.
  351. + Ptr<ListPositionAllocator> positionAllocator = CreateObject<ListPositionAllocator>();
  352. + positionAllocator->Add(Vector(10000.0, 0.0, 0.0));
  353. + positionAllocator->Add(Vector(0.0, 0.0, 0.0));
  354. + positionAllocator->Add(Vector(0.0, 0.0, 0.0));
  355. + MobilityHelper mobility;
  356. + mobility.SetPositionAllocator(positionAllocator);
  357. + mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  358. + mobility.Install(wifiSrvNode);
  359. + mobility.Install(wifiCliNode1);
  360. + mobility.Install(wifiCliNode2);
  361. +
  362. + // Internet stack
  363. + InternetStackHelper stack;
  364. + stack.Install(wifiSrvNode);
  365. + stack.Install(wifiCliNode1);
  366. + stack.Install(wifiCliNode2);
  367. +
  368. + Ipv4AddressHelper address;
  369. + address.SetBase("192.168.1.0", "255.255.255.0");
  370. + Ipv4InterfaceContainer srvNodeInterface = address.Assign(srvDevice);
  371. + address.Assign(cli1Device);
  372. + address.Assign(cli2Device);
  373. +
  374. + // Applications
  375. + UdpClientHelper clientHelper1(srvNodeInterface.GetAddress(0), 5000);
  376. + clientHelper1.SetAttribute("MaxPackets", UintegerValue(1u));
  377. + clientHelper1.SetAttribute("PacketSize", UintegerValue(1000));
  378. + ApplicationContainer clientApp1 = clientHelper1.Install(wifiCliNode1);
  379. + clientApp1.Start(Seconds(1.0));
  380. + Ptr<UdpClient> udpClient1;
  381. + udpClient1 = DynamicCast<UdpClient>(clientApp1.Get(0));
  382. + udpClient1->TraceConnectWithoutContext("Tx", MakeBoundCallback(&TagMarker, UP_VO));
  383. +
  384. + UdpClientHelper clientHelper2(srvNodeInterface.GetAddress(0), 4000);
  385. + clientHelper2.SetAttribute("MaxPackets", UintegerValue(1u));
  386. + clientHelper2.SetAttribute("PacketSize", UintegerValue(1000));
  387. + ApplicationContainer clientApp2 = clientHelper2.Install(separateClients ? wifiCliNode2 : wifiCliNode1);
  388. + clientApp2.Start(Seconds(1.000001)); // 1us delay to receive the voice packet and backoff
  389. + Ptr<UdpClient> udpClient2;
  390. + udpClient2 = DynamicCast<UdpClient>(clientApp2.Get(0));
  391. + udpClient2->TraceConnectWithoutContext("Tx", MakeBoundCallback(&TagMarker, UP_VI));
  392. +
  393. + PopulateArpCache();
  394. + Ipv4GlobalRoutingHelper::PopulateRoutingTables();
  395. +
  396. + Config::Connect("/NodeList/*/DeviceList/*/Phy/State/State", MakeCallback(&PhyStateTrace));
  397. +
  398. + Simulator::Stop(Seconds(5.0));
  399. + Simulator::Run();
  400. + Simulator::Destroy();
  401. +}
  402. +
  403. +int main(int argc, char *argv[])
  404. +{
  405. + Packet::EnableChecking();
  406. + Time::SetResolution(Time::PS);
  407. +
  408. + test(false);
  409. + test(true);
  410. +
  411. + return 0;
  412. +}
  413. +
  414. diff --git a/examples/wireless/wscript b/examples/wireless/wscript
  415. index 1336e41..e70024b 100644
  416. --- a/examples/wireless/wscript
  417. +++ b/examples/wireless/wscript
  418. @@ -84,3 +84,9 @@ def build(bld):
  419. obj = bld.create_ns3_program('simple-ht-hidden-stations', ['internet', 'mobility', 'wifi', 'applications'])
  420. obj.source = 'simple-ht-hidden-stations.cc'
  421. +
  422. + obj = bld.create_ns3_program('inet-wireless-udp', ['internet', 'mobility', 'wifi', 'applications'])
  423. + obj.source = 'inet-wireless-udp.cc'
  424. +
  425. + obj = bld.create_ns3_program('wifi-backoff', ['internet', 'mobility', 'wifi', 'applications'])
  426. + obj.source = 'wifi-backoff.cc'
  427. diff --git a/src/applications/model/udp-client.cc b/src/applications/model/udp-client.cc
  428. index 49347c3..415ab99 100644
  429. --- a/src/applications/model/udp-client.cc
  430. +++ b/src/applications/model/udp-client.cc
  431. @@ -69,6 +69,9 @@ UdpClient::GetTypeId (void)
  432. UintegerValue (1024),
  433. MakeUintegerAccessor (&UdpClient::m_size),
  434. MakeUintegerChecker<uint32_t> (12,1500))
  435. + .AddTraceSource ("Tx", "A new packet is created and is sent",
  436. + MakeTraceSourceAccessor (&UdpClient::m_txTrace),
  437. + "ns3::Packet::TracedCallback")
  438. ;
  439. return tid;
  440. }
  441. @@ -169,6 +172,7 @@ UdpClient::Send (void)
  442. peerAddressStringStream << Ipv6Address::ConvertFrom (m_peerAddress);
  443. }
  444. + m_txTrace (p);
  445. if ((m_socket->Send (p)) >= 0)
  446. {
  447. ++m_sent;
  448. diff --git a/src/applications/model/udp-client.h b/src/applications/model/udp-client.h
  449. index 642d033..6d13df0 100644
  450. --- a/src/applications/model/udp-client.h
  451. +++ b/src/applications/model/udp-client.h
  452. @@ -27,6 +27,7 @@
  453. #include "ns3/event-id.h"
  454. #include "ns3/ptr.h"
  455. #include "ns3/ipv4-address.h"
  456. +#include "ns3/traced-callback.h"
  457. namespace ns3 {
  458. @@ -95,6 +96,8 @@ private:
  459. uint16_t m_peerPort; //!< Remote peer port
  460. EventId m_sendEvent; //!< Event to send the next packet
  461. + /// Traced Callback: transmitted packets.
  462. + TracedCallback<Ptr<const Packet> > m_txTrace;
  463. };
  464. } // namespace ns3
  465. diff --git a/src/core/model/clcg32.cc b/src/core/model/clcg32.cc
  466. new file mode 100644
  467. index 0000000..964736d
  468. --- /dev/null
  469. +++ b/src/core/model/clcg32.cc
  470. @@ -0,0 +1,121 @@
  471. +#include "ns3/clcg32.h"
  472. +
  473. +int cLCG32::nextId = 0;
  474. +
  475. +void cLCG32::initialize(int seedSet, int rngId, int numRngs)
  476. +{
  477. + int autoSeedIndex = seedSet * numRngs + rngId;
  478. + autoSeedIndex = autoSeedIndex % 256;
  479. + seed = autoSeeds[autoSeedIndex];
  480. +}
  481. +
  482. +void cLCG32::selfTest()
  483. +{
  484. + seed = 1;
  485. + for (int i = 0; i < 10000; i++)
  486. + intRand();
  487. +}
  488. +
  489. +unsigned long cLCG32::intRand()
  490. +{
  491. + numDrawn++;
  492. + const long int a = 16807, q = 127773, r = 2836;
  493. + seed = a * (seed % q) - r * (seed / q);
  494. + if (seed <= 0)
  495. + seed += LCG32_MAX + 1;
  496. + return seed - 1; // shift range [1..2^31-2] to [0..2^31-3]
  497. +}
  498. +
  499. +unsigned long cLCG32::intRandMax()
  500. +{
  501. + return LCG32_MAX - 1; // 2^31-3
  502. +}
  503. +
  504. +unsigned long cLCG32::intRand(unsigned long n)
  505. +{
  506. + // code from MersenneTwister.h, Richard J. Wagner rjwagner@writeme.com
  507. + // Find which bits are used in n
  508. + unsigned long used = n - 1;
  509. + used |= used >> 1;
  510. + used |= used >> 2;
  511. + used |= used >> 4;
  512. + used |= used >> 8;
  513. + used |= used >> 16;
  514. +
  515. + // Draw numbers until one is found in [0,n]
  516. + unsigned long i;
  517. + do
  518. + i = intRand() & used; // toss unused bits to shorten search
  519. + while (i >= n);
  520. + return i;
  521. +}
  522. +
  523. +double cLCG32::doubleRand()
  524. +{
  525. + return (double)intRand() * (1.0 / LCG32_MAX);
  526. +}
  527. +
  528. +double cLCG32::doubleRandNonz()
  529. +{
  530. + return (double)(intRand() + 1) * (1.0 / (LCG32_MAX + 1));
  531. +}
  532. +
  533. +double cLCG32::doubleRandIncl1()
  534. +{
  535. + return (double)intRand() * (1.0 / (LCG32_MAX - 1));
  536. +}
  537. +
  538. +long cLCG32::autoSeeds[] = {
  539. + 1L, 1331238991L, 1550655590L, 930627303L, 766698560L, 372156336L,
  540. + 1645116277L, 1635860990L, 1154667137L, 692982627L, 1961833381L,
  541. + 713190994L, 460575272L, 1298018763L, 1497719440L, 2030952567L,
  542. + 901595110L, 631930165L, 354421844L, 1213737427L, 1800697079L,
  543. + 795809157L, 821079954L, 1624537871L, 1918430133L, 861482464L,
  544. + 1736896562L, 1220028201L, 634729389L, 456922549L, 23246132L,
  545. + 979545543L, 1008653149L, 1156436224L, 1689665648L, 1604778030L,
  546. + 1628735393L, 1949577498L, 550023088L, 1726571906L, 1267216792L,
  547. + 1750609806L, 314116942L, 736299588L, 2095003524L, 1281569003L,
  548. + 356484144L, 1423591576L, 2140958617L, 1577658393L, 1116852912L,
  549. + 1865734753L, 1701937813L, 301264580L, 171817360L, 1809513683L,
  550. + 360646631L, 546534802L, 1652205397L, 136501886L, 605448579L,
  551. + 1857604347L, 1223969344L, 668104522L, 1821072732L, 738721927L,
  552. + 1237280745L, 1753702432L, 2125855022L, 1259255700L, 935058038L,
  553. + 1325807218L, 1151620124L, 585222105L, 1970906347L, 1267057970L,
  554. + 66562942L, 1959090863L, 1503754591L, 114059398L, 2007872839L,
  555. + 1886985293L, 1870986444L, 2110445215L, 1375265396L, 1512926254L,
  556. + 470646700L, 1951555990L, 500432100L, 1843528576L, 347147950L,
  557. + 1431668171L, 929595364L, 1507452793L, 800443847L, 1428656866L,
  558. + 5715478L, 1607979231L, 2032092669L, 37809413L, 996425830L,
  559. + 1010869813L, 1884232020L, 312192738L, 1821061493L, 462270727L,
  560. + 248900140L, 678804905L, 905130946L, 1892339752L, 1307421505L,
  561. + 491642575L, 1091346202L, 1076664921L, 1140141037L, 122447008L,
  562. + 1244153851L, 1382627577L, 611793617L, 1989326495L, 808278095L,
  563. + 1352281487L, 2106046913L, 1731628906L, 1226683843L, 1683200486L,
  564. + 90274853L, 1676390615L, 2147466840L, 498396356L, 2140522509L,
  565. + 1217803227L, 1146667727L, 788324559L, 1530171233L, 317473611L,
  566. + 319146380L, 992289339L, 2077765218L, 652681396L, 789950931L,
  567. + 485020132L, 632682054L, 32775496L, 1683083109L, 603834907L,
  568. + 351704670L, 1809710911L, 171230418L, 1511135464L, 1986612391L,
  569. + 1646573708L, 1411714374L, 1546459273L, 872179784L, 1307370996L,
  570. + 801917373L, 2051724276L, 144283230L, 1535180348L, 1949917822L,
  571. + 650872229L, 113201992L, 890256110L, 1965781805L, 1903960687L,
  572. + 679060319L, 452497769L, 630187802L, 174438105L, 1298843779L,
  573. + 961082145L, 1565131991L, 2078229636L, 50366922L, 959177042L,
  574. + 144513213L, 1423462005L, 207666443L, 152219823L, 13354949L,
  575. + 412643566L, 631135695L, 166938633L, 958408264L, 1324624652L,
  576. + 494931978L, 1472820641L, 1150735880L, 1508483704L, 1640573652L,
  577. + 359288909L, 1315013967L, 1051019865L, 1254156333L, 1883764098L,
  578. + 587564032L, 1288274932L, 1912367727L, 1595891993L, 2138169990L,
  579. + 1794668172L, 2059764593L, 1152025509L, 115613893L, 926625010L,
  580. + 131630606L, 706594585L, 1386707532L, 1624163092L, 2081362360L,
  581. + 1882152641L, 1428465736L, 602313149L, 1170668648L, 863700348L,
  582. + 931140599L, 1856765731L, 197473249L, 507314638L, 1381732824L,
  583. + 252975355L, 925311926L, 1726193892L, 576725369L, 774762078L,
  584. + 198434005L, 192355221L, 1296038143L, 1201667973L, 653782169L,
  585. + 1426685702L, 1503907840L, 211726157L, 33491376L, 906578176L,
  586. + 238345926L, 1826083853L, 1366925216L, 480315631L, 1549695660L,
  587. + 1337366022L, 1793656969L, 1469954017L, 1701980729L, 98857548L,
  588. + 1883864564L, 1709982325L, 251608257L, 1171967839L, 642486710L,
  589. + 1358844649L, 1115145546L, 1398997376L, 1021484058L, 2035865982L,
  590. +};
  591. +
  592. diff --git a/src/core/model/clcg32.h b/src/core/model/clcg32.h
  593. new file mode 100644
  594. index 0000000..64badc9
  595. --- /dev/null
  596. +++ b/src/core/model/clcg32.h
  597. @@ -0,0 +1,71 @@
  598. +#ifndef __NS3_CLCG32_H
  599. +#define __NS3_CLCG32_H
  600. +
  601. +#define LCG32_MAX 0x7ffffffeL /* = 2^31-2 */
  602. +
  603. +/**
  604. + * Implements a 32-bit (2^31-2 cycle length) linear congruential random
  605. + * number generator.
  606. + * - Range: 1 ... 2^31-2
  607. + * - Period length: 2^31-2
  608. + * - Method: x=(x * 7^5) mod (2^31-1)
  609. + * - Required hardware: exactly 32-bit integer aritmetics
  610. + * - To check: if x[0]=1 then x[10000]=1,043,618,065
  611. + *
  612. + * Source: Raj Jain: The Art of Computer Systems Performance Analysis
  613. + * (John Wiley & Sons, 1991) pp 441-444, 455.
  614. + */
  615. +class cLCG32
  616. +{
  617. + public:
  618. + int id;
  619. + protected:
  620. + static int nextId;
  621. + long numDrawn;
  622. + long seed;
  623. +
  624. + // 256 pre-generated seeds, spaced 8,388,608 values in the sequence.
  625. + // This covers the whole RNG period. Enough for 128 runs with 2 RNGs
  626. + // each, or 64 runs with 4 RNGs each -- assuming one run never uses
  627. + // more than 8 million random numbers per RNG.
  628. + static long autoSeeds[256];
  629. +
  630. + public:
  631. + cLCG32() : id(nextId++), numDrawn(0), seed(0) { initialize(0, 0, 0); }
  632. + virtual ~cLCG32() {}
  633. +
  634. + /** Sets up the RNG. */
  635. + virtual void initialize(int seedSet, int rngId, int numRngs);
  636. +
  637. + /** Tests correctness of the RNG */
  638. + virtual void selfTest();
  639. +
  640. + /**
  641. + * Returns how many random numbers have been drawn from this RNG.
  642. + * Subclasses should increment numDrawn in the intRand(), etc. methods.
  643. + */
  644. + virtual unsigned long getNumbersDrawn() const {return numDrawn;}
  645. +
  646. + /** Random integer in the range [0,intRandMax()] */
  647. + virtual unsigned long intRand();
  648. +
  649. + /** Maximum value that can be returned by intRand() */
  650. + virtual unsigned long intRandMax();
  651. +
  652. + /** Random integer in [0,n), n < intRandMax() */
  653. + virtual unsigned long intRand(unsigned long n);
  654. +
  655. + /** Random double on the [0,1) interval */
  656. + virtual double doubleRand();
  657. +
  658. + /** Random double on the (0,1) interval */
  659. + virtual double doubleRandNonz();
  660. +
  661. + /** Random double on the [0,1] interval */
  662. + virtual double doubleRandIncl1();
  663. +};
  664. +
  665. +
  666. +#endif
  667. +
  668. +
  669. diff --git a/src/core/wscript b/src/core/wscript
  670. index 1535d66..8c41388 100644
  671. --- a/src/core/wscript
  672. +++ b/src/core/wscript
  673. @@ -160,6 +160,7 @@ def build(bld):
  674. 'model/random-variable-stream.cc',
  675. 'model/rng-seed-manager.cc',
  676. 'model/rng-stream.cc',
  677. + 'model/clcg32.cc',
  678. 'model/command-line.cc',
  679. 'model/type-name.cc',
  680. 'model/attribute.cc',
  681. @@ -256,6 +257,7 @@ def build(bld):
  682. 'model/random-variable-stream.h',
  683. 'model/rng-seed-manager.h',
  684. 'model/rng-stream.h',
  685. + 'model/clcg32.h',
  686. 'model/command-line.h',
  687. 'model/type-name.h',
  688. 'model/type-traits.h',
  689. diff --git a/src/wifi/bindings/modulegen__gcc_ILP32.py b/src/wifi/bindings/modulegen__gcc_ILP32.py
  690. index 9ba4c4e..380cdad 100644
  691. --- a/src/wifi/bindings/modulegen__gcc_ILP32.py
  692. +++ b/src/wifi/bindings/modulegen__gcc_ILP32.py
  693. @@ -8890,7 +8890,7 @@ def register_Ns3WifiRemoteStationManager_methods(root_module, cls):
  694. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportDataFailed(ns3::Mac48Address address, ns3::WifiMacHeader const * header) [member function]
  695. cls.add_method('ReportDataFailed',
  696. 'void',
  697. - [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header')])
  698. + [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header'), param('ns3::Ptr< ns3::Packet const >', 'p')])
  699. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportDataOk(ns3::Mac48Address address, ns3::WifiMacHeader const * header, double ackSnr, ns3::WifiMode ackMode, double dataSnr) [member function]
  700. cls.add_method('ReportDataOk',
  701. 'void',
  702. @@ -8898,7 +8898,7 @@ def register_Ns3WifiRemoteStationManager_methods(root_module, cls):
  703. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportFinalDataFailed(ns3::Mac48Address address, ns3::WifiMacHeader const * header) [member function]
  704. cls.add_method('ReportFinalDataFailed',
  705. 'void',
  706. - [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header')])
  707. + [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header'), param('ns3::Ptr< ns3::Packet const >', 'p')])
  708. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportFinalRtsFailed(ns3::Mac48Address address, ns3::WifiMacHeader const * header) [member function]
  709. cls.add_method('ReportFinalRtsFailed',
  710. 'void',
  711. diff --git a/src/wifi/bindings/modulegen__gcc_LP64.py b/src/wifi/bindings/modulegen__gcc_LP64.py
  712. index 9ba4c4e..380cdad 100644
  713. --- a/src/wifi/bindings/modulegen__gcc_LP64.py
  714. +++ b/src/wifi/bindings/modulegen__gcc_LP64.py
  715. @@ -8890,7 +8890,7 @@ def register_Ns3WifiRemoteStationManager_methods(root_module, cls):
  716. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportDataFailed(ns3::Mac48Address address, ns3::WifiMacHeader const * header) [member function]
  717. cls.add_method('ReportDataFailed',
  718. 'void',
  719. - [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header')])
  720. + [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header'), param('ns3::Ptr< ns3::Packet const >', 'p')])
  721. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportDataOk(ns3::Mac48Address address, ns3::WifiMacHeader const * header, double ackSnr, ns3::WifiMode ackMode, double dataSnr) [member function]
  722. cls.add_method('ReportDataOk',
  723. 'void',
  724. @@ -8898,7 +8898,7 @@ def register_Ns3WifiRemoteStationManager_methods(root_module, cls):
  725. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportFinalDataFailed(ns3::Mac48Address address, ns3::WifiMacHeader const * header) [member function]
  726. cls.add_method('ReportFinalDataFailed',
  727. 'void',
  728. - [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header')])
  729. + [param('ns3::Mac48Address', 'address'), param('ns3::WifiMacHeader const *', 'header'), param('ns3::Ptr< ns3::Packet const >', 'p')])
  730. ## wifi-remote-station-manager.h (module 'wifi'): void ns3::WifiRemoteStationManager::ReportFinalRtsFailed(ns3::Mac48Address address, ns3::WifiMacHeader const * header) [member function]
  731. cls.add_method('ReportFinalRtsFailed',
  732. 'void',
  733. diff --git a/src/wifi/model/block-ack-manager.cc b/src/wifi/model/block-ack-manager.cc
  734. index 52ef1b9..c4956d0 100644
  735. --- a/src/wifi/model/block-ack-manager.cc
  736. +++ b/src/wifi/model/block-ack-manager.cc
  737. @@ -606,7 +606,7 @@ BlockAckManager::NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac4
  738. (*it).second.first.SetStartingSequence (sequenceFirstLost);
  739. }
  740. //notify remote station of unsuccessful transmission
  741. - m_stationManager->ReportDataFailed ((*queueIt).hdr.GetAddr1 (), &(*queueIt).hdr);
  742. + m_stationManager->ReportDataFailed ((*queueIt).hdr.GetAddr1 (), &(*queueIt).hdr, (*queueIt).packet);
  743. if (!m_txFailedCallback.IsNull ())
  744. {
  745. m_txFailedCallback ((*queueIt).hdr);
  746. diff --git a/src/wifi/model/dca-txop.cc b/src/wifi/model/dca-txop.cc
  747. index dfce078..9c356b8 100644
  748. --- a/src/wifi/model/dca-txop.cc
  749. +++ b/src/wifi/model/dca-txop.cc
  750. @@ -624,7 +624,7 @@ DcaTxop::MissedAck (void)
  751. if (!NeedDataRetransmission ())
  752. {
  753. NS_LOG_DEBUG ("Ack Fail");
  754. - m_stationManager->ReportFinalDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
  755. + m_stationManager->ReportFinalDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  756. if (!m_txFailedCallback.IsNull ())
  757. {
  758. m_txFailedCallback (m_currentHdr);
  759. diff --git a/src/wifi/model/dcf-manager.cc b/src/wifi/model/dcf-manager.cc
  760. index f77b625..2f98d5b 100644
  761. --- a/src/wifi/model/dcf-manager.cc
  762. +++ b/src/wifi/model/dcf-manager.cc
  763. @@ -214,6 +214,10 @@ public:
  764. {
  765. m_dcf->NotifyNavResetNow (duration);
  766. }
  767. + virtual void TxNavStart (Time duration)
  768. + {
  769. + m_dcf->NotifyTxNavStartNow(duration);
  770. + }
  771. virtual void AckTimeoutStart (Time duration)
  772. {
  773. m_dcf->NotifyAckTimeoutStartNow (duration);
  774. @@ -297,10 +301,12 @@ private:
  775. ****************************************************************/
  776. DcfManager::DcfManager ()
  777. - : m_lastAckTimeoutEnd (MicroSeconds (0)),
  778. + : m_grantedState(0),
  779. + m_lastAckTimeoutEnd (MicroSeconds (0)),
  780. m_lastCtsTimeoutEnd (MicroSeconds (0)),
  781. m_lastNavStart (MicroSeconds (0)),
  782. m_lastNavDuration (MicroSeconds (0)),
  783. + m_lastTxNavDuration (MicroSeconds (0)),
  784. m_lastRxStart (MicroSeconds (0)),
  785. m_lastRxDuration (MicroSeconds (0)),
  786. m_lastRxReceivedOk (true),
  787. @@ -452,6 +458,20 @@ DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g)
  788. return retval;
  789. }
  790. +Time
  791. +DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g, Time h) const
  792. +{
  793. + NS_LOG_FUNCTION (this << a << b << c << d << e << f << g << h);
  794. + Time i = Max (a, b);
  795. + Time j = Max (c, d);
  796. + Time k = Max (e, f);
  797. + Time l = Max (g, h);
  798. + Time m = Max (i, j);
  799. + Time n = Max (k, l);
  800. + Time retval = Max (m, n);
  801. + return retval;
  802. +}
  803. +
  804. bool
  805. DcfManager::IsBusy (void) const
  806. {
  807. @@ -547,6 +567,7 @@ DcfManager::DoGrantAccess (void)
  808. * could change the global state of the manager, and, thus, could change
  809. * the result of the calculations.
  810. */
  811. + m_grantedState = state;
  812. state->NotifyAccessGranted ();
  813. for (std::vector<DcfState *>::const_iterator k = internalCollisionStates.begin ();
  814. k != internalCollisionStates.end (); k++)
  815. @@ -569,7 +590,7 @@ DcfManager::AccessTimeout (void)
  816. }
  817. Time
  818. -DcfManager::GetAccessGrantStart (void) const
  819. +DcfManager::GetAccessGrantStart (DcfState *state) const
  820. {
  821. NS_LOG_FUNCTION (this);
  822. Time rxAccessStart;
  823. @@ -587,13 +608,15 @@ DcfManager::GetAccessGrantStart (void) const
  824. }
  825. Time busyAccessStart = m_lastBusyStart + m_lastBusyDuration + m_sifs;
  826. Time txAccessStart = m_lastTxStart + m_lastTxDuration + m_sifs;
  827. + Time txNavAccessStart = m_grantedState == state ? Seconds(0) : m_lastTxStart + m_lastTxDuration + m_lastTxNavDuration + m_sifs;
  828. Time navAccessStart = m_lastNavStart + m_lastNavDuration + m_sifs;
  829. - Time ackTimeoutAccessStart = m_lastAckTimeoutEnd + m_sifs;
  830. + Time ackTimeoutAccessStart = m_grantedState == state ? m_lastAckTimeoutEnd + m_sifs : Seconds(0);
  831. Time ctsTimeoutAccessStart = m_lastCtsTimeoutEnd + m_sifs;
  832. Time switchingAccessStart = m_lastSwitchingStart + m_lastSwitchingDuration + m_sifs;
  833. Time accessGrantedStart = MostRecent (rxAccessStart,
  834. busyAccessStart,
  835. txAccessStart,
  836. + txNavAccessStart,
  837. navAccessStart,
  838. ackTimeoutAccessStart,
  839. ctsTimeoutAccessStart,
  840. @@ -612,7 +635,7 @@ DcfManager::GetBackoffStartFor (DcfState *state)
  841. {
  842. NS_LOG_FUNCTION (this << state);
  843. Time mostRecentEvent = MostRecent (state->GetBackoffStart (),
  844. - GetAccessGrantStart () + MicroSeconds (state->GetAifsn () * m_slotTimeUs));
  845. + GetAccessGrantStart (state) + MicroSeconds (state->GetAifsn () * m_slotTimeUs));
  846. return mostRecentEvent;
  847. }
  848. @@ -878,6 +901,12 @@ DcfManager::NotifyNavStartNow (Time duration)
  849. m_lastNavDuration = duration;
  850. }
  851. }
  852. +void
  853. +DcfManager::NotifyTxNavStartNow (Time duration)
  854. +{
  855. + NS_LOG_FUNCTION (this << duration);
  856. + m_lastTxNavDuration = duration;
  857. +}
  858. void
  859. DcfManager::NotifyAckTimeoutStartNow (Time duration)
  860. diff --git a/src/wifi/model/dcf-manager.h b/src/wifi/model/dcf-manager.h
  861. index 10ea55b..feacde1 100644
  862. --- a/src/wifi/model/dcf-manager.h
  863. +++ b/src/wifi/model/dcf-manager.h
  864. @@ -383,6 +383,12 @@ public:
  865. */
  866. void NotifyNavStartNow (Time duration);
  867. /**
  868. + * \param duration the value of the transmitted NAV.
  869. + *
  870. + * Called at start of tx
  871. + */
  872. + void NotifyTxNavStartNow (Time duration);
  873. + /**
  874. * Notify that ACK timer has started for the given duration.
  875. *
  876. * \param duration
  877. @@ -467,12 +473,27 @@ private:
  878. */
  879. Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const;
  880. /**
  881. + * Return the most recent time.
  882. + *
  883. + * \param a
  884. + * \param b
  885. + * \param c
  886. + * \param d
  887. + * \param e
  888. + * \param f
  889. + * \param g
  890. + * \param h
  891. + *
  892. + * \return the most recent time
  893. + */
  894. + Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g, Time h) const;
  895. + /**
  896. * Access will never be granted to the medium _before_
  897. * the time returned by this method.
  898. *
  899. * \returns the absolute time at which access could start to be granted
  900. */
  901. - Time GetAccessGrantStart (void) const;
  902. + Time GetAccessGrantStart (DcfState *state) const;
  903. /**
  904. * Return the time when the backoff procedure
  905. * started for the given DcfState.
  906. @@ -518,10 +539,12 @@ private:
  907. typedef std::vector<DcfState *> States;
  908. States m_states;
  909. + DcfState *m_grantedState;
  910. Time m_lastAckTimeoutEnd;
  911. Time m_lastCtsTimeoutEnd;
  912. Time m_lastNavStart;
  913. Time m_lastNavDuration;
  914. + Time m_lastTxNavDuration;
  915. Time m_lastRxStart;
  916. Time m_lastRxDuration;
  917. bool m_lastRxReceivedOk;
  918. diff --git a/src/wifi/model/edca-txop-n.cc b/src/wifi/model/edca-txop-n.cc
  919. index e4f7ab5..1e6aafa 100644
  920. --- a/src/wifi/model/edca-txop-n.cc
  921. +++ b/src/wifi/model/edca-txop-n.cc
  922. @@ -470,7 +470,7 @@ EdcaTxopN::RemoveRetransmitPacket (uint8_t tid, Mac48Address recipient, uint16_t
  923. }
  924. void
  925. -EdcaTxopN::NotifyAccessGranted (void)
  926. +EdcaTxopN::EnsurePacketDequeued (void)
  927. {
  928. NS_LOG_FUNCTION (this);
  929. if (m_currentPacket == 0)
  930. @@ -520,6 +520,13 @@ EdcaTxopN::NotifyAccessGranted (void)
  931. }
  932. }
  933. }
  934. +}
  935. +
  936. +void
  937. +EdcaTxopN::NotifyAccessGranted (void)
  938. +{
  939. + NS_LOG_FUNCTION (this);
  940. + EnsurePacketDequeued();
  941. MacLowTransmissionParameters params;
  942. params.DisableOverrideDurationId ();
  943. if (m_currentHdr.GetAddr1 ().IsGroup ())
  944. @@ -643,7 +650,11 @@ EdcaTxopN::NotifyAccessGranted (void)
  945. void EdcaTxopN::NotifyInternalCollision (void)
  946. {
  947. NS_LOG_FUNCTION (this);
  948. - NotifyCollision ();
  949. + std::cout << "IC: " << "ac = ???" << ", seq = ??? " << std::endl;
  950. + std::cout << "RE: " << "ac = ???" << ", seq = ??? " << std::endl;
  951. + EnsurePacketDequeued ();
  952. + m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  953. + MissedAck();
  954. }
  955. void
  956. @@ -821,7 +832,7 @@ EdcaTxopN::MissedAck (void)
  957. if (!NeedDataRetransmission ())
  958. {
  959. NS_LOG_DEBUG ("Ack Fail");
  960. - m_stationManager->ReportFinalDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
  961. + m_stationManager->ReportFinalDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  962. bool resetCurrentPacket = true;
  963. if (!m_txFailedCallback.IsNull ())
  964. {
  965. diff --git a/src/wifi/model/edca-txop-n.h b/src/wifi/model/edca-txop-n.h
  966. index ad5917f..2127c1f 100644
  967. --- a/src/wifi/model/edca-txop-n.h
  968. +++ b/src/wifi/model/edca-txop-n.h
  969. @@ -203,6 +203,7 @@ public:
  970. * false otherwise
  971. */
  972. bool NeedsAccess (void) const;
  973. + void EnsurePacketDequeued (void);
  974. /**
  975. * Notify the EDCAF that access has been granted.
  976. */
  977. diff --git a/src/wifi/model/mac-low.cc b/src/wifi/model/mac-low.cc
  978. index d968de8..07683bc 100644
  979. --- a/src/wifi/model/mac-low.cc
  980. +++ b/src/wifi/model/mac-low.cc
  981. @@ -1549,6 +1549,15 @@ MacLow::DoNavStartNow (Time duration)
  982. }
  983. void
  984. +MacLow::NotifyTxNavStartNow (Time duration)
  985. +{
  986. + for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++)
  987. + {
  988. + (*i)->TxNavStart (duration);
  989. + }
  990. +}
  991. +
  992. +void
  993. MacLow::NotifyAckTimeoutStartNow (Time duration)
  994. {
  995. for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++)
  996. @@ -1595,6 +1604,7 @@ MacLow::ForwardDown (Ptr<const Packet> packet, const WifiMacHeader* hdr,
  997. ", mode=" << txVector.GetMode () <<
  998. ", duration=" << hdr->GetDuration () <<
  999. ", seq=0x" << std::hex << m_currentHdr.GetSequenceControl () << std::dec);
  1000. + NotifyTxNavStartNow(hdr->GetDuration());
  1001. if (!m_ampdu || hdr->IsRts ())
  1002. {
  1003. m_phy->SendPacket (packet, txVector, preamble, 0, 0);
  1004. @@ -1701,7 +1711,7 @@ MacLow::NormalAckTimeout (void)
  1005. /// \todo should check that there was no rx start before now.
  1006. /// we should restart a new ack timeout now until the expected
  1007. /// end of rx if there was a rx start before now.
  1008. - m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
  1009. + m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  1010. MacLowTransmissionListener *listener = m_listener;
  1011. m_listener = 0;
  1012. m_sentMpdus = 0;
  1013. @@ -1714,7 +1724,7 @@ void
  1014. MacLow::FastAckTimeout (void)
  1015. {
  1016. NS_LOG_FUNCTION (this);
  1017. - m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
  1018. + m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  1019. MacLowTransmissionListener *listener = m_listener;
  1020. m_listener = 0;
  1021. if (m_phy->IsStateIdle ())
  1022. @@ -1734,7 +1744,7 @@ MacLow::BlockAckTimeout (void)
  1023. NS_LOG_FUNCTION (this);
  1024. NS_LOG_DEBUG ("block ack timeout");
  1025. - m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
  1026. + m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  1027. MacLowTransmissionListener *listener = m_listener;
  1028. m_listener = 0;
  1029. m_sentMpdus = 0;
  1030. @@ -1747,7 +1757,7 @@ void
  1031. MacLow::SuperFastAckTimeout ()
  1032. {
  1033. NS_LOG_FUNCTION (this);
  1034. - m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
  1035. + m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr, m_currentPacket);
  1036. MacLowTransmissionListener *listener = m_listener;
  1037. m_listener = 0;
  1038. if (m_phy->IsStateIdle ())
  1039. @@ -1999,7 +2009,8 @@ MacLow::SendDataPacket (void)
  1040. }
  1041. ForwardDown (m_currentPacket, &m_currentHdr, dataTxVector, preamble);
  1042. - m_currentPacket = 0;
  1043. +// KLUDGE: uncommented to be able to pass it to reportDataFailed
  1044. +// m_currentPacket = 0;
  1045. }
  1046. bool
  1047. diff --git a/src/wifi/model/mac-low.h b/src/wifi/model/mac-low.h
  1048. index 53e5a25..4c9bb69 100644
  1049. --- a/src/wifi/model/mac-low.h
  1050. +++ b/src/wifi/model/mac-low.h
  1051. @@ -165,6 +165,12 @@ public:
  1052. */
  1053. virtual void NavReset (Time duration) = 0;
  1054. /**
  1055. + * Notify that TXNAV has started for the given duration.
  1056. + *
  1057. + * \param duration duration of TXNAV timer
  1058. + */
  1059. + virtual void TxNavStart (Time duration) = 0;
  1060. + /**
  1061. * Notify that ACK timeout has started for a given duration.
  1062. *
  1063. * \param duration duration of ACK timeout
  1064. @@ -1045,6 +1051,12 @@ private:
  1065. */
  1066. bool IsNavZero (void) const;
  1067. /**
  1068. + * Start TXNAV with the given duration.
  1069. + *
  1070. + * \param duration
  1071. + */
  1072. + void NotifyTxNavStartNow (Time duration);
  1073. + /**
  1074. * Notify DcfManager (via DcfListener) that
  1075. * ACK timer should be started for the given
  1076. * duration.
  1077. diff --git a/src/wifi/model/random-stream.cc b/src/wifi/model/random-stream.cc
  1078. index 3fe8619..83cdccc 100644
  1079. --- a/src/wifi/model/random-stream.cc
  1080. +++ b/src/wifi/model/random-stream.cc
  1081. @@ -20,6 +20,7 @@
  1082. #include "random-stream.h"
  1083. #include "ns3/assert.h"
  1084. +#include "ns3/simulator.h"
  1085. #include <cmath>
  1086. namespace ns3 {
  1087. @@ -28,22 +29,27 @@ RandomStream::~RandomStream ()
  1088. {
  1089. }
  1090. -
  1091. RealRandomStream::RealRandomStream ()
  1092. {
  1093. m_stream = CreateObject<UniformRandomVariable> ();
  1094. + m_lcg32.initialize(0, 0, 0);
  1095. }
  1096. uint32_t
  1097. RealRandomStream::GetNext (uint32_t min, uint32_t max)
  1098. {
  1099. - return m_stream->GetInteger (min, max);
  1100. + NS_ASSERT(min == 0);
  1101. + uint32_t v = m_lcg32.intRand(max + 1);
  1102. + static const char*AC[] = {"AC_BE_NQOS", "AC_VO", "AC_VI", "AC_BK", "AC_BE"};
  1103. + std::cout << "GB: " << "ac = " << AC[m_lcg32.id % 5] << ", cw = " << max << ", slots = " << v << ", nth = " << m_lcg32.getNumbersDrawn() << std::endl;
  1104. + return v;
  1105. }
  1106. int64_t
  1107. RealRandomStream::AssignStreams (int64_t stream)
  1108. {
  1109. m_stream->SetStream (stream);
  1110. + m_lcg32.initialize(0, stream, 0);
  1111. return 1;
  1112. }
  1113. diff --git a/src/wifi/model/random-stream.h b/src/wifi/model/random-stream.h
  1114. index 6998d89..e76c8fd 100644
  1115. --- a/src/wifi/model/random-stream.h
  1116. +++ b/src/wifi/model/random-stream.h
  1117. @@ -24,6 +24,7 @@
  1118. #include <stdint.h>
  1119. #include <list>
  1120. #include "ns3/random-variable-stream.h"
  1121. +#include "ns3/clcg32.h"
  1122. namespace ns3 {
  1123. @@ -60,6 +61,9 @@ public:
  1124. class RealRandomStream : public RandomStream
  1125. {
  1126. +private:
  1127. + cLCG32 m_lcg32;
  1128. +
  1129. public:
  1130. RealRandomStream ();
  1131. virtual uint32_t GetNext (uint32_t min, uint32_t max);
  1132. diff --git a/src/wifi/model/wifi-mac.cc b/src/wifi/model/wifi-mac.cc
  1133. index a5bc952..287229a 100644
  1134. --- a/src/wifi/model/wifi-mac.cc
  1135. +++ b/src/wifi/model/wifi-mac.cc
  1136. @@ -331,8 +331,8 @@ WifiMac::Configure80211a (void)
  1137. SetSlot (MicroSeconds (9));
  1138. SetEifsNoDifs (MicroSeconds (16 + 44));
  1139. SetPifs (MicroSeconds (16 + 9));
  1140. - SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
  1141. - SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
  1142. + SetCtsTimeout (MicroSeconds (16 + 44 + 9));
  1143. + SetAckTimeout (MicroSeconds (16 + 44 + 9));
  1144. }
  1145. void
  1146. diff --git a/src/wifi/model/wifi-remote-station-manager.cc b/src/wifi/model/wifi-remote-station-manager.cc
  1147. index e748f54..89f41a9 100644
  1148. --- a/src/wifi/model/wifi-remote-station-manager.cc
  1149. +++ b/src/wifi/model/wifi-remote-station-manager.cc
  1150. @@ -30,6 +30,7 @@
  1151. #include "ns3/wifi-phy.h"
  1152. #include "ns3/wifi-mac.h"
  1153. #include "ns3/trace-source-accessor.h"
  1154. +#include "ns3/seq-ts-header.h"
  1155. #include "wifi-mac-header.h"
  1156. #include "wifi-mac-trailer.h"
  1157. @@ -707,8 +708,27 @@ WifiRemoteStationManager::ReportRtsFailed (Mac48Address address, const WifiMacHe
  1158. DoReportRtsFailed (station);
  1159. }
  1160. +static int getSeq(const Ptr<const Packet> packet)
  1161. +{
  1162. + int seq = -1;
  1163. + if (packet.operator->()) {
  1164. + PacketMetadata::ItemIterator i = packet->BeginItem();
  1165. + while (i.HasNext()) {
  1166. + PacketMetadata::Item item = i.Next();
  1167. + if (!item.isFragment && item.type == PacketMetadata::Item::HEADER) {
  1168. + if (item.tid == SeqTsHeader::GetTypeId()) {
  1169. + SeqTsHeader header;
  1170. + header.Deserialize(item.current);
  1171. + seq = header.GetSeq();
  1172. + }
  1173. + }
  1174. + }
  1175. + }
  1176. + return seq;
  1177. +}
  1178. +
  1179. void
  1180. -WifiRemoteStationManager::ReportDataFailed (Mac48Address address, const WifiMacHeader *header)
  1181. +WifiRemoteStationManager::ReportDataFailed (Mac48Address address, const WifiMacHeader *header, const Ptr<const Packet> packet)
  1182. {
  1183. NS_LOG_FUNCTION (this << address << *header);
  1184. NS_ASSERT (!address.IsGroup ());
  1185. @@ -716,6 +736,10 @@ WifiRemoteStationManager::ReportDataFailed (Mac48Address address, const WifiMacH
  1186. station->m_slrc++;
  1187. m_macTxDataFailed (address);
  1188. DoReportDataFailed (station);
  1189. + static const char *ac[] = {"AC_BE", "AC_BK", "AC_VI", "AC_VO", "AC_BE_NQOS", "???"};
  1190. + int index = header->IsQosData() ? QosUtilsMapTidToAc(header->GetQosTid()) : 5;
  1191. + int seq = getSeq(packet);
  1192. + std::cout << "RE: " << "ac = " << ac[index] << ", seq = " << seq << ", num = " << station->m_slrc << std::endl;
  1193. }
  1194. void
  1195. @@ -755,7 +779,7 @@ WifiRemoteStationManager::ReportFinalRtsFailed (Mac48Address address, const Wifi
  1196. }
  1197. void
  1198. -WifiRemoteStationManager::ReportFinalDataFailed (Mac48Address address, const WifiMacHeader *header)
  1199. +WifiRemoteStationManager::ReportFinalDataFailed (Mac48Address address, const WifiMacHeader *header, const Ptr<const Packet> packet)
  1200. {
  1201. NS_LOG_FUNCTION (this << address << *header);
  1202. NS_ASSERT (!address.IsGroup ());
  1203. @@ -764,6 +788,10 @@ WifiRemoteStationManager::ReportFinalDataFailed (Mac48Address address, const Wif
  1204. station->m_slrc = 0;
  1205. m_macTxFinalDataFailed (address);
  1206. DoReportFinalDataFailed (station);
  1207. + static const char *ac[] = {"AC_BE", "AC_BK", "AC_VI", "AC_VO", "AC_BE_NQOS", "???"};
  1208. + int index = header->IsQosData() ? QosUtilsMapTidToAc(header->GetQosTid()) : 5;
  1209. + int seq = getSeq(packet);
  1210. + std::cout << "CA: " << "ac = " << ac[index] << ", seq = " << seq << std::endl;
  1211. }
  1212. void
  1213. diff --git a/src/wifi/model/wifi-remote-station-manager.h b/src/wifi/model/wifi-remote-station-manager.h
  1214. index e6136cc..bda2b27 100644
  1215. --- a/src/wifi/model/wifi-remote-station-manager.h
  1216. +++ b/src/wifi/model/wifi-remote-station-manager.h
  1217. @@ -437,7 +437,7 @@ public:
  1218. * \param address the address of the receiver
  1219. * \param header MAC header of the DATA packet
  1220. */
  1221. - void ReportDataFailed (Mac48Address address, const WifiMacHeader *header);
  1222. + void ReportDataFailed (Mac48Address address, const WifiMacHeader *header, const Ptr<const Packet> packet);
  1223. /**
  1224. * Should be invoked whenever we receive the Cts associated to an RTS
  1225. * we just sent. Note that we also get the SNR of the RTS we sent since
  1226. @@ -478,7 +478,7 @@ public:
  1227. * \param address the address of the receiver
  1228. * \param header MAC header of the DATA packet
  1229. */
  1230. - void ReportFinalDataFailed (Mac48Address address, const WifiMacHeader *header);
  1231. + void ReportFinalDataFailed (Mac48Address address, const WifiMacHeader *header, const Ptr<const Packet> packet);
  1232. /**
  1233. * \param address remote address