Parent: [6ccca6] (diff)

Download this file

PDUForwardingTable.cc    152 lines (132 with data), 3.8 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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// Copyright Š 2014 - 2015 PRISTINE Consortium (http://ict-pristine.eu)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
/**
* @file PDUForwardingTable.cc
* @author Tomas Hykel (xhykel01@stud.fit.vutbr.cz)
* @brief PDU forwarding (routing) table used by RMT relay.
* @detail
*/
#include "PDUForwardingTable.h"
Define_Module(PDUForwardingTable);
void PDUForwardingTable::initialize()
{
WATCH_LIST(fwTable);
}
PDUForwardingTable::PDUForwardingTable()
{
}
void PDUForwardingTable::handleMessage(cMessage *msg)
{
}
/**
* Dumps the contents of the forwarding table to OMNeT++ output console.
*
*/
void PDUForwardingTable::printAll()
{
EV << "Printing the whole forwarding table: " << endl;
for(PDUFwdTable::iterator it = this->fwTable.begin(); it!= fwTable.end(); ++it)
{
PDUForwardingTableEntry a = *it;
EV << this->getFullPath()
<< " dstAddr: " << a.getDestAddr().getApname().getName()
<< "; QoS ID: " << a.getQosId()
<< "; port-id: " << a.getPort()->getFullName() << endl;
}
}
/**
* Looks up a port-id to be used for given address and Qos-id.
*
* @param destAddr destination IPC process address
* @param QoSid QoS-id
* @return port-id
*/
RMTPort* PDUForwardingTable::lookup(Address& destAddr, unsigned short QoSid)
{
for(PDUFwdTableIter it = fwTable.begin(); it != fwTable.end(); ++it )
{
PDUForwardingTableEntry a = *it;
if ((a.getDestAddr().getApname() == destAddr.getApname()) && (a.getQosId() == QoSid))
{
return a.getPort();
}
}
return NULL;
}
RMTPort* PDUForwardingTable::lookup(Address& destAddr)
{
for(PDUFwdTableIter it = fwTable.begin(); it != fwTable.end(); ++it )
{
PDUForwardingTableEntry a = *it;
if (a.getDestAddr().getApname() == destAddr.getApname())
{
return a.getPort();
}
}
return NULL;
}
/**
* Inserts a prepared forwarding table entry into the table.
*
* @param entry table entry to be inserted
*/
void PDUForwardingTable::insert(const PDUForwardingTableEntry* entry)
{
Enter_Method("insert()");
fwTable.push_back(*entry);
}
/**
* Constructs a new forwarding table entry and adds it into the table.
*
* @param destAddr destination IPC process address
* @param qosId flow QoS ID
*/
void PDUForwardingTable::insert(Address destAddr, unsigned short qosId, RMTPort* port)
{
Enter_Method("insert()");
// multiple ports per item aren't supported at the moment
if (lookup(destAddr, qosId) == NULL)
{
PDUForwardingTableEntry entry = PDUForwardingTableEntry(destAddr, qosId, port);
fwTable.push_back(entry);
}
}
/**
* Removes entries with matching port-id from the forwarding table.
*
* @param portId target port-id
*/
void PDUForwardingTable::remove(Address destAddr, int qosId)
{
PDUFwdTableIter i = fwTable.begin();
while (i != fwTable.end())
{
if (i->getDestAddr() == destAddr && i->getQosId() == qosId)
{
i = fwTable.erase(i);
}
else
{
++i;
}
}
}
void PDUForwardingTable::clean()
{
/* Q: How to handle memory here? */
fwTable.clear();
}