A Discrete-Event Network Simulator
API
vsa-manager.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Author: Junling Bu <linlinjavaer@gmail.com>
16  */
17 #include "vsa-manager.h"
18 
19 #include "higher-tx-tag.h"
20 #include "wave-net-device.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 #include "ns3/socket.h"
25 #include "ns3/wifi-phy.h"
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("VsaManager");
31 
32 NS_OBJECT_ENSURE_REGISTERED(VsaManager);
33 
35 const static uint8_t oi_bytes_1609[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40};
38 
39 TypeId
41 {
42  static TypeId tid = TypeId("ns3::VsaManager")
43  .SetParent<Object>()
44  .SetGroupName("Wave")
45  .AddConstructor<VsaManager>();
46  return tid;
47 }
48 
50  : m_device(nullptr)
51 {
52  m_vsaReceived = MakeNullCallback<bool, Ptr<const Packet>, const Address&, uint32_t, uint32_t>();
53 }
54 
56 {
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION(this);
63  RemoveAll();
64  m_device = nullptr;
65 }
66 
67 void
69 {
70  std::map<uint32_t, Ptr<OcbWifiMac>> macs = m_device->GetMacs();
71  for (std::map<uint32_t, Ptr<OcbWifiMac>>::iterator i = macs.begin(); i != macs.end(); ++i)
72  {
73  i->second->AddReceiveVscCallback(oi_1609, MakeCallback(&VsaManager::ReceiveVsc, this));
74  }
75 }
76 
77 void
79 {
80  NS_LOG_FUNCTION(this << device);
81  m_device = device;
82 }
83 
84 void
86 {
87  NS_LOG_FUNCTION(this << &vsaInfo);
89  if (vsaInfo.oi.IsNull())
90  {
91  // refer to 1609.4-2010 chapter 6.4.1.1
92  uint8_t oibytes[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40};
93  oibytes[4] |= (vsaInfo.managementId & 0x0f);
94  oi = OrganizationIdentifier(oibytes, 5);
95  }
96  else
97  {
98  oi = vsaInfo.oi;
99  }
100 
101  // if destination MAC address is the unicast address or repeat rate is 0,
102  // then only single one VSA frame is to be sent.
103  if (vsaInfo.peer.IsGroup() && (vsaInfo.repeatRate != 0))
104  {
105  VsaWork* vsa = new VsaWork();
106  vsa->sentInterval = vsaInfo.sendInterval;
107  vsa->channelNumber = vsaInfo.channelNumber;
108  vsa->peer = vsaInfo.peer;
109  vsa->repeatPeriod = MilliSeconds(VSA_REPEAT_PERIOD * 1000 / vsaInfo.repeatRate);
110  vsa->vsc = vsaInfo.vsc;
111  vsa->oi = oi;
113  m_vsas.push_back(vsa);
114  }
115  DoSendVsa(vsaInfo.sendInterval, vsaInfo.channelNumber, vsaInfo.vsc->Copy(), oi, vsaInfo.peer);
116 }
117 
118 void
120 {
121  NS_LOG_FUNCTION(this << vsa);
123  DoSendVsa(vsa->sentInterval, vsa->channelNumber, vsa->vsc->Copy(), vsa->oi, vsa->peer);
124 }
125 
126 void
128  uint32_t channel,
129  Ptr<Packet> vsc,
131  Mac48Address peer)
132 {
133  NS_LOG_FUNCTION(this << interval << channel << vsc << oi << peer);
138 
139  // if the request is for transmitting in SCH Interval (or CCH Interval), but currently
140  // is not in SCH Interval (or CCH Interval) and , then the WAVE device will wait
141  // some time to insert this VSA frame into MAC internal queue.
142  // if the request is for transmitting in any channel interval, then the WAVE device
143  // insert this VSA frame into MAC internal queue immediately.
144  if (interval == VSA_TRANSMIT_IN_SCHI)
145  {
146  Time wait = coordinator->NeedTimeToSchInterval();
147  if (wait != Seconds(0))
148  {
149  Simulator::Schedule(wait,
151  this,
152  interval,
153  channel,
154  vsc,
155  oi,
156  peer);
157  return;
158  }
159  }
160  else if (interval == VSA_TRANSMIT_IN_CCHI)
161  {
162  Time wait = coordinator->NeedTimeToCchInterval();
163  if (wait != Seconds(0))
164  {
165  Simulator::Schedule(wait,
167  this,
168  interval,
169  channel,
170  vsc,
171  oi,
172  peer);
173  return;
174  }
175  }
176  else
177  {
178  NS_ASSERT(interval == VSA_TRANSMIT_IN_BOTHI);
179  // do nothing here, since VSA_IN_BOTHI allows to sent VSA frames in any interval.
180  }
181 
182  if (!scheduler->IsChannelAccessAssigned(channel))
183  {
184  NS_LOG_DEBUG("there is no channel access assigned for channel " << channel);
185  return;
186  }
187 
188  // refer to 1609.4-2010 chapter 5.4.1
189  // Management frames are assigned the highest AC (AC_VO).
190  SocketPriorityTag priorityTag;
191  priorityTag.SetPriority(7);
192  vsc->AddPacketTag(priorityTag);
193 
194  WifiTxVector txVector;
195  txVector.SetChannelWidth(10);
196  txVector.SetTxPowerLevel(manager->GetManagementPowerLevel(channel));
197  txVector.SetMode(manager->GetManagementDataRate(channel));
198  txVector.SetPreambleType(manager->GetManagementPreamble(channel));
200  HigherLayerTxVectorTag(txVector, manager->GetManagementAdaptable(channel));
201  vsc->AddPacketTag(tag);
202 
204  mac->SendVsc(vsc, peer, oi);
205 }
206 
207 void
209 {
210  NS_LOG_FUNCTION(this);
211  for (std::vector<VsaWork*>::iterator i = m_vsas.begin(); i != m_vsas.end(); ++i)
212  {
213  if (!(*i)->repeat.IsExpired())
214  {
215  (*i)->repeat.Cancel();
216  }
217  (*i)->vsc = nullptr;
218  delete (*i);
219  }
220  m_vsas.clear();
221 }
222 
223 void
224 VsaManager::RemoveByChannel(uint32_t channelNumber)
225 {
226  NS_LOG_FUNCTION(this << channelNumber);
227  for (std::vector<VsaWork*>::iterator i = m_vsas.begin(); i != m_vsas.end();)
228  {
229  if ((*i)->channelNumber == channelNumber)
230  {
231  if (!(*i)->repeat.IsExpired())
232  {
233  (*i)->repeat.Cancel();
234  }
235  (*i)->vsc = nullptr;
236  delete (*i);
237  i = m_vsas.erase(i);
238  }
239  else
240  {
241  ++i;
242  }
243  }
244 }
245 
246 void
248 {
249  NS_LOG_FUNCTION(this << oi);
250  for (std::vector<VsaWork*>::iterator i = m_vsas.begin(); i != m_vsas.end();)
251  {
252  if ((*i)->oi == oi)
253  {
254  if (!(*i)->repeat.IsExpired())
255  {
256  (*i)->repeat.Cancel();
257  }
258  (*i)->vsc = nullptr;
259  delete (*i);
260  i = m_vsas.erase(i);
261  }
262  else
263  {
264  ++i;
265  }
266  }
267 }
268 
269 void
271  Callback<bool, Ptr<const Packet>, const Address&, uint32_t, uint32_t> vsaCallback)
272 {
273  NS_LOG_FUNCTION(this);
274  m_vsaReceived = vsaCallback;
275 }
276 
277 bool
279  const OrganizationIdentifier& oi,
280  Ptr<const Packet> vsc,
281  const Address& src)
282 {
283  NS_LOG_FUNCTION(this << mac << oi << vsc << src);
284  NS_ASSERT(oi == oi_1609);
285  if (m_vsaReceived.IsNull())
286  {
287  return true;
288  }
289  uint32_t channelNumber = mac->GetWifiPhy()->GetChannelNumber();
290  uint32_t managementId = oi.GetManagementId();
291  return m_vsaReceived(vsc, src, managementId, channelNumber);
292 }
293 } // namespace ns3
a polymophic address class
Definition: address.h:100
Callback template class.
Definition: callback.h:443
Time NeedTimeToCchInterval(Time duration=Seconds(0.0)) const
Time NeedTimeToSchInterval(Time duration=Seconds(0.0)) const
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission.
Definition: higher-tx-tag.h:48
an EUI-48 address
Definition: mac48-address.h:46
bool IsGroup() const
A base class which provides memory management and object aggregation.
Definition: object.h:89
the organization identifier is a public organizationally unique identifier assigned by the IEEE.
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:979
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
indicates whether the socket has a priority set.
Definition: socket.h:1316
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition: socket.cc:852
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
refer to 1609.4-2010 chapter 6.4 Vendor Specific Action (VSA) frames transmission.
Definition: vsa-manager.h:125
void RemoveAll()
cancel all VSA transmissions
Definition: vsa-manager.cc:208
void SetWaveVsaCallback(Callback< bool, Ptr< const Packet >, const Address &, uint32_t, uint32_t > vsaCallback)
Set wave vsa callback function.
Definition: vsa-manager.cc:270
void DoInitialize() override
Initialize() implementation.
Definition: vsa-manager.cc:68
Ptr< WaveNetDevice > m_device
the device
Definition: vsa-manager.h:217
static const uint32_t VSA_REPEAT_PERIOD
A number of VSA frames will be transmitted repeatedly during the period of 5s.
Definition: vsa-manager.h:181
void DoRepeat(VsaWork *vsa)
Definition: vsa-manager.cc:119
void DoDispose() override
Destructor implementation.
Definition: vsa-manager.cc:60
bool ReceiveVsc(Ptr< WifiMac > mac, const OrganizationIdentifier &oi, Ptr< const Packet > vsc, const Address &src)
Definition: vsa-manager.cc:278
void DoSendVsa(VsaTransmitInterval interval, uint32_t channel, Ptr< Packet > vsc, OrganizationIdentifier oi, Mac48Address peer)
Definition: vsa-manager.cc:127
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: vsa-manager.cc:78
Callback< bool, Ptr< const Packet >, const Address &, uint32_t, uint32_t > m_vsaReceived
VSA received callback.
Definition: vsa-manager.h:215
~VsaManager() override
Definition: vsa-manager.cc:55
static TypeId GetTypeId()
Get the type ID.
Definition: vsa-manager.cc:40
std::vector< VsaWork * > m_vsas
VSAs.
Definition: vsa-manager.h:216
void RemoveByChannel(uint32_t channelNumber)
Definition: vsa-manager.cc:224
void RemoveByOrganizationIdentifier(const OrganizationIdentifier &oi)
Definition: vsa-manager.cc:247
void SendVsa(const VsaInfo &vsaInfo)
Definition: vsa-manager.cc:85
Ptr< ChannelScheduler > GetChannelScheduler() const
std::map< uint32_t, Ptr< OcbWifiMac > > GetMacs() const
Ptr< ChannelCoordinator > GetChannelCoordinator() const
Ptr< OcbWifiMac > GetMac(uint32_t channelNumber) const
Ptr< ChannelManager > GetChannelManager() const
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
VsaTransmitInterval
indicate which interval the VSA frames will be transmitted in.
Definition: vsa-manager.h:36
@ VSA_TRANSMIT_IN_CCHI
Definition: vsa-manager.h:37
@ VSA_TRANSMIT_IN_BOTHI
Definition: vsa-manager.h:39
@ VSA_TRANSMIT_IN_SCHI
Definition: vsa-manager.h:38
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:707
static const OrganizationIdentifier oi_1609
OI for IEEE standard 1609.
Definition: vsa-manager.cc:37
static const uint8_t oi_bytes_1609[5]
OI bytes for use in organization identifier.
Definition: vsa-manager.cc:35
channel
Definition: third.py:81
mac
Definition: third.py:85
uint8_t managementId
management ID
Definition: vsa-manager.h:67
VsaTransmitInterval sendInterval
send interval
Definition: vsa-manager.h:71
uint32_t channelNumber
channel number
Definition: vsa-manager.h:69
uint8_t repeatRate
repeat rate
Definition: vsa-manager.h:70
Mac48Address peer
peer
Definition: vsa-manager.h:65
Ptr< Packet > vsc
VSC.
Definition: vsa-manager.h:68
OrganizationIdentifier oi
OI.
Definition: vsa-manager.h:66
VsaWork structure.
Definition: vsa-manager.h:185
Mac48Address peer
peer
Definition: vsa-manager.h:186
Ptr< Packet > vsc
VSC.
Definition: vsa-manager.h:188
Time repeatPeriod
repeat period
Definition: vsa-manager.h:191
OrganizationIdentifier oi
OI.
Definition: vsa-manager.h:187
VsaTransmitInterval sentInterval
VSA transmit interval.
Definition: vsa-manager.h:190
uint32_t channelNumber
channel number
Definition: vsa-manager.h:189
EventId repeat
repeat ID
Definition: vsa-manager.h:192