A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
csma-net-device.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Emmanuelle Laprise
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
7 */
8
9#include "csma-net-device.h"
10
11#include "csma-channel.h"
12
13#include "ns3/boolean.h"
14#include "ns3/enum.h"
15#include "ns3/error-model.h"
16#include "ns3/ethernet-header.h"
17#include "ns3/ethernet-trailer.h"
18#include "ns3/llc-snap-header.h"
19#include "ns3/log.h"
20#include "ns3/pointer.h"
21#include "ns3/queue.h"
22#include "ns3/simulator.h"
23#include "ns3/trace-source-accessor.h"
24#include "ns3/uinteger.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("CsmaNetDevice");
30
31NS_OBJECT_ENSURE_REGISTERED(CsmaNetDevice);
32
33TypeId
35{
36 static TypeId tid =
37 TypeId("ns3::CsmaNetDevice")
39 .SetGroupName("Csma")
40 .AddConstructor<CsmaNetDevice>()
41 .AddAttribute("Address",
42 "The MAC address of this device.",
43 Mac48AddressValue(Mac48Address("ff:ff:ff:ff:ff:ff")),
46 .AddAttribute("Mtu",
47 "The MAC-level Maximum Transmission Unit",
51 .AddAttribute("EncapsulationMode",
52 "The link-layer encapsulation type to use.",
55 MakeEnumChecker(DIX, "Dix", LLC, "Llc"))
56 .AddAttribute("SendEnable",
57 "Enable or disable the transmitter section of the device.",
58 BooleanValue(true),
61 .AddAttribute("ReceiveEnable",
62 "Enable or disable the receiver section of the device.",
63 BooleanValue(true),
66 .AddAttribute("ReceiveErrorModel",
67 "The receiver error model used to simulate packet loss",
71
72 //
73 // Transmit queueing discipline for the device which includes its own set
74 // of trace hooks.
75 //
76 .AddAttribute("TxQueue",
77 "A queue to use as the transmit queue in the device.",
81
82 //
83 // Trace sources at the "top" of the net device, where packets transition
84 // to/from higher layers.
85 //
86 .AddTraceSource("MacTx",
87 "Trace source indicating a packet has "
88 "arrived for transmission by this device",
90 "ns3::Packet::TracedCallback")
91 .AddTraceSource("MacTxDrop",
92 "Trace source indicating a packet has been "
93 "dropped by the device before transmission",
95 "ns3::Packet::TracedCallback")
96 .AddTraceSource("MacPromiscRx",
97 "A packet has been received by this device, "
98 "has been passed up from the physical layer "
99 "and is being forwarded up the local protocol stack. "
100 "This is a promiscuous trace,",
102 "ns3::Packet::TracedCallback")
103 .AddTraceSource("MacRx",
104 "A packet has been received by this device, "
105 "has been passed up from the physical layer "
106 "and is being forwarded up the local protocol stack. "
107 "This is a non-promiscuous trace,",
109 "ns3::Packet::TracedCallback")
110#if 0
111 // Not currently implemented in this device
112 .AddTraceSource ("MacRxDrop",
113 "Trace source indicating a packet was received, "
114 "but dropped before being forwarded up the stack",
116 "ns3::Packet::TracedCallback")
117#endif
118 .AddTraceSource("MacTxBackoff",
119 "Trace source indicating a packet has been "
120 "delayed by the CSMA backoff process",
122 "ns3::Packet::TracedCallback")
123 //
124 // Trace sources at the "bottom" of the net device, where packets transition
125 // to/from the channel.
126 //
127 .AddTraceSource("PhyTxBegin",
128 "Trace source indicating a packet has "
129 "begun transmitting over the channel",
131 "ns3::Packet::TracedCallback")
132 .AddTraceSource("PhyTxEnd",
133 "Trace source indicating a packet has been "
134 "completely transmitted over the channel",
136 "ns3::Packet::TracedCallback")
137 .AddTraceSource("PhyTxDrop",
138 "Trace source indicating a packet has been "
139 "dropped by the device during transmission",
141 "ns3::Packet::TracedCallback")
142#if 0
143 // Not currently implemented in this device
144 .AddTraceSource ("PhyRxBegin",
145 "Trace source indicating a packet has "
146 "begun being received by the device",
148 "ns3::Packet::TracedCallback")
149#endif
150 .AddTraceSource("PhyRxEnd",
151 "Trace source indicating a packet has been "
152 "completely received by the device",
154 "ns3::Packet::TracedCallback")
155 .AddTraceSource("PhyRxDrop",
156 "Trace source indicating a packet has been "
157 "dropped by the device during reception",
159 "ns3::Packet::TracedCallback")
160 //
161 // Trace sources designed to simulate a packet sniffer facility (tcpdump).
162 //
163 .AddTraceSource("Sniffer",
164 "Trace source simulating a non-promiscuous "
165 "packet sniffer attached to the device",
167 "ns3::Packet::TracedCallback")
168 .AddTraceSource("PromiscSniffer",
169 "Trace source simulating a promiscuous "
170 "packet sniffer attached to the device",
172 "ns3::Packet::TracedCallback");
173 return tid;
174}
175
177 : m_linkUp(false)
178{
179 NS_LOG_FUNCTION(this);
182 m_channel = nullptr;
183
184 //
185 // We would like to let the attribute system take care of initializing the
186 // packet encapsulation stuff, but we also don't want to get caught up in
187 // initialization order changes. So we'll get the three problem variables
188 // into a consistent state here before the attribute calls, and then depend
189 // on the semantics of the setters to preserve a consistent state. This
190 // really doesn't have to be the same set of values as the initial values
191 // set by the attributes, but it does have to be a consistent set. That is,
192 // you can just change the default encapsulation mode above without having
193 // to change it here.
194 //
196}
197
203
204void
206{
208 m_channel = nullptr;
209 m_node = nullptr;
210 m_queue = nullptr;
212}
213
214void
216{
217 NS_LOG_FUNCTION(mode);
218
219 m_encapMode = mode;
220
221 NS_LOG_LOGIC("m_encapMode = " << m_encapMode);
222 NS_LOG_LOGIC("m_mtu = " << m_mtu);
223}
224
231
232bool
234{
235 NS_LOG_FUNCTION(this << mtu);
236 m_mtu = mtu;
237
238 NS_LOG_LOGIC("m_encapMode = " << m_encapMode);
239 NS_LOG_LOGIC("m_mtu = " << m_mtu);
240
241 return true;
242}
243
244uint16_t
246{
248 return m_mtu;
249}
250
251void
253{
254 NS_LOG_FUNCTION(sendEnable);
255 m_sendEnable = sendEnable;
256}
257
258void
260{
261 NS_LOG_FUNCTION(receiveEnable);
262 m_receiveEnable = receiveEnable;
263}
264
265bool
271
272bool
278
279void
285
286void
288 uint32_t minSlots,
289 uint32_t maxSlots,
290 uint32_t ceiling,
291 uint32_t maxRetries)
292{
293 NS_LOG_FUNCTION(slotTime << minSlots << maxSlots << ceiling << maxRetries);
294 m_backoff.m_slotTime = slotTime;
295 m_backoff.m_minSlots = minSlots;
296 m_backoff.m_maxSlots = maxSlots;
297 m_backoff.m_ceiling = ceiling;
298 m_backoff.m_maxRetries = maxRetries;
299}
300
301void
303 Mac48Address source,
304 Mac48Address dest,
305 uint16_t protocolNumber)
306{
307 NS_LOG_FUNCTION(p << source << dest << protocolNumber);
308
309 EthernetHeader header(false);
310 header.SetSource(source);
311 header.SetDestination(dest);
312
313 EthernetTrailer trailer;
314
315 NS_LOG_LOGIC("p->GetSize () = " << p->GetSize());
316 NS_LOG_LOGIC("m_encapMode = " << m_encapMode);
317 NS_LOG_LOGIC("m_mtu = " << m_mtu);
318
319 uint16_t lengthType = 0;
320 switch (m_encapMode)
321 {
322 case DIX:
323 NS_LOG_LOGIC("Encapsulating packet as DIX (type interpretation)");
324 //
325 // This corresponds to the type interpretation of the lengthType field as
326 // in the old Ethernet Blue Book.
327 //
328 lengthType = protocolNumber;
329
330 //
331 // All Ethernet frames must carry a minimum payload of 46 bytes. We need
332 // to pad out if we don't have enough bytes. These must be real bytes
333 // since they will be written to pcap files and compared in regression
334 // trace files.
335 //
336 if (p->GetSize() < 46)
337 {
338 uint8_t buffer[46];
339 memset(buffer, 0, 46);
340 Ptr<Packet> padd = Create<Packet>(buffer, 46 - p->GetSize());
341 p->AddAtEnd(padd);
342 }
343 break;
344 case LLC: {
345 NS_LOG_LOGIC("Encapsulating packet as LLC (length interpretation)");
346
347 LlcSnapHeader llc;
348 llc.SetType(protocolNumber);
349 p->AddHeader(llc);
350
351 //
352 // This corresponds to the length interpretation of the lengthType
353 // field but with an LLC/SNAP header added to the payload as in
354 // IEEE 802.2
355 //
356 lengthType = p->GetSize();
357
358 //
359 // All Ethernet frames must carry a minimum payload of 46 bytes. The
360 // LLC SNAP header counts as part of this payload. We need to pad out
361 // if we don't have enough bytes. These must be real bytes since they
362 // will be written to pcap files and compared in regression trace files.
363 //
364 if (p->GetSize() < 46)
365 {
366 uint8_t buffer[46];
367 memset(buffer, 0, 46);
368 Ptr<Packet> padd = Create<Packet>(buffer, 46 - p->GetSize());
369 p->AddAtEnd(padd);
370 }
371
372 NS_ASSERT_MSG(p->GetSize() <= GetMtu(),
373 "CsmaNetDevice::AddHeader(): 802.3 Length/Type field with LLC/SNAP: "
374 "length interpretation must not exceed device frame size minus overhead");
375 }
376 break;
377 case ILLEGAL:
378 default:
379 NS_FATAL_ERROR("CsmaNetDevice::AddHeader(): Unknown packet encapsulation mode");
380 break;
381 }
382
383 NS_LOG_LOGIC("header.SetLengthType (" << lengthType << ")");
384 header.SetLengthType(lengthType);
385 p->AddHeader(header);
386
388 {
389 trailer.EnableFcs(true);
390 }
391 trailer.CalcFcs(p);
392 p->AddTrailer(trailer);
393}
394
395#if 0
396bool
397CsmaNetDevice::ProcessHeader (Ptr<Packet> p, uint16_t & param)
398{
399 NS_LOG_FUNCTION (p << param);
400
401 EthernetTrailer trailer;
402 p->RemoveTrailer (trailer);
403
404 EthernetHeader header (false);
405 p->RemoveHeader (header);
406
407 if ((header.GetDestination () != GetBroadcast ()) &&
408 (header.GetDestination () != GetAddress ()))
409 {
410 return false;
411 }
412
413 switch (m_encapMode)
414 {
415 case DIX:
416 param = header.GetLengthType ();
417 break;
418 case LLC:
419 {
420 LlcSnapHeader llc;
421 p->RemoveHeader (llc);
422 param = llc.GetType ();
423 }
424 break;
425 case ILLEGAL:
426 default:
427 NS_FATAL_ERROR ("CsmaNetDevice::ProcessHeader(): Unknown packet encapsulation mode");
428 break;
429 }
430 return true;
431}
432#endif
433
434void
436{
438
439 //
440 // This function is called to start the process of transmitting a packet. We
441 // expect that the packet to transmit will be found in m_currentPkt.
442 //
443 NS_ASSERT_MSG(m_currentPkt, "CsmaNetDevice::TransmitStart(): m_currentPkt not set");
444
445 NS_LOG_LOGIC("m_currentPkt = " << m_currentPkt);
446 NS_LOG_LOGIC("UID = " << m_currentPkt->GetUid());
447
448 //
449 // Only transmit if the send side of net device is enabled
450 //
451 if (!IsSendEnabled())
452 {
454 m_currentPkt = nullptr;
455 return;
456 }
457
458 //
459 // Somebody has called here telling us to start transmitting a packet. They
460 // can only do this if the state machine is in the READY or BACKOFF state.
461 // Specifically, if we are ready to start transmitting, we cannot already
462 // be transmitting (i.e., BUSY)
463 //
465 "Must be READY to transmit. Tx state is: " << m_txMachineState);
466
467 //
468 // Now we have to sense the state of the medium and either start transmitting
469 // if it is idle, or backoff our transmission if someone else is on the wire.
470 //
471 if (m_channel->GetState() != IDLE)
472 {
473 //
474 // The channel is busy -- backoff and rechedule TransmitStart() unless
475 // we have exhausted all of our retries.
476 //
478
480 {
481 //
482 // Too many retries, abort transmission of packet
483 //
485 }
486 else
487 {
489
491 Time backoffTime = m_backoff.GetBackoffTime();
492
493 NS_LOG_LOGIC("Channel busy, backing off for " << backoffTime.As(Time::S));
494
496 }
497 }
498 else
499 {
500 //
501 // The channel is free, transmit the packet
502 //
504 if (!m_channel->TransmitStart(m_currentPkt, m_deviceId))
505 {
506 NS_LOG_WARN("Channel TransmitStart returns an error");
508 m_currentPkt = nullptr;
510 }
511 else
512 {
513 //
514 // Transmission succeeded, reset the backoff time parameters and
515 // schedule a transmit complete event.
516 //
519
521 NS_LOG_LOGIC("Schedule TransmitCompleteEvent in " << tEvent.As(Time::S));
523 }
524 }
525}
526
527void
529{
531
532 //
533 // When we started the process of transmitting the current packet, it was
534 // placed in m_currentPkt. So we had better find one there.
535 //
536 NS_ASSERT_MSG(m_currentPkt, "CsmaNetDevice::TransmitAbort(): m_currentPkt zero");
537 NS_LOG_LOGIC("m_currentPkt=" << m_currentPkt);
538 NS_LOG_LOGIC("Pkt UID is " << m_currentPkt->GetUid() << ")");
539
541 m_currentPkt = nullptr;
542
544 "Must be in BACKOFF state to abort. Tx state is: " << m_txMachineState);
545
546 //
547 // We're done with that one, so reset the backoff algorithm and ready the
548 // transmit state machine.
549 //
552
553 //
554 // If there is another packet on the input queue, we need to start trying to
555 // get that out. If the queue is empty we just wait until someone puts one
556 // in.
557 //
558 if (m_queue->IsEmpty())
559 {
560 return;
561 }
562 else
563 {
564 Ptr<Packet> packet = m_queue->Dequeue();
565 NS_ASSERT_MSG(packet,
566 "CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?");
567 m_currentPkt = packet;
571 }
572}
573
574void
576{
578
579 //
580 // This function is called to finish the process of transmitting a packet.
581 // We need to tell the channel that we've stopped wiggling the wire and
582 // schedule an event that will be executed when it's time to re-enable
583 // the transmitter after the interframe gap.
584 //
586 "CsmaNetDevice::transmitCompleteEvent(): Must be BUSY if transmitting");
587 NS_ASSERT(m_channel->GetState() == TRANSMITTING);
589
590 //
591 // When we started transmitting the current packet, it was placed in
592 // m_currentPkt. So we had better find one there.
593 //
594 NS_ASSERT_MSG(m_currentPkt, "CsmaNetDevice::TransmitCompleteEvent(): m_currentPkt zero");
595 NS_LOG_LOGIC("m_currentPkt=" << m_currentPkt);
596 NS_LOG_LOGIC("Pkt UID is " << m_currentPkt->GetUid() << ")");
597
598 m_channel->TransmitEnd();
600 m_currentPkt = nullptr;
601
602 NS_LOG_LOGIC("Schedule TransmitReadyEvent in " << m_tInterframeGap.As(Time::S));
603
605}
606
607void
609{
611
612 //
613 // This function is called to enable the transmitter after the interframe
614 // gap has passed. If there are pending transmissions, we use this opportunity
615 // to start the next transmit.
616 //
618 "CsmaNetDevice::TransmitReadyEvent(): Must be in interframe gap");
620
621 //
622 // We expect that the packet we had been transmitting was cleared when the
623 // TransmitCompleteEvent() was executed.
624 //
625 NS_ASSERT_MSG(!m_currentPkt, "CsmaNetDevice::TransmitReadyEvent(): m_currentPkt nonzero");
626
627 //
628 // Get the next packet from the queue for transmitting
629 //
630 if (m_queue->IsEmpty())
631 {
632 return;
633 }
634 else
635 {
636 Ptr<Packet> packet = m_queue->Dequeue();
637 NS_ASSERT_MSG(packet,
638 "CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?");
639 m_currentPkt = packet;
643 }
644}
645
646bool
648{
649 NS_LOG_FUNCTION(this << &ch);
650
651 m_channel = ch;
652
653 m_deviceId = m_channel->Attach(this);
654
655 //
656 // The channel provides us with the transmitter data rate.
657 //
658 m_bps = m_channel->GetDataRate();
659
660 //
661 // We use the Ethernet interframe gap of 96 bit times.
662 //
664
665 //
666 // This device is up whenever a channel is attached to it.
667 //
668 NotifyLinkUp();
669 return true;
670}
671
672void
678
679void
685
686void
688{
689 NS_LOG_FUNCTION(packet << senderDevice);
690 NS_LOG_LOGIC("UID is " << packet->GetUid());
691
692 //
693 // We never forward up packets that we sent. Real devices don't do this since
694 // their receivers are disabled during send, so we don't.
695 //
696 if (senderDevice == this)
697 {
698 return;
699 }
700
701 //
702 // Hit the trace hook. This trace will fire on all packets received from the
703 // channel except those originated by this device.
704 //
705 m_phyRxEndTrace(packet);
706
707 //
708 // Only receive if the send side of net device is enabled
709 //
710 if (!IsReceiveEnabled())
711 {
712 m_phyRxDropTrace(packet);
713 return;
714 }
715
716 Ptr<Packet> pktCopy = packet->Copy();
717
718 if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt(pktCopy))
719 {
720 NS_LOG_LOGIC("Dropping pkt due to error model ");
721 m_phyRxDropTrace(packet);
722 return;
723 }
724
725 //
726 // Trace sinks will expect complete packets, not packets without some of the
727 // headers.
728 //
729
730 EthernetTrailer trailer;
731 pktCopy->RemoveTrailer(trailer);
733 {
734 trailer.EnableFcs(true);
735 }
736
737 bool crcGood = trailer.CheckFcs(pktCopy);
738 if (!crcGood)
739 {
740 NS_LOG_INFO("CRC error on Packet " << packet);
741 m_phyRxDropTrace(packet);
742 return;
743 }
744
745 EthernetHeader header(false);
746 pktCopy->RemoveHeader(header);
747
748 NS_LOG_LOGIC("Pkt source is " << header.GetSource());
749 NS_LOG_LOGIC("Pkt destination is " << header.GetDestination());
750
751 uint16_t protocol;
752 //
753 // If the length/type is less than 1500, it corresponds to a length
754 // interpretation packet. In this case, it is an 802.3 packet and
755 // will also have an 802.2 LLC header. If greater than 1500, we
756 // find the protocol number (Ethernet type) directly.
757 //
758 if (header.GetLengthType() <= 1500)
759 {
760 NS_ASSERT(pktCopy->GetSize() >= header.GetLengthType());
761 uint32_t padlen = pktCopy->GetSize() - header.GetLengthType();
762 NS_ASSERT(padlen <= 46);
763 if (padlen > 0)
764 {
765 pktCopy->RemoveAtEnd(padlen);
766 }
767
768 LlcSnapHeader llc;
769 pktCopy->RemoveHeader(llc);
770 protocol = llc.GetType();
771 }
772 else
773 {
774 protocol = header.GetLengthType();
775 }
776
777 //
778 // Classify the packet based on its destination.
779 //
780 PacketType packetType;
781
782 if (header.GetDestination().IsBroadcast())
783 {
784 packetType = PACKET_BROADCAST;
785 }
786 else if (header.GetDestination().IsGroup())
787 {
788 packetType = PACKET_MULTICAST;
789 }
790 else if (header.GetDestination() == m_address)
791 {
792 packetType = PACKET_HOST;
793 }
794 else
795 {
796 packetType = PACKET_OTHERHOST;
797 }
798
799 //
800 // For all kinds of packetType we receive, we hit the promiscuous sniffer
801 // hook and pass a copy up to the promiscuous callback. Pass a copy to
802 // make sure that nobody messes with our packet.
803 //
804 m_promiscSnifferTrace(packet);
806 {
807 m_macPromiscRxTrace(packet);
809 pktCopy,
810 protocol,
811 header.GetSource(),
812 header.GetDestination(),
813 packetType);
814 }
815
816 //
817 // If this packet is not destined for some other host, it must be for us
818 // as either a broadcast, multicast or unicast. We need to hit the mac
819 // packet received trace hook and forward the packet up the stack.
820 //
821 if (packetType != PACKET_OTHERHOST)
822 {
823 m_snifferTrace(packet);
824 m_macRxTrace(packet);
825 m_rxCallback(this, pktCopy, protocol, header.GetSource());
826 }
827}
828
831{
833 return m_queue;
834}
835
836void
843
844void
846{
847 NS_LOG_FUNCTION(index);
848 m_ifIndex = index;
849}
850
853{
855 return m_ifIndex;
856}
857
860{
862 return m_channel;
863}
864
865void
871
874{
876 return m_address;
877}
878
879bool
881{
883 return m_linkUp;
884}
885
886void
892
893bool
895{
897 return true;
898}
899
906
907bool
909{
911 return true;
912}
913
916{
917 NS_LOG_FUNCTION(multicastGroup);
918
919 Mac48Address ad = Mac48Address::GetMulticast(multicastGroup);
920
921 //
922 // Implicit conversion (operator Address ()) is defined for Mac48Address, so
923 // use it by just returning the EUI-48 address which is automagically converted
924 // to an Address.
925 //
926 NS_LOG_LOGIC("multicast address is " << ad);
927
928 return ad;
929}
930
931bool
933{
935 return false;
936}
937
938bool
940{
942 return false;
943}
944
945bool
946CsmaNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
947{
948 NS_LOG_FUNCTION(packet << dest << protocolNumber);
949 return SendFrom(packet, m_address, dest, protocolNumber);
950}
951
952bool
954 const Address& src,
955 const Address& dest,
956 uint16_t protocolNumber)
957{
958 NS_LOG_FUNCTION(packet << src << dest << protocolNumber);
959 NS_LOG_LOGIC("packet =" << packet);
960 NS_LOG_LOGIC("UID is " << packet->GetUid() << ")");
961
963
964 //
965 // Only transmit if send side of net device is enabled
966 //
967 if (!IsSendEnabled())
968 {
969 m_macTxDropTrace(packet);
970 return false;
971 }
972
973 Mac48Address destination = Mac48Address::ConvertFrom(dest);
975 AddHeader(packet, source, destination, protocolNumber);
976
977 m_macTxTrace(packet);
978
979 //
980 // Place the packet to be sent on the send queue. Note that the
981 // queue may fire a drop trace, but we will too.
982 //
983 if (!m_queue->Enqueue(packet))
984 {
985 m_macTxDropTrace(packet);
986 return false;
987 }
988
989 //
990 // If the device is idle, we need to start a transmission. Otherwise,
991 // the transmission will be started when the current packet finished
992 // transmission (see TransmitCompleteEvent)
993 //
994 if (m_txMachineState == READY)
995 {
996 if (!m_queue->IsEmpty())
997 {
998 Ptr<Packet> packet = m_queue->Dequeue();
999 NS_ASSERT_MSG(packet,
1000 "CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?");
1001 m_currentPkt = packet;
1004 TransmitStart();
1005 }
1006 }
1007 return true;
1008}
1009
1012{
1014 return m_node;
1015}
1016
1017void
1019{
1020 NS_LOG_FUNCTION(node);
1021
1022 m_node = node;
1023}
1024
1025bool
1027{
1029 return true;
1030}
1031
1032void
1038
1039Address
1041{
1043
1044 NS_LOG_LOGIC("MAC IPv6 multicast address is " << ad);
1045 return ad;
1046}
1047
1048void
1054
1055bool
1057{
1059 return true;
1060}
1061
1062int64_t
1064{
1065 return m_backoff.AssignStreams(stream);
1066}
1067
1068} // namespace ns3
a polymophic address class
Definition address.h:90
void ResetBackoffTime()
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
Definition backoff.cc:74
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
Definition backoff.h:50
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition backoff.cc:92
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time)
Definition backoff.h:40
bool MaxRetriesReached() const
Definition backoff.cc:80
void IncrNumRetries()
Increments the number of retries by 1.
Definition backoff.cc:86
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time)
Definition backoff.h:34
Time GetBackoffTime()
Definition backoff.cc:47
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
Definition backoff.h:45
Time m_slotTime
Length of one slot.
Definition backoff.h:56
AttributeValue implementation for Boolean.
Definition boolean.h:26
Callback template class.
Definition callback.h:422
bool IsNull() const
Check for null implementation.
Definition callback.h:555
A Device for a Csma Network Link.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
Ptr< Queue< Packet > > GetQueue() const
Get a copy of the attached Queue.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
Ptr< Node > GetNode() const override
Get the node to which this device is attached.
EncapsulationMode
Enumeration of the types of packets supported in the class.
@ ILLEGAL
Encapsulation mode not set.
@ DIX
DIX II / Ethernet II packet.
@ LLC
802.2 LLC/SNAP Packet
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
The trace source fired when the mac layer is forced to begin the backoff process for a packet.
void SetReceiveEnable(bool enable)
Enable or disable the receive side of the network device.
Backoff m_backoff
Holds the backoff parameters and is used to calculate the next backoff time to use when the channel i...
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
void DoDispose() override
Perform any object release functionality required to break reference cycles in reference counted obje...
~CsmaNetDevice() override
Destroy a CsmaNetDevice.
bool SetMtu(const uint16_t mtu) override
void TransmitAbort()
Aborts the transmission of the current packet.
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
bool NeedsArp() const override
Does this device need to use the address resolution protocol?
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void TransmitStart()
Start Sending a Packet Down the Wire.
void SetIfIndex(const uint32_t index) override
@ BACKOFF
The transmitter is waiting for the channel to be free.
@ READY
The transmitter is ready to begin transmission of a packet.
@ BUSY
The transmitter is busy transmitting a packet.
@ GAP
The transmitter is in the interframe gap time.
Ptr< Queue< Packet > > m_queue
The Queue which this CsmaNetDevice uses as a packet source.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
uint32_t m_mtu
The Maximum Transmission Unit.
bool SupportsSendFrom() const override
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
CsmaNetDevice()
Construct a CsmaNetDevice.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
Address GetBroadcast() const override
static TypeId GetTypeId()
Get the type ID.
bool IsPointToPoint() const override
Is this a point to point link?
Ptr< CsmaChannel > m_channel
The CsmaChannel to which this CsmaNetDevice has been attached.
bool Attach(Ptr< CsmaChannel > ch)
Attach the device to a channel.
bool IsBridge() const override
Is this a bridge?
void TransmitCompleteEvent()
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
Start sending a packet down the channel, with MAC spoofing.
void Receive(Ptr< const Packet > p, Ptr< CsmaNetDevice > sender)
Receive a packet from a connected CsmaChannel.
bool IsMulticast() const override
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
CsmaNetDevice::EncapsulationMode GetEncapsulationMode()
Get the encapsulation mode of this device.
void AddHeader(Ptr< Packet > p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the packet type.
uint16_t GetMtu() const override
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< Channel > GetChannel() const override
void NotifyLinkUp()
Notify any interested parties that the link has come up.
void SetBackoffParams(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t maxRetries, uint32_t ceiling)
Set the backoff parameters used to determine the wait to retry transmitting a packet when the channel...
Ptr< Packet > m_currentPkt
Next packet that will be transmitted (if transmitter is not currently transmitting) or packet that is...
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
uint32_t m_deviceId
Device ID returned by the attached functions.
bool m_receiveEnable
Enable net device to receive packets.
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.
Ptr< Node > m_node
The Node to which this device is attached.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the CsmaNetDevice.
void SetSendEnable(bool enable)
Enable or disable the send side of the network device.
bool IsLinkUp() const override
void TransmitReadyEvent()
Cause the Transmitter to Become Ready to Send Another Packet.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
uint32_t GetIfIndex() const override
bool IsBroadcast() const override
static const uint16_t DEFAULT_MTU
Default Maximum Transmission Unit (MTU) for the CsmaNetDevice.
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
bool m_sendEnable
Enable net device to send packets.
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...
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Start sending a packet down the channel.
bool IsSendEnabled() const
Is the send side of the network device enabled?
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
Set the callback to be used to notify higher layers when a packet has been received.
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Address GetAddress() const override
void AddLinkChangeCallback(Callback< void > callback) override
void SetNode(Ptr< Node > node) override
Set the node to which this device is being attached.
void SetAddress(Address address) override
Set the address of this interface.
Mac48Address m_address
The MAC address which has been assigned to this device.
Time m_tInterframeGap
The interframe gap that the Net Device uses insert time between packet transmission.
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the CsmaNetDevice.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
uint32_t m_ifIndex
The interface index (really net evice index) that has been assigned to this network device.
bool IsReceiveEnabled() const
Is the receive side of the network device enabled?
bool m_linkUp
Flag indicating whether or not the link is up.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
Definition data-rate.cc:220
Hold variables of type enum.
Definition enum.h:52
Packet header for Ethernet.
uint16_t GetLengthType() const
void SetDestination(Mac48Address destination)
Mac48Address GetDestination() const
void SetLengthType(uint16_t size)
void SetSource(Mac48Address source)
Mac48Address GetSource() const
Packet trailer for Ethernet.
bool CheckFcs(Ptr< const Packet > p) const
Calculate an FCS on the provided packet and check this value against the FCS found when the trailer w...
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
Header for the LLC/SNAP encapsulation.
uint16_t GetType()
Return the Ethertype.
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
static Mac48Address GetMulticast(Ipv4Address address)
bool IsGroup() const
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
bool IsBroadcast() const
AttributeValue implementation for Mac48Address.
Network layer to device interface.
Definition net-device.h:87
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
@ PACKET_HOST
Packet addressed to us.
Definition net-device.h:290
@ PACKET_OTHERHOST
Packet addressed to someone else.
Definition net-device.h:296
@ PACKET_BROADCAST
Packet addressed to all.
Definition net-device.h:292
@ PACKET_MULTICAST
Packet addressed to multicast group.
Definition net-device.h:294
static bool ChecksumEnabled()
Definition node.cc:267
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition packet.h:850
uint64_t GetUid() const
Returns the packet's Uid.
Definition packet.cc:401
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Template class for packet Queues.
Definition queue.h:257
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ S
second
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:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition boolean.h:70
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:221
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()
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:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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:35
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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:250
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:179
@ TRANSMITTING
Channel is BUSY, a packet is being written by a net device.
@ IDLE
Channel is IDLE, no packet is being transmitted.