Limit Ethernet Bridge state table size (default 8000 - configurable)
authorRichard Whitehouse <github@richardwhiuk.com>
Fri, 15 Apr 2011 21:30:16 +0000 (22:30 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Fri, 15 Apr 2011 21:30:16 +0000 (22:30 +0100)
src/devices/bridge/model/bridge-net-device.cc
src/devices/bridge/model/bridge-net-device.h

index 100fa1bfe92bf1f2d339660495970df37abe868d..83a71226ab3c9042a9c0e818f47ff3b0c233a978 100644 (file)
@@ -42,7 +42,12 @@ BridgeNetDevice::GetTypeId (void)
                    UintegerValue (1500),
                    MakeUintegerAccessor (&BridgeNetDevice::SetMtu,
                                          &BridgeNetDevice::GetMtu),
-                   MakeUintegerChecker<uint16_t> ())                   
+                   MakeUintegerChecker<uint16_t> ())    
+    .AddAttribute ("StateSize", "The size of the State Table",
+                   UintegerValue (8000),
+                   MakeUintegerAccessor (&BridgeNetDevice::SetStateSize,
+                                         &BridgeNetDevice::GetStateSize),
+                   MakeUintegerChecker<unsigned long> ())                  
     .AddAttribute ("EnableLearning",
                    "Enable the learning mode of the Learning Bridge",
                    BooleanValue (true),
@@ -50,7 +55,7 @@ BridgeNetDevice::GetTypeId (void)
                    MakeBooleanChecker ())
     .AddAttribute ("ExpirationTime",
                    "Time it takes for learned MAC state entry to expire.",
-                   TimeValue (Seconds (30)),
+                   TimeValue (Seconds (300)),
                    MakeTimeAccessor (&BridgeNetDevice::m_expirationTime),
                    MakeTimeChecker ())
     ;
@@ -177,9 +182,12 @@ void BridgeNetDevice::Learn (Address const &src, Ptr<BridgePortNetDevice> port)
 
   if (m_enableLearning)
     {
-      LearnedState &state = m_learnState[src48];
-      state.associatedPort = port;
-      state.expirationTime = Simulator::Now () + m_expirationTime;
+       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;
+       }
     }
 }
 
@@ -301,6 +309,27 @@ BridgeNetDevice::GetMtu (void) const
   return m_mtu;
 }
 
+bool 
+BridgeNetDevice::SetMaxStateSize (const unsigned long maxStateSize )
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  m_maxStateSize = maxStateSize ;
+  return true;
+}
+
+unsigned long 
+BridgeNetDevice::GetMaxStateSize (void) const
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  return m_maxStateSize;
+}
+
+unsigned long 
+BridgeNetDevice::GetStateSize (void) const
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  return m_learnState.size();
+}
 
 bool 
 BridgeNetDevice::IsLinkUp (void) const
index 1b63ff9ab9a5b58db1f9d30466da46cf519cb08b..270991954acd12e36e8661fef1120d3cfc3d24aa 100644 (file)
@@ -100,6 +100,11 @@ public:
   virtual Address GetAddress (void) const;
   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;
@@ -150,6 +155,7 @@ private:
   uint16_t mPortNumber;
   uint32_t m_ifIndex;
   uint16_t m_mtu;
+  unsigned long m_maxStateSize;
   bool m_enableLearning;
 
 };