#include <InterfaceTable.h>
Inheritance diagram for InterfaceTable:

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.
Public Member Functions | |
| InterfaceTable () | |
| virtual | ~InterfaceTable () |
| virtual void | receiveChangeNotification (int category, cPolymorphic *details) |
| void | addInterface (InterfaceEntry *entry, cModule *ifmod) |
| int | numInterfaces () |
| InterfaceEntry * | interfaceAt (int pos) |
| InterfaceEntry * | interfaceByNodeOutputGateId (int id) |
| InterfaceEntry * | interfaceByNodeInputGateId (int id) |
| InterfaceEntry * | interfaceByNetworkLayerGateIndex (int index) |
| InterfaceEntry * | interfaceByName (const char *name) |
| InterfaceEntry * | firstLoopbackInterface () |
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 | |
| NotificationBoard * | nb |
| InterfaceVector | interfaces |
|
|
|
|
|
00041 {
00042 }
|
|
|
00045 {
00046 for (unsigned int i=0; i<interfaces.size(); i++)
00047 delete interfaces[i];
00048 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
|
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 }
|
|
|
Raises an error. 00082 {
00083 opp_error("This module doesn't process messages");
00084 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
00071 {return 2;}
|
|
|
Returns the number of interfaces. 00101 {return interfaces.size();}
|
|
||||||||||||
|
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 }
|
|
|
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 }
|
|
|
|
|
|
|
1.4.0