A Discrete-Event Network Simulator
API
wimax-net-device.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008,2009 INRIA, UDcast
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@UDcast.com>
20  */
21 
22 #include "wimax-net-device.h"
23 
24 #include "bandwidth-manager.h"
25 #include "burst-profile-manager.h"
26 #include "connection-manager.h"
27 #include "send-params.h"
28 #include "service-flow-manager.h"
29 #include "wimax-channel.h"
30 
31 #include "ns3/callback.h"
32 #include "ns3/enum.h"
33 #include "ns3/llc-snap-header.h"
34 #include "ns3/node.h"
35 #include "ns3/packet-burst.h"
36 #include "ns3/packet.h"
37 #include "ns3/pointer.h"
38 #include "ns3/simulator.h"
39 #include "ns3/trace-source-accessor.h"
40 #include "ns3/uinteger.h"
41 
42 #include <list>
43 
44 namespace ns3
45 {
46 
47 NS_LOG_COMPONENT_DEFINE("WimaxNetDevice");
48 
49 NS_OBJECT_ENSURE_REGISTERED(WimaxNetDevice);
50 
51 uint32_t WimaxNetDevice::m_nrFrames = 0;
52 uint8_t WimaxNetDevice::m_direction = ~0;
54 
55 TypeId
57 {
58  static TypeId tid =
59  TypeId("ns3::WimaxNetDevice")
60 
62  .SetGroupName("Wimax")
63 
64  // No AddConstructor because this is an abstract class.
65 
66  .AddAttribute("Mtu",
67  "The MAC-level Maximum Transmission Unit",
70  MakeUintegerChecker<uint16_t>(0, MAX_MSDU_SIZE))
71 
72  .AddAttribute("Phy",
73  "The PHY layer attached to this device.",
74  PointerValue(),
76  MakePointerChecker<WimaxPhy>())
77 
78  .AddAttribute(
79  "Channel",
80  "The channel attached to this device.",
81  PointerValue(),
83  MakePointerChecker<WimaxChannel>())
84 
85  .AddAttribute("RTG",
86  "receive/transmit transition gap.",
87  UintegerValue(0),
89  MakeUintegerChecker<uint16_t>(0, 120))
90 
91  .AddAttribute("TTG",
92  "transmit/receive transition gap.",
93  UintegerValue(0),
95  MakeUintegerChecker<uint16_t>(0, 120))
96 
97  .AddAttribute("ConnectionManager",
98  "The connection manager attached to this device.",
99  PointerValue(),
102  MakePointerChecker<ConnectionManager>())
103 
104  .AddAttribute("BurstProfileManager",
105  "The burst profile manager attached to this device.",
106  PointerValue(),
109  MakePointerChecker<BurstProfileManager>())
110 
111  .AddAttribute("BandwidthManager",
112  "The bandwidth manager attached to this device.",
113  PointerValue(),
116  MakePointerChecker<BandwidthManager>())
117 
118  .AddAttribute("InitialRangingConnection",
119  "Initial ranging connection",
120  PointerValue(),
122  MakePointerChecker<WimaxConnection>())
123 
124  .AddAttribute("BroadcastConnection",
125  "Broadcast connection",
126  PointerValue(),
128  MakePointerChecker<WimaxConnection>())
129 
130  .AddTraceSource("Rx",
131  "Receive trace",
133  "ns3::WimaxNetDevice::TxRxTracedCallback")
134 
135  .AddTraceSource("Tx",
136  "Transmit trace",
138  "ns3::WimaxNetDevice::TxRxTracedCallback");
139  return tid;
140 }
141 
143  : m_state(0),
144  m_symbolIndex(0),
145  m_ttg(0),
146  m_rtg(0)
147 {
149  m_connectionManager = CreateObject<ConnectionManager>();
150  m_burstProfileManager = CreateObject<BurstProfileManager>(this);
151  m_bandwidthManager = CreateObject<BandwidthManager>(this);
152  m_nrFrames = 0;
153  m_direction = ~0;
155 }
156 
158 {
159 }
160 
161 void
163 {
164  m_phy->Dispose();
165  m_phy = nullptr;
166  m_node = nullptr;
167  m_initialRangingConnection = nullptr;
168  m_broadcastConnection = nullptr;
169  m_connectionManager = nullptr;
170  m_burstProfileManager = nullptr;
171  m_bandwidthManager = nullptr;
172 
174 }
175 
176 void
178 {
179  m_ttg = ttg;
180 }
181 
182 uint16_t
184 {
185  return m_ttg;
186 }
187 
188 void
190 {
191  m_rtg = rtg;
192 }
193 
194 uint16_t
196 {
197  return m_rtg;
198 }
199 
200 void
201 WimaxNetDevice::SetName(const std::string name)
202 {
203  m_name = name;
204 }
205 
206 std::string
208 {
209  return m_name;
210 }
211 
212 void
213 WimaxNetDevice::SetIfIndex(const uint32_t index)
214 {
215  m_ifIndex = index;
216 }
217 
218 uint32_t
220 {
221  return m_ifIndex;
222 }
223 
226 {
227  return DoGetChannel();
228 }
229 
232 {
233  return DoGetChannel();
234 }
235 
236 bool
237 WimaxNetDevice::SetMtu(const uint16_t mtu)
238 {
239  if (mtu > MAX_MSDU_SIZE)
240  {
241  return false;
242  }
243  m_mtu = mtu;
244  return true;
245 }
246 
247 uint16_t
249 {
250  return m_mtu;
251 }
252 
253 bool
255 {
256  return m_phy && m_linkUp;
257 }
258 
259 void
261 {
262  m_linkChange = callback;
263 }
264 
265 bool
267 {
268  return true;
269 }
270 
271 Address
273 {
275 }
276 
277 bool
279 {
280  return false;
281 }
282 
283 Address
285 {
286  return Mac48Address("01:00:5e:00:00:00");
287 }
288 
289 Address
291 {
292  return GetMulticast();
293 }
294 
295 bool
297 {
298  return false;
299 }
300 
301 bool
302 WimaxNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
303 {
305  LlcSnapHeader llcHdr;
306  llcHdr.SetType(protocolNumber);
307  packet->AddHeader(llcHdr);
308 
309  m_traceTx(packet, to);
310 
311  return DoSend(packet, Mac48Address::ConvertFrom(GetAddress()), to, protocolNumber);
312 }
313 
314 void
316 {
317  m_node = node;
318 }
319 
320 Ptr<Node>
322 {
323  return m_node;
324 }
325 
326 bool
328 {
329  return false;
330  /*
331  * Modified by Mohamed Amine ISMAIL.
332  * see "Transmission of IPv4 packets over IEEE 802.16's IP Convergence
333  * Sublayer draft-ietf-16ng-ipv4-over-802-dot-16-ipcs-04.txt" section
334  * 5.2
335  */
336 }
337 
338 void
340 {
341  m_forwardUp = cb;
342 }
343 
344 void
346 {
347  m_traceRx(packet, source);
348  LlcSnapHeader llc;
349  packet->RemoveHeader(llc);
350  m_forwardUp(this, packet, llc.GetType(), source);
351 }
352 
353 void
355 {
356  m_phy->Attach(channel);
357 }
358 
359 void
361 {
362  m_phy = phy;
363 }
364 
367 {
368  return m_phy;
369 }
370 
371 void
373 {
374  if (m_phy)
375  {
376  m_phy->Attach(channel);
377  }
378 }
379 
380 uint64_t
381 WimaxNetDevice::GetChannel(uint8_t index) const
382 {
383  return m_dlChannels.at(index);
384 }
385 
386 void
387 WimaxNetDevice::SetNrFrames(uint32_t nrFrames)
388 {
389  m_nrFrames = nrFrames;
390 }
391 
392 uint32_t
394 {
395  return m_nrFrames;
396 }
397 
398 void
400 {
402 }
403 
404 void
406 {
407  m_address = address;
408 }
409 
410 Address
412 {
413  return m_address;
414 }
415 
418 {
419  return m_address;
420 }
421 
422 void
424 {
425  m_state = state;
426 }
427 
428 uint8_t
430 {
431  return m_state;
432 }
433 
436 {
438 }
439 
442 {
443  return m_broadcastConnection;
444 }
445 
446 void
448 {
449  m_currentDcd = dcd;
450 }
451 
452 Dcd
454 {
455  return m_currentDcd;
456 }
457 
458 void
460 {
461  m_currentUcd = ucd;
462 }
463 
464 Ucd
466 {
467  return m_currentUcd;
468 }
469 
472 {
473  return m_connectionManager;
474 }
475 
476 void
478 {
479  m_connectionManager = cm;
480 }
481 
484 {
485  return m_burstProfileManager;
486 }
487 
488 void
490 {
491  m_burstProfileManager = bpm;
492 }
493 
496 {
497  return m_bandwidthManager;
498 }
499 
500 void
502 {
503  m_bandwidthManager = bwm;
504 }
505 
506 void
508 {
510  CreateObject<WimaxConnection>(Cid::InitialRanging(), Cid::INITIAL_RANGING);
511  m_broadcastConnection = CreateObject<WimaxConnection>(Cid::Broadcast(), Cid::BROADCAST);
512 }
513 
514 void
516 {
517  NS_LOG_DEBUG("WimaxNetDevice::Receive, station = " << GetMacAddress());
518 
519  Ptr<PacketBurst> b = burst->Copy();
520  for (auto iter = b->Begin(); iter != b->End(); ++iter)
521  {
522  Ptr<Packet> packet = *iter;
523  DoReceive(packet);
524  }
525 }
526 
529 {
530  return m_phy->GetChannel();
531 }
532 
533 void
535 {
536  m_phy->SetReceiveCallback(MakeCallback(&WimaxNetDevice::Receive, this));
537 }
538 
539 bool
541  const Address& source,
542  const Address& dest,
543  uint16_t protocolNumber)
544 {
547 
548  LlcSnapHeader llcHdr;
549  llcHdr.SetType(protocolNumber);
550  packet->AddHeader(llcHdr);
551 
552  m_traceTx(packet, to);
553  return DoSend(packet, from, to, protocolNumber);
554 }
555 
556 void
558 {
559  m_promiscRx = cb;
560 }
561 
562 bool
564 {
565  return !(m_promiscRx.IsNull());
566 }
567 
568 void
570 {
571  // m_promiscRx(p);
572 }
573 
574 bool
576 {
577  return false;
578 }
579 
580 void
582 {
583  SendParams* params = new OfdmSendParams(burst, modulationType, m_direction);
584  m_phy->Send(params);
585  delete params;
586 }
587 
588 void
590 {
591  // initializing vector of channels (or frequencies)
592  // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
593  // Section 12.3.3.1 from IEEE 802.16-2004 standard
594  // profR10_3 :
595  // channels: 5000 + n â‹… 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
596  // from a range 5GHz to 6GHz, according to Section 8.5.1.
597  uint64_t frequency = 5000;
598 
599  for (uint8_t i = 0; i < 200; i++)
600  {
601  m_dlChannels.push_back(frequency);
602  frequency += 5;
603  }
604 }
605 
606 bool
608 {
610  return false;
611 }
612 
613 Address
615 {
616  NS_LOG_FUNCTION(multicastGroup);
617 
618  Mac48Address ad = Mac48Address::GetMulticast(multicastGroup);
619 
620  //
621  // Implicit conversion (operator Address ()) is defined for Mac48Address, so
622  // use it by just returning the EUI-48 address which is automagically converted
623  // to an Address.
624  //
625  NS_LOG_LOGIC("multicast address is " << ad);
626 
627  return ad;
628 }
629 
630 Address
632 {
634 
635  NS_LOG_LOGIC("MAC IPv6 multicast address is " << ad);
636  return ad;
637 }
638 
639 void
641 {
642  /* \todo Add a callback invoked whenever the link
643  * status changes to UP. This callback is typically used
644  * by the IP/ARP layer to flush the ARP cache and by IPv6 stack
645  * to flush NDISC cache whenever the link goes up.
646  */
647  NS_FATAL_ERROR("Not implemented-- please implement and contribute a patch");
648 }
649 } // namespace ns3
a polymophic address class
Definition: address.h:101
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
@ BROADCAST
Definition: cid.h:42
@ INITIAL_RANGING
Definition: cid.h:43
static Cid InitialRanging()
Definition: cid.cc:87
static Cid Broadcast()
Definition: cid.cc:75
This class implements Downlink channel descriptor as described by "IEEE Standard for Local and metrop...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Header for the LLC/SNAP encapsulation.
uint16_t GetType()
Return the Ethertype.
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetMulticast(Ipv4Address address)
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
Network layer to device interface.
Definition: net-device.h:98
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
OfdmSendParams class.
Definition: send-params.h:68
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
Hold objects of type Ptr<T>.
Definition: pointer.h:37
The SendParams class defines the parameters with which Send() function of a particular PHY is called.
Definition: send-params.h:42
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
This class implements the UCD message as described by "IEEE Standard for Local and metropolitan area ...
Hold an unsigned integer type.
Definition: uinteger.h:45
NetDevice::ReceiveCallback m_forwardUp
forward up callback function
Ptr< Channel > GetChannel() const override
Get the channel.
virtual std::string GetName() const
Get device name.
void DoDispose() override
Destructor implementation.
uint16_t GetRtg() const
Get receive/transmit transition gap.
void SetRtg(uint16_t rtg)
Set receive/transmit transition gap.
virtual void SetConnectionManager(Ptr< ConnectionManager > connectionManager)
Set the connection manager of the device.
Ptr< BandwidthManager > m_bandwidthManager
badnwidth manager
bool NeedsArp() const override
Check if device needs ARP.
Ptr< BurstProfileManager > m_burstProfileManager
burst profile manager
static uint8_t m_direction
downlink or uplink
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceTx
void Receive(Ptr< const PacketBurst > burst)
Receive a packet burst.
void SetAddress(Address address) override
Set address of the device.
std::vector< uint64_t > m_dlChannels
not sure if it shall be included here
NetDevice::PromiscReceiveCallback m_promiscRx
promiscuous receive callback function
Mac48Address m_address
MAC address.
static TypeId GetTypeId()
Get the type ID.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
Send a packet.
Ptr< ConnectionManager > GetConnectionManager() const
Get the connection manager of the device.
Ptr< WimaxConnection > m_initialRangingConnection
initial rnaging connection
uint32_t GetIfIndex() const override
Get interface index.
bool IsMulticast() const override
Check if multicast enabled.
Ucd GetCurrentUcd() const
Get the current UCD.
virtual Address MakeMulticastAddress(Ipv4Address multicastGroup) const
Make multicast address.
void SetPhy(Ptr< WimaxPhy > phy)
Set the physical layer object.
Address GetAddress() const override
Get address of the device.
Address GetBroadcast() const override
Get broadcast address.
virtual bool DoSend(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest, uint16_t protocolNumber)=0
Send a packet.
virtual Ptr< Channel > GetPhyChannel() const
Get the channel (this method is redundant with GetChannel())
void AddLinkChangeCallback(Callback< void > callback) override
Add link change callback function.
virtual void SetName(const std::string name)
Set device name.
uint8_t GetState() const
Get the device state.
uint16_t GetMtu() const override
Get MTU of the device.
static const uint16_t DEFAULT_MSDU_SIZE
recommended by wimax forum.
static const uint16_t MAX_MSDU_SIZE
Maximum MSDU size.
void SetCurrentUcd(Ucd ucd)
Set the current UCD.
uint32_t GetNrFrames() const
Get the number of frames.
void SetMacAddress(Mac48Address address)
Set the MAC address.
Ptr< Node > GetNode() const override
Get node pointer.
Ptr< WimaxConnection > m_broadcastConnection
broadcast connection
static Time m_frameStartTime
temp, to determine the frame start time at SS side, shall actually be determined by frame start pream...
void SetBurstProfileManager(Ptr< BurstProfileManager > burstProfileManager)
Set the burst profile manager.
void SetState(uint8_t state)
Set the device state.
Ptr< WimaxPhy > m_phy
the phy
void SetChannel(Ptr< WimaxChannel > wimaxChannel)
Set the channel object.
bool SetMtu(const uint16_t mtu) override
Set MTU value for the device.
Ptr< WimaxConnection > GetInitialRangingConnection() const
Get the initial ranging connection.
virtual void SetLinkChangeCallback(Callback< void > callback)
Set link change callback function.
Ptr< ConnectionManager > m_connectionManager
connection manager
void SetBandwidthManager(Ptr< BandwidthManager > bandwidthManager)
Set the bandwidth manager on the device.
Ptr< WimaxPhy > GetPhy() const
Get the physical layer object.
uint32_t m_ifIndex
IF index.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
Set promiscuous receive callback function.
bool IsPointToPoint() const override
Check if device is a point-to-point device.
void InitializeChannels()
Initialize channels function.
Ptr< BandwidthManager > GetBandwidthManager() const
Get the bandwidth manager on the device.
Ptr< WimaxConnection > GetBroadcastConnection() const
Get the broadcast connection.
Callback< void > m_linkChange
link change callback
virtual Address GetMulticast() const
Get multicast address.
std::string m_name
service name
virtual void DoReceive(Ptr< Packet > packet)=0
Receive a packet.
bool IsPromisc()
Check if device is promiscuous.
static uint32_t m_nrFrames
temp, shall be in BS.
void Attach(Ptr< WimaxChannel > channel)
Attach device to channel.
void SetTtg(uint16_t ttg)
Set transmission/receive transition gap.
void CreateDefaultConnections()
Creates the initial ranging and broadcast connections.
void SetNrFrames(uint32_t nrFrames)
Set the number of frames.
uint16_t m_ttg
length of TTG in units of PSs
void SetCurrentDcd(Dcd dcd)
Set the current DCD.
void SetReceiveCallback()
Set receive callback function.
bool SupportsSendFrom() const override
Check if device supports the SendFrom method.
bool IsLinkUp() const override
Check if link is up.
void SetIfIndex(const uint32_t index) override
Set interface index.
uint16_t GetTtg() const
Get transmission/receive transition gap.
Mac48Address GetMacAddress() const
Get the MAC address.
void SetNode(Ptr< Node > node) override
Set node pointer.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Send function.
Ptr< Node > m_node
the node
void NotifyPromiscTrace(Ptr< Packet > p)
Notify promiscuous trace of a packet arrival.
void ForwardUp(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest)
Forward a packet to the next layer above the device.
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceRx
virtual Ptr< WimaxChannel > DoGetChannel() const
Get the channel.
Ptr< BurstProfileManager > GetBurstProfileManager() const
Get the burst profile manager.
Dcd GetCurrentDcd() const
Get the current DCD.
void ForwardDown(Ptr< PacketBurst > burst, WimaxPhy::ModulationType modulationType)
Forward a packet down the stack.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
uint16_t m_rtg
length of RTG in units of PSs
bool IsBroadcast() const override
Check if broadcast enabled.
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#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_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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:1326
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:47
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
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:704
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
channel
Definition: third.py:88
phy
Definition: third.py:89
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.