22 #include "ns3/queue.h"
23 #include "ns3/simulator.h"
24 #include "ns3/ethernet-header.h"
25 #include "ns3/ethernet-trailer.h"
26 #include "ns3/llc-snap-header.h"
27 #include "ns3/error-model.h"
29 #include "ns3/boolean.h"
30 #include "ns3/uinteger.h"
31 #include "ns3/pointer.h"
32 #include "ns3/trace-source-accessor.h"
47 .AddConstructor<CsmaNetDevice> ()
48 .AddAttribute (
"Address",
49 "The MAC address of this device.",
52 MakeMac48AddressChecker ())
53 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
57 MakeUintegerChecker<uint16_t> ())
58 .AddAttribute (
"EncapsulationMode",
59 "The link-layer encapsulation type to use.",
64 .AddAttribute (
"SendEnable",
65 "Enable or disable the transmitter section of the device.",
68 MakeBooleanChecker ())
69 .AddAttribute (
"ReceiveEnable",
70 "Enable or disable the receiver section of the device.",
73 MakeBooleanChecker ())
74 .AddAttribute (
"ReceiveErrorModel",
75 "The receiver error model used to simulate packet loss",
78 MakePointerChecker<ErrorModel> ())
84 .AddAttribute (
"TxQueue",
85 "A queue to use as the transmit queue in the device.",
88 MakePointerChecker<Queue> ())
94 .AddTraceSource (
"MacTx",
95 "Trace source indicating a packet has arrived for transmission by this device",
97 .AddTraceSource (
"MacTxDrop",
98 "Trace source indicating a packet has been dropped by the device before transmission",
100 .AddTraceSource (
"MacPromiscRx",
101 "A packet has been received by this device, has been passed up from the physical layer "
102 "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
104 .AddTraceSource (
"MacRx",
105 "A packet has been received by this device, has been passed up from the physical layer "
106 "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
110 .AddTraceSource (
"MacRxDrop",
111 "Trace source indicating a packet was received, but dropped before being forwarded up the stack",
114 .AddTraceSource (
"MacTxBackoff",
115 "Trace source indicating a packet has been delayed by the CSMA backoff process",
121 .AddTraceSource (
"PhyTxBegin",
122 "Trace source indicating a packet has begun transmitting over the channel",
124 .AddTraceSource (
"PhyTxEnd",
125 "Trace source indicating a packet has been completely transmitted over the channel",
127 .AddTraceSource (
"PhyTxDrop",
128 "Trace source indicating a packet has been dropped by the device during transmission",
132 .AddTraceSource (
"PhyRxBegin",
133 "Trace source indicating a packet has begun being received by the device",
136 .AddTraceSource (
"PhyRxEnd",
137 "Trace source indicating a packet has been completely received by the device",
139 .AddTraceSource (
"PhyRxDrop",
140 "Trace source indicating a packet has been dropped by the device during reception",
145 .AddTraceSource (
"Sniffer",
146 "Trace source simulating a non-promiscuous packet sniffer attached to the device",
148 .AddTraceSource (
"PromiscSniffer",
149 "Trace source simulating a promiscuous packet sniffer attached to the device",
268 NS_LOG_FUNCTION (slotTime << minSlots << maxSlots << ceiling << maxRetries);
291 uint16_t lengthType = 0;
295 NS_LOG_LOGIC (
"Encapsulating packet as DIX (type interpretation)");
300 lengthType = protocolNumber;
311 memset (buffer, 0, 46);
318 NS_LOG_LOGIC (
"Encapsulating packet as LLC (length interpretation)");
340 memset (buffer, 0, 46);
346 "CsmaNetDevice::AddHeader(): 802.3 Length/Type field with LLC/SNAP: "
347 "length interpretation must not exceed device frame size minus overhead");
352 NS_FATAL_ERROR (
"CsmaNetDevice::AddHeader(): Unknown packet encapsulation mode");
356 NS_LOG_LOGIC (
"header.SetLengthType (" << lengthType <<
")");
370 CsmaNetDevice::ProcessHeader (
Ptr<Packet> p, uint16_t & param)
389 param = header.GetLengthType ();
395 param = llc.GetType ();
400 NS_FATAL_ERROR (
"CsmaNetDevice::ProcessHeader(): Unknown packet encapsulation mode");
478 NS_LOG_WARN (
"Channel TransmitStart returns an error");
662 if (senderDevice ==
this)
703 bool crcGood = trailer.
CheckFcs (packet);
933 AddHeader (packet, source, destination, protocolNumber);
941 if (
m_queue->Enqueue (packet) ==
false)
954 if (
m_queue->IsEmpty () ==
false)
uint32_t RemoveHeader(Header &header)
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
keep track of time values and allow control of global simulation resolution
void ResetBackoffTime(void)
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
#define NS_LOG_FUNCTION(parameters)
TxMachineState m_txMachineState
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
void SetReceiveEnable(bool enable)
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
CsmaNetDevice::EncapsulationMode GetEncapsulationMode(void)
void TransmitReadyEvent(void)
void AddHeader(Ptr< Packet > p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber)
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
void Receive(Ptr< Packet > p, Ptr< CsmaNetDevice > sender)
static bool ChecksumEnabled(void)
TracedCallback< Ptr< const Packet > > m_macRxTrace
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
uint64_t GetUid(void) const
Ptr< Packet > m_currentPkt
#define NS_ASSERT(condition)
void SetReceiveErrorModel(Ptr< ErrorModel > em)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
uint32_t GetSize(void) const
bool IsBroadcast(void) const
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
virtual void DoDispose(void)
#define NS_LOG_FUNCTION_NOARGS()
virtual Address GetBroadcast(void) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void SetIfIndex(const uint32_t index)
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual bool NeedsArp(void) const
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
a polymophic address class
bool MaxRetriesReached(void)
double GetSeconds(void) const
TracedCallback m_linkChangeCallbacks
void AddAtEnd(Ptr< const Packet > packet)
double CalculateTxTime(uint32_t bytes) const
Calculate transmission time.
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
virtual bool IsLinkUp(void) const
void SetQueue(Ptr< Queue > queue)
TracedCallback< Ptr< const Packet > > m_snifferTrace
hold variables of type 'enum'
bool CheckFcs(Ptr< const Packet > p) const
static TypeId GetTypeId(void)
static Mac48Address GetMulticast(Ipv4Address address)
void TransmitCompleteEvent(void)
Hold an unsigned integer type.
bool IsReceiveEnabled(void)
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual Ptr< Node > GetNode(void) const
Ptr< Queue > GetQueue(void) const
void SetInterframeGap(Time t)
virtual Address GetAddress(void) const
#define NS_LOG_LOGIC(msg)
virtual uint32_t GetIfIndex(void) const
static Mac48Address ConvertFrom(const Address &address)
virtual uint16_t GetMtu(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Ptr< Packet > Copy(void) const
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
Packet trailer for Ethernet.
hold objects of type Ptr<T>
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Ptr< ErrorModel > m_receiveErrorModel
void AddTrailer(const Trailer &trailer)
Ptr< CsmaChannel > m_channel
void RemoveAtEnd(uint32_t size)
static const uint16_t DEFAULT_MTU
uint32_t RemoveTrailer(Trailer &trailer)
virtual Ptr< Channel > GetChannel(void) const
virtual bool IsBridge(void) const
int64_t AssignStreams(int64_t stream)
virtual bool SetMtu(const uint16_t mtu)
virtual bool SupportsSendFrom(void) const
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
#define NS_ASSERT_MSG(condition, message)
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
EncapsulationMode m_encapMode
NetDevice::ReceiveCallback m_rxCallback
void SetBackoffParams(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t maxRetries, uint32_t ceiling)
void ConnectWithoutContext(const CallbackBase &callback)
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
Network layer to device interface.
hold objects of type ns3::Mac48Address
void SetSendEnable(bool enable)
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
int64_t AssignStreams(int64_t stream)
NetDevice::PromiscReceiveCallback m_promiscRxCallback
virtual void SetAddress(Address address)
virtual void AddLinkChangeCallback(Callback< void > callback)
bool Attach(Ptr< CsmaChannel > ch)
virtual void SetNode(Ptr< Node > node)
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual bool IsMulticast(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual void DoDispose(void)
a unique identifier for an interface.
virtual bool IsBroadcast(void) const
TypeId SetParent(TypeId tid)
void AddHeader(const Header &header)
virtual bool IsPointToPoint(void) const
TracedCallback< Ptr< const Packet > > m_macTxTrace
void IncrNumRetries(void)