A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("WimaxNetDevice");
43 
44 namespace ns3 {
45 
46 NS_OBJECT_ENSURE_REGISTERED (WimaxNetDevice)
47  ;
48 
49 uint32_t WimaxNetDevice::m_nrFrames = 0;
50 uint8_t WimaxNetDevice::m_direction = ~0;
51 Time WimaxNetDevice::m_frameStartTime = Seconds (0);
52 
54 {
55  static TypeId
56  tid =
57  TypeId ("ns3::WimaxNetDevice")
58 
59  .SetParent<NetDevice> ()
60 
61  .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
63  MakeUintegerAccessor (&WimaxNetDevice::SetMtu,
65  MakeUintegerChecker<uint16_t> (0,MAX_MSDU_SIZE))
66 
67  .AddAttribute ("Phy",
68  "The PHY layer attached to this device.",
69  PointerValue (),
70  MakePointerAccessor (&WimaxNetDevice::GetPhy, &WimaxNetDevice::SetPhy),
71  MakePointerChecker<WimaxPhy> ())
72 
73  .AddAttribute ("Channel",
74  "The channel attached to this device.",
75  PointerValue (),
77  MakePointerChecker<WimaxChannel> ())
78 
79  .AddAttribute ("RTG",
80  "receive/transmit transition gap.",
81  UintegerValue (0),
82  MakeUintegerAccessor (&WimaxNetDevice::GetRtg, &WimaxNetDevice::SetRtg),
83  MakeUintegerChecker<uint16_t> (0, 120))
84 
85  .AddAttribute ("TTG",
86  "transmit/receive transition gap.",
87  UintegerValue (0),
88  MakeUintegerAccessor (&WimaxNetDevice::GetTtg, &WimaxNetDevice::SetTtg),
89  MakeUintegerChecker<uint16_t> (0, 120))
90 
91  .AddAttribute ("ConnectionManager",
92  "The connection manager attached to this device.",
93  PointerValue (),
94  MakePointerAccessor (&WimaxNetDevice::GetConnectionManager,
96  MakePointerChecker<ConnectionManager> ())
97 
98  .AddAttribute ("BurstProfileManager",
99  "The burst profile manager attached to this device.",
100  PointerValue (),
101  MakePointerAccessor (&WimaxNetDevice::GetBurstProfileManager,
103  MakePointerChecker<BurstProfileManager> ())
104 
105  .AddAttribute ("BandwidthManager",
106  "The bandwidth manager attached to this device.",
107  PointerValue (),
108  MakePointerAccessor (&WimaxNetDevice::GetBandwidthManager,
110  MakePointerChecker<BandwidthManager> ())
111 
112  .AddAttribute ("InitialRangingConnection",
113  "Initial ranging connection",
114  PointerValue (),
115  MakePointerAccessor (&WimaxNetDevice::m_initialRangingConnection),
116  MakePointerChecker<WimaxConnection> ())
117 
118  .AddAttribute ("BroadcastConnection",
119  "Broadcast connection",
120  PointerValue (),
121  MakePointerAccessor (&WimaxNetDevice::m_broadcastConnection),
122  MakePointerChecker<WimaxConnection> ())
123 
124  .AddTraceSource ("Rx", "Receive trace", MakeTraceSourceAccessor (&WimaxNetDevice::m_traceRx))
125 
126  .AddTraceSource ("Tx", "Transmit trace", MakeTraceSourceAccessor (&WimaxNetDevice::m_traceTx));
127  return tid;
128 }
129 
131  : m_state (0),
132  m_symbolIndex (0),
133  m_ttg (0),
134  m_rtg (0)
135 {
137  m_connectionManager = CreateObject<ConnectionManager> ();
138  m_burstProfileManager = CreateObject<BurstProfileManager> (this);
139  m_bandwidthManager = CreateObject<BandwidthManager> (this);
140  m_nrFrames = 0;
141  m_direction = ~0;
142  m_frameStartTime = Seconds (0);
143 }
144 
146 {
147 }
148 
149 void
151 {
152 
153  m_phy->Dispose ();
154  m_phy = 0;
155  m_node = 0;
160  m_bandwidthManager = 0;
162  m_bandwidthManager = 0;
163 
165 }
166 
167 
168 void
170 {
171  m_ttg = ttg;
172 }
173 
174 uint16_t
176 {
177  return m_ttg;
178 }
179 
180 void
182 {
183  m_rtg = rtg;
184 }
185 
186 uint16_t
188 {
189  return m_rtg;
190 }
191 
192 void
193 WimaxNetDevice::SetName (const std::string name)
194 {
195  m_name = name;
196 }
197 
198 std::string
200 {
201  return m_name;
202 }
203 
204 void
205 WimaxNetDevice::SetIfIndex (const uint32_t index)
206 {
207  m_ifIndex = index;
208 }
209 
210 uint32_t
212 {
213  return m_ifIndex;
214 }
215 
218 {
219  return DoGetChannel ();
220 }
221 
224 {
225  return DoGetChannel ();
226 }
227 
228 bool
229 WimaxNetDevice::SetMtu (const uint16_t mtu)
230 {
231  if (mtu > MAX_MSDU_SIZE)
232  {
233  return false;
234  }
235  m_mtu = mtu;
236  return true;
237 }
238 
239 uint16_t
241 {
242  return m_mtu;
243 }
244 
245 bool
247 {
248 
249  return m_phy != 0 && m_linkUp;
250 
251 }
252 
253 void
255 {
256  m_linkChange = callback;
257 }
258 
259 bool
261 {
262  return true;
263 }
264 
265 Address
267 {
268  return Mac48Address::GetBroadcast ();
269 }
270 
271 bool
273 {
274  return false;
275 }
276 
277 Address
279 {
280  return Mac48Address ("01:00:5e:00:00:00");
281 }
282 
283 Address
285 {
286  return GetMulticast ();
287 }
288 
289 bool
291 {
292  return false;
293 }
294 
295 bool
296 WimaxNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
297 {
298 
300  LlcSnapHeader llcHdr;
301  llcHdr.SetType (protocolNumber);
302  packet->AddHeader (llcHdr);
303 
304  m_traceTx (packet, to);
305 
306  return DoSend (packet, Mac48Address::ConvertFrom (GetAddress ()), to, protocolNumber);
307 }
308 
309 void
311 {
312  m_node = node;
313 }
314 
315 Ptr<Node>
317 {
318  return m_node;
319 }
320 
321 bool
323 {
324  return false;
325  /*
326  * Modified by Mohamed Amine ISMAIL.
327  * see "Transmission of IPv4 packets over IEEE 802.16's IP Convergence
328  * Sublayer draft-ietf-16ng-ipv4-over-802-dot-16-ipcs-04.txt" section
329  * 5.2
330  */
331 }
332 
333 void
335 {
336  m_forwardUp = cb;
337 }
338 
339 void
341 {
342  m_traceRx (packet, source);
343  LlcSnapHeader llc;
344  packet->RemoveHeader (llc);
345  m_forwardUp (this, packet, llc.GetType (), source);
346 }
347 
348 void
350 {
351  m_phy->Attach (channel);
352 }
353 
354 void
356 {
357  m_phy = phy;
358 }
359 
362 {
363  return m_phy;
364 }
365 
366 void
368 {
369  if (m_phy != 0)
370  {
371  m_phy->Attach (channel);
372  }
373 
374 }
375 
376 uint64_t
377 WimaxNetDevice::GetChannel (uint8_t index) const
378 {
379  return m_dlChannels.at (index);
380 }
381 
382 void
383 WimaxNetDevice::SetNrFrames (uint32_t nrFrames)
384 {
385  m_nrFrames = nrFrames;
386 }
387 
388 uint32_t WimaxNetDevice::GetNrFrames (void) const
389 {
390 
391  return m_nrFrames;
392 }
393 
394 void
396 {
398 }
399 
400 void
402 {
403  m_address = address;
404 }
405 
406 Address
408 {
409  return m_address;
410 }
411 
414 {
415  return m_address;
416 }
417 
418 void
420 {
421  m_state = state;
422 }
423 
424 uint8_t
426 {
427  return m_state;
428 }
429 
432 {
434 }
435 
438 {
439  return m_broadcastConnection;
440 }
441 
442 void
444 {
445  m_currentDcd = dcd;
446 }
447 
448 Dcd
450 {
451  return m_currentDcd;
452 }
453 
454 void
456 {
457  m_currentUcd = ucd;
458 }
459 
460 Ucd
462 {
463  return m_currentUcd;
464 }
465 
468 {
469  return m_connectionManager;
470 }
471 
472 void
474 {
475  m_connectionManager = cm;
476 }
477 
480 {
481  return m_burstProfileManager;
482 }
483 
484 void
486 {
487  m_burstProfileManager = bpm;
488 }
489 
492 {
493  return m_bandwidthManager;
494 }
495 
496 void
498 {
499  m_bandwidthManager = bwm;
500 }
501 
502 void
504 {
505  m_initialRangingConnection = CreateObject<WimaxConnection> (Cid::InitialRanging (), Cid::INITIAL_RANGING);
506  m_broadcastConnection = CreateObject<WimaxConnection> (Cid::Broadcast (), Cid::BROADCAST);
507 }
508 
509 void
511 {
512 
513  NS_LOG_DEBUG ("WimaxNetDevice::Receive, station = " << GetMacAddress ());
514 
515  Ptr<PacketBurst> b = burst->Copy ();
516  for (std::list<Ptr<Packet> >::const_iterator iter = b->Begin (); iter != b->End (); ++iter)
517  {
518  Ptr<Packet> packet = *iter;
519  DoReceive (packet);
520  }
521 }
522 
525 {
526  return m_phy->GetChannel ();
527 }
528 
529 void
531 {
532  m_phy->SetReceiveCallback (MakeCallback (&WimaxNetDevice::Receive, this));
533 }
534 
535 bool
536 WimaxNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
537 {
538 
539  Mac48Address from = Mac48Address::ConvertFrom (source);
541 
542  LlcSnapHeader llcHdr;
543  llcHdr.SetType (protocolNumber);
544  packet->AddHeader (llcHdr);
545 
546  m_traceTx (packet, to);
547  return DoSend (packet, from, to, protocolNumber);
548 }
549 
550 void
552 {
553  m_promiscRx = cb;
554 }
555 
556 bool
558 {
559  return !(m_promiscRx.IsNull ());
560 }
561 
562 void
564 {
565  // m_promiscRx(p);
566 }
567 
568 bool
570 {
571  return false;
572 }
573 
574 void
576 {
577  SendParams * params = new OfdmSendParams (burst, modulationType, m_direction);
578  m_phy->Send (params);
579  delete params;
580 }
581 
582 void
584 {
585 
586  // initializing vector of channels (or frequencies)
587  // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
588  // Section 12.3.3.1 from IEEE 802.16-2004 standard
589  // profR10_3 :
590  // channels: 5000 + n â‹… 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
591  // from a range 5GHz to 6GHz, according to Section 8.5.1.
592  uint64_t frequency = 5000;
593 
594  for (uint8_t i = 0; i < 200; i++)
595  {
596  m_dlChannels.push_back (frequency);
597  frequency += 5;
598  }
599 }
600 
601 bool
603 {
605  return false;
606 }
607 
608 Address
610 {
611  NS_LOG_FUNCTION (multicastGroup);
612 
613  Mac48Address ad = Mac48Address::GetMulticast (multicastGroup);
614 
615  //
616  // Implicit conversion (operator Address ()) is defined for Mac48Address, so
617  // use it by just returning the EUI-48 address which is automagically converted
618  // to an Address.
619  //
620  NS_LOG_LOGIC ("multicast address is " << ad);
621 
622  return ad;
623 }
624 
625 Address
627 {
629 
630  NS_LOG_LOGIC ("MAC IPv6 multicast address is " << ad);
631  return ad;
632 }
633 
634 void
636 {
637  /* \todo Add a callback invoked whenever the link
638  * status changes to UP. This callback is typically used
639  * by the IP/ARP layer to flush the ARP cache and by IPv6 stack
640  * to flush NDISC cache whenever the link goes up.
641  */
642  NS_FATAL_ERROR ("Not implemented-- please implement and contribute a patch");
643 }
644 } // namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
void SetRtg(uint16_t rtg)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
uint16_t GetRtg(void) const
NetDevice::PromiscReceiveCallback m_promiscRx
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:1014
Ptr< WimaxConnection > m_broadcastConnection
void ForwardUp(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Ptr< BurstProfileManager > m_burstProfileManager
Callback< void > m_linkChange
Dcd GetCurrentDcd(void) const
Ptr< WimaxConnection > GetBroadcastConnection(void) const
void Receive(Ptr< const PacketBurst > burst)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
void SetType(uint16_t type)
Ptr< ConnectionManager > GetConnectionManager(void) const
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
a polymophic address class
Definition: address.h:86
static const uint16_t DEFAULT_MSDU_SIZE
virtual bool IsMulticast(void) const
uint32_t GetNrFrames(void) const
virtual Ptr< Channel > GetChannel(void) const
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceTx
virtual bool SetMtu(const uint16_t mtu)
static TypeId GetTypeId(void)
virtual Address GetMulticast(void) const
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)
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:46
Ptr< WimaxConnection > m_initialRangingConnection
virtual void SetIfIndex(const uint32_t index)
Doxygen 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:1238
static uint32_t m_nrFrames
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual void SetConnectionManager(Ptr< ConnectionManager > connectionManager)
Doxygen introspection did not find any typical Config paths.
Mac48Address GetMacAddress(void) const
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
#define list
static Mac48Address ConvertFrom(const Address &address)
virtual uint32_t GetIfIndex(void) const
virtual Ptr< Node > GetNode(void) const
NS_LOG_COMPONENT_DEFINE("WimaxNetDevice")
void SetBandwidthManager(Ptr< BandwidthManager > bandwidthManager)
virtual Address GetAddress(void) const
hold objects of type Ptr
Definition: pointer.h:33
virtual void SetLinkChangeCallback(Callback< void > callback)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual bool IsBroadcast(void) const
void SetBurstProfileManager(Ptr< BurstProfileManager > burstProfileManager)
Ucd GetCurrentUcd(void) const
an EUI-48 address
Definition: mac48-address.h:41
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:46
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
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:75
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)
Definition: log.h:289
void CreateDefaultConnections(void)
NetDevice::ReceiveCallback m_forwardUp
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< BandwidthManager > m_bandwidthManager
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
static Time m_frameStartTime
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
uint8_t GetState(void) const
Header for the LLC/SNAP encapsulation.
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceRx
static uint8_t m_direction