![]() |
Multicast Routing Modelling In OMNeT++
|
Class represent multicast routing table. More...
#include <MulticastRoutingTable.h>
Public Member Functions | |
void | generateShowIPMroute () |
virtual void | printRoutingTable () const |
virtual std::vector < MulticastIPRoute * > | getRouteFor (IPAddress group) |
virtual MulticastIPRoute * | getRouteFor (IPAddress group, IPAddress source) |
virtual std::vector < MulticastIPRoute * > | getRoutesForSource (IPAddress source) |
virtual int | getNumRoutes () const |
virtual MulticastIPRoute * | getRoute (int k) const |
virtual const MulticastIPRoute * | findRoute (const IPAddress &source, const IPAddress &group, const IPAddress &RP, int intId, const IPAddress &nextHop) const |
virtual void | addRoute (const MulticastIPRoute *entry) |
virtual bool | deleteRoute (const MulticastIPRoute *entry) |
virtual | ~MulticastRoutingTable () |
Protected Member Functions | |
virtual bool | routeMatches (const MulticastIPRoute *entry, const IPAddress &source, const IPAddress &group, const IPAddress &RP, int intId, const IPAddress &nextHop) const |
virtual void | updateDisplayString () |
virtual int | numInitStages () const |
virtual void | initialize (int stage) |
virtual void | handleMessage (cMessage *) |
Protected Attributes | |
RouteVector | multicastRoutes |
std::vector< std::string > | showMRoute |
IInterfaceTable * | ift |
Class represent multicast routing table.
It contains entries = routes for each multicast source and group. There are methods to get right route from table, add new route, delete old on, etc.
Definition at line 29 of file MulticastRoutingTable.h.
MulticastRoutingTable::~MulticastRoutingTable | ( | ) | [virtual] |
MULTICAST ROUTING TABLE DESTRUCTOR
The method deletes Multicast Routing Table. Delete all entries in table.
Definition at line 25 of file MulticastRoutingTable.cc.
{ for (unsigned int i=0; i<multicastRoutes.size(); i++) delete multicastRoutes[i]; }
bool MulticastRoutingTable::routeMatches | ( | const MulticastIPRoute * | entry, |
const IPAddress & | source, | ||
const IPAddress & | group, | ||
const IPAddress & | RP, | ||
int | intId, | ||
const IPAddress & | nextHop | ||
) | const [protected, virtual] |
ROUTE MATCHES
Finds a match between route entry and given parameters.
entry | Link to route. |
source | IP address of multicast source. |
group | IP address of multicast group. |
RP | IP address of RP router. |
intId | ID of incoming (RPF) interface. |
nextHop | IP address of RPF neighbor. |
Definition at line 152 of file MulticastRoutingTable.cc.
{ if (!source.isUnspecified() && !source.equals(entry->getSource())) return false; if (!group.isUnspecified() && !group.equals(entry->getGroup())) return false; if (!RP.isUnspecified() && !RP.equals(entry->getRP())) return false; if (intId!=entry->getInIntId()) return false; if (!nextHop.isUnspecified() && !nextHop.equals(entry->getInIntNextHop())) return false; return true; }
void MulticastRoutingTable::updateDisplayString | ( | ) | [protected, virtual] |
UPDATE DISPLAY STRING
Update string under multicast table icon - number of multicast routes.
Definition at line 56 of file MulticastRoutingTable.cc.
{ if (!ev.isGUI()) return; char buf[80]; sprintf(buf, "%d routes", multicastRoutes.size()); getDisplayString().setTagArg("t",0,buf); }
GENERATE SHOW IP MROUTE
This method should be called after each change of multicast routing table. It is output which represents state of the table. Format is same as format on Cisco routers.
Definition at line 364 of file MulticastRoutingTable.cc.
{ EV << "MulticastRoutingTable::generateShowIPRoute()" << endl; showMRoute.clear(); int n = getNumRoutes(); const MulticastIPRoute* ipr; for (int i=0; i<n; i++) { ipr = getRoute(i); stringstream os; os << "("; if (ipr->getSource().isUnspecified()) os << "*, "; else os << ipr->getSource() << ", "; os << ipr->getGroup() << "), "; if (!ipr->getRP().isUnspecified()) os << "RP is " << ipr->getRP()<< ", "; os << "flags: "; vector<flag> flags = ipr->getFlags(); for (unsigned int j = 0; j < flags.size(); j++) { EV << "MulticastRoutingTable::generateShowIPRoute(): Flag = " << flags[j] << endl; switch(flags[j]) { case D: os << "D"; break; case S: os << "S"; break; case C: os << "C"; break; case P: os << "P"; break; case A: os << "A"; break; } } os << endl; os << "Incoming interface: "; if (ipr->getInIntPtr()) os << ipr->getInIntPtr()->getName() << ", "; os << "RPF neighbor " << ipr->getInIntNextHop() << endl; os << "Outgoing interface list:" << endl; InterfaceVector all = ipr->getOutInt(); if (all.size() == 0) os << "Null" << endl; else for (unsigned int k = 0; k < all.size(); k++) { os << all[k].intPtr->getName() << ", "; if (all[k].forwarding == Forward) os << "Forward/"; else os << "Pruned/"; if (all[k].mode == Densemode) os << "Dense"; else os << "Sparse"; os << endl; } showMRoute.push_back(os.str()); } stringstream out; }
void MulticastRoutingTable::printRoutingTable | ( | ) | const [virtual] |
PRINT ROUTING TABLE
Can be used for debugging purposes.
Definition at line 71 of file MulticastRoutingTable.cc.
{ EV << "-- Multicast routing table --\n"; for (int i=0; i<getNumRoutes(); i++) EV << getRoute(i)->detailedInfo() << "\n"; EV << "\n"; }
vector< MulticastIPRoute * > MulticastRoutingTable::getRouteFor | ( | IPAddress | group | ) | [virtual] |
GET ROUTE FOR
The method returns all routes from multicast routing table for given multicast group.
group | IP address of multicast group. |
Definition at line 178 of file MulticastRoutingTable.cc.
{ Enter_Method("getMulticastRoutesFor(%x)", group.getInt()); // note: str().c_str() too slow here here EV << "MulticastRoutingTable::getRouteFor - address = " << group << endl; vector<MulticastIPRoute*> routes; // search in multicast table int n = multicastRoutes.size(); for (int i = 0; i < n; i++) { MulticastIPRoute *route = getRoute(i); if (route->getGroup().getInt() == group.getInt()) routes.push_back(route); } return routes; }
MulticastIPRoute * MulticastRoutingTable::getRouteFor | ( | IPAddress | group, |
IPAddress | source | ||
) | [virtual] |
GET ROUTE FOR
The method returns one route from multicast routing table for given group and source IP addresses.
group | IP address of multicast group. |
source | IP address of multicast source. |
Definition at line 207 of file MulticastRoutingTable.cc.
{ Enter_Method("getMulticastRoutesFor(%x, %x)", group.getInt(), source.getInt()); // note: str().c_str() too slow here here EV << "MulticastRoutingTable::getRouteFor - group = " << group << ", source = " << source << endl; // search in multicast routing table MulticastIPRoute *route = NULL; int n = multicastRoutes.size(); int i; // go through all multicast routes for (i = 0; i < n; i++) { route = getRoute(i); if (route->getGroup().getInt() == group.getInt() && route->getSource().getInt() == source.getInt()) break; } if (i == n) return NULL; return route; }
std::vector< MulticastIPRoute * > MulticastRoutingTable::getRoutesForSource | ( | IPAddress | source | ) | [virtual] |
GET ROUTES FOR SOURCES
The method returns all routes from multicast routing table for given source.
source | IP address of multicast source. |
Definition at line 238 of file MulticastRoutingTable.cc.
{ Enter_Method("getRoutesForSource(%x)", source.getInt()); // note: str().c_str() too slow here here EV << "MulticastRoutingTable::getRoutesForSource - source = " << source << endl; vector<MulticastIPRoute*> routes; // search in multicast table int n = multicastRoutes.size(); int i; for (i = 0; i < n; i++) { //FIXME works only for classfull adresses (function getNetwork) !!!! MulticastIPRoute *route = getRoute(i); if (route->getSource().getNetwork().getInt() == source.getInt()) routes.push_back(route); } return routes; }
int MulticastRoutingTable::getNumRoutes | ( | ) | const [virtual] |
GET NUMBER OF ROUTES
Returns number of entries in multicast routing table.
Definition at line 119 of file MulticastRoutingTable.cc.
{ return multicastRoutes.size(); }
MulticastIPRoute * MulticastRoutingTable::getRoute | ( | int | k | ) | const [virtual] |
GET ROUTE
Returns the k-th route. The returned route cannot be modified; you must delete and re-add it instead. This rule is emphasized by returning a const pointer.
Definition at line 131 of file MulticastRoutingTable.cc.
{ if (k < (int)multicastRoutes.size()) return multicastRoutes[k]; return NULL; }
const MulticastIPRoute * MulticastRoutingTable::findRoute | ( | const IPAddress & | source, |
const IPAddress & | group, | ||
const IPAddress & | RP, | ||
int | intId, | ||
const IPAddress & | nextHop | ||
) | const [virtual] |
FIND ROUTE
Finds route according to given parameters (source, group, RP, ID and next hop of incoming int).
source | IP address of multicast source. |
group | IP address of multicast group. |
RP | IP address of RP router. |
intId | ID of incoming (RPF) interface. |
nextHop | IP address of RPF neighbor. |
Definition at line 104 of file MulticastRoutingTable.cc.
{ int n = getNumRoutes(); for (int i=0; i<n; i++) if (routeMatches(getRoute(i), source, group, RP, intId, nextHop)) return getRoute(i); return NULL; }
void MulticastRoutingTable::addRoute | ( | const MulticastIPRoute * | entry | ) | [virtual] |
ADD ROUTE
Function check new multicast table entry and then add new entry to multicast table.
entry | New entry about new multicast group. |
Definition at line 267 of file MulticastRoutingTable.cc.
{ Enter_Method("addMulticastRoute(...)"); // check for null multicast group address if (entry->getGroup().isUnspecified()) error("addMulticastRoute(): multicast group address cannot be NULL"); // check that group address is multicast address if (!entry->getGroup().isMulticast()) error("addMulticastRoute(): group address is not multicast address"); // check for source or RP address if (entry->getSource().isUnspecified() && entry->getRP().isUnspecified()) error("addMulticastRoute(): source or RP address has to be specified"); // check that the incoming interface exists if (!entry->getInIntPtr() || entry->getInIntNextHop().isUnspecified()) error("addMulticastRoute(): incoming interface has to be specified"); // add to tables multicastRoutes.push_back(const_cast<MulticastIPRoute*>(entry)); updateDisplayString(); generateShowIPMroute(); }
bool MulticastRoutingTable::deleteRoute | ( | const MulticastIPRoute * | entry | ) | [virtual] |
DELETE ROUTE
Function check new multicast table entry and then add new entry to multicast table.
entry | Multicast entry which should be deleted from multicast table. |
Definition at line 305 of file MulticastRoutingTable.cc.
{ Enter_Method("deleteMulticastRoute(...)"); // find entry in routing table vector<MulticastIPRoute*>::iterator i; for (i=multicastRoutes.begin(); i!=multicastRoutes.end(); ++i) { if ((*i) == entry) break; } // if entry was found, it can be deleted if (i!=multicastRoutes.end()) { // first delete all timers assigned to route if (entry->getSrt() != NULL) { cancelEvent(entry->getSrt()); delete entry->getSrt(); } if (entry->getGrt() != NULL) { cancelEvent(entry->getGrt()); delete entry->getGrt(); } if (entry->getSat()) { cancelEvent(entry->getSat()); delete entry->getSat(); } // delete timers from outgoing interfaces InterfaceVector outInt = entry->getOutInt(); for (unsigned int j = 0;j < outInt.size(); j++) { if (outInt[j].pruneTimer != NULL) { cancelEvent(outInt[j].pruneTimer); delete outInt[j].pruneTimer; } } // delete route multicastRoutes.erase(i); delete entry; updateDisplayString(); generateShowIPMroute(); return true; } return false; }
void MulticastRoutingTable::initialize | ( | int | stage | ) | [protected, virtual] |
INITIALIZE
The method initializes Multicast Routing Table module. It get access to all needed objects.
stage | Stage of initialization. |
Definition at line 38 of file MulticastRoutingTable.cc.
{ if (stage==0) { // get a pointer to IInterfaceTable ift = AnsaInterfaceTableAccess().get(); // watch multicast table //WATCH_PTRVECTOR(multicastRoutes); WATCH_VECTOR(showMRoute); } }
void MulticastRoutingTable::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
HANDLE MESSAGE
Module does not have any gate, it cannot get messages.
Definition at line 84 of file MulticastRoutingTable.cc.
{
opp_error("This module doesn't process messages");
}
RouteVector MulticastRoutingTable::multicastRoutes [protected] |
Multicast routing table.
Definition at line 32 of file MulticastRoutingTable.h.
std::vector<std::string> MulticastRoutingTable::showMRoute [protected] |
Output of multicast routing table, same as Cisco mroute.
Definition at line 33 of file MulticastRoutingTable.h.
IInterfaceTable* MulticastRoutingTable::ift [protected] |
Pointer to interface table.
Definition at line 34 of file MulticastRoutingTable.h.