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 
60  .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
64  MakeUintegerChecker<uint16_t> (0,MAX_MSDU_SIZE))
65 
66  .AddAttribute ("Phy",
67  "The PHY layer attached to this device.",
68  PointerValue (),
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),
82  MakeUintegerChecker<uint16_t> (0, 120))
83 
84  .AddAttribute ("TTG",
85  "transmit/receive transition gap.",
86  UintegerValue (0),
88  MakeUintegerChecker<uint16_t> (0, 120))
89 
90  .AddAttribute ("ConnectionManager",
91  "The connection manager attached to this device.",
92  PointerValue (),
95  MakePointerChecker<ConnectionManager> ())
96 
97  .AddAttribute ("BurstProfileManager",
98  "The burst profile manager attached to this device.",
99  PointerValue (),
102  MakePointerChecker<BurstProfileManager> ())
103 
104  .AddAttribute ("BandwidthManager",
105  "The bandwidth manager attached to this device.",
106  PointerValue (),
109  MakePointerChecker<BandwidthManager> ())
110 
111  .AddAttribute ("InitialRangingConnection",
112  "Initial ranging connection",
113  PointerValue (),
115  MakePointerChecker<WimaxConnection> ())
116 
117  .AddAttribute ("BroadcastConnection",
118  "Broadcast connection",
119  PointerValue (),
121  MakePointerChecker<WimaxConnection> ())
122 
123  .AddTraceSource ("Rx",
124  "Receive trace",
126  "ns3::Packet::TracedCallback")
127 
128  .AddTraceSource ("Tx",
129  "Transmit trace",
131  "ns3::Packet::TracedCallback");
132  return tid;
133 }
134 
136  : m_state (0),
137  m_symbolIndex (0),
138  m_ttg (0),
139  m_rtg (0)
140 {
142  m_connectionManager = CreateObject<ConnectionManager> ();
143  m_burstProfileManager = CreateObject<BurstProfileManager> (this);
144  m_bandwidthManager = CreateObject<BandwidthManager> (this);
145  m_nrFrames = 0;
146  m_direction = ~0;
148 }
149 
151 {
152 }
153 
154 void
156 {
157 
158  m_phy->Dispose ();
159  m_phy = 0;
160  m_node = 0;
165  m_bandwidthManager = 0;
167  m_bandwidthManager = 0;
168 
170 }
171 
172 
173 void
175 {
176  m_ttg = ttg;
177 }
178 
179 uint16_t
181 {
182  return m_ttg;
183 }
184 
185 void
187 {
188  m_rtg = rtg;
189 }
190 
191 uint16_t
193 {
194  return m_rtg;
195 }
196 
197 void
198 WimaxNetDevice::SetName (const std::string name)
199 {
200  m_name = name;
201 }
202 
203 std::string
205 {
206  return m_name;
207 }
208 
209 void
210 WimaxNetDevice::SetIfIndex (const uint32_t index)
211 {
212  m_ifIndex = index;
213 }
214 
215 uint32_t
217 {
218  return m_ifIndex;
219 }
220 
223 {
224  return DoGetChannel ();
225 }
226 
229 {
230  return DoGetChannel ();
231 }
232 
233 bool
234 WimaxNetDevice::SetMtu (const uint16_t mtu)
235 {
236  if (mtu > MAX_MSDU_SIZE)
237  {
238  return false;
239  }
240  m_mtu = mtu;
241  return true;
242 }
243 
244 uint16_t
246 {
247  return m_mtu;
248 }
249 
250 bool
252 {
253 
254  return m_phy != 0 && m_linkUp;
255 
256 }
257 
258 void
260 {
261  m_linkChange = callback;
262 }
263 
264 bool
266 {
267  return true;
268 }
269 
270 Address
272 {
273  return Mac48Address::GetBroadcast ();
274 }
275 
276 bool
278 {
279  return false;
280 }
281 
282 Address
284 {
285  return Mac48Address ("01:00:5e:00:00:00");
286 }
287 
288 Address
290 {
291  return GetMulticast ();
292 }
293 
294 bool
296 {
297  return false;
298 }
299 
300 bool
301 WimaxNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
302 {
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 != 0)
375  {
376  m_phy->Attach (channel);
377  }
378 
379 }
380 
381 uint64_t
382 WimaxNetDevice::GetChannel (uint8_t index) const
383 {
384  return m_dlChannels.at (index);
385 }
386 
387 void
388 WimaxNetDevice::SetNrFrames (uint32_t nrFrames)
389 {
390  m_nrFrames = nrFrames;
391 }
392 
393 uint32_t WimaxNetDevice::GetNrFrames (void) const
394 {
395 
396  return m_nrFrames;
397 }
398 
399 void
401 {
403 }
404 
405 void
407 {
408  m_address = address;
409 }
410 
411 Address
413 {
414  return m_address;
415 }
416 
419 {
420  return m_address;
421 }
422 
423 void
425 {
426  m_state = state;
427 }
428 
429 uint8_t
431 {
432  return m_state;
433 }
434 
437 {
439 }
440 
443 {
444  return m_broadcastConnection;
445 }
446 
447 void
449 {
450  m_currentDcd = dcd;
451 }
452 
453 Dcd
455 {
456  return m_currentDcd;
457 }
458 
459 void
461 {
462  m_currentUcd = ucd;
463 }
464 
465 Ucd
467 {
468  return m_currentUcd;
469 }
470 
473 {
474  return m_connectionManager;
475 }
476 
477 void
479 {
480  m_connectionManager = cm;
481 }
482 
485 {
486  return m_burstProfileManager;
487 }
488 
489 void
491 {
492  m_burstProfileManager = bpm;
493 }
494 
497 {
498  return m_bandwidthManager;
499 }
500 
501 void
503 {
504  m_bandwidthManager = bwm;
505 }
506 
507 void
509 {
510  m_initialRangingConnection = CreateObject<WimaxConnection> (Cid::InitialRanging (), Cid::INITIAL_RANGING);
511  m_broadcastConnection = CreateObject<WimaxConnection> (Cid::Broadcast (), Cid::BROADCAST);
512 }
513 
514 void
516 {
517 
518  NS_LOG_DEBUG ("WimaxNetDevice::Receive, station = " << GetMacAddress ());
519 
520  Ptr<PacketBurst> b = burst->Copy ();
521  for (std::list<Ptr<Packet> >::const_iterator iter = b->Begin (); iter != b->End (); ++iter)
522  {
523  Ptr<Packet> packet = *iter;
524  DoReceive (packet);
525  }
526 }
527 
530 {
531  return m_phy->GetChannel ();
532 }
533 
534 void
536 {
537  m_phy->SetReceiveCallback (MakeCallback (&WimaxNetDevice::Receive, this));
538 }
539 
540 bool
541 WimaxNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
542 {
543 
544  Mac48Address from = Mac48Address::ConvertFrom (source);
546 
547  LlcSnapHeader llcHdr;
548  llcHdr.SetType (protocolNumber);
549  packet->AddHeader (llcHdr);
550 
551  m_traceTx (packet, to);
552  return DoSend (packet, from, to, protocolNumber);
553 }
554 
555 void
557 {
558  m_promiscRx = cb;
559 }
560 
561 bool
563 {
564  return !(m_promiscRx.IsNull ());
565 }
566 
567 void
569 {
570  // m_promiscRx(p);
571 }
572 
573 bool
575 {
576  return false;
577 }
578 
579 void
581 {
582  SendParams * params = new OfdmSendParams (burst, modulationType, m_direction);
583  m_phy->Send (params);
584  delete params;
585 }
586 
587 void
589 {
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
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: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:1078
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)
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:339
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
#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
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceTx
virtual bool SetMtu(const uint16_t mtu)
static TypeId GetTypeId(void)
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:210
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:1296
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)
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:47
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: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:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
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< 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:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
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