|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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);
a unique identifier for an interface.
@ PACKET_BROADCAST
Packet addressed to all.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void AddBridgePort(Ptr< NetDevice > bridgePort)
Add a 'port' to a bridge device.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
AttributeValue implementation for Boolean.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
static Mac48Address GetMulticast(Ipv4Address address)
void ForwardBroadcast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a broadcast or a multicast packet.
static bool IsMatchingType(const Address &address)
virtual Address GetAddress(void) const =0
static Time Now(void)
Return the current simulation virtual time.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsNull(void) const
Check for null implementation.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual void SetAddress(Address address)
Set the address of this interface.
void ForwardUnicast(Ptr< NetDevice > incomingPort, Ptr< const Packet > packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
Forwards a unicast packet.
Ipv4 addresses are stored in host order in this class.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
promiscuous receive callback
Describes an IPv6 address.
@ PACKET_HOST
Packet addressed oo us.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)=0
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::map< Mac48Address, LearnedState > m_learnState
Container for known address statuses.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Time m_expirationTime
time it takes for learned MAC state to expire
virtual Ptr< Channel > GetChannel(void) const
Ptr< Node > m_node
node owning this NetDevice
Ptr< NetDevice > GetLearnedState(Mac48Address source)
Gets the port associated to a source address.
@ PACKET_OTHERHOST
Packet addressed to someone else.
virtual Ptr< Node > GetNode(void) const
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
uint16_t m_mtu
MTU of the bridged NetDevice.
a polymophic address class
virtual uint16_t GetMtu(void) const
static Mac48Address ConvertFrom(const Address &address)
std::vector< Ptr< NetDevice > > m_ports
bridged ports
virtual void SetIfIndex(const uint32_t index)
virtual ~BridgeNetDevice()
uint32_t GetNBridgePorts(void) const
Gets the number of bridged 'ports', i.e., the NetDevices currently bridged.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Simulation virtual time values and global simulation resolution.
uint32_t m_ifIndex
Interface index.
Ptr< NetDevice > associatedPort
port associated with the address
static TypeId GetTypeId(void)
Get the type ID.
Ptr< NetDevice > GetBridgePort(uint32_t n) const
Gets the n-th bridged port.
virtual uint32_t GetIfIndex(void) const
virtual Ptr< Channel > GetChannel(void) const =0
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
virtual bool NeedsArp(void) const
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
ns3::BridgeNetDevice declaration.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual bool IsLinkUp(void) const
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
std::string GetName(void) const
Get the name.
NetDevice::ReceiveCallback m_rxCallback
receive callback
Structure holding the status of an address.
virtual bool IsBroadcast(void) const
virtual bool SupportsSendFrom() const
#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< Packet > Copy(void) const
performs a COW copy of the packet.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual Address GetBroadcast(void) const
AttributeValue implementation for Time.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time expirationTime
time it takes for learned MAC state to expire
Mac48Address m_address
MAC address of the NetDevice.
PacketType
Packet types are used as they are in Linux.
Hold an unsigned integer type.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual Address GetAddress(void) const
Ptr< BridgeChannel > m_channel
virtual bridged channel
virtual void SetNode(Ptr< Node > node)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
a virtual net device that bridges multiple LAN segments
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 DoDispose(void)
Destructor implementation.
virtual bool SupportsSendFrom(void) const =0
bool m_enableLearning
true if the bridge will learn the node status
virtual bool SetMtu(const uint16_t mtu)
void Learn(Mac48Address source, Ptr< NetDevice > port)
Learns the port a MAC address is sending from.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual void DoDispose(void)
Destructor implementation.
virtual bool IsMulticast(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.
uint64_t GetUid(void) const
Returns the packet's Uid.
Network layer to device interface.
@ PACKET_MULTICAST
Packet addressed to multicast group.