|
INET Framework for OMNeT++/OMNEST
|
#include <ansaRoutingTable6.h>
Public Member Functions | |
| AnsaRoutingTable6 () | |
| const IPv6Route * | doLongestPrefixMatch (const IPv6Address &dest) |
| void | addDirectRoute (const IPv6Address &destPrefix, int prefixLength, unsigned int interfaceId) |
Protected Member Functions | |
| virtual int | numInitStages () const |
| virtual void | initialize (int stage) |
| virtual void | receiveChangeNotification (int category, const cPolymorphic *details) |
| virtual void | addRoute (IPv6Route *route) |
Static Protected Member Functions | |
| static bool | routeLessThan (const IPv6Route *a, const IPv6Route *b) |
Protected Attributes | |
| std::vector< AnsaIPv6Route * > * | routes |
Definition at line 41 of file ansaRoutingTable6.h.
Definition at line 106 of file ansaRoutingTable6.cc.
| void AnsaRoutingTable6::addDirectRoute | ( | const IPv6Address & | destPrefix, |
| int | prefixLength, | ||
| unsigned int | interfaceId | ||
| ) |
Definition at line 226 of file ansaRoutingTable6.cc.
{
// create route object
IPv6Route *route = new IPv6Route(destPrefix, prefixLength, IPv6Route::STATIC);
route->setInterfaceId(interfaceId);
route->setNextHop(IPv6Address::UNSPECIFIED_ADDRESS);
route->setMetric(0);
// then add it
addRoute(route);
}
| void AnsaRoutingTable6::addRoute | ( | IPv6Route * | route | ) | [protected, virtual] |
Reimplemented from RoutingTable6.
Definition at line 261 of file ansaRoutingTable6.cc.
Referenced by addDirectRoute().
{
AnsaIPv6Route *route6 = new AnsaIPv6Route(route->getDestPrefix(),
route->getPrefixLength(),
route->getSrc());
route6->setNextHop(route->getNextHop());
route6->setMetric(route->getMetric());
route6->setInterfaceId(route->getInterfaceId());
route6->setExpiryTime(route->getExpiryTime());
route6->setActive(true);
if (route->getInterfaceId() != -1){
InterfaceEntry *ie = ift->getInterfaceById(route->getInterfaceId());
if (ie != NULL){
route6->setInterfaceName(ie->getName());
}
}
delete route;
routeList.push_back(route6);
// we keep entries sorted by prefix length and metric in routeList,
// so that we can stop at the first match when doing the longest prefix matching
std::sort(routeList.begin(), routeList.end(), routeLessThan);
updateDisplayString();
nb->fireChangeNotification(NF_IPv6_ROUTE_ADDED, route6);
}
| const IPv6Route * AnsaRoutingTable6::doLongestPrefixMatch | ( | const IPv6Address & | dest | ) |
Performs longest prefix match in the routing table and returns the resulting route, or NULL if there was no match.
Reimplemented from RoutingTable6.
Definition at line 195 of file ansaRoutingTable6.cc.
{
Enter_Method("doLongestPrefixMatch(%s)", dest.str().c_str());
AnsaIPv6Route *route;
// we'll just stop at the first match, because the table is sorted
// by prefix lengths and metric (see addRoute())
for (RouteList::const_iterator it = routeList.begin(); it != routeList.end(); it++){
if (dest.matches((*it)->getDestPrefix(), (*it)->getPrefixLength())){
route = (AnsaIPv6Route *)(*it);
if (!route->isActive()){
return NULL;
}
bool entryExpired = false;
if (simTime() > (*it)->getExpiryTime() && (*it)->getExpiryTime() != 0){
EV<< "Expired prefix detected!!" << endl;
removeOnLinkPrefix((*it)->getDestPrefix(), (*it)->getPrefixLength());
entryExpired = true;
continue;
}else{
return *it;
}
}
}
return NULL;
}
| void AnsaRoutingTable6::initialize | ( | int | stage | ) | [protected, virtual] |
Reimplemented from RoutingTable6.
Definition at line 110 of file ansaRoutingTable6.cc.
{
if (stage == 1){
ift = InterfaceTableAccess().get();
nb = NotificationBoardAccess().get();
if (ift == NULL){
throw cRuntimeError("AnsaInterfaceTable not found");
}
if (nb == NULL){
throw cRuntimeError("NotificationBoard not found");
}
nb->subscribe(this, NF_INTERFACE_STATE_CHANGED);
WATCH_PTRVECTOR(*routes);
WATCH_PTRVECTOR(routeList);
WATCH_MAP(destCache);
isrouter = par("isRouter");
WATCH(isrouter);
// add IPv6InterfaceData to interfaces
for (int i = 0; i < ift->getNumInterfaces(); i++){
InterfaceEntry *ie = ift->getInterface(i);
configureInterfaceForIPv6(ie);
}
if (isrouter){
// add globally routable prefixes to routing table
for (int x = 0; x < ift->getNumInterfaces(); x++){
InterfaceEntry *ie = ift->getInterface(x);
if (ie->isLoopback())
continue;
for (int y = 0; y < ie->ipv6Data()->getNumAdvPrefixes(); y++){
if (ie->ipv6Data()->getAdvPrefix(y).prefix.isGlobal()){
addOrUpdateOwnAdvPrefix(ie->ipv6Data()->getAdvPrefix(y).prefix, ie->ipv6Data()->getAdvPrefix(y).prefixLength, ie->getInterfaceId(), 0);
}
}
}
}
}else if (stage == 4){
// configurator adds routes only in stage==3
updateDisplayString();
}
}
| virtual int AnsaRoutingTable6::numInitStages | ( | ) | const [inline, protected, virtual] |
| void AnsaRoutingTable6::receiveChangeNotification | ( | int | category, |
| const cPolymorphic * | details | ||
| ) | [protected, virtual] |
Called by the NotificationBoard whenever a change of a category occurs to which this client has subscribed.
Reimplemented from RoutingTable6.
Definition at line 159 of file ansaRoutingTable6.cc.
{
if (simulation.getContextType() == CTX_INITIALIZE)
return;
Enter_Method_Silent();
if (category == NF_INTERFACE_STATE_CHANGED){
InterfaceEntry *ie;
AnsaIPv6Route *r;
// Walk thru the whole routing table and try to get interface for each route.
// If interface does not exist in InterfaceTable, it's down and we should
// disable the route.
// If interface of a disabled route does exist in InterfaceTable, it's up
// and we should enable the route again.
for (RouteList::const_iterator it = routeList.begin(); it != routeList.end(); it++){
r = (AnsaIPv6Route *)(*it);
ie = ift->getInterfaceById(r->getInterfaceId());
if (ie == NULL && r->isActive()){
r->setActive(false);
}else if (ie != NULL && ie->isDown() && r->isActive()){
r->setActive(false);
}else if (ie != NULL && !ie->isDown() && !r->isActive()){
r->setActive(true);
}
}
std::sort(routeList.begin(), routeList.end(), routeLessThan);
purgeDestCache();
}
}
| bool AnsaRoutingTable6::routeLessThan | ( | const IPv6Route * | a, |
| const IPv6Route * | b | ||
| ) | [static, protected] |
Reimplemented from RoutingTable6.
Definition at line 238 of file ansaRoutingTable6.cc.
Referenced by addRoute(), and receiveChangeNotification().
{
// Helper for sort() in addRoute().
// We want routes with longer prefixes to be at front,
// so we compare them as "less". For metric, a smaller
// value is better (we report that as "less"). Disabled
// routes are "more" than enabled routes.
AnsaIPv6Route *ax = (AnsaIPv6Route *) a;
AnsaIPv6Route *bx = (AnsaIPv6Route *) b;
if (ax->isActive() && !bx->isActive())
return true;
if (!ax->isActive() && bx->isActive())
return false;
if (a->getPrefixLength() != b->getPrefixLength())
return a->getPrefixLength() > b->getPrefixLength();
return a->getMetric() < b->getMetric();
}
std::vector<AnsaIPv6Route*>* AnsaRoutingTable6::routes [protected] |
Definition at line 43 of file ansaRoutingTable6.h.
Referenced by AnsaRoutingTable6(), and initialize().