19 #include "ns3/boolean.h"
20 #include "ns3/channel.h"
23 #include "ns3/packet.h"
24 #include "ns3/simulator.h"
25 #include "ns3/uinteger.h"
44 TypeId(
"ns3::BridgeNetDevice")
46 .SetGroupName(
"Bridge")
49 "The MAC-level Maximum Transmission Unit",
52 MakeUintegerChecker<uint16_t>())
53 .AddAttribute(
"EnableLearning",
54 "Enable the learning mode of the Learning Bridge",
58 .AddAttribute(
"ExpirationTime",
59 "Time it takes for learned MAC state entry to expire.",
71 m_channel = CreateObject<BridgeChannel>();
117 Learn(src48, incomingPort);
131 Learn(src48, incomingPort);
151 << incomingPort->GetInstanceTypeId().GetName() <<
", packet=" << packet
152 <<
", protocol=" << protocol <<
", src=" << src <<
", dst=" << dst <<
")");
154 Learn(src, incomingPort);
156 if (outPort && outPort != incomingPort)
159 << outPort->GetInstanceTypeId().GetName() <<
"'");
160 outPort->SendFrom(packet->
Copy(), src, dst, protocol);
164 NS_LOG_LOGIC(
"No learned state: send through all ports");
168 if (
port != incomingPort)
171 << src <<
" => " << dst
172 <<
"): " << incomingPort->GetInstanceTypeId().GetName() <<
" --> "
173 <<
port->GetInstanceTypeId().GetName() <<
" (UID " << packet->
GetUid()
175 port->SendFrom(packet->
Copy(), src, dst, protocol);
190 << incomingPort->GetInstanceTypeId().GetName() <<
", packet=" << packet
191 <<
", protocol=" << protocol <<
", src=" << src <<
", dst=" << dst <<
")");
192 Learn(src, incomingPort);
197 if (
port != incomingPort)
199 NS_LOG_LOGIC(
"LearningBridgeForward (" << src <<
" => " << dst <<
"): "
200 << incomingPort->GetInstanceTypeId().GetName()
201 <<
" --> " <<
port->GetInstanceTypeId().GetName()
202 <<
" (UID " << packet->
GetUid() <<
").");
203 port->SendFrom(packet->
Copy(), src, dst, protocol);
265 NS_FATAL_ERROR(
"Device does not support eui 48 addresses: cannot be added to bridge.");
267 if (!bridgePort->SupportsSendFrom())
269 NS_FATAL_ERROR(
"Device does not support SendFrom: cannot be added to bridge.");
276 NS_LOG_DEBUG(
"RegisterProtocolHandler for " << bridgePort->GetInstanceTypeId().GetName());
282 m_channel->AddChannel(bridgePort->GetChannel());
401 uint16_t protocolNumber)
412 outPort->SendFrom(packet, src, dest, protocolNumber);
422 pktCopy = packet->
Copy();
424 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)
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.
Ptr< Packet > Copy() const
performs a COW copy of the packet.
uint64_t GetUid() const
Returns the packet's Uid.
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 ",...
#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 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 AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
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