A Discrete-Event Network Simulator
API
wimax-net-device.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008,2009 INRIA, UDcast
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  * <amine.ismail@UDcast.com>
21  */
22 
23 #include "ns3/llc-snap-header.h"
24 #include "ns3/simulator.h"
25 #include "ns3/callback.h"
26 #include "ns3/node.h"
27 #include "ns3/packet.h"
28 #include "wimax-net-device.h"
29 #include "wimax-channel.h"
30 #include "ns3/packet-burst.h"
31 #include "burst-profile-manager.h"
32 #include <list>
33 #include "send-params.h"
34 #include "ns3/uinteger.h"
35 #include "ns3/trace-source-accessor.h"
36 #include "ns3/pointer.h"
37 #include "ns3/enum.h"
38 #include "service-flow-manager.h"
39 #include "connection-manager.h"
40 #include "bandwidth-manager.h"
41 
42 namespace ns3 {
43 
44 NS_LOG_COMPONENT_DEFINE ("WimaxNetDevice");
45 
46 NS_OBJECT_ENSURE_REGISTERED (WimaxNetDevice);
47 
48 uint32_t WimaxNetDevice::m_nrFrames = 0;
49 uint8_t WimaxNetDevice::m_direction = ~0;
51 
53 {
54  static TypeId
55  tid =
56  TypeId ("ns3::WimaxNetDevice")
57 
58  .SetParent<NetDevice> ()
59  .SetGroupName ("Wimax")
60 
61  // No AddConstructor because this is an abstract class.
62 
63  .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
67  MakeUintegerChecker<uint16_t> (0,MAX_MSDU_SIZE))
68 
69  .AddAttribute ("Phy",
70  "The PHY layer attached to this device.",
71  PointerValue (),
73  MakePointerChecker<WimaxPhy> ())
74 
75  .AddAttribute ("Channel",
76  "The channel attached to this device.",
77  PointerValue (),
79  MakePointerChecker<WimaxChannel> ())
80 
81  .AddAttribute ("RTG",
82  "receive/transmit transition gap.",
83  UintegerValue (0),
85  MakeUintegerChecker<uint16_t> (0, 120))
86 
87  .AddAttribute ("TTG",
88  "transmit/receive transition gap.",
89  UintegerValue (0),
91  MakeUintegerChecker<uint16_t> (0, 120))
92 
93  .AddAttribute ("ConnectionManager",
94  "The connection manager attached to this device.",
95  PointerValue (),
98  MakePointerChecker<ConnectionManager> ())
99 
100  .AddAttribute ("BurstProfileManager",
101  "The burst profile manager attached to this device.",
102  PointerValue (),
105  MakePointerChecker<BurstProfileManager> ())
106 
107  .AddAttribute ("BandwidthManager",
108  "The bandwidth manager attached to this device.",
109  PointerValue (),
112  MakePointerChecker<BandwidthManager> ())
113 
114  .AddAttribute ("InitialRangingConnection",
115  "Initial ranging connection",
116  PointerValue (),
118  MakePointerChecker<WimaxConnection> ())
119 
120  .AddAttribute ("BroadcastConnection",
121  "Broadcast connection",
122  PointerValue (),
124  MakePointerChecker<WimaxConnection> ())
125 
126  .AddTraceSource ("Rx",
127  "Receive trace",
129  "ns3::WimaxNetDevice::TxRxTracedCallback")
130 
131  .AddTraceSource ("Tx",
132  "Transmit trace",
134  "ns3::WimaxNetDevice::TxRxTracedCallback");
135  return tid;
136 }
137 
139  : m_state (0),
140  m_symbolIndex (0),
141  m_ttg (0),
142  m_rtg (0)
143 {
145  m_connectionManager = CreateObject<ConnectionManager> ();
146  m_burstProfileManager = CreateObject<BurstProfileManager> (this);
147  m_bandwidthManager = CreateObject<BandwidthManager> (this);
148  m_nrFrames = 0;
149  m_direction = ~0;
151 }
152 
154 {
155 }
156 
157 void
159 {
160 
161  m_phy->Dispose ();
162  m_phy = 0;
163  m_node = 0;
168  m_bandwidthManager = 0;
170  m_bandwidthManager = 0;
171 
173 }
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 
257  return m_phy != 0 && m_linkUp;
258 
259 }
260 
261 void
263 {
264  m_linkChange = callback;
265 }
266 
267 bool
269 {
270  return true;
271 }
272 
273 Address
275 {
276  return Mac48Address::GetBroadcast ();
277 }
278 
279 bool
281 {
282  return false;
283 }
284 
285 Address
287 {
288  return Mac48Address ("01:00:5e:00:00:00");
289 }
290 
291 Address
293 {
294  return GetMulticast ();
295 }
296 
297 bool
299 {
300  return false;
301 }
302 
303 bool
304 WimaxNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
305 {
306 
308  LlcSnapHeader llcHdr;
309  llcHdr.SetType (protocolNumber);
310  packet->AddHeader (llcHdr);
311 
312  m_traceTx (packet, to);
313 
314  return DoSend (packet, Mac48Address::ConvertFrom (GetAddress ()), to, protocolNumber);
315 }
316 
317 void
319 {
320  m_node = node;
321 }
322 
323 Ptr<Node>
325 {
326  return m_node;
327 }
328 
329 bool
331 {
332  return false;
333  /*
334  * Modified by Mohamed Amine ISMAIL.
335  * see "Transmission of IPv4 packets over IEEE 802.16's IP Convergence
336  * Sublayer draft-ietf-16ng-ipv4-over-802-dot-16-ipcs-04.txt" section
337  * 5.2
338  */
339 }
340 
341 void
343 {
344  m_forwardUp = cb;
345 }
346 
347 void
349 {
350  m_traceRx (packet, source);
351  LlcSnapHeader llc;
352  packet->RemoveHeader (llc);
353  m_forwardUp (this, packet, llc.GetType (), source);
354 }
355 
356 void
358 {
359  m_phy->Attach (channel);
360 }
361 
362 void
364 {
365  m_phy = phy;
366 }
367 
370 {
371  return m_phy;
372 }
373 
374 void
376 {
377  if (m_phy != 0)
378  {
379  m_phy->Attach (channel);
380  }
381 
382 }
383 
384 uint64_t
385 WimaxNetDevice::GetChannel (uint8_t index) const
386 {
387  return m_dlChannels.at (index);
388 }
389 
390 void
391 WimaxNetDevice::SetNrFrames (uint32_t nrFrames)
392 {
393  m_nrFrames = nrFrames;
394 }
395 
396 uint32_t WimaxNetDevice::GetNrFrames (void) const
397 {
398 
399  return m_nrFrames;
400 }
401 
402 void
404 {
406 }
407 
408 void
410 {
411  m_address = address;
412 }
413 
414 Address
416 {
417  return m_address;
418 }
419 
422 {
423  return m_address;
424 }
425 
426 void
428 {
429  m_state = state;
430 }
431 
432 uint8_t
434 {
435  return m_state;
436 }
437 
440 {
442 }
443 
446 {
447  return m_broadcastConnection;
448 }
449 
450 void
452 {
453  m_currentDcd = dcd;
454 }
455 
456 Dcd
458 {
459  return m_currentDcd;
460 }
461 
462 void
464 {
465  m_currentUcd = ucd;
466 }
467 
468 Ucd
470 {
471  return m_currentUcd;
472 }
473 
476 {
477  return m_connectionManager;
478 }
479 
480 void
482 {
483  m_connectionManager = cm;
484 }
485 
488 {
489  return m_burstProfileManager;
490 }
491 
492 void
494 {
495  m_burstProfileManager = bpm;
496 }
497 
500 {
501  return m_bandwidthManager;
502 }
503 
504 void
506 {
507  m_bandwidthManager = bwm;
508 }
509 
510 void
512 {
513  m_initialRangingConnection = CreateObject<WimaxConnection> (Cid::InitialRanging (), Cid::INITIAL_RANGING);
514  m_broadcastConnection = CreateObject<WimaxConnection> (Cid::Broadcast (), Cid::BROADCAST);
515 }
516 
517 void
519 {
520 
521  NS_LOG_DEBUG ("WimaxNetDevice::Receive, station = " << GetMacAddress ());
522 
523  Ptr<PacketBurst> b = burst->Copy ();
524  for (std::list<Ptr<Packet> >::const_iterator iter = b->Begin (); iter != b->End (); ++iter)
525  {
526  Ptr<Packet> packet = *iter;
527  DoReceive (packet);
528  }
529 }
530 
533 {
534  return m_phy->GetChannel ();
535 }
536 
537 void
539 {
540  m_phy->SetReceiveCallback (MakeCallback (&WimaxNetDevice::Receive, this));
541 }
542 
543 bool
544 WimaxNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
545 {
546 
547  Mac48Address from = Mac48Address::ConvertFrom (source);
549 
550  LlcSnapHeader llcHdr;
551  llcHdr.SetType (protocolNumber);
552  packet->AddHeader (llcHdr);
553 
554  m_traceTx (packet, to);
555  return DoSend (packet, from, to, protocolNumber);
556 }
557 
558 void
560 {
561  m_promiscRx = cb;
562 }
563 
564 bool
566 {
567  return !(m_promiscRx.IsNull ());
568 }
569 
570 void
572 {
573  // m_promiscRx(p);
574 }
575 
576 bool
578 {
579  return false;
580 }
581 
582 void
584 {
585  SendParams * params = new OfdmSendParams (burst, modulationType, m_direction);
586  m_phy->Send (params);
587  delete params;
588 }
589 
590 void
592 {
593 
594  // initializing vector of channels (or frequencies)
595  // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
596  // Section 12.3.3.1 from IEEE 802.16-2004 standard
597  // profR10_3 :
598  // channels: 5000 + n â‹… 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
599  // from a range 5GHz to 6GHz, according to Section 8.5.1.
600  uint64_t frequency = 5000;
601 
602  for (uint8_t i = 0; i < 200; i++)
603  {
604  m_dlChannels.push_back (frequency);
605  frequency += 5;
606  }
607 }
608 
609 bool
611 {
613  return false;
614 }
615 
616 Address
618 {
619  NS_LOG_FUNCTION (multicastGroup);
620 
621  Mac48Address ad = Mac48Address::GetMulticast (multicastGroup);
622 
623  //
624  // Implicit conversion (operator Address ()) is defined for Mac48Address, so
625  // use it by just returning the EUI-48 address which is automagically converted
626  // to an Address.
627  //
628  NS_LOG_LOGIC ("multicast address is " << ad);
629 
630  return ad;
631 }
632 
633 Address
635 {
637 
638  NS_LOG_LOGIC ("MAC IPv6 multicast address is " << ad);
639  return ad;
640 }
641 
642 void
644 {
645  /* \todo Add a callback invoked whenever the link
646  * status changes to UP. This callback is typically used
647  * by the IP/ARP layer to flush the ARP cache and by IPv6 stack
648  * to flush NDISC cache whenever the link goes up.
649  */
650  NS_FATAL_ERROR ("Not implemented-- please implement and contribute a patch");
651 }
652 } // namespace ns3
a polymophic address class
Definition: address.h:91
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
@ BROADCAST
Definition: cid.h:43
@ INITIAL_RANGING
Definition: cid.h:44
static Cid InitialRanging(void)
Definition: cid.cc:82
static Cid Broadcast(void)
Definition: cid.cc:72
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:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
Header for the LLC/SNAP encapsulation.
uint16_t GetType(void)
Return the Ethertype.
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetMulticast(Ipv4Address address)
static Mac48Address GetBroadcast(void)
static Mac48Address ConvertFrom(const Address &address)
Network layer to device interface.
Definition: net-device.h:96
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
OfdmSendParams class.
Definition: send-params.h:68
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
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:44
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
This class implements the UCD message as described by "IEEE Standard for Local and metropolitan area ...
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual bool IsLinkUp(void) const
Check if link is up.
Mac48Address GetMacAddress(void) const
Get the MAC address.
NetDevice::ReceiveCallback m_forwardUp
forward up callback function
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
Ptr< BurstProfileManager > m_burstProfileManager
burst profile manager
static uint8_t m_direction
downlink or uplink
void Receive(Ptr< const PacketBurst > burst)
Receive a packet burst.
std::vector< uint64_t > m_dlChannels
not sure if it shall be included here
Dcd GetCurrentDcd(void) const
Get the current DCD.
NetDevice::PromiscReceiveCallback m_promiscRx
promiscious receive fcallback function
Mac48Address m_address
MAC address.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< WimaxConnection > m_initialRangingConnection
initial rnaging connection
uint32_t GetNrFrames(void) const
Get the number of frames.
virtual Address MakeMulticastAddress(Ipv4Address multicastGroup) const
Make multicast address.
void CreateDefaultConnections(void)
Creates the initial ranging and broadcast connections.
void SetPhy(Ptr< WimaxPhy > phy)
Set the physical layer object.
virtual bool DoSend(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest, uint16_t protocolNumber)=0
Send a packet.
Ptr< WimaxConnection > GetBroadcastConnection(void) const
Get the broadcast connection.
virtual void SetName(const std::string name)
Set device name.
virtual Ptr< WimaxChannel > DoGetChannel(void) const
Get the channel.
Ptr< BandwidthManager > GetBandwidthManager(void) const
Get the bandwidth manager on the device.
static const uint16_t DEFAULT_MSDU_SIZE
recommended by wimax forum.
uint16_t GetTtg(void) const
Get transmission/receive transition gap.
virtual void SetIfIndex(const uint32_t index)
Set interface index.
static const uint16_t MAX_MSDU_SIZE
Maximum MSDU size.
virtual bool IsBroadcast(void) const
Check if broadcast enabled.
void SetCurrentUcd(Ucd ucd)
Set the current UCD.
void SetMacAddress(Mac48Address address)
Set the MAC address.
Ptr< ConnectionManager > GetConnectionManager(void) const
Get the connection manager of the device.
Ptr< WimaxConnection > m_broadcastConnection
broadcast connection
void SetReceiveCallback(void)
Set receive callback function.
virtual void DoDispose(void)
Destructor implementation.
static Time m_frameStartTime
temp, to determine the frame start time at SS side, shall actually be determined by frame start pream...
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Send function.
void SetBurstProfileManager(Ptr< BurstProfileManager > burstProfileManager)
Set the burst profile manager.
Ucd GetCurrentUcd(void) const
Get the current UCD.
Ptr< WimaxPhy > GetPhy(void) const
Get the physical layer object.
virtual bool SetMtu(const uint16_t mtu)
Set MTU value for the device.
void SetState(uint8_t state)
Set the device state.
bool IsPromisc(void)
Check if device is promiscious.
Ptr< WimaxPhy > m_phy
the phy
void SetChannel(Ptr< WimaxChannel > wimaxChannel)
Set the channel object.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
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.
uint32_t m_ifIndex
IF index.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Set promiscious receive callback function.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Send a packet.
uint8_t GetState(void) const
Get the device state.
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceRx
Ptr< WimaxConnection > GetInitialRangingConnection(void) const
Get the initial ranging connection.
virtual void SetAddress(Address address)
Set address of the device.
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceTx
virtual Address GetAddress(void) const
Get address of the device.
Callback< void > m_linkChange
link change callback
virtual Address GetBroadcast(void) const
Get broadcast address.
virtual uint32_t GetIfIndex(void) const
Get interface index.
virtual void AddLinkChangeCallback(Callback< void > callback)
Add link change callback function.
virtual Ptr< Node > GetNode(void) const
Get node pointer.
std::string m_name
service name
virtual bool SupportsSendFrom(void) const
Check if device supports the SendFrom method.
virtual void DoReceive(Ptr< Packet > packet)=0
Receive a packet.
virtual ~WimaxNetDevice(void)
virtual std::string GetName(void) const
Get device name.
static uint32_t m_nrFrames
temp, shall be in BS. defined here to allow SS to access. SS shall actually determine it from DLFP,...
virtual bool NeedsArp(void) const
Check if device needs ARP.
void Attach(Ptr< WimaxChannel > channel)
Attach device to channel.
void SetTtg(uint16_t ttg)
Set transmission/receive transition gap.
virtual Address GetMulticast(void) const
Get multicast address.
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.
Ptr< BurstProfileManager > GetBurstProfileManager(void) const
Get the burst profile manager.
uint16_t GetRtg(void) const
Get receive/transmit transition gap.
virtual bool IsMulticast(void) const
Check if multicast enabled.
virtual uint16_t GetMtu(void) const
Get MTU of the device.
virtual bool IsPointToPoint(void) const
Check if device is a point-to-point device.
virtual void SetNode(Ptr< Node > node)
Set node pointer.
void InitializeChannels(void)
Initialize channels function.
virtual Ptr< Channel > GetChannel(void) const
Get the channel.
Ptr< Node > m_node
the node
void NotifyPromiscTrace(Ptr< Packet > p)
Notify promiscious trace of a packet arrival.
virtual Ptr< Channel > GetPhyChannel(void) const
Get the channel (this method is redundant with GetChannel())
void ForwardUp(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest)
Forward a packet to the next layer above the device.
void ForwardDown(Ptr< PacketBurst > burst, WimaxPhy::ModulationType modulationType)
Forward a packet down the stack.
uint16_t m_rtg
length of RTG in units of PSs
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:52
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:44
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:793
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
channel
Definition: third.py:92
phy
Definition: third.py:93
#define list