FwTable Class Reference

#include <FwTable.h>

Inheritance diagram for FwTable:
cSimpleModule cModule cComponent cDefaultList cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject

List of all members.

Public Member Functions

virtual ~FwTable ()
virtual std::string getRouterId ()
virtual void setRouterId (std::string a)
virtual list< int > findMatchingRoute (string FID)
virtual int getNumRoutes ()
virtual const char * getLID (int index)
virtual const char * getInterfaceName (int index)
virtual FwRoutegetFwRoute (string LID)

Protected Types

typedef std::vector< FwRoute * > RouteVector

Protected Member Functions

virtual void initialize (int stage)
virtual int numInitStages () const
virtual void updateDisplayString ()
virtual void handleMessage (cMessage *)
virtual void configureRouterId ()
void addInterfaceRoute (InterfaceEntry *entry)
virtual void receiveChangeNotification (int category, const cPolymorphic *details)

Protected Attributes

IInterfaceTable * ift
 cached pointer
NotificationBoard * nb
 cached pointer
std::string routerId
 The ID of the Router Using this Forwarding Table.
RouteVector routes
 Unicast route array.

Detailed Description

Represents the forwarding table. This object has one instance per host or router. It has methods to manage the interface table and the interface table, so one can achieve functionality similar to the "route" and "ifconfig" commands.

See the NED documentation for general overview.


Member Typedef Documentation

typedef std::vector<FwRoute *> FwTable::RouteVector [protected]

Constructor & Destructor Documentation

FwTable::~FwTable (  )  [virtual]

Destructor of the class.

00046 {
00047     for (unsigned int i=0; i<routes.size(); i++)
00048         delete routes[i];
00049 }


Member Function Documentation

void FwTable::addInterfaceRoute ( InterfaceEntry *  entry  )  [protected]

Adds the FID for an interface.

00162 {
00163         //Go to the end of the list
00164     RouteVector::iterator it = routes.end();
00165 
00166     //Set up entry
00167     FwRoute *fwEntry = new FwRoute();
00168     string tempLID;
00169 
00170     //Create a random LID, with few 1s
00171         tempLID = "0000000000000000000000000000000000000000000000000000000000000000";
00172 
00173         //Set at least 5 1s
00174         for(int i=0;i<5;i++)
00175                 tempLID[intrand(FID_LEN*8)]='1';
00176 
00177         //And some extra...
00178         //int extra=intrand(6);
00179         //for(int i=0;i<5;i++)
00180         //      tempLID[intrand(64)]='1';
00181 
00182     fwEntry->setLID(tempLID);
00183     fwEntry->setInterface(entry);
00184     fwEntry->setMetric(intrand(100));
00185 
00186 
00187     //Push it to the route vector
00188     routes.push_back(fwEntry);
00189 
00190     //Update Display String
00191     updateDisplayString();
00192 }

void FwTable::configureRouterId (  )  [protected, virtual]

Set the Router ID

00091 {
00092         const char *routerIdStr = par("routerId").stringValue();
00093         if (!strcmp(routerIdStr, "auto"))  // non-"auto" cases already handled in stage 1
00094         {
00095                 //Put the simulation name of the parent module as the routerID
00096                 routerId = this->getParentModule()->getFullName();
00097         }
00098         else {
00099                 //Put the name specified in the configuration file as the routerID
00100                 routerId=routerIdStr;
00101         }
00102 }

list< int > FwTable::findMatchingRoute ( string  FID  )  [virtual]

The routing function.

00202 {
00203     Enter_Method("findMatchingRoute(%s)", FID.c_str()); // note: str().c_str() too slow here
00204 
00205     list<int> matchingInterfaces;
00206 
00207     if(!routes.empty()) {
00208                 for (RouteVector::const_iterator i=routes.begin(); i!=routes.end(); ++i)
00209                 {
00210                         FwRoute *e = *i;
00211                         //Make the LID and FID comparison
00212                         if (e->getLID().compare(lidAND(e->getLID(),FID))==0)
00213                         {
00214                                 matchingInterfaces.push_back(e->getInterface()->getNetworkLayerGateIndex());
00215                         }
00216                 }
00217     }
00218     else {
00219         ev << "No routes found in router " << this->getParentModule()->getFullName() << endl;
00220     }
00221 
00222     return matchingInterfaces;
00223 }

FwRoute * FwTable::getFwRoute ( string  LID  )  [virtual]

Return a pointer to the forwarding entry for the specified interface

00236                                        {
00237         for (int i=0; i<getNumRoutes(); i++) {
00238                 if(LID.compare(routes.at(i)->getLID())==0) {
00239                         return routes.at(i);
00240                 }
00241         }
00242 
00243         return NULL;
00244 }

const char * FwTable::getInterfaceName ( int  index  )  [virtual]

Get the name of a specific interface

00231                                                {
00232         return routes.at(index)->getInterfaceName();
00233 }

const char * FwTable::getLID ( int  index  )  [virtual]

Return the LID of a specified link.

00226                                      {
00227         return routes.at(index)->getLID().c_str();
00228 }

int FwTable::getNumRoutes (  )  [virtual]

Returns the total number of routes (unicast only, unlike IP)

00196 {
00197     return routes.size();
00198 }

virtual std::string FwTable::getRouterId (  )  [inline, virtual]

Forwarding on/off Returns routerId.

00111 {return routerId;}

void FwTable::handleMessage ( cMessage msg  )  [protected, virtual]

Raises an error.

Reimplemented from cSimpleModule.

00120 {
00121     opp_error("This module doesn't process messages");
00122 }

void FwTable::initialize ( int  stage  )  [protected, virtual]

Initialization of the Forwarding Table module

Reimplemented from cComponent.

00053 {
00054     if (stage==0)
00055     {
00056         // used for the random generator
00057         srand ( time(NULL) );
00058 
00059         // get a pointer to the NotificationBoard module and IInterfaceTable
00060         nb = NotificationBoardAccess().get();
00061         ift = InterfaceTableAccess().get();
00062 
00063         configureRouterId();
00064 
00065         nb->subscribe(this, NF_INTERFACE_CREATED);
00066         nb->subscribe(this, NF_INTERFACE_DELETED);
00067         nb->subscribe(this, NF_INTERFACE_STATE_CHANGED);
00068         nb->subscribe(this, NF_INTERFACE_CONFIG_CHANGED);
00069         nb->subscribe(this, NF_INTERFACE_IPv4CONFIG_CHANGED);
00070 
00071         WATCH_PTRVECTOR(routes);
00072         WATCH(routerId);
00073     }
00074    if (stage==1)
00075     {
00076            // L2 modules register themselves in stage 0, so we can only configure
00077        // the interfaces in stage 1.
00078            IInterfaceTable *interfaceTable = InterfaceTableAccess().get();
00079            for (int i=1; i<interfaceTable->getNumInterfaces(); i++) {
00080                    //Create a new entry for each interface
00081                    addInterfaceRoute(interfaceTable->getInterface(i));
00082 
00083                    ev << "Adding forwarding route for interface ";
00084                    ev << (interfaceTable->getInterface(i)->getName()[0] ? interfaceTable->getInterface(i)->getName() : "*") << endl;
00085            }
00086     }
00087 }

virtual int FwTable::numInitStages (  )  const [inline, protected, virtual]

Returns the number of initialization stages.

Reimplemented from cComponent.

00074 {return 4;}

void FwTable::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.

00126 {
00127     if (simulation.getContextType()==CTX_INITIALIZE)
00128         return;  // ignore notifications during initialize
00129 
00130     Enter_Method_Silent();
00131     printNotificationBanner(category, details);
00132 
00133     if (category==NF_INTERFACE_CREATED)
00134     {
00135         // add netmask route for the new interface
00136         //updateNetmaskRoutes();
00137     }
00138     else if (category==NF_INTERFACE_DELETED)
00139     {
00140         // remove all routes that point to that interface
00141         //InterfaceEntry *entry = check_and_cast<InterfaceEntry*>(details);
00142         //deleteInterfaceRoutes(entry);
00143     }
00144     else if (category==NF_INTERFACE_STATE_CHANGED)
00145     {
00146         //invalidateCache();
00147     }
00148     else if (category==NF_INTERFACE_CONFIG_CHANGED)
00149     {
00150         //invalidateCache();
00151     }
00152     else if (category==NF_INTERFACE_IPv4CONFIG_CHANGED)
00153     {
00154         // if anything IPv4-related changes in the interfaces, interface netmask
00155         // based routes have to be re-built.
00156         //updateNetmaskRoutes();
00157     }
00158 }

virtual void FwTable::setRouterId ( std::string  a  )  [inline, virtual]

Sets routerId.

00116 {routerId = a;}

void FwTable::updateDisplayString (  )  [protected, virtual]

Displays summary above the icon.

00106 {
00107     if (!ev.isGUI())
00108         return;
00109 
00110     char buf[80];
00111     if (routerId.empty())
00112         sprintf(buf, "%d routes", (int)routes.size());
00113     else
00114         sprintf(buf, "routerId: %s\n%d routes", routerId.c_str(), (int)routes.size());
00115     getDisplayString().setTagArg("t",0,buf);
00116 }


Member Data Documentation

IInterfaceTable* FwTable::ift [protected]

cached pointer

NotificationBoard* FwTable::nb [protected]

cached pointer

std::string FwTable::routerId [protected]

The ID of the Router Using this Forwarding Table.

Unicast route array.


The documentation for this class was generated from the following files:
Generated on Thu Jun 14 17:12:42 2012 for PAL by  doxygen 1.6.3