A Discrete-Event Network Simulator
API
wimax-net-device.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008,2009 INRIA, UDcast
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19 * <amine.ismail@UDcast.com>
20 */
21
22#include "wimax-net-device.h"
23
24#include "bandwidth-manager.h"
26#include "connection-manager.h"
27#include "send-params.h"
29#include "wimax-channel.h"
30
31#include "ns3/callback.h"
32#include "ns3/enum.h"
33#include "ns3/llc-snap-header.h"
34#include "ns3/node.h"
35#include "ns3/packet-burst.h"
36#include "ns3/packet.h"
37#include "ns3/pointer.h"
38#include "ns3/simulator.h"
39#include "ns3/trace-source-accessor.h"
40#include "ns3/uinteger.h"
41
42#include <list>
43
44namespace ns3
45{
46
47NS_LOG_COMPONENT_DEFINE("WimaxNetDevice");
48
49NS_OBJECT_ENSURE_REGISTERED(WimaxNetDevice);
50
54
55TypeId
57{
58 static TypeId tid =
59 TypeId("ns3::WimaxNetDevice")
60
62 .SetGroupName("Wimax")
63
64 // No AddConstructor because this is an abstract class.
65
66 .AddAttribute("Mtu",
67 "The MAC-level Maximum Transmission Unit",
70 MakeUintegerChecker<uint16_t>(0, MAX_MSDU_SIZE))
71
72 .AddAttribute("Phy",
73 "The PHY layer attached to this device.",
76 MakePointerChecker<WimaxPhy>())
77
78 .AddAttribute(
79 "Channel",
80 "The channel attached to this device.",
83 MakePointerChecker<WimaxChannel>())
84
85 .AddAttribute("RTG",
86 "receive/transmit transition gap.",
89 MakeUintegerChecker<uint16_t>(0, 120))
90
91 .AddAttribute("TTG",
92 "transmit/receive transition gap.",
95 MakeUintegerChecker<uint16_t>(0, 120))
96
97 .AddAttribute("ConnectionManager",
98 "The connection manager attached to this device.",
102 MakePointerChecker<ConnectionManager>())
103
104 .AddAttribute("BurstProfileManager",
105 "The burst profile manager attached to this device.",
106 PointerValue(),
109 MakePointerChecker<BurstProfileManager>())
110
111 .AddAttribute("BandwidthManager",
112 "The bandwidth manager attached to this device.",
113 PointerValue(),
116 MakePointerChecker<BandwidthManager>())
117
118 .AddAttribute("InitialRangingConnection",
119 "Initial ranging connection",
120 PointerValue(),
122 MakePointerChecker<WimaxConnection>())
123
124 .AddAttribute("BroadcastConnection",
125 "Broadcast connection",
126 PointerValue(),
128 MakePointerChecker<WimaxConnection>())
129
130 .AddTraceSource("Rx",
131 "Receive trace",
133 "ns3::WimaxNetDevice::TxRxTracedCallback")
134
135 .AddTraceSource("Tx",
136 "Transmit trace",
138 "ns3::WimaxNetDevice::TxRxTracedCallback");
139 return tid;
140}
141
143 : m_state(0),
144 m_symbolIndex(0),
145 m_ttg(0),
146 m_rtg(0)
147{
149 m_connectionManager = CreateObject<ConnectionManager>();
150 m_burstProfileManager = CreateObject<BurstProfileManager>(this);
151 m_bandwidthManager = CreateObject<BandwidthManager>(this);
152 m_nrFrames = 0;
153 m_direction = ~0;
155}
156
158{
159}
160
161void
163{
164 m_phy->Dispose();
165 m_phy = nullptr;
166 m_node = nullptr;
168 m_broadcastConnection = nullptr;
169 m_connectionManager = nullptr;
170 m_burstProfileManager = nullptr;
171 m_bandwidthManager = nullptr;
172 m_connectionManager = nullptr;
173 m_bandwidthManager = nullptr;
174
176}
177
178void
180{
181 m_ttg = ttg;
182}
183
184uint16_t
186{
187 return m_ttg;
188}
189
190void
192{
193 m_rtg = rtg;
194}
195
196uint16_t
198{
199 return m_rtg;
200}
201
202void
203WimaxNetDevice::SetName(const std::string name)
204{
205 m_name = name;
206}
207
208std::string
210{
211 return m_name;
212}
213
214void
216{
217 m_ifIndex = index;
218}
219
222{
223 return m_ifIndex;
224}
225
228{
229 return DoGetChannel();
230}
231
234{
235 return DoGetChannel();
236}
237
238bool
239WimaxNetDevice::SetMtu(const uint16_t mtu)
240{
241 if (mtu > MAX_MSDU_SIZE)
242 {
243 return false;
244 }
245 m_mtu = mtu;
246 return true;
247}
248
249uint16_t
251{
252 return m_mtu;
253}
254
255bool
257{
258 return m_phy && m_linkUp;
259}
260
261void
263{
264 m_linkChange = callback;
265}
266
267bool
269{
270 return true;
271}
272
275{
277}
278
279bool
281{
282 return false;
283}
284
287{
288 return Mac48Address("01:00:5e:00:00:00");
289}
290
293{
294 return GetMulticast();
295}
296
297bool
299{
300 return false;
301}
302
303bool
304WimaxNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
305{
307 LlcSnapHeader llcHdr;
308 llcHdr.SetType(protocolNumber);
309 packet->AddHeader(llcHdr);
310
311 m_traceTx(packet, to);
312
313 return DoSend(packet, Mac48Address::ConvertFrom(GetAddress()), to, protocolNumber);
314}
315
316void
318{
319 m_node = node;
320}
321
324{
325 return m_node;
326}
327
328bool
330{
331 return false;
332 /*
333 * Modified by Mohamed Amine ISMAIL.
334 * see "Transmission of IPv4 packets over IEEE 802.16's IP Convergence
335 * Sublayer draft-ietf-16ng-ipv4-over-802-dot-16-ipcs-04.txt" section
336 * 5.2
337 */
338}
339
340void
342{
343 m_forwardUp = cb;
344}
345
346void
348{
349 m_traceRx(packet, source);
350 LlcSnapHeader llc;
351 packet->RemoveHeader(llc);
352 m_forwardUp(this, packet, llc.GetType(), source);
353}
354
355void
357{
358 m_phy->Attach(channel);
359}
360
361void
363{
364 m_phy = phy;
365}
366
369{
370 return m_phy;
371}
372
373void
375{
376 if (m_phy)
377 {
378 m_phy->Attach(channel);
379 }
380}
381
382uint64_t
383WimaxNetDevice::GetChannel(uint8_t index) const
384{
385 return m_dlChannels.at(index);
386}
387
388void
390{
391 m_nrFrames = nrFrames;
392}
393
396{
397 return m_nrFrames;
398}
399
400void
402{
404}
405
406void
408{
410}
411
414{
415 return m_address;
416}
417
420{
421 return m_address;
422}
423
424void
426{
427 m_state = state;
428}
429
430uint8_t
432{
433 return m_state;
434}
435
438{
440}
441
444{
446}
447
448void
450{
451 m_currentDcd = dcd;
452}
453
454Dcd
456{
457 return m_currentDcd;
458}
459
460void
462{
463 m_currentUcd = ucd;
464}
465
466Ucd
468{
469 return m_currentUcd;
470}
471
474{
475 return m_connectionManager;
476}
477
478void
480{
482}
483
486{
488}
489
490void
492{
494}
495
498{
499 return m_bandwidthManager;
500}
501
502void
504{
505 m_bandwidthManager = bwm;
506}
507
508void
510{
512 CreateObject<WimaxConnection>(Cid::InitialRanging(), Cid::INITIAL_RANGING);
513 m_broadcastConnection = CreateObject<WimaxConnection>(Cid::Broadcast(), Cid::BROADCAST);
514}
515
516void
518{
519 NS_LOG_DEBUG("WimaxNetDevice::Receive, station = " << GetMacAddress());
520
521 Ptr<PacketBurst> b = burst->Copy();
522 for (std::list<Ptr<Packet>>::const_iterator iter = b->Begin(); iter != b->End(); ++iter)
523 {
524 Ptr<Packet> packet = *iter;
525 DoReceive(packet);
526 }
527}
528
531{
532 return m_phy->GetChannel();
533}
534
535void
537{
538 m_phy->SetReceiveCallback(MakeCallback(&WimaxNetDevice::Receive, this));
539}
540
541bool
543 const Address& source,
544 const Address& dest,
545 uint16_t protocolNumber)
546{
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
558void
560{
561 m_promiscRx = cb;
562}
563
564bool
566{
567 return !(m_promiscRx.IsNull());
568}
569
570void
572{
573 // m_promiscRx(p);
574}
575
576bool
578{
579 return false;
580}
581
582void
584{
585 SendParams* params = new OfdmSendParams(burst, modulationType, m_direction);
586 m_phy->Send(params);
587 delete params;
588}
589
590void
592{
593 // initializing vector of channels (or frequencies)
594 // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
595 // Section 12.3.3.1 from IEEE 802.16-2004 standard
596 // profR10_3 :
597 // channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
598 // from a range 5GHz to 6GHz, according to Section 8.5.1.
599 uint64_t frequency = 5000;
600
601 for (uint8_t i = 0; i < 200; i++)
602 {
603 m_dlChannels.push_back(frequency);
604 frequency += 5;
605 }
606}
607
608bool
610{
612 return false;
613}
614
617{
618 NS_LOG_FUNCTION(multicastGroup);
619
620 Mac48Address ad = Mac48Address::GetMulticast(multicastGroup);
621
622 //
623 // Implicit conversion (operator Address ()) is defined for Mac48Address, so
624 // use it by just returning the EUI-48 address which is automagically converted
625 // to an Address.
626 //
627 NS_LOG_LOGIC("multicast address is " << ad);
628
629 return ad;
630}
631
634{
636
637 NS_LOG_LOGIC("MAC IPv6 multicast address is " << ad);
638 return ad;
639}
640
641void
643{
644 /* \todo Add a callback invoked whenever the link
645 * status changes to UP. This callback is typically used
646 * by the IP/ARP layer to flush the ARP cache and by IPv6 stack
647 * to flush NDISC cache whenever the link goes up.
648 */
649 NS_FATAL_ERROR("Not implemented-- please implement and contribute a patch");
650}
651} // namespace ns3
a polymophic address class
Definition: address.h:100
bool IsNull() const
Check for null implementation.
Definition: callback.h:572
@ BROADCAST
Definition: cid.h:42
@ INITIAL_RANGING
Definition: cid.h:43
static Cid InitialRanging()
Definition: cid.cc:87
static Cid Broadcast()
Definition: cid.cc:75
This class implements Downlink channel descriptor as described by "IEEE Standard for Local and metrop...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Header for the LLC/SNAP encapsulation.
uint16_t GetType()
Return the Ethertype.
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetMulticast(Ipv4Address address)
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
Network layer to device interface.
Definition: net-device.h:98
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
OfdmSendParams class.
Definition: send-params.h:68
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
Hold objects of type Ptr<T>.
Definition: pointer.h:37
The SendParams class defines the parameters with which Send() function of a particular PHY is called.
Definition: send-params.h:42
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
This class implements the UCD message as described by "IEEE Standard for Local and metropolitan area ...
Hold an unsigned integer type.
Definition: uinteger.h:45
NetDevice::ReceiveCallback m_forwardUp
forward up callback function
Ptr< Channel > GetChannel() const override
Get the channel.
virtual std::string GetName() const
Get device name.
void DoDispose() override
Destructor implementation.
uint16_t GetRtg() const
Get receive/transmit transition gap.
void SetRtg(uint16_t rtg)
Set receive/transmit transition gap.
virtual void SetConnectionManager(Ptr< ConnectionManager > connectionManager)
Set the connection manager of the device.
Ptr< BandwidthManager > m_bandwidthManager
badnwidth manager
bool NeedsArp() const override
Check if device needs ARP.
Ptr< BurstProfileManager > m_burstProfileManager
burst profile manager
static uint8_t m_direction
downlink or uplink
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceTx
void Receive(Ptr< const PacketBurst > burst)
Receive a packet burst.
void SetAddress(Address address) override
Set address of the device.
std::vector< uint64_t > m_dlChannels
not sure if it shall be included here
NetDevice::PromiscReceiveCallback m_promiscRx
promiscious receive fcallback function
Mac48Address m_address
MAC address.
static TypeId GetTypeId()
Get the type ID.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
Send a packet.
Ptr< ConnectionManager > GetConnectionManager() const
Get the connection manager of the device.
Ptr< WimaxConnection > m_initialRangingConnection
initial rnaging connection
uint32_t GetIfIndex() const override
Get interface index.
bool IsMulticast() const override
Check if multicast enabled.
Ucd GetCurrentUcd() const
Get the current UCD.
virtual Address MakeMulticastAddress(Ipv4Address multicastGroup) const
Make multicast address.
void SetPhy(Ptr< WimaxPhy > phy)
Set the physical layer object.
Address GetAddress() const override
Get address of the device.
Address GetBroadcast() const override
Get broadcast address.
virtual bool DoSend(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest, uint16_t protocolNumber)=0
Send a packet.
virtual Ptr< Channel > GetPhyChannel() const
Get the channel (this method is redundant with GetChannel())
void AddLinkChangeCallback(Callback< void > callback) override
Add link change callback function.
virtual void SetName(const std::string name)
Set device name.
uint8_t GetState() const
Get the device state.
uint16_t GetMtu() const override
Get MTU of the device.
static const uint16_t DEFAULT_MSDU_SIZE
recommended by wimax forum.
static const uint16_t MAX_MSDU_SIZE
Maximum MSDU size.
void SetCurrentUcd(Ucd ucd)
Set the current UCD.
uint32_t GetNrFrames() const
Get the number of frames.
void SetMacAddress(Mac48Address address)
Set the MAC address.
Ptr< Node > GetNode() const override
Get node pointer.
Ptr< WimaxConnection > m_broadcastConnection
broadcast connection
static Time m_frameStartTime
temp, to determine the frame start time at SS side, shall actually be determined by frame start pream...
void SetBurstProfileManager(Ptr< BurstProfileManager > burstProfileManager)
Set the burst profile manager.
void SetState(uint8_t state)
Set the device state.
Ptr< WimaxPhy > m_phy
the phy
void SetChannel(Ptr< WimaxChannel > wimaxChannel)
Set the channel object.
bool SetMtu(const uint16_t mtu) override
Set MTU value for the device.
Ptr< WimaxConnection > GetInitialRangingConnection() const
Get the initial ranging connection.
virtual void SetLinkChangeCallback(Callback< void > callback)
Set link change callback function.
Ptr< ConnectionManager > m_connectionManager
connection manager
void SetBandwidthManager(Ptr< BandwidthManager > bandwidthManager)
Set the bandwidth manager on the device.
Ptr< WimaxPhy > GetPhy() const
Get the physical layer object.
uint32_t m_ifIndex
IF index.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
Set promiscious receive callback function.
bool IsPointToPoint() const override
Check if device is a point-to-point device.
void InitializeChannels()
Initialize channels function.
Ptr< BandwidthManager > GetBandwidthManager() const
Get the bandwidth manager on the device.
Ptr< WimaxConnection > GetBroadcastConnection() const
Get the broadcast connection.
Callback< void > m_linkChange
link change callback
virtual Address GetMulticast() const
Get multicast address.
std::string m_name
service name
virtual void DoReceive(Ptr< Packet > packet)=0
Receive a packet.
bool IsPromisc()
Check if device is promiscious.
static uint32_t m_nrFrames
temp, shall be in BS.
void Attach(Ptr< WimaxChannel > channel)
Attach device to channel.
void SetTtg(uint16_t ttg)
Set transmission/receive transition gap.
void CreateDefaultConnections()
Creates the initial ranging and broadcast connections.
void SetNrFrames(uint32_t nrFrames)
Set the number of frames.
uint16_t m_ttg
length of TTG in units of PSs
void SetCurrentDcd(Dcd dcd)
Set the current DCD.
void SetReceiveCallback()
Set receive callback function.
bool SupportsSendFrom() const override
Check if device supports the SendFrom method.
bool IsLinkUp() const override
Check if link is up.
void SetIfIndex(const uint32_t index) override
Set interface index.
uint16_t GetTtg() const
Get transmission/receive transition gap.
Mac48Address GetMacAddress() const
Get the MAC address.
void SetNode(Ptr< Node > node) override
Set node pointer.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Send function.
Ptr< Node > m_node
the node
void NotifyPromiscTrace(Ptr< Packet > p)
Notify promiscious trace of a packet arrival.
void ForwardUp(Ptr< Packet > packet, const Mac48Address &source, const Mac48Address &dest)
Forward a packet to the next layer above the device.
TracedCallback< Ptr< const Packet >, const Mac48Address & > m_traceRx
virtual Ptr< WimaxChannel > DoGetChannel() const
Get the channel.
Ptr< BurstProfileManager > GetBurstProfileManager() const
Get the burst profile manager.
Dcd GetCurrentDcd() const
Get the current DCD.
void ForwardDown(Ptr< PacketBurst > burst, WimaxPhy::ModulationType modulationType)
Forward a packet down the stack.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
uint16_t m_rtg
length of RTG in units of PSs
bool IsBroadcast() const override
Check if broadcast enabled.
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:231
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:40
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:848
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:707
channel
Definition: third.py:81
phy
Definition: third.py:82
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
#define list