A Discrete-Event Network Simulator
API
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 "ns3/bridge-channel.h"
21 #include "ns3/mac48-address.h"
22 #include "ns3/net-device.h"
23 #include "ns3/nstime.h"
24 
25 #include <map>
26 #include <stdint.h>
27 #include <string>
28 
35 namespace ns3
36 {
37 
38 class Node;
39 
72 class BridgeNetDevice : public NetDevice
73 {
74  public:
79  static TypeId GetTypeId();
81  ~BridgeNetDevice() override;
82 
83  // Delete copy constructor and assignment operator to avoid misuse
84  BridgeNetDevice(const BridgeNetDevice&) = delete;
86 
100  void AddBridgePort(Ptr<NetDevice> bridgePort);
101 
107  uint32_t GetNBridgePorts() const;
108 
114  Ptr<NetDevice> GetBridgePort(uint32_t n) const;
115 
116  // inherited from NetDevice base class.
117  void SetIfIndex(const uint32_t index) override;
118  uint32_t GetIfIndex() const override;
119  Ptr<Channel> GetChannel() const override;
120  void SetAddress(Address address) override;
121  Address GetAddress() const override;
122  bool SetMtu(const uint16_t mtu) override;
123  uint16_t GetMtu() const override;
124  bool IsLinkUp() const override;
125  void AddLinkChangeCallback(Callback<void> callback) override;
126  bool IsBroadcast() const override;
127  Address GetBroadcast() const override;
128  bool IsMulticast() const override;
129  Address GetMulticast(Ipv4Address multicastGroup) const override;
130  bool IsPointToPoint() const override;
131  bool IsBridge() const override;
132  bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
133  bool SendFrom(Ptr<Packet> packet,
134  const Address& source,
135  const Address& dest,
136  uint16_t protocolNumber) override;
137  Ptr<Node> GetNode() const override;
138  void SetNode(Ptr<Node> node) override;
139  bool NeedsArp() const override;
142  bool SupportsSendFrom() const override;
143  Address GetMulticast(Ipv6Address addr) const override;
144 
145  protected:
146  void DoDispose() override;
147 
157  void ReceiveFromDevice(Ptr<NetDevice> device,
158  Ptr<const Packet> packet,
159  uint16_t protocol,
160  const Address& source,
161  const Address& destination,
162  PacketType packetType);
163 
172  void ForwardUnicast(Ptr<NetDevice> incomingPort,
173  Ptr<const Packet> packet,
174  uint16_t protocol,
175  Mac48Address src,
176  Mac48Address dst);
177 
186  void ForwardBroadcast(Ptr<NetDevice> incomingPort,
187  Ptr<const Packet> packet,
188  uint16_t protocol,
189  Mac48Address src,
190  Mac48Address dst);
191 
197  void Learn(Mac48Address source, Ptr<NetDevice> port);
198 
205 
206  private:
209 
212 
218  {
221  };
222 
223  std::map<Mac48Address, LearnedState> m_learnState;
226  std::vector<Ptr<NetDevice>> m_ports;
227  uint32_t m_ifIndex;
228  uint16_t m_mtu;
230 };
231 
232 } // namespace ns3
233 
234 #endif /* BRIDGE_NET_DEVICE_H */
a polymophic address class
Definition: address.h:100
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.
BridgeNetDevice & operator=(const BridgeNetDevice &)=delete
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
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
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Describes an IPv6 address.
Definition: ipv6-address.h:50
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:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
uint16_t port
Definition: dsdv-manet.cc:45
address
Definition: first.py:40
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