00001 // 00002 // Copyright (C) 2005 Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef __INET_INTERFACEENTRY_H 00019 #define __INET_INTERFACEENTRY_H 00020 00021 #include <vector> 00022 #include <omnetpp.h> 00023 #include "INETDefs.h" 00024 #include "MACAddress.h" 00025 #include "InterfaceToken.h" 00026 #include "NotifierConsts.h" 00027 00028 00029 // Forward declarations. Do NOT #include the corresponding header files 00030 // since that would create dependence on IPv4 and IPv6 stuff! 00031 class IInterfaceTable; 00032 class InterfaceEntry; 00033 class InterfaceProtocolData; 00034 class IPv4InterfaceData; 00035 class IPv6InterfaceData; 00036 00041 class INET_API InterfaceProtocolData : public cPolymorphic 00042 { 00043 friend class InterfaceEntry; //only this guy is allowed to set ownerp 00044 00045 protected: 00046 InterfaceEntry *ownerp; // the interface entry this object belongs to 00047 00048 protected: 00049 // fires notification with the given category, and the interface entry as details 00050 virtual void changed(int category); 00051 00052 public: 00053 InterfaceProtocolData() {ownerp = NULL;} 00054 00058 InterfaceEntry *getInterfaceEntry() const {return ownerp;} 00059 }; 00060 00061 00067 class INET_API InterfaceEntry : public cNamedObject 00068 { 00069 friend class InterfaceProtocolData; // to call protocolDataChanged() 00070 protected: 00071 IInterfaceTable *ownerp; 00072 int interfaceId; 00073 int nwLayerGateIndex; 00074 int nodeOutputGateId; 00075 int nodeInputGateId; 00076 int peernamid; 00077 int mtu; 00078 bool down; 00079 bool broadcast; 00080 bool multicast; 00081 bool pointToPoint; 00082 bool loopback; 00083 double datarate; 00084 MACAddress macAddr; 00085 InterfaceToken token; 00086 00087 IPv4InterfaceData *ipv4data; 00088 IPv6InterfaceData *ipv6data; 00089 InterfaceProtocolData *protocol3data; 00090 InterfaceProtocolData *protocol4data; 00091 00092 private: 00093 // copying not supported: following are private and also left undefined 00094 InterfaceEntry(const InterfaceEntry& obj); 00095 InterfaceEntry& operator=(const InterfaceEntry& obj); 00096 00097 protected: 00098 // change notifications 00099 virtual void configChanged() {changed(NF_INTERFACE_CONFIG_CHANGED);} 00100 virtual void stateChanged() {changed(NF_INTERFACE_STATE_CHANGED);} 00101 virtual void changed(int category); 00102 00103 public: 00104 // internal: to be invoked from InterfaceTable only! 00105 virtual void setInterfaceTable(IInterfaceTable *t) {ownerp = t;} 00106 virtual void setInterfaceId(int id) {interfaceId = id;} 00107 00108 public: 00109 InterfaceEntry(); 00110 virtual ~InterfaceEntry() {} 00111 virtual std::string info() const; 00112 virtual std::string detailedInfo() const; 00113 00117 IInterfaceTable *getInterfaceTable() const {return ownerp;} 00118 00121 int getInterfaceId() const {return interfaceId;} 00122 int getNetworkLayerGateIndex() const {return nwLayerGateIndex;} 00123 int getNodeOutputGateId() const {return nodeOutputGateId;} 00124 int getNodeInputGateId() const {return nodeInputGateId;} 00125 int getPeerNamId() const {return peernamid;} 00126 int getMTU() const {return mtu;} 00127 bool isDown() const {return down;} 00128 bool isBroadcast() const {return broadcast;} 00129 bool isMulticast() const {return multicast;} 00130 bool isPointToPoint() const {return pointToPoint;} 00131 bool isLoopback() const {return loopback;} 00132 double getDatarate() const {return datarate;} 00133 const MACAddress& getMacAddress() const {return macAddr;} 00134 const InterfaceToken& getInterfaceToken() const {return token;} 00136 00139 virtual void setName(const char *s) {cNamedObject::setName(s); configChanged();} 00140 virtual void setNetworkLayerGateIndex(int i) {nwLayerGateIndex = i; configChanged();} 00141 virtual void setNodeOutputGateId(int i) {nodeOutputGateId = i; configChanged();} 00142 virtual void setNodeInputGateId(int i) {nodeInputGateId = i; configChanged();} 00143 virtual void setPeerNamId(int ni) {peernamid = ni; configChanged();} 00144 virtual void setMtu(int m) {mtu = m; configChanged();} 00145 virtual void setDown(bool b) {down = b; stateChanged();} 00146 virtual void setBroadcast(bool b) {broadcast = b; configChanged();} 00147 virtual void setMulticast(bool b) {multicast = b; configChanged();} 00148 virtual void setPointToPoint(bool b) {pointToPoint = b; configChanged();} 00149 virtual void setLoopback(bool b) {loopback = b; configChanged();} 00150 virtual void setDatarate(double d) {datarate = d; configChanged();} 00151 virtual void setMACAddress(const MACAddress& addr) {macAddr = addr; configChanged();} 00152 virtual void setInterfaceToken(const InterfaceToken& t) {token = t; configChanged();} 00154 00157 IPv4InterfaceData *ipv4Data() {return ipv4data;} 00158 IPv6InterfaceData *ipv6Data() {return ipv6data;} 00159 InterfaceProtocolData *getProtocol3Data() {return protocol3data;} 00160 InterfaceProtocolData *getProtocol4Data() {return protocol4data;} 00162 00165 virtual void setIPv4Data(IPv4InterfaceData *p); 00166 virtual void setIPv6Data(IPv6InterfaceData *p); 00167 virtual void setProtocol3Data(InterfaceProtocolData *p) {protocol3data = p; configChanged();} 00168 virtual void setProtocol4Data(InterfaceProtocolData *p) {protocol4data = p; configChanged();} 00170 }; 00171 00172 #endif 00173