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/socket.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  .SetGroupName ("Wave")
41  .AddConstructor<VsaManager> ()
42  ;
43  return tid;
44 }
45 
47  : m_device (0)
48 {
49  m_vsaReceived = MakeNullCallback<bool, Ptr<const Packet>,const Address &, uint32_t, uint32_t> ();
50 }
51 
53 {
54 
55 }
56 
57 void
59 {
60  NS_LOG_FUNCTION (this);
61  RemoveAll ();
62  m_device = 0;
63 }
64 
65 void
67 {
68  std::map<uint32_t, Ptr<OcbWifiMac> > macs = m_device->GetMacs ();
69  for (std::map<uint32_t, Ptr<OcbWifiMac> >::iterator i = macs.begin (); i != macs.end (); ++i)
70  {
71  i->second->AddReceiveVscCallback (oi_1609, MakeCallback (&VsaManager::ReceiveVsc, this));
72  }
73 }
74 
75 void
77 {
78  NS_LOG_FUNCTION (this << device);
79  m_device = device;
80 }
81 
82 void
83 VsaManager::SendVsa (const VsaInfo & vsaInfo)
84 {
85  NS_LOG_FUNCTION (this << &vsaInfo);
87  if (vsaInfo.oi.IsNull ())
88  {
89  // refer to 1609.4-2010 chapter 6.4.1.1
90  uint8_t oibytes[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40};
91  oibytes[4] |= (vsaInfo.managementId & 0x0f);
92  oi = OrganizationIdentifier (oibytes, 5);
93  }
94  else
95  {
96  oi = vsaInfo.oi;
97  }
98 
99  // if destination MAC address is the unicast address or repeat rate is 0,
100  // then only single one VSA frame is to be sent.
101  if (vsaInfo.peer.IsGroup () && (vsaInfo.repeatRate != 0))
102  {
103  VsaWork *vsa = new VsaWork ();
104  vsa->sentInterval = vsaInfo.sendInterval;
105  vsa->channelNumber = vsaInfo.channelNumber;
106  vsa->peer = vsaInfo.peer;
107  vsa->repeatPeriod = MilliSeconds (VSA_REPEAT_PERIOD * 1000 / vsaInfo.repeatRate);
108  vsa->vsc = vsaInfo.vsc;
109  vsa->oi = oi;
110  vsa->repeat = Simulator::Schedule (vsa->repeatPeriod, &VsaManager::DoRepeat, this, vsa);
111  m_vsas.push_back (vsa);
112  }
113  DoSendVsa (vsaInfo.sendInterval, vsaInfo.channelNumber, vsaInfo.vsc->Copy (), oi, vsaInfo.peer);
114 }
115 
116 void
118 {
119  NS_LOG_FUNCTION (this << vsa);
120  vsa->repeat = Simulator::Schedule (vsa->repeatPeriod, &VsaManager::DoRepeat, this, vsa);
121  DoSendVsa (vsa->sentInterval, vsa->channelNumber, vsa->vsc->Copy (), vsa->oi, vsa->peer);
122 }
123 
124 void
127 {
128  NS_LOG_FUNCTION (this << interval << channel << vsc << oi << peer);
129  NS_ASSERT (m_device != 0);
133 
134  // if the request is for transmitting in SCH Interval (or CCH Interval), but currently
135  // is not in SCH Interval (or CCH Interval) and , then the WAVE device will wait
136  // some time to insert this VSA frame into MAC internal queue.
137  // if the request is for transmitting in any channel interval, then the WAVE device
138  // insert this VSA frame into MAC internal queue immediately.
139  if (interval == VSA_TRANSMIT_IN_SCHI)
140  {
141  Time wait = coordinator->NeedTimeToSchInterval ();
142  if (wait != Seconds (0))
143  {
145  interval, channel, vsc, oi, peer);
146  return;
147  }
148  }
149  else if (interval == VSA_TRANSMIT_IN_CCHI)
150  {
151  Time wait = coordinator->NeedTimeToCchInterval ();
152  if (wait != Seconds (0))
153  {
155  interval, channel, vsc, oi, peer);
156  return;
157  }
158  }
159  else
160  {
161  NS_ASSERT (interval == VSA_TRANSMIT_IN_BOTHI);
162  // do nothing here, since VSA_IN_BOTHI allows to sent VSA frames in any interval.
163  }
164 
165  if (!scheduler->IsChannelAccessAssigned (channel))
166  {
167  NS_LOG_DEBUG ("there is no channel access assigned for channel " << channel);
168  return;
169  }
170 
171  // refer to 1609.4-2010 chapter 5.4.1
172  // Management frames are assigned the highest AC (AC_VO).
173  SocketPriorityTag priorityTag;
174  priorityTag.SetPriority (7);
175  vsc->AddPacketTag (priorityTag);
176 
177  WifiTxVector txVector;
178  txVector.SetChannelWidth (10);
179  txVector.SetTxPowerLevel (manager->GetManagementPowerLevel (channel));
180  txVector.SetMode (manager->GetManagementDataRate (channel));
181  HigherLayerTxVectorTag tag = HigherLayerTxVectorTag (txVector, manager->GetManagementAdaptable (channel));
182  vsc->AddPacketTag (tag);
183 
184  Ptr<OcbWifiMac> mac = m_device->GetMac (channel);
185  mac->SendVsc (vsc, peer, oi);
186 }
187 
188 void
190 {
191  NS_LOG_FUNCTION (this);
192  for (std::vector<VsaWork *>::iterator i = m_vsas.begin ();
193  i != m_vsas.end (); ++i)
194  {
195  if (!(*i)->repeat.IsExpired ())
196  {
197  (*i)->repeat.Cancel ();
198  }
199  (*i)->vsc = 0;
200  delete (*i);
201  }
202  m_vsas.clear ();
203 }
204 
205 void
206 VsaManager::RemoveByChannel (uint32_t channelNumber)
207 {
208  NS_LOG_FUNCTION (this << channelNumber);
209  for (std::vector<VsaWork *>::iterator i = m_vsas.begin ();
210  i != m_vsas.end (); )
211  {
212  if ((*i)->channelNumber == channelNumber)
213  {
214  if (!(*i)->repeat.IsExpired ())
215  {
216  (*i)->repeat.Cancel ();
217  }
218  (*i)->vsc = 0;
219  delete (*i);
220  i = m_vsas.erase (i);
221  }
222  else
223  {
224  ++i;
225  }
226  }
227 }
228 
229 
230 void
232 {
233  NS_LOG_FUNCTION (this << oi);
234  for (std::vector<VsaWork *>::iterator i = m_vsas.begin ();
235  i != m_vsas.end (); )
236  {
237  if ((*i)->oi == oi)
238  {
239  if (!(*i)->repeat.IsExpired ())
240  {
241  (*i)->repeat.Cancel ();
242  }
243  (*i)->vsc = 0;
244  delete (*i);
245  i = m_vsas.erase (i);
246  }
247  else
248  {
249  ++i;
250  }
251  }
252 }
253 
254 void
255 VsaManager::SetWaveVsaCallback (Callback<bool, Ptr<const Packet>,const Address &, uint32_t, uint32_t> vsaCallback)
256 {
257  NS_LOG_FUNCTION (this);
258  m_vsaReceived = vsaCallback;
259 }
260 
261 bool
263 {
264  NS_LOG_FUNCTION (this << mac << oi << vsc << src);
265  NS_ASSERT (oi == oi_1609);
266  if (m_vsaReceived.IsNull ())
267  {
268  return true;
269  }
270  uint32_t channelNumber = mac->GetWifiPhy ()->GetChannelNumber ();
271  uint32_t managementId = oi.GetManagementId ();
272  return m_vsaReceived (vsc, src, managementId, channelNumber);
273 }
274 } // namespace ns3
Ptr< WaveNetDevice > m_device
Definition: vsa-manager.h:177
tuple channel
Definition: third.py:85
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
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:824
#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
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:903
refer to 1609.4-2010 chapter 6.4 Vendor Specific Action (VSA) frames transmission.
Definition: vsa-manager.h:104
virtual ~VsaManager(void)
Definition: vsa-manager.cc:52
static const uint8_t oi_bytes_1609[5]
Definition: vsa-manager.cc:32
void SendVsa(const VsaInfo &vsaInfo)
Definition: vsa-manager.cc:83
void SetWaveVsaCallback(Callback< bool, Ptr< const Packet >, const Address &, uint32_t, uint32_t > vsaCallback)
Definition: vsa-manager.cc:255
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
void SetChannelWidth(uint32_t channelWidth)
Sets the selected channelWidth (in MHz)
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:125
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:66
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
the organization identifier is a public organizationally unique identifier assigned by the IEEE...
void DoDispose(void)
Destructor implementation.
Definition: vsa-manager.cc:58
Time NeedTimeToCchInterval(Time duration=Seconds(0.0)) const
indicates whether the socket has a priority set.
Definition: socket.h:1304
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: vsa-manager.cc:76
void DoRepeat(VsaWork *vsa)
Definition: vsa-manager.cc:117
tuple mac
Definition: third.py:92
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:206
#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:895
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
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition: socket.cc:848
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:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
void RemoveAll(void)
cancel all VSA transmissions
Definition: vsa-manager.cc:189
bool ReceiveVsc(Ptr< WifiMac > mac, const OrganizationIdentifier &oi, Ptr< const Packet > vsc, const Address &src)
Definition: vsa-manager.cc:262
void RemoveByOrganizationIdentifier(const OrganizationIdentifier &oi)
Definition: vsa-manager.cc:231
enum VsaTransmitInterval sendInterval
Definition: vsa-manager.h:67