A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
simple-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef SIMPLE_NET_DEVICE_H
20#define SIMPLE_NET_DEVICE_H
21
22#include "data-rate.h"
23#include "mac48-address.h"
24#include "queue-fwd.h"
25
26#include "ns3/event-id.h"
27#include "ns3/net-device.h"
28#include "ns3/traced-callback.h"
29
30#include <stdint.h>
31#include <string>
32
33namespace ns3
34{
35
36class SimpleChannel;
37class Node;
38class ErrorModel;
39
40/**
41 * \ingroup netdevice
42 *
43 * This device assumes 48-bit mac addressing; there is also the possibility to
44 * add an ErrorModel if you want to force losses on the device.
45 *
46 * The device can be installed on a node through the SimpleNetDeviceHelper.
47 * In case of manual creation, the user is responsible for assigning an unique
48 * address to the device.
49 *
50 * By default the device is in Broadcast mode, with infinite bandwidth.
51 *
52 * \brief simple net device for simple things and testing
53 */
55{
56 public:
57 /**
58 * \brief Get the type ID.
59 * \return the object TypeId
60 */
61 static TypeId GetTypeId();
63
64 /**
65 * Receive a packet from a connected SimpleChannel. The
66 * SimpleNetDevice receives packets from its connected channel
67 * and then forwards them by calling its rx callback method
68 *
69 * \param packet Packet received on the channel
70 * \param protocol protocol number
71 * \param to address packet should be sent to
72 * \param from address packet was sent from
73 */
74 void Receive(Ptr<Packet> packet, uint16_t protocol, Mac48Address to, Mac48Address from);
75
76 /**
77 * Attach a channel to this net device. This will be the
78 * channel the net device sends on
79 *
80 * \param channel channel to assign to this net device
81 *
82 */
83 void SetChannel(Ptr<SimpleChannel> channel);
84
85 /**
86 * Attach a queue to the SimpleNetDevice.
87 *
88 * \param queue Ptr to the new queue.
89 */
90 void SetQueue(Ptr<Queue<Packet>> queue);
91
92 /**
93 * Get a copy of the attached Queue.
94 *
95 * \returns Ptr to the queue.
96 */
98
99 /**
100 * Attach a receive ErrorModel to the SimpleNetDevice.
101 *
102 * The SimpleNetDevice may optionally include an ErrorModel in
103 * the packet receive chain.
104 *
105 * \see ErrorModel
106 * \param em Ptr to the ErrorModel.
107 */
109
110 // inherited from NetDevice base class.
111 void SetIfIndex(const uint32_t index) override;
112 uint32_t GetIfIndex() const override;
113 Ptr<Channel> GetChannel() const override;
114 void SetAddress(Address address) override;
115 Address GetAddress() const override;
116 bool SetMtu(const uint16_t mtu) override;
117 uint16_t GetMtu() const override;
118 bool IsLinkUp() const override;
119 void AddLinkChangeCallback(Callback<void> callback) override;
120 bool IsBroadcast() const override;
121 Address GetBroadcast() const override;
122 bool IsMulticast() const override;
123 Address GetMulticast(Ipv4Address multicastGroup) const override;
124 bool IsPointToPoint() const override;
125 bool IsBridge() const override;
126 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
127 bool SendFrom(Ptr<Packet> packet,
128 const Address& source,
129 const Address& dest,
130 uint16_t protocolNumber) override;
131 Ptr<Node> GetNode() const override;
132 void SetNode(Ptr<Node> node) override;
133 bool NeedsArp() const override;
135
136 Address GetMulticast(Ipv6Address addr) const override;
137
139 bool SupportsSendFrom() const override;
140
141 protected:
142 void DoDispose() override;
143
144 private:
145 Ptr<SimpleChannel> m_channel; //!< the channel the device is connected to
147 NetDevice::PromiscReceiveCallback m_promiscCallback; //!< Promiscuous receive callback
148 Ptr<Node> m_node; //!< Node this netDevice is associated to
149 uint16_t m_mtu; //!< MTU
150 uint32_t m_ifIndex; //!< Interface index
151 Mac48Address m_address; //!< MAC address
152 Ptr<ErrorModel> m_receiveErrorModel; //!< Receive error model.
153
154 /**
155 * The trace source fired when the phy layer drops a packet it has received
156 * due to the error model being active. Although SimpleNetDevice doesn't
157 * really have a Phy model, we choose this trace source name for alignment
158 * with other trace sources.
159 *
160 * \see class CallBackTraceSource
161 */
163
164 /**
165 * The StartTransmission method is used internally to start the process
166 * of sending a packet out on the channel, by scheduling the
167 * FinishTransmission method at a time corresponding to the transmission
168 * delay of the packet.
169 */
170 void StartTransmission();
171
172 /**
173 * The FinishTransmission method is used internally to finish the process
174 * of sending a packet out on the channel.
175 * \param packet The packet to send on the channel
176 */
177 void FinishTransmission(Ptr<Packet> packet);
178
179 bool m_linkUp; //!< Flag indicating whether or not the link is up
180
181 /**
182 * Flag indicating whether or not the NetDevice is a Point to Point model.
183 * Enabling this will disable Broadcast and Arp.
184 */
186
187 Ptr<Queue<Packet>> m_queue; //!< The Queue for outgoing packets.
188 DataRate m_bps; //!< The device nominal Data rate. Zero means infinite
189 EventId FinishTransmissionEvent; //!< the Tx Complete event
190
191 /**
192 * List of callbacks to fire if the link changes state (up or down).
193 */
195};
196
197} // namespace ns3
198
199#endif /* SIMPLE_NET_DEVICE_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:55
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Template class for packet Queues.
Definition: queue.h:268
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
bool NeedsArp() const override
void DoDispose() override
Destructor implementation.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received due to the error model being...
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
void SetNode(Ptr< Node > node) override
void SetAddress(Address address) override
Set the address of this interface.
void SetIfIndex(const uint32_t index) override
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the SimpleNetDevice.
bool SetMtu(const uint16_t mtu) override
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
static TypeId GetTypeId()
Get the type ID.
DataRate m_bps
The device nominal Data rate.
Ptr< Queue< Packet > > m_queue
The Queue for outgoing packets.
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
Ptr< Channel > GetChannel() const override
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice.
uint16_t GetMtu() const override
EventId FinishTransmissionEvent
the Tx Complete event
bool m_linkUp
Flag indicating whether or not the link is up.
void AddLinkChangeCallback(Callback< void > callback) override
bool m_pointToPointMode
Flag indicating whether or not the NetDevice is a Point to Point model.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
void FinishTransmission(Ptr< Packet > packet)
The FinishTransmission method is used internally to finish the process of sending a packet out on the...
uint32_t GetIfIndex() const override
Ptr< ErrorModel > m_receiveErrorModel
Receive error model.
bool IsMulticast() const override
Ptr< SimpleChannel > m_channel
the channel the device is connected to
Ptr< Node > m_node
Node this netDevice is associated to.
uint32_t m_ifIndex
Interface index.
Mac48Address m_address
MAC address.
Ptr< Queue< Packet > > GetQueue() const
Get a copy of the attached Queue.
Ptr< Node > GetNode() const override
bool IsLinkUp() const override
void StartTransmission()
The StartTransmission method is used internally to start the process of sending a packet out on the c...
Address GetBroadcast() const override
NetDevice::PromiscReceiveCallback m_promiscCallback
Promiscuous receive callback.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
bool IsBroadcast() const override
bool SupportsSendFrom() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
Address GetAddress() const override
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.
Forward declaration of template class Queue.