Update README and add contrib dir
This commit is contained in:
207
contrib/ethernet/model/ethernet-channel.h
Normal file
207
contrib/ethernet/model/ethernet-channel.h
Normal file
@@ -0,0 +1,207 @@
|
||||
#ifndef ETHERNET_CHANNEL_H
|
||||
#define ETHERNET_CHANNEL_H
|
||||
|
||||
#include "ns3/channel.h"
|
||||
#include "ns3/data-rate.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/traced-callback.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
// Add a doxygen group for this module.
|
||||
// If you have more than one file, this should be in only one of them.
|
||||
/**
|
||||
* \defgroup ethernet Description of the ethernet
|
||||
*/
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
class EthernetNetDevice;
|
||||
class Packet;
|
||||
|
||||
/**
|
||||
* \ingroup ethernet
|
||||
* \brief Simple Ethernet Channel.
|
||||
*
|
||||
* This class represents a very simple full duplex Ethernet channel. It is
|
||||
* largely inspired by the PointToPointChannel. There is no multi-drop
|
||||
* capability on this channel -- there can be a maximum of two Ethernet
|
||||
* net devices connected.
|
||||
*
|
||||
* There are two "wires" in the channel. The first device connected gets the
|
||||
* [0] wire to transmit on. The second device gets the [1] wire. There is a
|
||||
* state (IDLE, TRANSMITTING) associated with each wire.
|
||||
*
|
||||
* \see Attach
|
||||
* \see TransmitStart
|
||||
*/
|
||||
|
||||
class EthernetChannel : public Channel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Get the TypeId
|
||||
*
|
||||
* \return The TypeId for this class
|
||||
*/
|
||||
static TypeId GetTypeId();
|
||||
|
||||
/**
|
||||
* \brief Create a EthernetChannel
|
||||
*
|
||||
* By default, you get a channel that has a 25ns delay.
|
||||
*/
|
||||
EthernetChannel();
|
||||
|
||||
/**
|
||||
* \brief Attach a given netdevice to this channel
|
||||
* \param device pointer to the netdevice to attach to the channel
|
||||
*/
|
||||
void Attach(Ptr<EthernetNetDevice> device);
|
||||
|
||||
/**
|
||||
* \brief Transmit a packet over this channel
|
||||
* \param p Packet to transmit
|
||||
* \param src Source EthernetNetDevice
|
||||
* \param txTime Transmit time to apply
|
||||
* \returns true if successful (currently always true)
|
||||
*/
|
||||
virtual bool TransmitStart(Ptr<const Packet> p, Ptr<EthernetNetDevice> src, Time txTime);
|
||||
|
||||
/**
|
||||
* \brief Get number of devices on this channel
|
||||
* \returns number of devices on this channel
|
||||
*/
|
||||
std::size_t GetNDevices() const override;
|
||||
|
||||
/**
|
||||
* \brief Get EthernetNetDevice corresponding to index i on this channel
|
||||
* \param i Index number of the device requested
|
||||
* \returns Ptr to EthernetNetDevice requested
|
||||
*/
|
||||
Ptr<EthernetNetDevice> GetEthernetDevice(std::size_t i) const;
|
||||
|
||||
/**
|
||||
* \brief Get NetDevice corresponding to index i on this channel
|
||||
* \param i Index number of the device requested
|
||||
* \returns Ptr to NetDevice requested
|
||||
*/
|
||||
Ptr<NetDevice> GetDevice(std::size_t i) const override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \brief Get the delay associated with this channel
|
||||
* \returns Time delay
|
||||
*/
|
||||
Time GetDelay() const;
|
||||
|
||||
/**
|
||||
* \brief Check to make sure the wire is initialized
|
||||
* \returns true if initialized, asserts otherwise
|
||||
*/
|
||||
bool IsInitialized() const;
|
||||
|
||||
/**
|
||||
* \brief Get the net-device source
|
||||
* \param i the wire requested
|
||||
* \returns Ptr to EthernetNetDevice source for the
|
||||
* specified wire
|
||||
*/
|
||||
Ptr<EthernetNetDevice> GetSource(uint32_t i) const;
|
||||
|
||||
/**
|
||||
* \brief Get the net-device destination
|
||||
* \param i the wire requested
|
||||
* \returns Ptr to EthernetNetDevice destination for
|
||||
* the specified wire
|
||||
*/
|
||||
Ptr<EthernetNetDevice> GetDestination(uint32_t i) const;
|
||||
|
||||
/**
|
||||
* TracedCallback signature for packet transmission animation events.
|
||||
*
|
||||
* \param [in] packet The packet being transmitted.
|
||||
* \param [in] txDevice the TransmitTing NetDevice.
|
||||
* \param [in] rxDevice the Receiving NetDevice.
|
||||
* \param [in] duration The amount of time to transmit the packet.
|
||||
* \param [in] lastBitTime Last bit receive time (relative to now)
|
||||
* \deprecated The non-const \c Ptr<NetDevice> argument is deprecated
|
||||
* and will be changed to \c Ptr<const NetDevice> in a future release.
|
||||
*/
|
||||
typedef void (*TxRxAnimationCallback)(Ptr<const Packet> packet,
|
||||
Ptr<NetDevice> txDevice,
|
||||
Ptr<NetDevice> rxDevice,
|
||||
Time duration,
|
||||
Time lastBitTime);
|
||||
|
||||
private:
|
||||
/** Each ethernet full duplex wire has exactly two net devices. */
|
||||
static const std::size_t N_DEVICES = 2;
|
||||
|
||||
Time m_delay; //!< Propagation delay
|
||||
std::size_t m_nDevices; //!< Devices of this channel
|
||||
|
||||
/**
|
||||
* The trace source for the packet transmission animation events that the
|
||||
* device can fire.
|
||||
* Arguments to the callback are the packet, transmitting
|
||||
* net device, receiving net device, transmission time and
|
||||
* packet receipt time.
|
||||
*
|
||||
* \see class CallBackTraceSource
|
||||
* \deprecated The non-const \c Ptr<NetDevice> argument is deprecated
|
||||
* and will be changed to \c Ptr<const NetDevice> in a future release.
|
||||
*/
|
||||
TracedCallback<Ptr<const Packet>, // Packet being transmitted
|
||||
Ptr<NetDevice>, // Transmitting NetDevice
|
||||
Ptr<NetDevice>, // Receiving NetDevice
|
||||
Time, // Amount of time to transmit the pkt
|
||||
Time // Last bit receive time (relative to now)
|
||||
>
|
||||
m_txrxEthernet;
|
||||
|
||||
/** \brief Wire states
|
||||
*
|
||||
*/
|
||||
enum WireState
|
||||
{
|
||||
/** Initializing state */
|
||||
INITIALIZING,
|
||||
/** Idle state (no transmission from NetDevice) */
|
||||
IDLE,
|
||||
/** Transmitting state (data being transmitted from NetDevice. */
|
||||
TRANSMITTING,
|
||||
/** Propagating state (data is being propagated in the channel. */
|
||||
PROPAGATING
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Wire model for the EthernetChannel
|
||||
*/
|
||||
class Wire
|
||||
{
|
||||
public:
|
||||
/** \brief Create the wire, it will be in INITIALIZING state
|
||||
*
|
||||
*/
|
||||
Wire()
|
||||
: m_state(INITIALIZING),
|
||||
m_src(nullptr),
|
||||
m_dst(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
WireState m_state; //!< State of the wire
|
||||
Ptr<EthernetNetDevice> m_src; //!< First NetDevice
|
||||
Ptr<EthernetNetDevice> m_dst; //!< Second NetDevice
|
||||
};
|
||||
|
||||
Wire m_wire[N_DEVICES]; //!< Wire model
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ETHERNET_CHANNEL_H */
|
||||
Reference in New Issue
Block a user