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 
29 namespace ns3 {
30 
31 class Node;
32 
65 class BridgeNetDevice : public NetDevice
66 {
67 public:
68  static TypeId GetTypeId (void);
69  BridgeNetDevice ();
70  virtual ~BridgeNetDevice ();
71 
85  void AddBridgePort (Ptr<NetDevice> bridgePort);
86 
87  uint32_t GetNBridgePorts (void) const;
88 
89  Ptr<NetDevice> GetBridgePort (uint32_t n) const;
90 
91  // inherited from NetDevice base class.
92  virtual void SetIfIndex (const uint32_t index);
93  virtual uint32_t GetIfIndex (void) const;
94  virtual Ptr<Channel> GetChannel (void) const;
95  virtual void SetAddress (Address address);
96  virtual Address GetAddress (void) const;
97  virtual bool SetMtu (const uint16_t mtu);
98  virtual uint16_t GetMtu (void) const;
99  virtual bool IsLinkUp (void) const;
100  virtual void AddLinkChangeCallback (Callback<void> callback);
101  virtual bool IsBroadcast (void) const;
102  virtual Address GetBroadcast (void) const;
103  virtual bool IsMulticast (void) const;
104  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
105  virtual bool IsPointToPoint (void) const;
106  virtual bool IsBridge (void) const;
107  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
108  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
109  virtual Ptr<Node> GetNode (void) const;
110  virtual void SetNode (Ptr<Node> node);
111  virtual bool NeedsArp (void) const;
114  virtual bool SupportsSendFrom () const;
115  virtual Address GetMulticast (Ipv6Address addr) const;
116 
117 protected:
118  virtual void DoDispose (void);
119 
120  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
121  Address const &source, Address const &destination, PacketType packetType);
122  void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
123  uint16_t protocol, Mac48Address src, Mac48Address dst);
124  void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
125  uint16_t protocol, Mac48Address src, Mac48Address dst);
126  void Learn (Mac48Address source, Ptr<NetDevice> port);
128 
129 private:
132 
135 
137  Time m_expirationTime; // time it takes for learned MAC state to expire
139  {
142  };
143  std::map<Mac48Address, LearnedState> m_learnState;
146  std::vector< Ptr<NetDevice> > m_ports;
147  uint32_t m_ifIndex;
148  uint16_t m_mtu;
150 };
151 
152 } // namespace ns3
153 
154 #endif /* BRIDGE_NET_DEVICE_H */
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' 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:95
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void Learn(Mac48Address source, Ptr< NetDevice > port)
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< NetDevice > GetLearnedState(Mac48Address source)
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual void SetIfIndex(const uint32_t index)
virtual uint32_t GetIfIndex(void) const
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:272
virtual bool IsMulticast(void) const
virtual Ptr< Channel > GetChannel(void) const
static TypeId GetTypeId(void)
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)
NetDevice::PromiscReceiveCallback m_promiscRxCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
Ptr< NetDevice > GetBridgePort(uint32_t n) const
std::vector< Ptr< NetDevice > > m_ports
virtual uint16_t GetMtu(void) const
virtual bool SetMtu(const uint16_t mtu)
virtual bool SupportsSendFrom() const
virtual bool IsBroadcast(void) const
virtual Address GetBroadcast(void) const
virtual bool NeedsArp(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
NetDevice::ReceiveCallback m_rxCallback
virtual Address GetAddress(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
an EUI-48 address
Definition: mac48-address.h:43
virtual Ptr< Node > GetNode(void) const
virtual void DoDispose(void)
Destructor implementation.
std::map< Mac48Address, LearnedState > m_learnState
Describes an IPv6 address.
Definition: ipv6-address.h:47
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Network layer to device interface.
Definition: net-device.h:75
BridgeNetDevice & operator=(const BridgeNetDevice &)
Ptr< BridgeChannel > m_channel
uint32_t GetNBridgePorts(void) const
tuple address
Definition: first.py:37
virtual void SetNode(Ptr< Node > node)
a unique identifier for an interface.
Definition: type-id.h:51
virtual bool IsLinkUp(void) const
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType)