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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#ifndef ALOHA_NOACK_NET_DEVICE_H
21#define ALOHA_NOACK_NET_DEVICE_H
22
23#include "ns3/queue-fwd.h"
24#include <ns3/address.h>
25#include <ns3/callback.h>
26#include <ns3/generic-phy.h>
27#include <ns3/mac48-address.h>
28#include <ns3/net-device.h>
29#include <ns3/node.h>
30#include <ns3/nstime.h>
31#include <ns3/packet.h>
32#include <ns3/ptr.h>
33#include <ns3/traced-callback.h>
34
35#include <cstring>
36
37namespace ns3
38{
39
40class SpectrumChannel;
41class Channel;
42class SpectrumErrorModel;
43
44/**
45 * \ingroup spectrum
46 *
47 * This devices implements the following features:
48 * - layer 3 protocol multiplexing
49 * - MAC addressing
50 * - Aloha MAC:
51 * + packets transmitted as soon as possible
52 * + a new packet is queued if previous one is still being transmitted
53 * + no acknowledgements, hence no retransmissions
54 * - can support any PHY layer compatible with the API defined in generic-phy.h
55 *
56 */
58{
59 public:
60 /**
61 * State of the NetDevice
62 */
63 enum State
64 {
65 IDLE, //!< Idle state
66 TX, //!< Transmitting state
67 RX //!< Receiving state
68 };
69
70 /**
71 * \brief Get the type ID.
72 * \return the object TypeId
73 */
74 static TypeId GetTypeId();
75
77 ~AlohaNoackNetDevice() override;
78
79 /**
80 * set the queue which is going to be used by this device
81 *
82 * @param queue
83 */
84 virtual void SetQueue(Ptr<Queue<Packet>> queue);
85
86 /**
87 * Notify the MAC that the PHY has finished a previously started transmission
88 *
89 */
91
92 /**
93 * Notify the MAC that the PHY has started a reception
94 *
95 */
97
98 /**
99 * Notify the MAC that the PHY finished a reception with an error
100 *
101 */
103
104 /**
105 * Notify the MAC that the PHY finished a reception successfully
106 *
107 * @param p the received packet
108 */
110
111 /**
112 * This class doesn't talk directly with the underlying channel (a
113 * dedicated PHY class is expected to do it), however the NetDevice
114 * specification features a GetChannel() method. This method here
115 * is therefore provide to allow AlohaNoackNetDevice::GetChannel() to have
116 * something meaningful to return.
117 *
118 * @param c the underlying channel
119 */
120 void SetChannel(Ptr<Channel> c);
121
122 /**
123 * set the callback used to instruct the lower layer to start a TX
124 *
125 * @param c
126 */
128
129 /**
130 * Set the Phy object which is attached to this device.
131 * This object is needed so that we can set/get attributes and
132 * connect to trace sources of the PHY from the net device.
133 *
134 * @param phy the Phy object attached to the device. Note that the
135 * API between the PHY and the above (this NetDevice which also
136 * implements the MAC) is implemented entirely by
137 * callbacks, so we do not require that the PHY inherits by any
138 * specific class.
139 */
140 void SetPhy(Ptr<Object> phy);
141
142 /**
143 * @return a reference to the PHY object embedded in this NetDevice.
144 */
145 Ptr<Object> GetPhy() const;
146
147 // inherited from NetDevice
148 void SetIfIndex(const uint32_t index) override;
149 uint32_t GetIfIndex() const override;
150 Ptr<Channel> GetChannel() const override;
151 bool SetMtu(const uint16_t mtu) override;
152 uint16_t GetMtu() const override;
153 void SetAddress(Address address) override;
154 Address GetAddress() const override;
155 bool IsLinkUp() const override;
156 void AddLinkChangeCallback(Callback<void> callback) override;
157 bool IsBroadcast() const override;
158 Address GetBroadcast() const override;
159 bool IsMulticast() const override;
160 bool IsPointToPoint() const override;
161 bool IsBridge() const override;
162 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
163 bool SendFrom(Ptr<Packet> packet,
164 const Address& source,
165 const Address& dest,
166 uint16_t protocolNumber) override;
167 Ptr<Node> GetNode() const override;
168 void SetNode(Ptr<Node> node) override;
169 bool NeedsArp() const override;
171 Address GetMulticast(Ipv4Address addr) const override;
172 Address GetMulticast(Ipv6Address addr) const override;
174 bool SupportsSendFrom() const override;
175
176 private:
177 /**
178 * Notification of Guard Interval end.
179 */
181 void DoDispose() override;
182
183 /**
184 * start the transmission of a packet by contacting the PHY layer
185 */
186 void StartTransmission();
187
188 Ptr<Queue<Packet>> m_queue; //!< packet queue
189
194
195 Ptr<Node> m_node; //!< Node owning this NetDevice
197
198 Mac48Address m_address; //!< MAC address
199
202
204
205 /**
206 * List of callbacks to fire if the link changes state (up or down).
207 */
209
210 uint32_t m_ifIndex; //!< Interface index
211 mutable uint32_t m_mtu; //!< NetDevice MTU
212 bool m_linkUp; //!< true if the link is up
213
214 State m_state; //!< State of the NetDevice
215 Ptr<Packet> m_currentPkt; //!< Current packet
216 Ptr<Object> m_phy; //!< PHY object
217};
218
219} // namespace ns3
220
221#endif /* ALOHA_NOACK_NET_DEVICE_H */
a polymophic address class
Definition: address.h:101
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
bool IsLinkUp() const override
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
bool NeedsArp() const override
uint32_t m_ifIndex
Interface index.
void DoDispose() override
Destructor implementation.
bool IsBroadcast() const override
uint32_t m_mtu
NetDevice MTU.
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.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
an EUI-48 address
Definition: mac48-address.h:46
Network layer to device interface.
Definition: net-device.h:98
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, PacketType > PromiscReceiveCallback
Definition: net-device.h:352
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Template class for packet Queues.
Definition: queue.h:268
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.