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 * 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 * Authors: Kirill Andreev <andreev@iitp.ru>
18 * Pavel Boyko <boyko@iitp.ru>
19 */
20
21#ifndef L2ROUTING_NET_DEVICE_H
22#define L2ROUTING_NET_DEVICE_H
23
25
26#include "ns3/bridge-channel.h"
27#include "ns3/mac48-address.h"
28#include "ns3/net-device.h"
29#include "ns3/node.h"
30#include "ns3/random-variable-stream.h"
31
32namespace ns3
33{
34
35/**
36 * \ingroup mesh
37 *
38 * \brief Virtual net device modeling mesh point.
39 *
40 * Mesh point is a virtual net device which is responsible for
41 * - Aggregating and coordinating 1..* real devices -- mesh interfaces, see MeshInterfaceDevice
42 * class.
43 * - Hosting all mesh-related level 2 protocols.
44 *
45 * One of hosted L2 protocols must implement L2RoutingProtocol interface and is used for packets
46 * forwarding.
47 *
48 * From the level 3 point of view MeshPointDevice is similar to BridgeNetDevice, but the packets,
49 * which going through may be changed (because L2 protocols may require their own headers or tags).
50 *
51 * Attributes: \todo
52 */
54{
55 public:
56 /**
57 * \brief Get the type ID.
58 * \return the object TypeId
59 */
60 static TypeId GetTypeId();
61 /// C-tor create empty (without interfaces and protocols) mesh point
63 /// D-tor
64 ~MeshPointDevice() override;
65
66 /// \name Interfaces
67 ///@{
68 /**
69 * \brief Attach new interface to the station. Interface must support 48-bit MAC address and
70 * SendFrom method.
71 * \param port the port used
72 *
73 * \attention Only MeshPointDevice can have IP address, but not individual interfaces.
74 */
76 /**
77 * \return number of interfaces
78 */
80 /**
81 * \return interface device by its index (aka ID)
82 * \param id is interface id, 0 <= id < GetNInterfaces
83 */
85 /**
86 * \return vector of interfaces
87 */
88 std::vector<Ptr<NetDevice>> GetInterfaces() const;
89 ///@}
90
91 /// \name Protocols
92 ///@{
93 /**
94 * Register routing protocol to be used. Protocol must be already installed on this mesh point.
95 *
96 * \param protocol the routing protocol
97 */
99 /**
100 * Access current routing protocol
101 *
102 * \return the current routing protocol
103 */
105 ///@}
106
107 // Inherited from NetDevice
108 void SetIfIndex(const uint32_t index) override;
109 uint32_t GetIfIndex() const override;
110 Ptr<Channel> GetChannel() const override;
111 Address GetAddress() const override;
112 void SetAddress(Address a) override;
113 bool SetMtu(const uint16_t mtu) override;
114 uint16_t GetMtu() const override;
115 bool IsLinkUp() const override;
116 void AddLinkChangeCallback(Callback<void> callback) override;
117 bool IsBroadcast() const override;
118 Address GetBroadcast() const override;
119 bool IsMulticast() const override;
120 Address GetMulticast(Ipv4Address multicastGroup) const override;
121 bool IsPointToPoint() const override;
122 bool IsBridge() const override;
123 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
124 bool SendFrom(Ptr<Packet> packet,
125 const Address& source,
126 const Address& dest,
127 uint16_t protocolNumber) override;
128 Ptr<Node> GetNode() const override;
129 void SetNode(Ptr<Node> node) override;
130 bool NeedsArp() const override;
133 bool SupportsSendFrom() const override;
134 Address GetMulticast(Ipv6Address addr) const override;
135 void DoDispose() override;
136
137 /// \name Statistics
138 ///@{
139 /**
140 * Print statistics counters
141 * \param os the output stream
142 */
143 void Report(std::ostream& os) const;
144 /// Reset statistics counters
145 void ResetStats();
146 ///@}
147
148 /**
149 * Assign a fixed random variable stream number to the random variables
150 * used by this model. Return the number of streams (possibly zero) that
151 * have been assigned.
152 *
153 * \param stream first stream index to use
154 * \return the number of stream indices assigned by this model
155 */
156 int64_t AssignStreams(int64_t stream);
157
158 /**
159 * Return a (random) forwarding delay value from the random variable
160 * ForwardingDelay attribute.
161 *
162 * \return A Time value from the ForwardingDelay random variable
163 */
164 Time GetForwardingDelay() const;
165
166 private:
167 /**
168 * Receive packet from interface
169 *
170 * \param device the device to receive from
171 * \param packet the received packet
172 * \param protocol the protocol
173 * \param source the source address
174 * \param destination the destination address
175 * \param packetType the packet type
176 */
178 Ptr<const Packet> packet,
179 uint16_t protocol,
180 const Address& source,
181 const Address& destination,
182 PacketType packetType);
183 /**
184 * Forward packet down to interfaces
185 *
186 * \param incomingPort the incoming port
187 * \param packet the packet to forward
188 * \param protocol the protocol
189 * \param src the source MAC address
190 * \param dst the destination MAC address
191 */
192 void Forward(Ptr<NetDevice> incomingPort,
193 Ptr<const Packet> packet,
194 uint16_t protocol,
195 const Mac48Address src,
196 const Mac48Address dst);
197 /**
198 * \brief Response callback for L2 routing protocol. This will be executed when routing
199 * information is ready.
200 *
201 * \param success True is route found.
202 * \param packet Packet to send
203 * \param src Source MAC address
204 * \param dst Destination MAC address
205 * \param protocol Protocol ID
206 * \param iface Interface to use (ID) for send (decided by routing protocol). All
207 * interfaces will be used if outIface = 0xffffffff \todo diagnose routing errors
208 */
209 void DoSend(bool success,
210 Ptr<Packet> packet,
211 Mac48Address src,
212 Mac48Address dst,
213 uint16_t protocol,
214 uint32_t iface);
215
216 private:
217 /// Receive action
219 /// Promisc receive action
221 /// Mesh point MAC address, supposed to be the address of the first added interface
223 /// Parent node
225 /// List of interfaces
226 std::vector<Ptr<NetDevice>> m_ifaces;
227 /// If index
229 /// MTU in bytes
230 uint16_t m_mtu;
231 /// Virtual channel for upper layers
233 /// Current routing protocol, used mainly by GetRoutingProtocol
235 /// Random variable used for forwarding delay and jitter
237
238 /// statistics counters
240 {
241 uint32_t unicastData; ///< unicast data
242 uint32_t unicastDataBytes; ///< unicast data bytes
243 uint32_t broadcastData; ///< broadcast data
244 uint32_t broadcastDataBytes; ///< broadcast data bytes
245
246 /// constructor
247 Statistics();
248 };
249
250 // Counters
251 Statistics m_rxStats; ///< receive statistics
252 Statistics m_txStats; ///< transmit statistics
253 Statistics m_fwdStats; ///< forward statistics
254};
255} // namespace ns3
256#endif
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
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
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:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
uint16_t port
Definition: dsdv-manet.cc:44
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