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
36namespace ns3
37{
38
39class Node;
40
74{
75 public:
80 static TypeId GetTypeId();
82 ~BridgeNetDevice() override;
83
84 // Delete copy constructor and assignment operator to avoid misuse
87
101 void AddBridgePort(Ptr<NetDevice> bridgePort);
102
109
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
159 Ptr<const Packet> packet,
160 uint16_t protocol,
161 const Address& source,
162 const Address& destination,
163 PacketType packetType);
164
173 void ForwardUnicast(Ptr<NetDevice> incomingPort,
174 Ptr<const Packet> packet,
175 uint16_t protocol,
176 Mac48Address src,
177 Mac48Address dst);
178
187 void ForwardBroadcast(Ptr<NetDevice> incomingPort,
188 Ptr<const Packet> packet,
189 uint16_t protocol,
190 Mac48Address src,
191 Mac48Address dst);
192
199
206
207 private:
210
213
219 {
222 };
223
224 std::map<Mac48Address, LearnedState> m_learnState;
227 std::vector<Ptr<NetDevice>> m_ports;
229 uint16_t m_mtu;
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