#include "ns3/helper-module.h"
#include "ns3/wifi-module.h"
#include "ns3/node-module.h"
-#include "ns3/bridge-helper.h"
+#include "ns3/ethernet-bridge-helper.h"
#include <vector>
#include <stdint.h>
#include <sstream>
Ipv4InterfaceContainer staInterface;
Ipv4InterfaceContainer apInterface;
MobilityHelper mobility;
- BridgeHelper bridge;
+ EthernetBridgeHelper bridge;
WifiHelper wifi = WifiHelper::Default ();
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
// bridge lives on the node bridge1 and bridges together the topBridgeDevices
// which are the three CSMA net devices on the node in the diagram above.
//
- BridgeHelper bridge;
+ EthernetBridgeHelper bridge;
bridge.Install (bridge1, topBridgeDevices);
// Add internet stack to the router nodes
// Create the bridge netdevice, which will do the packet switching
Ptr<Node> switchNode = csmaSwitch.Get (0);
- BridgeHelper bridge;
+ EthernetBridgeHelper bridge;
bridge.Install (switchNode, switchDevices);
// Add internet stack to the terminals
// Create the bridge netdevice, which will do the packet switching
Ptr<Node> switchANode = switchA.Get(0);
- BridgeHelper bridgeA;
+ EthernetBridgeHelper bridgeA;
bridgeA.Install (switchANode, switchADevices);
Ptr<Node> switchBNode = switchB.Get(0);
- BridgeHelper bridgeB;
+ EthernetBridgeHelper bridgeB;
bridgeB.Install (switchBNode, switchBDevices);
// Setup the terminals as Internet hosts.
+++ /dev/null
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "bridge-helper.h"
-#include "ns3/log.h"
-#include "ns3/bridge-net-device.h"
-#include "ns3/node.h"
-#include "ns3/names.h"
-
-NS_LOG_COMPONENT_DEFINE ("BridgeHelper");
-
-namespace ns3 {
-
-BridgeHelper::BridgeHelper ()
-{
- NS_LOG_FUNCTION_NOARGS ();
- m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
-}
-
-void
-BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
-{
- NS_LOG_FUNCTION_NOARGS ();
- m_deviceFactory.Set (n1, v1);
-}
-
-NetDeviceContainer
-BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c, std::map<Ptr<NetDevice>, bool> portsEnabled)
-{
- NS_LOG_FUNCTION_NOARGS ();
- NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
-
- NetDeviceContainer devs;
- Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
- devs.Add (dev);
- node->AddDevice (dev);
-
- for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
- {
- NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
- Ptr<BridgePortNetDevice> port = dev->AddBridgePort (*i);
- if(portsEnabled.find(*i) != portsEnabled.end()){
- port->SetEnabled(portsEnabled[*i]);
- }
- }
- return devs;
-}
-
-
-NetDeviceContainer
-BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
-{
- NS_LOG_FUNCTION_NOARGS ();
- NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
-
- NetDeviceContainer devs;
- Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
- devs.Add (dev);
- node->AddDevice (dev);
-
- for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
- {
- NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
- dev->AddBridgePort (*i);
- }
- return devs;
-}
-
-NetDeviceContainer
-BridgeHelper::Install (std::string nodeName, NetDeviceContainer c)
-{
- NS_LOG_FUNCTION_NOARGS ();
- Ptr<Node> node = Names::Find<Node> (nodeName);
- return Install (node, c);
-}
-
-} // namespace ns3
+++ /dev/null
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- * Author: Gustavo Carneiro <gjc@inescporto.pt>
- */
-#ifndef BRIDGE_HELPER_H
-#define BRIDGE_HELPER_H
-
-#include "ns3/net-device-container.h"
-#include "ns3/object-factory.h"
-#include <string>
-#include <map>
-
-namespace ns3 {
-
-class Node;
-class AttributeValue;
-
-/**
- * \brief Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
- */
-class BridgeHelper
-{
-public:
- /*
- * Construct a BridgeHelper
- */
- BridgeHelper ();
- /**
- * Set an attribute on each ns3::BridgeNetDevice created by
- * BridgeHelper::Install
- *
- * \param n1 the name of the attribute to set
- * \param v1 the value of the attribute to set
- */
- void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
-
- /**
- * This method creates an ns3::BridgeNetDevice with the attributes
- * configured by BridgeHelper::SetDeviceAttribute, adds the device
- * to the node, and attaches the given NetDevices as ports of the
- * bridge.
- *
- * This version uses static spanning tree to disable loops.
- *
- * \param node The node to install the device in
- * \param c Container of NetDevices to add as bridge ports
- * \returns A container holding the added net device.
- */
- NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c, std::map<Ptr<NetDevice>, bool> portsEnabled);
-
- /**
- * This method creates an ns3::BridgeNetDevice with the attributes
- * configured by BridgeHelper::SetDeviceAttribute, adds the device
- * to the node, and attaches the given NetDevices as ports of the
- * bridge.
- *
- * \param node The node to install the device in
- * \param c Container of NetDevices to add as bridge ports
- * \returns A container holding the added net device.
- */
- NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
- /**
- * This method creates an ns3::BridgeNetDevice with the attributes
- * configured by BridgeHelper::SetDeviceAttribute, adds the device
- * to the node, and attaches the given NetDevices as ports of the
- * bridge.
- *
- * \param nodeName The name of the node to install the device in
- * \param c Container of NetDevices to add as bridge ports
- * \returns A container holding the added net device.
- */
- NetDeviceContainer Install (std::string nodeName, NetDeviceContainer c);
-private:
- ObjectFactory m_deviceFactory;
-};
-
-} // namespace ns3
-
-
-#endif /* BRIDGE_HELPER_H */
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ethernet-bridge-helper.h"
+#include "ns3/log.h"
+#include "ns3/ethernet-bridge-net-device.h"
+#include "ns3/node.h"
+#include "ns3/names.h"
+
+NS_LOG_COMPONENT_DEFINE ("EthernetBridgeHelper");
+
+namespace ns3 {
+
+EthernetBridgeHelper::EthernetBridgeHelper ()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ m_deviceFactory.SetTypeId ("ns3::EthernetBridgeNetDevice");
+}
+
+void
+EthernetBridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ m_deviceFactory.Set (n1, v1);
+}
+
+NetDeviceContainer
+EthernetBridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c, std::map<Ptr<NetDevice>, bool> portsEnabled)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
+
+ NetDeviceContainer devs;
+ Ptr<EthernetBridgeNetDevice> dev = m_deviceFactory.Create<EthernetBridgeNetDevice> ();
+ devs.Add (dev);
+ node->AddDevice (dev);
+
+ for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+ {
+ NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
+ Ptr<BridgePortNetDevice> port = dev->AddBridgePort (*i);
+ if(portsEnabled.find(*i) != portsEnabled.end()){
+ port->SetEnabled(portsEnabled[*i]);
+ }
+ }
+ return devs;
+}
+
+
+NetDeviceContainer
+EthernetBridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
+
+ NetDeviceContainer devs;
+ Ptr<EthernetBridgeNetDevice> dev = m_deviceFactory.Create<EthernetBridgeNetDevice> ();
+ devs.Add (dev);
+ node->AddDevice (dev);
+
+ for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+ {
+ NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
+ dev->AddBridgePort (*i);
+ }
+ return devs;
+}
+
+NetDeviceContainer
+EthernetBridgeHelper::Install (std::string nodeName, NetDeviceContainer c)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ Ptr<Node> node = Names::Find<Node> (nodeName);
+ return Install (node, c);
+}
+
+} // namespace ns3
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ * Author: Gustavo Carneiro <gjc@inescporto.pt>
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+#ifndef ETHERNET_BRIDGE_HELPER_H
+#define ETHERNET_BRIDGE_HELPER_H
+
+#include "ns3/net-device-container.h"
+#include "ns3/object-factory.h"
+#include <string>
+#include <map>
+#include <assert.h>
+
+namespace ns3 {
+
+class Node;
+class AttributeValue;
+
+class BridgeHelper { public: BridgeHelper(){ assert(false); } void Install(ns3::Ptr<ns3::Node>, ns3::NetDeviceContainer){ assert(false); } };
+
+/**
+ * \brief Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
+ */
+class EthernetBridgeHelper
+{
+public:
+ /*
+ * Construct a EthernetBridgeHelper
+ */
+ EthernetBridgeHelper ();
+ /**
+ * Set an attribute on each ns3::EthernetBridgeNetDevice created by
+ * EthernetBridgeHelper::Install
+ *
+ * \param n1 the name of the attribute to set
+ * \param v1 the value of the attribute to set
+ */
+ void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
+
+ /**
+ * This method creates an ns3::EthernetBridgeNetDevice with the attributes
+ * configured by EthernetBridgeHelper::SetDeviceAttribute, adds the device
+ * to the node, and attaches the given NetDevices as ports of the
+ * bridge.
+ *
+ * This version uses static spanning tree to disable loops.
+ *
+ * \param node The node to install the device in
+ * \param c Container of NetDevices to add as bridge ports
+ * \returns A container holding the added net device.
+ */
+ NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c, std::map<Ptr<NetDevice>, bool> portsEnabled);
+
+ /**
+ * This method creates an ns3::EthernetBridgeNetDevice with the attributes
+ * configured by EthernetBridgeHelper::SetDeviceAttribute, adds the device
+ * to the node, and attaches the given NetDevices as ports of the
+ * bridge.
+ *
+ * \param node The node to install the device in
+ * \param c Container of NetDevices to add as bridge ports
+ * \returns A container holding the added net device.
+ */
+ NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
+ /**
+ * This method creates an ns3::EthernetBridgeNetDevice with the attributes
+ * configured by EthernetBridgeHelper::SetDeviceAttribute, adds the device
+ * to the node, and attaches the given NetDevices as ports of the
+ * bridge.
+ *
+ * \param nodeName The name of the node to install the device in
+ * \param c Container of NetDevices to add as bridge ports
+ * \returns A container holding the added net device.
+ */
+ NetDeviceContainer Install (std::string nodeName, NetDeviceContainer c);
+private:
+ ObjectFactory m_deviceFactory;
+};
+
+} // namespace ns3
+
+
+#endif /* ETHERNET_BRIDGE_HELPER_H */
{
static TypeId tid = TypeId ("ns3::BridgeNetDevice")
.SetParent<NetDevice> ()
- .AddConstructor<BridgeNetDevice> ()
.AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
UintegerValue (1500),
MakeUintegerAccessor (&BridgeNetDevice::SetMtu,
&BridgeNetDevice::GetMtu),
MakeUintegerChecker<uint16_t> ())
- .AddAttribute ("EnableLearning",
- "Enable the learning mode of the Learning Bridge",
- BooleanValue (true),
- MakeBooleanAccessor (&BridgeNetDevice::m_enableLearning),
- MakeBooleanChecker ())
;
return tid;
}
{
NS_LOG_FUNCTION_NOARGS ();
m_channel = CreateObject<BridgeChannel> ();
- m_state = CreateObject<BridgeState> ();
}
BridgeNetDevice::~BridgeNetDevice()
switch (packetType)
{
case PACKET_HOST:
- if (dst48 == m_address)
+ if (dst48 == m_macAddress)
{
m_rxCallback (this, packet, protocol, src);
}
break;
case PACKET_OTHERHOST:
- if (dst48 == m_address)
+ if (dst48 == m_macAddress)
{
m_rxCallback (this, packet, protocol, src);
}
}
}
-void
-BridgeNetDevice::ForwardUnicast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
-{
- NS_LOG_FUNCTION_NOARGS ();
-
- Ptr<BridgePortNetDevice> outPort = GetLearnedState (dst);
- if (outPort != NULL && outPort != incomingPort)
- {
- NS_LOG_LOGIC ("Learning bridge state says to use port `" << outPort->GetInstanceTypeId ().GetName () << "'");
- outPort->Send (packet->Copy (), src, dst, protocol);
- }
- else
- {
- NS_LOG_LOGIC ("No learned state: send through all ports");
- for (std::vector< Ptr<BridgePortNetDevice> >::iterator iter = m_ports.begin ();
- iter != m_ports.end (); iter++)
- {
- Ptr<BridgePortNetDevice> port = *iter;
- if (port != incomingPort)
- {
- NS_LOG_LOGIC ("LearningBridgeForward (" << src << " => " << dst << "): "
- << incomingPort->GetInstanceTypeId ().GetName ()
- << " --> " << port->GetInstanceTypeId ().GetName ()
- << " (UID " << packet->GetUid () << ").");
- port->Send (packet->Copy (), src, dst, protocol);
- }
- }
- }
-}
-
void
BridgeNetDevice::ForwardBroadcast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
{
}
}
-void BridgeNetDevice::Learn (Address const &src, Ptr<BridgePortNetDevice> port)
-{
- NS_LOG_FUNCTION_NOARGS ();
-
- Mac48Address src48 = Mac48Address::ConvertFrom (src);
-
- if (m_enableLearning)
- {
- m_state->Learn(src48, port);
- }
-}
-
-Ptr<BridgePortNetDevice> BridgeNetDevice::GetLearnedState (Mac48Address source)
-{
- NS_LOG_FUNCTION_NOARGS ();
- if (m_enableLearning)
- {
- return m_state->GetPort(source);
- }
- return NULL;
-}
-
uint32_t
BridgeNetDevice::GetNBridgePorts (void) const
{
NS_ASSERT (device != this);
- NS_LOG_DEBUG("AddBridgePort(bridge_addr=" << m_address << ", device_address=" << (Mac48Address::ConvertFrom(device->GetAddress())));
+ NS_LOG_DEBUG("AddBridgePort(bridge_addr=" << m_macAddress << ", device_address=" << (Mac48Address::ConvertFrom(device->GetAddress())));
- if (m_address == Mac48Address ())
+ if (m_macAddress == Mac48Address ())
{
- m_address = Mac48Address::ConvertFrom (device->GetAddress ());
+ m_macAddress = Mac48Address::ConvertFrom (device->GetAddress ());
}
Ptr<BridgePortNetDevice> port = CreateBridgePort(this, device, m_node);
}
-Ptr<BridgePortNetDevice>
-BridgeNetDevice::CreateBridgePort(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node){
- return CreateObject<BridgePortNetDevice>(bridge, device, node);
-}
-
void
BridgeNetDevice::SetIfIndex(const uint32_t index)
{
BridgeNetDevice::SetAddress (Address address)
{
NS_LOG_FUNCTION_NOARGS ();
- m_address = Mac48Address::ConvertFrom (address);
+ m_macAddress = Mac48Address::ConvertFrom (address);
}
Address
BridgeNetDevice::GetAddress (void) const
{
NS_LOG_FUNCTION_NOARGS ();
- return m_address;
+ return m_macAddress;
}
bool
return m_mtu;
}
-bool
-BridgeNetDevice::SetMaxStateSize (const unsigned long maxStateSize )
-{
- NS_LOG_FUNCTION_NOARGS ();
- m_state->SetMaxSize(maxStateSize);
- return true;
-}
-
-unsigned long
-BridgeNetDevice::GetMaxStateSize (void) const
-{
- NS_LOG_FUNCTION_NOARGS ();
- return m_state->GetMaxSize();
-}
-
-unsigned long
-BridgeNetDevice::GetStateSize (void) const
-{
- NS_LOG_FUNCTION_NOARGS ();
- return m_state->GetSize();
-}
-
bool
BridgeNetDevice::IsLinkUp (void) const
{
BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
{
NS_LOG_FUNCTION_NOARGS ();
- return SendFrom (packet, m_address, dest, protocolNumber);
+ return SendFrom (packet, m_macAddress, dest, protocolNumber);
}
bool
NS_LOG_FUNCTION_NOARGS ();
Mac48Address dst = Mac48Address::ConvertFrom (dest);
+ /*
+
// try to use the learned state if data is unicast
if (!dst.IsGroup ())
{
}
}
+ */
+
// data was not unicast or no state has been learned for that mac
// address => flood through all ports.
for (std::vector< Ptr<BridgePortNetDevice> >::iterator iter = m_ports.begin ();
return Mac48Address::GetMulticast (addr);
}
-std::ostream& BridgeNetDevice::Print(std::ostream& file){
- file << 1 << std::endl;
- file << m_address << std::endl;
- file << *m_state;
- return file;
-}
-
std::ostream& operator<<(std::ostream& file, BridgeNetDevice& dev){
return dev.Print(file);
}
#ifndef BRIDGE_NET_DEVICE_H
#define BRIDGE_NET_DEVICE_H
-#include "bridge-port-net-device.h"
-#include "bridge-state.h"
+#include "bridge-net-device.h"
+#include "ethernet-bridge-port-net-device.h"
#include "ns3/net-device.h"
#include "ns3/mac48-address.h"
#include "ns3/nstime.h"
virtual bool SetMtu (const uint16_t mtu);
virtual uint16_t GetMtu (void) const;
- virtual bool SetMaxStateSize (const unsigned long maxStateSize );
- virtual unsigned long GetMaxStateSize (void) const;
- virtual unsigned long GetStateSize (void) const;
-
virtual bool IsLinkUp (void) const;
virtual void AddLinkChangeCallback (Callback<void> callback);
virtual bool IsBroadcast (void) const;
virtual Address GetMulticast (Ipv6Address addr) const;
virtual void Forward (Ptr<BridgePortNetDevice> port, Ptr<const Packet> packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType);
- virtual void Learn (Address const &src, Ptr<BridgePortNetDevice> port);
protected:
virtual void DoDispose (void);
- virtual void ForwardUnicast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst);
+ virtual void ForwardUnicast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst) = 0;
virtual void ForwardBroadcast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst);
- virtual Ptr<BridgePortNetDevice> GetLearnedState (Mac48Address source);
- virtual Ptr<BridgePortNetDevice> CreateBridgePort(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node);
+ virtual Ptr<BridgePortNetDevice> CreateBridgePort(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node) = 0;
+
+ virtual std::ostream& Print(std::ostream&) = 0;
- virtual std::ostream& Print(std::ostream&);
+ Mac48Address m_macAddress;
private:
NetDevice::ReceiveCallback m_rxCallback;
NetDevice::PromiscReceiveCallback m_promiscRxCallback;
- Mac48Address m_address;
Ptr<Node> m_node;
Ptr<BridgeChannel> m_channel;
- Ptr<BridgeState> m_state;
-
std::vector<Ptr<BridgePortNetDevice> > m_ports;
uint16_t mPortNumber;
return tid;
}
+void BridgePortNetDevice::Send(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber){
+ NS_LOG_FUNCTION_NOARGS ();
+ if(m_enabled){
+ NS_LOG_LOGIC("SendingPacket(src=" << source << ", dest=" << dest << ")");
+ m_device->SendFrom(packet->Copy(), source, dest, protocolNumber);
+ }
+}
+
BridgePortNetDevice::BridgePortNetDevice(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node) : m_bridge(bridge), m_device(device), m_enabled(true){
NS_LOG_FUNCTION_NOARGS ();
m_enabled = enabled;
}
-void BridgePortNetDevice::Send(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber){
- NS_LOG_FUNCTION_NOARGS ();
- if(m_enabled){
- NS_LOG_LOGIC("SendingPacket(src=" << source << ", dest=" << dest << ")");
- m_device->SendFrom(packet->Copy(), source, dest, protocolNumber);
- }
-}
-
-Ptr<NetDevice> BridgePortNetDevice::GetDevice(){
- return m_device;
-}
-
-/**
- * By moving learning to the port, we can have some ports which learn, and some which don't.
- **/
-
-void
-BridgePortNetDevice::Receive (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol,
- Address const &src, Address const &dst, NetDevice::PacketType packetType)
+Ptr<NetDevice> BridgePortNetDevice::GetDevice()
{
- NS_LOG_FUNCTION_NOARGS ();
-
- if(m_enabled){
-
- NS_LOG_LOGIC ("UID is " << packet->GetUid ());
-
- NS_LOG_LOGIC ("LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
- << ", packet=" << packet << ", protocol="<<protocol
- << ", src=" << src << ", dst=" << dst << ")");
-
- m_bridge->Learn(src, this);
-
- m_bridge->Forward(this, packet, protocol, src, dst, packetType);
-
- }
-
+ return m_device;
}
}
#include <stdint.h>
#include <string>
#include <map>
+#include <assert.h>
namespace ns3 {
virtual void SetEnabled(bool enabled);
protected:
- virtual void Receive (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, Address const &source, Address const &destination, NetDevice::PacketType packetType);
+ virtual void Receive (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, Address const &source, Address const &destination, NetDevice::PacketType packetType) = 0;
Ptr<BridgeNetDevice> m_bridge;
Ptr<NetDevice> m_device;
+++ /dev/null
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License version 2 as
-* published by the Free Software Foundation;
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*
-* Author: Richard Whitehouse <ns3@richardwhiuk.com>
-*/
-
-#include "bridge-state.h"
-#include "ns3/log.h"
-#include "ns3/boolean.h"
-#include "ns3/simulator.h"
-#include "ns3/uinteger.h"
-
-NS_LOG_COMPONENT_DEFINE ("BridgeState");
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (BridgeState);
-
-TypeId BridgeState::GetTypeId (void){
-
-static TypeId tid = TypeId ("ns3::BridgeState")
-.SetParent<Object> ()
-.AddConstructor<BridgeState> ()
-.AddAttribute ("ExpirationTime",
-"Time it takes for learned MAC state entry to expire.",
-TimeValue (Seconds (300)),
-MakeTimeAccessor (&BridgeState::m_time),
-MakeTimeChecker ())
-.AddAttribute ("StateSize", "The size of the State Table",
-UintegerValue (8000),
-MakeUintegerAccessor (&BridgeState::m_max),
-MakeUintegerChecker<unsigned long> ())
-;
-return tid;
-}
-
-unsigned long BridgeState::GetMaxSize() const {
- return m_max;
-}
-
-BridgeState::BridgeState(){
-
-}
-
-BridgeState::~BridgeState(){
-
-}
-
-void BridgeState::Learn(ns3::Mac48Address addr, Ptr<BridgePortNetDevice> port){
- std::map<Mac48Address, Host>::iterator it = m_learnState.find(addr);
- if(it != m_learnState.end() || m_learnState.size() < m_max){
- Host &state = m_learnState[addr];
- state.associatedPort = port;
- state.expirationTime = Simulator::Now () + m_time;
- }
-}
-
-void BridgeState::SetMaxSize(unsigned long max){
- m_max = max;
-}
-
-Ptr<BridgePortNetDevice> BridgeState::GetPort(ns3::Mac48Address addr){
- Time now = Simulator::Now ();
- std::map<Mac48Address, Host>::iterator iter = m_learnState.find(addr);
- if (iter != m_learnState.end()){
- Host &state = iter->second;
- if (state.expirationTime > now){
- return state.associatedPort;
- } else {
- m_learnState.erase (iter);
- }
- }
-}
-
-unsigned long BridgeState::GetSize(){
- return m_learnState.size();
-}
-
-void BridgeState::SetExpirationTime(Time time){
- m_time = time;
-}
-
-Time BridgeState::GetExpirationTime(){
- return m_time;
-}
-
-std::ostream& operator<<(std::ostream& file, BridgeState& state){
- // Output state
- file << state.m_learnState.size();
- std::map<Mac48Address, BridgeState::Host>::iterator it;
- for(it = state.m_learnState.begin(); it != state.m_learnState.end(); ++it){
- file << std::endl;
- file << it->first << std::endl;
- file << it->second.associatedPort << std::endl;
- file << it->second.expirationTime;
- }
- return file;
-}
-
-}
-
-
+++ /dev/null
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Richard Whitehouse <ns3@richardwhiuk.com>
- */
-#ifndef BRIDGE_STATE_H
-#define BRIDGE_STATE_H
-
-#include "bridge-port-net-device.h"
-#include "ns3/object-factory.h"
-#include "ns3/mac48-address.h"
-#include "ns3/nstime.h"
-
-namespace ns3 {
-
-class BridgeState : public Object {
-
-public:
-
- static TypeId GetTypeId (void);
- BridgeState ();
- virtual ~BridgeState ();
-
- unsigned long GetSize();
-
- unsigned long GetMaxSize() const;
- void SetMaxSize(const unsigned long max);
-
- void Learn(Mac48Address addr, Ptr<BridgePortNetDevice> port);
- Ptr<BridgePortNetDevice> GetPort(Mac48Address addr);
-
- void SetExpirationTime(Time time);
-
- Time GetExpirationTime();
-
-private:
-
- unsigned long m_max;
- Time m_time;
-
- struct Host {
- Ptr<BridgePortNetDevice> associatedPort;
- Time expirationTime;
- };
-
- std::map<Mac48Address, Host> m_learnState;
-
- friend std::ostream& operator<<(std::ostream&, BridgeState&);
-
-};
-
-std::ostream& operator<<(std::ostream&, BridgeState&);
-
-}
-
-#endif
-
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ * Author: Gustavo Carneiro <gjc@inescporto.pt>
+ */
+#include "ethernet-bridge-net-device.h"
+#include "ns3/node.h"
+#include "ns3/channel.h"
+#include "ns3/packet.h"
+#include "ns3/log.h"
+#include "ns3/boolean.h"
+#include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+
+NS_LOG_COMPONENT_DEFINE ("EthernetBridgeNetDevice");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (EthernetBridgeNetDevice);
+
+
+TypeId
+EthernetBridgeNetDevice::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::EthernetBridgeNetDevice")
+ .SetParent<BridgeNetDevice> ()
+ .AddConstructor<EthernetBridgeNetDevice> ()
+ .AddAttribute ("EnableLearning",
+ "Enable the learning mode of the Learning Bridge",
+ BooleanValue (true),
+ MakeBooleanAccessor (&EthernetBridgeNetDevice::m_enableLearning),
+ MakeBooleanChecker ())
+ ;
+ return tid;
+}
+
+
+EthernetBridgeNetDevice::EthernetBridgeNetDevice () : BridgeNetDevice()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ m_state = CreateObject<EthernetBridgeState> ();
+}
+
+EthernetBridgeNetDevice::~EthernetBridgeNetDevice()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+void EthernetBridgeNetDevice::Forward (Ptr<BridgePortNetDevice> port, Ptr<const Packet> packet, uint16_t protocol, Address const &src, Address const &dst, NetDevice::PacketType packetType){
+
+ Mac48Address src48 = Mac48Address::ConvertFrom (src);
+ Mac48Address dst48 = Mac48Address::ConvertFrom (dst);
+
+/* if (!m_promiscRxCallback.IsNull ())
+ {
+ m_promiscRxCallback (this, packet, protocol, src, dst, packetType);
+ } */
+
+ switch (packetType)
+ {
+ case PACKET_HOST:
+ if (dst48 == m_macAddress)
+ {
+// m_rxCallback (this, packet, protocol, src);
+ }
+ break;
+
+ case PACKET_BROADCAST:
+ case PACKET_MULTICAST:
+// m_rxCallback (this, packet, protocol, src);
+ ForwardBroadcast (port, packet, protocol, src48, dst48);
+ break;
+
+ case PACKET_OTHERHOST:
+ if (dst48 == m_macAddress)
+ {
+// m_rxCallback (this, packet, protocol, src);
+ }
+ else
+ {
+ ForwardUnicast (port, packet, protocol, src48, dst48);
+ }
+ break;
+ }
+}
+
+void
+EthernetBridgeNetDevice::ForwardUnicast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Ptr<BridgePortNetDevice> outPort = GetLearnedState (dst);
+
+ if (outPort != NULL && outPort != incomingPort){
+
+ NS_LOG_LOGIC ("Learning bridge state says to use port `" << outPort->GetInstanceTypeId ().GetName () << "'");
+
+ outPort->Send (packet->Copy (), src, dst, protocol);
+
+ } else {
+
+ NS_LOG_LOGIC ("No learned state: send through all ports");
+
+ ForwardBroadcast(incomingPort, packet, protocol, src, dst);
+
+ }
+}
+
+void EthernetBridgeNetDevice::ForwardBroadcast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst)
+{
+ NS_LOG_FUNCTION_NOARGS();
+
+ BridgeNetDevice::ForwardBroadcast(incomingPort, packet, protocol, src, dst);
+}
+
+void EthernetBridgeNetDevice::Learn (Address const &src, Ptr<BridgePortNetDevice> port){
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Mac48Address src48 = Mac48Address::ConvertFrom (src);
+
+ if (m_enableLearning)
+ {
+ m_state->Learn(src48, port);
+ }
+}
+
+Ptr<BridgePortNetDevice> EthernetBridgeNetDevice::GetLearnedState (Mac48Address source)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ if (m_enableLearning)
+ {
+ return m_state->GetPort(source);
+ }
+ return NULL;
+}
+
+Ptr<BridgePortNetDevice>
+EthernetBridgeNetDevice::CreateBridgePort(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node){
+ return CreateObject<EthernetBridgePortNetDevice>(bridge, device, node);
+}
+
+/*
+bool
+EthernetBridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ return SendFrom (packet, m_address, dest, protocolNumber);
+}
+
+bool
+EthernetBridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ Mac48Address dst = Mac48Address::ConvertFrom (dest);
+
+ // try to use the learned state if data is unicast
+ if (!dst.IsGroup ())
+ {
+ Ptr<BridgePortNetDevice> outPort = GetLearnedState (dst);
+ if (outPort != NULL)
+ {
+ outPort->Send(packet, src, dest, protocolNumber);
+ return true;
+ }
+ }
+
+ // data was not unicast or no state has been learned for that mac
+ // address => flood through all ports.
+ for (std::vector< Ptr<BridgePortNetDevice> >::iterator iter = m_ports.begin ();
+ iter != m_ports.end (); iter++)
+ {
+ Ptr<BridgePortNetDevice> port = *iter;
+ port->Send (packet, src, dest, protocolNumber);
+ }
+
+ return true;
+}
+*/
+
+std::ostream& EthernetBridgeNetDevice::Print(std::ostream& file){
+ file << 1 << std::endl;
+ file << m_macAddress << std::endl;
+ file << *m_state;
+ return file;
+}
+
+} // namespace ns3
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Gustavo Carneiro <gjc@inescporto.pt>
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+#ifndef ETHERNET_BRIDGE_NET_DEVICE_H
+#define ETHERNET_BRIDGE_NET_DEVICE_H
+
+#include "bridge-net-device.h"
+#include "ethernet-bridge-port-net-device.h"
+#include "ethernet-bridge-state.h"
+#include "ns3/net-device.h"
+#include "ns3/mac48-address.h"
+#include "ns3/nstime.h"
+#include "ns3/bridge-channel.h"
+#include "ns3/object-factory.h"
+#include <stdint.h>
+#include <string>
+#include <map>
+
+namespace ns3 {
+
+class Node;
+
+/**
+ * \ingroup bridge
+ * \brief a virtual net device that bridges multiple LAN segments
+ */
+class EthernetBridgeNetDevice : public BridgeNetDevice
+{
+public:
+ static TypeId GetTypeId (void);
+ EthernetBridgeNetDevice ();
+ virtual ~EthernetBridgeNetDevice ();
+
+ virtual void Forward (Ptr<BridgePortNetDevice> port, Ptr<const Packet> packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType);
+ virtual void Learn (Address const &src, Ptr<BridgePortNetDevice> port);
+
+protected:
+ virtual void ForwardUnicast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst);
+ virtual void ForwardBroadcast (Ptr<BridgePortNetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol, Mac48Address src, Mac48Address dst);
+ virtual Ptr<BridgePortNetDevice> GetLearnedState (Mac48Address source);
+
+ virtual Ptr<BridgePortNetDevice> CreateBridgePort(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node);
+
+ virtual std::ostream& Print(std::ostream&);
+
+private:
+ Ptr<EthernetBridgeState> m_state;
+
+ uint16_t mPortNumber;
+ bool m_enableLearning;
+
+};
+
+} // namespace ns3
+
+#endif /* ETHERNET_BRIDGE_NET_DEVICE_H */
+
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+#include "ethernet-bridge-net-device.h"
+#include "ns3/node.h"
+#include "ns3/channel.h"
+#include "ns3/packet.h"
+#include "ns3/log.h"
+#include "ns3/boolean.h"
+#include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+
+NS_LOG_COMPONENT_DEFINE ("EthernetBridgePortNetDevice");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (EthernetBridgePortNetDevice);
+
+TypeId
+EthernetBridgePortNetDevice::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::EthernetBridgePortNetDevice")
+ .SetParent<BridgePortNetDevice> ()
+ ;
+ return tid;
+}
+
+
+EthernetBridgePortNetDevice::EthernetBridgePortNetDevice(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node) : BridgePortNetDevice(bridge,device,node) {
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+EthernetBridgePortNetDevice::~EthernetBridgePortNetDevice(){
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+void EthernetBridgePortNetDevice::SetEnabled(bool enabled){
+ m_enabled = enabled;
+}
+
+void EthernetBridgePortNetDevice::Send(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber){
+ NS_LOG_FUNCTION_NOARGS ();
+ BridgePortNetDevice::Send(packet, source, dest, protocolNumber);
+}
+
+/**
+ * By moving learning to the port, we can have some ports which learn, and some which don't.
+ **/
+
+void
+EthernetBridgePortNetDevice::Receive (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol,
+ Address const &src, Address const &dst, NetDevice::PacketType packetType)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Ptr<EthernetBridgeNetDevice> bridge = m_bridge->GetObject<EthernetBridgeNetDevice>();
+
+ if(m_enabled){
+
+ NS_LOG_LOGIC ("UID is " << packet->GetUid ());
+
+ NS_LOG_LOGIC ("LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
+ << ", packet=" << packet << ", protocol="<<protocol
+ << ", src=" << src << ", dst=" << dst << ")");
+
+ bridge->Learn(src, this);
+
+ bridge->Forward(this, packet, protocol, src, dst, packetType);
+
+ }
+
+}
+
+}
+
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+#ifndef ETHERNET_BRIDGE_PORT_NET_DEVICE_H
+#define ETHERNET_BRIDGE_PORT_NET_DEVICE_H
+
+#include "bridge-port-net-device.h"
+#include "ns3/net-device.h"
+#include "ns3/mac48-address.h"
+#include "ns3/nstime.h"
+#include <stdint.h>
+#include <string>
+#include <map>
+
+namespace ns3 {
+
+class Node;
+class BridgeNetDevice;
+
+/**
+ * \ingroup bridge
+ * \brief a port on a virtual net device that bridges multiple LAN segments
+ */
+
+class EthernetBridgePortNetDevice : public BridgePortNetDevice {
+
+public:
+ EthernetBridgePortNetDevice(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node);
+ virtual ~EthernetBridgePortNetDevice();
+
+ static TypeId GetTypeId (void);
+
+ virtual void Send (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber);
+
+ virtual void SetEnabled(bool enabled);
+
+protected:
+ virtual void Receive (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, Address const &source, Address const &destination, NetDevice::PacketType packetType);
+
+};
+
+} // namespace ns3
+
+#endif /* BRIDGE_PORT_NET_DEVICE_H */
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation;
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* Author: Richard Whitehouse <ns3@richardwhiuk.com>
+*/
+
+#include "ethernet-bridge-state.h"
+#include "ns3/log.h"
+#include "ns3/boolean.h"
+#include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+
+NS_LOG_COMPONENT_DEFINE ("EthernetBridgeState");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (EthernetBridgeState);
+
+TypeId EthernetBridgeState::GetTypeId (void){
+
+static TypeId tid = TypeId ("ns3::EthernetBridgeState")
+.SetParent<Object> ()
+.AddConstructor<EthernetBridgeState> ()
+.AddAttribute ("ExpirationTime",
+"Time it takes for learned MAC state entry to expire.",
+TimeValue (Seconds (300)),
+MakeTimeAccessor (&EthernetBridgeState::m_time),
+MakeTimeChecker ())
+.AddAttribute ("StateSize", "The size of the State Table",
+UintegerValue (8000),
+MakeUintegerAccessor (&EthernetBridgeState::m_max),
+MakeUintegerChecker<unsigned long> ())
+;
+return tid;
+}
+
+unsigned long EthernetBridgeState::GetMaxSize() const {
+ return m_max;
+}
+
+EthernetBridgeState::EthernetBridgeState(){
+
+}
+
+EthernetBridgeState::~EthernetBridgeState(){
+
+}
+
+void EthernetBridgeState::Learn(ns3::Mac48Address addr, Ptr<BridgePortNetDevice> port){
+ std::map<Mac48Address, Host>::iterator it = m_learnState.find(addr);
+ if(it != m_learnState.end() || m_learnState.size() < m_max){
+ Host &state = m_learnState[addr];
+ state.associatedPort = port;
+ state.expirationTime = Simulator::Now () + m_time;
+ }
+}
+
+void EthernetBridgeState::SetMaxSize(unsigned long max){
+ m_max = max;
+}
+
+Ptr<BridgePortNetDevice> EthernetBridgeState::GetPort(ns3::Mac48Address addr){
+ Time now = Simulator::Now ();
+ std::map<Mac48Address, Host>::iterator iter = m_learnState.find(addr);
+ if (iter != m_learnState.end()){
+ Host &state = iter->second;
+ if (state.expirationTime > now){
+ return state.associatedPort;
+ } else {
+ m_learnState.erase (iter);
+ }
+ }
+}
+
+unsigned long EthernetBridgeState::GetSize(){
+ return m_learnState.size();
+}
+
+void EthernetBridgeState::SetExpirationTime(Time time){
+ m_time = time;
+}
+
+Time EthernetBridgeState::GetExpirationTime(){
+ return m_time;
+}
+
+std::ostream& operator<<(std::ostream& file, EthernetBridgeState& state){
+ // Output state
+ file << state.m_learnState.size();
+ std::map<Mac48Address, EthernetBridgeState::Host>::iterator it;
+ for(it = state.m_learnState.begin(); it != state.m_learnState.end(); ++it){
+ file << std::endl;
+ file << it->first << std::endl;
+ file << it->second.associatedPort << std::endl;
+ file << it->second.expirationTime;
+ }
+ return file;
+}
+
+}
+
+
--- /dev/null
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+
+#ifndef ETHERNET_BRIDGE_STATE_H
+#define ETHERNET_BRIDGE_STATE_H
+
+#include "bridge-port-net-device.h"
+#include "ns3/object-factory.h"
+#include "ns3/mac48-address.h"
+#include "ns3/nstime.h"
+
+namespace ns3 {
+
+class EthernetBridgeState : public Object {
+
+public:
+
+ static TypeId GetTypeId (void);
+ EthernetBridgeState ();
+ virtual ~EthernetBridgeState ();
+
+ unsigned long GetSize();
+
+ unsigned long GetMaxSize() const;
+ void SetMaxSize(const unsigned long max);
+
+ void Learn(Mac48Address addr, Ptr<BridgePortNetDevice> port);
+ Ptr<BridgePortNetDevice> GetPort(Mac48Address addr);
+
+ void SetExpirationTime(Time time);
+
+ Time GetExpirationTime();
+
+private:
+
+ unsigned long m_max;
+ Time m_time;
+
+ struct Host {
+ Ptr<BridgePortNetDevice> associatedPort;
+ Time expirationTime;
+ };
+
+ std::map<Mac48Address, Host> m_learnState;
+
+ friend std::ostream& operator<<(std::ostream&, EthernetBridgeState&);
+
+};
+
+std::ostream& operator<<(std::ostream&, EthernetBridgeState&);
+
+}
+
+#endif
+
def build(bld):
obj = bld.create_ns3_module('bridge', ['node'])
obj.source = [
- 'model/bridge-state.cc',
+ 'model/ethernet-bridge-state.cc',
+ 'model/ethernet-bridge-port-net-device.cc',
+ 'model/ethernet-bridge-net-device.cc',
'model/moose-bridge-state.cc',
'model/moose-bridge-port-net-device.cc',
'model/moose-bridge-net-device.cc',
'model/bridge-port-net-device.cc',
'model/bridge-channel.cc',
'helper/moose-bridge-helper.cc',
- 'helper/bridge-helper.cc',
+ 'helper/ethernet-bridge-helper.cc',
]
headers = bld.new_task_gen('ns3header')
headers.module = 'bridge'
headers.source = [
- 'model/bridge-state.h',
+ 'model/ethernet-bridge-state.h',
+ 'model/ethernet-bridge-port-net-device.h',
+ 'model/ethernet-bridge-net-device.h',
'model/moose-bridge-state.h',
'model/moose-bridge-port-net-device.h',
'model/moose-bridge-net-device.h',
'model/bridge-port-net-device.h',
'model/bridge-channel.h',
'helper/moose-bridge-helper.h',
- 'helper/bridge-helper.h',
+ 'helper/ethernet-bridge-helper.h',
]
if bld.env['ENABLE_EXAMPLES']:
#include "ns3/node.h"
#include "ns3/moose-bridge-net-device.h"
#include "ns3/moose-bridge-helper.h"
-#include "ns3/bridge-helper.h"
+#include "ns3/ethernet-bridge-helper.h"
+#include "ns3/ethernet-bridge-net-device.h"
#include "internet-stack-helper.h"
#include "ipv4-address-helper.h"
#include "csma-helper.h"
CsmaHelper csma;
Ipv4AddressHelper ipv4;
InternetStackHelper internet;
+ EthernetBridgeHelper ethernetHelper;
MooseBridgeHelper mooseHelper;
- BridgeHelper ethernetHelper;
LinkLayerHelper();
#include "ns3/address.h"
#include "ns3/application-container.h"
-#include "ns3/bridge-helper.h"
+#include "ns3/ethernet-bridge-helper.h"
#include "ns3/callback.h"
#include "ns3/config.h"
#include "ns3/csma-helper.h"
// Create the bridge netdevice, which will do the packet switching
Ptr<Node> switchNode = csmaSwitch.Get (0);
- BridgeHelper bridge;
+ EthernetBridgeHelper bridge;
bridge.Install (switchNode, switchDevices);
InternetStackHelper internet;