Download this file

SimpleTable.cc    70 lines (54 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <SimpleTable/SimpleTable.h>
Register_Class(SimpleTable::SimpleTable);
namespace SimpleTable {
using namespace std;
#include <sstream>
// Lookup function, return a list of RMTPorts to forward a PDU/Address+qos.
vector<RMTPort * > SimpleTable::lookup(const PDU * pdu){
return lookup(pdu->getDstAddr(), pdu->getConnId().getQoSId());
}
vector<RMTPort * > SimpleTable::lookup(const Address &dst, const unsigned short &qos){
vector<RMTPort* > ret;
string dstAddr = dst.getIpcAddress().getName();
qos2Port * t = &table[dstAddr];
if(t->find(qos) != t->end()){
ret.push_back((*t)[qos]);
} else if (qos == 0 && t->size() > 0){
ret.push_back(t->begin()->second);
}
return ret;
}
// Returns a representation of the Forwarding Knowledge
string SimpleTable::toString(){
std::ostringstream os;
os << this->getName()<<endl;
for(FWDTableIt tIt = table.begin(); tIt != table.end(); tIt++){
os << "\t" <<tIt->first<<endl;
for(qos2PortIt qIt = tIt->second.begin(); qIt != tIt->second.end(); qIt++){
os << "\t\t->(" << qIt->first << " , "<<qIt->second->getFullPath()<<")" <<endl;
}
}
return os.str();
}
//Insert/Remove an entry
void SimpleTable::insert(const Address &addr, const unsigned short &qos, RMTPort * port){
insert(addr.getIpcAddress().getName(), qos, port);
}
void SimpleTable::remove(const Address &addr, const unsigned short &qos){
remove(addr.getIpcAddress().getName(), qos);
}
void SimpleTable::insert(const string &addr, const unsigned short &qos, RMTPort * port){
table[addr][qos] = port;
}
void SimpleTable::remove(const string &addr, const unsigned short &qos){
table[addr].erase(qos);
if(table[addr].empty()){
table.erase(addr);
}
}
// Called after initialize
void SimpleTable::onPolicyInit(){}
void SimpleTable::finish(){
// EV << toString() <<endl;
}
}