LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2014 North Carolina State University | 3 * Copyright (c) 2014 North Carolina State University |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "ns3/wave-mac-helper.h" | 25 #include "ns3/wave-mac-helper.h" |
26 #include "ns3/wave-helper.h" | 26 #include "ns3/wave-helper.h" |
27 #include "ns3/mobility-model.h" | 27 #include "ns3/mobility-model.h" |
28 #include "ns3/mobility-helper.h" | 28 #include "ns3/mobility-helper.h" |
29 | 29 |
30 NS_LOG_COMPONENT_DEFINE ("BsmApplication"); | 30 NS_LOG_COMPONENT_DEFINE ("BsmApplication"); |
31 | 31 |
32 namespace ns3 { | 32 namespace ns3 { |
33 | 33 |
34 // (Arbitrary) port for establishing socket to transmit WAVE BSMs | 34 // (Arbitrary) port for establishing socket to transmit WAVE BSMs |
35 int BsmApplication::wavePort = 9080; | 35 uint16_t BsmApplication::wavePort = 9080; |
36 | 36 |
37 NS_OBJECT_ENSURE_REGISTERED (BsmApplication); | 37 NS_OBJECT_ENSURE_REGISTERED (BsmApplication); |
38 | 38 |
39 TypeId | 39 TypeId |
40 BsmApplication::GetTypeId (void) | 40 BsmApplication::GetTypeId (void) |
41 { | 41 { |
42 static TypeId tid = TypeId ("ns3::BsmApplication") | 42 static TypeId tid = TypeId ("ns3::BsmApplication") |
43 .SetParent<Application> () | 43 .SetParent<Application> () |
44 .SetGroupName ("Wave") | 44 .SetGroupName ("Wave") |
45 .AddConstructor<BsmApplication> () | 45 .AddConstructor<BsmApplication> () |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // total length of time transmitting WAVE packets | 93 // total length of time transmitting WAVE packets |
94 Time totalTxTime = m_TotalSimTime - startTime; | 94 Time totalTxTime = m_TotalSimTime - startTime; |
95 // total WAVE packets needing to be sent | 95 // total WAVE packets needing to be sent |
96 m_numWavePackets = (uint32_t) (totalTxTime.GetDouble () / m_waveInterval.GetDo
uble ()); | 96 m_numWavePackets = (uint32_t) (totalTxTime.GetDouble () / m_waveInterval.GetDo
uble ()); |
97 | 97 |
98 TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); | 98 TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); |
99 | 99 |
100 // every node broadcasts WAVE BSM to potentially all other nodes | 100 // every node broadcasts WAVE BSM to potentially all other nodes |
101 Ptr<Socket> recvSink = Socket::CreateSocket (GetNode (m_nodeId), tid); | 101 Ptr<Socket> recvSink = Socket::CreateSocket (GetNode (m_nodeId), tid); |
102 recvSink->SetRecvCallback (MakeCallback (&BsmApplication::ReceiveWavePacket, t
his)); | 102 recvSink->SetRecvCallback (MakeCallback (&BsmApplication::ReceiveWavePacket, t
his)); |
103 InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), (uint16_t
)wavePort); | 103 InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), wavePort)
; |
104 recvSink->BindToNetDevice (GetNetDevice (m_nodeId)); | 104 recvSink->BindToNetDevice (GetNetDevice (m_nodeId)); |
105 recvSink->Bind (local); | 105 recvSink->Bind (local); |
106 recvSink->SetAllowBroadcast (true); | 106 recvSink->SetAllowBroadcast (true); |
107 | 107 |
108 // dest is broadcast address | 108 // dest is broadcast address |
109 InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"),
(uint16_t)wavePort); | 109 InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"),
wavePort); |
110 recvSink->Connect (remote); | 110 recvSink->Connect (remote); |
111 | 111 |
112 // Transmission start time for each BSM: | 112 // Transmission start time for each BSM: |
113 // We assume that the start transmission time | 113 // We assume that the start transmission time |
114 // for the first packet will be on a ns-3 time | 114 // for the first packet will be on a ns-3 time |
115 // "Second" boundary - e.g., 1.0 s. | 115 // "Second" boundary - e.g., 1.0 s. |
116 // However, the actual transmit time must reflect | 116 // However, the actual transmit time must reflect |
117 // additional effects of 1) clock drift and | 117 // additional effects of 1) clock drift and |
118 // 2) transmit delay requirements. | 118 // 2) transmit delay requirements. |
119 // 1) Clock drift - clocks are not perfectly | 119 // 1) Clock drift - clocks are not perfectly |
(...skipping 24 matching lines...) Expand all Loading... |
144 // (t_time + t_drift) | 144 // (t_time + t_drift) |
145 | 145 |
146 // WAVE devices sync to GPS time | 146 // WAVE devices sync to GPS time |
147 // and all devices would like to begin broadcasting | 147 // and all devices would like to begin broadcasting |
148 // their safety messages immediately at the start of | 148 // their safety messages immediately at the start of |
149 // the CCH interval. However, if all do so, then | 149 // the CCH interval. However, if all do so, then |
150 // significant collisions occur. Thus, we assume there | 150 // significant collisions occur. Thus, we assume there |
151 // is some GPS sync accuracy on GPS devices, | 151 // is some GPS sync accuracy on GPS devices, |
152 // typically 40-100 ns. | 152 // typically 40-100 ns. |
153 // Get a uniformly random number for GPS sync accuracy, in ns. | 153 // Get a uniformly random number for GPS sync accuracy, in ns. |
154 Time tDrift = NanoSeconds (m_unirv->GetInteger (0, (uint32_t)m_gpsAccuracyNs))
; | 154 Time tDrift = NanoSeconds (m_unirv->GetInteger (0, static_cast<uint32_t>(m_gps
AccuracyNs))); |
155 | 155 |
156 // When transmitting at a default rate of 10 Hz, | 156 // When transmitting at a default rate of 10 Hz, |
157 // the subsystem shall transmit every 100 ms +/- | 157 // the subsystem shall transmit every 100 ms +/- |
158 // a random value between 0 and 5 ms. [MPR-BSMTX-TXTIM-002] | 158 // a random value between 0 and 5 ms. [MPR-BSMTX-TXTIM-002] |
159 // Source: CAMP Vehicle Safety Communications 4 Consortium | 159 // Source: CAMP Vehicle Safety Communications 4 Consortium |
160 // On-board Minimum Performance Requirements | 160 // On-board Minimum Performance Requirements |
161 // for V2V Safety Systems Version 1.0, December 17, 2014 | 161 // for V2V Safety Systems Version 1.0, December 17, 2014 |
162 // max transmit delay (default 10ms) | 162 // max transmit delay (default 10ms) |
163 // get value for transmit delay, as number of ns | 163 // get value for transmit delay, as number of ns |
164 uint32_t d_ns = static_cast<uint32_t> (m_txMaxDelay.GetInteger ()); | 164 uint32_t d_ns = static_cast<uint32_t> (m_txMaxDelay.GetInteger ()); |
(...skipping 29 matching lines...) Expand all Loading... |
194 Time txMaxDelay) | 194 Time txMaxDelay) |
195 { | 195 { |
196 NS_LOG_FUNCTION (this); | 196 NS_LOG_FUNCTION (this); |
197 | 197 |
198 m_unirv = CreateObject<UniformRandomVariable> (); | 198 m_unirv = CreateObject<UniformRandomVariable> (); |
199 | 199 |
200 m_TotalSimTime = totalTime; | 200 m_TotalSimTime = totalTime; |
201 m_wavePacketSize = wavePacketSize; | 201 m_wavePacketSize = wavePacketSize; |
202 m_waveInterval = waveInterval; | 202 m_waveInterval = waveInterval; |
203 m_gpsAccuracyNs = gpsAccuracyNs; | 203 m_gpsAccuracyNs = gpsAccuracyNs; |
204 int size = rangesSq.size (); | 204 int size = static_cast<int>(rangesSq.size ()); |
205 m_waveBsmStats = waveBsmStats; | 205 m_waveBsmStats = waveBsmStats; |
206 m_nodesMoving = nodesMoving; | 206 m_nodesMoving = nodesMoving; |
207 m_chAccessMode = chAccessMode; | 207 m_chAccessMode = chAccessMode; |
208 m_txSafetyRangesSq.clear (); | 208 m_txSafetyRangesSq.clear (); |
209 m_txSafetyRangesSq.resize (size, 0); | 209 m_txSafetyRangesSq.resize (size, 0); |
210 | 210 |
211 for (int index = 0; index < size; index++) | 211 for (int index = 0; index < size; index++) |
212 { | 212 { |
213 // stored as square of value, for optimization | 213 // stored as square of value, for optimization |
214 m_txSafetyRangesSq[index] = rangesSq[index]; | 214 m_txSafetyRangesSq[index] = rangesSq[index]; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // has also started moving in the scenario | 268 // has also started moving in the scenario |
269 // if it has not started moving, then | 269 // if it has not started moving, then |
270 // it is not a candidate to receive a packet | 270 // it is not a candidate to receive a packet |
271 int receiverMoving = m_nodesMoving->at (rxNodeId); | 271 int receiverMoving = m_nodesMoving->at (rxNodeId); |
272 if (receiverMoving == 1) | 272 if (receiverMoving == 1) |
273 { | 273 { |
274 double distSq = MobilityHelper::GetDistanceSquaredBetween
(txNode, rxNode); | 274 double distSq = MobilityHelper::GetDistanceSquaredBetween
(txNode, rxNode); |
275 if (distSq > 0.0) | 275 if (distSq > 0.0) |
276 { | 276 { |
277 // dest node within range? | 277 // dest node within range? |
278 int rangeCount = m_txSafetyRangesSq.size (); | 278 int rangeCount = static_cast<int>(m_txSafetyRangesSq.s
ize ()); |
279 for (int index = 1; index <= rangeCount; index++) | 279 for (int index = 1; index <= rangeCount; index++) |
280 { | 280 { |
281 if (distSq <= m_txSafetyRangesSq[index - 1]) | 281 if (distSq <= m_txSafetyRangesSq[index - 1]) |
282 { | 282 { |
283 // we should expect dest node to receive broad
cast pkt | 283 // we should expect dest node to receive broad
cast pkt |
284 m_waveBsmStats->IncExpectedRxPktCount (index); | 284 m_waveBsmStats->IncExpectedRxPktCount (index); |
285 } | 285 } |
286 } | 286 } |
287 } | 287 } |
288 } | 288 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 // has also started moving in the scenario | 353 // has also started moving in the scenario |
354 // if it has not started moving, then | 354 // if it has not started moving, then |
355 // it is not a candidate to receive a packet | 355 // it is not a candidate to receive a packet |
356 int rxNodeId = rxNode->GetId (); | 356 int rxNodeId = rxNode->GetId (); |
357 int receiverMoving = m_nodesMoving->at (rxNodeId); | 357 int receiverMoving = m_nodesMoving->at (rxNodeId); |
358 if (receiverMoving == 1) | 358 if (receiverMoving == 1) |
359 { | 359 { |
360 double rxDistSq = MobilityHelper::GetDistanceSquaredBetween (rxNode, txNod
e); | 360 double rxDistSq = MobilityHelper::GetDistanceSquaredBetween (rxNode, txNod
e); |
361 if (rxDistSq > 0.0) | 361 if (rxDistSq > 0.0) |
362 { | 362 { |
363 int rangeCount = m_txSafetyRangesSq.size (); | 363 int rangeCount = static_cast<int>(m_txSafetyRangesSq.size ()); |
364 for (int index = 1; index <= rangeCount; index++) | 364 for (int index = 1; index <= rangeCount; index++) |
365 { | 365 { |
366 if (rxDistSq <= m_txSafetyRangesSq[index - 1]) | 366 if (rxDistSq <= m_txSafetyRangesSq[index - 1]) |
367 { | 367 { |
368 m_waveBsmStats->IncRxPktInRangeCount (index); | 368 m_waveBsmStats->IncRxPktInRangeCount (index); |
369 } | 369 } |
370 } | 370 } |
371 } | 371 } |
372 } | 372 } |
373 } | 373 } |
(...skipping 27 matching lines...) Expand all Loading... |
401 NS_LOG_FUNCTION (this); | 401 NS_LOG_FUNCTION (this); |
402 | 402 |
403 std::pair<Ptr<Ipv4>, uint32_t> interface = m_adhocTxInterfaces->Get (id); | 403 std::pair<Ptr<Ipv4>, uint32_t> interface = m_adhocTxInterfaces->Get (id); |
404 Ptr<Ipv4> pp = interface.first; | 404 Ptr<Ipv4> pp = interface.first; |
405 Ptr<NetDevice> device = pp->GetObject<NetDevice> (); | 405 Ptr<NetDevice> device = pp->GetObject<NetDevice> (); |
406 | 406 |
407 return device; | 407 return device; |
408 } | 408 } |
409 | 409 |
410 } // namespace ns3 | 410 } // namespace ns3 |
LEFT | RIGHT |