A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 */