20 #include "ns3/channel.h"
21 #include "ns3/packet.h"
23 #include "ns3/boolean.h"
24 #include "ns3/simulator.h"
25 #include "ns3/uinteger.h"
45 .SetGroupName(
"Bridge")
47 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
51 MakeUintegerChecker<uint16_t> ())
52 .AddAttribute (
"EnableLearning",
53 "Enable the learning mode of the Learning Bridge",
57 .AddAttribute (
"ExpirationTime",
58 "Time it takes for learned MAC state entry to expire.",
72 m_channel = CreateObject<BridgeChannel> ();
114 Learn (src48, incomingPort);
128 Learn (src48, incomingPort);
145 <<
", packet=" << packet <<
", protocol="<<protocol
146 <<
", src=" << src <<
", dst=" << dst <<
")");
148 Learn (src, incomingPort);
150 if (outPort != NULL && outPort != incomingPort)
153 outPort->
SendFrom (packet->
Copy (), src, dst, protocol);
157 NS_LOG_LOGIC (
"No learned state: send through all ports");
159 iter !=
m_ports.end (); iter++)
162 if (
port != incomingPort)
164 NS_LOG_LOGIC (
"LearningBridgeForward (" << src <<
" => " << dst <<
"): "
166 <<
" --> " <<
port->GetInstanceTypeId ().GetName ()
167 <<
" (UID " << packet->
GetUid () <<
").");
168 port->SendFrom (packet->
Copy (), src, dst, protocol);
180 <<
", packet=" << packet <<
", protocol="<<protocol
181 <<
", src=" << src <<
", dst=" << dst <<
")");
182 Learn (src, incomingPort);
185 iter !=
m_ports.end (); iter++)
188 if (
port != incomingPort)
190 NS_LOG_LOGIC (
"LearningBridgeForward (" << src <<
" => " << dst <<
"): "
192 <<
" --> " <<
port->GetInstanceTypeId ().GetName ()
193 <<
" (UID " << packet->
GetUid () <<
").");
194 port->SendFrom (packet->
Copy (), src, dst, protocol);
216 std::map<Mac48Address, LearnedState>::iterator iter =
256 NS_FATAL_ERROR (
"Device does not support eui 48 addresses: cannot be added to bridge.");
260 NS_FATAL_ERROR (
"Device does not support SendFrom: cannot be added to bridge.");
269 0, bridgePort,
true);
270 m_ports.push_back (bridgePort);
403 outPort->
SendFrom (packet, src, dest, protocolNumber);
412 iter !=
m_ports.end (); iter++)
414 pktCopy = packet->
Copy ();
416 port->SendFrom (pktCopy, src, dest, protocolNumber);
ns3::BridgeNetDevice declaration.
a polymophic address class
AttributeValue implementation for Boolean.
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.
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 ~BridgeNetDevice()
virtual Address GetAddress(void) const
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)
bool IsNull(void) 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.
virtual bool SupportsSendFrom(void) const =0
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)=0
virtual Ptr< Channel > GetChannel(void) const =0
virtual Address GetAddress(void) const =0
PacketType
Packet types are used as they are in Linux.
@ PACKET_HOST
Packet addressed oo 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 TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual void DoDispose(void)
Destructor implementation.
uint64_t GetUid(void) const
Returns the packet's Uid.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName(void) const
Get the name.
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,...
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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 > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
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