A Discrete-Event Network Simulator
API
fd-net-device.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 INRIA, 2012 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Alina Quereilhac <alina.quereilhac@inria.fr>
18  * Claudio Freire <klaussfreire@sourceforge.net>
19  */
20 
21 #include "fd-net-device.h"
22 
23 #include "ns3/abort.h"
24 #include "ns3/boolean.h"
25 #include "ns3/channel.h"
26 #include "ns3/enum.h"
27 #include "ns3/ethernet-header.h"
28 #include "ns3/ethernet-trailer.h"
29 #include "ns3/llc-snap-header.h"
30 #include "ns3/log.h"
31 #include "ns3/mac48-address.h"
32 #include "ns3/pointer.h"
33 #include "ns3/simulator.h"
34 #include "ns3/string.h"
35 #include "ns3/trace-source-accessor.h"
36 #include "ns3/uinteger.h"
37 
38 #include <arpa/inet.h>
39 #include <net/ethernet.h>
40 #include <unistd.h>
41 
42 namespace ns3
43 {
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 
61 {
62  NS_LOG_FUNCTION(this);
63 
64  auto buf = (uint8_t*)malloc(m_bufferSize);
65  NS_ABORT_MSG_IF(buf == nullptr, "malloc() failed");
66 
67  NS_LOG_LOGIC("Calling read on fd " << m_fd);
68  ssize_t len = read(m_fd, buf, m_bufferSize);
69  if (len <= 0)
70  {
71  free(buf);
72  buf = nullptr;
73  len = 0;
74  }
75  NS_LOG_LOGIC("Read " << len << " bytes on fd " << m_fd);
76  return FdReader::Data(buf, len);
77 }
78 
80 
81 TypeId
83 {
84  static TypeId tid =
85  TypeId("ns3::FdNetDevice")
87  .SetGroupName("FdNetDevice")
88  .AddConstructor<FdNetDevice>()
89  .AddAttribute("Address",
90  "The MAC address of this device.",
91  Mac48AddressValue(Mac48Address("ff:ff:ff:ff:ff:ff")),
92  MakeMac48AddressAccessor(&FdNetDevice::m_address),
93  MakeMac48AddressChecker())
94  .AddAttribute("Start",
95  "The simulation time at which to spin up "
96  "the device thread.",
97  TimeValue(Seconds(0.)),
100  .AddAttribute("Stop",
101  "The simulation time at which to tear down "
102  "the device thread.",
103  TimeValue(Seconds(0.)),
105  MakeTimeChecker())
106  .AddAttribute("EncapsulationMode",
107  "The link-layer encapsulation type to use.",
108  EnumValue(DIX),
109  MakeEnumAccessor<EncapsulationMode>(&FdNetDevice::m_encapMode),
110  MakeEnumChecker(DIX, "Dix", LLC, "Llc", DIXPI, "DixPi"))
111  .AddAttribute("RxQueueSize",
112  "Maximum size of the read queue. "
113  "This value limits number of packets that have been read "
114  "from the network into a memory buffer but have not yet "
115  "been processed by the simulator.",
116  UintegerValue(1000),
118  MakeUintegerChecker<uint32_t>())
119  //
120  // Trace sources at the "top" of the net device, where packets transition
121  // to/from higher layers. These points do not really correspond to the
122  // MAC layer of the underlying operating system, but exist to provide
123  // a consistent tracing environment. These trace hooks should really be
124  // interpreted as the points at which a packet leaves the ns-3 environment
125  // destined for the underlying operating system or vice-versa.
126  //
127  .AddTraceSource("MacTx",
128  "Trace source indicating a packet has "
129  "arrived for transmission by this device",
131  "ns3::Packet::TracedCallback")
132  .AddTraceSource("MacTxDrop",
133  "Trace source indicating a packet has "
134  "been dropped by the device before transmission",
136  "ns3::Packet::TracedCallback")
137  .AddTraceSource("MacPromiscRx",
138  "A packet has been received by this device, "
139  "has been passed up from the physical layer "
140  "and is being forwarded up the local protocol stack. "
141  "This is a promiscuous trace,",
143  "ns3::Packet::TracedCallback")
144  .AddTraceSource("MacRx",
145  "A packet has been received by this device, "
146  "has been passed up from the physical layer "
147  "and is being forwarded up the local protocol stack. "
148  "This is a non-promiscuous trace,",
150  "ns3::Packet::TracedCallback")
151 
152  //
153  // Trace sources designed to simulate a packet sniffer facility (tcpdump).
154  //
155  .AddTraceSource("Sniffer",
156  "Trace source simulating a non-promiscuous "
157  "packet sniffer attached to the device",
159  "ns3::Packet::TracedCallback")
160  .AddTraceSource("PromiscSniffer",
161  "Trace source simulating a promiscuous "
162  "packet sniffer attached to the device",
164  "ns3::Packet::TracedCallback");
165  return tid;
166 }
167 
169  : m_node(nullptr),
170  m_ifIndex(0),
171  // Defaults to Ethernet v2 MTU
172  m_mtu(1500),
173  m_fd(-1),
174  m_fdReader(nullptr),
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)
288  {
289  m_fdReader->Stop();
290  m_fdReader = nullptr;
291  }
292 
293  if (m_fd != -1)
294  {
295  close(m_fd);
296  m_fd = -1;
297  }
298 
299  while (!m_pendingQueue.empty())
300  {
301  std::pair<uint8_t*, ssize_t> next = m_pendingQueue.front();
302  m_pendingQueue.pop();
303  FreeBuffer(next.first);
304  }
305 
307 }
308 
309 void
310 FdNetDevice::ReceiveCallback(uint8_t* buf, ssize_t len)
311 {
312  NS_LOG_FUNCTION(this << static_cast<void*>(buf) << len);
313  bool skip = false;
314 
315  {
316  std::unique_lock lock{m_pendingReadMutex};
317  if (m_pendingQueue.size() >= m_maxPendingReads)
318  {
319  NS_LOG_WARN("Packet dropped");
320  skip = true;
321  }
322  else
323  {
324  m_pendingQueue.emplace(buf, len);
325  }
326  }
327 
328  if (skip)
329  {
330  struct timespec time = {0, 100000000L}; // 100 ms
331  nanosleep(&time, nullptr);
332  }
333  else
334  {
336  }
337 }
338 
349 static void
350 AddPIHeader(uint8_t*& buf, size_t& len)
351 {
352  // Synthesize PI header for our friend the kernel
353  auto buf2 = (uint8_t*)malloc(len + 4);
354  memcpy(buf2 + 4, buf, len);
355  len += 4;
356 
357  // PI = 16 bits flags (0) + 16 bits proto
358  // NOTE: be careful to interpret buffer data explicitly as
359  // little-endian to be insensible to native byte ordering.
360  uint16_t flags = 0;
361  uint16_t proto = 0x0008; // default to IPv4
362  if (len > 14)
363  {
364  if (buf[12] == 0x81 && buf[13] == 0x00 && len > 18)
365  {
366  // tagged ethernet packet
367  proto = buf[16] | (buf[17] << 8);
368  }
369  else
370  {
371  // untagged ethernet packet
372  proto = buf[12] | (buf[13] << 8);
373  }
374  }
375  buf2[0] = (uint8_t)flags;
376  buf2[1] = (uint8_t)(flags >> 8);
377  buf2[2] = (uint8_t)proto;
378  buf2[3] = (uint8_t)(proto >> 8);
379 
380  // swap buffer
381  free(buf);
382  buf = buf2;
383 }
384 
391 static void
392 RemovePIHeader(uint8_t*& buf, ssize_t& len)
393 {
394  // strip PI header if present, shrink buffer
395  if (len >= 4)
396  {
397  len -= 4;
398  memmove(buf, buf + 4, len);
399  buf = (uint8_t*)realloc(buf, len);
400  }
401 }
402 
403 uint8_t*
405 {
406  return (uint8_t*)malloc(len);
407 }
408 
409 void
411 {
412  free(buf);
413 }
414 
415 void
417 {
418  NS_LOG_FUNCTION(this);
419 
420  uint8_t* buf = nullptr;
421  ssize_t len = 0;
422 
423  if (m_pendingQueue.empty())
424  {
425  NS_LOG_LOGIC("buffer is empty, probably the device is stopped.");
426  return;
427  }
428 
429  {
430  std::unique_lock lock{m_pendingReadMutex};
431  std::pair<uint8_t*, ssize_t> next = m_pendingQueue.front();
432  m_pendingQueue.pop();
433 
434  buf = next.first;
435  len = next.second;
436  }
437 
438  NS_LOG_LOGIC("buffer: " << static_cast<void*>(buf) << " length: " << len);
439 
440  // We need to remove the PI header and ignore it
441  if (m_encapMode == DIXPI)
442  {
443  RemovePIHeader(buf, len);
444  }
445 
446  //
447  // Create a packet out of the buffer we received and free that buffer.
448  //
449  Ptr<Packet> packet = Create<Packet>(reinterpret_cast<const uint8_t*>(buf), len);
450  FreeBuffer(buf);
451  buf = nullptr;
452 
453  //
454  // Trace sinks will expect complete packets, not packets without some of the
455  // headers
456  //
457  Ptr<Packet> originalPacket = packet->Copy();
458 
459  Mac48Address destination;
460  Mac48Address source;
461  uint16_t protocol;
462  bool isBroadcast = false;
463  bool isMulticast = false;
464 
465  EthernetHeader header(false);
466 
467  //
468  // This device could be running in an environment where completely unexpected
469  // kinds of packets are flying around, so we need to harden things a bit and
470  // filter out packets we think are completely bogus, so we always check to see
471  // that the packet is long enough to contain the header we want to remove.
472  //
473  if (packet->GetSize() < header.GetSerializedSize())
474  {
475  m_phyRxDropTrace(originalPacket);
476  return;
477  }
478 
479  packet->RemoveHeader(header);
480  destination = header.GetDestination();
481  source = header.GetSource();
482  isBroadcast = header.GetDestination().IsBroadcast();
483  isMulticast = header.GetDestination().IsGroup();
484  protocol = header.GetLengthType();
485 
486  //
487  // If the length/type is less than 1500, it corresponds to a length
488  // interpretation packet. In this case, it is an 802.3 packet and
489  // will also have an 802.2 LLC header. If greater than 1500, we
490  // find the protocol number (Ethernet type) directly.
491  //
492  if (m_encapMode == LLC and header.GetLengthType() <= 1500)
493  {
494  LlcSnapHeader llc;
495  //
496  // Check to see that the packet is long enough to possibly contain the
497  // header we want to remove before just naively calling.
498  //
499  if (packet->GetSize() < llc.GetSerializedSize())
500  {
501  m_phyRxDropTrace(originalPacket);
502  return;
503  }
504 
505  packet->RemoveHeader(llc);
506  protocol = llc.GetType();
507  }
508 
509  NS_LOG_LOGIC("Pkt source is " << source);
510  NS_LOG_LOGIC("Pkt destination is " << destination);
511 
512  PacketType packetType;
513 
514  if (isBroadcast)
515  {
516  packetType = NS3_PACKET_BROADCAST;
517  }
518  else if (isMulticast)
519  {
520  packetType = NS3_PACKET_MULTICAST;
521  }
522  else if (destination == m_address)
523  {
524  packetType = NS3_PACKET_HOST;
525  }
526  else
527  {
528  packetType = NS3_PACKET_OTHERHOST;
529  }
530 
531  //
532  // For all kinds of packetType we receive, we hit the promiscuous sniffer
533  // hook and pass a copy up to the promiscuous callback. Pass a copy to
534  // make sure that nobody messes with our packet.
535  //
536  m_promiscSnifferTrace(originalPacket);
537 
539  {
540  m_macPromiscRxTrace(originalPacket);
541  m_promiscRxCallback(this, packet, protocol, source, destination, packetType);
542  }
543 
544  //
545  // If this packet is not destined for some other host, it must be for us
546  // as either a broadcast, multicast or unicast. We need to hit the mac
547  // packet received trace hook and forward the packet up the stack.
548  //
549  if (packetType != NS3_PACKET_OTHERHOST)
550  {
551  m_snifferTrace(originalPacket);
552  m_macRxTrace(originalPacket);
553  m_rxCallback(this, packet, protocol, source);
554  }
555 }
556 
557 bool
558 FdNetDevice::Send(Ptr<Packet> packet, const Address& destination, uint16_t protocolNumber)
559 {
560  NS_LOG_FUNCTION(this << packet << destination << protocolNumber);
561  return SendFrom(packet, m_address, destination, protocolNumber);
562 }
563 
564 bool
566  const Address& src,
567  const Address& dest,
568  uint16_t protocolNumber)
569 {
570  NS_LOG_FUNCTION(this << packet << src << dest << protocolNumber);
571  NS_LOG_LOGIC("packet: " << packet << " UID: " << packet->GetUid());
572 
573  if (!IsLinkUp())
574  {
575  m_macTxDropTrace(packet);
576  return false;
577  }
578 
579  Mac48Address destination = Mac48Address::ConvertFrom(dest);
581 
582  NS_LOG_LOGIC("Transmit packet with UID " << packet->GetUid());
583  NS_LOG_LOGIC("Transmit packet from " << source);
584  NS_LOG_LOGIC("Transmit packet to " << destination);
585 
586  EthernetHeader header(false);
587  header.SetSource(source);
588  header.SetDestination(destination);
589 
590  NS_ASSERT_MSG(packet->GetSize() <= m_mtu,
591  "FdNetDevice::SendFrom(): Packet too big " << packet->GetSize());
592 
593  if (m_encapMode == LLC)
594  {
595  LlcSnapHeader llc;
596  llc.SetType(protocolNumber);
597  packet->AddHeader(llc);
598 
599  header.SetLengthType(packet->GetSize());
600  }
601  else
602  {
603  header.SetLengthType(protocolNumber);
604  }
605 
606  packet->AddHeader(header);
607 
608  //
609  // there's not much meaning associated with the different layers in this
610  // device, so don't be surprised when they're all stacked together in
611  // essentially one place. We do this for trace consistency across devices.
612  //
613  m_macTxTrace(packet);
614 
615  m_promiscSnifferTrace(packet);
616  m_snifferTrace(packet);
617 
618  NS_LOG_LOGIC("calling write");
619 
620  auto len = (size_t)packet->GetSize();
621  uint8_t* buffer = AllocateBuffer(len);
622  if (!buffer)
623  {
624  m_macTxDropTrace(packet);
625  return false;
626  }
627 
628  packet->CopyData(buffer, len);
629 
630  // We need to add the PI header
631  if (m_encapMode == DIXPI)
632  {
633  AddPIHeader(buffer, len);
634  }
635 
636  ssize_t written = Write(buffer, len);
637  FreeBuffer(buffer);
638 
639  if (written == -1 || (size_t)written != len)
640  {
641  m_macTxDropTrace(packet);
642  return false;
643  }
644 
645  return true;
646 }
647 
648 ssize_t
649 FdNetDevice::Write(uint8_t* buffer, size_t length)
650 {
651  NS_LOG_FUNCTION(this << static_cast<void*>(buffer) << length);
652 
653  uint32_t ret = write(m_fd, buffer, length);
654  return ret;
655 }
656 
657 void
659 {
660  if (m_fd == -1 and fd > 0)
661  {
662  m_fd = fd;
663  }
664 }
665 
666 int
668 {
669  return m_fd;
670 }
671 
672 void
674 {
676 }
677 
678 Address
680 {
681  return m_address;
682 }
683 
684 void
686 {
687  m_linkUp = true;
689 }
690 
691 void
692 FdNetDevice::SetIfIndex(const uint32_t index)
693 {
694  m_ifIndex = index;
695 }
696 
697 uint32_t
699 {
700  return m_ifIndex;
701 }
702 
705 {
706  return nullptr;
707 }
708 
709 bool
710 FdNetDevice::SetMtu(const uint16_t mtu)
711 {
712  // The MTU depends on the technology associated to
713  // the file descriptor. The user is responsible of
714  // setting the correct value of the MTU.
715  // If the file descriptor is created using a helper,
716  // then is the responsibility of the helper to set
717  // the correct MTU value.
718  m_mtu = mtu;
719  return true;
720 }
721 
722 uint16_t
724 {
725  return m_mtu;
726 }
727 
728 bool
730 {
731  return m_linkUp;
732 }
733 
734 void
736 {
738 }
739 
740 bool
742 {
743  return m_isBroadcast;
744 }
745 
746 void
748 {
749  m_isBroadcast = broadcast;
750 }
751 
752 Address
754 {
755  return Mac48Address("ff:ff:ff:ff:ff:ff");
756 }
757 
758 bool
760 {
761  return m_isMulticast;
762 }
763 
764 void
766 {
767  m_isMulticast = multicast;
768 }
769 
770 Address
772 {
773  return Mac48Address::GetMulticast(multicastGroup);
774 }
775 
776 Address
778 {
779  return Mac48Address::GetMulticast(addr);
780 }
781 
782 bool
784 {
785  return false;
786 }
787 
788 bool
790 {
791  return false;
792 }
793 
794 Ptr<Node>
796 {
797  return m_node;
798 }
799 
800 void
802 {
803  m_node = node;
804 
805  // Save the node ID for use in the read thread, to avoid having
806  // to make a call to GetNode ()->GetId () that increments
807  // Ptr<Node>'s reference count.
808  m_nodeId = node->GetId();
809 }
810 
811 bool
813 {
814  return true;
815 }
816 
817 void
819 {
820  m_rxCallback = cb;
821 }
822 
823 void
825 {
826  m_promiscRxCallback = cb;
827 }
828 
829 bool
831 {
832  return true;
833 }
834 
835 } // namespace ns3
a polymophic address class
Definition: address.h:101
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
Hold variables of type enum.
Definition: enum.h:62
Packet header for Ethernet.
uint16_t GetLengthType() const
uint32_t GetSerializedSize() const override
void SetDestination(Mac48Address destination)
Mac48Address GetDestination() const
void SetLengthType(uint16_t size)
void SetSource(Mac48Address source)
Mac48Address GetSource() const
uint32_t m_bufferSize
size of the read buffer
Definition: fd-net-device.h:67
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
FdReader::Data DoRead() override
The read implementation.
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:84
EventId m_stopEvent
NetDevice stop event.
void StopDevice()
Tear down the device.
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.
bool IsMulticast() const override
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.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
virtual void SetIsBroadcast(bool broadcast)
Set if the NetDevice is able to send Broadcast messages.
Ptr< Node > GetNode() const override
void Start(Time tStart)
Set a start time for the device.
Ptr< Node > m_node
The ns-3 node associated to the net device.
bool SetMtu(const uint16_t mtu) override
int GetFileDescriptor() const
Get the associated file descriptor.
TracedCallback m_linkChangeCallbacks
Callbacks to fire if the link changes state (up or down).
virtual Ptr< FdReader > DoCreateFdReader()
Create the FdReader object.
void SetAddress(Address address) override
Set the address of this interface.
uint32_t m_maxPendingReads
Maximum number of packets that can be received and scheduled for read but not yet read.
std::mutex m_pendingReadMutex
Mutex to increase pending read counter.
Address GetBroadcast() const override
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...
Time m_tStart
Time to start spinning up the device.
void SetNode(Ptr< Node > node) override
std::queue< std::pair< uint8_t *, ssize_t > > m_pendingQueue
Number of packets that were received and scheduled for read but not yet read.
void Stop(Time tStop)
Set a stop time for the device.
void SetIfIndex(const uint32_t index) override
EventId m_startEvent
NetDevice start event.
void StartDevice()
Spin up the device.
bool m_isMulticast
Flag indicating whether or not the underlying net device supports multicast.
void DoDispose() override
Destructor implementation.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
bool IsBroadcast() const override
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
Address GetAddress() const override
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.
bool NeedsArp() const override
~FdNetDevice() override
Destructor for the FdNetDevice.
uint16_t GetMtu() const override
void SetEncapsulationMode(FdNetDevice::EncapsulationMode mode)
Set the link layer encapsulation mode of this device.
static TypeId GetTypeId()
Get the type ID.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
EncapsulationMode m_encapMode
The type of encapsulation of the received/transmitted frames.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
Ptr< Channel > GetChannel() const override
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
void NotifyLinkUp()
Notify that the link is up and ready.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
uint32_t GetIfIndex() const override
void AddLinkChangeCallback(Callback< void > callback) override
EncapsulationMode
Enumeration of the types of frames supported in the class.
Definition: fd-net-device.h:96
@ DIX
DIX II / Ethernet II packet.
Definition: fd-net-device.h:97
@ DIXPI
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:99
@ LLC
802.2 LLC/SNAP Packet
Definition: fd-net-device.h:98
bool m_linkUp
Flag indicating whether or not the link is up.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
virtual void DoFinishStoppingDevice()
Complete additional actions, if any, to tear down the device.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
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.
bool IsLinkUp() const override
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...
Mac48Address m_address
The net device mac address.
virtual void SetIsMulticast(bool multicast)
Set if the NetDevice is able to send Multicast messages.
void ForwardUp()
Forward the frame to the appropriate callback for processing.
void DoInitialize() override
Method Initialization for start and stop attributes.
FdNetDevice::EncapsulationMode GetEncapsulationMode() const
Get the link layer encapsulation mode of this device.
bool SupportsSendFrom() const override
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.
virtual void DoFinishStartingDevice()
Complete additional actions, if any, to spin up down the device.
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
int m_fd
The file descriptor to read from.
Definition: fd-reader.h:135
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Header for the LLC/SNAP encapsulation.
uint16_t GetType()
Return the Ethertype.
uint32_t GetSerializedSize() const override
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetMulticast(Ipv4Address address)
bool IsGroup() const
static Mac48Address ConvertFrom(const Address &address)
bool IsBroadcast() const
Network layer to device interface.
Definition: net-device.h:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition: net-device.h:322
uint32_t GetId() const
Definition: node.cc:117
virtual void DoInitialize()
Initialize() implementation.
Definition: object.cc:359
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:400
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
uint64_t GetUid() const
Returns the packet's Uid.
Definition: packet.cc:412
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
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:285
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:588
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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:931
Hold an unsigned integer type.
Definition: uinteger.h:45
#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:86
#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:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:261
EventImpl * MakeEvent(void(*f)())
Make an EventImpl from a function pointer taking varying numbers of arguments.
Definition: make-event.cc:36
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:47
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
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:704
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:194
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
A structure representing data read.
Definition: fd-reader.h:91