Refactoring to create EthernetBridgeNetDevice as a subclass, like MooseBridgeNetDevic...
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 8 May 2011 10:05:11 +0000 (11:05 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 8 May 2011 10:05:11 +0000 (11:05 +0100)
23 files changed:
examples/wireless/wifi-wired-bridging.cc
src/devices/bridge/examples/csma-bridge-one-hop.cc
src/devices/bridge/examples/csma-bridge.cc
src/devices/bridge/examples/moose-csma-bridge.cc
src/devices/bridge/helper/bridge-helper.cc [deleted file]
src/devices/bridge/helper/bridge-helper.h [deleted file]
src/devices/bridge/helper/ethernet-bridge-helper.cc [new file with mode: 0644]
src/devices/bridge/helper/ethernet-bridge-helper.h [new file with mode: 0644]
src/devices/bridge/model/bridge-net-device.cc
src/devices/bridge/model/bridge-net-device.h
src/devices/bridge/model/bridge-port-net-device.cc
src/devices/bridge/model/bridge-port-net-device.h
src/devices/bridge/model/bridge-state.cc [deleted file]
src/devices/bridge/model/bridge-state.h [deleted file]
src/devices/bridge/model/ethernet-bridge-net-device.cc [new file with mode: 0644]
src/devices/bridge/model/ethernet-bridge-net-device.h [new file with mode: 0644]
src/devices/bridge/model/ethernet-bridge-port-net-device.cc [new file with mode: 0644]
src/devices/bridge/model/ethernet-bridge-port-net-device.h [new file with mode: 0644]
src/devices/bridge/model/ethernet-bridge-state.cc [new file with mode: 0644]
src/devices/bridge/model/ethernet-bridge-state.h [new file with mode: 0644]
src/devices/bridge/wscript
src/helper/link-layer-helper.h
src/test/csma-system-test-suite.cc

index b236356f5d5d407617c0d863920afa1ab8b31e69..26ac2e9c74918e80f171acc93b7f0e8bf0c76fdf 100644 (file)
@@ -49,7 +49,7 @@
 #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>
@@ -108,7 +108,7 @@ int main (int argc, char *argv[])
       Ipv4InterfaceContainer staInterface;
       Ipv4InterfaceContainer apInterface;
       MobilityHelper mobility;
-      BridgeHelper bridge;
+      EthernetBridgeHelper bridge;
       WifiHelper wifi = WifiHelper::Default ();
       NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
       YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
index 8b4f07f8998456088f13052f0eb6f6ed3aef536c..378b677001639cf6b72d00286dea5428a5a82b31 100644 (file)
@@ -139,7 +139,7 @@ main (int argc, char *argv[])
   // 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
index 994ec6b8ecdf9763d3392bc3e779cf3d702b2964..bc2d865f1ec01f77181cc70bf02c4e59d08a85a2 100644 (file)
@@ -89,7 +89,7 @@ main (int argc, char *argv[])
 
   // 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
index 92adc21a3174a5da71c6af5afc3b8391f26438ad..1b2ce784b5ccc27c670673f4843b037149e9cdf3 100644 (file)
@@ -98,11 +98,11 @@ int main (int argc, char *argv[])
 
   // 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.
diff --git a/src/devices/bridge/helper/bridge-helper.cc b/src/devices/bridge/helper/bridge-helper.cc
deleted file mode 100644 (file)
index b74ca8b..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- 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
diff --git a/src/devices/bridge/helper/bridge-helper.h b/src/devices/bridge/helper/bridge-helper.h
deleted file mode 100644 (file)
index bd00d4e..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/* -*- 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 */
diff --git a/src/devices/bridge/helper/ethernet-bridge-helper.cc b/src/devices/bridge/helper/ethernet-bridge-helper.cc
new file mode 100644 (file)
index 0000000..afce12e
--- /dev/null
@@ -0,0 +1,92 @@
+/* -*- 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
diff --git a/src/devices/bridge/helper/ethernet-bridge-helper.h b/src/devices/bridge/helper/ethernet-bridge-helper.h
new file mode 100644 (file)
index 0000000..82df72b
--- /dev/null
@@ -0,0 +1,100 @@
+/* -*- 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 */
index d42efee8f5635995cf6d197c192187ebfb27221a..cde43f3caf456c9ccaa378cd60507a081f2a0b45 100644 (file)
@@ -37,17 +37,11 @@ BridgeNetDevice::GetTypeId (void)
 {
   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;
 }
@@ -59,7 +53,6 @@ BridgeNetDevice::BridgeNetDevice ()
 {
   NS_LOG_FUNCTION_NOARGS ();
   m_channel = CreateObject<BridgeChannel> ();
-  m_state = CreateObject<BridgeState> ();
 }
 
 BridgeNetDevice::~BridgeNetDevice()
@@ -94,7 +87,7 @@ void BridgeNetDevice::Forward (Ptr<BridgePortNetDevice> port, Ptr<const Packet>
   switch (packetType)
     {
     case PACKET_HOST:
-      if (dst48 == m_address)
+      if (dst48 == m_macAddress)
         {
           m_rxCallback (this, packet, protocol, src);
         }
@@ -107,7 +100,7 @@ void BridgeNetDevice::Forward (Ptr<BridgePortNetDevice> port, Ptr<const Packet>
       break;
 
     case PACKET_OTHERHOST:
-      if (dst48 == m_address)
+      if (dst48 == m_macAddress)
         {
           m_rxCallback (this, packet, protocol, src);
         }
@@ -119,36 +112,6 @@ void BridgeNetDevice::Forward (Ptr<BridgePortNetDevice> port, Ptr<const Packet>
     }
 }
 
-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)
 {
@@ -165,28 +128,6 @@ BridgeNetDevice::ForwardBroadcast (Ptr<BridgePortNetDevice> incomingPort, Ptr<co
     }
 }
 
-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
 {
@@ -210,11 +151,11 @@ BridgeNetDevice::AddBridgePort (Ptr<NetDevice> device)
   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);
@@ -226,11 +167,6 @@ BridgeNetDevice::AddBridgePort (Ptr<NetDevice> device)
 
 }
 
-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)
 {
@@ -256,14 +192,14 @@ void
 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 
@@ -281,28 +217,6 @@ BridgeNetDevice::GetMtu (void) const
   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
 {
@@ -366,7 +280,7 @@ bool
 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 
@@ -375,6 +289,8 @@ BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address
   NS_LOG_FUNCTION_NOARGS ();
   Mac48Address dst = Mac48Address::ConvertFrom (dest); 
 
+  /*
+
   // try to use the learned state if data is unicast
   if (!dst.IsGroup ())
     {
@@ -386,6 +302,8 @@ BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address
         }
     }
 
+  */
+
   // 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 ();
@@ -450,13 +368,6 @@ Address BridgeNetDevice::GetMulticast (Ipv6Address addr) const
   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);
 }
index dd55ab3ebb43385f6ea0c7b9401140b087857de9..3534a738d7d49e622758211600c8699fad660735 100644 (file)
@@ -19,8 +19,8 @@
 #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"
@@ -102,10 +102,6 @@ public:
   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;
@@ -125,29 +121,26 @@ public:
   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;
index 6406e852b43b4d6b9c16d182126e736127fbb38f..a8545f7f9a10829ba34a5c806a7b8b90a3cf9a20 100644 (file)
@@ -39,6 +39,14 @@ BridgePortNetDevice::GetTypeId (void)
   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 ();
@@ -66,42 +74,9 @@ void BridgePortNetDevice::SetEnabled(bool enabled){
        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;
 }
 
 }
index 3239454dcd43344281243d42bb6e38c7acf73b0c..e9cb1ba421504ccbf2570a1a292a3ac6dbfe0aac 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <string>
 #include <map>
+#include <assert.h>
 
 namespace ns3 {
 
@@ -50,7 +51,7 @@ public:
   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;
diff --git a/src/devices/bridge/model/bridge-state.cc b/src/devices/bridge/model/bridge-state.cc
deleted file mode 100644 (file)
index 6c30162..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/* -*- 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;
-}
-
-}
-
-
diff --git a/src/devices/bridge/model/bridge-state.h b/src/devices/bridge/model/bridge-state.h
deleted file mode 100644 (file)
index 91b986f..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- 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
-
diff --git a/src/devices/bridge/model/ethernet-bridge-net-device.cc b/src/devices/bridge/model/ethernet-bridge-net-device.cc
new file mode 100644 (file)
index 0000000..35b5b9b
--- /dev/null
@@ -0,0 +1,200 @@
+/* -*- 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
diff --git a/src/devices/bridge/model/ethernet-bridge-net-device.h b/src/devices/bridge/model/ethernet-bridge-net-device.h
new file mode 100644 (file)
index 0000000..fc25bf5
--- /dev/null
@@ -0,0 +1,72 @@
+/* -*- 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 */
+
diff --git a/src/devices/bridge/model/ethernet-bridge-port-net-device.cc b/src/devices/bridge/model/ethernet-bridge-port-net-device.cc
new file mode 100644 (file)
index 0000000..aa8aa5f
--- /dev/null
@@ -0,0 +1,89 @@
+/* -*- 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);
+
+  }
+
+}
+
+}
+
diff --git a/src/devices/bridge/model/ethernet-bridge-port-net-device.h b/src/devices/bridge/model/ethernet-bridge-port-net-device.h
new file mode 100644 (file)
index 0000000..7856e59
--- /dev/null
@@ -0,0 +1,58 @@
+/* -*- 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 */
diff --git a/src/devices/bridge/model/ethernet-bridge-state.cc b/src/devices/bridge/model/ethernet-bridge-state.cc
new file mode 100644 (file)
index 0000000..7e8bb61
--- /dev/null
@@ -0,0 +1,114 @@
+/* -*- 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;
+}
+
+}
+
+
diff --git a/src/devices/bridge/model/ethernet-bridge-state.h b/src/devices/bridge/model/ethernet-bridge-state.h
new file mode 100644 (file)
index 0000000..e4c9bbb
--- /dev/null
@@ -0,0 +1,70 @@
+/* -*- 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
+
index 110bd5f9d1ae0e739a211c7c0b73c241b7d73885..31e958041dc860521fc1415c496206de0028a3d4 100644 (file)
@@ -3,7 +3,9 @@
 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',
@@ -11,12 +13,14 @@ def build(bld):
         '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',
@@ -24,7 +28,7 @@ def build(bld):
        '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']:
index affbfd6df3b9b9e5f0b029482879bbe4323da3b9..8c8710068f80bdaa923a13f94d87fd49d7527e43 100644 (file)
@@ -25,7 +25,8 @@
 #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"
@@ -78,8 +79,8 @@ public:
        CsmaHelper csma;
        Ipv4AddressHelper ipv4;
        InternetStackHelper internet;
+       EthernetBridgeHelper ethernetHelper;
        MooseBridgeHelper mooseHelper;
-       BridgeHelper ethernetHelper;
 
        LinkLayerHelper();
 
index 4902ec5bababdc96833758008080484fb972cc99..a158d6c0c671fb2700228f0b70778f0a6560f05e 100644 (file)
@@ -23,7 +23,7 @@
 
 #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"
@@ -116,7 +116,7 @@ CsmaBridgeTestCase::DoRun (void)
 
   // 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;