A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-net-device.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "uan-net-device.h"
10
11#include "uan-channel.h"
12#include "uan-mac.h"
13#include "uan-phy.h"
14#include "uan-transducer.h"
15
16#include "ns3/assert.h"
17#include "ns3/log.h"
18#include "ns3/node.h"
19#include "ns3/pointer.h"
20#include "ns3/trace-source-accessor.h"
21#include "ns3/traced-callback.h"
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("UanNetDevice");
27
28NS_OBJECT_ENSURE_REGISTERED(UanNetDevice);
29
31 : NetDevice(),
32 m_mtu(64000),
33 m_cleared(false)
34{
35}
36
40
41void
43{
44 if (m_cleared)
45 {
46 return;
47 }
48 m_cleared = true;
49 m_node = nullptr;
50 if (m_channel)
51 {
52 m_channel->Clear();
53 m_channel = nullptr;
54 }
55 if (m_mac)
56 {
57 m_mac->Clear();
58 m_mac = nullptr;
59 }
60 if (m_phy)
61 {
62 m_phy->Clear();
63 m_phy = nullptr;
64 }
65 if (m_trans)
66 {
67 m_trans->Clear();
68 m_trans = nullptr;
69 }
70}
71
72void
74{
76 m_mac->Initialize();
77 m_channel->Initialize();
79
81}
82
83void
89
92{
93 static TypeId tid =
94 TypeId("ns3::UanNetDevice")
96 .SetGroupName("Uan")
97 .AddAttribute(
98 "Channel",
99 "The channel attached to this device.",
100 PointerValue(),
103 .AddAttribute("Phy",
104 "The PHY layer attached to this device.",
105 PointerValue(),
108 .AddAttribute("Mac",
109 "The MAC layer attached to this device.",
110 PointerValue(),
113 .AddAttribute(
114 "Transducer",
115 "The Transducer attached to this device.",
116 PointerValue(),
119 .AddTraceSource("Rx",
120 "Received payload from the MAC layer.",
122 "ns3::UanNetDevice::RxTxTracedCallback")
123 .AddTraceSource("Tx",
124 "Send payload to the MAC layer.",
126 "ns3::UanNetDevice::RxTxTracedCallback");
127 return tid;
128}
129
130void
132{
133 if (mac)
134 {
135 m_mac = mac;
136 NS_LOG_DEBUG("Set MAC");
137
138 if (m_phy)
139 {
140 m_phy->SetMac(mac);
141 m_mac->AttachPhy(m_phy);
142 NS_LOG_DEBUG("Attached MAC to PHY");
143 }
144 m_mac->SetForwardUpCb(MakeCallback(&UanNetDevice::ForwardUp, this));
145 }
146}
147
148void
150{
151 if (phy)
152 {
153 m_phy = phy;
154 m_phy->SetDevice(Ptr<UanNetDevice>(this));
155 NS_LOG_DEBUG("Set PHY");
156 if (m_mac)
157 {
158 m_mac->AttachPhy(phy);
159 m_phy->SetMac(m_mac);
160 NS_LOG_DEBUG("Attached PHY to MAC");
161 }
162 if (m_trans)
163 {
164 m_phy->SetTransducer(m_trans);
165 NS_LOG_DEBUG("Added PHY to trans");
166 }
167 }
168}
169
170void
172{
173 if (channel)
174 {
175 m_channel = channel;
176 NS_LOG_DEBUG("Set CHANNEL");
177 if (m_trans)
178 {
179 m_channel->AddDevice(this, m_trans);
180 NS_LOG_DEBUG("Added self to channel device list");
182 NS_LOG_DEBUG("Set Transducer channel");
183 }
184 if (m_phy)
185 {
186 m_phy->SetChannel(channel);
187 }
188 }
189}
190
193{
194 return m_channel;
195}
196
199{
200 return m_mac;
201}
202
205{
206 return m_phy;
207}
208
209void
211{
212 m_ifIndex = index;
213}
214
217{
218 return m_ifIndex;
219}
220
223{
224 return m_channel;
225}
226
229{
230 return m_mac->GetAddress();
231}
232
233bool
235{
236 /// \todo Check this in MAC
237 NS_LOG_WARN("UanNetDevice: MTU is not implemented");
238 m_mtu = mtu;
239 return true;
240}
241
242uint16_t
244{
245 return m_mtu;
246}
247
248bool
250{
251 return (m_linkup && m_phy);
252}
253
254bool
256{
257 return true;
258}
259
262{
263 return m_mac->GetBroadcast();
264}
265
266bool
268{
269 return true;
270}
271
273UanNetDevice::GetMulticast(Ipv4Address /* multicastGroup */) const
274{
275 return m_mac->GetBroadcast();
276}
277
280{
281 return m_mac->GetBroadcast();
282}
283
284bool
286{
287 return false;
288}
289
290bool
292{
293 return false;
294}
295
296bool
297UanNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
298{
299 uint8_t tmp[6];
300 dest.CopyTo(tmp);
301 Mac8Address udest(tmp[0]);
302
303 return m_mac->Enqueue(packet, protocolNumber, udest);
304}
305
306bool
308 const Address& /* source */,
309 const Address& /* dest */,
310 uint16_t /* protocolNumber */)
311{
312 // Not yet implemented
313 NS_ASSERT_MSG(false, "Not yet implemented");
314 return false;
315}
316
319{
320 return m_node;
321}
322
323void
325{
326 m_node = node;
327}
328
329bool
331{
332 return true;
333}
334
335void
340
341void
342UanNetDevice::ForwardUp(Ptr<Packet> pkt, uint16_t protocolNumber, const Mac8Address& src)
343{
344 NS_LOG_DEBUG("Forwarding packet up to application");
345 m_rxLogger(pkt, src);
346 m_forwardUp(this, pkt, protocolNumber, src);
347}
348
351{
352 return m_trans;
353}
354
355void
357{
358 if (trans)
359 {
360 m_trans = trans;
361 NS_LOG_DEBUG("Set Transducer");
362 if (m_phy)
363 {
364 m_phy->SetTransducer(m_trans);
365 NS_LOG_DEBUG("Attached Phy to transducer");
366 }
367
368 if (m_channel)
369 {
370 m_channel->AddDevice(this, m_trans);
372 NS_LOG_DEBUG("Added self to channel device list");
373 }
374 }
375}
376
377void
382
383void
385{
386 // Not implemented yet
387 NS_ASSERT_MSG(0, "Not yet implemented");
388}
389
390bool
392{
393 return false;
394}
395
396void
398{
399 NS_ASSERT_MSG(m_mac, "Tried to set MAC address with no MAC");
400 m_mac->SetAddress(Mac8Address::ConvertFrom(address));
401}
402
403void
405{
406 m_phy->SetSleepMode(sleep);
407}
408
409void
411{
412 m_mac->SetTxModeIndex(txModeIndex);
413}
414
417{
418 return m_mac->GetTxModeIndex();
419}
420
421} // namespace ns3
a polymophic address class
Definition address.h:90
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition address.cc:75
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
A class used for addressing MAC8 MAC's.
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Network layer to device interface.
Definition net-device.h:87
void Initialize()
Invoke DoInitialize on all Objects aggregated to this one.
Definition object.cc:203
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:440
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
bool SupportsSendFrom() const override
bool SetMtu(const uint16_t mtu) override
Ptr< UanTransducer > GetTransducer() const
Get the transducer associated with this device.
void SetTxModeIndex(uint32_t txModeIndex)
Set the Tx mode index (Modulation type).
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
Address GetAddress() const override
UanNetDevice()
Default constructor.
uint32_t m_ifIndex
The interface index of this device.
void AddLinkChangeCallback(Callback< void > callback) override
uint32_t GetTxModeIndex()
Get the Tx mode index (Modulation type).
bool IsLinkUp() const override
void DoDispose() override
Destructor implementation.
void DoInitialize() override
Initialize() implementation.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
void Clear()
Clear all pointer references.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
~UanNetDevice() override
Dummy destructor, DoDispose.
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.
bool IsBroadcast() const override
uint32_t GetIfIndex() const override
Ptr< UanPhy > m_phy
The PHY layer attached to this device.
bool IsMulticast() const override
Ptr< Node > GetNode() const override
void SetAddress(Address address) override
Set the address of this interface.
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 SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
bool m_linkup
The link state, true if up.
void SetChannel(Ptr< UanChannel > channel)
Attach a channel.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
void SetNode(Ptr< Node > node) override
Ptr< UanMac > GetMac() const
Get the MAC used by this device.
void SetIfIndex(const uint32_t index) override
TracedCallback m_linkChanges
Callback to invoke when the link state changes to UP.
Ptr< UanChannel > m_channel
The channel attached to this device.
Ptr< Channel > GetChannel() const override
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Ptr< UanChannel > DoGetChannel() const
TracedCallback< Ptr< const Packet >, Mac8Address > m_rxLogger
Trace source triggered when forwarding up received payload from the MAC layer.
uint16_t GetMtu() const override
Address GetBroadcast() const override
void SetTransducer(Ptr< UanTransducer > trans)
Set the transdcuer used by this device.
uint16_t m_mtu
The device MTU value, in bytes.
bool NeedsArp() const override
Ptr< UanPhy > GetPhy() const
Get the Phy used by this device.
ReceiveCallback m_forwardUp
The receive callback.
Ptr< UanMac > m_mac
The MAC layer attached to this device.
static TypeId GetTypeId()
Register this type.
void SetPhy(Ptr< UanPhy > phy)
Set the Phy layer for this device.
virtual void Clear()=0
Clears all pointer references.
virtual void SetChannel(Ptr< UanChannel > chan)=0
Attach this transducer to a channel.
#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:75
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:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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:684