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  Clear ();
86 }
87 
88 TypeId
90 {
91  static TypeId tid = TypeId ("ns3::UanNetDevice")
92  .SetParent<NetDevice> ()
93  .SetGroupName ("Uan")
94  .AddAttribute ("Channel", "The channel attached to this device.",
95  PointerValue (),
97  MakePointerChecker<UanChannel> ())
98  .AddAttribute ("Phy", "The PHY layer attached to this device.",
99  PointerValue (),
101  MakePointerChecker<UanPhy> ())
102  .AddAttribute ("Mac", "The MAC layer attached to this device.",
103  PointerValue (),
105  MakePointerChecker<UanMac> ())
106  .AddAttribute ("Transducer", "The Transducer attached to this device.",
107  PointerValue (),
110  MakePointerChecker<UanTransducer> ())
111  .AddTraceSource ("Rx", "Received payload from the MAC layer.",
113  "ns3::UanNetDevice::RxTxTracedCallback")
114  .AddTraceSource ("Tx", "Send payload to the MAC layer.",
116  "ns3::UanNetDevice::RxTxTracedCallback")
117  ;
118  return tid;
119 }
120 
121 void
123 {
124  if (mac != 0)
125  {
126  m_mac = mac;
127  NS_LOG_DEBUG ("Set MAC");
128 
129  if (m_phy != 0)
130  {
131  m_phy->SetMac (mac);
132  m_mac->AttachPhy (m_phy);
133  NS_LOG_DEBUG ("Attached MAC to PHY");
134  }
135  m_mac->SetForwardUpCb (MakeCallback (&UanNetDevice::ForwardUp, this));
136  }
137 
138 }
139 
140 void
142 {
143  if (phy != 0)
144  {
145  m_phy = phy;
146  m_phy->SetDevice (Ptr<UanNetDevice> (this));
147  NS_LOG_DEBUG ("Set PHY");
148  if (m_mac != 0)
149  {
150  m_mac->AttachPhy (phy);
151  m_phy->SetMac (m_mac);
152  NS_LOG_DEBUG ("Attached PHY to MAC");
153  }
154  if (m_trans != 0)
155  {
156  m_phy->SetTransducer (m_trans);
157  NS_LOG_DEBUG ("Added PHY to trans");
158  }
159 
160  }
161 }
162 
163 void
165 {
166  if (channel != 0)
167  {
168  m_channel = channel;
169  NS_LOG_DEBUG ("Set CHANNEL");
170  if (m_trans != 0)
171  {
172 
173  m_channel->AddDevice (this, m_trans);
174  NS_LOG_DEBUG ("Added self to channel device list");
175  m_trans->SetChannel (m_channel);
176  NS_LOG_DEBUG ("Set Transducer channel");
177  }
178  if (m_phy != 0 )
179  {
180  m_phy->SetChannel (channel);
181  }
182  }
183 }
184 
187 {
188  return m_channel;
189 
190 }
193 {
194  return m_mac;
195 }
196 
199 {
200  return m_phy;
201 }
202 
203 void
204 UanNetDevice::SetIfIndex (uint32_t index)
205 {
206  m_ifIndex = index;
207 }
208 
209 uint32_t
211 {
212  return m_ifIndex;
213 }
214 
217 {
218  return m_channel;
219 }
220 
221 Address
223 {
224  return m_mac->GetAddress ();
225 }
226 
227 bool
228 UanNetDevice::SetMtu (uint16_t mtu)
229 {
231  NS_LOG_WARN ("UanNetDevice: MTU is not implemented");
232  m_mtu = mtu;
233  return true;
234 }
235 
236 uint16_t
238 {
239  return m_mtu;
240 }
241 
242 bool
244 {
245  return (m_linkup && (m_phy != 0));
246 }
247 
248 bool
250 {
251  return true;
252 }
253 
254 Address
256 {
257  return m_mac->GetBroadcast ();
258 }
259 
260 bool
262 {
263  return false;
264 }
265 
266 Address
268 {
269  NS_FATAL_ERROR ("UanNetDevice does not support multicast");
270  return m_mac->GetBroadcast ();
271 }
272 
273 Address
275 {
276  NS_FATAL_ERROR ("UanNetDevice does not support multicast");
277  return m_mac->GetBroadcast ();
278 }
279 
280 bool
282 {
283  return false;
284 }
285 bool
287 {
288  return false;
289 }
290 
291 bool
292 UanNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
293 {
294  return m_mac->Enqueue (packet, dest, protocolNumber);
295 }
296 
297 bool
298 UanNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
299 {
300  // Not yet implemented
301  NS_ASSERT_MSG (0, "Not yet implemented");
302  return false;
303 }
304 Ptr<Node>
306 {
307  return m_node;
308 }
309 
310 void
312 {
313  m_node = node;
314 }
315 
316 bool
318 {
319  return false;
320 }
321 
322 void
324 {
325  m_forwardUp = cb;
326 }
327 
328 void
330 {
331  NS_LOG_DEBUG ("Forwarding packet up to application");
332  m_rxLogger (pkt, src);
333  m_forwardUp (this, pkt, 0, src);
334 
335 }
336 
339 {
340  return m_trans;
341 }
342 void
344 {
345 
346  if (trans != 0)
347  {
348  m_trans = trans;
349  NS_LOG_DEBUG ("Set Transducer");
350  if (m_phy != 0)
351  {
352  m_phy->SetTransducer (m_trans);
353  NS_LOG_DEBUG ("Attached Phy to transducer");
354  }
355 
356  if (m_channel != 0)
357  {
358  m_channel->AddDevice (this, m_trans);
359  m_trans->SetChannel (m_channel);
360  NS_LOG_DEBUG ("Added self to channel device list");
361  }
362  }
363 
364 }
365 
366 void
368 {
370 }
371 
372 
373 void
375 {
376  // Not implemented yet
377  NS_ASSERT_MSG (0, "Not yet implemented");
378 }
379 
380 bool
382 {
383  return false;
384 }
385 
386 void
388 {
389  NS_ASSERT_MSG (0, "Tried to set MAC address with no MAC");
390  m_mac->SetAddress (UanAddress::ConvertFrom (address));
391 }
392 
393 void
395 {
396  m_phy->SetSleepMode (sleep);
397 }
398 
399 } // namespace ns3
400 
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)
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:44
bool m_linkup
The link state, true if up.
virtual void DoDispose()
Destructor implementation.
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.
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
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:405
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
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:236
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:904
void Clear(void)
Clear all pointer references.
virtual void SetIfIndex(const uint32_t index)