Update README and add contrib dir
This commit is contained in:
464
contrib/ethernet/model/ethernet-net-device.h
Normal file
464
contrib/ethernet/model/ethernet-net-device.h
Normal file
@@ -0,0 +1,464 @@
|
||||
#ifndef ETHERNET_NET_DEVICE_H
|
||||
#define ETHERNET_NET_DEVICE_H
|
||||
|
||||
#include "ns3/address.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/data-rate.h"
|
||||
#include "ns3/mac48-address.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/queue-fwd.h"
|
||||
#include "ns3/traced-callback.h"
|
||||
|
||||
#include "ns3/net-device.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
class EthernetChannel;
|
||||
class ErrorModel;
|
||||
|
||||
/**
|
||||
* \ingroup ethernet
|
||||
* \class EthernetNetDevice
|
||||
* \brief A Device for a Ethernet full duplex Link.
|
||||
*
|
||||
* This EthernetNetDevice class specializes the NetDevice abstract
|
||||
* base class. Together with a EthernetChannel (and a peer
|
||||
* EthernetNetDevice), the class models, with some level of
|
||||
* abstraction, a full duplex ethernet link.
|
||||
* Key parameters or objects that can be specified for this device
|
||||
* include a queue, data rate, and interframe transmission gap (the
|
||||
* propagation delay is set in the EthernetChannel).
|
||||
*/
|
||||
|
||||
class EthernetNetDevice : public NetDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Get the TypeId
|
||||
*
|
||||
* \return The TypeId for this class
|
||||
*/
|
||||
static TypeId GetTypeId();
|
||||
|
||||
/**
|
||||
* Construct a EthernetNetDevice
|
||||
*
|
||||
* This is the constructor for the EthernetNetDevice. It takes as a
|
||||
* parameter a pointer to the Node to which this device is connected,
|
||||
* as well as an optional DataRate object.
|
||||
*/
|
||||
EthernetNetDevice();
|
||||
|
||||
/**
|
||||
* Destroy a EthernetNetDevice
|
||||
*
|
||||
* This is the destructor for the EthernetNetDevice.
|
||||
*/
|
||||
~EthernetNetDevice() override;
|
||||
|
||||
// Delete copy constructor and assignment operator to avoid misuse
|
||||
EthernetNetDevice& operator=(const EthernetNetDevice&) = delete;
|
||||
EthernetNetDevice(const EthernetNetDevice&) = delete;
|
||||
|
||||
/**
|
||||
* Set the Data Rate used for transmission of packets. The data rate is
|
||||
* set in the Attach () method from the corresponding field in the channel
|
||||
* to which the device is attached. It can be overridden using this method.
|
||||
*
|
||||
* \param bps the data rate at which this object operates
|
||||
*/
|
||||
void SetDataRate(DataRate bps);
|
||||
|
||||
/**
|
||||
* Attach the device to a channel.
|
||||
*
|
||||
* \param ch Ptr to the channel to which this object is being attached.
|
||||
* \return true if the operation was successful (always true actually)
|
||||
*/
|
||||
bool Attach(Ptr<EthernetChannel> ch);
|
||||
|
||||
/**
|
||||
* Attach a queue to the EthernetNetDevice.
|
||||
*
|
||||
* The EthernetNetDevice "owns" a queue that implements a queueing
|
||||
* method such as DropTailQueue or RedQueue
|
||||
*
|
||||
* \param queue Ptr to the new queue.
|
||||
*/
|
||||
void SetQueue(Ptr<Queue<Packet>> queue);
|
||||
|
||||
/**
|
||||
* Get a copy of the attached Queue.
|
||||
*
|
||||
* \param index Queue index
|
||||
* \returns Ptr to the queue.
|
||||
*/
|
||||
Ptr<Queue<Packet>> GetQueue(uint8_t index) const;
|
||||
|
||||
/**
|
||||
* Attach a receive ErrorModel to the EthernetNetDevice.
|
||||
*
|
||||
* The EthernetNetDevice may optionally include an ErrorModel in
|
||||
* the packet receive chain.
|
||||
*
|
||||
* \param em Ptr to the ErrorModel.
|
||||
*/
|
||||
void SetReceiveErrorModel(Ptr<ErrorModel> em);
|
||||
|
||||
/**
|
||||
* Receive a packet from a connected EthernetNetDevice.
|
||||
*
|
||||
* The EthernetNetDevice receives packets from its connected channel
|
||||
* and forwards them up the protocol stack. This is the public method
|
||||
* used by the channel to indicate that the last bit of a packet has
|
||||
* arrived at the device.
|
||||
*
|
||||
* \param p Ptr to the received packet.
|
||||
*/
|
||||
virtual void Receive(Ptr<Packet> p);
|
||||
|
||||
// The remaining methods are documented in ns3::NetDevice*
|
||||
|
||||
void SetIfIndex(const uint32_t index) override;
|
||||
uint32_t GetIfIndex() const override;
|
||||
|
||||
Ptr<Channel> GetChannel() const override;
|
||||
|
||||
void SetAddress(Address address) override;
|
||||
Address GetAddress() const override;
|
||||
|
||||
bool SetMtu(const uint16_t mtu) override;
|
||||
uint16_t GetMtu() const override;
|
||||
|
||||
bool IsLinkUp() const override;
|
||||
|
||||
void AddLinkChangeCallback(Callback<void> callback) override;
|
||||
|
||||
bool IsBroadcast() const override;
|
||||
Address GetBroadcast() const override;
|
||||
|
||||
bool IsMulticast() const override;
|
||||
Address GetMulticast(Ipv4Address multicastGroup) const override;
|
||||
|
||||
bool IsPointToPoint() const override;
|
||||
bool IsBridge() const override;
|
||||
|
||||
bool Send(Ptr<Packet> packet, const Address& dest, uint16_t ethertype) override;
|
||||
bool Send(Ptr<Packet> packet, const Address& dest, uint16_t ethertype, uint16_t vid, uint8_t pcp, uint8_t dei);
|
||||
virtual bool SendFrom(Ptr<Packet> packet,
|
||||
const Address& source,
|
||||
const Address& dest,
|
||||
uint16_t ethertype) override;
|
||||
bool SendFrom(Ptr<Packet> packet,
|
||||
const Address& source,
|
||||
const Address& dest,
|
||||
uint16_t ethertype,
|
||||
uint16_t vid,
|
||||
uint8_t pcp,
|
||||
uint8_t dei);
|
||||
|
||||
Ptr<Node> GetNode() const override;
|
||||
void SetNode(Ptr<Node> node) override;
|
||||
|
||||
bool NeedsArp() const override;
|
||||
|
||||
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override;
|
||||
|
||||
Address GetMulticast(Ipv6Address addr) const override;
|
||||
|
||||
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override;
|
||||
bool SupportsSendFrom() const override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \brief Dispose of the object
|
||||
*/
|
||||
void DoDispose() override;
|
||||
|
||||
/**
|
||||
* \returns the address of the remote device connected to this device
|
||||
* through the ethernet channel.
|
||||
*/
|
||||
Address GetRemote() const;
|
||||
|
||||
/**
|
||||
* Adds the necessary headers and trailers to a packet of data in order to
|
||||
* respect the protocol implemented by the agent.
|
||||
* \param p packet
|
||||
* \param dst Dst mac address
|
||||
* \param src Src mac address
|
||||
* \param ethertype ethertype
|
||||
*/
|
||||
void AddHeader(Ptr<Packet> p, Mac48Address dst, Mac48Address src, uint16_t ethertype);
|
||||
|
||||
/**
|
||||
* Adds the necessary headers to a packet of data in order to
|
||||
* respect the protocol implemented by the agent.
|
||||
* \param p packet
|
||||
* \param dst Dst mac address
|
||||
* \param src Src mac address
|
||||
* \param ethertype ethertype
|
||||
* \param vid vlain id
|
||||
* \param pcp pcp field
|
||||
* \param dei dei bit
|
||||
*/
|
||||
void AddHeader(Ptr<Packet> p, Mac48Address dst, Mac48Address src, uint16_t ethertype, uint16_t vid, uint8_t pcp, uint8_t dei);
|
||||
|
||||
/**
|
||||
* Start Sending a Packet Down the Wire.
|
||||
*
|
||||
* The TransmitStart method is the method that is used internally in the
|
||||
* EthernetNetDevice to begin the process of sending a packet out on
|
||||
* the channel. The corresponding method is called on the channel to let
|
||||
* it know that the physical device this class represents has virtually
|
||||
* started sending signals. An event is scheduled for the time at which
|
||||
* the bits have been completely transmitted.
|
||||
*
|
||||
* \see EthernetChannel::TransmitStart ()
|
||||
* \see TransmitComplete()
|
||||
* \param p a reference to the packet to send
|
||||
* \returns true if success, false on failure
|
||||
*/
|
||||
bool TransmitStart(Ptr<Packet> p);
|
||||
|
||||
/**
|
||||
* Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
|
||||
*
|
||||
* The TransmitComplete method is used internally to finish the process
|
||||
* of sending a packet out on the channel.
|
||||
*/
|
||||
void TransmitComplete();
|
||||
|
||||
/**
|
||||
* Find the nextEligible Queue for transimission
|
||||
*
|
||||
* \returns Int id to the queue.
|
||||
*/
|
||||
virtual int TransmitSelection();
|
||||
|
||||
virtual void CheckForReadyPacket();
|
||||
|
||||
|
||||
/**
|
||||
* \brief Make the link up and running
|
||||
*
|
||||
* It calls also the linkChange callback.
|
||||
*/
|
||||
void NotifyLinkUp();
|
||||
|
||||
/**
|
||||
* Enumeration of the states of the transmit machine of the net device.
|
||||
*/
|
||||
enum TxMachineState
|
||||
{
|
||||
READY, /**< The transmitter is ready to begin transmission of a packet */
|
||||
BUSY /**< The transmitter is busy transmitting a packet */
|
||||
};
|
||||
|
||||
/**
|
||||
* The state of the Net Device transmit state machine.
|
||||
*/
|
||||
TxMachineState m_txMachineState;
|
||||
|
||||
/**
|
||||
* The data rate that the Net Device uses to simulate packet transmission
|
||||
* timing.
|
||||
*/
|
||||
DataRate m_bps;
|
||||
|
||||
/**
|
||||
* The preamble and start of frame delimiter gap that the Net Device uses to throttle packet
|
||||
* transmission in bytes
|
||||
*/
|
||||
uint8_t m_preambleAndSFDGap;
|
||||
|
||||
/**
|
||||
* The interframe gap that the Net Device uses to throttle packet
|
||||
* transmission in bytes
|
||||
*/
|
||||
uint8_t m_interframeGap;
|
||||
|
||||
/**
|
||||
* The EthernetChannel to which this EthernetNetDevice has been
|
||||
* attached.
|
||||
*/
|
||||
Ptr<EthernetChannel> m_channel;
|
||||
|
||||
/**
|
||||
* The Queues which this EthernetNetDevice uses as a packet source.
|
||||
* Management of this Queues has been delegated to the EthernetNetDevice
|
||||
* and it has the responsibility for deletion.
|
||||
* \see class DropTailQueue
|
||||
*/
|
||||
std::vector<Ptr<Queue<Packet>>> m_queues;
|
||||
|
||||
/**
|
||||
* Error model for receive packet events
|
||||
*/
|
||||
Ptr<ErrorModel> m_receiveErrorModel;
|
||||
|
||||
/**
|
||||
* The trace source fired when packets come into the "top" of the device
|
||||
* at the L3/L2 transition, before being queued for transmission.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_macTxTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when packets coming into the "top" of the device
|
||||
* at the L3/L2 transition are dropped before being queued for transmission.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_macTxDropTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired for packets successfully received by the device
|
||||
* immediately before being forwarded up to higher layers (at the L2/L3
|
||||
* transition). This is a promiscuous trace (which doesn't mean a lot here
|
||||
* in the point-to-point device).
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_macPromiscRxTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired for packets successfully received by the device
|
||||
* immediately before being forwarded up to higher layers (at the L2/L3
|
||||
* transition). This is a non-promiscuous trace (which doesn't mean a lot
|
||||
* here in the point-to-point device).
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_macRxTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired for packets successfully received by the device
|
||||
* but are dropped before being forwarded up to higher layers (at the L2/L3
|
||||
* transition).
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_macRxDropTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when a packet begins the transmission process on
|
||||
* the medium.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_phyTxBeginTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when a packet ends the transmission process on
|
||||
* the medium.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_phyTxEndTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when the phy layer drops a packet before it tries
|
||||
* to transmit it.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_phyTxDropTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when a packet begins the reception process from
|
||||
* the medium -- when the simulated first bit(s) arrive.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_phyRxBeginTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when a packet ends the reception process from
|
||||
* the medium.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_phyRxEndTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when the phy layer drops a packet it has received.
|
||||
* This happens if the receiver is not enabled or the error model is active
|
||||
* and indicates that the packet is corrupt.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_phyRxDropTrace;
|
||||
|
||||
/**
|
||||
* The trace source fired when the packet is receive to compute latency.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_latencyTrace;
|
||||
|
||||
/**
|
||||
* TracedCallback signature for packet transmission/reception events
|
||||
* (for external visualyzer).
|
||||
*
|
||||
* \param [in] packet The packet being transmitted.
|
||||
* \param [in] tx or rx NetDevice.
|
||||
*/
|
||||
typedef void (*MacTxAnimationCallback)(Ptr<const Packet> packet,
|
||||
Ptr<NetDevice> device);
|
||||
|
||||
TracedCallback<Ptr<const Packet>, Ptr<NetDevice>> m_macTxAnimationTrace;
|
||||
TracedCallback<Ptr<const Packet>, Ptr<NetDevice>> m_macRxAnimationTrace;
|
||||
/**
|
||||
* A trace source that emulates a non-promiscuous protocol sniffer connected
|
||||
* to the device. Unlike your average everyday sniffer, this trace source
|
||||
* will not fire on PACKET_OTHERHOST events.
|
||||
*
|
||||
* On the transmit size, this trace hook will fire after a packet is dequeued
|
||||
* from the device queue for transmission. In Linux, for example, this would
|
||||
* correspond to the point just before a device \c hard_start_xmit where
|
||||
* \c dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET
|
||||
* ETH_P_ALL handlers.
|
||||
*
|
||||
* On the receive side, this trace hook will fire when a packet is received,
|
||||
* just before the receive callback is executed. In Linux, for example,
|
||||
* this would correspond to the point at which the packet is dispatched to
|
||||
* packet sniffers in \c netif_receive_skb.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_snifferTrace;
|
||||
|
||||
/**
|
||||
* A trace source that emulates a promiscuous mode protocol sniffer connected
|
||||
* to the device. This trace source fire on packets destined for any host
|
||||
* just like your average everyday packet sniffer.
|
||||
*
|
||||
* On the transmit size, this trace hook will fire after a packet is dequeued
|
||||
* from the device queue for transmission. In Linux, for example, this would
|
||||
* correspond to the point just before a device \c hard_start_xmit where
|
||||
* \c dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET
|
||||
* ETH_P_ALL handlers.
|
||||
*
|
||||
* On the receive side, this trace hook will fire when a packet is received,
|
||||
* just before the receive callback is executed. In Linux, for example,
|
||||
* this would correspond to the point at which the packet is dispatched to
|
||||
* packet sniffers in \c netif_receive_skb.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>> m_promiscSnifferTrace;
|
||||
|
||||
|
||||
TracedCallback<std::vector<Ptr<Queue<Packet>>>,
|
||||
bool,
|
||||
Ptr<const Packet>> m_FIFOStateSnifferTrace;
|
||||
|
||||
|
||||
Ptr<Node> m_node; //!< Node owning this NetDevice
|
||||
Mac48Address m_address; //!< Mac48Address of this NetDevice
|
||||
NetDevice::ReceiveCallback m_rxCallback; //!< Receive callback
|
||||
NetDevice::PromiscReceiveCallback m_promiscCallback; //!< Receive callback
|
||||
// (promisc data)
|
||||
uint32_t m_ifIndex; //!< Index of the interface
|
||||
bool m_linkUp; //!< Identify if the link is up or not
|
||||
TracedCallback<> m_linkChangeCallbacks; //!< Callback for the link change event
|
||||
|
||||
static const uint16_t DEFAULT_MTU = 1500; //!< Default MTU
|
||||
|
||||
/**
|
||||
* \brief The Maximum Transmission Unit
|
||||
*
|
||||
* This corresponds to the maximum
|
||||
* number of bytes that can be transmitted as seen from higher layers.
|
||||
* This corresponds to the 1500 byte MTU size often seen on IP over
|
||||
* Ethernet.
|
||||
*/
|
||||
uint32_t m_mtu;
|
||||
|
||||
Ptr<Packet> m_currentPkt; //!< Current packet processed
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ETHERNET_NET_DEVICE_H */
|
||||
Reference in New Issue
Block a user