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> ();
 
  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);
 
  404        iter != 
m_ports.end (); iter++)
 
  406       pktCopy = packet->
Copy ();
 
  408       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)
 
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. 
 
virtual bool IsBridge(void) const 
Return true if the net device is acting as a bridge. 
 
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 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 
 
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...
 
uint64_t GetUid(void) const 
Returns the packet's Uid. 
 
bool IsNull(void) const 
Check for null implementation. 
 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
 
PacketType
Packet types are used as they are in Linux. 
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
 
virtual bool IsMulticast(void) const 
 
virtual Ptr< Channel > GetChannel(void) const 
 
static TypeId GetTypeId(void)
Get the type ID. 
 
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate. 
 
Packet addressed to multicast group. 
 
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)
 
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback 
 
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)
 
Ptr< NetDevice > GetBridgePort(uint32_t n) const 
Gets the n-th bridged port. 
 
AttributeValue implementation for Time. 
 
std::vector< Ptr< NetDevice > > m_ports
bridged ports 
 
virtual uint16_t GetMtu(void) const 
 
Hold an unsigned integer type. 
 
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)
 
uint32_t m_ifIndex
Interface index. 
 
virtual Address GetBroadcast(void) const 
 
static Mac48Address ConvertFrom(const Address &address)
 
Ptr< Packet > Copy(void) const 
performs a COW copy of the packet. 
 
virtual bool NeedsArp(void) const 
 
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 
 
virtual Address GetAddress(void) const 
 
Ptr< const AttributeChecker > MakeBooleanChecker(void)
 
Packet addressed to someone else. 
 
Mac48Address m_address
MAC address of the NetDevice. 
 
virtual Address GetMulticast(Ipv4Address multicastGroup) const 
Make and return a MAC multicast address using the provided multicast group. 
 
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 Ptr< Node > GetNode(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 
 
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. 
 
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 
 
uint32_t GetNBridgePorts(void) const 
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged. 
 
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. 
 
TypeId SetParent(TypeId tid)
Set the parent TypeId. 
 
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)
Receives a packet from one bridged port.