1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation;
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * Author: Gustavo Carneiro <gjc@inescporto.pt>
18 #ifndef BRIDGE_NET_DEVICE_H
19 #define BRIDGE_NET_DEVICE_H
21 #include "ns3/net-device.h"
22 #include "ns3/mac48-address.h"
23 #include "ns3/nstime.h"
24 #include "ns3/bridge-channel.h"
35 * \defgroup bridge Bridge
37 * \brief a virtual net device that bridges multiple LAN segments
39 * The BridgeNetDevice object is a "virtual" netdevice that aggregates
40 * multiple "real" netdevices and implements the data plane forwarding
41 * part of IEEE 802.1D. By adding a BridgeNetDevice to a Node, it
42 * will act as a "bridge", or "switch", to multiple LAN segments.
44 * By default the bridge netdevice implements a "learning bridge"
45 * algorithm (see 802.1D), where incoming unicast frames from one port
46 * may occasionally be forwarded throughout all other ports, but
47 * usually they are forwarded only to a single correct output port.
49 * \attention The Spanning Tree Protocol part of 802.1D is not
50 * implemented. Therefore, you have to be careful not to create
51 * bridging loops, or else the network will collapse.
53 * \attention Bridging is designed to work only with NetDevices
54 * modelling IEEE 802-style technologies, such as CsmaNetDevice and
57 * \attention If including a WifiNetDevice in a bridge, the wifi
58 * device must be in Access Point mode. Adhoc mode is not supported
64 * \brief a virtual net device that bridges multiple LAN segments
66 class BridgeNetDevice : public NetDevice
69 static TypeId GetTypeId (void);
72 /** \brief Add a 'port' to a bridge device
74 * This method adds a new bridge port to a BridgeNetDevice, so that
75 * the new bridge port NetDevice becomes part of the bridge and L2
76 * frames start being forwarded to/from this NetDevice.
78 * \attention The netdevice that is being added as bridge port must
79 * _not_ have an IP address. In order to add IP connectivity to a
80 * bridging node you must enable IP on the BridgeNetDevice itself,
81 * never on its port netdevices.
83 void AddBridgePort (Ptr<NetDevice> bridgePort);
85 // inherited from NetDevice base class.
86 virtual void SetName(const std::string name);
87 virtual std::string GetName(void) const;
88 virtual void SetIfIndex(const uint32_t index);
89 virtual uint32_t GetIfIndex(void) const;
90 virtual Ptr<Channel> GetChannel (void) const;
91 virtual Address GetAddress (void) const;
92 virtual bool SetMtu (const uint16_t mtu);
93 virtual uint16_t GetMtu (void) const;
94 virtual bool IsLinkUp (void) const;
95 virtual void SetLinkChangeCallback (Callback<void> callback);
96 virtual bool IsBroadcast (void) const;
97 virtual Address GetBroadcast (void) const;
98 virtual bool IsMulticast (void) const;
99 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
100 virtual bool IsPointToPoint (void) const;
101 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
102 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
103 virtual Ptr<Node> GetNode (void) const;
104 virtual void SetNode (Ptr<Node> node);
105 virtual bool NeedsArp (void) const;
106 virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
107 virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb);
108 virtual bool SupportsSendFrom () const;
109 virtual Address GetMulticast (Ipv6Address addr) const;
112 virtual void DoDispose (void);
114 void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
115 Address const &source, Address const &destination, PacketType packetType);
116 void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
117 uint16_t protocol, Mac48Address src, Mac48Address dst);
118 void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
119 uint16_t protocol, Mac48Address src, Mac48Address dst);
120 void Learn (Mac48Address source, Ptr<NetDevice> port);
121 Ptr<NetDevice> GetLearnedState (Mac48Address source);
124 NetDevice::ReceiveCallback m_rxCallback;
125 NetDevice::PromiscReceiveCallback m_promiscRxCallback;
127 Mac48Address m_address;
128 Time m_expirationTime; // time it takes for learned MAC state to expire
131 Ptr<NetDevice> associatedPort;
134 std::map<Mac48Address, LearnedState> m_learnState;
136 Ptr<BridgeChannel> m_channel;
138 std::vector< Ptr<NetDevice> > m_ports;
141 bool m_enableLearning;
146 #endif /* BRIDGE_NET_DEVICE_H */