A Discrete-Event Network Simulator
API
bridge-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
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;
6  *
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.
11  *
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
15  *
16  * Author: Gustavo Carneiro <gjc@inescporto.pt>
17  */
18 #ifndef BRIDGE_NET_DEVICE_H
19 #define BRIDGE_NET_DEVICE_H
20 
21 #include "ns3/net-device.h"
22 #include "ns3/mac48-address.h"
23 #include "ns3/nstime.h"
24 #include "ns3/bridge-channel.h"
25 #include <stdint.h>
26 #include <string>
27 #include <map>
28 
35 namespace ns3 {
36 
37 class Node;
38 
71 class BridgeNetDevice : public NetDevice
72 {
73 public:
78  static TypeId GetTypeId (void);
79  BridgeNetDevice ();
80  virtual ~BridgeNetDevice ();
81 
96  void AddBridgePort (Ptr<NetDevice> bridgePort);
97 
103  uint32_t GetNBridgePorts (void) const;
104 
110  Ptr<NetDevice> GetBridgePort (uint32_t n) const;
111 
112  // inherited from NetDevice base class.
113  virtual void SetIfIndex (const uint32_t index);
114  virtual uint32_t GetIfIndex (void) const;
115  virtual Ptr<Channel> GetChannel (void) const;
116  virtual void SetAddress (Address address);
117  virtual Address GetAddress (void) const;
118  virtual bool SetMtu (const uint16_t mtu);
119  virtual uint16_t GetMtu (void) const;
120  virtual bool IsLinkUp (void) const;
121  virtual void AddLinkChangeCallback (Callback<void> callback);
122  virtual bool IsBroadcast (void) const;
123  virtual Address GetBroadcast (void) const;
124  virtual bool IsMulticast (void) const;
125  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
126  virtual bool IsPointToPoint (void) const;
127  virtual bool IsBridge (void) const;
128  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
129  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
130  virtual Ptr<Node> GetNode (void) const;
131  virtual void SetNode (Ptr<Node> node);
132  virtual bool NeedsArp (void) const;
135  virtual bool SupportsSendFrom () const;
136  virtual Address GetMulticast (Ipv6Address addr) const;
137 
138 protected:
139  virtual void DoDispose (void);
140 
150  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
151  Address const &source, Address const &destination, PacketType packetType);
152 
161  void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
162  uint16_t protocol, Mac48Address src, Mac48Address dst);
163 
172  void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
173  uint16_t protocol, Mac48Address src, Mac48Address dst);
174 
180  void Learn (Mac48Address source, Ptr<NetDevice> port);
181 
188 
189 private:
196 
204 
207 
210 
216  {
219  };
220  std::map<Mac48Address, LearnedState> m_learnState;
223  std::vector< Ptr<NetDevice> > m_ports;
224  uint32_t m_ifIndex;
225  uint16_t m_mtu;
227 };
228 
229 } // namespace ns3
230 
231 #endif /* BRIDGE_NET_DEVICE_H */
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a &#39;port&#39; to a bridge device.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Ptr< NetDevice > GetLearnedState(Mac48Address source)
Gets the port associated to a source address.
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a broadcast or a multicast packet.
virtual bool IsMulticast(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual void SetIfIndex(const uint32_t index)
Time expirationTime
time it takes for learned MAC state to expire
virtual bool IsLinkUp(void) const
virtual Ptr< Node > GetNode(void) const
static TypeId GetTypeId(void)
Get the type ID.
virtual bool NeedsArp(void) const
virtual void SetAddress(Address address)
Set the address of this interface.
a virtual net device that bridges multiple LAN segments
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual Address GetAddress(void) const
uint32_t GetNBridgePorts(void) const
Gets the number of bridged &#39;ports&#39;, i.e., the NetDevices currently bridged.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void AddLinkChangeCallback(Callback< void > callback)
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
Ptr< NetDevice > associatedPort
port associated with the address
std::vector< Ptr< NetDevice > > m_ports
bridged ports
virtual bool SetMtu(const uint16_t mtu)
uint32_t m_ifIndex
Interface index.
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
address
Definition: first.py:44
NetDevice::ReceiveCallback m_rxCallback
receive callback
Mac48Address m_address
MAC address of the NetDevice.
virtual bool IsBroadcast(void) const
an EUI-48 address
Definition: mac48-address.h:43
virtual uint32_t GetIfIndex(void) const
virtual void DoDispose(void)
Destructor implementation.
Ptr< Node > m_node
node owning this NetDevice
virtual Address GetBroadcast(void) const
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
Structure holding the status of an address.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
uint16_t m_mtu
MTU of the bridged NetDevice.
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
Network layer to device interface.
Definition: net-device.h:95
bool m_enableLearning
true if the bridge will learn the node status
BridgeNetDevice & operator=(const BridgeNetDevice &)
Copy constructor.
Ptr< BridgeChannel > m_channel
virtual bridged channel
Time m_expirationTime
time it takes for learned MAC state to expire
virtual uint16_t GetMtu(void) const
virtual bool SupportsSendFrom() const
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
virtual void SetNode(Ptr< Node > node)
a unique identifier for an interface.
Definition: type-id.h:58
virtual Ptr< Channel > GetChannel(void) const
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType)
Receives a packet from one bridged port.