8#include "ns3/boolean.h"
9#include "ns3/channel.h"
12#include "ns3/packet.h"
13#include "ns3/simulator.h"
14#include "ns3/uinteger.h"
33 TypeId(
"ns3::BridgeNetDevice")
35 .SetGroupName(
"Bridge")
38 "The MAC-level Maximum Transmission Unit",
42 .AddAttribute(
"EnableLearning",
43 "Enable the learning mode of the Learning Bridge",
47 .AddAttribute(
"ExpirationTime",
48 "Time it takes for learned MAC state entry to expire.",
106 Learn(src48, incomingPort);
120 Learn(src48, incomingPort);
140 << incomingPort->GetInstanceTypeId().GetName() <<
", packet=" << packet
141 <<
", protocol=" << protocol <<
", src=" << src <<
", dst=" << dst <<
")");
143 Learn(src, incomingPort);
145 if (outPort && outPort != incomingPort)
148 << outPort->GetInstanceTypeId().GetName() <<
"'");
149 outPort->SendFrom(packet->Copy(), src, dst, protocol);
153 NS_LOG_LOGIC(
"No learned state: send through all ports");
157 if (
port != incomingPort)
160 << src <<
" => " << dst
161 <<
"): " << incomingPort->GetInstanceTypeId().GetName() <<
" --> "
162 <<
port->GetInstanceTypeId().GetName() <<
" (UID " << packet->GetUid()
164 port->SendFrom(packet->Copy(), src, dst, protocol);
179 << incomingPort->GetInstanceTypeId().GetName() <<
", packet=" << packet
180 <<
", protocol=" << protocol <<
", src=" << src <<
", dst=" << dst <<
")");
181 Learn(src, incomingPort);
186 if (
port != incomingPort)
188 NS_LOG_LOGIC(
"LearningBridgeForward (" << src <<
" => " << dst <<
"): "
189 << incomingPort->GetInstanceTypeId().GetName()
190 <<
" --> " <<
port->GetInstanceTypeId().GetName()
191 <<
" (UID " << packet->GetUid() <<
").");
192 port->SendFrom(packet->Copy(), src, dst, protocol);
254 NS_FATAL_ERROR(
"Device does not support eui 48 addresses: cannot be added to bridge.");
256 if (!bridgePort->SupportsSendFrom())
258 NS_FATAL_ERROR(
"Device does not support SendFrom: cannot be added to bridge.");
265 NS_LOG_DEBUG(
"RegisterProtocolHandler for " << bridgePort->GetInstanceTypeId().GetName());
271 m_channel->AddChannel(bridgePort->GetChannel());
390 uint16_t protocolNumber)
401 outPort->SendFrom(packet, src, dest, protocolNumber);
411 pktCopy = packet->Copy();
413 port->SendFrom(pktCopy, src, dest, protocolNumber);
ns3::BridgeNetDevice declaration.
a polymophic address class
a virtual net device that bridges multiple LAN segments
bool IsBroadcast() const override
Ptr< BridgeChannel > m_channel
virtual bridged channel
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
Receives a packet from one bridged port.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
Ptr< Node > m_node
node owning this NetDevice
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
Address GetBroadcast() const override
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
uint32_t m_ifIndex
Interface index.
bool SupportsSendFrom() const override
Mac48Address m_address
MAC address of the NetDevice.
uint16_t GetMtu() const override
bool NeedsArp() const override
NetDevice::ReceiveCallback m_rxCallback
receive callback
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
static TypeId GetTypeId()
Get the type ID.
std::vector< Ptr< NetDevice > > m_ports
bridged ports
Time m_expirationTime
time it takes for learned MAC state to expire
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool IsMulticast() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void DoDispose() override
Destructor implementation.
uint32_t GetIfIndex() const override
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
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
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' to a bridge device.
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetNode(Ptr< Node > node) override
bool SetMtu(const uint16_t mtu) override
uint16_t m_mtu
MTU of the bridged NetDevice.
Ptr< Channel > GetChannel() const override
Address GetAddress() const override
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
void SetIfIndex(const uint32_t index) override
void AddLinkChangeCallback(Callback< void > callback) override
~BridgeNetDevice() override
Ptr< Node > GetNode() const override
bool IsLinkUp() const override
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
void SetAddress(Address address) override
Set the address of this interface.
uint32_t GetNBridgePorts() const
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a broadcast or a multicast packet.
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
bool IsNull() const
Check for null implementation.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
static Mac48Address GetMulticast(Ipv4Address address)
static bool IsMatchingType(const Address &address)
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
Network layer to device interface.
PacketType
Packet types are used as they are in Linux.
@ PACKET_HOST
Packet addressed to us.
@ PACKET_OTHERHOST
Packet addressed to someone else.
@ PACKET_BROADCAST
Packet addressed to all.
@ PACKET_MULTICAST
Packet addressed to multicast group.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
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