Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.79 KB | None | 0 0
  1. /*
  2. * Copyright (c) 2015, 2016 IMDEA Networks Institute
  3. * Author: Hany Assasa <hany.assasa@gmail.com>
  4. */
  5. #include "ns3/applications-module.h"
  6. #include "ns3/core-module.h"
  7. #include "ns3/internet-module.h"
  8. #include "ns3/mobility-module.h"
  9. #include "ns3/network-module.h"
  10. #include "ns3/wifi-module.h"
  11. #include "common-functions.h"
  12.  
  13. /**
  14. * Simulation Objective:
  15. * This script is used to evaluate IEEE 802.11ad relay operation for UDP connection using Link Switching Type working in
  16. * Half Duplex Decode and Forward relay mode. IEEE 802.11ad defines relay operation mode for SP protection against sudden
  17. * link interruptions.
  18. *
  19. * Network Topology:
  20. * The scenario consists of 3 DMG STAs (Two REDS + 1 RDS) and one PCP/AP.
  21. *
  22. * DMG AP (0,1)
  23. *
  24. *
  25. * West REDS (-1,0) East REDS (1,0)
  26. *
  27. *
  28. * RDS (0,-1)
  29. *
  30. * West REDS2 (-1,-2) East REDS2 (1,-2)
  31. *
  32. *
  33. * RDS2 (0,-3)
  34. * Simulation Description:
  35. * At the beginning each station requests information regarding the capabilities of all other stations. Once this is completed
  36. * we initiate Relay Discovery Procedure. During the relay discovery procedure, the Source DMG performs Beamforming Training with
  37. * the destination REDS and all the available RDSs. After the source REDS completes BF with the destination REDS it can establish
  38. * service period for direct communication without gonig throught the DMG PCP/AP.
  39. *
  40. * We establish forward and reverse SP allocations since the standard supports only unicast transmission for single SP allocation.
  41. * As a result, we create the following two SP allocations:
  42. *
  43. * SP1 for Forward Traffic : West REDS -----> East REDS (8ms)
  44. * SP2 for Reverse Traffic : East REDS -----> West REDS (8ms)
  45. * SP1 for Forward Traffic : West REDS1 -----> East REDS2 (8ms)
  46. * SP2 for Reverse Traffic : East REDS1 -----> West REDS2 (8ms)
  47. *
  48. * The user is able to define his/her own algorithm for the selection of the best Relay Station (RDS) between the source REDS
  49. * and the destination REDS for data forwarding.
  50. *
  51. * Running Simulation:
  52. * To use this script simply type the following run command:
  53. * ./waf --run "evaluate_halfduplex_relay_udp --dataRate=800Mbps --simulationTime=10 --pcap=true"
  54. * Note: The default script switches the link for SP1 only.
  55. *
  56. * To switch the link for SP2, run the following command:
  57. * ./waf --run "evaluate_halfduplex_relay_udp --switchReverse=true --simulationTime=10 --pcap=true"
  58. *
  59. * Output:
  60. * The simulation generates the following traces:
  61. * 1. PCAP traces for each station.
  62. */
  63.  
  64. NS_LOG_COMPONENT_DEFINE ("EvaluateHalfDuplexRelayOperationUDP");
  65.  
  66. using namespace ns3;
  67. using namespace std;
  68.  
  69. /** West Node Allocation Variables **/
  70. uint64_t westEastLastTotalRx = 0;
  71. double westEastAverageThroughput = 0;
  72. /** South Node Allocation Variables **/
  73. uint64_t eastWestTotalRx = 0;
  74. double eastWestAverageThroughput = 0;
  75.  
  76. /** West Node2 Allocation Variables **/
  77. uint64_t westEastLastTotalRx2 = 0;
  78. double westEastAverageThroughput2 = 0;
  79. /** South Node2 Allocation Variables **/
  80. uint64_t eastWestTotalRx2 = 0;
  81. double eastWestAverageThroughput2 = 0;
  82.  
  83. Ptr<PacketSink> sink1, sink2, sink3, sink4;
  84.  
  85. /* DMG Devices */
  86. Ptr<WifiNetDevice> apWifiNetDevice;
  87. Ptr<WifiNetDevice> westRedsNetDevice;
  88. Ptr<WifiNetDevice> eastRedsNetDevice;
  89. Ptr<WifiNetDevice> rdsNetDevice;
  90. Ptr<WifiNetDevice> westRedsNetDevice2;
  91. Ptr<WifiNetDevice> eastRedsNetDevice2;
  92. Ptr<WifiNetDevice> rdsNetDevice2;
  93.  
  94. Ptr<DmgApWifiMac> apWifiMac;
  95. Ptr<DmgStaWifiMac> westRedsMac;
  96. Ptr<DmgStaWifiMac> eastRedsMac;
  97. Ptr<DmgStaWifiMac> rdsMac;
  98. Ptr<DmgStaWifiMac> westRedsMac2;
  99. Ptr<DmgStaWifiMac> eastRedsMac2;
  100. Ptr<DmgStaWifiMac> rdsMac2;
  101.  
  102. /*** Access Point Variables ***/
  103. uint8_t assoicatedStations = 0; /* Total number of assoicated stations with the AP */
  104. uint8_t stationsTrained = 0; /* Number of BF trained stations */
  105. bool scheduledStaticPeriods = false; /* Flag to indicate whether we scheduled Static Service Periods or not */
  106. uint32_t channelMeasurementResponses = 0;
  107.  
  108. /*** Service Period Parameters ***/
  109. uint16_t sp1Duration = 8000; /* The duration of the forward SP allocation in MicroSeconds */
  110. uint16_t sp2Duration = 8000; /* The duration of the reverse SP allocation in MicroSeconds */
  111. uint8_t spBlocks = 3; /* The number of SP allocations in one DTI */
  112. uint16_t cbapDuration = 10000; /* The duration of the allocated CBAP period in MicroSeconds (10ms) */
  113.  
  114. bool switchForward = true; /* Switch the forward link. */
  115. bool switchReverse = false; /* Switch the reverse link. */
  116.  
  117. typedef enum {
  118. FORWARD_DIRECTION = 0,
  119. REVERSE_DIRECTION = 1,
  120. } RelayDiretion;
  121.  
  122. RelayDiretion m_relayDirection = FORWARD_DIRECTION;
  123.  
  124. double
  125. CalculateSingleStreamThroughput (Ptr<PacketSink> sink, uint64_t &lastTotalRx, double &averageThroughput)
  126. {
  127. double thr = (sink->GetTotalRx() - lastTotalRx) * (double) 8/1e5; /* Convert Application RX Packets to MBits. */
  128. lastTotalRx = sink->GetTotalRx ();
  129. averageThroughput += thr;
  130. return thr;
  131. }
  132.  
  133. void
  134. CalculateThroughput (void)
  135. {
  136. double thr1, thr2;
  137. thr1 = CalculateSingleStreamThroughput (sink1, westEastLastTotalRx, westEastAverageThroughput);
  138. thr2 = CalculateSingleStreamThroughput (sink2, eastWestTotalRx, eastWestAverageThroughput);
  139. std::cout << Simulator::Now ().GetSeconds () << '\t' << thr1 << '\t'<< thr2 << std::endl;
  140. Simulator::Schedule (MilliSeconds (100), &CalculateThroughput);
  141. }
  142.  
  143. void
  144. CalculateThroughput2 (void)
  145. {
  146. double thr3, thr4;
  147. thr3 = CalculateSingleStreamThroughput (sink1, westEastLastTotalRx2, westEastAverageThroughput2);
  148. thr4 = CalculateSingleStreamThroughput (sink2, eastWestTotalRx2, eastWestAverageThroughput2);
  149. std::cout << Simulator::Now ().GetSeconds () << '\t' << thr3 << '\t'<< thr4 << std::endl;
  150. Simulator::Schedule (MilliSeconds (100), &CalculateThroughput2);
  151. }
  152.  
  153. void
  154. RlsCompleted (Ptr<DmgStaWifiMac> staWifiMac, Mac48Address address)
  155. {
  156. if (staWifiMac == westRedsMac)
  157. {
  158. std::cout << "West STA: RLS Procedure is completed with RDS=" << address << " at " << Simulator::Now () << std::endl;
  159. std::cout << "East STA: Execute RLS procedure" << std::endl;
  160. m_relayDirection = REVERSE_DIRECTION;
  161. Simulator::ScheduleNow (&DmgStaWifiMac::StartRelayDiscovery, eastRedsMac, westRedsMac->GetAddress ());
  162. }
  163. else
  164. {
  165. uint32_t startTime = 0;
  166. std::cout << "East REDS: RLS Procedure is completed with RDS=" << address << " at " << Simulator::Now () << std::endl;
  167.  
  168. /* Assetion check values */
  169. NS_ASSERT_MSG (((sp1Duration + sp2Duration) * (spBlocks)) < apWifiMac->GetDTIDuration (),
  170. "Allocations cannot exceed DTI period");
  171.  
  172. /* Schedule a CBAP allocation for communication between DMG STAs */
  173. startTime = apWifiMac->AllocateCbapPeriod (true, startTime, cbapDuration);
  174.  
  175. /* Protection Period */
  176. startTime += GUARD_TIME.GetMicroSeconds ()/2;
  177.  
  178. /* Schedule SP allocations for data communication between the source REDS and the destination REDS */
  179. std::cout << "Allocating static service period allocation for communication between "
  180. << westRedsMac->GetAddress () << " and " << eastRedsMac->GetAddress () << std::endl;
  181. startTime = apWifiMac->AddAllocationPeriod (1, SERVICE_PERIOD_ALLOCATION, true,
  182. westRedsMac->GetAssociationID (), eastRedsMac->GetAssociationID (),
  183. startTime, sp1Duration, sp2Duration, spBlocks);
  184.  
  185. /* Protection Period */
  186. startTime += GUARD_TIME.GetMicroSeconds ()/2;
  187.  
  188. std::cout << "Allocating static service period allocation for communication between "
  189. << eastRedsMac->GetAddress () << " and " << westRedsMac->GetAddress () << std::endl;
  190.  
  191. startTime = apWifiMac->AddAllocationPeriod (2, SERVICE_PERIOD_ALLOCATION, true,
  192. eastRedsMac->GetAssociationID (), westRedsMac->GetAssociationID (),
  193. startTime, sp2Duration, sp1Duration, spBlocks);
  194. }
  195. }
  196.  
  197. void
  198. RlsCompleted2 (Ptr<DmgStaWifiMac> staWifiMac, Mac48Address address)
  199. {
  200. if (staWifiMac == westRedsMac2)
  201. {
  202. std::cout << "West STA2: RLS Procedure is completed with RDS=" << address << " at " << Simulator::Now () << std::endl;
  203. std::cout << "East STA2: Execute RLS procedure" << std::endl;
  204. m_relayDirection = REVERSE_DIRECTION;
  205. Simulator::ScheduleNow (&DmgStaWifiMac::StartRelayDiscovery, eastRedsMac2, westRedsMac2->GetAddress ());
  206. }
  207. else
  208. {
  209. uint32_t startTime = 0;
  210. std::cout << "East REDS2: RLS Procedure is completed with RDS2=" << address << " at " << Simulator::Now () << std::endl;
  211.  
  212. /* Assetion check values */
  213. NS_ASSERT_MSG (((sp1Duration + sp2Duration) * (spBlocks)) < apWifiMac->GetDTIDuration (),
  214. "Allocations cannot exceed DTI period");
  215.  
  216. /* Schedule a CBAP allocation for communication between DMG STAs */
  217. startTime = apWifiMac->AllocateCbapPeriod (true, startTime, cbapDuration);
  218.  
  219. /* Protection Period */
  220. startTime += GUARD_TIME.GetMicroSeconds ()/2;
  221.  
  222. /* Schedule SP allocations for data communication between the source REDS and the destination REDS */
  223. std::cout << "Allocating static service period allocation for communication between "
  224. << westRedsMac2->GetAddress () << " and " << eastRedsMac2->GetAddress () << std::endl;
  225. startTime = apWifiMac->AddAllocationPeriod (1, SERVICE_PERIOD_ALLOCATION, true,
  226. westRedsMac2->GetAssociationID (), eastRedsMac2->GetAssociationID (),
  227. startTime, sp1Duration, sp2Duration, spBlocks);
  228.  
  229. /* Protection Period */
  230. startTime += GUARD_TIME.GetMicroSeconds ()/2;
  231.  
  232. std::cout << "Allocating static service period allocation for communication between "
  233. << eastRedsMac2->GetAddress () << " and " << westRedsMac->GetAddress () << std::endl;
  234.  
  235. startTime = apWifiMac->AddAllocationPeriod (2, SERVICE_PERIOD_ALLOCATION, true,
  236. eastRedsMac2->GetAssociationID (), westRedsMac2->GetAssociationID (),
  237. startTime, sp2Duration, sp1Duration, spBlocks);
  238. }
  239. }
  240.  
  241. void
  242. StartChannelMeasurements (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac,
  243. Ptr<DmgStaWifiMac> staWifiMac, Mac48Address address,
  244. string srcName, string dstName)
  245. {
  246. if ((rdsMac->GetAddress () == staWifiMac->GetAddress ()) &&
  247. ((srcRedsMac->GetAddress () == address) || (dstRedsMac->GetAddress () == address)))
  248. {
  249. stationsTrained++;
  250. if (stationsTrained == 2)
  251. {
  252. stationsTrained = 0;
  253. std::cout << "RDS: Completed BF Training with both " << srcName << " and " << dstName << std::endl;
  254. /* Send Channel Measurement Request from the source REDS to the RDS */
  255. std::cout << srcName << ": Send Channel Measurement Request to the candidate RDS" << std::endl;
  256. srcRedsMac->SendChannelMeasurementRequest (rdsMac->GetAddress (), 10);
  257. }
  258. }
  259. else if ((srcRedsMac->GetAddress () == staWifiMac->GetAddress ()) && (dstRedsMac->GetAddress () == address))
  260. {
  261. std::cout << srcName << ": Completed BF Training with " << dstName << std::endl;
  262. /* Send Channel Measurement Request to the destination REDS */
  263. std::cout << srcName << ": Send Channel Measurement Request to " << dstName << std::endl;
  264. srcRedsMac->SendChannelMeasurementRequest ((dstRedsMac->GetAddress ()), 10);
  265. }
  266. }
  267.  
  268. void
  269. StartChannelMeasurements2 (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac,
  270. Ptr<DmgStaWifiMac> staWifiMac, Mac48Address address,
  271. string srcName, string dstName)
  272. {
  273. if ((rdsMac2->GetAddress () == staWifiMac->GetAddress ()) &&
  274. ((srcRedsMac->GetAddress () == address) || (dstRedsMac->GetAddress () == address)))
  275. {
  276. stationsTrained++;
  277. if (stationsTrained == 2)
  278. {
  279. stationsTrained = 0;
  280. std::cout << "RDS: Completed BF Training with both " << srcName << " and " << dstName << std::endl;
  281. /* Send Channel Measurement Request from the source REDS to the RDS */
  282. std::cout << srcName << ": Send Channel Measurement Request to the candidate RDS" << std::endl;
  283. srcRedsMac->SendChannelMeasurementRequest (rdsMac2->GetAddress (), 10);
  284. }
  285. }
  286. else if ((srcRedsMac->GetAddress () == staWifiMac->GetAddress ()) && (dstRedsMac->GetAddress () == address))
  287. {
  288. std::cout << srcName << ": Completed BF Training with " << dstName << std::endl;
  289. /* Send Channel Measurement Request to the destination REDS */
  290. std::cout << srcName << ": Send Channel Measurement Request to " << dstName << std::endl;
  291. srcRedsMac->SendChannelMeasurementRequest ((dstRedsMac->GetAddress ()), 10);
  292. }
  293. }
  294.  
  295. void
  296. SLSCompleted (Ptr<DmgStaWifiMac> staWifiMac, Mac48Address address,
  297. ChannelAccessPeriod accessPeriod, SECTOR_ID sectorId, ANTENNA_ID antennaId)
  298. {
  299. if (accessPeriod == CHANNEL_ACCESS_DTI)
  300. {
  301. std::cout << "DMG STA " << staWifiMac->GetAddress () << " completed SLS phase with DMG STA " << address << std::endl;
  302. if (m_relayDirection == FORWARD_DIRECTION)
  303. {
  304. StartChannelMeasurements (westRedsMac, eastRedsMac, staWifiMac, address, "West STA", "East STA");
  305. }
  306. else
  307. {
  308. StartChannelMeasurements (eastRedsMac, westRedsMac, staWifiMac, address, "East STA", "West STA");
  309. }
  310. }
  311. }
  312.  
  313. void
  314. SLSCompleted2 (Ptr<DmgStaWifiMac> staWifiMac, Mac48Address address,
  315. ChannelAccessPeriod accessPeriod, SECTOR_ID sectorId, ANTENNA_ID antennaId)
  316. {
  317. if (accessPeriod == CHANNEL_ACCESS_DTI)
  318. {
  319. std::cout << "DMG STA " << staWifiMac->GetAddress () << " completed SLS phase with DMG STA " << address << std::endl;
  320. if (m_relayDirection == FORWARD_DIRECTION)
  321. {
  322. StartChannelMeasurements2 (westRedsMac2, eastRedsMac2, staWifiMac, address, "West STA2", "East STA2");
  323. }
  324. else
  325. {
  326. StartChannelMeasurements2 (eastRedsMac2, westRedsMac2, staWifiMac, address, "East STA2", "West STA2");
  327. }
  328. }
  329. }
  330.  
  331. void
  332. ProcessChannelReports (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac, Mac48Address address,
  333. string srcName, string dstName)
  334. {
  335. if (address == rdsMac->GetAddress ())
  336. {
  337. std::cout << srcName << ": received Channel Measurement Response from the RDS" << std::endl;
  338. /* TxSS for the Link Between the Source REDS + the Destination REDS */
  339. apWifiMac->AllocateBeamformingServicePeriod (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID (), 0, true);
  340. }
  341. else if (address == dstRedsMac->GetAddress ())
  342. {
  343. std::cout << srcName << ": Received Channel Measurement Response from " << dstName << std::endl;
  344. std::cout << srcName << ": Execute RLS procedure" << std::endl;
  345. /* Initiate Relay Link Switch Procedure */
  346. Simulator::ScheduleNow (&DmgStaWifiMac::StartRlsProcedure, srcRedsMac);
  347. }
  348. }
  349.  
  350. void
  351. ProcessChannelReports2 (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac, Mac48Address address,
  352. string srcName, string dstName)
  353. {
  354. if (address == rdsMac2->GetAddress ())
  355. {
  356. std::cout << srcName << ": received Channel Measurement Response from the RDS" << std::endl;
  357. /* TxSS for the Link Between the Source REDS + the Destination REDS */
  358. apWifiMac->AllocateBeamformingServicePeriod (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID (), 0, true);
  359. }
  360. else if (address == dstRedsMac->GetAddress ())
  361. {
  362. std::cout << srcName << ": Received Channel Measurement Response from " << dstName << std::endl;
  363. std::cout << srcName << ": Execute RLS procedure" << std::endl;
  364. /* Initiate Relay Link Switch Procedure */
  365. Simulator::ScheduleNow (&DmgStaWifiMac::StartRlsProcedure, srcRedsMac);
  366. }
  367. }
  368.  
  369.  
  370. void
  371. ChannelReportReceived (Mac48Address address)
  372. {
  373. if (m_relayDirection == FORWARD_DIRECTION)
  374. {
  375. ProcessChannelReports (westRedsMac, eastRedsMac, address, "West STA", "East STA");
  376. }
  377. else
  378. {
  379. ProcessChannelReports (eastRedsMac, westRedsMac, address, "East STA", "West STA");
  380. }
  381. }
  382.  
  383. void
  384. ChannelReportReceived2 (Mac48Address address)
  385. {
  386. if (m_relayDirection == FORWARD_DIRECTION)
  387. {
  388. ProcessChannelReports (westRedsMac2, eastRedsMac2, address, "West STA2", "East STA2");
  389. }
  390. else
  391. {
  392. ProcessChannelReports (eastRedsMac2, westRedsMac2, address, "East STA2", "West STA2");
  393. }
  394. }
  395.  
  396. uint8_t
  397. SelectRelay (ChannelMeasurementInfoList rdsMeasurements, ChannelMeasurementInfoList dstRedsMeasurements, Mac48Address &rdsAddress)
  398. {
  399. /* Make relay selection decision based on channel measurements */
  400. rdsAddress = rdsMac->GetAddress ();
  401. return rdsMac->GetAssociationID ();
  402. }
  403.  
  404. uint8_t
  405. SelectRelay2 (ChannelMeasurementInfoList rdsMeasurements, ChannelMeasurementInfoList dstRedsMeasurements, Mac48Address &rdsAddress)
  406. {
  407. /* Make relay selection decision based on channel measurements */
  408. rdsAddress = rdsMac2->GetAddress ();
  409. return rdsMac2->GetAssociationID ();
  410. }
  411.  
  412.  
  413. void
  414. SwitchTransmissionLink (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac)
  415. {
  416. std::cout << "Switching transmission link from the Direct Link to the Relay Link for SP Allocation:"
  417. << "SRC AID=" << uint (srcRedsMac->GetAssociationID ())
  418. << ", DST AID=" << uint (dstRedsMac->GetAssociationID ()) << std::endl;
  419. rdsMac->SwitchTransmissionLink (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID ());
  420. srcRedsMac->SwitchTransmissionLink (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID ());
  421. dstRedsMac->SwitchTransmissionLink (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID ());
  422. }
  423.  
  424. void
  425. SwitchTransmissionLink2 (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac)
  426. {
  427. std::cout << "Switching transmission link from the Direct Link to the Relay Link for SP Allocation:"
  428. << "SRC AID=" << uint (srcRedsMac->GetAssociationID ())
  429. << ", DST AID=" << uint (dstRedsMac->GetAssociationID ()) << std::endl;
  430. rdsMac2->SwitchTransmissionLink (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID ());
  431. srcRedsMac->SwitchTransmissionLink (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID ());
  432. dstRedsMac->SwitchTransmissionLink (srcRedsMac->GetAssociationID (), dstRedsMac->GetAssociationID ());
  433. }
  434.  
  435.  
  436. void
  437. TearDownRelay (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac)
  438. {
  439. std::cout << "Tearing-down Relay Link for SP Allocation:"
  440. << "SRC AID=" << uint (srcRedsMac->GetAssociationID ())
  441. << ", DST AID=" << uint (dstRedsMac->GetAssociationID ()) << std::endl;
  442. srcRedsMac->TeardownRelay (srcRedsMac->GetAssociationID (),
  443. dstRedsMac->GetAssociationID (),
  444. rdsMac->GetAssociationID ());
  445. }
  446.  
  447. void
  448. TearDownRelay2 (Ptr<DmgStaWifiMac> srcRedsMac, Ptr<DmgStaWifiMac> dstRedsMac)
  449. {
  450. std::cout << "Tearing-down Relay Link for SP Allocation:"
  451. << "SRC AID=" << uint (srcRedsMac->GetAssociationID ())
  452. << ", DST AID=" << uint (dstRedsMac->GetAssociationID ()) << std::endl;
  453. srcRedsMac->TeardownRelay (srcRedsMac->GetAssociationID (),
  454. dstRedsMac->GetAssociationID (),
  455. rdsMac2->GetAssociationID ());
  456. }
  457.  
  458. /**
  459. * Callback method to log changes of the bytes in WifiMacQueue
  460. */
  461. void
  462. BytesInQueueTrace (Ptr<OutputStreamWrapper> stream, uint64_t oldVal, uint64_t newVal)
  463. {
  464. *stream->GetStream () << Simulator::Now ().GetSeconds () << " " << newVal << std::endl;
  465. }
  466.  
  467.  
  468. int
  469. main (int argc, char *argv[])
  470. {
  471. uint32_t payloadSize = 1472; /* Transport Layer Payload size in bytes. */
  472. string dataRate = "100Mbps"; /* Application Layer Data Rate. */
  473. uint32_t msduAggregationSize = 7935; /* The maximum aggregation size for A-MSDU in Bytes. */
  474. uint32_t queueSize = 1000; /* Wifi Mac Queue Size. */
  475. uint16_t firstPeriod = 4000; /* The duration of the RDS first period in MicroSeconds. */
  476. uint16_t secondPeriod = 4000; /* The duration of the RDS second period in MicroSeconds. */
  477. uint32_t switchTime = 4; /* The time we switch to the relay link in Seconds */
  478. uint32_t switchTime2 = 4; /* The time we switch to the relay2 link in Seconds */
  479. string phyMode = "DMG_MCS12"; /* Type of the Physical Layer. */
  480. bool verbose = false; /* Print Logging Information. */
  481. double simulationTime = 10; /* Simulation time in seconds. */
  482. bool pcapTracing = false; /* PCAP Tracing is enabled or not. */
  483.  
  484. /* Command line argument parser setup. */
  485. CommandLine cmd;
  486. cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
  487. cmd.AddValue ("dataRate", "Payload size in bytes", dataRate);
  488. cmd.AddValue ("msduAggregation", "The maximum aggregation size for A-MSDU in Bytes", msduAggregationSize);
  489. cmd.AddValue ("queueSize", "The size of the Wifi Mac Queue", queueSize);
  490. cmd.AddValue ("sp1Duration", "The duration of the forward SP allocation in MicroSeconds", sp1Duration);
  491. cmd.AddValue ("sp2Duration", "The duration of the reverse SP allocation in MicroSeconds", sp2Duration);
  492. cmd.AddValue ("spBlocks", "The number of blocks making up SP allocation", spBlocks);
  493. cmd.AddValue ("cbapDuration", "The duration of the allocated CBAP period in MicroSeconds (10ms)", cbapDuration);
  494. cmd.AddValue ("firstPeriod", "The duration of the RDS first period in MicroSeconds", firstPeriod);
  495. cmd.AddValue ("secondPeriod", "The duration of the RDS second period in MicroSeconds", secondPeriod);
  496. cmd.AddValue ("switchTime", "The time a which we switch from the direct link to the relay link", switchTime);
  497. cmd.AddValue ("switchTime2", "The time a which we switch from the direct link to the relay link", switchTime2);
  498. cmd.AddValue ("switchForward", "Switch the forward link", switchForward);
  499. cmd.AddValue ("switchReverse", "Switch the reverse link", switchReverse);
  500. cmd.AddValue ("phyMode", "The 802.11ad PHY Mode", phyMode);
  501. cmd.AddValue ("verbose", "Turn on all WifiNetDevice log components", verbose);
  502. cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
  503. cmd.AddValue ("pcap", "Enable PCAP Tracing", pcapTracing);
  504. cmd.Parse (argc, argv);
  505.  
  506. /* Global params: no fragmentation, no RTS/CTS, fixed rate for all packets */
  507. Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("999999"));
  508. Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999"));
  509.  
  510. /**** WifiHelper is a meta-helper: it helps creates helpers ****/
  511. WifiHelper wifi;
  512.  
  513. /* Basic setup */
  514. wifi.SetStandard (WIFI_PHY_STANDARD_80211ad);
  515.  
  516. /* Turn on logging */
  517. if (verbose)
  518. {
  519. wifi.EnableLogComponents ();
  520. LogComponentEnable ("EvaluateHalfDuplexRelayOperation", LOG_LEVEL_ALL);
  521. }
  522.  
  523. /**** Set up Channel ****/
  524. YansWifiChannelHelper wifiChannel ;
  525. /* Simple propagation delay model */
  526. wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  527. /* Friis model with standard-specific wavelength */
  528. wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel", "Frequency", DoubleValue (60.48e9));
  529.  
  530. /**** Setup physical layer ****/
  531. YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  532. /* Nodes will be added to the channel we set up earlier */
  533. wifiPhy.SetChannel (wifiChannel.Create ());
  534. /* All nodes transmit at 10 dBm == 10 mW, no adaptation */
  535. wifiPhy.Set ("TxPowerStart", DoubleValue (10.0));
  536. wifiPhy.Set ("TxPowerEnd", DoubleValue (10.0));
  537. wifiPhy.Set ("TxPowerLevels", UintegerValue (1));
  538. wifiPhy.Set ("TxGain", DoubleValue (0));
  539. wifiPhy.Set ("RxGain", DoubleValue (0));
  540. /* Sensitivity model includes implementation loss and noise figure */
  541. wifiPhy.Set ("RxNoiseFigure", DoubleValue (10));
  542. wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-79));
  543. wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-79 + 3));
  544. /* Set the phy layer error model */
  545. wifiPhy.SetErrorRateModel ("ns3::SensitivityModel60GHz");
  546. /* Set default algorithm for all nodes to be constant rate */
  547. wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "ControlMode", StringValue (phyMode),
  548. "DataMode", StringValue (phyMode));
  549.  
  550. /* Give all nodes directional antenna */
  551. wifiPhy.EnableAntenna (true, true);
  552. wifiPhy.SetAntenna ("ns3::Directional60GhzAntenna",
  553. "Sectors", UintegerValue (8),
  554. "Antennas", UintegerValue (1));
  555.  
  556. /* Make seven nodes and set them up with the phy and the mac */
  557. NodeContainer wifiNodes;
  558. wifiNodes.Create (7);
  559. Ptr<Node> apNode = wifiNodes.Get (0);
  560. Ptr<Node> rdsNode = wifiNodes.Get (1);
  561. Ptr<Node> westNode = wifiNodes.Get (2);
  562. Ptr<Node> eastNode = wifiNodes.Get (3);
  563. Ptr<Node> rdsNode2 = wifiNodes.Get (4);
  564. Ptr<Node> westNode2 = wifiNodes.Get (5);
  565. Ptr<Node> eastNode2 = wifiNodes.Get (6);
  566.  
  567. /* Add a DMG upper mac */
  568. DmgWifiMacHelper wifiMac = DmgWifiMacHelper::Default ();
  569.  
  570. /* Install PCP/AP Node */
  571. Ssid ssid = Ssid ("HD-DF");
  572. wifiMac.SetType ("ns3::DmgApWifiMac",
  573. "Ssid", SsidValue(ssid),
  574. "BE_MaxAmpduSize", UintegerValue (0),
  575. "BE_MaxAmsduSize", UintegerValue (msduAggregationSize),
  576. "SSSlotsPerABFT", UintegerValue (8), "SSFramesPerSlot", UintegerValue (8),
  577. "BeaconInterval", TimeValue (MicroSeconds (102400)),
  578. "BeaconTransmissionInterval", TimeValue (MicroSeconds (600)),
  579. "ATIPresent", BooleanValue (false));
  580.  
  581. NetDeviceContainer apDevice;
  582. apDevice = wifi.Install (wifiPhy, wifiMac, apNode);
  583.  
  584. /* Install RDS Nodes */
  585. wifiMac.SetType ("ns3::DmgStaWifiMac",
  586. "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false),
  587. "BE_MaxAmpduSize", UintegerValue (0),
  588. "BE_MaxAmsduSize", UintegerValue (msduAggregationSize),
  589. "RDSActivated", BooleanValue (true), //Activate RDS
  590. "REDSActivated", BooleanValue (false));
  591.  
  592. NetDeviceContainer rdsDevice, rdsDevice2;
  593. rdsDevice = wifi.Install (wifiPhy, wifiMac, rdsNode);
  594. rdsDevice2 = wifi.Install (wifiPhy, wifiMac, rdsNode2);
  595.  
  596. /* Install REDS Nodes */
  597. wifiMac.SetType ("ns3::DmgStaWifiMac",
  598. "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false),
  599. "BE_MaxAmpduSize", UintegerValue (0),
  600. "BE_MaxAmsduSize", UintegerValue (msduAggregationSize),
  601. "RDSActivated", BooleanValue (false),
  602. "REDSActivated", BooleanValue (true), //Activate REDS
  603. "RDSDuplexMode", BooleanValue (false),
  604. "RDSDataSensingTime", UintegerValue (200),
  605. "RDSFirstPeriod", UintegerValue (firstPeriod),
  606. "RDSSecondPeriod", UintegerValue (secondPeriod));
  607.  
  608. NetDeviceContainer redsDevices, redsDevices2;
  609. redsDevices = wifi.Install (wifiPhy, wifiMac, NodeContainer (westNode, eastNode));
  610. redsDevices2 = wifi.Install (wifiPhy, wifiMac, NodeContainer (westNode2, eastNode2));
  611.  
  612. /* Setting mobility model */
  613. MobilityHelper mobility;
  614. Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  615. positionAlloc->Add (Vector (0.0, +1.0, 0.0)); /* PCP/AP */
  616. positionAlloc->Add (Vector (0.0, -1.0, 0.0)); /* RDS */
  617. positionAlloc->Add (Vector (-1.0, 0.0, 0.0)); /* West REDS */
  618. positionAlloc->Add (Vector (+1.0, 0.0, 0.0)); /* East REDS */
  619. positionAlloc->Add (Vector (0.0, -3.0, 0.0)); /* RDS2 */
  620. positionAlloc->Add (Vector (-1.0, -2.0, 0.0)); /* West REDS2 */
  621. positionAlloc->Add (Vector (+1.0, -2.0, 0.0)); /* East REDS2 */
  622.  
  623. mobility.SetPositionAllocator (positionAlloc);
  624. mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  625. mobility.Install (wifiNodes);
  626.  
  627. /* Internet stack*/
  628. InternetStackHelper stack;
  629. stack.Install (wifiNodes);
  630.  
  631. Ipv4AddressHelper address;
  632. address.SetBase ("10.0.0.0", "255.255.255.0");
  633. Ipv4InterfaceContainer ApInterface;
  634. ApInterface = address.Assign (apDevice);
  635. Ipv4InterfaceContainer rdsInterface, rdsInterface2;
  636. rdsInterface = address.Assign (rdsDevice);
  637. rdsInterface2 = address.Assign (rdsDevice2);
  638. Ipv4InterfaceContainer redsInterfaces, redsInterfaces2;
  639. redsInterfaces = address.Assign (redsDevices);
  640. redsInterfaces2 = address.Assign (redsDevices2);
  641.  
  642. /* Populate routing table */
  643. Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  644.  
  645. /* We do not want any ARP packets */
  646. PopulateArpCache ();
  647.  
  648. /* Install Simple UDP Server on the East STAs */
  649. PacketSinkHelper sinkHelper1 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 5001));
  650. PacketSinkHelper sinkHelper2 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 5002));
  651. sink1 = StaticCast<PacketSink> (sinkHelper1.Install (eastNode).Get (0));
  652. sink2 = StaticCast<PacketSink> (sinkHelper2.Install (westNode).Get (0));
  653.  
  654. PacketSinkHelper sinkHelper3 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 5003));
  655. PacketSinkHelper sinkHelper4 ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 5004));
  656. sink3 = StaticCast<PacketSink> (sinkHelper3.Install (eastNode2).Get (0));
  657. sink4 = StaticCast<PacketSink> (sinkHelper4.Install (westNode2).Get (0));
  658.  
  659. /* Install Simple UDP Transmiter on the West Nodes (Transmit to the East Nodes) */
  660. ApplicationContainer srcApp;
  661. OnOffHelper src;
  662. src.SetAttribute ("Remote", AddressValue (InetSocketAddress (redsInterfaces.GetAddress (1), 5001)));
  663. src.SetAttribute ("MaxBytes", UintegerValue (0));
  664. src.SetAttribute ("PacketSize", UintegerValue (payloadSize));
  665. src.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1e6]"));
  666. src.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
  667. src.SetAttribute ("DataRate", DataRateValue (DataRate (dataRate)));
  668. srcApp = src.Install (westNode);
  669. srcApp.Start (Seconds (3.0));
  670.  
  671. /* Install Simple UDP Transmiter on the South Node (Transmit to the East Node) */
  672. src.SetAttribute ("Remote", AddressValue (InetSocketAddress (redsInterfaces.GetAddress (0), 5002)));
  673. srcApp = src.Install (eastNode);
  674. srcApp.Start (Seconds (3.0));
  675.  
  676. ApplicationContainer srcApp2;
  677. OnOffHelper src2;
  678. src2.SetAttribute ("Remote", AddressValue (InetSocketAddress (redsInterfaces2.GetAddress (1), 5003)));
  679. src2.SetAttribute ("MaxBytes", UintegerValue (0));
  680. src2.SetAttribute ("PacketSize", UintegerValue (payloadSize));
  681. src2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1e6]"));
  682. src2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
  683. src2.SetAttribute ("DataRate", DataRateValue (DataRate (dataRate)));
  684. srcApp2 = src2.Install (westNode2);
  685. srcApp2.Start (Seconds (3.0));
  686.  
  687. /* Install Simple UDP Transmiter on the South Node (Transmit to the East Node) */
  688. src2.SetAttribute ("Remote", AddressValue (InetSocketAddress (redsInterfaces2.GetAddress (0), 5004)));
  689. srcApp2 = src2.Install (eastNode2);
  690. srcApp2.Start (Seconds (3.0));
  691.  
  692. /* Schedule Throughput Calulcation */
  693. Simulator::Schedule (Seconds (3.1), &CalculateThroughput);
  694. Simulator::Schedule (Seconds (3.1), &CalculateThroughput2);
  695.  
  696. /** Connect Trace Sources **/
  697. apWifiNetDevice = StaticCast<WifiNetDevice> (apDevice.Get (0));
  698. westRedsNetDevice = StaticCast<WifiNetDevice> (redsDevices.Get (0));
  699. eastRedsNetDevice = StaticCast<WifiNetDevice> (redsDevices.Get (1));
  700. rdsNetDevice = StaticCast<WifiNetDevice> (rdsDevice.Get (0));
  701.  
  702. westRedsNetDevice2 = StaticCast<WifiNetDevice> (redsDevices2.Get (0));
  703. eastRedsNetDevice2 = StaticCast<WifiNetDevice> (redsDevices2.Get (1));
  704. rdsNetDevice2 = StaticCast<WifiNetDevice> (rdsDevice2.Get (0));
  705.  
  706. /* Set Maximum number of packets in WifiMacQueue */
  707. Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/DcaTxop/Queue/MaxPackets", UintegerValue (queueSize));
  708. Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_EdcaTxopN/Queue/MaxPackets", UintegerValue (queueSize));
  709. Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::DmgWifiMac/SPQueue/MaxPackets", UintegerValue (queueSize));
  710.  
  711. /* Enable Traces */
  712. if (pcapTracing)
  713. {
  714. wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
  715. wifiPhy.EnablePcap ("Traces/AccessPoint", apWifiNetDevice, false);
  716. wifiPhy.EnablePcap ("Traces/RDS", rdsNetDevice, false);
  717. wifiPhy.EnablePcap ("Traces/WEST", westRedsNetDevice, false);
  718. wifiPhy.EnablePcap ("Traces/EAST", eastRedsNetDevice, false);
  719. wifiPhy.EnablePcap ("Traces/RDS2", rdsNetDevice2, false);
  720. wifiPhy.EnablePcap ("Traces/WEST2", westRedsNetDevice2, false);
  721. wifiPhy.EnablePcap ("Traces/EAST2", eastRedsNetDevice2, false);
  722. }
  723.  
  724. apWifiMac = StaticCast<DmgApWifiMac> (apWifiNetDevice->GetMac ());
  725. westRedsMac = StaticCast<DmgStaWifiMac> (westRedsNetDevice->GetMac ());
  726. eastRedsMac = StaticCast<DmgStaWifiMac> (eastRedsNetDevice->GetMac ());
  727. rdsMac = StaticCast<DmgStaWifiMac> (rdsNetDevice->GetMac ());
  728.  
  729. westRedsMac2 = StaticCast<DmgStaWifiMac> (westRedsNetDevice2->GetMac ());
  730. eastRedsMac2 = StaticCast<DmgStaWifiMac> (eastRedsNetDevice2->GetMac ());
  731. rdsMac2 = StaticCast<DmgStaWifiMac> (rdsNetDevice2->GetMac ());
  732.  
  733. westRedsMac->TraceConnectWithoutContext ("RlsCompleted", MakeBoundCallback (&RlsCompleted, westRedsMac));
  734. eastRedsMac->TraceConnectWithoutContext ("RlsCompleted", MakeBoundCallback (&RlsCompleted, eastRedsMac));
  735.  
  736. westRedsMac->TraceConnectWithoutContext ("ChannelReportReceived", MakeCallback (&ChannelReportReceived));
  737. eastRedsMac->TraceConnectWithoutContext ("ChannelReportReceived", MakeCallback (&ChannelReportReceived));
  738.  
  739. westRedsMac->TraceConnectWithoutContext ("SLSCompleted", MakeBoundCallback (&SLSCompleted, westRedsMac));
  740. eastRedsMac->TraceConnectWithoutContext ("SLSCompleted", MakeBoundCallback (&SLSCompleted, eastRedsMac));
  741. rdsMac->TraceConnectWithoutContext ("SLSCompleted", MakeBoundCallback (&SLSCompleted, rdsMac));
  742.  
  743. westRedsMac2->TraceConnectWithoutContext ("RlsCompleted2", MakeBoundCallback (&RlsCompleted2, westRedsMac2));
  744. eastRedsMac2->TraceConnectWithoutContext ("RlsCompleted2", MakeBoundCallback (&RlsCompleted2, eastRedsMac2));
  745.  
  746. westRedsMac2->TraceConnectWithoutContext ("ChannelReportReceived2", MakeCallback (&ChannelReportReceived2));
  747. eastRedsMac2->TraceConnectWithoutContext ("ChannelReportReceived2", MakeCallback (&ChannelReportReceived2));
  748.  
  749. westRedsMac2->TraceConnectWithoutContext ("SLSCompleted2", MakeBoundCallback (&SLSCompleted2, westRedsMac2));
  750. eastRedsMac2->TraceConnectWithoutContext ("SLSCompleted2", MakeBoundCallback (&SLSCompleted2, eastRedsMac2));
  751. rdsMac2->TraceConnectWithoutContext ("SLSCompleted2", MakeBoundCallback (&SLSCompleted2, rdsMac2));
  752.  
  753. /* Relay Selector Function */
  754. westRedsMac->RegisterRelaySelectorFunction (MakeCallback (&SelectRelay));
  755. eastRedsMac->RegisterRelaySelectorFunction (MakeCallback (&SelectRelay));
  756.  
  757. westRedsMac2->RegisterRelaySelectorFunction (MakeCallback (&SelectRelay2));
  758. eastRedsMac2->RegisterRelaySelectorFunction (MakeCallback (&SelectRelay2));
  759.  
  760.  
  761. /** Schedule Events **/
  762. /* Request the DMG Capabilities of other DMG STAs */
  763. Simulator::Schedule (Seconds (1.05), &DmgStaWifiMac::RequestInformation, westRedsMac, eastRedsMac->GetAddress ());
  764. Simulator::Schedule (Seconds (1.05), &DmgStaWifiMac::RequestInformation, westRedsMac2, eastRedsMac2->GetAddress ());
  765.  
  766. Simulator::Schedule (Seconds (1.06), &DmgStaWifiMac::RequestInformation, westRedsMac, rdsMac->GetAddress ());
  767. Simulator::Schedule (Seconds (1.06), &DmgStaWifiMac::RequestInformation, westRedsMac2, rdsMac2->GetAddress ());
  768.  
  769. Simulator::Schedule (Seconds (1.07), &DmgStaWifiMac::RequestInformation, rdsMac, westRedsMac->GetAddress ());
  770. Simulator::Schedule (Seconds (1.07), &DmgStaWifiMac::RequestInformation, rdsMac2, westRedsMac2->GetAddress ());
  771.  
  772. Simulator::Schedule (Seconds (1.08), &DmgStaWifiMac::RequestInformation, rdsMac, eastRedsMac->GetAddress ());
  773. Simulator::Schedule (Seconds (1.08), &DmgStaWifiMac::RequestInformation, rdsMac2, eastRedsMac2->GetAddress ());
  774.  
  775. Simulator::Schedule (Seconds (1.09), &DmgStaWifiMac::RequestInformation, eastRedsMac, westRedsMac->GetAddress ());
  776. Simulator::Schedule (Seconds (1.09), &DmgStaWifiMac::RequestInformation, eastRedsMac2, westRedsMac2->GetAddress ());
  777.  
  778. Simulator::Schedule (Seconds (1.10), &DmgStaWifiMac::RequestInformation, eastRedsMac, rdsMac->GetAddress ());
  779. Simulator::Schedule (Seconds (1.10), &DmgStaWifiMac::RequestInformation, eastRedsMac2, rdsMac2->GetAddress ());
  780.  
  781. /* Initiate Relay Discovery Procedure */
  782. Simulator::Schedule (Seconds (1.3), &DmgStaWifiMac::StartRelayDiscovery, westRedsMac, eastRedsMac->GetAddress ());
  783. Simulator::Schedule (Seconds (1.3), &DmgStaWifiMac::StartRelayDiscovery, westRedsMac2, eastRedsMac2->GetAddress ());
  784.  
  785.  
  786. /* Schedule link switch event */
  787. if (switchForward)
  788. {
  789. Simulator::Schedule (Seconds (switchTime), &SwitchTransmissionLink, westRedsMac, eastRedsMac);
  790. Simulator::Schedule (Seconds (switchTime2), &SwitchTransmissionLink2, westRedsMac2, eastRedsMac2);
  791. }
  792. if (switchReverse)
  793. {
  794. Simulator::Schedule (Seconds (switchTime), &SwitchTransmissionLink, eastRedsMac, westRedsMac);
  795. Simulator::Schedule (Seconds (switchTime2), &SwitchTransmissionLink2, eastRedsMac2, westRedsMac2);
  796. }
  797.  
  798. /* Schedule tear down event */
  799. if (switchForward)
  800. {
  801. Simulator::Schedule (Seconds (switchTime + 3), &TearDownRelay, westRedsMac, eastRedsMac);
  802. Simulator::Schedule (Seconds (switchTime2 + 3), &TearDownRelay2, westRedsMac2, eastRedsMac2);
  803. }
  804. if (switchReverse)
  805. {
  806. Simulator::Schedule (Seconds (switchTime + 3), &TearDownRelay, eastRedsMac, westRedsMac);
  807. Simulator::Schedule (Seconds (switchTime2 + 3), &TearDownRelay2, eastRedsMac2, westRedsMac2);
  808. }
  809.  
  810. /* Print Output*/
  811. std::cout << "Time(s)" << '\t' << "A1" << '\t'<< "A2" << std::endl;
  812.  
  813. Simulator::Stop (Seconds (simulationTime));
  814. Simulator::Run ();
  815. Simulator::Destroy ();
  816.  
  817. /* Print Results Summary */
  818. std::cout << "Total number of packets received during each channel time allocation:" << std::endl;
  819. std::cout << "SP1 = " << sink1->GetTotalReceivedPackets () << std::endl;
  820. std::cout << "SP2 = " << sink2->GetTotalReceivedPackets () << std::endl;
  821. std::cout << "SP1 = " << sink3->GetTotalReceivedPackets () << std::endl;
  822. std::cout << "SP2 = " << sink4->GetTotalReceivedPackets () << std::endl;
  823.  
  824. std::cout << "Total throughput during each channel time allocation:" << std::endl;
  825. std::cout << "SP1 = " << westEastAverageThroughput/((simulationTime - 1) * 10) << std::endl;
  826. std::cout << "SP2 = " << eastWestAverageThroughput/((simulationTime - 1) * 10) << std::endl;
  827. std::cout << "SP1 = " << westEastAverageThroughput2/((simulationTime - 1) * 10) << std::endl;
  828. std::cout << "SP2 = " << eastWestAverageThroughput2/((simulationTime - 1) * 10) << std::endl;
  829.  
  830. return 0;
  831. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement