A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bridge-net-device.h
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: Gustavo Carneiro <gjc@inescporto.pt>
16 */
17#ifndef BRIDGE_NET_DEVICE_H
18#define BRIDGE_NET_DEVICE_H
19
20#include "bridge-channel.h"
21
22#include "ns3/mac48-address.h"
23#include "ns3/net-device.h"
24#include "ns3/nstime.h"
25
26#include <map>
27#include <stdint.h>
28#include <string>
29
30/**
31 * \file
32 * \ingroup bridge
33 * ns3::BridgeNetDevice declaration.
34 */
35
36namespace ns3
37{
38
39class Node;
40
41/**
42 * \defgroup bridge Bridge Network Device
43 *
44 * \brief a virtual net device that bridges multiple LAN segments
45 *
46 * The BridgeNetDevice object is a "virtual" netdevice that aggregates
47 * multiple "real" netdevices and implements the data plane forwarding
48 * part of IEEE 802.1D. By adding a BridgeNetDevice to a Node, it
49 * will act as a "bridge", or "switch", to multiple LAN segments.
50 *
51 * By default the bridge netdevice implements a "learning bridge"
52 * algorithm (see 802.1D), where incoming unicast frames from one port
53 * may occasionally be forwarded throughout all other ports, but
54 * usually they are forwarded only to a single correct output port.
55 *
56 * \attention The Spanning Tree Protocol part of 802.1D is not
57 * implemented. Therefore, you have to be careful not to create
58 * bridging loops, or else the network will collapse.
59 *
60 * \attention Bridging is designed to work only with NetDevices
61 * modelling IEEE 802-style technologies, such as CsmaNetDevice and
62 * WifiNetDevice.
63 *
64 * \attention If including a WifiNetDevice in a bridge, the wifi
65 * device must be in Access Point mode. Adhoc mode is not supported
66 * with bridging.
67 */
68
69/**
70 * \ingroup bridge
71 * \brief a virtual net device that bridges multiple LAN segments
72 */
74{
75 public:
76 /**
77 * \brief Get the type ID.
78 * \return the object TypeId
79 */
80 static TypeId GetTypeId();
82 ~BridgeNetDevice() override;
83
84 // Delete copy constructor and assignment operator to avoid misuse
87
88 /**
89 * \brief Add a 'port' to a bridge device
90 * \param bridgePort the NetDevice to add
91 *
92 * This method adds a new bridge port to a BridgeNetDevice, so that
93 * the new bridge port NetDevice becomes part of the bridge and L2
94 * frames start being forwarded to/from this NetDevice.
95 *
96 * \attention The netdevice that is being added as bridge port must
97 * _not_ have an IP address. In order to add IP connectivity to a
98 * bridging node you must enable IP on the BridgeNetDevice itself,
99 * never on its port netdevices.
100 */
101 void AddBridgePort(Ptr<NetDevice> bridgePort);
102
103 /**
104 * \brief Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
105 *
106 * \return the number of bridged ports.
107 */
109
110 /**
111 * \brief Gets the n-th bridged port.
112 * \param n the port index
113 * \return the n-th bridged NetDevice
114 */
116
117 // inherited from NetDevice base class.
118 void SetIfIndex(const uint32_t index) override;
119 uint32_t GetIfIndex() const override;
120 Ptr<Channel> GetChannel() const override;
121 void SetAddress(Address address) override;
122 Address GetAddress() const override;
123 bool SetMtu(const uint16_t mtu) override;
124 uint16_t GetMtu() const override;
125 bool IsLinkUp() const override;
126 void AddLinkChangeCallback(Callback<void> callback) override;
127 bool IsBroadcast() const override;
128 Address GetBroadcast() const override;
129 bool IsMulticast() const override;
130 Address GetMulticast(Ipv4Address multicastGroup) const override;
131 bool IsPointToPoint() const override;
132 bool IsBridge() const override;
133 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
134 bool SendFrom(Ptr<Packet> packet,
135 const Address& source,
136 const Address& dest,
137 uint16_t protocolNumber) override;
138 Ptr<Node> GetNode() const override;
139 void SetNode(Ptr<Node> node) override;
140 bool NeedsArp() const override;
143 bool SupportsSendFrom() const override;
144 Address GetMulticast(Ipv6Address addr) const override;
145
146 protected:
147 void DoDispose() override;
148
149 /**
150 * \brief Receives a packet from one bridged port.
151 * \param device the originating port
152 * \param packet the received packet
153 * \param protocol the packet protocol (e.g., Ethertype)
154 * \param source the packet source
155 * \param destination the packet destination
156 * \param packetType the packet type (e.g., host, broadcast, etc.)
157 */
159 Ptr<const Packet> packet,
160 uint16_t protocol,
161 const Address& source,
162 const Address& destination,
163 PacketType packetType);
164
165 /**
166 * \brief Forwards a unicast packet
167 * \param incomingPort the packet incoming port
168 * \param packet the packet
169 * \param protocol the packet protocol (e.g., Ethertype)
170 * \param src the packet source
171 * \param dst the packet destination
172 */
173 void ForwardUnicast(Ptr<NetDevice> incomingPort,
174 Ptr<const Packet> packet,
175 uint16_t protocol,
176 Mac48Address src,
177 Mac48Address dst);
178
179 /**
180 * \brief Forwards a broadcast or a multicast packet
181 * \param incomingPort the packet incoming port
182 * \param packet the packet
183 * \param protocol the packet protocol (e.g., Ethertype)
184 * \param src the packet source
185 * \param dst the packet destination
186 */
187 void ForwardBroadcast(Ptr<NetDevice> incomingPort,
188 Ptr<const Packet> packet,
189 uint16_t protocol,
190 Mac48Address src,
191 Mac48Address dst);
192
193 /**
194 * \brief Learns the port a MAC address is sending from
195 * \param source source address
196 * \param port the port the source is sending from
197 */
199
200 /**
201 * \brief Gets the port associated to a source address
202 * \param source the source address
203 * \returns the port the source is associated to, or NULL if no association is known.
204 */
206
207 private:
210
211 Mac48Address m_address; //!< MAC address of the NetDevice
212 Time m_expirationTime; //!< time it takes for learned MAC state to expire
213
214 /**
215 * \ingroup bridge
216 * Structure holding the status of an address
217 */
219 {
220 Ptr<NetDevice> associatedPort; //!< port associated with the address
221 Time expirationTime; //!< time it takes for learned MAC state to expire
222 };
223
224 std::map<Mac48Address, LearnedState> m_learnState; //!< Container for known address statuses
225 Ptr<Node> m_node; //!< node owning this NetDevice
226 Ptr<BridgeChannel> m_channel; //!< virtual bridged channel
227 std::vector<Ptr<NetDevice>> m_ports; //!< bridged ports
228 uint32_t m_ifIndex; //!< Interface index
229 uint16_t m_mtu; //!< MTU of the bridged NetDevice
230 bool m_enableLearning; //!< true if the bridge will learn the node status
231};
232
233} // namespace ns3
234
235#endif /* BRIDGE_NET_DEVICE_H */
ns3::BridgeChannel declaration.
a polymophic address class
Definition: address.h:101
a virtual net device that bridges multiple LAN segments
bool IsBroadcast() const override
Ptr< BridgeChannel > m_channel
virtual bridged channel
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
Receives a packet from one bridged port.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
Ptr< Node > m_node
node owning this NetDevice
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
Address GetBroadcast() const override
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
uint32_t m_ifIndex
Interface index.
bool SupportsSendFrom() const override
BridgeNetDevice(const BridgeNetDevice &)=delete
Mac48Address m_address
MAC address of the NetDevice.
uint16_t GetMtu() const override
bool NeedsArp() const override
NetDevice::ReceiveCallback m_rxCallback
receive callback
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
static TypeId GetTypeId()
Get the type ID.
std::vector< Ptr< NetDevice > > m_ports
bridged ports
Time m_expirationTime
time it takes for learned MAC state to expire
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool IsMulticast() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void DoDispose() override
Destructor implementation.
uint32_t GetIfIndex() const override
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
Ptr< NetDevice > GetLearnedState(Mac48Address source)
Gets the port associated to a source address.
bool m_enableLearning
true if the bridge will learn the node status
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' to a bridge device.
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetNode(Ptr< Node > node) override
bool SetMtu(const uint16_t mtu) override
uint16_t m_mtu
MTU of the bridged NetDevice.
Ptr< Channel > GetChannel() const override
BridgeNetDevice & operator=(const BridgeNetDevice &)=delete
Address GetAddress() const override
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
void SetIfIndex(const uint32_t index) override
void AddLinkChangeCallback(Callback< void > callback) override
Ptr< Node > GetNode() const override
bool IsLinkUp() const override
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
void SetAddress(Address address) override
Set the address of this interface.
uint32_t GetNBridgePorts() const
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a broadcast or a multicast packet.
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
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
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.
Structure holding the status of an address.
Time expirationTime
time it takes for learned MAC state to expire
Ptr< NetDevice > associatedPort
port associated with the address