A Discrete-Event Network Simulator
API
uan-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) 2009 University of Washington
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 * Author: Leonard Tracy <lentracy@gmail.com>
19 */
20
21#include "ns3/trace-source-accessor.h"
22#include "ns3/traced-callback.h"
23#include "ns3/pointer.h"
24#include "ns3/node.h"
25#include "ns3/assert.h"
26#include "uan-net-device.h"
27#include "uan-phy.h"
28#include "uan-mac.h"
29#include "uan-channel.h"
30#include "uan-transducer.h"
31#include "ns3/log.h"
32
33namespace ns3 {
34
35NS_LOG_COMPONENT_DEFINE ("UanNetDevice");
36
37NS_OBJECT_ENSURE_REGISTERED (UanNetDevice);
38
40 : NetDevice (),
41 m_mtu (64000),
42 m_cleared (false)
43{
44}
45
47{
48}
49
50void
52{
53 if (m_cleared)
54 {
55 return;
56 }
57 m_cleared = true;
58 m_node = 0;
59 if (m_channel)
60 {
61 m_channel->Clear ();
62 m_channel = 0;
63 }
64 if (m_mac)
65 {
66 m_mac->Clear ();
67 m_mac = 0;
68 }
69 if (m_phy)
70 {
71 m_phy->Clear ();
72 m_phy = 0;
73 }
74 if (m_trans)
75 {
76 m_trans->Clear ();
77 m_trans = 0;
78 }
79}
80
81void
83{
84 m_phy->Initialize ();
85 m_mac->Initialize ();
86 m_channel->Initialize ();
87 m_trans->Initialize ();
88
90}
91
92void
94{
95 Clear ();
97}
98
101{
102 static TypeId tid = TypeId ("ns3::UanNetDevice")
104 .SetGroupName ("Uan")
105 .AddAttribute ("Channel", "The channel attached to this device.",
106 PointerValue (),
108 MakePointerChecker<UanChannel> ())
109 .AddAttribute ("Phy", "The PHY layer attached to this device.",
110 PointerValue (),
112 MakePointerChecker<UanPhy> ())
113 .AddAttribute ("Mac", "The MAC layer attached to this device.",
114 PointerValue (),
116 MakePointerChecker<UanMac> ())
117 .AddAttribute ("Transducer", "The Transducer attached to this device.",
118 PointerValue (),
121 MakePointerChecker<UanTransducer> ())
122 .AddTraceSource ("Rx", "Received payload from the MAC layer.",
124 "ns3::UanNetDevice::RxTxTracedCallback")
125 .AddTraceSource ("Tx", "Send payload to the MAC layer.",
127 "ns3::UanNetDevice::RxTxTracedCallback")
128 ;
129 return tid;
130}
131
132void
134{
135 if (mac != 0)
136 {
137 m_mac = mac;
138 NS_LOG_DEBUG ("Set MAC");
139
140 if (m_phy != 0)
141 {
142 m_phy->SetMac (mac);
143 m_mac->AttachPhy (m_phy);
144 NS_LOG_DEBUG ("Attached MAC to PHY");
145 }
146 m_mac->SetForwardUpCb (MakeCallback (&UanNetDevice::ForwardUp, this));
147 }
148
149}
150
151void
153{
154 if (phy != 0)
155 {
156 m_phy = phy;
157 m_phy->SetDevice (Ptr<UanNetDevice> (this));
158 NS_LOG_DEBUG ("Set PHY");
159 if (m_mac != 0)
160 {
161 m_mac->AttachPhy (phy);
162 m_phy->SetMac (m_mac);
163 NS_LOG_DEBUG ("Attached PHY to MAC");
164 }
165 if (m_trans != 0)
166 {
167 m_phy->SetTransducer (m_trans);
168 NS_LOG_DEBUG ("Added PHY to trans");
169 }
170
171 }
172}
173
174void
176{
177 if (channel != 0)
178 {
180 NS_LOG_DEBUG ("Set CHANNEL");
181 if (m_trans != 0)
182 {
183
184 m_channel->AddDevice (this, m_trans);
185 NS_LOG_DEBUG ("Added self to channel device list");
186 m_trans->SetChannel (m_channel);
187 NS_LOG_DEBUG ("Set Transducer channel");
188 }
189 if (m_phy != 0 )
190 {
191 m_phy->SetChannel (channel);
192 }
193 }
194}
195
198{
199 return m_channel;
200
201}
204{
205 return m_mac;
206}
207
210{
211 return m_phy;
212}
213
214void
216{
217 m_ifIndex = index;
218}
219
222{
223 return m_ifIndex;
224}
225
228{
229 return m_channel;
230}
231
234{
235 return m_mac->GetAddress ();
236}
237
238bool
240{
242 NS_LOG_WARN ("UanNetDevice: MTU is not implemented");
243 m_mtu = mtu;
244 return true;
245}
246
247uint16_t
249{
250 return m_mtu;
251}
252
253bool
255{
256 return (m_linkup && (m_phy != 0));
257}
258
259bool
261{
262 return true;
263}
264
267{
268 return m_mac->GetBroadcast ();
269}
270
271bool
273{
274 return true;
275}
276
278UanNetDevice::GetMulticast ([[maybe_unused]] Ipv4Address multicastGroup) const
279{
280 return m_mac->GetBroadcast ();
281}
282
285{
286 return m_mac->GetBroadcast ();
287}
288
289bool
291{
292 return false;
293}
294bool
296{
297 return false;
298}
299
300bool
301UanNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
302{
303 uint8_t tmp [6];
304 dest.CopyTo (tmp);
305 Mac8Address udest (tmp[0]);
306
307 return m_mac->Enqueue (packet, protocolNumber, udest);
308}
309
310bool
312 [[maybe_unused]] const Address& source,
313 [[maybe_unused]] const Address& dest,
314 [[maybe_unused]] uint16_t protocolNumber)
315{
316 // Not yet implemented
317 NS_ASSERT_MSG (0, "Not yet implemented");
318 return false;
319}
322{
323 return m_node;
324}
325
326void
328{
329 m_node = node;
330}
331
332bool
334{
335 return true;
336}
337
338void
340{
341 m_forwardUp = cb;
342}
343
344void
345UanNetDevice::ForwardUp (Ptr<Packet> pkt, uint16_t protocolNumber, const Mac8Address &src)
346{
347 NS_LOG_DEBUG ("Forwarding packet up to application");
348 m_rxLogger (pkt, src);
349 m_forwardUp (this, pkt, protocolNumber, src);
350
351}
352
355{
356 return m_trans;
357}
358void
360{
361
362 if (trans != 0)
363 {
364 m_trans = trans;
365 NS_LOG_DEBUG ("Set Transducer");
366 if (m_phy != 0)
367 {
368 m_phy->SetTransducer (m_trans);
369 NS_LOG_DEBUG ("Attached Phy to transducer");
370 }
371
372 if (m_channel != 0)
373 {
374 m_channel->AddDevice (this, m_trans);
375 m_trans->SetChannel (m_channel);
376 NS_LOG_DEBUG ("Added self to channel device list");
377 }
378 }
379
380}
381
382void
384{
386}
387
388
389void
391{
392 // Not implemented yet
393 NS_ASSERT_MSG (0, "Not yet implemented");
394}
395
396bool
398{
399 return false;
400}
401
402void
404{
405 NS_ASSERT_MSG (NULL != m_mac, "Tried to set MAC address with no MAC");
406 m_mac->SetAddress (Mac8Address::ConvertFrom (address));
407}
408
409void
411{
412 m_phy->SetSleepMode (sleep);
413}
414
415void
417{
418 m_mac->SetTxModeIndex (txModeIndex);
419}
420
423{
424 return m_mac->GetTxModeIndex ();
425}
426
427} // namespace ns3
428
a polymophic address class
Definition: address.h:91
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:54
Network layer to device interface.
Definition: net-device.h:96
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
virtual Address GetBroadcast(void) const
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
void Clear(void)
Clear all pointer references.
virtual Address GetAddress(void) const
Ptr< UanPhy > GetPhy(void) const
Get the Phy used by this device.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
void SetTxModeIndex(uint32_t txModeIndex)
Set the Tx mode index (Modulation type).
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void SetIfIndex(const uint32_t index)
virtual bool SetMtu(const uint16_t mtu)
UanNetDevice()
Default constructor.
uint32_t m_ifIndex
The interface index of this device.
uint32_t GetTxModeIndex()
Get the Tx mode index (Modulation type).
virtual bool IsBroadcast(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Ptr< UanMac > GetMac(void) const
Get the MAC used by this device.
virtual uint32_t GetIfIndex(void) const
virtual Ptr< Node > GetNode(void) const
virtual bool IsLinkUp(void) const
Ptr< UanChannel > DoGetChannel(void) const
virtual void SetAddress(Address address)
Set the address of this interface.
TracedCallback< Ptr< const Packet >, Mac8Address > m_txLogger
Trace source triggered when sending to the MAC layer.
void SetMac(Ptr< UanMac > mac)
Set the MAC layer for this device.
Ptr< Node > m_node
The node hosting this device.
Ptr< UanTransducer > GetTransducer(void) const
Get the transducer associated with this device.
Ptr< UanPhy > m_phy
The PHY layer attached to this device.
virtual void SetNode(Ptr< Node > node)
static TypeId GetTypeId(void)
Register this type.
virtual bool IsMulticast(void) const
void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
bool m_cleared
Flag when we've been cleared.
virtual void ForwardUp(Ptr< Packet > pkt, uint16_t protocolNumber, const Mac8Address &src)
Forward the packet to a higher level, set with SetReceiveCallback.
Ptr< UanTransducer > m_trans
The Transducer attached to this device.
bool m_linkup
The link state, true if up.
void SetChannel(Ptr< UanChannel > channel)
Attach a channel.
virtual void DoDispose(void)
Destructor implementation.
virtual void DoInitialize(void)
Initialize() implementation.
virtual Ptr< Channel > GetChannel(void) const
virtual uint16_t GetMtu(void) const
TracedCallback m_linkChanges
Callback to invoke when the link state changes to UP.
Ptr< UanChannel > m_channel
The channel attached to this device.
TracedCallback< Ptr< const Packet >, Mac8Address > m_rxLogger
Trace source triggered when forwarding up received payload from the MAC layer.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
void SetTransducer(Ptr< UanTransducer > trans)
Set the transdcuer used by this device.
virtual ~UanNetDevice()
Dummy destructor, DoDispose.
uint16_t m_mtu
The device MTU value, in bytes.
ReceiveCallback m_forwardUp
The receive callback.
virtual bool SupportsSendFrom(void) const
Ptr< UanMac > m_mac
The MAC layer attached to this device.
void SetPhy(Ptr< UanPhy > phy)
Set the Phy layer for this device.
virtual bool NeedsArp(void) const
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
channel
Definition: third.py:92
mac
Definition: third.py:96
phy
Definition: third.py:93