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 
95  void AddBridgePort (Ptr<NetDevice> bridgePort);
96 
102  uint32_t GetNBridgePorts (void) const;
103 
109  Ptr<NetDevice> GetBridgePort (uint32_t n) const;
110 
111  // inherited from NetDevice base class.
112  virtual void SetIfIndex (const uint32_t index);
113  virtual uint32_t GetIfIndex (void) const;
114  virtual Ptr<Channel> GetChannel (void) const;
115  virtual void SetAddress (Address address);
116  virtual Address GetAddress (void) const;
117  virtual bool SetMtu (const uint16_t mtu);
118  virtual uint16_t GetMtu (void) const;
119  virtual bool IsLinkUp (void) const;
120  virtual void AddLinkChangeCallback (Callback<void> callback);
121  virtual bool IsBroadcast (void) const;
122  virtual Address GetBroadcast (void) const;
123  virtual bool IsMulticast (void) const;
124  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
125  virtual bool IsPointToPoint (void) const;
126  virtual bool IsBridge (void) const;
127  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
128  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
129  virtual Ptr<Node> GetNode (void) const;
130  virtual void SetNode (Ptr<Node> node);
131  virtual bool NeedsArp (void) const;
134  virtual bool SupportsSendFrom () const;
135  virtual Address GetMulticast (Ipv6Address addr) const;
136 
137 protected:
138  virtual void DoDispose (void);
139 
149  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
150  Address const &source, Address const &destination, PacketType packetType);
151 
160  void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
161  uint16_t protocol, Mac48Address src, Mac48Address dst);
162 
171  void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
172  uint16_t protocol, Mac48Address src, Mac48Address dst);
173 
179  void Learn (Mac48Address source, Ptr<NetDevice> port);
180 
187 
188 private:
195 
203 
206 
209 
215  {
218  };
219  std::map<Mac48Address, LearnedState> m_learnState;
222  std::vector< Ptr<NetDevice> > m_ports;
223  uint32_t m_ifIndex;
224  uint16_t m_mtu;
226 };
227 
228 } // namespace ns3
229 
230 #endif /* BRIDGE_NET_DEVICE_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::BridgeNetDevice::AddBridgePort
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' to a bridge device.
Definition: bridge-net-device.cc:250
ns3::BridgeNetDevice::ForwardBroadcast
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a broadcast or a multicast packet.
Definition: bridge-net-device.cc:175
ns3::Callback< void >
ns3::BridgeNetDevice::ReceiveFromDevice
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.
Definition: bridge-net-device.cc:95
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::BridgeNetDevice::BridgeNetDevice
BridgeNetDevice()
Definition: bridge-net-device.cc:67
ns3::BridgeNetDevice::GetMulticast
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Definition: bridge-net-device.cc:361
ns3::BridgeNetDevice::SetAddress
virtual void SetAddress(Address address)
Set the address of this interface.
Definition: bridge-net-device.cc:296
ns3::BridgeNetDevice::ForwardUnicast
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
Definition: bridge-net-device.cc:140
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::BridgeNetDevice::m_promiscRxCallback
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
Definition: bridge-net-device.h:205
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::BridgeNetDevice::m_learnState
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
Definition: bridge-net-device.h:219
ns3::BridgeNetDevice::IsBridge
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Definition: bridge-net-device.cc:377
ns3::Ptr< NetDevice >
ns3::BridgeNetDevice::m_expirationTime
Time m_expirationTime
time it takes for learned MAC state to expire
Definition: bridge-net-device.h:208
ns3::BridgeNetDevice::GetChannel
virtual Ptr< Channel > GetChannel(void) const
Definition: bridge-net-device.cc:289
ns3::BridgeNetDevice::m_node
Ptr< Node > m_node
node owning this NetDevice
Definition: bridge-net-device.h:220
ns3::BridgeNetDevice::GetLearnedState
Ptr< NetDevice > GetLearnedState(Mac48Address source)
Gets the port associated to a source address.
Definition: bridge-net-device.cc:210
ns3::BridgeNetDevice::GetNode
virtual Ptr< Node > GetNode(void) const
Definition: bridge-net-device.cc:424
ns3::BridgeNetDevice::IsPointToPoint
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Definition: bridge-net-device.cc:370
ns3::BridgeNetDevice::m_mtu
uint16_t m_mtu
MTU of the bridged NetDevice.
Definition: bridge-net-device.h:224
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::BridgeNetDevice::GetMtu
virtual uint16_t GetMtu(void) const
Definition: bridge-net-device.cc:318
ns3::BridgeNetDevice::m_ports
std::vector< Ptr< NetDevice > > m_ports
bridged ports
Definition: bridge-net-device.h:222
ns3::BridgeNetDevice::SetIfIndex
virtual void SetIfIndex(const uint32_t index)
Definition: bridge-net-device.cc:275
ns3::BridgeNetDevice::~BridgeNetDevice
virtual ~BridgeNetDevice()
Definition: bridge-net-device.cc:75
ns3::BridgeNetDevice::GetNBridgePorts
uint32_t GetNBridgePorts(void) const
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
Definition: bridge-net-device.cc:235
first.address
address
Definition: first.py:44
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::BridgeNetDevice::m_ifIndex
uint32_t m_ifIndex
Interface index.
Definition: bridge-net-device.h:223
ns3::BridgeNetDevice::LearnedState::associatedPort
Ptr< NetDevice > associatedPort
port associated with the address
Definition: bridge-net-device.h:216
ns3::BridgeNetDevice::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: bridge-net-device.cc:41
ns3::BridgeNetDevice::GetBridgePort
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
Definition: bridge-net-device.cc:243
ns3::BridgeNetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const
Definition: bridge-net-device.cc:282
ns3::BridgeNetDevice::SetPromiscReceiveCallback
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
Definition: bridge-net-device.cc:455
ns3::BridgeNetDevice::NeedsArp
virtual bool NeedsArp(void) const
Definition: bridge-net-device.cc:440
ns3::BridgeNetDevice::IsLinkUp
virtual bool IsLinkUp(void) const
Definition: bridge-net-device.cc:326
ns3::BridgeNetDevice::SendFrom
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Definition: bridge-net-device.cc:392
ns3::BridgeNetDevice::m_rxCallback
NetDevice::ReceiveCallback m_rxCallback
receive callback
Definition: bridge-net-device.h:204
ns3::BridgeNetDevice::LearnedState
Structure holding the status of an address.
Definition: bridge-net-device.h:215
ns3::BridgeNetDevice::IsBroadcast
virtual bool IsBroadcast(void) const
Definition: bridge-net-device.cc:339
ns3::BridgeNetDevice::SupportsSendFrom
virtual bool SupportsSendFrom() const
Definition: bridge-net-device.cc:462
ns3::BridgeNetDevice::GetBroadcast
virtual Address GetBroadcast(void) const
Definition: bridge-net-device.cc:347
ns3::BridgeNetDevice::LearnedState::expirationTime
Time expirationTime
time it takes for learned MAC state to expire
Definition: bridge-net-device.h:217
ns3::BridgeNetDevice::m_address
Mac48Address m_address
MAC address of the NetDevice.
Definition: bridge-net-device.h:207
ns3::BridgeNetDevice::operator=
BridgeNetDevice & operator=(const BridgeNetDevice &)
Copy constructor.
ns3::NetDevice::PacketType
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
ns3::BridgeNetDevice::AddLinkChangeCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
Definition: bridge-net-device.cc:334
ns3::BridgeNetDevice::GetAddress
virtual Address GetAddress(void) const
Definition: bridge-net-device.cc:303
ns3::BridgeNetDevice::m_channel
Ptr< BridgeChannel > m_channel
virtual bridged channel
Definition: bridge-net-device.h:221
ns3::BridgeNetDevice::SetNode
virtual void SetNode(Ptr< Node > node)
Definition: bridge-net-device.cc:432
ns3::BridgeNetDevice::Send
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Definition: bridge-net-device.cc:385
ns3::BridgeNetDevice
a virtual net device that bridges multiple LAN segments
Definition: bridge-net-device.h:72
ns3::BridgeNetDevice::BridgeNetDevice
BridgeNetDevice(const BridgeNetDevice &)
Copy constructor.
ns3::BridgeNetDevice::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: bridge-net-device.cc:81
ns3::BridgeNetDevice::m_enableLearning
bool m_enableLearning
true if the bridge will learn the node status
Definition: bridge-net-device.h:225
ns3::BridgeNetDevice::SetMtu
virtual bool SetMtu(const uint16_t mtu)
Definition: bridge-net-device.cc:310
ns3::BridgeNetDevice::Learn
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
Definition: bridge-net-device.cc:199
ns3::BridgeNetDevice::SetReceiveCallback
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Definition: bridge-net-device.cc:448
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::BridgeNetDevice::IsMulticast
virtual bool IsMulticast(void) const
Definition: bridge-net-device.cc:354
ns3::NetDevice
Network layer to device interface.
Definition: net-device.h:96
port
uint16_t port
Definition: dsdv-manet.cc:45