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  NS_LOG_FUNCTION (this << bufferSize);
56  m_bufferSize = bufferSize;
57 }
58 
60 {
61  NS_LOG_FUNCTION (this);
62 
63  uint8_t *buf = (uint8_t *)malloc (m_bufferSize);
64  NS_ABORT_MSG_IF (buf == 0, "malloc() failed");
65 
66  NS_LOG_LOGIC ("Calling read on fd " << m_fd);
67  ssize_t len = read (m_fd, buf, m_bufferSize);
68  if (len <= 0)
69  {
70  free (buf);
71  buf = 0;
72  len = 0;
73  }
74  NS_LOG_LOGIC ("Read " << len << " bytes on fd " << m_fd);
75  return FdReader::Data (buf, len);
76 }
77 
79 
80 TypeId
82 {
83  static TypeId tid = TypeId ("ns3::FdNetDevice")
84  .SetParent<NetDevice> ()
85  .SetGroupName ("FdNetDevice")
86  .AddConstructor<FdNetDevice> ()
87  .AddAttribute ("Address",
88  "The MAC address of this device.",
89  Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")),
92  .AddAttribute ("Start",
93  "The simulation time at which to spin up "
94  "the device thread.",
95  TimeValue (Seconds (0.)),
97  MakeTimeChecker ())
98  .AddAttribute ("Stop",
99  "The simulation time at which to tear down "
100  "the device thread.",
101  TimeValue (Seconds (0.)),
103  MakeTimeChecker ())
104  .AddAttribute ("EncapsulationMode",
105  "The link-layer encapsulation type to use.",
106  EnumValue (DIX),
108  MakeEnumChecker (DIX, "Dix",
109  LLC, "Llc",
110  DIXPI, "DixPi"))
111  .AddAttribute ("RxQueueSize", "Maximum size of the read queue. "
112  "This value limits number of packets that have been read "
113  "from the network into a memory buffer but have not yet "
114  "been processed by the simulator.",
115  UintegerValue (1000),
117  MakeUintegerChecker<uint32_t> ())
118  //
119  // Trace sources at the "top" of the net device, where packets transition
120  // to/from higher layers. These points do not really correspond to the
121  // MAC layer of the underlying operating system, but exist to provide
122  // a consistent tracing environment. These trace hooks should really be
123  // interpreted as the points at which a packet leaves the ns-3 environment
124  // destined for the underlying operating system or vice-versa.
125  //
126  .AddTraceSource ("MacTx",
127  "Trace source indicating a packet has "
128  "arrived for transmission by this device",
130  "ns3::Packet::TracedCallback")
131  .AddTraceSource ("MacTxDrop",
132  "Trace source indicating a packet has "
133  "been dropped by the device before transmission",
135  "ns3::Packet::TracedCallback")
136  .AddTraceSource ("MacPromiscRx",
137  "A packet has been received by this device, "
138  "has been passed up from the physical layer "
139  "and is being forwarded up the local protocol stack. "
140  "This is a promiscuous trace,",
142  "ns3::Packet::TracedCallback")
143  .AddTraceSource ("MacRx",
144  "A packet has been received by this device, "
145  "has been passed up from the physical layer "
146  "and is being forwarded up the local protocol stack. "
147  "This is a non-promiscuous trace,",
149  "ns3::Packet::TracedCallback")
150 
151  //
152  // Trace sources designed to simulate a packet sniffer facility (tcpdump).
153  //
154  .AddTraceSource ("Sniffer",
155  "Trace source simulating a non-promiscuous "
156  "packet sniffer attached to the device",
158  "ns3::Packet::TracedCallback")
159  .AddTraceSource ("PromiscSniffer",
160  "Trace source simulating a promiscuous "
161  "packet sniffer attached to the device",
163  "ns3::Packet::TracedCallback")
164  ;
165  return tid;
166 }
167 
169  : m_node (0),
170  m_ifIndex (0),
171  // Defaults to Ethernet v2 MTU
172  m_mtu (1500),
173  m_fd (-1),
174  m_fdReader (0),
175  m_isBroadcast (true),
176  m_isMulticast (false),
177  m_startEvent (),
178  m_stopEvent ()
179 {
180  NS_LOG_FUNCTION (this);
181 }
182 
184 {
185  NS_LOG_FUNCTION (this);
186 }
187 
188 void
190 {
191  NS_LOG_FUNCTION (this);
192  Start (m_tStart);
193  if (m_tStop != Seconds (0))
194  {
195  Stop (m_tStop);
196  }
197 
199 }
200 
201 void
203 {
204  NS_LOG_FUNCTION (this);
205  StopDevice ();
207 }
208 
209 void
211 {
212  NS_LOG_FUNCTION (this << mode);
213  m_encapMode = mode;
214  NS_LOG_LOGIC ("m_encapMode = " << m_encapMode);
215 }
216 
219 {
220  NS_LOG_FUNCTION (this);
221  return m_encapMode;
222 }
223 
224 void
226 {
227  NS_LOG_FUNCTION (this << tStart);
230 }
231 
232 void
234 {
235  NS_LOG_FUNCTION (this << tStop);
238 }
239 
240 void
242 {
243  NS_LOG_FUNCTION (this);
244 
245  if (m_fd == -1)
246  {
247  NS_LOG_DEBUG ("FdNetDevice::Start(): Failure, invalid file descriptor.");
248  return;
249  }
250 
253 
255 
256  NotifyLinkUp ();
257 }
258 
261 {
262  NS_LOG_FUNCTION (this);
263 
264  Ptr<FdNetDeviceFdReader> fdReader = Create<FdNetDeviceFdReader> ();
265  // 22 bytes covers 14 bytes Ethernet header with possible 8 bytes LLC/SNAP
266  fdReader->SetBufferSize (m_mtu + 22);
267  return fdReader;
268 }
269 
270 void
272 {
273  NS_LOG_FUNCTION (this);
274 }
275 
276 void
278 {
279  NS_LOG_FUNCTION (this);
280 }
281 
282 void
284 {
285  NS_LOG_FUNCTION (this);
286 
287  if (m_fdReader != 0)
288  {
289  m_fdReader->Stop ();
290  m_fdReader = 0;
291  }
292 
293  if (m_fd != -1)
294  {
295  close (m_fd);
296  m_fd = -1;
297  }
298 
300 }
301 
302 void
303 FdNetDevice::ReceiveCallback (uint8_t *buf, ssize_t len)
304 {
305  NS_LOG_FUNCTION (this << static_cast<void *> (buf) << len);
306  bool skip = false;
307 
308  {
310  if (m_pendingQueue.size () >= m_maxPendingReads)
311  {
312  NS_LOG_WARN ("Packet dropped");
313  skip = true;
314  }
315  else
316  {
317  m_pendingQueue.push (std::make_pair (buf, len));
318  }
319  }
320 
321  if (skip)
322  {
323  struct timespec time = {
324  0, 100000000L
325  }; // 100 ms
326  nanosleep (&time, NULL);
327  }
328  else
329  {
331  }
332 }
333 
344 static void
345 AddPIHeader (uint8_t *&buf, size_t &len)
346 {
347  // Synthesize PI header for our friend the kernel
348  uint8_t *buf2 = (uint8_t*)malloc (len + 4);
349  memcpy (buf2 + 4, buf, len);
350  len += 4;
351 
352  // PI = 16 bits flags (0) + 16 bits proto
353  // NOTE: be careful to interpret buffer data explicitly as
354  // little-endian to be insensible to native byte ordering.
355  uint16_t flags = 0;
356  uint16_t proto = 0x0008; // default to IPv4
357  if (len > 14)
358  {
359  if (buf[12] == 0x81 && buf[13] == 0x00 && len > 18)
360  {
361  // tagged ethernet packet
362  proto = buf[16] | (buf[17] << 8);
363  }
364  else
365  {
366  // untagged ethernet packet
367  proto = buf[12] | (buf[13] << 8);
368  }
369  }
370  buf2[0] = (uint8_t)flags;
371  buf2[1] = (uint8_t)(flags >> 8);
372  buf2[2] = (uint8_t)proto;
373  buf2[3] = (uint8_t)(proto >> 8);
374 
375  // swap buffer
376  free (buf);
377  buf = buf2;
378 }
379 
386 static void
387 RemovePIHeader (uint8_t *&buf, ssize_t &len)
388 {
389  // strip PI header if present, shrink buffer
390  if (len >= 4)
391  {
392  len -= 4;
393  memmove (buf, buf + 4, len);
394  buf = (uint8_t*)realloc (buf, len);
395  }
396 }
397 
398 uint8_t *
400 {
401  return (uint8_t*) malloc(len);
402 }
403 
404 void
406 {
407  free (buf);
408 }
409 
410 void
412 {
413  NS_LOG_FUNCTION (this);
414 
415  uint8_t *buf = 0;
416  ssize_t len = 0;
417 
418  {
420  std::pair<uint8_t *, ssize_t> next = m_pendingQueue.front ();
421  m_pendingQueue.pop ();
422 
423  buf = next.first;
424  len = next.second;
425  }
426 
427  NS_LOG_LOGIC ("buffer: " << static_cast<void *> (buf) << " length: " << len);
428 
429  // We need to remove the PI header and ignore it
430  if (m_encapMode == DIXPI)
431  {
432  RemovePIHeader (buf, len);
433  }
434 
435  //
436  // Create a packet out of the buffer we received and free that buffer.
437  //
438  Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len);
439  FreeBuffer (buf);
440  buf = 0;
441 
442  //
443  // Trace sinks will expect complete packets, not packets without some of the
444  // headers
445  //
446  Ptr<Packet> originalPacket = packet->Copy ();
447 
448  Mac48Address destination;
449  Mac48Address source;
450  uint16_t protocol;
451  bool isBroadcast = false;
452  bool isMulticast = false;
453 
454  EthernetHeader header (false);
455 
456  //
457  // This device could be running in an environment where completely unexpected
458  // kinds of packets are flying around, so we need to harden things a bit and
459  // filter out packets we think are completely bogus, so we always check to see
460  // that the packet is long enough to contain the header we want to remove.
461  //
462  if (packet->GetSize () < header.GetSerializedSize ())
463  {
464  m_phyRxDropTrace (originalPacket);
465  return;
466  }
467 
468  packet->RemoveHeader (header);
469  destination = header.GetDestination ();
470  source = header.GetSource ();
471  isBroadcast = header.GetDestination ().IsBroadcast ();
472  isMulticast = header.GetDestination ().IsGroup ();
473  protocol = header.GetLengthType ();
474 
475  //
476  // If the length/type is less than 1500, it corresponds to a length
477  // interpretation packet. In this case, it is an 802.3 packet and
478  // will also have an 802.2 LLC header. If greater than 1500, we
479  // find the protocol number (Ethernet type) directly.
480  //
481  if (m_encapMode == LLC and header.GetLengthType () <= 1500)
482  {
483  LlcSnapHeader llc;
484  //
485  // Check to see that the packet is long enough to possibly contain the
486  // header we want to remove before just naively calling.
487  //
488  if (packet->GetSize () < llc.GetSerializedSize ())
489  {
490  m_phyRxDropTrace (originalPacket);
491  return;
492  }
493 
494  packet->RemoveHeader (llc);
495  protocol = llc.GetType ();
496  }
497 
498  NS_LOG_LOGIC ("Pkt source is " << source);
499  NS_LOG_LOGIC ("Pkt destination is " << destination);
500 
501  PacketType packetType;
502 
503  if (isBroadcast)
504  {
505  packetType = NS3_PACKET_BROADCAST;
506  }
507  else if (isMulticast)
508  {
509  packetType = NS3_PACKET_MULTICAST;
510  }
511  else if (destination == m_address)
512  {
513  packetType = NS3_PACKET_HOST;
514  }
515  else
516  {
517  packetType = NS3_PACKET_OTHERHOST;
518  }
519 
520  //
521  // For all kinds of packetType we receive, we hit the promiscuous sniffer
522  // hook and pass a copy up to the promiscuous callback. Pass a copy to
523  // make sure that nobody messes with our packet.
524  //
525  m_promiscSnifferTrace (originalPacket);
526 
527  if (!m_promiscRxCallback.IsNull ())
528  {
529  m_macPromiscRxTrace (originalPacket);
530  m_promiscRxCallback (this, packet, protocol, source, destination,
531  packetType);
532  }
533 
534  //
535  // If this packet is not destined for some other host, it must be for us
536  // as either a broadcast, multicast or unicast. We need to hit the mac
537  // packet received trace hook and forward the packet up the stack.
538  //
539  if (packetType != NS3_PACKET_OTHERHOST)
540  {
541  m_snifferTrace (originalPacket);
542  m_macRxTrace (originalPacket);
543  m_rxCallback (this, packet, protocol, source);
544  }
545 }
546 
547 bool
548 FdNetDevice::Send (Ptr<Packet> packet, const Address& destination, uint16_t protocolNumber)
549 {
550  NS_LOG_FUNCTION (this << packet << destination << protocolNumber);
551  return SendFrom (packet, m_address, destination, protocolNumber);
552 }
553 
554 bool
555 FdNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
556 {
557  NS_LOG_FUNCTION (this << packet << src << dest << protocolNumber);
558  NS_LOG_LOGIC ("packet: " << packet << " UID: " << packet->GetUid ());
559 
560  if (IsLinkUp () == false)
561  {
562  m_macTxDropTrace (packet);
563  return false;
564  }
565 
566  Mac48Address destination = Mac48Address::ConvertFrom (dest);
568 
569  NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ());
570  NS_LOG_LOGIC ("Transmit packet from " << source);
571  NS_LOG_LOGIC ("Transmit packet to " << destination);
572 
573  EthernetHeader header (false);
574  header.SetSource (source);
575  header.SetDestination (destination);
576 
577  NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet too big " << packet->GetSize ());
578 
579  if (m_encapMode == LLC)
580  {
581  LlcSnapHeader llc;
582  llc.SetType (protocolNumber);
583  packet->AddHeader (llc);
584 
585  header.SetLengthType (packet->GetSize ());
586  }
587  else
588  {
589  header.SetLengthType (protocolNumber);
590  }
591 
592  packet->AddHeader (header);
593 
594  //
595  // there's not much meaning associated with the different layers in this
596  // device, so don't be surprised when they're all stacked together in
597  // essentially one place. We do this for trace consistency across devices.
598  //
599  m_macTxTrace (packet);
600 
601  m_promiscSnifferTrace (packet);
602  m_snifferTrace (packet);
603 
604  NS_LOG_LOGIC ("calling write");
605 
606 
607  size_t len = (size_t) packet->GetSize ();
608  uint8_t *buffer = AllocateBuffer (len);
609  if(!buffer)
610  {
611  m_macTxDropTrace(packet);
612  return false;
613  }
614 
615  packet->CopyData (buffer, len);
616 
617  // We need to add the PI header
618  if (m_encapMode == DIXPI)
619  {
620  AddPIHeader (buffer, len);
621  }
622 
623  ssize_t written = Write(buffer, len);
624  FreeBuffer (buffer);
625 
626  if (written == -1 || (size_t) written != len)
627  {
628  m_macTxDropTrace (packet);
629  return false;
630  }
631 
632  return true;
633 }
634 
635 ssize_t
636 FdNetDevice::Write (uint8_t *buffer, size_t length)
637 {
638  NS_LOG_FUNCTION (this << static_cast<void *> (buffer) << length);
639 
640  uint32_t ret = write (m_fd, buffer, length);
641  return ret;
642 }
643 
644 void
646 {
647  if (m_fd == -1 and fd > 0)
648  {
649  m_fd = fd;
650  }
651 }
652 
653 int
655 {
656  return m_fd;
657 }
658 
659 void
661 {
663 }
664 
665 Address
667 {
668  return m_address;
669 }
670 
671 void
673 {
674  m_linkUp = true;
676 }
677 
678 void
679 FdNetDevice::SetIfIndex (const uint32_t index)
680 {
681  m_ifIndex = index;
682 }
683 
684 uint32_t
686 {
687  return m_ifIndex;
688 }
689 
692 {
693  return NULL;
694 }
695 
696 bool
697 FdNetDevice::SetMtu (const uint16_t mtu)
698 {
699  // The MTU depends on the technology associated to
700  // the file descriptor. The user is responsible of
701  // setting the correct value of the MTU.
702  // If the file descriptor is created using a helper,
703  // then is the responsibility of the helper to set
704  // the correct MTU value.
705  m_mtu = mtu;
706  return true;
707 }
708 
709 uint16_t
711 {
712  return m_mtu;
713 }
714 
715 bool
717 {
718  return m_linkUp;
719 }
720 
721 void
723 {
725 }
726 
727 bool
729 {
730  return m_isBroadcast;
731 }
732 
733 void
735 {
736  m_isBroadcast = broadcast;
737 }
738 
739 Address
741 {
742  return Mac48Address ("ff:ff:ff:ff:ff:ff");
743 }
744 
745 bool
747 {
748  return m_isMulticast;
749 }
750 
751 void
753 {
754  m_isMulticast = multicast;
755 }
756 
757 Address
759 {
760  return Mac48Address::GetMulticast (multicastGroup);
761 }
762 
763 Address
765 {
766  return Mac48Address::GetMulticast (addr);
767 }
768 
769 bool
771 {
772  return false;
773 }
774 
775 bool
777 {
778  return false;
779 }
780 
781 Ptr<Node>
783 {
784  return m_node;
785 }
786 
787 void
789 {
790  m_node = node;
791 
792  // Save the node ID for use in the read thread, to avoid having
793  // to make a call to GetNode ()->GetId () that increments
794  // Ptr<Node>'s reference count.
795  m_nodeId = node->GetId ();
796 }
797 
798 bool
800 {
801  return true;
802 }
803 
804 void
806 {
807  m_rxCallback = cb;
808 }
809 
810 void
812 {
813  m_promiscRxCallback = cb;
814 }
815 
816 bool
818 {
819  return true;
820 }
821 
822 } // namespace ns3
a polymophic address class
Definition: address.h:91
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
A class which provides a simple way to implement a Critical Section.
Definition: system-mutex.h:119
Hold variables of type enum.
Definition: enum.h:55
Packet header for Ethernet.
void SetDestination(Mac48Address destination)
void SetLengthType(uint16_t size)
void SetSource(Mac48Address source)
Mac48Address GetDestination(void) const
virtual uint32_t GetSerializedSize(void) const
Mac48Address GetSource(void) const
uint16_t GetLengthType(void) const
uint32_t m_bufferSize
size of the read buffer
Definition: fd-net-device.h:68
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
FdReader::Data DoRead(void)
The read implementation.
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:85
EventId m_stopEvent
NetDevice stop event.
virtual uint32_t GetIfIndex(void) const
virtual void FreeBuffer(uint8_t *buf)
Free the given packet buffer.
bool m_isBroadcast
Flag indicating whether or not the underlying net device supports broadcast.
Ptr< FdReader > m_fdReader
Reader for the file descriptor.
virtual void DoInitialize(void)
Method Initialization for start and stop attributes.
uint32_t m_ifIndex
The ns-3 interface index (in the sense of net device index) that has been assigned to this network de...
int m_fd
The file descriptor used for receive/send network traffic.
virtual uint8_t * AllocateBuffer(size_t len)
Allocate packet buffer.
uint16_t m_mtu
The MTU associated to the file descriptor technology.
virtual void SetIsBroadcast(bool broadcast)
Set if the NetDevice is able to send Broadcast messages.
virtual void DoDispose(void)
Destructor implementation.
virtual void SetNode(Ptr< Node > node)
virtual ~FdNetDevice()
Destructor for the FdNetDevice.
FdNetDevice::EncapsulationMode GetEncapsulationMode(void) const
Get the link layer encapsulation mode of this device.
void Start(Time tStart)
Set a start time for the device.
Ptr< Node > m_node
The ns-3 node associated to the net device.
TracedCallback m_linkChangeCallbacks
Callbacks to fire if the link changes state (up or down).
virtual uint16_t GetMtu(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
uint32_t m_maxPendingReads
Maximum number of packets that can be received and scheduled for read but not yet read.
virtual bool IsMulticast(void) const
std::queue< std::pair< uint8_t *, ssize_t > > m_pendingQueue
Number of packets that were received and scheduled for read but not yet read.
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void NotifyLinkUp(void)
Notify that the link is up and ready.
virtual bool NeedsArp(void) const
Time m_tStart
Time to start spinning up the device.
void Stop(Time tStop)
Set a stop time for the device.
virtual void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
EventId m_startEvent
NetDevice start event.
bool m_isMulticast
Flag indicating whether or not the underlying net device supports multicast.
virtual Address GetAddress(void) const
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
virtual void SetIfIndex(const uint32_t index)
virtual bool SetMtu(const uint16_t mtu)
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
virtual void SetAddress(Address address)
Set the address of this interface.
void ForwardUp(void)
Forward the frame to the appropriate callback for processing.
FdNetDevice()
Constructor for the FdNetDevice.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
virtual bool IsLinkUp(void) const
static TypeId GetTypeId(void)
Get the type ID.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
void SetEncapsulationMode(FdNetDevice::EncapsulationMode mode)
Set the link layer encapsulation mode of this device.
SystemMutex m_pendingReadMutex
Mutex to increase pending read counter.
virtual Ptr< FdReader > DoCreateFdReader(void)
Create the FdReader object.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual Ptr< Node > GetNode(void) const
EncapsulationMode m_encapMode
The type of encapsulation of the received/transmitted frames.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
EncapsulationMode
Enumeration of the types of frames supported in the class.
Definition: fd-net-device.h:97
@ DIX
DIX II / Ethernet II packet.
Definition: fd-net-device.h:98
@ DIXPI
When using TAP devices, if flag IFF_NO_PI is not set on the device, IP packets will have an extra hea...
@ LLC
802.2 LLC/SNAP Packet
Definition: fd-net-device.h:99
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
bool m_linkUp
Flag indicating whether or not the link is up.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void SetFileDescriptor(int fd)
Set the associated file descriptor.
Time m_tStop
Time to start tearing down the device.
virtual ssize_t Write(uint8_t *buffer, size_t length)
Write packet data to device.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
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...
virtual Ptr< Channel > GetChannel(void) const
virtual void DoFinishStartingDevice(void)
Complete additional actions, if any, to spin up down the device.
Mac48Address m_address
The net device mac address.
virtual void SetIsMulticast(bool multicast)
Set if the NetDevice is able to send Multicast messages.
virtual bool SupportsSendFrom() const
virtual bool IsBroadcast(void) const
virtual Address GetBroadcast(void) const
int GetFileDescriptor(void) const
Get the associated file descriptor.
void StopDevice(void)
Tear down the device.
uint32_t m_nodeId
a copy of the node id so the read thread doesn't have to GetNode() in in order to find the node ID.
void StartDevice(void)
Spin up the device.
int m_fd
The file descriptor to read from.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
Header for the LLC/SNAP encapsulation.
uint16_t GetType(void)
Return the Ethertype.
virtual uint32_t GetSerializedSize(void) const
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetMulticast(Ipv4Address address)
bool IsGroup(void) const
bool IsBroadcast(void) const
static Mac48Address ConvertFrom(const Address &address)
AttributeValue implementation for Mac48Address.
Network layer to device interface.
Definition: net-device.h:96
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition: net-device.h:318
uint32_t GetId(void) const
Definition: node.cc:109
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
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:268
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:572
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
AttributeValue implementation for Time.
Definition: nstime.h:1353
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:923
Hold an unsigned integer type.
Definition: uinteger.h:44
#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 > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:203
Ptr< const AttributeAccessor > MakeMac48AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeMac48AddressChecker(void)
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:1354
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
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
static void RemovePIHeader(uint8_t *&buf, ssize_t &len)
Removes PI header.
static void AddPIHeader(uint8_t *&buf, size_t &len)
Synthesize PI header for the kernel.
#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_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
EventImpl * MakeEvent(void(*f)(void))
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:34
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
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.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:161
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
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:1642
A structure representing data read.