A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mesh-point-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008,2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Kirill Andreev <andreev@iitp.ru>
7 * Pavel Boyko <boyko@iitp.ru>
8 */
9
10#ifndef L2ROUTING_NET_DEVICE_H
11#define L2ROUTING_NET_DEVICE_H
12
14
15#include "ns3/bridge-channel.h"
16#include "ns3/mac48-address.h"
17#include "ns3/net-device.h"
18#include "ns3/node.h"
19#include "ns3/random-variable-stream.h"
20
21namespace ns3
22{
23
24/**
25 * \ingroup mesh
26 *
27 * \brief Virtual net device modeling mesh point.
28 *
29 * Mesh point is a virtual net device which is responsible for
30 * - Aggregating and coordinating 1..* real devices -- mesh interfaces, see MeshInterfaceDevice
31 * class.
32 * - Hosting all mesh-related level 2 protocols.
33 *
34 * One of hosted L2 protocols must implement L2RoutingProtocol interface and is used for packets
35 * forwarding.
36 *
37 * From the level 3 point of view MeshPointDevice is similar to BridgeNetDevice, but the packets,
38 * which going through may be changed (because L2 protocols may require their own headers or tags).
39 *
40 * Attributes: \todo
41 */
43{
44 public:
45 /**
46 * \brief Get the type ID.
47 * \return the object TypeId
48 */
49 static TypeId GetTypeId();
50 /// C-tor create empty (without interfaces and protocols) mesh point
52 /// D-tor
53 ~MeshPointDevice() override;
54
55 /// \name Interfaces
56 ///@{
57 /**
58 * \brief Attach new interface to the station. Interface must support 48-bit MAC address and
59 * SendFrom method.
60 * \param port the port used
61 *
62 * \attention Only MeshPointDevice can have IP address, but not individual interfaces.
63 */
65 /**
66 * \return number of interfaces
67 */
69 /**
70 * \return interface device by its index (aka ID)
71 * \param id is interface id, 0 <= id < GetNInterfaces
72 */
74 /**
75 * \return vector of interfaces
76 */
77 std::vector<Ptr<NetDevice>> GetInterfaces() const;
78 ///@}
79
80 /// \name Protocols
81 ///@{
82 /**
83 * Register routing protocol to be used. Protocol must be already installed on this mesh point.
84 *
85 * \param protocol the routing protocol
86 */
88 /**
89 * Access current routing protocol
90 *
91 * \return the current routing protocol
92 */
94 ///@}
95
96 // Inherited from NetDevice
97 void SetIfIndex(const uint32_t index) override;
98 uint32_t GetIfIndex() const override;
99 Ptr<Channel> GetChannel() const override;
100 Address GetAddress() const override;
101 void SetAddress(Address a) override;
102 bool SetMtu(const uint16_t mtu) override;
103 uint16_t GetMtu() const override;
104 bool IsLinkUp() const override;
105 void AddLinkChangeCallback(Callback<void> callback) override;
106 bool IsBroadcast() const override;
107 Address GetBroadcast() const override;
108 bool IsMulticast() const override;
109 Address GetMulticast(Ipv4Address multicastGroup) const override;
110 bool IsPointToPoint() const override;
111 bool IsBridge() const override;
112 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
113 bool SendFrom(Ptr<Packet> packet,
114 const Address& source,
115 const Address& dest,
116 uint16_t protocolNumber) override;
117 Ptr<Node> GetNode() const override;
118 void SetNode(Ptr<Node> node) override;
119 bool NeedsArp() const override;
122 bool SupportsSendFrom() const override;
123 Address GetMulticast(Ipv6Address addr) const override;
124 void DoDispose() override;
125
126 /// \name Statistics
127 ///@{
128 /**
129 * Print statistics counters
130 * \param os the output stream
131 */
132 void Report(std::ostream& os) const;
133 /// Reset statistics counters
134 void ResetStats();
135 ///@}
136
137 /**
138 * Assign a fixed random variable stream number to the random variables
139 * used by this model. Return the number of streams (possibly zero) that
140 * have been assigned.
141 *
142 * \param stream first stream index to use
143 * \return the number of stream indices assigned by this model
144 */
145 int64_t AssignStreams(int64_t stream);
146
147 /**
148 * Return a (random) forwarding delay value from the random variable
149 * ForwardingDelay attribute.
150 *
151 * \return A Time value from the ForwardingDelay random variable
152 */
153 Time GetForwardingDelay() const;
154
155 private:
156 /**
157 * Receive packet from interface
158 *
159 * \param device the device to receive from
160 * \param packet the received packet
161 * \param protocol the protocol
162 * \param source the source address
163 * \param destination the destination address
164 * \param packetType the packet type
165 */
167 Ptr<const Packet> packet,
168 uint16_t protocol,
169 const Address& source,
170 const Address& destination,
171 PacketType packetType);
172 /**
173 * Forward packet down to interfaces
174 *
175 * \param incomingPort the incoming port
176 * \param packet the packet to forward
177 * \param protocol the protocol
178 * \param src the source MAC address
179 * \param dst the destination MAC address
180 */
181 void Forward(Ptr<NetDevice> incomingPort,
182 Ptr<const Packet> packet,
183 uint16_t protocol,
184 const Mac48Address src,
185 const Mac48Address dst);
186 /**
187 * \brief Response callback for L2 routing protocol. This will be executed when routing
188 * information is ready.
189 *
190 * \param success True is route found.
191 * \param packet Packet to send
192 * \param src Source MAC address
193 * \param dst Destination MAC address
194 * \param protocol Protocol ID
195 * \param iface Interface to use (ID) for send (decided by routing protocol). All
196 * interfaces will be used if outIface = 0xffffffff \todo diagnose routing errors
197 */
198 void DoSend(bool success,
199 Ptr<Packet> packet,
200 Mac48Address src,
201 Mac48Address dst,
202 uint16_t protocol,
203 uint32_t iface);
204
205 private:
206 /// Receive action
208 /// Promisc receive action
210 /// Mesh point MAC address, supposed to be the address of the first added interface
212 /// Parent node
214 /// List of interfaces
215 std::vector<Ptr<NetDevice>> m_ifaces;
216 /// If index
218 /// MTU in bytes
219 uint16_t m_mtu;
220 /// Virtual channel for upper layers
222 /// Current routing protocol, used mainly by GetRoutingProtocol
224 /// Random variable used for forwarding delay and jitter
226
227 /// statistics counters
229 {
230 uint32_t unicastData; ///< unicast data
231 uint32_t unicastDataBytes; ///< unicast data bytes
232 uint32_t broadcastData; ///< broadcast data
233 uint32_t broadcastDataBytes; ///< broadcast data bytes
234
235 /// constructor
236 Statistics();
237 };
238
239 // Counters
240 Statistics m_rxStats; ///< receive statistics
241 Statistics m_txStats; ///< transmit statistics
242 Statistics m_fwdStats; ///< forward statistics
243};
244} // namespace ns3
245#endif
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
an EUI-48 address
Virtual net device modeling mesh point.
void AddInterface(Ptr< NetDevice > port)
Attach new interface to the station.
Ptr< Node > GetNode() const override
void DoSend(bool success, Ptr< Packet > packet, Mac48Address src, Mac48Address dst, uint16_t protocol, uint32_t iface)
Response callback for L2 routing protocol.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
uint32_t m_ifIndex
If index.
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
uint16_t m_mtu
MTU in bytes.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
Ptr< Node > m_node
Parent node.
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
void SetRoutingProtocol(Ptr< MeshL2RoutingProtocol > protocol)
Register routing protocol to be used.
void SetIfIndex(const uint32_t index) override
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void DoDispose() override
Destructor implementation.
bool SupportsSendFrom() const override
Ptr< Channel > GetChannel() const override
Ptr< RandomVariableStream > m_forwardingRandomVariable
Random variable used for forwarding delay and jitter.
Ptr< BridgeChannel > m_channel
Virtual channel for upper layers.
void SetAddress(Address a) override
Set the address of this interface.
Ptr< NetDevice > GetInterface(uint32_t id) const
NetDevice::ReceiveCallback m_rxCallback
Receive action.
bool IsMulticast() const override
Statistics m_fwdStats
forward statistics
std::vector< Ptr< NetDevice > > GetInterfaces() const
void AddLinkChangeCallback(Callback< void > callback) override
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
std::vector< Ptr< NetDevice > > m_ifaces
List of interfaces.
void Forward(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, const Mac48Address src, const Mac48Address dst)
Forward packet down to interfaces.
bool IsLinkUp() const override
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
Receive packet from interface.
MeshPointDevice()
C-tor create empty (without interfaces and protocols) mesh point.
static TypeId GetTypeId()
Get the type ID.
uint16_t GetMtu() const override
bool IsBroadcast() const override
void Report(std::ostream &os) const
Print statistics counters.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
Promisc receive action.
Statistics m_rxStats
receive statistics
bool IsBridge() const override
Return true if the net device is acting as a bridge.
uint32_t GetIfIndex() const override
bool SetMtu(const uint16_t mtu) override
void SetNode(Ptr< Node > node) override
Statistics m_txStats
transmit statistics
Mac48Address m_address
Mesh point MAC address, supposed to be the address of the first added interface.
Address GetAddress() const override
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< MeshL2RoutingProtocol > m_routingProtocol
Current routing protocol, used mainly by GetRoutingProtocol.
uint32_t GetNInterfaces() const
Address GetBroadcast() const override
void ResetStats()
Reset statistics counters.
Time GetForwardingDelay() const
Return a (random) forwarding delay value from the random variable ForwardingDelay attribute.
Ptr< MeshL2RoutingProtocol > GetRoutingProtocol() const
Access current routing protocol.
~MeshPointDevice() override
D-tor.
bool NeedsArp() const override
Network layer to device interface.
Definition net-device.h:87
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
uint16_t port
Definition dsdv-manet.cc:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t broadcastData
broadcast data
uint32_t unicastDataBytes
unicast data bytes
uint32_t broadcastDataBytes
broadcast data bytes