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