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"
40 .AddConstructor<BridgeNetDevice> ()
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",
50 MakeBooleanChecker ())
51 .AddAttribute (
"ExpirationTime",
52 "Time it takes for learned MAC state entry to expire.",
66 m_channel = CreateObject<BridgeChannel> ();
136 NS_LOG_DEBUG (
"LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
137 <<
", packet=" << packet <<
", protocol="<<protocol
138 <<
", src=" << src <<
", dst=" << dst <<
")");
140 Learn (src, incomingPort);
142 if (outPort != NULL && outPort != incomingPort)
144 NS_LOG_LOGIC (
"Learning bridge state says to use port `" << outPort->GetInstanceTypeId ().GetName () <<
"'");
145 outPort->SendFrom (packet->
Copy (), src, dst, protocol);
149 NS_LOG_LOGIC (
"No learned state: send through all ports");
151 iter !=
m_ports.end (); iter++)
154 if (port != incomingPort)
156 NS_LOG_LOGIC (
"LearningBridgeForward (" << src <<
" => " << dst <<
"): "
157 << incomingPort->GetInstanceTypeId ().GetName ()
158 <<
" --> " << port->GetInstanceTypeId ().GetName ()
159 <<
" (UID " << packet->
GetUid () <<
").");
160 port->SendFrom (packet->
Copy (), src, dst, protocol);
171 NS_LOG_DEBUG (
"LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
172 <<
", packet=" << packet <<
", protocol="<<protocol
173 <<
", src=" << src <<
", dst=" << dst <<
")");
174 Learn (src, incomingPort);
177 iter !=
m_ports.end (); iter++)
180 if (port != incomingPort)
182 NS_LOG_LOGIC (
"LearningBridgeForward (" << src <<
" => " << dst <<
"): "
183 << incomingPort->GetInstanceTypeId ().GetName ()
184 <<
" --> " << port->GetInstanceTypeId ().GetName ()
185 <<
" (UID " << packet->
GetUid () <<
").");
186 port->SendFrom (packet->
Copy (), src, dst, protocol);
208 std::map<Mac48Address, LearnedState>::iterator iter =
248 NS_FATAL_ERROR (
"Device does not support eui 48 addresses: cannot be added to bridge.");
250 if (!bridgePort->SupportsSendFrom ())
252 NS_FATAL_ERROR (
"Device does not support SendFrom: cannot be added to bridge.");
259 NS_LOG_DEBUG (
"RegisterProtocolHandler for " << bridgePort->GetInstanceTypeId ().GetName ());
261 0, bridgePort,
true);
262 m_ports.push_back (bridgePort);
263 m_channel->AddChannel (bridgePort->GetChannel ());
395 outPort->SendFrom (packet, src, dest, protocolNumber);
403 iter !=
m_ports.end (); iter++)
406 port->SendFrom (packet, 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)
keep track of time values and allow control of global simulation resolution
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void Learn(Mac48Address source, Ptr< NetDevice > port)
Packet addressed to someone else.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< NetDevice > GetLearnedState(Mac48Address source)
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual void SetIfIndex(const uint32_t index)
virtual uint32_t GetIfIndex(void) const
uint64_t GetUid(void) const
A packet is allocated a new uid when it is created empty or with zero-filled payload.
bool IsNull(void) const
Check for null implementation.
#define NS_ASSERT(condition)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual bool IsMulticast(void) const
virtual Ptr< Channel > GetChannel(void) const
static TypeId GetTypeId(void)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual void SetAddress(Address address)
Set the address of this interface.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
NetDevice::PromiscReceiveCallback m_promiscRxCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
Ptr< NetDevice > associatedPort
static Mac48Address GetMulticast(Ipv4Address address)
Ptr< NetDevice > GetBridgePort(uint32_t n) const
hold objects of type ns3::Time
std::vector< Ptr< NetDevice > > m_ports
virtual uint16_t GetMtu(void) const
Hold an unsigned integer type.
NS_LOG_COMPONENT_DEFINE("BridgeNetDevice")
virtual bool SetMtu(const uint16_t mtu)
virtual bool SupportsSendFrom() const
virtual bool IsBroadcast(void) const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
virtual Address GetBroadcast(void) const
#define NS_LOG_LOGIC(msg)
static Mac48Address ConvertFrom(const Address &address)
Ptr< Packet > Copy(void) const
virtual bool NeedsArp(void) const
virtual ~BridgeNetDevice()
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
NetDevice::ReceiveCallback m_rxCallback
virtual Address GetAddress(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
static Time Now(void)
Return the "current simulation time".
virtual Ptr< Node > GetNode(void) const
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
std::map< Mac48Address, LearnedState > m_learnState
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Network layer to device interface.
#define NS_LOG_DEBUG(msg)
Ptr< BridgeChannel > m_channel
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
uint32_t GetNBridgePorts(void) const
PacketType
Packet types are used as they are in Linux.
Packet addressed to multicast group.
virtual void SetNode(Ptr< Node > node)
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
virtual bool IsLinkUp(void) const
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType)