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
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
tuple channel
Definition: third.py:85
void SetRtg(uint16_t rtg)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint16_t GetRtg(void) const
NetDevice::PromiscReceiveCallback m_promiscRx
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
virtual bool DoSend(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest, uint16_t protocolNumber)=0
virtual ~WimaxNetDevice(void)
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
Ptr< WimaxConnection > m_broadcastConnection
void ForwardUp(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest)
Ptr< BurstProfileManager > m_burstProfileManager
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Callback< void > m_linkChange
Dcd GetCurrentDcd(void) const
Ptr< WimaxConnection > GetBroadcastConnection(void) const
void Receive(Ptr< const PacketBurst > burst)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:719
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void SetType(uint16_t type)
Set the Ethertype.
Ptr< ConnectionManager > GetConnectionManager(void) const
a polymophic address class
Definition: address.h:90
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
static const uint16_t DEFAULT_MSDU_SIZE
virtual bool IsMulticast(void) const
uint32_t GetNrFrames(void) const
virtual Ptr< Channel > GetChannel(void) const
virtual bool SetMtu(const uint16_t mtu)
static TypeId GetTypeId(void)
tuple phy
Definition: third.py:86
virtual Address GetMulticast(void) const
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:220
uint16_t GetTtg(void) const
void SetCurrentDcd(Dcd dcd)
static Mac48Address GetMulticast(Ipv4Address address)
The SendParams class defines the parameters with which Send() function of a particular PHY is called...
Definition: send-params.h:43
void SetTtg(uint16_t ttg)
uint16_t GetType(void)
Return the Ethertype.
static Cid Broadcast(void)
Definition: cid.cc:72
Ptr< ConnectionManager > m_connectionManager
static Cid InitialRanging(void)
Definition: cid.cc:82
Hold an unsigned integer type.
Definition: uinteger.h:44
Ptr< WimaxConnection > m_initialRangingConnection
virtual void SetIfIndex(const uint32_t index)
Introspection did not find any typical Config paths.
std::vector< uint64_t > m_dlChannels
virtual Ptr< WimaxChannel > DoGetChannel(void) const
virtual Address GetBroadcast(void) const
static Mac48Address GetBroadcast(void)
Ptr< WimaxConnection > GetInitialRangingConnection(void) const
Ptr< BandwidthManager > GetBandwidthManager(void) const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
static uint32_t m_nrFrames
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual void SetConnectionManager(Ptr< ConnectionManager > connectionManager)
Introspection did not find any typical Config paths.
Mac48Address GetMacAddress(void) const
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
virtual void DoDispose(void)
Destructor implementation.
#define list
static Mac48Address ConvertFrom(const Address &address)
virtual uint32_t GetIfIndex(void) const
virtual Ptr< Node > GetNode(void) const
void SetBandwidthManager(Ptr< BandwidthManager > bandwidthManager)
virtual Address GetAddress(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr.
Definition: pointer.h:36
virtual void SetLinkChangeCallback(Callback< void > callback)
virtual bool IsBroadcast(void) const
void SetBurstProfileManager(Ptr< BurstProfileManager > burstProfileManager)
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceTx
Ucd GetCurrentUcd(void) const
an EUI-48 address
Definition: mac48-address.h:43
void SetMacAddress(Mac48Address address)
virtual void DoReceive(Ptr< Packet > packet)=0
void SetChannel(Ptr< WimaxChannel > wimaxChannel)
void SetPhy(Ptr< WimaxPhy > phy)
virtual bool IsLinkUp(void) const
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
void NotifyPromiscTrace(Ptr< Packet > p)
virtual bool SupportsSendFrom(void) const
Ptr< BurstProfileManager > GetBurstProfileManager(void) const
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual void AddLinkChangeCallback(Callback< void > callback)
void SetNrFrames(uint32_t nrFrames)
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Network layer to device interface.
Definition: net-device.h:405
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
void SetCurrentUcd(Ucd ucd)
virtual uint16_t GetMtu(void) const
void ForwardDown(Ptr< PacketBurst > burst, WimaxPhy::ModulationType modulationType)
Ptr< WimaxPhy > GetPhy(void) const
virtual Ptr< Channel > GetPhyChannel(void) const
#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
void CreateDefaultConnections(void)
Creates the initial ranging and broadcast connections.
NetDevice::ReceiveCallback m_forwardUp
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceRx
virtual Address MakeMulticastAddress(Ipv4Address multicastGroup) const
void Attach(Ptr< WimaxChannel > channel)
void SetState(uint8_t state)
virtual std::string GetName(void) const
static const uint16_t MAX_MSDU_SIZE
virtual void SetName(const std::string name)
tuple address
Definition: first.py:37
virtual void SetAddress(Address address)
Set the address of this interface.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< WimaxPhy > m_phy
virtual void SetNode(Ptr< Node > node)
virtual bool NeedsArp(void) const
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
Ptr< BandwidthManager > m_bandwidthManager
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
static Time m_frameStartTime
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
uint8_t GetState(void) const
Header for the LLC/SNAP encapsulation.
static uint8_t m_direction