|
INET Framework for OMNeT++/OMNEST
|
#include <AnsaRoutingTable.h>
Public Member Functions | |
| AnsaRoutingTable () | |
| virtual | ~AnsaRoutingTable () |
| simtime_t | getInstallTime () const |
| void | setInstallTime (simtime_t time) |
| virtual void | printRoutingTable () const |
| virtual bool | isIPForwardingEnabled () |
| virtual IPAddress | getRouterId () |
| virtual void | setRouterId (IPAddress a) |
| virtual void | setTimeToLiveRoutingEntry (simtime_t a) |
| virtual simtime_t | getTimeToLiveRoutingEntry () |
| virtual void | dsdvTestAndDelete () |
| virtual const bool | testValidity (const IPRoute *entry) const |
| std::string | directIPRouteFormat (const IPRoute *entry) |
| std::string | otherIPRouteFormat (const IPRoute *entry) |
Interfaces | |
| virtual void | configureInterfaceForIPv4 (InterfaceEntry *ie) |
| virtual InterfaceEntry * | getInterfaceByAddress (const IPAddress &address) const |
Routing functions (query the route table) | |
| virtual bool | isLocalAddress (const IPAddress &dest) const |
| virtual const IPRoute * | findBestMatchingRoute (const IPAddress &dest) const |
| virtual InterfaceEntry * | getInterfaceForDestAddr (const IPAddress &dest) const |
| virtual IPAddress | getGatewayForDestAddr (const IPAddress &dest) const |
Multicast routing functions | |
| virtual bool | isLocalMulticastAddress (const IPAddress &dest) const |
| virtual MulticastRoutes | getMulticastRoutesFor (const IPAddress &dest) const |
Route table manipulation | |
| virtual int | getNumRoutes () const |
| virtual const IPRoute * | getRoute (int k) const |
| virtual const IPRoute * | findRoute (const IPAddress &target, const IPAddress &netmask, const IPAddress &gw, int metric=0, const char *dev=NULL) const |
| virtual const IPRoute * | getDefaultRoute () const |
| virtual void | addRoute (const IPRoute *entry) |
| virtual bool | deleteRoute (const IPRoute *entry) |
| virtual std::vector< IPAddress > | gatherAddresses () const |
Public Attributes | |
| simtime_t | installtime |
Protected Types | |
| typedef std::vector< IPRoute * > | RouteVector |
| typedef std::map< IPAddress, const IPRoute * > | RoutingCache |
| typedef std::set< IPAddress > | AddressSet |
Protected Member Functions | |
| virtual void | configureLoopbackForIPv4 () |
| virtual bool | routeMatches (const IPRoute *entry, const IPAddress &target, const IPAddress &nmask, const IPAddress &gw, int metric, const char *dev) const |
| virtual void | configureRouterId () |
| virtual void | updateNetmaskRoutes () |
| virtual void | updateDisplayString () |
| virtual void | deleteInterfaceRoutes (InterfaceEntry *entry) |
| virtual void | invalidateCache () |
| void | initializeAD () |
| bool | checkRoute (const IPRoute *entry) |
| bool | matchHostMask (const IPRoute *entry, const IPAddress &target, const IPAddress &nmask) |
| void | generateShowIPRoute () |
| virtual int | numInitStages () const |
| virtual void | initialize (int stage) |
| virtual void | handleMessage (cMessage *) |
| virtual void | receiveChangeNotification (int category, const cPolymorphic *details) |
Protected Attributes | |
| IInterfaceTable * | ift |
| NotificationBoard * | nb |
| IPAddress | routerId |
| bool | IPForward |
| simtime_t | timetolive_routing_entry |
| RouteVector | routes |
| RouteVector | multicastRoutes |
| RoutingCache | routingCache |
| AddressSet | localAddresses |
| std::map< IPRoute::RouteSource, int > | ADmap |
| std::vector< std::string > | showIPRoute |
Represents the routing table. This object has one instance per host or router. It has methods to manage the route table and the interface table, so one can achieve functionality similar to the "route" and "ifconfig" commands.
See the NED documentation for general overview.
This is a simple module without gates, it requires function calls to it (message handling does nothing). Methods are provided for reading and updating the interface table and the route table, as well as for unicast and multicast routing.
Interfaces are dynamically registered: at the start of the simulation, every L2 module adds its own interface entry to the table.
The route table is read from a file (RoutingTableParser); the file can also fill in or overwrite interface settings. The route table can also be read and modified during simulation, typically by routing protocol implementations (e.g. OSPF).
Entries in the route table are represented by IPRoute objects. IPRoute objects can be polymorphic: if a routing protocol needs to store additional data, it can simply subclass from IPRoute, and add the derived object to the table.
Uses RoutingTableParser to read routing files (.irt, .mrt).
Definition at line 75 of file AnsaRoutingTable.h.
typedef std::set<IPAddress> AnsaRoutingTable::AddressSet [protected] |
Definition at line 98 of file AnsaRoutingTable.h.
typedef std::vector<IPRoute *> AnsaRoutingTable::RouteVector [protected] |
Definition at line 89 of file AnsaRoutingTable.h.
typedef std::map<IPAddress, const IPRoute *> AnsaRoutingTable::RoutingCache [protected] |
Definition at line 94 of file AnsaRoutingTable.h.
Definition at line 43 of file AnsaRoutingTable.cc.
{
// DSDV
timetolive_routing_entry = timetolive_routing_entry.getMaxTime();
initializeAD();
}
| AnsaRoutingTable::~AnsaRoutingTable | ( | ) | [virtual] |
Definition at line 50 of file AnsaRoutingTable.cc.
| void AnsaRoutingTable::addRoute | ( | const IPRoute * | entry | ) | [virtual] |
Adds a route to the routing table. Note that once added, routes cannot be modified; you must delete and re-add them instead.
Implements IRoutingTable.
Definition at line 494 of file AnsaRoutingTable.cc.
{
Enter_Method("addRoute(...)");
// check for null address and default route
if (entry->getHost().isUnspecified() != entry->getNetmask().isUnspecified())
error("addRoute(): to add a default route, set both host and netmask to zero");
if (entry->getHost().doAnd(entry->getNetmask().isUnspecified()).getInt() != 0)
error("addRoute(): suspicious route: host %s has 1-bits outside netmask %s",
entry->getHost().str().c_str(), entry->getNetmask().str().c_str());
// check that the interface exists
if (!entry->getInterface())
error("addRoute(): interface cannot be NULL");
if (checkRoute(entry))
{
// if this is a default route, remove old default route (we're replacing it)
if (entry->getNetmask().isUnspecified() && getDefaultRoute()!=NULL)
deleteRoute(getDefaultRoute());
// add to tables
if (!entry->getHost().isMulticast())
routes.push_back(const_cast<IPRoute*>(entry));
else
multicastRoutes.push_back(const_cast<IPRoute*>(entry));
invalidateCache();
updateDisplayString();
nb->fireChangeNotification(NF_IPv4_ROUTE_ADDED, entry);
}
generateShowIPRoute();
}
| bool AnsaRoutingTable::checkRoute | ( | const IPRoute * | entry | ) | [protected] |
Definition at line 613 of file AnsaRoutingTable.cc.
Referenced by addRoute().
{
int n = getNumRoutes();
const IPRoute* ipr = NULL;
for (int i=0; i<n; i++)
{
if (matchHostMask(getRoute(i), entry->getHost(), entry->getNetmask()))
ipr=getRoute(i);
}
if (ipr==NULL)
return true;
else
{
if(ADmap.find(entry->getSource())->second < ADmap.find(ipr->getSource())->second)
return true;
}
return false;
}
| void AnsaRoutingTable::configureInterfaceForIPv4 | ( | InterfaceEntry * | ie | ) | [virtual] |
Implements IRoutingTable.
Definition at line 257 of file AnsaRoutingTable.cc.
Referenced by initialize().
{
IPv4InterfaceData *d = new IPv4InterfaceData();
ie->setIPv4Data(d);
// metric: some hints: OSPF cost (2e9/bps value), MS KB article Q299540, ...
d->setMetric((int)ceil(2e9/ie->getDatarate())); // use OSPF cost as default
}
| void AnsaRoutingTable::configureLoopbackForIPv4 | ( | ) | [protected, virtual] |
Definition at line 282 of file AnsaRoutingTable.cc.
{
InterfaceEntry *ie = ift->getFirstLoopbackInterface();
// add IPv4 info. Set 127.0.0.1/8 as address by default --
// we may reconfigure later it to be the routerId
IPv4InterfaceData *d = new IPv4InterfaceData();
d->setIPAddress(IPAddress::LOOPBACK_ADDRESS);
d->setNetmask(IPAddress::LOOPBACK_NETMASK);
d->setMetric(1);
ie->setIPv4Data(d);
}
| void AnsaRoutingTable::configureRouterId | ( | ) | [protected, virtual] |
Definition at line 129 of file AnsaRoutingTable.cc.
Referenced by initialize().
{
if (routerId.isUnspecified()) // not yet configured
{
const char *routerIdStr = par("routerId").stringValue();
if (!strcmp(routerIdStr, "auto")) // non-"auto" cases already handled in stage 1
{
// choose highest interface address as routerId
for (int i=0; i<ift->getNumInterfaces(); ++i)
{
InterfaceEntry *ie = ift->getInterface(i);
if (!ie->isLoopback() && ie->ipv4Data()->getIPAddress().getInt() > routerId.getInt())
routerId = ie->ipv4Data()->getIPAddress();
}
}
}
else // already configured
{
// if there is no interface with routerId yet, assign it to the loopback address;
// TODO find out if this is a good practice, in which situations it is useful etc.
if (getInterfaceByAddress(routerId)==NULL)
{
InterfaceEntry *lo0 = ift->getFirstLoopbackInterface();
lo0->ipv4Data()->setIPAddress(routerId);
lo0->ipv4Data()->setNetmask(IPAddress::ALLONES_ADDRESS);
}
}
}
| void AnsaRoutingTable::deleteInterfaceRoutes | ( | InterfaceEntry * | entry | ) | [protected, virtual] |
Definition at line 211 of file AnsaRoutingTable.cc.
Referenced by receiveChangeNotification().
{
RouteVector::iterator it = routes.begin();
while (it != routes.end())
{
IPRoute *route = *it;
if (route->getInterface() == entry)
{
deleteRoute(route);
it = routes.begin(); // iterator became invalid -- start over
}
else
{
++it;
}
}
}
| bool AnsaRoutingTable::deleteRoute | ( | const IPRoute * | entry | ) | [virtual] |
Deletes the given route from the routing table. Returns true if the route was deleted correctly, false if it was not in the routing table.
Implements IRoutingTable.
Definition at line 531 of file AnsaRoutingTable.cc.
Referenced by addRoute(), deleteInterfaceRoutes(), and dsdvTestAndDelete().
{
Enter_Method("deleteRoute(...)");
RouteVector::iterator i = std::find(routes.begin(), routes.end(), entry);
if (i!=routes.end())
{
nb->fireChangeNotification(NF_IPv4_ROUTE_DELETED, entry); // rather: going to be deleted
routes.erase(i);
delete entry;
invalidateCache();
updateDisplayString();
generateShowIPRoute();
return true;
}
i = std::find(multicastRoutes.begin(), multicastRoutes.end(), entry);
if (i!=multicastRoutes.end())
{
nb->fireChangeNotification(NF_IPv4_ROUTE_DELETED, entry); // rather: going to be deleted
multicastRoutes.erase(i);
delete entry;
invalidateCache();
updateDisplayString();
generateShowIPRoute();
return true;
}
generateShowIPRoute();
return false;
}
| std::string AnsaRoutingTable::directIPRouteFormat | ( | const IPRoute * | entry | ) |
Definition at line 674 of file AnsaRoutingTable.cc.
Referenced by generateShowIPRoute().
{
std::stringstream str;
if ((ipr->getSource())==IPRoute::IFACENETMASK)
str << "C ";
else
str << "S ";
str << (ipr->getHost()).str();
str << "/";
str << (ipr->getNetmask()).getNetmaskLength();
str << " is directly connected, ";
str << ipr->getInterfaceName();
return str.str();
}
| void AnsaRoutingTable::dsdvTestAndDelete | ( | ) | [virtual] |
Definition at line 329 of file AnsaRoutingTable.cc.
{
if (timetolive_routing_entry==timetolive_routing_entry.getMaxTime())
return;
for (RouteVector::iterator i=routes.begin(); i!=routes.end(); ++i)
{
IPRoute *e = *i;
if (this->isLocalAddress(e->getHost()))
continue;
if (((e->getHost()).str() != "*") && ((e->getHost()).str() != "<unspec>") && ((e->getHost()).str() != "127.0.0.1") && (simTime()-(getInstallTime()))>timetolive_routing_entry){
//EV << "Routes ends at" << routes.end() <<"\n";
deleteRoute(e);
//EV << "After deleting Routes ends at" << routes.end() <<"\n";
EV << "Deleting entry ip=" << e->getHost().str() <<"\n";
i--;
}
}
}
| const IPRoute * AnsaRoutingTable::findBestMatchingRoute | ( | const IPAddress & | dest | ) | const [virtual] |
The routing function.
Implements IRoutingTable.
Definition at line 363 of file AnsaRoutingTable.cc.
Referenced by getGatewayForDestAddr(), and getInterfaceForDestAddr().
{
Enter_Method("findBestMatchingRoute(%x)", dest.getInt()); // note: str().c_str() too slow here
RoutingCache::iterator it = routingCache.find(dest);
if (it != routingCache.end())
{
if (it->second==NULL)
{
routingCache.clear();
localAddresses.clear();
}
else if (testValidity(it->second))
{
return it->second;
}
}
// find best match (one with longest prefix)
// default route has zero prefix length, so (if exists) it'll be selected as last resort
const IPRoute *bestRoute = NULL;
uint32 longestNetmask = 0;
for (RouteVector::const_iterator i=routes.begin(); i!=routes.end(); ++i)
{
IPRoute *e = *i;
if (testValidity(e))
{
if (IPAddress::maskedAddrAreEqual(dest, e->getHost(), e->getNetmask()) && // match
(!bestRoute || e->getNetmask().getInt() > longestNetmask)) // longest so far
{
bestRoute = e;
longestNetmask = e->getNetmask().getInt();
}
}
}
if (bestRoute && bestRoute->getHost()!=dest)
{
bestRoute=NULL;
/* in this case we must find the mask must be 255.255.255.255 route */
for (RouteVector::const_iterator i=routes.begin(); i!=routes.end(); ++i)
{
IPRoute *e = *i;
if (testValidity(e))
{
if (IPAddress::maskedAddrAreEqual(dest, e->getHost(), IPAddress::ALLONES_ADDRESS) && // match
(!bestRoute || e->getNetmask().getInt()>longestNetmask)) // longest so far
{
bestRoute = e;
longestNetmask = e->getNetmask().getInt();
}
}
}
}
routingCache[dest] = bestRoute;
return bestRoute;
}
| const IPRoute * AnsaRoutingTable::findRoute | ( | const IPAddress & | target, |
| const IPAddress & | netmask, | ||
| const IPAddress & | gw, | ||
| int | metric = 0, |
||
| const char * | dev = NULL |
||
| ) | const [virtual] |
Finds the first route with the given parameters.
Implements IRoutingTable.
Definition at line 484 of file AnsaRoutingTable.cc.
{
int n = getNumRoutes();
for (int i=0; i<n; i++)
if (routeMatches(getRoute(i), target, netmask, gw, metric, dev))
return getRoute(i);
return NULL;
}
| std::vector< IPAddress > AnsaRoutingTable::gatherAddresses | ( | ) | const [virtual] |
Utility function: Returns a vector of all addresses of the node.
Implements IRoutingTable.
Definition at line 246 of file AnsaRoutingTable.cc.
{
std::vector<IPAddress> addressvector;
for (int i=0; i<ift->getNumInterfaces(); ++i)
addressvector.push_back(ift->getInterface(i)->ipv4Data()->getIPAddress());
return addressvector;
}
| void AnsaRoutingTable::generateShowIPRoute | ( | ) | [protected] |
Definition at line 641 of file AnsaRoutingTable.cc.
Referenced by addRoute(), deleteRoute(), and updateNetmaskRoutes().
{
showIPRoute.clear();
int n = getNumRoutes();
const IPRoute* ipr;
for (int i=0; i<n; i++)
{
ipr=getRoute(i);
switch (ipr->getSource())
{
case IPRoute::MANUAL:
if ((ipr->getMetric())>0)
showIPRoute.push_back(otherIPRouteFormat(ipr));
else
showIPRoute.push_back(directIPRouteFormat(ipr));
break;
case IPRoute::IFACENETMASK:
showIPRoute.push_back(directIPRouteFormat(ipr));
break;
case IPRoute::RIP:
case IPRoute::OSPF:
case IPRoute::BGP:
showIPRoute.push_back(otherIPRouteFormat(ipr));
break;
default: break;
}
}
}
| const IPRoute * AnsaRoutingTable::getDefaultRoute | ( | ) | const [virtual] |
Finds and returns the default route, or NULL if it doesn't exist
Implements IRoutingTable.
Definition at line 475 of file AnsaRoutingTable.cc.
Referenced by addRoute().
| IPAddress AnsaRoutingTable::getGatewayForDestAddr | ( | const IPAddress & | dest | ) | const [virtual] |
Convenience function based on findBestMatchingRoute().
Returns the gateway to send the destination. Returns null address if the destination is not in routing table or there is no gateway (local delivery).
Implements IRoutingTable.
Definition at line 430 of file AnsaRoutingTable.cc.
{
Enter_Method("getGatewayForDestAddr(%x)", dest.getInt()); // note: str().c_str() too slow here
const IPRoute *e = findBestMatchingRoute(dest);
return e ? e->getGateway() : IPAddress();
}
| simtime_t AnsaRoutingTable::getInstallTime | ( | ) | const [inline] |
Definition at line 158 of file AnsaRoutingTable.h.
Referenced by dsdvTestAndDelete(), and testValidity().
{return installtime;}
| InterfaceEntry * AnsaRoutingTable::getInterfaceByAddress | ( | const IPAddress & | address | ) | const [virtual] |
Returns an interface given by its address. Returns NULL if not found.
Implements IRoutingTable.
Definition at line 266 of file AnsaRoutingTable.cc.
Referenced by configureRouterId().
{
Enter_Method("getInterfaceByAddress(%x)", addr.getInt()); // note: str().c_str() too slow here
if (addr.isUnspecified())
return NULL;
for (int i=0; i<ift->getNumInterfaces(); ++i)
{
InterfaceEntry *ie = ift->getInterface(i);
if (ie->ipv4Data()->getIPAddress()==addr)
return ie;
}
return NULL;
}
| InterfaceEntry * AnsaRoutingTable::getInterfaceForDestAddr | ( | const IPAddress & | dest | ) | const [virtual] |
Convenience function based on findBestMatchingRoute().
Returns the interface Id to send the packets with dest as destination address, or -1 if destination is not in routing table.
Implements IRoutingTable.
Definition at line 422 of file AnsaRoutingTable.cc.
{
Enter_Method("getInterfaceForDestAddr(%x)", dest.getInt()); // note: str().c_str() too slow here
const IPRoute *e = findBestMatchingRoute(dest);
return e ? e->getInterface() : NULL;
}
| MulticastRoutes AnsaRoutingTable::getMulticastRoutesFor | ( | const IPAddress & | dest | ) | const [virtual] |
Returns routes for a multicast address.
Implements IRoutingTable.
Definition at line 439 of file AnsaRoutingTable.cc.
{
Enter_Method("getMulticastRoutesFor(%x)", dest.getInt()); // note: str().c_str() too slow here here
MulticastRoutes res;
res.reserve(16);
for (RouteVector::const_iterator i=multicastRoutes.begin(); i!=multicastRoutes.end(); ++i)
{
const IPRoute *e = *i;
if (IPAddress::maskedAddrAreEqual(dest, e->getHost(), e->getNetmask()))
{
MulticastRoute r;
r.interf = e->getInterface();
r.gateway = e->getGateway();
res.push_back(r);
}
}
return res;
}
| int AnsaRoutingTable::getNumRoutes | ( | ) | const [virtual] |
Returns the total number of routes (unicast, multicast, plus the default route).
Implements IRoutingTable.
Definition at line 460 of file AnsaRoutingTable.cc.
Referenced by checkRoute(), findRoute(), generateShowIPRoute(), and printRoutingTable().
{
return routes.size()+multicastRoutes.size();
}
| const IPRoute * AnsaRoutingTable::getRoute | ( | int | k | ) | const [virtual] |
Returns the kth route. The returned route cannot be modified; you must delete and re-add it instead. This rule is emphasized by returning a const pointer.
Implements IRoutingTable.
Definition at line 465 of file AnsaRoutingTable.cc.
Referenced by checkRoute(), findRoute(), generateShowIPRoute(), and printRoutingTable().
{
if (k < (int)routes.size())
return routes[k];
k -= routes.size();
if (k < (int)multicastRoutes.size())
return multicastRoutes[k];
return NULL;
}
| virtual IPAddress AnsaRoutingTable::getRouterId | ( | ) | [inline, virtual] |
Returns routerId.
Implements IRoutingTable.
Definition at line 183 of file AnsaRoutingTable.h.
{return routerId;}
| virtual simtime_t AnsaRoutingTable::getTimeToLiveRoutingEntry | ( | ) | [inline, virtual] |
Definition at line 281 of file AnsaRoutingTable.h.
{return timetolive_routing_entry;}
| void AnsaRoutingTable::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Raises an error.
Definition at line 171 of file AnsaRoutingTable.cc.
{
opp_error("This module doesn't process messages");
}
| void AnsaRoutingTable::initialize | ( | int | stage | ) | [protected, virtual] |
Definition at line 68 of file AnsaRoutingTable.cc.
{
if (stage==0)
{
// get a pointer to the NotificationBoard module and IInterfaceTable
nb = NotificationBoardAccess().get();
ift = InterfaceTableAccess().get();
IPForward = par("IPForward").boolValue();
nb->subscribe(this, NF_INTERFACE_CREATED);
nb->subscribe(this, NF_INTERFACE_DELETED);
nb->subscribe(this, NF_INTERFACE_STATE_CHANGED);
nb->subscribe(this, NF_INTERFACE_CONFIG_CHANGED);
nb->subscribe(this, NF_INTERFACE_IPv4CONFIG_CHANGED);
WATCH_VECTOR(showIPRoute); //
WATCH_PTRVECTOR(multicastRoutes);
WATCH(IPForward);
WATCH(routerId);
}
else if (stage==1)
{
// L2 modules register themselves in stage 0, so we can only configure
// the interfaces in stage 1.
const char *filename = par("configFile");
// At this point, all L2 modules have registered themselves (added their
// interface entries). Create the per-interface IPv4 data structures.
IInterfaceTable *interfaceTable = InterfaceTableAccess().get();
for (int i=0; i<interfaceTable->getNumInterfaces(); ++i)
configureInterfaceForIPv4(interfaceTable->getInterface(i));
const char *routerIdStr = par("routerId").stringValue();
// read routing table file (and interface configuration)
RoutingTableXmlParser parser(ift, this);
if (*filename && !parser.readRoutingTableFromXml(filename, routerIdStr))
error("Error reading routing table file %s", filename);
// set routerId if param is not "" (==no routerId) or "auto" (in which case we'll
// do it later in stage 3, after network configurators configured the interfaces)
if (strcmp(routerIdStr, "") && strcmp(routerIdStr, "auto"))
routerId = IPAddress(routerIdStr);
}
else if (stage==3)
{
// routerID selection must be after stage==2 when network autoconfiguration
// assigns interface addresses
configureRouterId();
// we don't use notifications during initialize(), so we do it manually.
// Should be in stage=3 because autoconfigurator runs in stage=2.
updateNetmaskRoutes();
//printRoutingTable();
}
}
| void AnsaRoutingTable::initializeAD | ( | ) | [protected] |
Definition at line 60 of file AnsaRoutingTable.cc.
Referenced by AnsaRoutingTable().
{
ADmap[IPRoute::MANUAL]=1;
ADmap[IPRoute::IFACENETMASK]=0;
ADmap[IPRoute::RIP]=120;
ADmap[IPRoute::OSPF]=110;
ADmap[IPRoute::BGP]=20;
}
| void AnsaRoutingTable::invalidateCache | ( | ) | [protected, virtual] |
Definition at line 229 of file AnsaRoutingTable.cc.
Referenced by addRoute(), deleteRoute(), receiveChangeNotification(), and updateNetmaskRoutes().
{
routingCache.clear();
localAddresses.clear();
}
| virtual bool AnsaRoutingTable::isIPForwardingEnabled | ( | ) | [inline, virtual] |
IP forwarding on/off
Implements IRoutingTable.
Definition at line 178 of file AnsaRoutingTable.h.
{return IPForward;}
| bool AnsaRoutingTable::isLocalAddress | ( | const IPAddress & | dest | ) | const [virtual] |
Checks if the address is a local one, i.e. one of the host's.
Implements IRoutingTable.
Definition at line 297 of file AnsaRoutingTable.cc.
Referenced by dsdvTestAndDelete(), and testValidity().
{
Enter_Method("isLocalAddress(%x)", dest.getInt()); // note: str().c_str() too slow here
if (localAddresses.empty())
{
// collect interface addresses if not yet done
for (int i=0; i<ift->getNumInterfaces(); i++)
{
IPAddress interfaceAddr = ift->getInterface(i)->ipv4Data()->getIPAddress();
localAddresses.insert(interfaceAddr);
}
}
AddressSet::iterator it = localAddresses.find(dest);
return it!=localAddresses.end();
}
| bool AnsaRoutingTable::isLocalMulticastAddress | ( | const IPAddress & | dest | ) | const [virtual] |
Checks if the address is in one of the local multicast group address list.
Implements IRoutingTable.
Definition at line 315 of file AnsaRoutingTable.cc.
{
Enter_Method("isLocalMulticastAddress(%x)", dest.getInt()); // note: str().c_str() too slow here
for (int i=0; i<ift->getNumInterfaces(); i++)
{
InterfaceEntry *ie = ift->getInterface(i);
for (unsigned int j=0; j < ie->ipv4Data()->getMulticastGroups().size(); j++)
if (dest.equals(ie->ipv4Data()->getMulticastGroups()[j]))
return true;
}
return false;
}
| bool AnsaRoutingTable::matchHostMask | ( | const IPRoute * | entry, |
| const IPAddress & | target, | ||
| const IPAddress & | nmask | ||
| ) | [protected] |
Definition at line 632 of file AnsaRoutingTable.cc.
Referenced by checkRoute().
{
if (!target.isUnspecified() && !target.equals(entry->getHost()))
return false;
if (!nmask.isUnspecified() && !nmask.equals(entry->getNetmask()))
return false;
return true;
}
| virtual int AnsaRoutingTable::numInitStages | ( | ) | const [inline, protected, virtual] |
Definition at line 141 of file AnsaRoutingTable.h.
{return 4;}
| std::string AnsaRoutingTable::otherIPRouteFormat | ( | const IPRoute * | entry | ) |
Definition at line 691 of file AnsaRoutingTable.cc.
Referenced by generateShowIPRoute().
{
std::stringstream str;
switch (ipr->getSource())
{
case IPRoute::RIP:
str << "R ";
break;
case IPRoute::OSPF:
str << "O ";
break;
case IPRoute::BGP:
str << "B ";
break;
case IPRoute::MANUAL:
str << "S ";
break;
default:
break;
}
str << (ipr->getHost()).str();
str << "/";
str << (ipr->getNetmask()).getNetmaskLength();
str << " [";
str << ADmap.find(ipr->getSource())->second;
str << "/";
str << ipr->getMetric();
str << "] via ";
if ((ipr->getGateway()).isUnspecified())
str << "*";
else
str << (ipr->getGateway()).str();
return str.str();
}
| void AnsaRoutingTable::printRoutingTable | ( | ) | const [virtual] |
For debugging
Implements IRoutingTable.
Definition at line 235 of file AnsaRoutingTable.cc.
{
EV << "-- Routing table --\n";
ev.printf("%-16s %-16s %-16s %-3s %s\n",
"Destination", "Gateway", "Netmask", "Iface");
for (int i=0; i<getNumRoutes(); i++)
EV << getRoute(i)->detailedInfo() << "\n";
EV << "\n";
}
| void AnsaRoutingTable::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.
Implements INotifiable.
Definition at line 176 of file AnsaRoutingTable.cc.
{
if (simulation.getContextType()==CTX_INITIALIZE)
return; // ignore notifications during initialize
Enter_Method_Silent();
printNotificationBanner(category, details);
if (category==NF_INTERFACE_CREATED)
{
// add netmask route for the new interface
updateNetmaskRoutes();
}
else if (category==NF_INTERFACE_DELETED)
{
// remove all routes that point to that interface
InterfaceEntry *entry = check_and_cast<InterfaceEntry*>(details);
deleteInterfaceRoutes(entry);
}
else if (category==NF_INTERFACE_STATE_CHANGED)
{
updateNetmaskRoutes();
}
else if (category==NF_INTERFACE_CONFIG_CHANGED)
{
invalidateCache();
}
else if (category==NF_INTERFACE_IPv4CONFIG_CHANGED)
{
// if anything IPv4-related changes in the interfaces, interface netmask
// based routes have to be re-built.
updateNetmaskRoutes();
}
}
| bool AnsaRoutingTable::routeMatches | ( | const IPRoute * | entry, |
| const IPAddress & | target, | ||
| const IPAddress & | nmask, | ||
| const IPAddress & | gw, | ||
| int | metric, | ||
| const char * | dev | ||
| ) | const [protected, virtual] |
Definition at line 562 of file AnsaRoutingTable.cc.
Referenced by findRoute().
{
if (!target.isUnspecified() && !target.equals(entry->getHost()))
return false;
if (!nmask.isUnspecified() && !nmask.equals(entry->getNetmask()))
return false;
if (!gw.isUnspecified() && !gw.equals(entry->getGateway()))
return false;
if (metric && metric!=entry->getMetric())
return false;
if (dev && strcmp(dev, entry->getInterfaceName()))
return false;
return true;
}
| void AnsaRoutingTable::setInstallTime | ( | simtime_t | time | ) | [inline] |
Definition at line 159 of file AnsaRoutingTable.h.
{installtime = time;}
| virtual void AnsaRoutingTable::setRouterId | ( | IPAddress | a | ) | [inline, virtual] |
Sets routerId.
Implements IRoutingTable.
Definition at line 188 of file AnsaRoutingTable.h.
{routerId = a;}
| virtual void AnsaRoutingTable::setTimeToLiveRoutingEntry | ( | simtime_t | a | ) | [inline, virtual] |
Definition at line 280 of file AnsaRoutingTable.h.
{timetolive_routing_entry = a;}
| const bool AnsaRoutingTable::testValidity | ( | const IPRoute * | entry | ) | const [virtual] |
Definition at line 350 of file AnsaRoutingTable.cc.
Referenced by findBestMatchingRoute().
{
if (timetolive_routing_entry==timetolive_routing_entry.getMaxTime())
return true;
if (this->isLocalAddress(entry->getHost()))
return true;
if (((entry->getHost()).str() != "*") && ((entry->getHost()).str() != "<unspec>") && ((entry->getHost()).str() != "127.0.0.1") && (simTime()-(getInstallTime()))>timetolive_routing_entry){
return false;
}
return true;
}
| void AnsaRoutingTable::updateDisplayString | ( | ) | [protected, virtual] |
Definition at line 158 of file AnsaRoutingTable.cc.
Referenced by addRoute(), deleteRoute(), and updateNetmaskRoutes().
{
if (!ev.isGUI())
return;
char buf[80];
if (routerId.isUnspecified())
sprintf(buf, "%d+%d routes", routes.size(), multicastRoutes.size());
else
sprintf(buf, "routerId: %s\n%d+%d routes", routerId.str().c_str(), routes.size(), multicastRoutes.size());
getDisplayString().setTagArg("t",0,buf);
}
| void AnsaRoutingTable::updateNetmaskRoutes | ( | ) | [protected, virtual] |
Definition at line 580 of file AnsaRoutingTable.cc.
Referenced by initialize(), and receiveChangeNotification().
{
// first, delete all routes with src=IFACENETMASK
for (unsigned int k=0; k<routes.size(); k++)
if (routes[k]->getSource()==IPRoute::IFACENETMASK)
routes.erase(routes.begin()+(k--)); // '--' is necessary because indices shift down
// then re-add them, according to actual interface configuration
for (int i=0; i<ift->getNumInterfaces(); i++)
{
InterfaceEntry *ie = ift->getInterface(i);
if (!ie->isDown())
{
if (ie->ipv4Data()->getNetmask()!=IPAddress::ALLONES_ADDRESS)
{
IPRoute *route = new IPRoute();
route->setType(IPRoute::DIRECT);
route->setSource(IPRoute::IFACENETMASK);
route->setHost((ie->ipv4Data()->getIPAddress()).doAnd(ie->ipv4Data()->getNetmask()));
route->setNetmask(ie->ipv4Data()->getNetmask());
route->setGateway(IPAddress());
route->setMetric(ie->ipv4Data()->getMetric());
route->setInterface(ie);
routes.push_back(route);
}
}
}
invalidateCache();
updateDisplayString();
generateShowIPRoute();
}
std::map<IPRoute::RouteSource,int> AnsaRoutingTable::ADmap [protected] |
Definition at line 101 of file AnsaRoutingTable.h.
Referenced by checkRoute(), initializeAD(), and otherIPRouteFormat().
IInterfaceTable* AnsaRoutingTable::ift [protected] |
Definition at line 78 of file AnsaRoutingTable.h.
Referenced by configureLoopbackForIPv4(), configureRouterId(), gatherAddresses(), getInterfaceByAddress(), initialize(), isLocalAddress(), isLocalMulticastAddress(), and updateNetmaskRoutes().
| simtime_t AnsaRoutingTable::installtime |
Definition at line 157 of file AnsaRoutingTable.h.
bool AnsaRoutingTable::IPForward [protected] |
Definition at line 82 of file AnsaRoutingTable.h.
Referenced by initialize().
AddressSet AnsaRoutingTable::localAddresses [mutable, protected] |
Definition at line 99 of file AnsaRoutingTable.h.
Referenced by findBestMatchingRoute(), invalidateCache(), and isLocalAddress().
RouteVector AnsaRoutingTable::multicastRoutes [protected] |
Definition at line 91 of file AnsaRoutingTable.h.
Referenced by addRoute(), deleteRoute(), getMulticastRoutesFor(), getNumRoutes(), getRoute(), initialize(), updateDisplayString(), and ~AnsaRoutingTable().
NotificationBoard* AnsaRoutingTable::nb [protected] |
Definition at line 79 of file AnsaRoutingTable.h.
Referenced by addRoute(), deleteRoute(), and initialize().
IPAddress AnsaRoutingTable::routerId [protected] |
Definition at line 81 of file AnsaRoutingTable.h.
Referenced by configureRouterId(), initialize(), and updateDisplayString().
RouteVector AnsaRoutingTable::routes [protected] |
Definition at line 90 of file AnsaRoutingTable.h.
Referenced by addRoute(), deleteInterfaceRoutes(), deleteRoute(), dsdvTestAndDelete(), findBestMatchingRoute(), getDefaultRoute(), getNumRoutes(), getRoute(), updateDisplayString(), updateNetmaskRoutes(), and ~AnsaRoutingTable().
RoutingCache AnsaRoutingTable::routingCache [mutable, protected] |
Definition at line 95 of file AnsaRoutingTable.h.
Referenced by findBestMatchingRoute(), and invalidateCache().
std::vector<std::string> AnsaRoutingTable::showIPRoute [protected] |
Definition at line 102 of file AnsaRoutingTable.h.
Referenced by generateShowIPRoute(), and initialize().
simtime_t AnsaRoutingTable::timetolive_routing_entry [protected] |
Definition at line 85 of file AnsaRoutingTable.h.
Referenced by AnsaRoutingTable(), dsdvTestAndDelete(), and testValidity().