A Discrete-Event Network Simulator
API
fd-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) 2012 INRIA, 2012 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: Alina Quereilhac <alina.quereilhac@inria.fr>
19  * Claudio Freire <klaussfreire@sourceforge.net>
20  */
21 
22 #include "fd-net-device.h"
23 
24 #include "ns3/abort.h"
25 #include "ns3/boolean.h"
26 #include "ns3/channel.h"
27 #include "ns3/enum.h"
28 #include "ns3/ethernet-header.h"
29 #include "ns3/ethernet-trailer.h"
30 #include "ns3/log.h"
31 #include "ns3/llc-snap-header.h"
32 #include "ns3/mac48-address.h"
33 #include "ns3/pointer.h"
34 #include "ns3/simulator.h"
35 #include "ns3/string.h"
36 #include "ns3/trace-source-accessor.h"
37 #include "ns3/uinteger.h"
38 
39 #include <unistd.h>
40 #include <arpa/inet.h>
41 #include <net/ethernet.h>
42 
43 namespace ns3 {
44 
45 NS_LOG_COMPONENT_DEFINE ("FdNetDevice");
46 
48  : m_bufferSize (65536) // Defaults to maximum TCP window size
49 {
50 }
51 
52 void
54 {
55  m_bufferSize = bufferSize;
56 }
57 
59 {
60  NS_LOG_FUNCTION (this);
61 
62  uint8_t *buf = (uint8_t *)malloc (m_bufferSize);
63  NS_ABORT_MSG_IF (buf == 0, "malloc() failed");
64 
65  NS_LOG_LOGIC ("Calling read on fd " << m_fd);
66  ssize_t len = read (m_fd, buf, m_bufferSize);
67  if (len <= 0)
68  {
69  free (buf);
70  buf = 0;
71  len = 0;
72  }
73 
74  return FdReader::Data (buf, len);
75 }
76 
78 
79 TypeId
81 {
82  static TypeId tid = TypeId ("ns3::FdNetDevice")
83  .SetParent<NetDevice> ()
84  .AddConstructor<FdNetDevice> ()
85  .AddAttribute ("Address",
86  "The MAC address of this device.",
87  Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")),
90  .AddAttribute ("Start",
91  "The simulation time at which to spin up "
92  "the device thread.",
93  TimeValue (Seconds (0.)),
95  MakeTimeChecker ())
96  .AddAttribute ("Stop",
97  "The simulation time at which to tear down "
98  "the device thread.",
99  TimeValue (Seconds (0.)),
101  MakeTimeChecker ())
102  .AddAttribute ("EncapsulationMode",
103  "The link-layer encapsulation type to use.",
104  EnumValue (DIX),
106  MakeEnumChecker (DIX, "Dix",
107  LLC, "Llc",
108  DIXPI, "DixPi"))
109  .AddAttribute ("RxQueueSize", "Maximum size of the read queue. "
110  "This value limits number of packets that have been read "
111  "from the network into a memory buffer but have not yet "
112  "been processed by the simulator.",
113  UintegerValue (1000),
115  MakeUintegerChecker<uint32_t> ())
116  //
117  // Trace sources at the "top" of the net device, where packets transition
118  // to/from higher layers. These points do not really correspond to the
119  // MAC layer of the underlying operating system, but exist to provide
120  // a consitent tracing environment. These trace hooks should really be
121  // interpreted as the points at which a packet leaves the ns-3 environment
122  // destined for the underlying operating system or vice-versa.
123  //
124  .AddTraceSource ("MacTx",
125  "Trace source indicating a packet has "
126  "arrived for transmission by this device",
128  "ns3::Packet::TracedCallback")
129  .AddTraceSource ("MacTxDrop",
130  "Trace source indicating a packet has "
131  "been dropped by the device before transmission",
133  "ns3::Packet::TracedCallback")
134  .AddTraceSource ("MacPromiscRx",
135  "A packet has been received by this device, "
136  "has been passed up from the physical layer "
137  "and is being forwarded up the local protocol stack. "
138  "This is a promiscuous trace,",
140  "ns3::Packet::TracedCallback")
141  .AddTraceSource ("MacRx",
142  "A packet has been received by this device, "
143  "has been passed up from the physical layer "
144  "and is being forwarded up the local protocol stack. "
145  "This is a non-promiscuous trace,",
147  "ns3::Packet::TracedCallback")
148 
149  //
150  // Trace sources designed to simulate a packet sniffer facility (tcpdump).
151  //
152  .AddTraceSource ("Sniffer",
153  "Trace source simulating a non-promiscuous "
154  "packet sniffer attached to the device",
156  "ns3::Packet::TracedCallback")
157  .AddTraceSource ("PromiscSniffer",
158  "Trace source simulating a promiscuous "
159  "packet sniffer attached to the device",
161  "ns3::Packet::TracedCallback")
162  ;
163  return tid;
164 }
165 
167  : m_node (0),
168  m_ifIndex (0),
169  m_mtu (1500), // Defaults to Ethernet v2 MTU
170  m_fd (-1),
171  m_fdReader (0),
172  m_isBroadcast (true),
173  m_isMulticast (false),
174  m_pendingReadCount (0),
175  m_startEvent (),
176  m_stopEvent ()
177 {
178  NS_LOG_FUNCTION (this);
179  Start (m_tStart);
180 }
181 
183 {
184 }
185 
187 {
188  NS_LOG_FUNCTION (this);
189 }
190 
191 void
193 {
194  NS_LOG_FUNCTION (this);
195  StopDevice ();
197 }
198 
199 void
201 {
202  NS_LOG_FUNCTION (mode);
203  m_encapMode = mode;
204  NS_LOG_LOGIC ("m_encapMode = " << m_encapMode);
205 }
206 
209 {
210  NS_LOG_FUNCTION (this);
211  return m_encapMode;
212 }
213 
214 void
216 {
217  NS_LOG_FUNCTION (tStart);
220 }
221 
222 void
224 {
225  NS_LOG_FUNCTION (tStop);
228 }
229 
230 void
232 {
233  NS_LOG_FUNCTION (this);
234 
235  if (m_fd == -1)
236  {
237  NS_LOG_DEBUG ("FdNetDevice::Start(): Failure, invalid file descriptor.");
238  return;
239  }
240  //
241  // A similar story exists for the node ID. We can't just naively do a
242  // GetNode ()->GetId () since GetNode is going to give us a Ptr<Node> which
243  // is reference counted. We need to stash away the node ID for use in the
244  // read thread.
245  //
246  m_nodeId = GetNode ()->GetId ();
247 
248  m_fdReader = Create<FdNetDeviceFdReader> ();
249  m_fdReader->SetBufferSize(m_mtu);
251 
252  NotifyLinkUp ();
253 }
254 
255 void
257 {
258  NS_LOG_FUNCTION (this);
259 
260  if (m_fdReader != 0)
261  {
262  m_fdReader->Stop ();
263  m_fdReader = 0;
264  }
265 
266  if (m_fd != -1)
267  {
268  close (m_fd);
269  m_fd = -1;
270  }
271 }
272 
273 void
274 FdNetDevice::ReceiveCallback (uint8_t *buf, ssize_t len)
275 {
276  NS_LOG_FUNCTION (this << buf << len);
277  bool skip = false;
278 
279  {
282  {
283  //XXX: Packet dropped!
284  skip = true;
285  }
286  else
287  {
289  }
290  }
291 
292  if (skip)
293  {
294  struct timespec time = { 0, 100000000L }; // 100 ms
295  nanosleep (&time, NULL);
296  }
297  else
298  {
300  }
301 }
302 
306 static void
307 AddPIHeader (uint8_t *&buf, ssize_t &len)
308 {
309  // Synthesize PI header for our friend the kernel
310  uint8_t *buf2 = (uint8_t*)malloc (len + 4);
311  memcpy (buf2 + 4, buf, len);
312  len += 4;
313 
314  // PI = 16 bits flags (0) + 16 bits proto
315  // NOTE: be careful to interpret buffer data explicitly as
316  // little-endian to be insensible to native byte ordering.
317  uint16_t flags = 0;
318  uint16_t proto = 0x0008; // default to IPv4
319  if (len > 14)
320  {
321  if (buf[12] == 0x81 && buf[13] == 0x00 && len > 18)
322  {
323  // tagged ethernet packet
324  proto = buf[16] | (buf[17] << 8);
325  }
326  else
327  {
328  // untagged ethernet packet
329  proto = buf[12] | (buf[13] << 8);
330  }
331  }
332  buf2[0] = (uint8_t)flags;
333  buf2[1] = (uint8_t)(flags >> 8);
334  buf2[2] = (uint8_t)proto;
335  buf2[3] = (uint8_t)(proto >> 8);
336 
337  // swap buffer
338  free (buf);
339  buf = buf2;
340 }
341 
342 static void
343 RemovePIHeader (uint8_t *&buf, ssize_t &len)
344 {
345  // strip PI header if present, shrink buffer
346  if (len >= 4)
347  {
348  len -= 4;
349  memmove (buf, buf + 4, len);
350  buf = (uint8_t*)realloc (buf, len);
351  }
352 }
353 
354 void
355 FdNetDevice::ForwardUp (uint8_t *buf, ssize_t len)
356 {
357  NS_LOG_FUNCTION (this << buf << len);
358 
359  if (m_pendingReadCount > 0)
360  {
361  {
364  }
365  }
366 
367  // We need to remove the PI header and ignore it
368  if (m_encapMode == DIXPI)
369  {
370  RemovePIHeader (buf, len);
371  }
372 
373  //
374  // Create a packet out of the buffer we received and free that buffer.
375  //
376  Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len);
377  free (buf);
378  buf = 0;
379 
380  //
381  // Trace sinks will expect complete packets, not packets without some of the
382  // headers
383  //
384  Ptr<Packet> originalPacket = packet->Copy ();
385 
386  Mac48Address destination;
387  Mac48Address source;
388  uint16_t protocol;
389  bool isBroadcast = false;
390  bool isMulticast = false;
391 
392  EthernetHeader header (false);
393 
394  //
395  // This device could be running in an environment where completely unexpected
396  // kinds of packets are flying around, so we need to harden things a bit and
397  // filter out packets we think are completely bogus, so we always check to see
398  // that the packet is long enough to contain the header we want to remove.
399  //
400  if (packet->GetSize () < header.GetSerializedSize ())
401  {
402  m_phyRxDropTrace (originalPacket);
403  return;
404  }
405 
406  packet->RemoveHeader (header);
407  destination = header.GetDestination ();
408  source = header.GetSource ();
409  isBroadcast = header.GetDestination ().IsBroadcast ();
410  isMulticast = header.GetDestination ().IsGroup ();
411  protocol = header.GetLengthType ();
412 
413  //
414  // If the length/type is less than 1500, it corresponds to a length
415  // interpretation packet. In this case, it is an 802.3 packet and
416  // will also have an 802.2 LLC header. If greater than 1500, we
417  // find the protocol number (Ethernet type) directly.
418  //
419  if (m_encapMode == LLC and header.GetLengthType () <= 1500)
420  {
421  LlcSnapHeader llc;
422  //
423  // Check to see that the packet is long enough to possibly contain the
424  // header we want to remove before just naively calling.
425  //
426  if (packet->GetSize () < llc.GetSerializedSize ())
427  {
428  m_phyRxDropTrace (originalPacket);
429  return;
430  }
431 
432  packet->RemoveHeader (llc);
433  protocol = llc.GetType ();
434  }
435 
436  NS_LOG_LOGIC ("Pkt source is " << source);
437  NS_LOG_LOGIC ("Pkt destination is " << destination);
438 
439  PacketType packetType;
440 
441  if (isBroadcast)
442  {
443  packetType = NS3_PACKET_BROADCAST;
444  }
445  else if (isMulticast)
446  {
447  packetType = NS3_PACKET_MULTICAST;
448  }
449  else if (destination == m_address)
450  {
451  packetType = NS3_PACKET_HOST;
452  }
453  else
454  {
455  packetType = NS3_PACKET_OTHERHOST;
456  }
457 
458  //
459  // For all kinds of packetType we receive, we hit the promiscuous sniffer
460  // hook and pass a copy up to the promiscuous callback. Pass a copy to
461  // make sure that nobody messes with our packet.
462  //
463  m_promiscSnifferTrace (originalPacket);
464 
465  if (!m_promiscRxCallback.IsNull ())
466  {
467  m_macPromiscRxTrace (originalPacket);
468  m_promiscRxCallback (this, packet, protocol, source, destination,
469  packetType);
470  }
471 
472  //
473  // If this packet is not destined for some other host, it must be for us
474  // as either a broadcast, multicast or unicast. We need to hit the mac
475  // packet received trace hook and forward the packet up the stack.
476  //
477  if (packetType != NS3_PACKET_OTHERHOST)
478  {
479  m_snifferTrace (originalPacket);
480  m_macRxTrace (originalPacket);
481  m_rxCallback (this, packet, protocol, source);
482  }
483 }
484 
485 bool
486 FdNetDevice::Send (Ptr<Packet> packet, const Address& destination, uint16_t protocolNumber)
487 {
488  NS_LOG_FUNCTION (this << packet << destination << protocolNumber);
489  return SendFrom (packet, m_address, destination, protocolNumber);
490 }
491 
492 bool
493 FdNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
494 {
495  NS_LOG_FUNCTION (this << packet << src << dest << protocolNumber);
496  NS_LOG_LOGIC ("packet " << packet);
497  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
498 
499  if (IsLinkUp () == false)
500  {
501  m_macTxDropTrace (packet);
502  return false;
503  }
504 
505  Mac48Address destination = Mac48Address::ConvertFrom (dest);
507 
508  NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ());
509  NS_LOG_LOGIC ("Transmit packet from " << source);
510  NS_LOG_LOGIC ("Transmit packet to " << destination);
511 
512  EthernetHeader header (false);
513  header.SetSource (source);
514  header.SetDestination (destination);
515 
516  if (m_encapMode == LLC)
517  {
518  LlcSnapHeader llc;
519  llc.SetType (protocolNumber);
520  packet->AddHeader (llc);
521 
522  header.SetLengthType (packet->GetSize ());
523  }
524  else
525  {
526  header.SetLengthType (protocolNumber);
527  }
528 
529  packet->AddHeader (header);
530 
531  //
532  // there's not much meaning associated with the different layers in this
533  // device, so don't be surprised when they're all stacked together in
534  // essentially one place. We do this for trace consistency across devices.
535  //
536  m_macTxTrace (packet);
537 
538  m_promiscSnifferTrace (packet);
539  m_snifferTrace (packet);
540 
541  NS_LOG_LOGIC ("calling write");
542 
543  NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet too big " << packet->GetSize ());
544 
545  ssize_t len = (ssize_t) packet->GetSize ();
546  uint8_t *buffer = (uint8_t*)malloc (len);
547  packet->CopyData (buffer, len);
548 
549  // We need to add the PI header
550  if (m_encapMode == DIXPI)
551  {
552  AddPIHeader (buffer, len);
553  }
554 
555  ssize_t written = write (m_fd, buffer, len);
556  free (buffer);
557 
558  if (written == -1 || written != len)
559  {
560  m_macTxDropTrace (packet);
561  return false;
562  }
563 
564  return true;
565 }
566 
567 void
569 {
570  if (m_fd == -1 and fd > 0)
571  {
572  m_fd = fd;
573  }
574 }
575 
576 void
578 {
580 }
581 
582 Address
584 {
585  return m_address;
586 }
587 
588 void
590 {
591  m_linkUp = true;
593 }
594 
595 void
596 FdNetDevice::SetIfIndex (const uint32_t index)
597 {
598  m_ifIndex = index;
599 }
600 
601 uint32_t
603 {
604  return m_ifIndex;
605 }
606 
609 {
610  return NULL;
611 }
612 
613 bool
614 FdNetDevice::SetMtu (const uint16_t mtu)
615 {
616  // The MTU depends on the technology associated to
617  // the file descriptor. The user is responsible of
618  // setting the correct value of the MTU.
619  // If the file descriptor is created using a helper,
620  // then is the responsibility of the helper to set
621  // the correct MTU value.
622  m_mtu = mtu;
623  return true;
624 }
625 
626 uint16_t
628 {
629  return m_mtu;
630 }
631 
632 bool
634 {
635  return m_linkUp;
636 }
637 
638 void
640 {
642 }
643 
644 bool
646 {
647  return m_isBroadcast;
648 }
649 
650 void
652 {
653  m_isBroadcast = broadcast;
654 }
655 
656 Address
658 {
659  return Mac48Address ("ff:ff:ff:ff:ff:ff");
660 }
661 
662 bool
664 {
665  return m_isMulticast;
666 }
667 
668 void
670 {
671  m_isMulticast = multicast;
672 }
673 
674 Address
676 {
677  return Mac48Address::GetMulticast (multicastGroup);
678 }
679 
680 Address
682 {
683  return Mac48Address::GetMulticast (addr);
684 }
685 
686 bool
688 {
689  return false;
690 }
691 
692 bool
694 {
695  return false;
696 }
697 
698 Ptr<Node>
700 {
701  return m_node;
702 }
703 
704 void
706 {
707  m_node = node;
708 }
709 
710 bool
712 {
713  return true;
714 }
715 
716 void
718 {
719  m_rxCallback = cb;
720 }
721 
722 void
724 {
725  m_promiscRxCallback = cb;
726 }
727 
728 bool
730 {
731  return true;
732 }
733 
734 } // namespace ns3
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
void StopDevice(void)
Tear down the device.
A structure representing data read.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint16_t m_mtu
The MTU associated to the file descriptor technology.
void ForwardUp(uint8_t *buf, ssize_t len)
Forward the frame to the appropriate callback for processing.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void SetFileDescriptor(int fd)
Set the associated file descriptor.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool SupportsSendFrom() const
EncapsulationMode m_encapMode
The typ of encapsulation of the received/transmited frames.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
virtual bool NeedsArp(void) const
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:380
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1072
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
DIX II / Ethernet II packet.
Definition: fd-net-device.h:92
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:272
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint16_t GetLengthType(void) const
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
bool IsBroadcast(void) const
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device at the L3/L2 transition are d...
static void RemovePIHeader(uint8_t *&buf, ssize_t &len)
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
Ptr< const AttributeChecker > MakeMac48AddressChecker(void)
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:311
Time m_tStart
Time to start spinning up the device.
virtual bool IsMulticast(void) const
void SetType(uint16_t type)
Set the Ethertype.
Ptr< FdNetDeviceFdReader > m_fdReader
Reader for the file descriptor.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
void Stop(Time tStop)
Set a stop time for the device.
virtual void SetIsBroadcast(bool broadcast)
virtual uint32_t GetIfIndex(void) const
void SetSource(Mac48Address source)
Ptr< const AttributeAccessor > MakeMac48AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void SetIfIndex(const uint32_t index)
a polymophic address class
Definition: address.h:90
void NotifyLinkUp(void)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual Ptr< Node > GetNode(void) const
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:439
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
Hold variables of type enum.
Definition: enum.h:54
virtual Ptr< Channel > GetChannel(void) const
static Mac48Address GetMulticast(Ipv4Address address)
AttributeValue implementation for Time.
Definition: nstime.h:921
uint16_t GetType(void)
Return the Ethertype.
int m_fd
The file descriptor to read from.
virtual void SetIsMulticast(bool multicast)
A class which provides a simple way to implement a Critical Section.
Definition: system-mutex.h:118
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
uint32_t m_maxPendingReads
Maximum number of packets that can be received and scheduled for read but not yeat read...
virtual Address GetBroadcast(void) const
FdNetDeviceFdReader()
Constructor for the FdNetDevice.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
void StartDevice(void)
Spin up the device.
void ReceiveCallback(uint8_t *buf, ssize_t len)
Callback to invoke when a new frame is received.
802.2 LLC/SNAP Packet
Definition: fd-net-device.h:93
Ptr< Node > m_node
The ns-3 node associated to the net device.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:899
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
virtual bool IsLinkUp(void) const
static Mac48Address ConvertFrom(const Address &address)
void SetEncapsulationMode(FdNetDevice::EncapsulationMode mode)
Set the link layer encapsulation mode of this device.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
int m_fd
The file descriptor used for receive/send network traffic.
TracedCallback m_linkChangeCallbacks
Callbacks to fire if the link changes state (up or down).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
bool IsGroup(void) const
virtual bool IsBroadcast(void) const
virtual void SetNode(Ptr< Node > node)
an EUI-48 address
Definition: mac48-address.h:43
Packet header for Ethernet.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:922
When using TAP devices, if flag IFF_NO_PI is not set on the device, IP packets will have an extra hea...
Definition: fd-net-device.h:94
FdReader::Data DoRead(void)
The read implementation.
FdNetDevice::EncapsulationMode GetEncapsulationMode(void) const
Get the link layer encapsulation mode of 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:84
Mac48Address GetSource(void) const
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
uint32_t m_pendingReadCount
Number of packets that were received and scheduled for read but not yeat read.
virtual bool SetMtu(const uint16_t mtu)
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
Describes an IPv6 address.
Definition: ipv6-address.h:47
Mac48Address GetDestination(void) const
uint32_t m_ifIndex
The ns-3 interface index (in the sense of net device index) that has been assigned to this network de...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
static TypeId GetTypeId(void)
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
uint32_t GetId(void) const
Definition: node.cc:106
virtual Address GetAddress(void) const
Network layer to device interface.
Definition: net-device.h:75
AttributeValue implementation for Mac48Address.
virtual void SetAddress(Address address)
Set the address of this interface.
virtual uint32_t GetSerializedSize(void) const
void Start(Time tStart)
Set a start time for the device.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
virtual uint32_t GetSerializedSize(void) const
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode...
void SetLengthType(uint16_t size)
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:368
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:82
tuple address
Definition: first.py:37
Mac48Address m_address
The net device mac address.
bool m_isBroadcast
Flag indicating whether or not the underlying net device supports broadcast.
static void AddPIHeader(uint8_t *&buf, ssize_t &len)
EncapsulationMode
Enumeration of the types of frames supported in the class.
Definition: fd-net-device.h:90
virtual uint16_t GetMtu(void) const
void SetDestination(Mac48Address destination)
virtual void DoDispose(void)
Destructor implementation.
bool m_linkUp
Flag indicating whether or not the link is up.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:51
FdNetDevice()
Constructor for the FdNetDevice.
virtual ~FdNetDevice()
Destructor for the FdNetDevice.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
bool m_isMulticast
Flag indicating whether or not the underlying net device supports multicast.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Time m_tStop
Time to start tearing down the device.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
Header for the LLC/SNAP encapsulation.
SystemMutex m_pendingReadMutex
Mutex to increase pending read counter.
EventImpl * MakeEvent(void(*f)(void))
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:34