22 #include "ns3/queue.h"
23 #include "ns3/simulator.h"
25 #include "ns3/boolean.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/pointer.h"
28 #include "ns3/channel.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "aloha-noack-mac-header.h"
31 #include "aloha-noack-net-device.h"
32 #include "ns3/llc-snap-header.h"
40 std::ostream&
operator<< (std::ostream& os, AlohaNoackNetDevice::State state)
44 case AlohaNoackNetDevice::IDLE:
47 case AlohaNoackNetDevice::TX:
50 case AlohaNoackNetDevice::RX:
58 NS_OBJECT_ENSURE_REGISTERED (AlohaNoackNetDevice);
61 AlohaNoackNetDevice::GetTypeId (
void)
63 static TypeId tid = TypeId (
"ns3::AlohaNoackNetDevice")
64 .SetParent<NetDevice> ()
65 .AddConstructor<AlohaNoackNetDevice> ()
66 .AddAttribute (
"Address",
67 "The MAC address of this device.",
68 Mac48AddressValue (Mac48Address (
"12:34:56:78:90:12")),
69 MakeMac48AddressAccessor (&AlohaNoackNetDevice::m_address),
70 MakeMac48AddressChecker ())
71 .AddAttribute (
"Queue",
72 "packets being transmitted get queued here",
74 MakePointerAccessor (&AlohaNoackNetDevice::m_queue),
75 MakePointerChecker<Queue> ())
76 .AddAttribute (
"Mtu",
"The Maximum Transmission Unit",
80 MakeUintegerChecker<uint16_t> (1,65535))
81 .AddAttribute (
"Phy",
"The PHY layer attached to this device.",
85 MakePointerChecker<Object> ())
86 .AddTraceSource (
"MacTx",
87 "Trace source indicating a packet has arrived for transmission by this device",
89 .AddTraceSource (
"MacTxDrop",
90 "Trace source indicating a packet has been dropped by the device before transmission",
92 .AddTraceSource (
"MacPromiscRx",
93 "A packet has been received by this device, has been passed up from the physical layer "
94 "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
96 .AddTraceSource (
"MacRx",
97 "A packet has been received by this device, has been passed up from the physical layer "
98 "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
104 AlohaNoackNetDevice::AlohaNoackNetDevice ()
110 AlohaNoackNetDevice::~AlohaNoackNetDevice ()
125 m_phyMacTxStartCallback = MakeNullCallback< bool, Ptr<Packet> > ();
314 m_promiscRxCallback = cb;
329 return SendFrom (packet, m_address, dest, protocolNumber);
338 llc.SetType (protocolNumber);
346 m_macTxTrace (packet);
357 if (m_queue->IsEmpty ())
359 NS_LOG_LOGIC (
"new packet is head of queue, starting TX immediately");
360 m_currentPkt = packet;
366 if (m_queue->Enqueue (packet) ==
false)
368 m_macTxDropTrace (packet);
377 if (m_queue->Enqueue (packet) ==
false)
379 m_macTxDropTrace (packet);
390 m_phyMacTxStartCallback = c;
401 if (m_phyMacTxStartCallback (m_currentPkt))
417 NS_ASSERT_MSG (m_state == TX,
"TX end notified while state != TX");
420 if (m_queue->IsEmpty () ==
false)
422 m_currentPkt = m_queue->Dequeue ();
454 NS_LOG_LOGIC (
"packet " << header.GetSource () <<
" --> " << header.GetDestination () <<
" (here: " << m_address <<
")");
464 else if (header.GetDestination ().
IsGroup ())
468 else if (header.GetDestination () == m_address)
479 if (!m_promiscRxCallback.IsNull ())
481 m_promiscRxCallback (
this, packet->
Copy (), llc.GetType (), header.GetSource (), header.GetDestination (), packetType);
486 m_rxCallback (
this, packet, llc.GetType (), header.GetSource () );
uint32_t RemoveHeader(Header &header)
virtual void SetIfIndex(const uint32_t index)
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void NotifyReceptionStart()
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual Address GetMulticast(Ipv4Address addr) const
Make and return a MAC multicast address using the provided multicast group.
void SetGenericPhyTxStartCallback(GenericPhyTxStartCallback c)
virtual Address GetBroadcast(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
bool IsBroadcast(void) const
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual void DoDispose(void)
TracedCallback m_linkChangeCallbacks
a polymophic address class
virtual Ptr< Node > GetNode(void) const
void NotifyReceptionEndOk(Ptr< Packet > p)
static Mac48Address GetMulticast(Ipv4Address address)
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual uint16_t GetMtu(void) const
virtual bool IsBroadcast(void) const
void NotifyTransmissionEnd(Ptr< const Packet >)
virtual bool SetMtu(const uint16_t mtu)
#define NS_LOG_LOGIC(msg)
static Mac48Address ConvertFrom(const Address &address)
virtual void DoDispose(void)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< Packet > Copy(void) const
virtual bool IsLinkUp(void) const
virtual bool SupportsSendFrom(void) const
void SetChannel(Ptr< Channel > c)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual bool NeedsArp(void) const
Ptr< Object > GetPhy() const
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
virtual void SetQueue(Ptr< Queue > queue)
virtual bool IsMulticast(void) const
#define NS_ASSERT_MSG(condition, message)
void NotifyReceptionEndError()
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
void ConnectWithoutContext(const CallbackBase &callback)
void SetPhy(Ptr< Object > phy)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual uint32_t GetIfIndex(void) const
virtual void SetNode(Ptr< Node > node)
void AddHeader(const Header &header)
virtual Ptr< Channel > GetChannel(void) const
virtual Address GetAddress(void) const
virtual void SetAddress(Address address)