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 00019 #include <stdio.h> 00020 #include <stdlib.h> 00021 #include <string.h> 00022 #include <ctype.h> 00023 #include <algorithm> 00024 #include <sstream> 00025 00026 #include "InterfaceEntry.h" 00027 #include "IInterfaceTable.h" 00028 00029 #ifndef WITHOUT_IPv4 00030 #include "IPv4InterfaceData.h" 00031 #endif 00032 00033 #ifndef WITHOUT_IPv6 00034 #include "IPv6InterfaceData.h" 00035 #endif 00036 00037 00038 void InterfaceProtocolData::changed(int category) 00039 { 00040 // notify the containing InterfaceEntry that something changed 00041 if (ownerp) 00042 ownerp->changed(category); 00043 } 00044 00045 00046 InterfaceEntry::InterfaceEntry() 00047 { 00048 ownerp = NULL; 00049 00050 nwLayerGateIndex = -1; 00051 nodeOutputGateId = -1; 00052 nodeInputGateId = -1; 00053 peernamid = -1; 00054 00055 mtu = 0; 00056 00057 down = false; 00058 broadcast = false; 00059 multicast = false; 00060 pointToPoint= false; 00061 loopback = false; 00062 datarate = 0; 00063 00064 ipv4data = NULL; 00065 ipv6data = NULL; 00066 protocol3data = NULL; 00067 protocol4data = NULL; 00068 } 00069 00070 std::string InterfaceEntry::info() const 00071 { 00072 std::stringstream out; 00073 out << (getName()[0] ? getName() : "*"); 00074 if (getNetworkLayerGateIndex()==-1) 00075 out << " on:-"; 00076 else 00077 out << " on:nwLayer.ifOut[" << getNetworkLayerGateIndex() << "]"; 00078 out << " MTU:" << getMTU(); 00079 if (isDown()) out << " DOWN"; 00080 if (isBroadcast()) out << " BROADCAST"; 00081 if (isMulticast()) out << " MULTICAST"; 00082 if (isPointToPoint()) out << " POINTTOPOINT"; 00083 if (isLoopback()) out << " LOOPBACK"; 00084 out << " macAddr:"; 00085 if (getMacAddress().isUnspecified()) 00086 out << "n/a"; 00087 else 00088 out << getMacAddress(); 00089 00090 if (ipv4data) 00091 out << " " << ((cPolymorphic*)ipv4data)->info(); // Khmm... 00092 if (ipv6data) 00093 out << " " << ((cPolymorphic*)ipv6data)->info(); // Khmm... 00094 if (protocol3data) 00095 out << " " << protocol3data->info(); 00096 if (protocol4data) 00097 out << " " << protocol4data->info(); 00098 return out.str(); 00099 } 00100 00101 std::string InterfaceEntry::detailedInfo() const 00102 { 00103 std::stringstream out; 00104 out << "name:" << (getName()[0] ? getName() : "*"); 00105 if (getNetworkLayerGateIndex()==-1) 00106 out << " on:-"; 00107 else 00108 out << " on:nwLayer.ifOut[" << getNetworkLayerGateIndex() << "]"; 00109 out << "MTU: " << getMTU() << " \t"; 00110 if (isDown()) out << "DOWN "; 00111 if (isBroadcast()) out << "BROADCAST "; 00112 if (isMulticast()) out << "MULTICAST "; 00113 if (isPointToPoint()) out << "POINTTOPOINT "; 00114 if (isLoopback()) out << "LOOPBACK "; 00115 out << "\n"; 00116 out << " macAddr:"; 00117 if (getMacAddress().isUnspecified()) 00118 out << "n/a"; 00119 else 00120 out << getMacAddress(); 00121 out << "\n"; 00122 if (ipv4data) 00123 out << " " << ((cPolymorphic*)ipv4data)->info() << "\n"; // Khmm... 00124 if (ipv6data) 00125 out << " " << ((cPolymorphic*)ipv6data)->info() << "\n"; // Khmm... 00126 if (protocol3data) 00127 out << " " << protocol3data->info() << "\n"; 00128 if (protocol4data) 00129 out << " " << protocol4data->info() << "\n"; 00130 00131 return out.str(); 00132 } 00133 00134 void InterfaceEntry::changed(int category) 00135 { 00136 if (ownerp) 00137 ownerp->interfaceChanged(this, category); 00138 } 00139 00140 void InterfaceEntry::setIPv4Data(IPv4InterfaceData *p) 00141 { 00142 #ifndef WITHOUT_IPv4 00143 ipv4data = p; 00144 p->ownerp = this; 00145 configChanged(); 00146 #else 00147 opp_error("setIPv4Data(): INET was compiled without IPv4 support"); 00148 #endif 00149 } 00150 00151 void InterfaceEntry::setIPv6Data(IPv6InterfaceData *p) 00152 { 00153 #ifndef WITHOUT_IPv6 00154 ipv6data = p; 00155 p->ownerp = this; 00156 configChanged(); 00157 #else 00158 opp_error("setIPv4Data(): INET was compiled without IPv6 support"); 00159 #endif 00160 } 00161