MakeUintegerAccessor (&BridgeNetDevice::SetMtu,
&BridgeNetDevice::GetMtu),
MakeUintegerChecker<uint16_t> ())
- .AddAttribute ("StateSize", "The size of the State Table",
- UintegerValue (8000),
- MakeUintegerAccessor (&BridgeNetDevice::SetMaxStateSize,
- &BridgeNetDevice::GetMaxStateSize),
- MakeUintegerChecker<unsigned long> ())
.AddAttribute ("EnableLearning",
"Enable the learning mode of the Learning Bridge",
BooleanValue (true),
MakeBooleanAccessor (&BridgeNetDevice::m_enableLearning),
MakeBooleanChecker ())
- .AddAttribute ("ExpirationTime",
- "Time it takes for learned MAC state entry to expire.",
- TimeValue (Seconds (300)),
- MakeTimeAccessor (&BridgeNetDevice::m_expirationTime),
- MakeTimeChecker ())
;
return tid;
}
{
NS_LOG_FUNCTION_NOARGS ();
m_channel = CreateObject<BridgeChannel> ();
+ m_state = CreateObject<BridgeState> ();
}
BridgeNetDevice::~BridgeNetDevice()
if (m_enableLearning)
{
- std::map<Mac48Address, LearnedState>::iterator it = m_learnState.find(src48);
- if(it != m_learnState.end() || m_learnState.size() < m_maxStateSize){
- LearnedState &state = m_learnState[src48];
- state.associatedPort = port;
- state.expirationTime = Simulator::Now () + m_expirationTime;
- }
+ m_state->Learn(src48, port);
}
}
NS_LOG_FUNCTION_NOARGS ();
if (m_enableLearning)
{
- Time now = Simulator::Now ();
- std::map<Mac48Address, LearnedState>::iterator iter =
- m_learnState.find (source);
- if (iter != m_learnState.end ())
- {
- LearnedState &state = iter->second;
- if (state.expirationTime > now)
- {
- return state.associatedPort;
- }
- else
- {
- m_learnState.erase (iter);
- }
- }
+ return m_state->GetPort(source);
}
return NULL;
}
BridgeNetDevice::SetMaxStateSize (const unsigned long maxStateSize )
{
NS_LOG_FUNCTION_NOARGS ();
- m_maxStateSize = maxStateSize ;
+ m_state->SetMaxSize(maxStateSize);
return true;
}
BridgeNetDevice::GetMaxStateSize (void) const
{
NS_LOG_FUNCTION_NOARGS ();
- return m_maxStateSize;
+ return m_state->GetMaxSize();
}
unsigned long
BridgeNetDevice::GetStateSize (void) const
{
NS_LOG_FUNCTION_NOARGS ();
- return m_learnState.size();
+ return m_state->GetSize();
}
bool
#define BRIDGE_NET_DEVICE_H
#include "bridge-port-net-device.h"
+#include "bridge-state.h"
#include "ns3/net-device.h"
#include "ns3/mac48-address.h"
#include "ns3/nstime.h"
NetDevice::PromiscReceiveCallback m_promiscRxCallback;
Mac48Address m_address;
- Time m_expirationTime; // time it takes for learned MAC state to expire
- struct LearnedState
- {
- Ptr<BridgePortNetDevice> associatedPort;
- Time expirationTime;
- };
- std::map<Mac48Address, LearnedState> m_learnState;
Ptr<Node> m_node;
Ptr<BridgeChannel> m_channel;
+ Ptr<BridgeState> m_state;
+
std::vector<Ptr<BridgePortNetDevice> > m_ports;
uint16_t mPortNumber;
uint32_t m_ifIndex;
uint16_t m_mtu;
- unsigned long m_maxStateSize;
bool m_enableLearning;
};
--- /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;
+}
+
+}
+
+
--- /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;
+
+};
+
+}
+
+#endif
+
def build(bld):
obj = bld.create_ns3_module('bridge', ['node'])
obj.source = [
+ 'model/bridge-state.cc',
'model/moose-bridge-port-net-device.cc',
'model/moose-bridge-net-device.cc',
'model/bridge-net-device.cc',
headers = bld.new_task_gen('ns3header')
headers.module = 'bridge'
headers.source = [
+ 'model/bridge-state.h',
'model/moose-bridge-port-net-device.h',
'model/moose-bridge-net-device.h',
'model/bridge-net-device.h',