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 uint32_t WimaxNetDevice::m_nrFrames = 0;
49 uint8_t WimaxNetDevice::m_direction = ~0;
50 Time WimaxNetDevice::m_frameStartTime = Seconds (0);
51 
53 {
54  static TypeId
55  tid =
56  TypeId ("ns3::WimaxNetDevice")
57 
58  .SetParent<NetDevice> ()
59 
60  .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
62  MakeUintegerAccessor (&WimaxNetDevice::SetMtu,
64  MakeUintegerChecker<uint16_t> (0,MAX_MSDU_SIZE))
65 
66  .AddAttribute ("Phy",
67  "The PHY layer attached to this device.",
68  PointerValue (),
69  MakePointerAccessor (&WimaxNetDevice::GetPhy, &WimaxNetDevice::SetPhy),
70  MakePointerChecker<WimaxPhy> ())
71 
72  .AddAttribute ("Channel",
73  "The channel attached to this device.",
74  PointerValue (),
76  MakePointerChecker<WimaxChannel> ())
77 
78  .AddAttribute ("RTG",
79  "receive/transmit transition gap.",
80  UintegerValue (0),
81  MakeUintegerAccessor (&WimaxNetDevice::GetRtg, &WimaxNetDevice::SetRtg),
82  MakeUintegerChecker<uint16_t> (0, 120))
83 
84  .AddAttribute ("TTG",
85  "transmit/receive transition gap.",
86  UintegerValue (0),
87  MakeUintegerAccessor (&WimaxNetDevice::GetTtg, &WimaxNetDevice::SetTtg),
88  MakeUintegerChecker<uint16_t> (0, 120))
89 
90  .AddAttribute ("ConnectionManager",
91  "The connection manager attached to this device.",
92  PointerValue (),
93  MakePointerAccessor (&WimaxNetDevice::GetConnectionManager,
95  MakePointerChecker<ConnectionManager> ())
96 
97  .AddAttribute ("BurstProfileManager",
98  "The burst profile manager attached to this device.",
99  PointerValue (),
100  MakePointerAccessor (&WimaxNetDevice::GetBurstProfileManager,
102  MakePointerChecker<BurstProfileManager> ())
103 
104  .AddAttribute ("BandwidthManager",
105  "The bandwidth manager attached to this device.",
106  PointerValue (),
107  MakePointerAccessor (&WimaxNetDevice::GetBandwidthManager,
109  MakePointerChecker<BandwidthManager> ())
110 
111  .AddAttribute ("InitialRangingConnection",
112  "Initial ranging connection",
113  PointerValue (),
114  MakePointerAccessor (&WimaxNetDevice::m_initialRangingConnection),
115  MakePointerChecker<WimaxConnection> ())
116 
117  .AddAttribute ("BroadcastConnection",
118  "Broadcast connection",
119  PointerValue (),
120  MakePointerAccessor (&WimaxNetDevice::m_broadcastConnection),
121  MakePointerChecker<WimaxConnection> ())
122 
123  .AddTraceSource ("Rx", "Receive trace", MakeTraceSourceAccessor (&WimaxNetDevice::m_traceRx))
124 
125  .AddTraceSource ("Tx", "Transmit trace", MakeTraceSourceAccessor (&WimaxNetDevice::m_traceTx));
126  return tid;
127 }
128 
130  : m_state (0),
131  m_symbolIndex (0),
132  m_ttg (0),
133  m_rtg (0)
134 {
136  m_connectionManager = CreateObject<ConnectionManager> ();
137  m_burstProfileManager = CreateObject<BurstProfileManager> (this);
138  m_bandwidthManager = CreateObject<BandwidthManager> (this);
139  m_nrFrames = 0;
140  m_direction = ~0;
141  m_frameStartTime = Seconds (0);
142 }
143 
145 {
146 }
147 
148 void
150 {
151 
152  m_phy->Dispose ();
153  m_phy = 0;
154  m_node = 0;
159  m_bandwidthManager = 0;
161  m_bandwidthManager = 0;
162 
164 }
165 
166 
167 void
169 {
170  m_ttg = ttg;
171 }
172 
173 uint16_t
175 {
176  return m_ttg;
177 }
178 
179 void
181 {
182  m_rtg = rtg;
183 }
184 
185 uint16_t
187 {
188  return m_rtg;
189 }
190 
191 void
192 WimaxNetDevice::SetName (const std::string name)
193 {
194  m_name = name;
195 }
196 
197 std::string
199 {
200  return m_name;
201 }
202 
203 void
204 WimaxNetDevice::SetIfIndex (const uint32_t index)
205 {
206  m_ifIndex = index;
207 }
208 
209 uint32_t
211 {
212  return m_ifIndex;
213 }
214 
217 {
218  return DoGetChannel ();
219 }
220 
223 {
224  return DoGetChannel ();
225 }
226 
227 bool
228 WimaxNetDevice::SetMtu (const uint16_t mtu)
229 {
230  if (mtu > MAX_MSDU_SIZE)
231  {
232  return false;
233  }
234  m_mtu = mtu;
235  return true;
236 }
237 
238 uint16_t
240 {
241  return m_mtu;
242 }
243 
244 bool
246 {
247 
248  return m_phy != 0 && m_linkUp;
249 
250 }
251 
252 void
254 {
255  m_linkChange = callback;
256 }
257 
258 bool
260 {
261  return true;
262 }
263 
264 Address
266 {
267  return Mac48Address::GetBroadcast ();
268 }
269 
270 bool
272 {
273  return false;
274 }
275 
276 Address
278 {
279  return Mac48Address ("01:00:5e:00:00:00");
280 }
281 
282 Address
284 {
285  return GetMulticast ();
286 }
287 
288 bool
290 {
291  return false;
292 }
293 
294 bool
295 WimaxNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
296 {
297 
299  LlcSnapHeader llcHdr;
300  llcHdr.SetType (protocolNumber);
301  packet->AddHeader (llcHdr);
302 
303  m_traceTx (packet, to);
304 
305  return DoSend (packet, Mac48Address::ConvertFrom (GetAddress ()), to, protocolNumber);
306 }
307 
308 void
310 {
311  m_node = node;
312 }
313 
314 Ptr<Node>
316 {
317  return m_node;
318 }
319 
320 bool
322 {
323  return false;
324  /*
325  * Modified by Mohamed Amine ISMAIL.
326  * see "Transmission of IPv4 packets over IEEE 802.16's IP Convergence
327  * Sublayer draft-ietf-16ng-ipv4-over-802-dot-16-ipcs-04.txt" section
328  * 5.2
329  */
330 }
331 
332 void
334 {
335  m_forwardUp = cb;
336 }
337 
338 void
340 {
341  m_traceRx (packet, source);
342  LlcSnapHeader llc;
343  packet->RemoveHeader (llc);
344  m_forwardUp (this, packet, llc.GetType (), source);
345 }
346 
347 void
349 {
350  m_phy->Attach (channel);
351 }
352 
353 void
355 {
356  m_phy = phy;
357 }
358 
361 {
362  return m_phy;
363 }
364 
365 void
367 {
368  if (m_phy != 0)
369  {
370  m_phy->Attach (channel);
371  }
372 
373 }
374 
375 uint64_t
376 WimaxNetDevice::GetChannel (uint8_t index) const
377 {
378  return m_dlChannels.at (index);
379 }
380 
381 void
382 WimaxNetDevice::SetNrFrames (uint32_t nrFrames)
383 {
384  m_nrFrames = nrFrames;
385 }
386 
387 uint32_t WimaxNetDevice::GetNrFrames (void) const
388 {
389 
390  return m_nrFrames;
391 }
392 
393 void
395 {
397 }
398 
399 void
401 {
402  m_address = address;
403 }
404 
405 Address
407 {
408  return m_address;
409 }
410 
413 {
414  return m_address;
415 }
416 
417 void
419 {
420  m_state = state;
421 }
422 
423 uint8_t
425 {
426  return m_state;
427 }
428 
431 {
433 }
434 
437 {
438  return m_broadcastConnection;
439 }
440 
441 void
443 {
444  m_currentDcd = dcd;
445 }
446 
447 Dcd
449 {
450  return m_currentDcd;
451 }
452 
453 void
455 {
456  m_currentUcd = ucd;
457 }
458 
459 Ucd
461 {
462  return m_currentUcd;
463 }
464 
467 {
468  return m_connectionManager;
469 }
470 
471 void
473 {
474  m_connectionManager = cm;
475 }
476 
479 {
480  return m_burstProfileManager;
481 }
482 
483 void
485 {
486  m_burstProfileManager = bpm;
487 }
488 
491 {
492  return m_bandwidthManager;
493 }
494 
495 void
497 {
498  m_bandwidthManager = bwm;
499 }
500 
501 void
503 {
504  m_initialRangingConnection = CreateObject<WimaxConnection> (Cid::InitialRanging (), Cid::INITIAL_RANGING);
505  m_broadcastConnection = CreateObject<WimaxConnection> (Cid::Broadcast (), Cid::BROADCAST);
506 }
507 
508 void
510 {
511 
512  NS_LOG_DEBUG ("WimaxNetDevice::Receive, station = " << GetMacAddress ());
513 
514  Ptr<PacketBurst> b = burst->Copy ();
515  for (std::list<Ptr<Packet> >::const_iterator iter = b->Begin (); iter != b->End (); ++iter)
516  {
517  Ptr<Packet> packet = *iter;
518  DoReceive (packet);
519  }
520 }
521 
524 {
525  return m_phy->GetChannel ();
526 }
527 
528 void
530 {
531  m_phy->SetReceiveCallback (MakeCallback (&WimaxNetDevice::Receive, this));
532 }
533 
534 bool
535 WimaxNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
536 {
537 
538  Mac48Address from = Mac48Address::ConvertFrom (source);
540 
541  LlcSnapHeader llcHdr;
542  llcHdr.SetType (protocolNumber);
543  packet->AddHeader (llcHdr);
544 
545  m_traceTx (packet, to);
546  return DoSend (packet, from, to, protocolNumber);
547 }
548 
549 void
551 {
552  m_promiscRx = cb;
553 }
554 
555 bool
557 {
558  return !(m_promiscRx.IsNull ());
559 }
560 
561 void
563 {
564  // m_promiscRx(p);
565 }
566 
567 bool
569 {
570  return false;
571 }
572 
573 void
575 {
576  SendParams * params = new OfdmSendParams (burst, modulationType, m_direction);
577  m_phy->Send (params);
578  delete params;
579 }
580 
581 void
583 {
584 
585  // initializing vector of channels (or frequencies)
586  // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
587  // Section 12.3.3.1 from IEEE 802.16-2004 standard
588  // profR10_3 :
589  // channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
590  // from a range 5GHz to 6GHz, according to Section 8.5.1.
591  uint64_t frequency = 5000;
592 
593  for (uint8_t i = 0; i < 200; i++)
594  {
595  m_dlChannels.push_back (frequency);
596  frequency += 5;
597  }
598 }
599 
600 bool
602 {
604  return false;
605 }
606 
607 Address
609 {
610  NS_LOG_FUNCTION (multicastGroup);
611 
612  Mac48Address ad = Mac48Address::GetMulticast (multicastGroup);
613 
614  //
615  // Implicit conversion (operator Address ()) is defined for Mac48Address, so
616  // use it by just returning the EUI-48 address which is automagically converted
617  // to an Address.
618  //
619  NS_LOG_LOGIC ("multicast address is " << ad);
620 
621  return ad;
622 }
623 
624 Address
626 {
628 
629  NS_LOG_LOGIC ("MAC IPv6 multicast address is " << ad);
630  return ad;
631 }
632 
633 void
635 {
636  /* \todo Add a callback invoked whenever the link
637  * status changes to UP. This callback is typically used
638  * by the IP/ARP layer to flush the ARP cache and by IPv6 stack
639  * to flush NDISC cache whenever the link goes up.
640  */
641  NS_FATAL_ERROR ("Not implemented-- please implement and contribute a patch");
642 }
643 } // 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:60
#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 the class in the ns-3 factory.
Definition: object-base.h:38
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:1018
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:170
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:335
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
#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: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)
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: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:1242
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)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
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
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)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
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:610
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