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 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("UanNetDevice");
36 
37 NS_OBJECT_ENSURE_REGISTERED (UanNetDevice);
38 
40  : NetDevice (),
41  m_mtu (64000),
42  m_cleared (false)
43 {
44 }
45 
47 {
48 }
49 
50 void
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 
81 void
83 {
84  m_phy->Initialize ();
85  m_mac->Initialize ();
86  m_channel->Initialize ();
87  m_trans->Initialize ();
88 
90 }
91 
92 void
94 {
95  Clear ();
97 }
98 
99 TypeId
101 {
102  static TypeId tid = TypeId ("ns3::UanNetDevice")
103  .SetParent<NetDevice> ()
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 
132 void
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 
151 void
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 
174 void
176 {
177  if (channel != 0)
178  {
179  m_channel = channel;
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 
214 void
215 UanNetDevice::SetIfIndex (uint32_t index)
216 {
217  m_ifIndex = index;
218 }
219 
220 uint32_t
222 {
223  return m_ifIndex;
224 }
225 
228 {
229  return m_channel;
230 }
231 
232 Address
234 {
235  return m_mac->GetAddress ();
236 }
237 
238 bool
239 UanNetDevice::SetMtu (uint16_t mtu)
240 {
242  NS_LOG_WARN ("UanNetDevice: MTU is not implemented");
243  m_mtu = mtu;
244  return true;
245 }
246 
247 uint16_t
249 {
250  return m_mtu;
251 }
252 
253 bool
255 {
256  return (m_linkup && (m_phy != 0));
257 }
258 
259 bool
261 {
262  return true;
263 }
264 
265 Address
267 {
268  return m_mac->GetBroadcast ();
269 }
270 
271 bool
273 {
274  return false;
275 }
276 
277 Address
279 {
280  NS_FATAL_ERROR ("UanNetDevice does not support multicast");
281  return m_mac->GetBroadcast ();
282 }
283 
284 Address
286 {
287  NS_FATAL_ERROR ("UanNetDevice does not support multicast");
288  return m_mac->GetBroadcast ();
289 }
290 
291 bool
293 {
294  return false;
295 }
296 bool
298 {
299  return false;
300 }
301 
302 bool
303 UanNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
304 {
305  return m_mac->Enqueue (packet, dest, protocolNumber);
306 }
307 
308 bool
309 UanNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
310 {
311  // Not yet implemented
312  NS_ASSERT_MSG (0, "Not yet implemented");
313  return false;
314 }
315 Ptr<Node>
317 {
318  return m_node;
319 }
320 
321 void
323 {
324  m_node = node;
325 }
326 
327 bool
329 {
330  return false;
331 }
332 
333 void
335 {
336  m_forwardUp = cb;
337 }
338 
339 void
341 {
342  NS_LOG_DEBUG ("Forwarding packet up to application");
343  m_rxLogger (pkt, src);
344  m_forwardUp (this, pkt, 0, src);
345 
346 }
347 
350 {
351  return m_trans;
352 }
353 void
355 {
356 
357  if (trans != 0)
358  {
359  m_trans = trans;
360  NS_LOG_DEBUG ("Set Transducer");
361  if (m_phy != 0)
362  {
363  m_phy->SetTransducer (m_trans);
364  NS_LOG_DEBUG ("Attached Phy to transducer");
365  }
366 
367  if (m_channel != 0)
368  {
369  m_channel->AddDevice (this, m_trans);
370  m_trans->SetChannel (m_channel);
371  NS_LOG_DEBUG ("Added self to channel device list");
372  }
373  }
374 
375 }
376 
377 void
379 {
381 }
382 
383 
384 void
386 {
387  // Not implemented yet
388  NS_ASSERT_MSG (0, "Not yet implemented");
389 }
390 
391 bool
393 {
394  return false;
395 }
396 
397 void
399 {
400  NS_ASSERT_MSG (0, "Tried to set MAC address with no MAC");
401  m_mac->SetAddress (UanAddress::ConvertFrom (address));
402 }
403 
404 void
406 {
407  m_phy->SetSleepMode (sleep);
408 }
409 
410 } // namespace ns3
411 
tuple channel
Definition: third.py:85
virtual bool SetMtu(const uint16_t mtu)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
Ptr< UanMac > GetMac(void) const
Get the MAC used by this device.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetMac(Ptr< UanMac > mac)
Set the MAC layer for this device.
virtual void SetAddress(Address address)
Set the address of this interface.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool m_linkup
The link state, true if up.
void SetChannel(Ptr< UanChannel > channel)
Attach a channel.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual bool IsMulticast(void) const
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual bool IsLinkUp(void) const
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual uint16_t GetMtu(void) const
virtual Ptr< Channel > GetChannel(void) const
Ptr< Node > m_node
The node hosting this device.
Ptr< UanTransducer > m_trans
The Transducer attached to this device.
virtual Address GetBroadcast(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.
Ptr< UanTransducer > GetTransducer(void) const
Get the transducer associated with this device.
ReceiveCallback m_forwardUp
The receive callback.
uint16_t m_mtu
The device MTU value, in bytes.
virtual void AddLinkChangeCallback(Callback< void > callback)
tuple phy
Definition: third.py:86
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:220
virtual uint32_t GetIfIndex(void) const
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
static UanAddress ConvertFrom(const Address &address)
Convert a generic address to a UanAddress.
Definition: uan-address.cc:54
virtual void ForwardUp(Ptr< Packet > pkt, const UanAddress &src)
Forward the packet to a higher level, set with SetReceiveCallback.
virtual void DoInitialize(void)
Initialize() implementation.
TracedCallback m_linkChanges
Callback to invoke when the link state changes to UP.
Ptr< UanPhy > m_phy
The PHY layer attached to this device.
virtual Ptr< Node > GetNode(void) const
TracedCallback< Ptr< const Packet >, UanAddress > m_rxLogger
Trace source triggered when forwarding up received payload from the MAC layer.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
virtual void DoDispose(void)
Destructor implementation.
UanNetDevice()
Default constructor.
tuple mac
Definition: third.py:92
virtual bool IsBroadcast(void) const
Ptr< UanMac > m_mac
The MAC layer attached to this device.
static TypeId GetTypeId(void)
Register this type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr.
Definition: pointer.h:36
virtual bool SupportsSendFrom(void) const
TracedCallback< Ptr< const Packet >, UanAddress > m_txLogger
Trace source triggered when sending to the MAC layer.
Ptr< UanPhy > GetPhy(void) const
Get the Phy used by this device.
#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:90
virtual Address GetAddress(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
void SetPhy(Ptr< UanPhy > phy)
Set the Phy layer for this device.
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
bool m_cleared
Flag when we've been cleared.
Network layer to device interface.
Definition: net-device.h:95
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Ptr< UanChannel > m_channel
The channel attached to this device.
virtual void SetNode(Ptr< Node > node)
void SetTransducer(Ptr< UanTransducer > trans)
Set the transdcuer used by this device.
virtual ~UanNetDevice()
Dummy destructor, DoDispose.
virtual bool NeedsArp(void) const
Ptr< UanChannel > DoGetChannel(void) const
tuple address
Definition: first.py:37
uint32_t m_ifIndex
The interface index of this device.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
void Clear(void)
Clear all pointer references.
virtual void SetIfIndex(const uint32_t index)