A Discrete-Event Network Simulator
Go to the documentation of this file.
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;
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
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 */
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>
35namespace ns3 {
37class Node;
78 static TypeId GetTypeId (void);
80 virtual ~BridgeNetDevice ();
82 // Delete copy constructor and assignment operator to avoid misuse
83 BridgeNetDevice (const BridgeNetDevice &) = delete;
99 void AddBridgePort (Ptr<NetDevice> bridgePort);
106 uint32_t GetNBridgePorts (void) const;
115 // inherited from NetDevice base class.
116 virtual void SetIfIndex (const uint32_t index);
117 virtual uint32_t GetIfIndex (void) const;
118 virtual Ptr<Channel> GetChannel (void) const;
119 virtual void SetAddress (Address address);
120 virtual Address GetAddress (void) const;
121 virtual bool SetMtu (const uint16_t mtu);
122 virtual uint16_t GetMtu (void) const;
123 virtual bool IsLinkUp (void) const;
124 virtual void AddLinkChangeCallback (Callback<void> callback);
125 virtual bool IsBroadcast (void) const;
126 virtual Address GetBroadcast (void) const;
127 virtual bool IsMulticast (void) const;
128 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
129 virtual bool IsPointToPoint (void) const;
130 virtual bool IsBridge (void) const;
131 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
132 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
133 virtual Ptr<Node> GetNode (void) const;
134 virtual void SetNode (Ptr<Node> node);
135 virtual bool NeedsArp (void) const;
138 virtual bool SupportsSendFrom () const;
139 virtual Address GetMulticast (Ipv6Address addr) const;
142 virtual void DoDispose (void);
153 void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
154 Address const &source, Address const &destination, PacketType packetType);
164 void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
165 uint16_t protocol, Mac48Address src, Mac48Address dst);
175 void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
176 uint16_t protocol, Mac48Address src, Mac48Address dst);
183 void Learn (Mac48Address source, Ptr<NetDevice> port);
204 {
207 };
208 std::map<Mac48Address, LearnedState> m_learnState;
211 std::vector< Ptr<NetDevice> > m_ports;
213 uint16_t m_mtu;
217} // namespace ns3
219#endif /* BRIDGE_NET_DEVICE_H */
a polymophic address class
Definition: address.h:91
a virtual net device that bridges multiple LAN segments
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
Ptr< BridgeChannel > m_channel
virtual bridged channel
virtual bool IsBroadcast(void) const
Ptr< Node > m_node
node owning this NetDevice
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
uint32_t m_ifIndex
Interface index.
virtual void SetNode(Ptr< Node > node)
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
BridgeNetDevice(const BridgeNetDevice &)=delete
Mac48Address m_address
MAC address of the NetDevice.
virtual Address GetBroadcast(void) const
virtual void SetAddress(Address address)
Set the address of this interface.
virtual bool IsLinkUp(void) const
NetDevice::ReceiveCallback m_rxCallback
receive callback
virtual bool SupportsSendFrom() const
virtual uint32_t GetIfIndex(void) const
Time m_expirationTime
time it takes for learned MAC state to expire
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
virtual Ptr< Node > GetNode(void) const
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.
bool m_enableLearning
true if the bridge will learn the node status
virtual void SetIfIndex(const uint32_t index)
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.
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' to a bridge device.
static TypeId GetTypeId(void)
Get the type ID.
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
virtual uint16_t GetMtu(void) const
uint16_t m_mtu
MTU of the bridged NetDevice.
virtual Address GetAddress(void) const
BridgeNetDevice & operator=(const BridgeNetDevice &)=delete
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
virtual void DoDispose(void)
Destructor implementation.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual bool NeedsArp(void) const
std::vector< Ptr< NetDevice > > m_ports
bridged ports
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool IsMulticast(void) const
uint32_t GetNBridgePorts(void) const
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual Ptr< Channel > GetChannel(void) const
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
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 SetMtu(const uint16_t mtu)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
an EUI-48 address
Definition: mac48-address.h:44
Network layer to device interface.
Definition: net-device.h:96
Packet types are used as they are in Linux.
Definition: net-device.h:297
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
a unique identifier for an interface.
Definition: type-id.h:59
uint16_t port
Definition: dsdv-manet.cc:45
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure holding the status of an address.
Time expirationTime
time it takes for learned MAC state to expire
Ptr< NetDevice > associatedPort
port associated with the address