20 #include "ns3/queue.h"
21 #include "ns3/simulator.h"
22 #include "ns3/mac48-address.h"
23 #include "ns3/llc-snap-header.h"
24 #include "ns3/error-model.h"
25 #include "ns3/trace-source-accessor.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/pointer.h"
28 #include "ns3/mpi-interface.h"
29 #include "point-to-point-net-device.h"
30 #include "point-to-point-channel.h"
31 #include "ppp-header.h"
37 NS_OBJECT_ENSURE_REGISTERED (PointToPointNetDevice);
40 PointToPointNetDevice::GetTypeId (
void)
42 static TypeId tid = TypeId (
"ns3::PointToPointNetDevice")
43 .SetParent<NetDevice> ()
44 .AddConstructor<PointToPointNetDevice> ()
45 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
46 UintegerValue (DEFAULT_MTU),
49 MakeUintegerChecker<uint16_t> ())
50 .AddAttribute (
"Address",
51 "The MAC address of this device.",
52 Mac48AddressValue (Mac48Address (
"ff:ff:ff:ff:ff:ff")),
53 MakeMac48AddressAccessor (&PointToPointNetDevice::m_address),
54 MakeMac48AddressChecker ())
55 .AddAttribute (
"DataRate",
56 "The default data rate for point to point links",
57 DataRateValue (DataRate (
"32768b/s")),
59 MakeDataRateChecker ())
60 .AddAttribute (
"ReceiveErrorModel",
61 "The receiver error model used to simulate packet loss",
64 MakePointerChecker<ErrorModel> ())
65 .AddAttribute (
"InterframeGap",
66 "The time to wait between packet (frame) transmissions",
75 .AddAttribute (
"TxQueue",
76 "A queue to use as the transmit queue in the device.",
79 MakePointerChecker<Queue> ())
85 .AddTraceSource (
"MacTx",
86 "Trace source indicating a packet has arrived for transmission by this device",
88 .AddTraceSource (
"MacTxDrop",
89 "Trace source indicating a packet has been dropped by the device before transmission",
91 .AddTraceSource (
"MacPromiscRx",
92 "A packet has been received by this device, has been passed up from the physical layer "
93 "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
95 .AddTraceSource (
"MacRx",
96 "A packet has been received by this device, has been passed up from the physical layer "
97 "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
101 .AddTraceSource (
"MacRxDrop",
102 "Trace source indicating a packet was dropped before being forwarded up the stack",
109 .AddTraceSource (
"PhyTxBegin",
110 "Trace source indicating a packet has begun transmitting over the channel",
112 .AddTraceSource (
"PhyTxEnd",
113 "Trace source indicating a packet has been completely transmitted over the channel",
115 .AddTraceSource (
"PhyTxDrop",
116 "Trace source indicating a packet has been dropped by the device during transmission",
120 .AddTraceSource (
"PhyRxBegin",
121 "Trace source indicating a packet has begun being received by the device",
124 .AddTraceSource (
"PhyRxEnd",
125 "Trace source indicating a packet has been completely received by the device",
127 .AddTraceSource (
"PhyRxDrop",
128 "Trace source indicating a packet has been dropped by the device during reception",
136 .AddTraceSource (
"Sniffer",
137 "Trace source simulating a non-promiscuous packet sniffer attached to the device",
139 .AddTraceSource (
"PromiscSniffer",
140 "Trace source simulating a promiscuous packet sniffer attached to the device",
149 m_txMachineState (READY),
228 bool result =
m_channel->TransmitStart (p,
this, txTime);
250 NS_ASSERT_MSG (m_currentPkt != 0,
"PointToPointNetDevice::TransmitComplete(): m_currentPkt zero");
308 uint16_t protocol = 0;
337 if (!m_promiscCallback.IsNull ())
344 m_rxCallback (
this, packet, protocol,
GetRemote ());
356 PointToPointNetDevice::NotifyLinkUp (
void)
359 m_linkChangeCallbacks ();
466 uint16_t protocolNumber)
500 if (
m_queue->Enqueue (packet) ==
true)
516 return m_queue->Enqueue (packet);
524 uint16_t protocolNumber)
556 m_promiscCallback = cb;
566 PointToPointNetDevice::DoMpiReceive (
Ptr<Packet> p)
575 for (uint32_t i = 0; i <
m_channel->GetNDevices (); ++i)
580 return tmp->GetAddress ();
608 case 0x0021:
return 0x0800;
609 case 0x0057:
return 0x86DD;
610 default:
NS_ASSERT_MSG (
false,
"PPP Protocol number not defined!");
620 case 0x0800:
return 0x0021;
621 case 0x86DD:
return 0x0057;
622 default:
NS_ASSERT_MSG (
false,
"PPP Protocol number not defined!");
uint32_t RemoveHeader(Header &header)
void SetReceiveErrorModel(Ptr< ErrorModel > em)
virtual bool IsLinkUp(void) const
#define NS_LOG_FUNCTION(parameters)
Ptr< Queue > GetQueue(void) const
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
Address GetRemote(void) const
virtual bool SupportsSendFrom(void) const
virtual ~PointToPointNetDevice()
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
uint64_t GetUid(void) const
#define NS_ASSERT(condition)
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
#define NS_LOG_COMPONENT_DEFINE(name)
static uint16_t EtherToPpp(uint16_t protocol)
Ethernet to PPP protocol number mapping.
uint32_t GetSize(void) const
virtual void DoDispose(void)
#define NS_LOG_FUNCTION_NOARGS()
virtual Ptr< Node > GetNode(void) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
TracedCallback< Ptr< const Packet > > m_macRxTrace
bool ProcessHeader(Ptr< Packet > p, uint16_t ¶m)
a polymophic address class
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
static uint16_t PppToEther(uint16_t protocol)
PPP to Ethernet protocol number mapping.
Class for representing data rates.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
double GetSeconds(void) const
double CalculateTxTime(uint32_t bytes) const
Calculate transmission time.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual void SetAddress(Address address)
void TransmitComplete(void)
TracedCallback< Ptr< const Packet > > m_snifferTrace
bool TransmitStart(Ptr< Packet > p)
void SetInterframeGap(Time t)
#define NS_LOG_LOGIC(msg)
virtual void AddLinkChangeCallback(Callback< void > callback)
static Mac48Address ConvertFrom(const Address &address)
virtual bool NeedsArp(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual uint32_t GetIfIndex(void) const
virtual Ptr< Channel > GetChannel(void) const
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual Address GetAddress(void) const
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< PointToPointChannel > m_channel
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
Ptr< ErrorModel > m_receiveErrorModel
#define NS_ASSERT_MSG(condition, message)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
void ConnectWithoutContext(const CallbackBase &callback)
TxMachineState m_txMachineState
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
virtual bool SetMtu(const uint16_t mtu)
virtual void SetIfIndex(const uint32_t index)
void SetDataRate(DataRate bps)
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
void Receive(Ptr< Packet > p)
virtual bool IsBroadcast(void) const
bool Attach(Ptr< PointToPointChannel > ch)
virtual void DoDispose(void)
virtual void SetNode(Ptr< Node > node)
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
virtual uint16_t GetMtu(void) const
virtual bool IsMulticast(void) const
TracedCallback< Ptr< const Packet > > m_macTxTrace
virtual Address GetBroadcast(void) const
void AddHeader(const Header &header)
void SetQueue(Ptr< Queue > queue)
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace