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/assert.h"
20 #include "ns3/simulator.h"
21 #include "ns3/qos-tag.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 
32 const static uint8_t oi_bytes_1609[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40};
33 const static OrganizationIdentifier oi_1609 = OrganizationIdentifier (oi_bytes_1609, 5);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::VsaManager")
39  .SetParent<Object> ()
40  .AddConstructor<VsaManager> ()
41  ;
42  return tid;
43 }
44 
46  : m_device (0)
47 {
48  m_vsaReceived = MakeNullCallback<bool, Ptr<const Packet>,const Address &, uint32_t, uint32_t> ();
49 }
50 
52 {
53 
54 }
55 
56 void
58 {
59  NS_LOG_FUNCTION (this);
60  RemoveAll ();
61  m_device = 0;
62 }
63 
64 void
66 {
67  std::map<uint32_t, Ptr<OcbWifiMac> > macs = m_device->GetMacs ();
68  for (std::map<uint32_t, Ptr<OcbWifiMac> >::iterator i = macs.begin (); i != macs.end (); ++i)
69  {
70  i->second->AddReceiveVscCallback (oi_1609, MakeCallback (&VsaManager::ReceiveVsc, this));
71  }
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this << device);
78  m_device = device;
79 }
80 
81 void
82 VsaManager::SendVsa (const VsaInfo & vsaInfo)
83 {
84  NS_LOG_FUNCTION (this << &vsaInfo);
86  if (vsaInfo.oi.IsNull ())
87  {
88  // refer to 1609.4-2010 chapter 6.4.1.1
89  uint8_t oibytes[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40};
90  oibytes[4] |= (vsaInfo.managementId & 0x0f);
91  oi = OrganizationIdentifier (oibytes, 5);
92  }
93  else
94  {
95  oi = vsaInfo.oi;
96  }
97 
98  // if destination MAC address is the unicast address or repeat rate is 0,
99  // then only single one VSA frame is to be sent.
100  if (vsaInfo.peer.IsGroup () && (vsaInfo.repeatRate != 0))
101  {
102  VsaWork *vsa = new VsaWork ();
103  vsa->sentInterval = vsaInfo.sendInterval;
104  vsa->channelNumber = vsaInfo.channelNumber;
105  vsa->peer = vsaInfo.peer;
106  vsa->repeatPeriod = MilliSeconds (VSA_REPEAT_PERIOD * 1000 / vsaInfo.repeatRate);
107  vsa->vsc = vsaInfo.vsc;
108  vsa->oi = oi;
109  vsa->repeat = Simulator::Schedule (vsa->repeatPeriod, &VsaManager::DoRepeat, this, vsa);
110  m_vsas.push_back (vsa);
111  }
112  DoSendVsa (vsaInfo.sendInterval, vsaInfo.channelNumber, vsaInfo.vsc->Copy (), oi, vsaInfo.peer);
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << vsa);
119  vsa->repeat = Simulator::Schedule (vsa->repeatPeriod, &VsaManager::DoRepeat, this, vsa);
120  DoSendVsa (vsa->sentInterval, vsa->channelNumber, vsa->vsc->Copy (), vsa->oi, vsa->peer);
121 }
122 
123 void
124 VsaManager::DoSendVsa (enum VsaTransmitInterval interval, uint32_t channel,
126 {
127  NS_LOG_FUNCTION (this << interval << channel << vsc << oi << peer);
128  NS_ASSERT (m_device != 0);
132 
133  // if the request is for transmitting in SCH Interval (or CCH Interval), but currently
134  // is not in SCH Interval (or CCH Interval) and , then the WAVE device will wait
135  // some time to insert this VSA frame into MAC internal queue.
136  // if the request is for transmitting in any channel interval, then the WAVE device
137  // insert this VSA frame into MAC internal queue immediately.
138  if (interval == VSA_TRANSMIT_IN_SCHI)
139  {
140  Time wait = coordinator->NeedTimeToSchInterval ();
141  if (wait != Seconds (0))
142  {
144  interval, channel, vsc, oi, peer);
145  return;
146  }
147  }
148  else if (interval == VSA_TRANSMIT_IN_CCHI)
149  {
150  Time wait = coordinator->NeedTimeToCchInterval ();
151  if (wait != Seconds (0))
152  {
154  interval, channel, vsc, oi, peer);
155  return;
156  }
157  }
158  else
159  {
160  NS_ASSERT (interval == VSA_TRANSMIT_IN_BOTHI);
161  // do nothing here, since VSA_IN_BOTHI allows to sent VSA frames in any interval.
162  }
163 
164  if (!scheduler->IsChannelAccessAssigned (channel))
165  {
166  NS_LOG_DEBUG ("there is no channel access assigned for channel " << channel);
167  return;
168  }
169 
170  // refer to 1609.4-2010 chapter 5.4.1
171  // Management frames are assigned the highest AC (AC_VO).
172  QosTag qosTag (7);
173  vsc->AddPacketTag (qosTag);
174 
175  WifiTxVector txVector;
176  txVector.SetTxPowerLevel (manager->GetManagementPowerLevel (channel));
177  txVector.SetMode (manager->GetManagementDataRate (channel));
178  HigherLayerTxVectorTag tag = HigherLayerTxVectorTag (txVector, manager->GetManagementAdaptable (channel));
179  vsc->AddPacketTag (tag);
180 
181  Ptr<OcbWifiMac> mac = m_device->GetMac (channel);
182  mac->SendVsc (vsc, peer, oi);
183 }
184 
185 void
187 {
188  NS_LOG_FUNCTION (this);
189  for (std::vector<VsaWork *>::iterator i = m_vsas.begin ();
190  i != m_vsas.end (); ++i)
191  {
192  if (!(*i)->repeat.IsExpired ())
193  {
194  (*i)->repeat.Cancel ();
195  }
196  (*i)->vsc = 0;
197  delete (*i);
198  }
199  m_vsas.clear ();
200 }
201 
202 void
203 VsaManager::RemoveByChannel (uint32_t channelNumber)
204 {
205  NS_LOG_FUNCTION (this << channelNumber);
206  for (std::vector<VsaWork *>::iterator i = m_vsas.begin ();
207  i != m_vsas.end (); )
208  {
209  if ((*i)->channelNumber == channelNumber)
210  {
211  if (!(*i)->repeat.IsExpired ())
212  {
213  (*i)->repeat.Cancel ();
214  }
215  (*i)->vsc = 0;
216  delete (*i);
217  i = m_vsas.erase (i);
218  }
219  else
220  {
221  ++i;
222  }
223  }
224 }
225 
226 
227 void
229 {
230  NS_LOG_FUNCTION (this << oi);
231  for (std::vector<VsaWork *>::iterator i = m_vsas.begin ();
232  i != m_vsas.end (); )
233  {
234  if ((*i)->oi == oi)
235  {
236  if (!(*i)->repeat.IsExpired ())
237  {
238  (*i)->repeat.Cancel ();
239  }
240  (*i)->vsc = 0;
241  delete (*i);
242  i = m_vsas.erase (i);
243  }
244  else
245  {
246  ++i;
247  }
248  }
249 }
250 
251 void
252 VsaManager::SetWaveVsaCallback (Callback<bool, Ptr<const Packet>,const Address &, uint32_t, uint32_t> vsaCallback)
253 {
254  NS_LOG_FUNCTION (this);
255  m_vsaReceived = vsaCallback;
256 }
257 
258 bool
260 {
261  NS_LOG_FUNCTION (this << mac << oi << vsc << src);
262  NS_ASSERT (oi == oi_1609);
263  if (m_vsaReceived.IsNull ())
264  {
265  return true;
266  }
267  uint32_t channelNumber = mac->GetWifiPhy ()->GetChannelNumber ();
268  uint32_t managementId = oi.GetManagementId ();
269  return m_vsaReceived (vsc, src, managementId, channelNumber);
270 }
271 } // namespace ns3
Ptr< WaveNetDevice > m_device
Definition: vsa-manager.h:177
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
#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:978
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
Definition: vsa-manager.h:147
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:836
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
void SendVsc(Ptr< Packet > vsc, Mac48Address peer, OrganizationIdentifier oi)
Definition: ocb-wifi-mac.cc:68
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:867
virtual ~VsaManager(void)
Definition: vsa-manager.cc:51
static const uint8_t oi_bytes_1609[5]
Definition: vsa-manager.cc:32
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
void SendVsa(const VsaInfo &vsaInfo)
Definition: vsa-manager.cc:82
void SetWaveVsaCallback(Callback< bool, Ptr< const Packet >, const Address &, uint32_t, uint32_t > vsaCallback)
Definition: vsa-manager.cc:252
Ptr< Packet > vsc
Definition: vsa-manager.h:64
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission...
Definition: higher-tx-tag.h:45
a polymophic address class
Definition: address.h:90
void DoSendVsa(enum VsaTransmitInterval interval, uint32_t channel, Ptr< Packet > vsc, OrganizationIdentifier oi, Mac48Address peer)
Definition: vsa-manager.cc:124
static TypeId GetTypeId(void)
Definition: vsa-manager.cc:36
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
enum VsaTransmitInterval sentInterval
Definition: vsa-manager.h:155
uint8_t managementId
Definition: vsa-manager.h:63
void DoInitialize(void)
Initialize() implementation.
Definition: vsa-manager.cc:65
the organization identifier is a public organizationally unique identifier assigned by the IEEE...
void DoDispose(void)
Destructor implementation.
Definition: vsa-manager.cc:57
Time NeedTimeToCchInterval(Time duration=Seconds(0.0)) const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: vsa-manager.cc:75
The aim of the QosTag is to provide means for an Application to specify the TID which will be used by...
Definition: qos-tag.h:61
void DoRepeat(VsaWork *vsa)
Definition: vsa-manager.cc:116
std::vector< VsaWork * > m_vsas
Definition: vsa-manager.h:176
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
std::map< uint32_t, Ptr< OcbWifiMac > > GetMacs(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
VsaTransmitInterval
indicate which interval the VSA frames will be transmitted in.
Definition: vsa-manager.h:32
uint32_t channelNumber
Definition: vsa-manager.h:65
static const OrganizationIdentifier oi_1609
Definition: vsa-manager.cc:33
bool IsGroup(void) const
Ptr< OcbWifiMac > GetMac(uint32_t channelNumber) const
Time NeedTimeToSchInterval(Time duration=Seconds(0.0)) const
an EUI-48 address
Definition: mac48-address.h:43
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
Mac48Address peer
Definition: vsa-manager.h:61
uint8_t repeatRate
Definition: vsa-manager.h:66
Ptr< ChannelManager > GetChannelManager(void) const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void RemoveByChannel(uint32_t channelNumber)
Definition: vsa-manager.cc:203
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
OrganizationIdentifier oi
Definition: vsa-manager.h:62
OrganizationIdentifier oi
Definition: vsa-manager.h:152
A base class which provides memory management and object aggregation.
Definition: object.h:87
uint8_t GetManagementId(void) const
Ptr< ChannelScheduler > GetChannelScheduler(void) const
Callback< bool, Ptr< const Packet >, const Address &, uint32_t, uint32_t > m_vsaReceived
Definition: vsa-manager.h:175
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
void RemoveAll(void)
cancel all VSA transmissions
Definition: vsa-manager.cc:186
bool ReceiveVsc(Ptr< WifiMac > mac, const OrganizationIdentifier &oi, Ptr< const Packet > vsc, const Address &src)
Definition: vsa-manager.cc:259
void RemoveByOrganizationIdentifier(const OrganizationIdentifier &oi)
Definition: vsa-manager.cc:228
enum VsaTransmitInterval sendInterval
Definition: vsa-manager.h:67