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