A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aloha-noack-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#ifndef ALOHA_NOACK_NET_DEVICE_H
10#define ALOHA_NOACK_NET_DEVICE_H
11
12#include "ns3/queue-fwd.h"
13#include <ns3/address.h>
14#include <ns3/callback.h>
15#include <ns3/generic-phy.h>
16#include <ns3/mac48-address.h>
17#include <ns3/net-device.h>
18#include <ns3/node.h>
19#include <ns3/nstime.h>
20#include <ns3/packet.h>
21#include <ns3/ptr.h>
22#include <ns3/traced-callback.h>
23
24#include <cstring>
25
26namespace ns3
27{
28
29class SpectrumChannel;
30class Channel;
31class SpectrumErrorModel;
32
33/**
34 * \ingroup spectrum
35 *
36 * This devices implements the following features:
37 * - layer 3 protocol multiplexing
38 * - MAC addressing
39 * - Aloha MAC:
40 * + packets transmitted as soon as possible
41 * + a new packet is queued if previous one is still being transmitted
42 * + no acknowledgements, hence no retransmissions
43 * - can support any PHY layer compatible with the API defined in generic-phy.h
44 *
45 */
47{
48 public:
49 /**
50 * State of the NetDevice
51 */
52 enum State
53 {
54 IDLE, //!< Idle state
55 TX, //!< Transmitting state
56 RX //!< Receiving state
57 };
58
59 /**
60 * \brief Get the type ID.
61 * \return the object TypeId
62 */
63 static TypeId GetTypeId();
64
66 ~AlohaNoackNetDevice() override;
67
68 /**
69 * set the queue which is going to be used by this device
70 *
71 * @param queue
72 */
73 virtual void SetQueue(Ptr<Queue<Packet>> queue);
74
75 /**
76 * Notify the MAC that the PHY has finished a previously started transmission
77 *
78 */
80
81 /**
82 * Notify the MAC that the PHY has started a reception
83 *
84 */
86
87 /**
88 * Notify the MAC that the PHY finished a reception with an error
89 *
90 */
92
93 /**
94 * Notify the MAC that the PHY finished a reception successfully
95 *
96 * @param p the received packet
97 */
99
100 /**
101 * This class doesn't talk directly with the underlying channel (a
102 * dedicated PHY class is expected to do it), however the NetDevice
103 * specification features a GetChannel() method. This method here
104 * is therefore provide to allow AlohaNoackNetDevice::GetChannel() to have
105 * something meaningful to return.
106 *
107 * @param c the underlying channel
108 */
109 void SetChannel(Ptr<Channel> c);
110
111 /**
112 * set the callback used to instruct the lower layer to start a TX
113 *
114 * @param c
115 */
117
118 /**
119 * Set the Phy object which is attached to this device.
120 * This object is needed so that we can set/get attributes and
121 * connect to trace sources of the PHY from the net device.
122 *
123 * @param phy the Phy object attached to the device. Note that the
124 * API between the PHY and the above (this NetDevice which also
125 * implements the MAC) is implemented entirely by
126 * callbacks, so we do not require that the PHY inherits by any
127 * specific class.
128 */
129 void SetPhy(Ptr<Object> phy);
130
131 /**
132 * @return a reference to the PHY object embedded in this NetDevice.
133 */
134 Ptr<Object> GetPhy() const;
135
136 // inherited from NetDevice
137 void SetIfIndex(const uint32_t index) override;
138 uint32_t GetIfIndex() const override;
139 Ptr<Channel> GetChannel() const override;
140 bool SetMtu(const uint16_t mtu) override;
141 uint16_t GetMtu() const override;
142 void SetAddress(Address address) override;
143 Address GetAddress() const override;
144 bool IsLinkUp() const override;
145 void AddLinkChangeCallback(Callback<void> callback) override;
146 bool IsBroadcast() const override;
147 Address GetBroadcast() const override;
148 bool IsMulticast() const override;
149 bool IsPointToPoint() const override;
150 bool IsBridge() const override;
151 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
152 bool SendFrom(Ptr<Packet> packet,
153 const Address& source,
154 const Address& dest,
155 uint16_t protocolNumber) override;
156 Ptr<Node> GetNode() const override;
157 void SetNode(Ptr<Node> node) override;
158 bool NeedsArp() const override;
160 Address GetMulticast(Ipv4Address addr) const override;
161 Address GetMulticast(Ipv6Address addr) const override;
162 void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override;
163 bool SupportsSendFrom() const override;
164
165 private:
166 /**
167 * Notification of Guard Interval end.
168 */
170 void DoDispose() override;
171
172 /**
173 * start the transmission of a packet by contacting the PHY layer
174 */
175 void StartTransmission();
176
177 Ptr<Queue<Packet>> m_queue; //!< packet queue
178
183
184 Ptr<Node> m_node; //!< Node owning this NetDevice
186
187 Mac48Address m_address; //!< MAC address
188
191
193
194 /**
195 * List of callbacks to fire if the link changes state (up or down).
196 */
198
199 uint32_t m_ifIndex; //!< Interface index
200 mutable uint32_t m_mtu; //!< NetDevice MTU
201 bool m_linkUp; //!< true if the link is up
202
203 State m_state; //!< State of the NetDevice
204 Ptr<Packet> m_currentPkt; //!< Current packet
205 Ptr<Object> m_phy; //!< PHY object
206};
207
208} // namespace ns3
209
210#endif /* ALOHA_NOACK_NET_DEVICE_H */
a polymophic address class
Definition address.h:90
This devices implements the following features:
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
void NotifyReceptionEndError()
Notify the MAC that the PHY finished a reception with an error.
TracedCallback< Ptr< const Packet > > m_macRxTrace
Rx trace.
Ptr< Queue< Packet > > m_queue
packet queue
void AddLinkChangeCallback(Callback< void > callback) override
virtual void SetQueue(Ptr< Queue< Packet > > queue)
set the queue which is going to be used by this device
Mac48Address m_address
MAC address.
Address GetAddress() const override
bool m_linkUp
true if the link is up
NetDevice::ReceiveCallback m_rxCallback
Rx callback.
void SetIfIndex(const uint32_t index) override
void StartTransmission()
start the transmission of a packet by contacting the PHY layer
NetDevice::PromiscReceiveCallback m_promiscRxCallback
Promiscuous Rx callback.
void NotifyReceptionStart()
Notify the MAC that the PHY has started a reception.
Ptr< Object > m_phy
PHY object.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
void SetAddress(Address address) override
Set the address of this interface.
Ptr< Packet > m_currentPkt
Current packet.
Ptr< Channel > m_channel
Channel.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
Promiscuous Rx trace.
void NotifyGuardIntervalEnd()
Notification of Guard Interval end.
Ptr< Node > m_node
Node owning this NetDevice.
Ptr< Channel > GetChannel() const override
void SetGenericPhyTxStartCallback(GenericPhyTxStartCallback c)
set the callback used to instruct the lower layer to start a TX
Address GetBroadcast() const override
uint16_t GetMtu() const override
uint32_t GetIfIndex() const override
GenericPhyTxStartCallback m_phyMacTxStartCallback
Tx Start callback.
bool SupportsSendFrom() const override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
static TypeId GetTypeId()
Get the type ID.
void NotifyTransmissionEnd(Ptr< const Packet >)
Notify the MAC that the PHY has finished a previously started transmission.
void SetChannel(Ptr< Channel > c)
This class doesn't talk directly with the underlying channel (a dedicated PHY class is expected to do...
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Address GetMulticast(Ipv4Address addr) const override
Make and return a MAC multicast address using the provided multicast group.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
State m_state
State of the NetDevice.
void SetNode(Ptr< Node > node) override
bool IsMulticast() const override
uint32_t m_ifIndex
Interface index.
void DoDispose() override
Destructor implementation.
bool IsBroadcast() const override
void SetPhy(Ptr< Object > phy)
Set the Phy object which is attached to this device.
TracedCallback< Ptr< const Packet > > m_macTxTrace
Tx trace.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void NotifyReceptionEndOk(Ptr< Packet > p)
Notify the MAC that the PHY finished a reception successfully.
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
Tx Drop trace.
State
State of the NetDevice.
bool SetMtu(const uint16_t mtu) override
Ptr< Node > GetNode() const override
bool IsBridge() const override
Return true if the net device is acting as a bridge.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
an EUI-48 address
Network layer to device interface.
Definition net-device.h:87
Smart pointer class similar to boost::intrusive_ptr.
Template class for packet Queues.
Definition queue.h:257
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.