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" 39 .SetGroupName(
"Bridge")
41 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
45 MakeUintegerChecker<uint16_t> ())
46 .AddAttribute (
"EnableLearning",
47 "Enable the learning mode of the Learning Bridge",
51 .AddAttribute (
"ExpirationTime",
52 "Time it takes for learned MAC state entry to expire.",
66 m_channel = CreateObject<BridgeChannel> ();
108 Learn (src48, incomingPort);
122 Learn (src48, incomingPort);
138 NS_LOG_DEBUG (
"LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
139 <<
", packet=" << packet <<
", protocol="<<protocol
140 <<
", src=" << src <<
", dst=" << dst <<
")");
142 Learn (src, incomingPort);
144 if (outPort != NULL && outPort != incomingPort)
146 NS_LOG_LOGIC (
"Learning bridge state says to use port `" << outPort->GetInstanceTypeId ().GetName () <<
"'");
147 outPort->SendFrom (packet->
Copy (), src, dst, protocol);
151 NS_LOG_LOGIC (
"No learned state: send through all ports");
153 iter !=
m_ports.end (); iter++)
156 if (
port != incomingPort)
158 NS_LOG_LOGIC (
"LearningBridgeForward (" << src <<
" => " << dst <<
"): " 159 << incomingPort->GetInstanceTypeId ().GetName ()
160 <<
" --> " <<
port->GetInstanceTypeId ().GetName ()
161 <<
" (UID " << packet->
GetUid () <<
").");
162 port->SendFrom (packet->
Copy (), src, dst, protocol);
173 NS_LOG_DEBUG (
"LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
174 <<
", packet=" << packet <<
", protocol="<<protocol
175 <<
", src=" << src <<
", dst=" << dst <<
")");
176 Learn (src, incomingPort);
179 iter !=
m_ports.end (); iter++)
182 if (
port != incomingPort)
184 NS_LOG_LOGIC (
"LearningBridgeForward (" << src <<
" => " << dst <<
"): " 185 << incomingPort->GetInstanceTypeId ().GetName ()
186 <<
" --> " <<
port->GetInstanceTypeId ().GetName ()
187 <<
" (UID " << packet->
GetUid () <<
").");
188 port->SendFrom (packet->
Copy (), src, dst, protocol);
210 std::map<Mac48Address, LearnedState>::iterator iter =
250 NS_FATAL_ERROR (
"Device does not support eui 48 addresses: cannot be added to bridge.");
252 if (!bridgePort->SupportsSendFrom ())
254 NS_FATAL_ERROR (
"Device does not support SendFrom: cannot be added to bridge.");
261 NS_LOG_DEBUG (
"RegisterProtocolHandler for " << bridgePort->GetInstanceTypeId ().GetName ());
263 0, bridgePort,
true);
264 m_ports.push_back (bridgePort);
265 m_channel->AddChannel (bridgePort->GetChannel ());
397 outPort->SendFrom (packet, src, dest, protocolNumber);
406 iter !=
m_ports.end (); iter++)
408 pktCopy = packet->
Copy ();
410 port->SendFrom (pktCopy, src, dest, protocolNumber);
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' to a bridge device.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
static bool IsMatchingType(const Address &address)
uint64_t GetUid(void) const
Returns the packet's Uid.
Simulation virtual time values and global simulation resolution.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
AttributeValue implementation for Boolean.
Packet addressed to someone else.
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.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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 IsMulticast(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual void SetIfIndex(const uint32_t index)
Time expirationTime
time it takes for learned MAC state to expire
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual bool IsLinkUp(void) const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
virtual Ptr< Node > GetNode(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual bool NeedsArp(void) const
virtual void DoDispose(void)
Destructor implementation.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual void SetAddress(Address address)
Set the address of this interface.
a virtual net device that bridges multiple LAN segments
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual Address GetAddress(void) const
uint32_t GetNBridgePorts(void) const
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void AddLinkChangeCallback(Callback< void > callback)
a polymophic address class
Ptr< NetDevice > associatedPort
port associated with the address
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
static Mac48Address GetMulticast(Ipv4Address address)
AttributeValue implementation for Time.
std::vector< Ptr< NetDevice > > m_ports
bridged ports
Hold an unsigned integer type.
virtual bool SetMtu(const uint16_t mtu)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
uint32_t m_ifIndex
Interface index.
static Mac48Address ConvertFrom(const Address &address)
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
virtual ~BridgeNetDevice()
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
NetDevice::ReceiveCallback m_rxCallback
receive callback
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Mac48Address m_address
MAC address of the NetDevice.
virtual bool IsBroadcast(void) const
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static Time Now(void)
Return the current simulation virtual time.
virtual uint32_t GetIfIndex(void) const
virtual void DoDispose(void)
Destructor implementation.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Ptr< Node > m_node
node owning this NetDevice
virtual Address GetBroadcast(void) const
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
Structure holding the status of an address.
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
uint16_t m_mtu
MTU of the bridged NetDevice.
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
Network layer to device interface.
bool m_enableLearning
true if the bridge will learn the node status
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< BridgeChannel > m_channel
virtual bridged channel
Time m_expirationTime
time it takes for learned MAC state to expire
virtual uint16_t GetMtu(void) const
virtual bool SupportsSendFrom() const
PacketType
Packet types are used as they are in Linux.
bool IsNull(void) const
Check for null implementation.
Packet addressed to multicast group.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void SetNode(Ptr< Node > node)
a unique identifier for an interface.
virtual Ptr< Channel > GetChannel(void) const
TypeId SetParent(TypeId tid)
Set the parent TypeId.
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.