-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvanet-routing-compare.cc
2513 lines (2241 loc) · 79.5 KB
/
vanet-routing-compare.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014 North Carolina State University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Scott E. Carpenter <[email protected]>
*
*/
/*
* This example program allows one to run vehicular ad hoc
* network (VANET) simulation scenarios in ns-3 to assess
* performance by evaluating different 802.11p MAC/PHY
* characteristics, propagation loss models (e.g. Friss,
* Two-Ray Ground, or ITU R-P.1411), and application traffic
* (e.g. Basic Safety Message) and/or routing traffic (e.g.
* DSDV, AODV, OLSR, or DSR) under either a synthetic highway
* scenario (i.e. a random waypoint mobility model) or by
* playing back mobility trace files (i.e. ns-2 movement files).
*
* The script draws from several ns-3 examples, including:
* /examples/routing/manet-routing-compare.cc
* /src/propagation/model/itu-r-1411-los-propagation-loss-model.cc
* /src/mobility/examples/ns2-mobility-trace.cc
* /src/wave/examples/wave-simple-80211p.cc
*
* The script allows many parameters to be modified and
* includes two predefined scenarios. By default
* scenario=1 runs for 10 simulated seconds with 40 nodes
* (i.e. vehicles) moving according to RandomWaypointMobilityModel
* with a speed of 20 m/s and no pause time within a 300x1500 m
* region. The WiFi is 802.11p with continuous access to a 10 MHz
* Control Channel (CH) for all traffic. All nodes transmit a
* 200-byte safety message 10 times per second at 6 Mbps.
* Additionally, all nodes (optionally) attempt to
* continuously route 64-byte packets at an application
* rate of 2.048 Kbps to one of 10 other nodes,
* selected as sink nodes. The default routing protocol is AODV
* and the Two-Ray Ground loss model is used.
* The transmit power is set to 20 dBm and the transmission range
* for safety message packet delivery is 145 m.
*
* Scenario 2 plays back vehicular trace files in
* ns-2 movement format, and are taken from:
* http://www.lst.inf.ethz.ch/research/ad-hoc/car-traces/
* This scenario is 300 simulation seconds of 99
* vehicles respectively within the Unterstrass
* section of Zurich Switzerland that travel based on
* models derived from real traffic data. Note that these
* scenarios can require a lot of clock time to complete.
*
* All parameters can be changed from their defaults (see
* --help) and changing simulation parameters can have dramatic
* impact on network performance.
*
* Several items can be output:
* - a CSV file of data reception statistics, output once per
* second
* - final statistics, in a CSV file
* - dump of routing tables at 5 seconds into the simulation
* - ASCII trace file
* - PCAP trace files for each node
*
* Simulation scenarios can be defined and configuration
* settings can be saved using config-store (raw text)
* which can they be replayed again. This is an easy way
* to define and save the settings for a scenario, and then
* re-execute the same scenario exactly, or to set up
* several different simulation scenarios.
* For example, to set up a scenario and save the configuration
* as "scenario1.txt":
* ./waf --run "vanet-routing-compare --scenario=1 --saveconfig=scenario1.txt"
* Then, to re-play the scenario using the save configuration
* settings:
* ./waf --run "vanet-routing-compare --loadconfig=scenario1.txt"
*
* Class Diagram:
* main()
* +--uses-- VanetRoutingExperiment
* +--is_a--- WifiApp
* +--uses--- ConfigStoreHelper
* +--has_a-- WaveBsmHelper
* | +--has_a-- WaveBsmStats
* +--has_a-- RoutingHelper
* | +--has_a--RoutingStats
* +--has_a-- WifiPhyStats
*
*/
#include <fstream>
#include <iostream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/aodv-module.h"
#include "ns3/olsr-module.h"
#include "ns3/dsdv-module.h"
#include "ns3/dsr-module.h"
#include "ns3/applications-module.h"
#include "ns3/itu-r-1411-los-propagation-loss-model.h"
#include "ns3/ocb-wifi-mac.h"
#include "ns3/wifi-80211p-helper.h"
#include "ns3/wave-mac-helper.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/config-store-module.h"
#include "ns3/integer.h"
#include "ns3/wave-bsm-helper.h"
#include "ns3/wave-helper.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/netanim-module.h"
using namespace ns3;
using namespace dsr;
NS_LOG_COMPONENT_DEFINE ("vanet-routing-compare");
/**
* \ingroup wave
* \brief The RoutingStats class manages collects statistics
* on routing data (application-data packet and byte counts)
* for the vehicular network
*/
class RoutingStats
{
public:
/**
* \brief Constructor
* \return none
*/
RoutingStats ();
/**
* \brief Returns the number of bytes received
* \return the number of bytes received
*/
uint32_t GetRxBytes ();
/**
* \brief Returns the cumulative number of bytes received
* \return the cumulative number of bytes received
*/
uint32_t GetCumulativeRxBytes ();
/**
* \brief Returns the count of packets received
* \return the count of packets received
*/
uint32_t GetRxPkts ();
/**
* \brief Returns the cumulative count of packets received
* \return the cumulative count of packets received
*/
uint32_t GetCumulativeRxPkts ();
/**
* \brief Increments the number of (application-data)
* bytes received, not including MAC/PHY overhead
* \param rxBytes the number of bytes received
* \return none
*/
void IncRxBytes (uint32_t rxBytes);
/**
* \brief Increments the count of packets received
* \return none
*/
void IncRxPkts ();
/**
* \brief Sets the number of bytes received.
* \param rxBytes the number of bytes received
* \return none
*/
void SetRxBytes (uint32_t rxBytes);
/**
* \brief Sets the number of packets received
* \param rxPkts the number of packets received
* \return none
*/
void SetRxPkts (uint32_t rxPkts);
/**
* \brief Returns the number of bytes transmitted
* \return the number of bytes transmitted
*/
uint32_t GetTxBytes ();
/**
* \brief Returns the cumulative number of bytes transmitted
* \return none
*/
uint32_t GetCumulativeTxBytes ();
/**
* \brief Returns the number of packets transmitted
* \return the number of packets transmitted
*/
uint32_t GetTxPkts ();
/**
* \brief Returns the cumulative number of packets transmitted
* \return the cumulative number of packets transmitted
*/
uint32_t GetCumulativeTxPkts ();
/**
* \brief Increment the number of bytes transmitted
* \param txBytes the number of additional bytes transmitted
* \return none
*/
void IncTxBytes (uint32_t txBytes);
/**
* \brief Increment the count of packets transmitted
* \return none
*/
void IncTxPkts ();
/**
* \brief Sets the number of bytes transmitted
* \param txBytes the number of bytes transmitted
* \return none
*/
void SetTxBytes (uint32_t txBytes);
/**
* \brief Sets the number of packets transmitted
* \param txPkts the number of packets transmitted
* \return none
*/
void SetTxPkts (uint32_t txPkts);
private:
uint32_t m_RxBytes; ///< reeive bytes
uint32_t m_cumulativeRxBytes; ///< cumulative receive bytes
uint32_t m_RxPkts; ///< receive packets
uint32_t m_cumulativeRxPkts; ///< cumulative receive packets
uint32_t m_TxBytes; ///< transmit bytes
uint32_t m_cumulativeTxBytes; ///< cumulative transmit bytes
uint32_t m_TxPkts; ///< transmit packets
uint32_t m_cumulativeTxPkts; ///< cumulative transmit packets
};
RoutingStats::RoutingStats ()
: m_RxBytes (0),
m_cumulativeRxBytes (0),
m_RxPkts (0),
m_cumulativeRxPkts (0),
m_TxBytes (0),
m_cumulativeTxBytes (0),
m_TxPkts (0),
m_cumulativeTxPkts (0)
{
}
uint32_t
RoutingStats::GetRxBytes ()
{
return m_RxBytes;
}
uint32_t
RoutingStats::GetCumulativeRxBytes ()
{
return m_cumulativeRxBytes;
}
uint32_t
RoutingStats::GetRxPkts ()
{
return m_RxPkts;
}
uint32_t
RoutingStats::GetCumulativeRxPkts ()
{
return m_cumulativeRxPkts;
}
void
RoutingStats::IncRxBytes (uint32_t rxBytes)
{
m_RxBytes += rxBytes;
m_cumulativeRxBytes += rxBytes;
}
void
RoutingStats::IncRxPkts ()
{
m_RxPkts++;
m_cumulativeRxPkts++;
}
void
RoutingStats::SetRxBytes (uint32_t rxBytes)
{
m_RxBytes = rxBytes;
}
void
RoutingStats::SetRxPkts (uint32_t rxPkts)
{
m_RxPkts = rxPkts;
}
uint32_t
RoutingStats::GetTxBytes ()
{
return m_TxBytes;
}
uint32_t
RoutingStats::GetCumulativeTxBytes ()
{
return m_cumulativeTxBytes;
}
uint32_t
RoutingStats::GetTxPkts ()
{
return m_TxPkts;
}
uint32_t
RoutingStats::GetCumulativeTxPkts ()
{
return m_cumulativeTxPkts;
}
void
RoutingStats::IncTxBytes (uint32_t txBytes)
{
m_TxBytes += txBytes;
m_cumulativeTxBytes += txBytes;
}
void
RoutingStats::IncTxPkts ()
{
m_TxPkts++;
m_cumulativeTxPkts++;
}
void
RoutingStats::SetTxBytes (uint32_t txBytes)
{
m_TxBytes = txBytes;
}
void
RoutingStats::SetTxPkts (uint32_t txPkts)
{
m_TxPkts = txPkts;
}
/**
* \ingroup wave
* \brief The RoutingHelper class generates routing data between
* nodes (vehicles) and uses the RoutingStats class to collect statistics
* on routing data (application-data packet and byte counts).
* A routing protocol is configured, and all nodes attempt to send
* (i.e. route) small packets to another node, which acts as
* data sinks. Not all nodes act as data sinks.
* for the vehicular network
*/
class RoutingHelper : public Object
{
public:
/**
* \brief Get class TypeId
* \return the TypeId for the class
*/
static TypeId GetTypeId (void);
/**
* \brief Constructor
* \return none
*/
RoutingHelper ();
/**
* \brief Destructor
* \return none
*/
virtual ~RoutingHelper ();
/**
* \brief Installs routing functionality on nodes and their
* devices and interfaces.
* \param c node container
* \param d net device container
* \param i IPv4 interface container
* \param totalTime the total time that nodes should attempt to
* route data
* \param protocol the routing protocol (1=OLSR;2=AODV;3=DSDV;4=DSR)
* \param nSinks the number of nodes which will act as data sinks
* \param routingTables dump routing tables at t=5 seconds (0=no;1=yes)
* \return none
*/
void Install (NodeContainer & c,
NetDeviceContainer & d,
Ipv4InterfaceContainer & i,
double totalTime,
int protocol,
uint32_t nSinks,
int routingTables);
/**
* \brief Trace the receipt of an on-off-application generated packet
* \param context this object
* \param packet a received packet
* \return none
*/
void OnOffTrace (std::string context, Ptr<const Packet> packet);
/**
* \brief Returns the RoutingStats instance
* \return the RoutingStats instance
*/
RoutingStats & GetRoutingStats ();
/**
* \brief Enable/disable logging
* \param log non-zero to enable logging
* \return none
*/
void SetLogging (int log);
private:
/**
* \brief Sets up the protocol protocol on the nodes
* \param c node container
* \return none
*/
void SetupRoutingProtocol (NodeContainer & c);
/**
* \brief Assigns IPv4 addresses to net devices and their interfaces
* \param d net device container
* \param adhocTxInterfaces IPv4 interface container
* \return none
*/
void AssignIpAddresses (NetDeviceContainer & d,
Ipv4InterfaceContainer & adhocTxInterfaces);
/**
* \brief Sets up routing messages on the nodes and their interfaces
* \param c node container
* \param adhocTxInterfaces IPv4 interface container
* \return none
*/
void SetupRoutingMessages (NodeContainer & c,
Ipv4InterfaceContainer & adhocTxInterfaces);
/**
* \brief Sets up a routing packet for tranmission
* \param addr destination address
* \param node source node
* \return Socket to be used for sending/receiving a routed data packet
*/
Ptr<Socket> SetupRoutingPacketReceive (Ipv4Address addr, Ptr<Node> node);
/**
* \brief Process a received routing packet
* \param socket the receiving socket
* \return none
*/
void ReceiveRoutingPacket (Ptr<Socket> socket);
double m_TotalSimTime; ///< seconds
uint32_t m_protocol; ///< routing protocol; 0=NONE, 1=OLSR, 2=AODV, 3=DSDV, 4=DSR
uint32_t m_port; ///< port
uint32_t m_nSinks; ///< number of sink nodes (< all nodes)
int m_routingTables; ///< dump routing table (at t=5 sec). 0=No, 1=Yes
RoutingStats routingStats; ///< routing statistics
std::string m_protocolName; ///< protocol name
int m_log; ///< log
};
NS_OBJECT_ENSURE_REGISTERED (RoutingHelper);
TypeId
RoutingHelper::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::RoutingHelper")
.SetParent<Object> ()
.AddConstructor<RoutingHelper> ();
return tid;
}
RoutingHelper::RoutingHelper ()
: m_TotalSimTime (300.01),
m_protocol (0),
m_port (9),
m_nSinks (0),
m_routingTables (0),
m_log (0)
{
}
RoutingHelper::~RoutingHelper ()
{
}
void
RoutingHelper::Install (NodeContainer & c,
NetDeviceContainer & d,
Ipv4InterfaceContainer & i,
double totalTime,
int protocol,
uint32_t nSinks,
int routingTables)
{
m_TotalSimTime = totalTime;
m_protocol = protocol;
m_nSinks = nSinks;
m_routingTables = routingTables;
SetupRoutingProtocol (c);
AssignIpAddresses (d, i);
SetupRoutingMessages (c, i);
}
Ptr<Socket>
RoutingHelper::SetupRoutingPacketReceive (Ipv4Address addr, Ptr<Node> node)
{
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> sink = Socket::CreateSocket (node, tid);
InetSocketAddress local = InetSocketAddress (addr, m_port);
sink->Bind (local);
sink->SetRecvCallback (MakeCallback (&RoutingHelper::ReceiveRoutingPacket, this));
return sink;
}
void
RoutingHelper::SetupRoutingProtocol (NodeContainer & c)
{
AodvHelper aodv;
OlsrHelper olsr;
DsdvHelper dsdv;
DsrHelper dsr;
DsrMainHelper dsrMain;
Ipv4ListRoutingHelper list;
InternetStackHelper internet;
Time rtt = Time (5.0);
AsciiTraceHelper ascii;
Ptr<OutputStreamWrapper> rtw = ascii.CreateFileStream ("routing_table");
switch (m_protocol)
{
case 0:
m_protocolName = "NONE";
break;
case 1:
if (m_routingTables != 0)
{
olsr.PrintRoutingTableAllAt (rtt, rtw);
}
list.Add (olsr, 100);
m_protocolName = "OLSR";
break;
case 2:
if (m_routingTables != 0)
{
aodv.PrintRoutingTableAllAt (rtt, rtw);
}
list.Add (aodv, 100);
m_protocolName = "AODV";
break;
case 3:
if (m_routingTables != 0)
{
dsdv.PrintRoutingTableAllAt (rtt, rtw);
}
list.Add (dsdv, 100);
m_protocolName = "DSDV";
break;
case 4:
// setup is later
m_protocolName = "DSR";
break;
default:
NS_FATAL_ERROR ("No such protocol:" << m_protocol);
break;
}
if (m_protocol < 4)
{
internet.SetRoutingHelper (list);
internet.Install (c);
}
else if (m_protocol == 4)
{
internet.Install (c);
dsrMain.Install (dsr, c);
}
if (m_log != 0)
{
NS_LOG_UNCOND ("Routing Setup for " << m_protocolName);
}
}
void
RoutingHelper::AssignIpAddresses (NetDeviceContainer & d,
Ipv4InterfaceContainer & adhocTxInterfaces)
{
NS_LOG_INFO ("Assigning IP addresses");
Ipv4AddressHelper addressAdhoc;
// we may have a lot of nodes, and want them all
// in same subnet, to support broadcast
addressAdhoc.SetBase ("10.1.0.0", "255.255.0.0");
adhocTxInterfaces = addressAdhoc.Assign (d);
}
void
RoutingHelper::SetupRoutingMessages (NodeContainer & c,
Ipv4InterfaceContainer & adhocTxInterfaces)
{
// Setup routing transmissions
OnOffHelper onoff1 ("ns3::UdpSocketFactory",Address ());
onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
int64_t stream = 2;
var->SetStream (stream);
for (uint32_t i = 0; i < m_nSinks; i++)
{
// protocol == 0 means no routing data, WAVE BSM only
// so do not set up sink
if (m_protocol != 0)
{
Ptr<Socket> sink = SetupRoutingPacketReceive (adhocTxInterfaces.GetAddress (i), c.Get (i));
}
AddressValue remoteAddress (InetSocketAddress (adhocTxInterfaces.GetAddress (i), m_port));
onoff1.SetAttribute ("Remote", remoteAddress);
ApplicationContainer temp = onoff1.Install (c.Get (i + m_nSinks));
temp.Start (Seconds (var->GetValue (1.0,2.0)));
temp.Stop (Seconds (m_TotalSimTime));
}
}
static inline std::string
PrintReceivedRoutingPacket (Ptr<Socket> socket, Ptr<Packet> packet, Address srcAddress)
{
std::ostringstream oss;
oss << Simulator::Now ().GetSeconds () << " " << socket->GetNode ()->GetId ();
if (InetSocketAddress::IsMatchingType (srcAddress))
{
InetSocketAddress addr = InetSocketAddress::ConvertFrom (srcAddress);
oss << " received one packet from " << addr.GetIpv4 ();
}
else
{
oss << " received one packet!";
}
return oss.str ();
}
void
RoutingHelper::ReceiveRoutingPacket (Ptr<Socket> socket)
{
Ptr<Packet> packet;
Address srcAddress;
while ((packet = socket->RecvFrom (srcAddress)))
{
// application data, for goodput
uint32_t RxRoutingBytes = packet->GetSize ();
GetRoutingStats ().IncRxBytes (RxRoutingBytes);
GetRoutingStats ().IncRxPkts ();
if (m_log != 0)
{
NS_LOG_UNCOND (m_protocolName + " " + PrintReceivedRoutingPacket (socket, packet, srcAddress));
}
}
}
void
RoutingHelper::OnOffTrace (std::string context, Ptr<const Packet> packet)
{
uint32_t pktBytes = packet->GetSize ();
routingStats.IncTxBytes (pktBytes);
}
RoutingStats &
RoutingHelper::GetRoutingStats ()
{
return routingStats;
}
void
RoutingHelper::SetLogging (int log)
{
m_log = log;
}
/**
* \ingroup wave
* \brief The WifiPhyStats class collects Wifi MAC/PHY statistics
*/
class WifiPhyStats : public Object
{
public:
/**
* \brief Gets the class TypeId
* \return the class TypeId
*/
static TypeId GetTypeId (void);
/**
* \brief Constructor
* \return none
*/
WifiPhyStats ();
/**
* \brief Destructor
* \return none
*/
virtual ~WifiPhyStats ();
/**
* \brief Returns the number of bytes that have been transmitted
* (this includes MAC/PHY overhead)
* \return the number of bytes transmitted
*/
uint32_t GetTxBytes ();
/**
* \brief Callback signiture for Phy/Tx trace
* \param context this object
* \param packet packet transmitted
* \param mode wifi mode
* \param preamble wifi preamble
* \param txPower transmission power
* \return none
*/
void PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower);
/**
* \brief Callback signiture for Phy/TxDrop
* \param context this object
* \param packet the tx packet being dropped
* \return none
*/
void PhyTxDrop (std::string context, Ptr<const Packet> packet);
/**
* \brief Callback signiture for Phy/RxDrop
* \param context this object
* \param packet the rx packet being dropped
* \return none
*/
void PhyRxDrop (std::string context, Ptr<const Packet> packet);
private:
uint32_t m_phyTxPkts; ///< phy transmit packets
uint32_t m_phyTxBytes; ///< phy transmit bytes
};
NS_OBJECT_ENSURE_REGISTERED (WifiPhyStats);
TypeId
WifiPhyStats::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::WifiPhyStats")
.SetParent<Object> ()
.AddConstructor<WifiPhyStats> ();
return tid;
}
WifiPhyStats::WifiPhyStats ()
: m_phyTxPkts (0),
m_phyTxBytes (0)
{
}
WifiPhyStats::~WifiPhyStats ()
{
}
void
WifiPhyStats::PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
{
NS_LOG_FUNCTION (this << context << packet << "PHYTX mode=" << mode );
++m_phyTxPkts;
uint32_t pktSize = packet->GetSize ();
m_phyTxBytes += pktSize;
//NS_LOG_UNCOND ("Received PHY size=" << pktSize);
}
void
WifiPhyStats::PhyTxDrop (std::string context, Ptr<const Packet> packet)
{
NS_LOG_UNCOND ("PHY Tx Drop");
}
void
WifiPhyStats::PhyRxDrop (std::string context, Ptr<const Packet> packet)
{
NS_LOG_UNCOND ("PHY Rx Drop");
}
uint32_t
WifiPhyStats::GetTxBytes ()
{
return m_phyTxBytes;
}
/**
* \ingroup wave
* \brief The WifiApp class enforces program flow for ns-3 wifi applications
*/
class WifiApp
{
public:
/**
* \brief Constructor
* \return none
*/
WifiApp ();
/**
* \brief Destructor
* \return none
*/
virtual ~WifiApp ();
/**
* \brief Enacts simulation of an ns-3 wifi application
* \param argc program arguments count
* \param argv program arguments
* \return none
*/
void Simulate (int argc, char **argv);
protected:
/**
* \brief Sets default attribute values
* \return none
*/
virtual void SetDefaultAttributeValues ();
/**
* \brief Process command line arguments
* \param argc program arguments count
* \param argv program arguments
* \return none
*/
virtual void ParseCommandLineArguments (int argc, char **argv);
/**
* \brief Configure nodes
* \return none
*/
virtual void ConfigureNodes ();
/**
* \brief Configure channels
* \return none
*/
virtual void ConfigureChannels ();
/**
* \brief Configure devices
* \return none
*/
virtual void ConfigureDevices ();
/**
* \brief Configure mobility
* \return none
*/
virtual void ConfigureMobility ();
/**
* \brief Configure applications
* \return none
*/
virtual void ConfigureApplications ();
/**
* \brief Configure tracing
* \return none
*/
virtual void ConfigureTracing ();
/**
* \brief Run the simulation
* \return none
*/
virtual void RunSimulation ();
/**
* \brief Process outputs
* \return none
*/
virtual void ProcessOutputs ();
};
WifiApp::WifiApp ()
{
}
WifiApp::~WifiApp ()
{
}
void
WifiApp::Simulate (int argc, char **argv)
{
// Simulator Program Flow:
// (source: NS-3 Annual Meeting, May, 2014, session 2 slides 6, 28)
// (HandleProgramInputs:)
// SetDefaultAttributeValues
// ParseCommandLineArguments
// (ConfigureTopology:)
// ConfigureNodes
// ConfigureChannels
// ConfigureDevices
// ConfigureMobility
// ConfigureApplications
// e.g AddInternetStackToNodes
// ConfigureIpAddressingAndRouting
// configureSendMessages
// ConfigureTracing
// RunSimulation
// ProcessOutputs
SetDefaultAttributeValues ();
ParseCommandLineArguments (argc, argv);
ConfigureNodes ();
ConfigureChannels ();
ConfigureDevices ();
ConfigureMobility ();
ConfigureApplications ();
ConfigureTracing ();
RunSimulation ();
ProcessOutputs ();
}
void
WifiApp::SetDefaultAttributeValues ()
{
}
void
WifiApp::ParseCommandLineArguments (int argc, char **argv)
{
}
void
WifiApp::ConfigureNodes ()
{
}
void
WifiApp::ConfigureChannels ()
{
}
void
WifiApp::ConfigureDevices ()
{
}
void
WifiApp::ConfigureMobility ()
{
}
void
WifiApp::ConfigureApplications ()
{
}
void
WifiApp::ConfigureTracing ()