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