MooseAddressValue(),
MakeMooseAddressAccessor (&MooseBridgeNetDevice::m_mooseAddress),
MakeMooseAddressChecker ())
- .AddAttribute ("MooseExpirationTime",
- "Time it takes for learned MOOSE state entry to expire.",
- TimeValue (Seconds (30)),
- MakeTimeAccessor (&MooseBridgeNetDevice::m_expirationTime),
- MakeTimeChecker ());
+ ;
return tid;
}
NS_LOG_FUNCTION_NOARGS ();
m_mooseAddress = MooseAddress::Allocate();
+ m_state = CreateObject<MooseBridgeState> ();
}
if(addr.GetMoosePrefix() != m_mooseAddress.GetMoosePrefix()){
return addr;
}
-
- std::map<MooseSuffixAddress, SuffixState*>::iterator iter = m_ethernetState.find(addr.GetMooseSuffix());
-
- if(iter == m_ethernetState.end()){
-
- // Expired state - must broadcast.
-
- return MooseAddress(Mac48Address::GetBroadcast());
- } else {
-
- Time now = Simulator::Now();
-
- SuffixState* state = iter->second;
-
- if(state->expirationTime > now){
- return MooseAddress(iter->second->ethernet);
- } else {
- m_ethernetState.erase(iter);
- m_suffixState.erase(iter->second->ethernet);
- return MooseAddress(Mac48Address::GetBroadcast());
- }
-
- }
-
+ return m_state->GetMac(addr.GetMooseSuffix());
+
}
MooseAddress MooseBridgeNetDevice::ToMoose(MooseAddress const& addr){
NS_LOG_FUNCTION_NOARGS();
- Time now = Simulator::Now();
-
MooseAddress::MooseType mt = addr.GetMooseType();
if(mt == MooseAddress::MOOSE){
Mac48Address addr48 = addr.GetMacAddress();
- // Fix Suffix.
- std::map<Mac48Address, SuffixState>::iterator iter = m_suffixState.find(addr48);
- if(iter == m_suffixState.end()){
- // Allocate New Suffix
-
- moose = MooseAddress::Allocate(m_mooseAddress.GetMoosePrefix());
-
- SuffixState &state = m_suffixState[addr48];
- state.ethernet = addr48;
- state.suffix = moose.GetMooseSuffix();
- state.expirationTime = now + m_expirationTime;
-
- NS_LOG_LOGIC("Allocating New MOOSE Suffix: (" << moose.GetMoosePrefix().GetInt() << "," << moose.GetMooseSuffix().GetInt() << ") for " << addr48);
+ MooseSuffixAddress suffix = m_state->GetSuffix(addr48, m_mooseAddress.GetMoosePrefix());
- m_ethernetState[state.suffix] = &m_suffixState[addr48];
-
- } else {
- SuffixState &state = iter->second;
- if(state.expirationTime > now){
- moose = MooseAddress::Combine(m_mooseAddress.GetMoosePrefix(), state.suffix);
-
- NS_LOG_LOGIC("Using Allocated MOOSE Suffix: (" << moose.GetMoosePrefix().GetInt() << "," << moose.GetMooseSuffix().GetInt() << ")");
-
- if(now + m_expirationTime > state.expirationTime){
- state.expirationTime = now + m_expirationTime;
- }
- } else {
- // Delete old and alloc new
-
- m_ethernetState.erase(state.suffix);
- m_suffixState.erase(iter);
-
- // Allocate New
-
- SuffixState &state = m_suffixState[addr48];
-
- moose = MooseAddress::Allocate(m_mooseAddress.GetMoosePrefix());
- state.ethernet = addr48;
- state.suffix = moose.GetMooseSuffix();
- state.expirationTime = now + m_expirationTime;
-
- NS_LOG_LOGIC("Expired MOOSE Suffix: (" << moose.GetMoosePrefix().GetInt() << "," << moose.GetMooseSuffix().GetInt() << ")");
-
- m_ethernetState[state.suffix] = &m_suffixState[addr48];
-
- }
- }
-
- return moose;
+ return MooseAddress::Combine(m_mooseAddress.GetMoosePrefix(), suffix);
} else {
NS_ASSERT( (mt == MooseAddress::HOST) || (mt == MooseAddress::MOOSE) );
for(std::map<MoosePrefixAddress, Ptr<BridgePortNetDevice> >::iterator it = routes.begin(); it != routes.end(); it ++){
- NS_LOG_LOGIC("Adding Prefix State: (port: " << it->second << ", time: " << Simulator::GetMaximumSimulationTime() << ")");
-
- PrefixState &state = m_prefixState[it->first];
- state.associatedPort = it->second;
- state.expirationTime = Simulator::GetMaximumSimulationTime();
+ m_state->Fixed(it->first, it->second);
}
void MooseBridgeNetDevice::Learn(MooseAddress const& addr, Ptr<BridgePortNetDevice> port){
NS_LOG_FUNCTION_NOARGS ();
-
- Time now = Simulator::Now();
NS_ASSERT(addr.GetMooseType() == MooseAddress::MOOSE);
if(addr.GetMoosePrefix() != m_mooseAddress.GetMoosePrefix()){
- PrefixState &state = m_prefixState[addr.GetMoosePrefix()];
- if(now + m_expirationTime > state.expirationTime){
- NS_LOG_LOGIC("Updating Learned Prefix State: (port: " << port << ", time: " << now + m_expirationTime << ", address: " << addr << ") - Previous State: (port: " << state.associatedPort << ", time: " << state.expirationTime << ")");
-
- state.associatedPort = port; // Only update if the expiration is not in the future
- state.expirationTime = now + m_expirationTime;
- }
+ m_state->Learn(addr.GetMoosePrefix(), port);
} else {
- PortState &state = m_portState[addr.GetMooseSuffix()];
- if(now + m_expirationTime > state.expirationTime){
- NS_LOG_LOGIC("Updating Learned Suffix State: (port: " << port << ", time: " << now + m_expirationTime << ", address: " << addr << ") - Previous State: (port: " << state.associatedPort << ", time: " << state.expirationTime << ")");
- state.associatedPort = port;
- state.expirationTime = now + m_expirationTime;
- }
+ m_state->Learn(addr.GetMooseSuffix(), port);
}
Ptr<BridgePortNetDevice> MooseBridgeNetDevice::GetLearnedPort(MooseAddress const&addr){
NS_LOG_FUNCTION_NOARGS();
- Time now = Simulator::Now();
-
if(addr.GetMooseType() != MooseAddress::MOOSE){
return NULL;
}
if(addr.GetMoosePrefix() != m_mooseAddress.GetMoosePrefix()){
- std::map<MoosePrefixAddress, PrefixState>::iterator iter = m_prefixState.find(addr.GetMoosePrefix());
-
- if(iter != m_prefixState.end()){
- return iter->second.associatedPort;
- }
+ return m_state->GetPort(addr.GetMoosePrefix());
} else {
- std::map<MooseSuffixAddress, PortState>::iterator iter = m_portState.find(addr.GetMooseSuffix());
-
- if(iter != m_portState.end()){
- return iter->second.associatedPort;
- }
+ return m_state->GetPort(addr.GetMooseSuffix());
}
return NULL;
#define MOOSE_BRIDGE_NET_DEVICE_H
#include "bridge-net-device.h"
+#include "moose-bridge-state.h"
#include "ns3/moose-address.h"
#include "ns3/moose-prefix-address.h"
#include "ns3/moose-suffix-address.h"
private:
-// Need more types of state
-
MooseAddress m_mooseAddress;
- // Remote Moose State
-
- struct PrefixState
- {
- Ptr<BridgePortNetDevice> associatedPort;
- Time expirationTime;
- };
-
- // Local Moose State
-
- struct SuffixState
- {
- Mac48Address ethernet;
- MooseSuffixAddress suffix;
- Time expirationTime;
- };
-
- struct PortState
- {
- Ptr<BridgePortNetDevice> associatedPort;
- Time expirationTime;
- };
-
- Time m_expirationTime;
-
- std::map<MoosePrefixAddress, PrefixState> m_prefixState;
- std::map<Mac48Address, SuffixState> m_suffixState;
- std::map<MooseSuffixAddress, SuffixState*> m_ethernetState;
- std::map<MooseSuffixAddress, PortState> m_portState;
+ Ptr<MooseBridgeState> m_state;
};
--- /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 "moose-bridge-state.h"
+#include "ns3/log.h"
+#include "ns3/boolean.h"
+#include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+
+NS_LOG_COMPONENT_DEFINE ("MooseBridgeState");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (MooseBridgeState);
+
+TypeId MooseBridgeState::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::MooseBridgeState")
+ .SetParent<Object> ()
+ .AddConstructor<MooseBridgeState> ()
+ .AddAttribute ( "ExpirationTime",
+ "Time it takes for learned state entry to expire.",
+ TimeValue (Seconds (300)),
+ MakeTimeAccessor (&MooseBridgeState::m_time),
+ MakeTimeChecker ())
+ .AddAttribute ( "StateSize", "The size of the State Table",
+ UintegerValue (8000),
+ MakeUintegerAccessor (&MooseBridgeState::m_max),
+ MakeUintegerChecker<unsigned long> ())
+ ;
+ return tid;
+}
+
+MooseBridgeState::MooseBridgeState(){
+
+}
+
+MooseBridgeState::~MooseBridgeState(){
+
+}
+
+void MooseBridgeState::Learn(MoosePrefixAddress addr, Ptr<BridgePortNetDevice> port){
+
+ Time now = Simulator::Now ();
+
+ Prefix &state = m_prefixState[addr];
+ // Only update if the expiration is not in the future
+ if(now + m_time > state.time){
+ state.port = port;
+ state.time = now + m_time;
+ }
+}
+
+void MooseBridgeState::Learn(MooseSuffixAddress addr, Ptr<BridgePortNetDevice> port){
+
+ Time now = Simulator::Now ();
+
+ Port &state = m_portState[addr];
+ // Only update if the expiration is not in the future
+ if(now + m_time > state.time){
+ state.port = port;
+ state.time = now + m_time;
+ }
+
+}
+
+void MooseBridgeState::Fixed(MoosePrefixAddress addr, Ptr<BridgePortNetDevice> port){
+
+
+ Prefix &state = m_prefixState[addr];
+ state.port = port;
+ state.time = Simulator::GetMaximumSimulationTime();
+}
+
+Mac48Address MooseBridgeState::GetMac(MooseSuffixAddress addr){
+
+ std::map<MooseSuffixAddress, Suffix*>::iterator iter = m_sufSuffixState.find(addr);
+
+ if(iter == m_sufSuffixState.end()){
+
+ // Not found.
+
+ return Mac48Address::GetBroadcast();
+
+ } else {
+
+ Time now = Simulator::Now();
+
+ Suffix* state = iter->second;
+
+ if(state->time > now){
+ return iter->second->ethernet;
+ } else {
+ m_sufSuffixState.erase(iter);
+ m_ethSuffixState.erase(iter->second->ethernet);
+ return Mac48Address::GetBroadcast();
+ }
+ }
+
+}
+
+MooseSuffixAddress MooseBridgeState::GetSuffix(Mac48Address addr, MoosePrefixAddress prefix){
+
+ Time now = Simulator::Now();
+
+ std::map<Mac48Address, Suffix>::iterator iter = m_ethSuffixState.find(addr);
+
+ if(iter == m_ethSuffixState.end()){
+ // Allocate New Suffix
+ MooseAddress moose = MooseAddress::Allocate(prefix);
+ Suffix &state = m_ethSuffixState[addr];
+ state.ethernet = addr;
+ state.suffix = moose.GetMooseSuffix();
+ state.time = now + m_time;
+ NS_LOG_LOGIC("Allocating New MOOSE Suffix: (" << moose.GetMoosePrefix().GetInt() << "," << moose.GetMooseSuffix().GetInt() << ") for " << addr);
+ m_sufSuffixState[state.suffix] = &m_ethSuffixState[addr];
+
+
+ return moose.GetMooseSuffix();
+
+ } else {
+ Suffix &state = iter->second;
+
+ // Valid Entry
+
+ if(state.time > now){
+ MooseAddress moose = MooseAddress::Combine(prefix, state.suffix);
+ NS_LOG_LOGIC("Using Allocated MOOSE Suffix: (" << prefix.GetInt() << "," << state.suffix.GetInt() << ")");
+
+ if(now + m_time > state.time){
+ state.time = now + m_time;
+ }
+
+
+ return moose.GetMooseSuffix();
+
+ } else {
+
+ // Expired Entry - Delete old and alloc new
+
+ m_sufSuffixState.erase(state.suffix);
+ m_ethSuffixState.erase(iter);
+
+ // Allocate New
+
+ Suffix &state = m_ethSuffixState[addr];
+ MooseAddress moose = MooseAddress::Allocate(prefix);
+ state.ethernet = addr;
+ state.suffix = moose.GetMooseSuffix();
+ state.time = now + m_time;
+
+ NS_LOG_LOGIC("Expired MOOSE Suffix: (" << prefix.GetInt() << "," << state.suffix.GetInt() << ")");
+
+ m_sufSuffixState[state.suffix] = &m_ethSuffixState[addr];
+
+
+ return moose.GetMooseSuffix();
+
+ }
+ }
+}
+
+Ptr<BridgePortNetDevice> MooseBridgeState::GetPort(MoosePrefixAddress addr){
+
+ Time now = Simulator::Now();
+
+ std::map<MoosePrefixAddress, Prefix>::iterator iter = m_prefixState.find(addr);
+
+ if(iter != m_prefixState.end() && iter->second.time > now){
+
+ return iter->second.port;
+ }
+
+ return NULL;
+
+}
+
+Ptr<BridgePortNetDevice> MooseBridgeState::GetPort(MooseSuffixAddress addr){
+
+ Time now = Simulator::Now();
+
+ std::map<MooseSuffixAddress, Port>::iterator iter = m_portState.find(addr);
+
+ if(iter != m_portState.end() && iter->second.time > now){
+
+ return iter->second.port;
+ }
+
+ return NULL;
+
+}
+
+unsigned long MooseBridgeState::GetSize(){
+ return m_prefixState.size() + m_portState.size();
+}
+
+}
+
--- /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 MOOSE_BRIDGE_STATE_H
+#define MOOSE_BRIDGE_STATE_H
+
+#include "bridge-port-net-device.h"
+#include "ns3/object-factory.h"
+#include "ns3/mac48-address.h"
+#include "ns3/nstime.h"
+#include "ns3/moose-address.h"
+#include "ns3/moose-prefix-address.h"
+#include "ns3/moose-suffix-address.h"
+
+namespace ns3 {
+
+class MooseBridgeState : public Object {
+
+public:
+
+ static TypeId GetTypeId (void);
+ MooseBridgeState();
+ ~MooseBridgeState();
+
+ unsigned long GetSize();
+
+ unsigned long GetMaxSize() const;
+ bool SetMaxSize(const unsigned long max);
+
+ void Learn(MooseSuffixAddress suffix, Ptr<BridgePortNetDevice> port);
+ void Learn(MoosePrefixAddress prefix, Ptr<BridgePortNetDevice> port);
+
+ void Fixed(MoosePrefixAddress prefix, Ptr<BridgePortNetDevice> port);
+
+ MooseSuffixAddress GetSuffix(Mac48Address addr, MoosePrefixAddress prefix);
+
+ Ptr<BridgePortNetDevice> GetPort(MoosePrefixAddress addr);
+ Ptr<BridgePortNetDevice> GetPort(MooseSuffixAddress addr);
+
+ Mac48Address GetMac(MooseSuffixAddress addr);
+
+private:
+
+ unsigned long m_max;
+
+ // Remote Moose State
+
+ struct Prefix {
+ Ptr<BridgePortNetDevice> port;
+ Time time;
+ };
+
+ // Local Moose State
+
+ struct Suffix {
+ Mac48Address ethernet;
+ MooseSuffixAddress suffix;
+ Time time;
+ };
+
+ struct Port {
+ Ptr<BridgePortNetDevice> port;
+ Time time;
+ };
+
+ Time m_time;
+
+ std::map<MoosePrefixAddress, Prefix> m_prefixState;
+ std::map<Mac48Address, Suffix> m_ethSuffixState;
+ std::map<MooseSuffixAddress, Suffix*> m_sufSuffixState;
+ std::map<MooseSuffixAddress, Port> m_portState;
+
+
+};
+
+}
+
+#endif
+
obj = bld.create_ns3_module('bridge', ['node'])
obj.source = [
'model/bridge-state.cc',
+ 'model/moose-bridge-state.cc',
'model/moose-bridge-port-net-device.cc',
'model/moose-bridge-net-device.cc',
'model/bridge-net-device.cc',
headers.module = 'bridge'
headers.source = [
'model/bridge-state.h',
+ 'model/moose-bridge-state.h',
'model/moose-bridge-port-net-device.h',
'model/moose-bridge-net-device.h',
'model/bridge-net-device.h',