16 void HierarchicalTable::addDomain(
const string & domId,
const string & qos,
const string & prefix) {
19 domains[prefix][qos] =
domData(domId, 0);
21 vector<string> parsed =
split(prefix,
'.');
22 domains[prefix][qos] =
domData(domId, parsed.size());
26 void HierarchicalTable::addDomain(
const string & domId,
const string & prefix) {
27 addDomain(domId, anyQoS, prefix);
30 void HierarchicalTable::removeDomain(
string domId) {
32 for(
const auto & addrP : domains) {
33 for(
const auto & qosP : addrP.second) {
34 if(qosP.second.domId == domId) {
40 domains[prefix].erase(qos);
46 vector<RMTPort * > HierarchicalTable::lookup(
const PDU * pdu){
49 vector<RMTPort * > HierarchicalTable::lookup(
const Address &dst,
const std::string& qos){
51 vector<RMTPort* > ret;
54 if(dstAddr ==
"") {
return ret; };
55 vector<RMTPort* >* found = NULL;
56 vector<string> parsed =
split(dstAddr,
'.');
58 for(
auto & addrP : domains) {
59 if(!
isPrefix(addrP.first, dstAddr)){
continue; }
61 bool foundAtQoS =
false;
62 bool foundAtAddr =
false;
64 if(addrP.second.find(qos) != addrP.second.end()) {
65 domData dd = addrP.second[qos];
66 string val = parsed[dd.prefLen];
67 if(table[dd.domId].find(val) != table[dd.domId].end()){
68 found = &table[dd.domId][val];
71 }
else if(table[dd.domId].find(
"*") != table[dd.domId].end()) {
72 found = &table[dd.domId][
"*"];
76 if(!foundAtAddr && addrP.second.find(anyQoS) != addrP.second.end()) {
77 domData dd = addrP.second[anyQoS];
79 string val = parsed[dd.prefLen];
80 if(table[dd.domId].find(val) != table[dd.domId].end()){
81 found = &table[dd.domId][val];
82 }
else if(!foundAtQoS && table[dd.domId].find(
"*") != table[dd.domId].end()) {
83 found = &table[dd.domId][
"*"];
88 if(found != NULL && !found->empty()) {
89 ret.push_back((*found)[intuniform(0, found->size()-1)]);
90 }
else if(direct.find(dst) != direct.end()) {
91 ret.push_back(direct[dst]);
98 string HierarchicalTable::toString(){
99 std::ostringstream os;
101 os << this->getName()<<endl;
102 for(
const auto & addrP : domains) {
103 for(
const auto & qosP : addrP.second) {
104 os <<
" Domain " << qosP.second.domId <<
" (\""<<addrP.first<<
"\" , QoS "<< qosP.first<<
")" << endl;
105 for(
const auto &entry : table[qosP.second.domId]) {
106 os <<
"\t" <<entry.first <<
" -> ";
107 for(
RMTPort * p : entry.second){
108 os << p->getFullPath() <<
" ";
119 void HierarchicalTable::addReplace(
const string &domId,
const string &addr, vector<RMTPort *> ports){
121 table[domId].erase(addr);
123 table[domId][addr] = ports;
128 void HierarchicalTable::onPolicyInit(){
130 cModule * ipcModule = getModuleByPath(
"^.^");
133 ipcModule->par(
"ipcAddress").stringValue(),
134 ipcModule->par(
"difName").stringValue());
137 void HierarchicalTable::setAddr(
const Address & addr) {
146 if(direct[dst]== NULL || direct[dst]==p) {
151 void HierarchicalTable::finish(){
152 if(par(
"printAtEnd").boolValue()){
153 EV <<
"-----------------" << endl;
154 EV <<
"Forwarding table::" << endl;
155 EV << toString() <<endl;
156 EV <<
"-----------------" << endl;
157 for(
auto tmp : direct){
158 EV <<
"\t" << tmp.first <<
" -> " << tmp.second->getFullPath() << endl;
std::string getQoSId() const
Getter of selected QoS-cube identifier.
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
bool isPrefix(std::string prefix, std::string s)
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
virtual ConnectionId & getConnId()
Register_Class(HierarchicalTable::HierarchicalTable)
virtual Address & getDstAddr()
const std::string & getName() const
Gets APN string name representation.
Address class holds IPC Process identification.