Switch to unified view

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