⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configinfo.java

📁 UoB JADhoc is an AODV Implementation in Java. This is a GZIPed TAR file for the Linux/Unix environme
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*JAdhoc ver 0.11 - Java AODV (RFC 3561) Protocol HandlerCopyright 2003-2004 ComNets, University of BremenThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/package jadhoc.conf;import java.io.*;import java.net.*;import java.util.*;import jadhoc.other.*;/*** This class provide configuration information of the Protocol* Handler. It provides methods to retrive, update & validate* parameters held in a configuration file** @author : Asanga Udugama* @date : 28-jul-2003* @email : adu@comnets.uni-bremen.de**/public class ConfigInfo {	// control variables	public boolean firstTime = false;	public String cfgFileName = "@!$";	public boolean infoChanged = false;	// common constants	public static final String YES = "yes";	public static final String NO = "no";	public static final String RERR_UNICAST = "unicast";	public static final String RERR_MULTICAST = "multicast";	public static final int RERR_UNICAST_VAL = 1;	public static final int RERR_MULTICAST_VAL = 2;	public static final String DELETE_MODE_HELLO = "hello";	public static final String DELETE_MODE_LINKLAYER = "linklayer";	public static final int DELETE_MODE_HELLO_VAL = 1;	public static final int DELETE_MODE_LINKLAYER_VAL = 2;	public static final String GUI_MODE = "gui";	public static final String NON_GUI_MODE = "non-gui";	public static final String LINUX_OS = "linux";	public static final String WINDOWS_OS = "windows";	public static final String IPv4_VERSION = "ipv4";	public static final String IPv6_VERSION = "ipv6";	public static final int IPv4_VERSION_VAL = 4;	public static final int IPv6_VERSION_VAL = 6;	public static final String ROUTE_DISCOVERY_ERS = "ers";	public static final String ROUTE_DISCOVERY_NON_ERS = "non-ers";	public static final int ROUTE_DISCOVERY_ERS_VAL = 1;	public static final int ROUTE_DISCOVERY_NON_ERS_VAL = 2;	// configuration constants	public static final String MAC_ADDRESS_OF_GATEWAY = "00:00:00:00:00:00";	// configuration variables ; application	public String executionMode = GUI_MODE;	public String osInUse = LINUX_OS;	public String ipVersion = IPv4_VERSION;	public String ipAddress = "104.101.112.230";	public String ifaceName = "eth1";	public String ipAddressGateway = "104.101.112.225";	public String loIfaceName = "lo";	public String loggingStatus = NO;	public String loggingLevel = "1";	public String logFile = "./jadhoc.log";	public String pathToSystemCmds = "/sbin";	public String onlyDestination = YES;	public String gratuitousRREP = NO;	public String RREPAckRequired = NO;	public String ipAddressMulticast = "224.0.0.2";	public String RERRSendingMode = RERR_UNICAST;	public String deletePeriodMode = DELETE_MODE_HELLO;       // (hello or linklayer)	public String routeDiscoveryMode = ROUTE_DISCOVERY_ERS; // ers or non-ers	public String packetBuffering = NO;	// configuration variables ; aodv	public String activeRouteTimeout = "3000"; 	//   ACTIVE_ROUTE_TIMEOUT     3,000 Milliseconds	public String allowedHelloLoss = "2";      	//   ALLOWED_HELLO_LOSS       2   	public String helloInterval = "1000";		//   HELLO_INTERVAL           1,000 Milliseconds	public String localAddTTL = "2";		//   LOCAL_ADD_TTL            2	public String netDiameter = "35";		//   NET_DIAMETER             35	public String nodeTraversalTime = "40";		//   NODE_TRAVERSAL_TIME      40 milliseconds	public String RERRRatelimit = "10";		//   RERR_RATELIMIT           10	public String RREQRetries = "6";		//   RREQ_RETRIES             2	public String RREQRateLimit = "10";		//   RREQ_RATELIMIT           10	public String timeoutBuffer = "2";		//   TIMEOUT_BUFFER           2	public String TTLStart = "1";			//   TTL_START                1	public String TTLIncrement = "2";		//   TTL_INCREMENT            2	public String TTLThreshold = "10";		//   TTL_THRESHOLD            7	//public String deletePeriod = "999";		//   DELETE_PERIOD            see note below (hello, linklayer)	//public String blacklistTimeout = "999";     	//   BLACKLIST_TIMEOUT        RREQ_RETRIES * NET_TRAVERSAL_TIME	//public String maxRepairTTL = "10";		//   MAX_REPAIR_TTL           0.3 * NET_DIAMETER	//public String minRepairTTL = "999";		//   MIN_REPAIR_TTL           see note below	//public String myRouteTimeout = "6000";		//   MY_ROUTE_TIMEOUT         2 * ACTIVE_ROUTE_TIMEOUT	//public String netTraversalTime = "2800";	//   NET_TRAVERSAL_TIME       2 * NODE_TRAVERSAL_TIME * NET_DIAMETER	//public String nextHopWait = "50";		//   NEXT_HOP_WAIT            NODE_TRAVERSAL_TIME + 10	//public String pathDiscoveryTime = "5600";	//   PATH_DISCOVERY_TIME      2 * NET_TRAVERSAL_TIME	//public String ringTraversalTime = "999";	//   RING_TRAVERSAL_TIME      2 * NODE_TRAVERSAL_TIME * (TTL_VALUE + TIMEOUT_BUFFER)	//public String TTLValue = "999";			//   TTL_VALUE                see note below	// configuration variable labels	public String executionModeStr = "ExecutionMode";	public String osInUseStr = "OSInUse";	public String ipVersionStr = "IPVersion";	public String ipAddressStr = "IPAddress";	public String ifaceNameStr = "IfaceName";	public String ipAddressGatewayStr = "IPAddressGateway";	public String loIfaceNameStr = "LoopbackIfaceName";	public String loggingStatusStr = "LoggingStatus";	public String loggingLevelStr = "LoggingLevel";	public String logFileStr = "LogFile";	public String pathToSystemCmdsStr = "PathToSystemCmds";	public String onlyDestinationStr = "OnlyDestination";	public String gratuitousRREPStr = "GratuitousRREP";	public String RREPAckRequiredStr = "RREPAckRequired";	public String ipAddressMulticastStr = "IPAddressMulticast";	public String RERRSendingModeStr = "RERRSendingMode";	public String deletePeriodModeStr = "DeletePeriodMode";	public String routeDiscoveryModeStr = "RouteDiscoveryMode";	public String packetBufferingStr = "PacketBuffering";	public String activeRouteTimeoutStr = "ActiveRouteTimeout";	public String allowedHelloLossStr = "AllowedHelloLoss";   	public String helloIntervalStr = "HelloInterval";	public String localAddTTLStr = "LocalAddTTL";	public String netDiameterStr = "NetDiameter";	public String nodeTraversalTimeStr = "NodeTraversalTime";	public String RERRRatelimitStr = "RERRRatelimit";	public String RREQRetriesStr = "RREQRetries";	public String RREQRateLimitStr = "RREQRateLimit";	public String timeoutBufferStr = "TimeoutBuffer";	public String TTLStartStr = "TTLStart";	public String TTLIncrementStr = "TTLIncrement";	public String TTLThresholdStr = "TTLThreshold";	// Parameters in their real data type. These parameters will be used	// by the protocol handler when accessing. This is done to speed the	// activities of the protocol handler.	public String executionModeVal;	public String osInUseVal;	public int ipVersionVal;	public InetAddress ipAddressVal;	public String ifaceNameVal;	public InetAddress ipAddressGatewayVal;	public String loIfaceNameVal;	public boolean loggingStatusVal;	public int loggingLevelVal;	public String logFileVal;	public String pathToSystemCmdsVal;	public boolean onlyDestinationVal;	public boolean gratuitousRREPVal;	public boolean RREPAckRequiredVal;	public InetAddress ipAddressMulticastVal;	public int RERRSendingModeVal;	public int deletePeriodModeVal;	public int routeDiscoveryModeVal;	public boolean packetBufferingVal;	public int activeRouteTimeoutVal;	public int allowedHelloLossVal;	public int blacklistTimeoutVal;	public int deletePeriodVal;   	public int helloIntervalVal;	public int localAddTTLVal;	public int maxRepairTTLVal;	public int myRouteTimeoutVal;	public int netDiameterVal;	public int netTraversalTimeVal;	public int nextHopWaitVal;	public int nodeTraversalTimeVal;	public int pathDiscoveryTimeVal;	public int RERRRatelimitVal;	public int RREQRetriesVal;	public int RREQRateLimitVal;	public int timeoutBufferVal;	public int TTLStartVal;	public int TTLIncrementVal;	public int TTLThresholdVal;	/**	* Constructor to create ConfigInfo and read config	* information from the given file.	* @param String cfg - Name of config file	*/	public ConfigInfo(String cfg) throws Exception {		cfgFileName = cfg;                File cfgFile = new File(cfgFileName.trim());                if(!cfgFile.exists()) {			createFileWithDefaults();                } else {                	if(!cfgFile.canRead() || !cfgFile.canWrite()) {                        	throw new Exception("Cannot read or write to file - " + cfgFileName);                	}		}		readInfo();	}	/**	* Constructor to create a default value filed ConfigInfo	* information object.	*/	public ConfigInfo() {	}	/**	* Method to create a config file using the default	* values.	*	*/	private void createFileWithDefaults() throws Exception {		updateInfo();		firstTime = true;	}	/**	* Method to read configuration information from	* the given File object and place them in the	* current object.	* @param File cfgFile - File object of config file	*/        public void readInfo() throws Exception {                String strLine, strTag, strValue;                int lineNo = 0;                BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(cfgFileName)));                while((strLine = r.readLine()) != null) {                        lineNo++;			if(strLine.trim().length() == 0			   || strLine.charAt(0) == '#') {				continue;			}                        try {				// separate the line to tag and value                                strLine = strLine.trim();                                strTag = strLine.substring(0, strLine.indexOf('=')).trim();                                strValue = strLine.substring((strLine.indexOf('=') + 1), (strLine.length())).trim();				// check & get each config variable				if(strTag.equals(executionModeStr)) {					if(!strValue.toLowerCase().equals(NON_GUI_MODE)					     && !strValue.toLowerCase().equals(GUI_MODE)) {						throw new Exception("Invalid Execution mode ("									+ GUI_MODE + " or "									+ NON_GUI_MODE + ")");					}					executionMode = strValue;					executionModeVal = strValue;				} else if(strTag.equals(osInUseStr)) {                                        if(!strValue.toLowerCase().equals(WINDOWS_OS)                                            && !strValue.toLowerCase().equals(LINUX_OS)) {						throw new Exception("Invalid osInUse - ("								+ WINDOWS_OS + " or "								+ LINUX_OS + ")");					}					osInUse = strValue;					osInUseVal = strValue;				} else if(strTag.equals(ipVersionStr)) {                                        if(!strValue.toLowerCase().equals(IPv4_VERSION)                                            && !strValue.toLowerCase().equals(IPv6_VERSION)) {                                            	throw new Exception("Invalid ipVersion - ("								+ IPv4_VERSION + " or "								+ IPv6_VERSION + ")");					}					///////////// temporary code					if(strValue.toLowerCase().equals(IPv6_VERSION)) {                                            	throw new Exception("IPv6 not supported at this time");					}					///////////// end of temprorary code					ipVersion = strValue;                                        if(strValue.toLowerCase().equals(IPv4_VERSION))						ipVersionVal = IPv4_VERSION_VAL;					else						ipVersionVal = IPv6_VERSION_VAL;				} else if(strTag.equals(ipAddressStr)) {                                        InetAddress adr = InetAddress.getByName(strValue);					if(ipVersionVal == IPv4_VERSION_VAL) {						if(!(adr instanceof Inet4Address))                                                	throw new Exception("Invalid ipAddress - must be IPv4");					} else if(ipVersionVal == IPv6_VERSION_VAL) {						if(!(adr instanceof Inet6Address))                                                	throw new Exception("Invalid ipAddress - must be IPv6");					} else                                        	throw new Exception("Invalid ipAddress - some inconsistancy");                                        ipAddress = adr.getHostAddress();                                        ipAddressVal = adr;				} else if(strTag.equals(ifaceNameStr)) {					if(strValue.trim().length() == 0)                                        	throw new Exception("Invalid ifaceName - cannot be blank");					ifaceName = strValue;					ifaceNameVal = strValue;				} else if(strTag.equals(ipAddressGatewayStr)) {                                        InetAddress adr = InetAddress.getByName(strValue);					if(ipVersionVal == IPv4_VERSION_VAL) {						if(!(adr instanceof Inet4Address))                                                	throw new Exception("Invalid ipAddressGateway - must be IPv4");					} else if(ipVersionVal == IPv6_VERSION_VAL) {						if(!(adr instanceof Inet6Address))                                                	throw new Exception("Invalid ipAddressGateway - must be IPv6");					} else                                        	throw new Exception("Invalid ipAddressGateway - some inconsistancy");                                        ipAddressGateway = adr.getHostAddress();                                        ipAddressGatewayVal = adr;				} else if(strTag.equals(loIfaceNameStr)) {					if(strValue.trim().length() == 0)                                        	throw new Exception("Invalid loIfaceName - cannot be blank");					loIfaceName = strValue;					loIfaceNameVal = strValue;				} else if(strTag.equals(loggingStatusStr)) {					if(!(strValue.toLowerCase().equals(YES)						|| strValue.toLowerCase().equals(NO)))						throw new Exception("Invalid LoggingStatus - Yes or No");					loggingStatus = strValue;					if(strValue.toLowerCase().equals(YES))						loggingStatusVal = true;					else						loggingStatusVal = false;				} else if(strTag.equals(loggingLevelStr)) {					if(loggingStatus.toLowerCase().equals(YES)) {						try {							int num = Integer.parseInt(strValue);							if(num < Logging.MIN_LOGGING || num > Logging.MAX_LOGGING)								throw new Exception();							loggingLevel = strValue;							loggingLevelVal = num;						} catch(Exception e) {							throw new Exception("Invalid LoggingLevel - (between "							 				+ Logging.MIN_LOGGING										+ " and " + Logging.MAX_LOGGING + ")");						}					}				} else if(strTag.equals(logFileStr)) {					if(loggingStatus.toLowerCase().equals(YES)) {						try {							if(strValue.trim().length() == 0)								throw new Exception();							logFile = strValue;							logFileVal = strValue;						} catch(Exception e) {							throw new Exception("Invalid LogFile " + strValue);						}					}				} else if(strTag.equals(pathToSystemCmdsStr)) {					//File dir = new File(strValue);					//if(!dir.isDirectory())					//	throw new Exception("Invalid PathToSystemCmds");					if(pathToSystemCmdsStr.trim().length() == 0)						throw new Exception("Invalid PathToSystemCmds");					pathToSystemCmds = strValue;					pathToSystemCmdsVal = strValue;				} else if(strTag.equals(onlyDestinationStr)) {					if(!(strValue.toLowerCase().equals(YES)						|| strValue.toLowerCase().equals(NO)))						throw new Exception("Invalid OnlyDestination - Yes or No");					onlyDestination = strValue;					if(strValue.toLowerCase().equals(YES))						onlyDestinationVal = true;					else						onlyDestinationVal = false;				} else if(strTag.equals(gratuitousRREPStr)) {					if(!(strValue.toLowerCase().equals(YES)						|| strValue.toLowerCase().equals(NO)))						throw new Exception("Invalid GratuitousRREP - Yes or No");					gratuitousRREP = strValue;					if(strValue.toLowerCase().equals(YES))						gratuitousRREPVal = true;					else						gratuitousRREPVal = false;				} else if(strTag.equals(RREPAckRequiredStr)) {					if(!(strValue.toLowerCase().equals(YES)						|| strValue.toLowerCase().equals(NO)))						throw new Exception("Invalid RREPAckRequired - Yes or No");					RREPAckRequired = strValue;					if(strValue.toLowerCase().equals(YES))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -