A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wimax-net-device.cc
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 
52 TypeId WimaxNetDevice::GetTypeId (void)
53 {
54  static TypeId
55  tid =
56  TypeId ("ns3::WimaxNetDevice")
57 
58  .SetParent<NetDevice> ()
59 
60  .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
61  UintegerValue (DEFAULT_MSDU_SIZE),
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 (),
75  MakePointerAccessor (&WimaxNetDevice::GetPhyChannel, &WimaxNetDevice::SetChannel),
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 
129 WimaxNetDevice::WimaxNetDevice (void)
130  : m_state (0),
131  m_symbolIndex (0),
132  m_ttg (0),
133  m_rtg (0)
134 {
135  InitializeChannels ();
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 
144 WimaxNetDevice::~WimaxNetDevice (void)
145 {
146 }
147 
148 void
150 {
151 
152  m_phy->Dispose ();
153  m_phy = 0;
154  m_node = 0;
155  m_initialRangingConnection = 0;
156  m_broadcastConnection = 0;
157  m_connectionManager = 0;
158  m_burstProfileManager = 0;
159  m_bandwidthManager = 0;
160  m_connectionManager = 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
198 WimaxNetDevice::GetName (void) const
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 
222 WimaxNetDevice::GetPhyChannel (void) const
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
253 WimaxNetDevice::SetLinkChangeCallback (Callback<void> callback)
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
277 WimaxNetDevice::GetMulticast (void) const
278 {
279  return Mac48Address ("01:00:5e:00:00:00");
280 }
281 
282 Address
283 WimaxNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
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
333 WimaxNetDevice::SetReceiveCallback (ReceiveCallback cb)
334 {
335  m_forwardUp = cb;
336 }
337 
338 void
339 WimaxNetDevice::ForwardUp (Ptr<Packet> packet, const Mac48Address &source, const Mac48Address &dest)
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
348 WimaxNetDevice::Attach (Ptr<WimaxChannel> channel)
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 {
396  m_address = Mac48Address::ConvertFrom (address);
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
418 WimaxNetDevice::SetState (uint8_t state)
419 {
420  m_state = state;
421 }
422 
423 uint8_t
424 WimaxNetDevice::GetState (void) const
425 {
426  return m_state;
427 }
428 
429 Ptr<WimaxConnection>
431 {
432  return m_initialRangingConnection;
433 }
434 
437 {
438  return m_broadcastConnection;
439 }
440 
441 void
442 WimaxNetDevice::SetCurrentDcd (Dcd dcd)
443 {
444  m_currentDcd = dcd;
445 }
446 
447 Dcd
448 WimaxNetDevice::GetCurrentDcd (void) const
449 {
450  return m_currentDcd;
451 }
452 
453 void
454 WimaxNetDevice::SetCurrentUcd (Ucd ucd)
455 {
456  m_currentUcd = ucd;
457 }
458 
459 Ucd
460 WimaxNetDevice::GetCurrentUcd (void) const
461 {
462  return m_currentUcd;
463 }
464 
465 Ptr<ConnectionManager>
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
502 WimaxNetDevice::CreateDefaultConnections (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
509 WimaxNetDevice::Receive (Ptr<const PacketBurst> burst)
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 
522 Ptr<WimaxChannel>
523 WimaxNetDevice::DoGetChannel (void) const
524 {
525  return m_phy->GetChannel ();
526 }
527 
528 void
529 WimaxNetDevice::SetReceiveCallback (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
556 WimaxNetDevice::IsPromisc (void)
557 {
558  return !(m_promiscRx.IsNull ());
559 }
560 
561 void
562 WimaxNetDevice::NotifyPromiscTrace (Ptr<Packet> p)
563 {
564  // m_promiscRx(p);
565 }
566 
567 bool
569 {
570  return false;
571 }
572 
573 void
574 WimaxNetDevice::ForwardDown (Ptr<PacketBurst> burst, WimaxPhy::ModulationType modulationType)
575 {
576  SendParams * params = new OfdmSendParams (burst, modulationType, m_direction);
577  m_phy->Send (params);
578  delete params;
579 }
580 
581 void
582 WimaxNetDevice::InitializeChannels (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
608 WimaxNetDevice::GetMulticast (Ipv4Address multicastGroup) const
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
625 WimaxNetDevice::GetMulticast (Ipv6Address addr) const
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)
Definition: packet.cc:285
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:311
uint16_t GetRtg(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
Ptr< WimaxConnection > GetBroadcastConnection(void) const
virtual void DoDispose(void)
Definition: object.cc:335
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
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
virtual bool IsMulticast(void) const
virtual Ptr< Channel > GetChannel(void) const
virtual bool SetMtu(const uint16_t mtu)
uint16_t GetTtg(void) const
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)
static Cid Broadcast(void)
Definition: cid.cc:72
static Cid InitialRanging(void)
Definition: cid.cc:82
virtual void SetIfIndex(const uint32_t index)
virtual Address GetBroadcast(void) const
static Mac48Address GetBroadcast(void)
Ptr< WimaxConnection > GetInitialRangingConnection(void) const
Ptr< BandwidthManager > GetBandwidthManager(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
virtual void SetConnectionManager(Ptr< ConnectionManager > connectionManager)
Mac48Address GetMacAddress(void) const
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
virtual void DoDispose(void)
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
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual bool IsBroadcast(void) const
void SetBurstProfileManager(Ptr< BurstProfileManager > burstProfileManager)
an EUI-48 address
Definition: mac48-address.h:41
void SetMacAddress(Mac48Address address)
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)
virtual bool SupportsSendFrom(void) const
Ptr< BurstProfileManager > GetBurstProfileManager(void) const
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual void AddLinkChangeCallback(Callback< void > callback)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual uint16_t GetMtu(void) const
Ptr< WimaxPhy > GetPhy(void) const
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
virtual void SetAddress(Address address)
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void SetNode(Ptr< Node > node)
virtual bool NeedsArp(void) const
void AddHeader(const Header &header)
Definition: packet.cc:270
Header for the LLC/SNAP encapsulation.