Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

InterfaceTable Class Reference

#include <InterfaceTable.h>

Inheritance diagram for InterfaceTable:

INotifiable List of all members.

Detailed Description

Represents the interface table. This object has one instance per host or router. It has methods to manage the interface table, so one can access functionality similar to the "ifconfig" command.

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.

Interfaces are dynamically registered: at the start of the simulation, every L2 module adds its own InterfaceEntry to the table; after that, IPv4's RoutingTable and IPv6's RoutingTable6 (an possibly, further L3 protocols) add protocol-specific data on each InterfaceEntry (see IPv4InterfaceData, IPv6InterfaceData, and InterfaceEntry::setIPv4Data(), InterfaceEntry::setIPv6Data())

Interfaces are represented by InterfaceEntry objects.

See also:
InterfaceEntry


Public Member Functions

 InterfaceTable ()
virtual ~InterfaceTable ()
virtual void receiveChangeNotification (int category, cPolymorphic *details)
void addInterface (InterfaceEntry *entry, cModule *ifmod)
int numInterfaces ()
InterfaceEntryinterfaceAt (int pos)
InterfaceEntryinterfaceByNodeOutputGateId (int id)
InterfaceEntryinterfaceByNodeInputGateId (int id)
InterfaceEntryinterfaceByNetworkLayerGateIndex (int index)
InterfaceEntryinterfaceByName (const char *name)
InterfaceEntryfirstLoopbackInterface ()

Protected Member Functions

void updateDisplayString ()
void discoverConnectingGates (InterfaceEntry *entry, cModule *ifmod)
int numInitStages () const
void initialize (int stage)
void handleMessage (cMessage *)

Private Types

typedef std::vector< InterfaceEntry * > InterfaceVector

Private Attributes

NotificationBoardnb
InterfaceVector interfaces


Member Typedef Documentation

typedef std::vector<InterfaceEntry *> InterfaceTable::InterfaceVector [private]
 


Constructor & Destructor Documentation

InterfaceTable::InterfaceTable  ) 
 

00041 {
00042 }

InterfaceTable::~InterfaceTable  )  [virtual]
 

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


Member Function Documentation

void InterfaceTable::addInterface InterfaceEntry entry,
cModule *  ifmod
 

Adds an interface. The second argument should be a module which belongs to the physical interface (e.g. PPP or EtherMac) -- it will be used to discover and fill in networkLayerGateIndex(), nodeOutputGateId(), and nodeInputGateId() in InterfaceEntry. It should be NULL if this is a virtual interface (e.g. loopback).

Note: Interface deletion is not supported, but one can mark one as "down".

00105 {
00106     // check name is unique
00107     if (interfaceByName(entry->name())!=NULL)
00108         opp_error("addInterface(): interface '%s' already registered", entry->name());
00109 
00110     // insert
00111     entry->_interfaceId = interfaces.size();
00112     interfaces.push_back(entry);
00113 
00114     // fill in networkLayerGateIndex, nodeOutputGateId, nodeInputGateId
00115     if (ifmod)
00116         discoverConnectingGates(entry, ifmod);
00117 }

void InterfaceTable::discoverConnectingGates InterfaceEntry entry,
cModule *  ifmod
[protected]
 

00120 {
00121     // ifmod is something like "host.eth[1].mac"; climb up to find "host.eth[1]" from it
00122     cModule *host = parentModule();
00123     while (ifmod && ifmod->parentModule()!=host)
00124         ifmod = ifmod->parentModule();
00125     if (!ifmod)
00126         opp_error("addInterface(): specified module is not in this host/router");
00127 
00128     // find gates connected to host / network layer
00129     cGate *nwlayerInGate=NULL, *nwlayerOutGate=NULL;
00130     for (int i=0; i<ifmod->gates(); i++)
00131     {
00132         cGate *g = ifmod->gate(i);
00133         if (!g) continue;
00134 
00135         // find the host/router's gates that internally connect to this interface
00136         if (g->type()=='O' && g->toGate() && g->toGate()->ownerModule()==host)
00137             entry->setNodeOutputGateId(g->toGate()->id());
00138         if (g->type()=='I' && g->fromGate() && g->fromGate()->ownerModule()==host)
00139             entry->setNodeInputGateId(g->fromGate()->id());
00140 
00141         // find the gate index of networkLayer/networkLayer6/mpls that connects to this interface
00142         if (g->type()=='O' && g->toGate() && g->toGate()->isName("ifIn"))
00143             nwlayerInGate = g->toGate();
00144         if (g->type()=='I' && g->fromGate() && g->fromGate()->isName("ifOut"))
00145             nwlayerOutGate = g->fromGate();
00146     }
00147 
00148     // consistency checks
00149     // note: we don't check nodeOutputGateId/nodeInputGateId, because wireless interfaces
00150     // are not connected to the host
00151     if (!nwlayerInGate || !nwlayerOutGate || nwlayerInGate->index()!=nwlayerOutGate->index())
00152         opp_error("addInterface(): interface must be connected to network layer's ifIn[]/ifOut[] gates of the same index");
00153     entry->setNetworkLayerGateIndex(nwlayerInGate->index());
00154 }

InterfaceEntry * InterfaceTable::firstLoopbackInterface  ) 
 

Returns the first interface with the isLoopback flag set. (If there's no loopback, it returns NULL -- but this should never happen because InterfaceTable itself registers a loopback interface on startup.)

00213 {
00214     Enter_Method_Silent();
00215 
00216     for (InterfaceVector::iterator i=interfaces.begin(); i!=interfaces.end(); ++i)
00217         if ((*i)->isLoopback())
00218             return *i;
00219     return NULL;
00220 }

void InterfaceTable::handleMessage cMessage *   )  [protected]
 

Raises an error.

00082 {
00083     opp_error("This module doesn't process messages");
00084 }

void InterfaceTable::initialize int  stage  )  [protected]
 

00051 {
00052     if (stage==0)
00053     {
00054         // get a pointer to the NotificationBoard module
00055         nb = NotificationBoardAccess().get();
00056 
00057         // register a loopback interface
00058         InterfaceEntry *ie = new InterfaceEntry();
00059         ie->setName("lo0");
00060         ie->setMtu(3924);
00061         ie->setLoopback(true);
00062         addInterface(ie, NULL);
00063     }
00064     else if (stage==1)
00065     {
00066         WATCH_PTRVECTOR(interfaces);
00067         updateDisplayString();
00068     }
00069 }

InterfaceEntry * InterfaceTable::interfaceAt int  pos  ) 
 

Returns the InterfaceEntry specified by an index 0..numInterfaces-1.

00096 {
00097     if (pos==-1) // -1 is commonly used as "none"
00098         return NULL;
00099     if (pos<0 || pos>=(int)interfaces.size())
00100         opp_error("interfaceAt(): nonexistent interface %d", pos);
00101     return interfaces[pos];
00102 }

InterfaceEntry * InterfaceTable::interfaceByName const char *  name  ) 
 

Returns an interface given by its name. Returns NULL if not found.

00201 {
00202     Enter_Method_Silent();
00203 
00204     if (!name)
00205         return NULL;
00206     for (InterfaceVector::iterator i=interfaces.begin(); i!=interfaces.end(); ++i)
00207         if (!strcmp(name, (*i)->name()))
00208             return *i;
00209     return NULL;
00210 }

InterfaceEntry * InterfaceTable::interfaceByNetworkLayerGateIndex int  index  ) 
 

Returns an interface given by its networkLayerGateIndex(). Returns NULL if not found.

00191 {
00192     // linear search is OK because normally we have don't have many interfaces and this func is rarely called
00193     Enter_Method_Silent();
00194     for (InterfaceVector::iterator i=interfaces.begin(); i!=interfaces.end(); ++i)
00195         if ((*i)->networkLayerGateIndex()==index)
00196             return *i;
00197     return NULL;
00198 }

InterfaceEntry * InterfaceTable::interfaceByNodeInputGateId int  id  ) 
 

Returns an interface given by its nodeInputGateId(). Returns NULL if not found.

00181 {
00182     // linear search is OK because normally we have don't have many interfaces and this func is rarely called
00183     Enter_Method_Silent();
00184     for (InterfaceVector::iterator i=interfaces.begin(); i!=interfaces.end(); ++i)
00185         if ((*i)->nodeInputGateId()==id)
00186             return *i;
00187     return NULL;
00188 }

InterfaceEntry * InterfaceTable::interfaceByNodeOutputGateId int  id  ) 
 

Returns an interface given by its nodeOutputGateId(). Returns NULL if not found.

00171 {
00172     // linear search is OK because normally we have don't have many interfaces and this func is rarely called
00173     Enter_Method_Silent();
00174     for (InterfaceVector::iterator i=interfaces.begin(); i!=interfaces.end(); ++i)
00175         if ((*i)->nodeOutputGateId()==id)
00176             return *i;
00177     return NULL;
00178 }

int InterfaceTable::numInitStages  )  const [inline, protected]
 

00071 {return 2;}

int InterfaceTable::numInterfaces  )  [inline]
 

Returns the number of interfaces.

00101 {return interfaces.size();}

void InterfaceTable::receiveChangeNotification int  category,
cPolymorphic *  details
[virtual]
 

Called by the NotificationBoard whenever a change of a category occurs to which this client has subscribed.

Implements INotifiable.

00087 {
00088     // nothing needed here at the moment
00089     Enter_Method_Silent();
00090     printNotificationBanner(category, details);
00091 }

void InterfaceTable::updateDisplayString  )  [protected]
 

00072 {
00073     if (!ev.isGUI())
00074         return;
00075 
00076     char buf[80];
00077     sprintf(buf, "%d interfaces", interfaces.size());
00078     displayString().setTagArg("t",0,buf);
00079 }


Member Data Documentation

InterfaceVector InterfaceTable::interfaces [private]
 

NotificationBoard* InterfaceTable::nb [private]
 


The documentation for this class was generated from the following files:
Generated on Thu Oct 19 18:22:24 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.0