A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
adhoc-wifi-mac.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006, 2009 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #include "adhoc-wifi-mac.h"
23 
24 #include "ns3/pointer.h"
25 #include "ns3/log.h"
26 #include "ns3/string.h"
27 #include "ns3/boolean.h"
28 #include "ns3/trace-source-accessor.h"
29 
30 #include "qos-tag.h"
31 #include "mac-low.h"
32 #include "dcf-manager.h"
33 #include "mac-rx-middle.h"
34 #include "mac-tx-middle.h"
35 #include "msdu-aggregator.h"
36 #include "amsdu-subframe-header.h"
37 #include "mgt-headers.h"
38 
39 NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
40 
41 namespace ns3 {
42 
43 NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
44 
45 TypeId
47 {
48  static TypeId tid = TypeId ("ns3::AdhocWifiMac")
50  .AddConstructor<AdhocWifiMac> ()
51  ;
52  return tid;
53 }
54 
56 {
57  NS_LOG_FUNCTION (this);
58 
59  // Let the lower layers know that we are acting in an IBSS
61 }
62 
64 {
65  NS_LOG_FUNCTION (this);
66 }
67 
68 void
70 {
71  // In an IBSS, the BSSID is supposed to be generated per Section
72  // 11.1.3 of IEEE 802.11. We don't currently do this - instead we
73  // make an IBSS STA a bit like an AP, with the BSSID for frames
74  // transmitted by each STA set to that STA's address.
75  //
76  // This is why we're overriding this method.
78  RegularWifiMac::SetBssid (address);
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION (this << packet << to);
85  if (m_stationManager->IsBrandNew (to))
86  {
87  // In ad hoc mode, we assume that every destination supports all
88  // the rates we support.
89  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
90  {
92  }
94  }
95 
96  WifiMacHeader hdr;
97 
98  // If we are not a QoS STA then we definitely want to use AC_BE to
99  // transmit the packet. A TID of zero will map to AC_BE (through \c
100  // QosUtilsMapTidToAc()), so we use that as our default here.
101  uint8_t tid = 0;
102 
103  // For now, a STA that supports QoS does not support non-QoS
104  // associations, and vice versa. In future the STA model should fall
105  // back to non-QoS if talking to a peer that is also non-QoS. At
106  // that point there will need to be per-station QoS state maintained
107  // by the association state machine, and consulted here.
108  if (m_qosSupported)
109  {
112  hdr.SetQosNoEosp ();
113  hdr.SetQosNoAmsdu ();
114  // Transmission of multiple frames in the same TXOP is not
115  // supported for now
116  hdr.SetQosTxopLimit (0);
117 
118  // Fill in the QoS control field in the MAC header
119  tid = QosUtilsGetTidForPacket (packet);
120  // Any value greater than 7 is invalid and likely indicates that
121  // the packet had no QoS tag, so we revert to zero, which'll
122  // mean that AC_BE is used.
123  if (tid >= 7)
124  {
125  tid = 0;
126  }
127  hdr.SetQosTid (tid);
128  }
129  else
130  {
131  hdr.SetTypeData ();
132  }
133 
134  hdr.SetAddr1 (to);
135  hdr.SetAddr2 (m_low->GetAddress ());
136  hdr.SetAddr3 (GetBssid ());
137  hdr.SetDsNotFrom ();
138  hdr.SetDsNotTo ();
139 
140  if (m_qosSupported)
141  {
142  // Sanity check that the TID is valid
143  NS_ASSERT (tid < 8);
144  m_edca[QosUtilsMapTidToAc (tid)]->Queue (packet, hdr);
145  }
146  else
147  {
148  m_dca->Queue (packet, hdr);
149  }
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION (this);
157 
158  // The approach taken here is that, from the point of view of a STA
159  // in IBSS mode, the link is always up, so we immediately invoke the
160  // callback if one is set
161  linkUp ();
162 }
163 
164 void
166 {
167  NS_LOG_FUNCTION (this << packet << hdr);
168  NS_ASSERT (!hdr->IsCtl ());
169  Mac48Address from = hdr->GetAddr2 ();
170  Mac48Address to = hdr->GetAddr1 ();
171  if (hdr->IsData ())
172  {
173  if (hdr->IsQosData () && hdr->IsQosAmsdu ())
174  {
175  NS_LOG_DEBUG ("Received A-MSDU from" << from);
176  DeaggregateAmsduAndForward (packet, hdr);
177  }
178  else
179  {
180  ForwardUp (packet, from, to);
181  }
182  return;
183  }
184 
185  // Invoke the receive handler of our parent class to deal with any
186  // other frames. Specifically, this will handle Block Ack-related
187  // Management Action frames.
188  RegularWifiMac::Receive (packet, hdr);
189 }
190 
191 } // namespace ns3