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

📄 osoperationslinuxipv6.java

📁 UoB JADhoc is an AODV Implementation in Java. This is a GZIPed TAR file for the Linux/Unix environme
💻 JAVA
字号:
/*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.os;import java.net.*;import java.io.*;import jadhoc.conf.*;import jadhoc.net.*;import jadhoc.other.*;/*** This class defines all the functions related to manipulating* the routing environment of a Linux/IPv6 environment. Implements* the OSOperationsInterface to provide a consistent interface* to the route manager.** @author : Asanga Udugama* @date : 28-jul-2003* @email : adu@comnets.uni-bremen.de**/public class OSOperationsLinuxIPv6 implements OSOperationsInterface {	public ConfigInfo cfgInfo;	public CurrentInfo curInfo;	Process proc;	String cmd, s;	BufferedReader stdInput, stdError;	/**	* Constructs the object	*/	public OSOperationsLinuxIPv6(ConfigInfo cfg, CurrentInfo cur) {		cfgInfo = cfg;		curInfo = cur;	}	/**	* Method to initialize the routing environment	* in a Linux IPv6 environment to perform AODV protocol	* handling	* @param int level - The initialization level	*			0 = full initialization level	*			1 - 100 = other init levels	* @return int - returns the success or failure	*/	public int initializeRouteEnvironment(int level) {                try {			switch(level) {				case 0:					fullInit();					break;				default: // do nothing					break;			}                } catch(Exception e) {                        return 1;                }                return 0;	}	private void fullInit() throws Exception {		cmd = "ip -6 neigh add " + cfgInfo.ipAddressGateway + " lladdr "			+ ConfigInfo.MAC_ADDRESS_OF_GATEWAY + " dev " + cfgInfo.ifaceNameVal;                proc = Runtime.getRuntime().exec(cmd);                stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));                stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));		// To see errors enable stdError print loop		//		//while((s = stdInput.readLine()) != null) {               	//        System.out.println(s);               	//}		//                //while((s = stdError.readLine()) != null) {                //        System.out.println(s);                //}	}	/**	* Method to add a route entry in the routing environment	* of a Linux/IPv6 environment.	* @param RouteEntry rtEntry - the route entry from which to get	*				information	* @return int - returns the success or failure	*/	public int addRoute(RouteEntry rtEntry) {                try {			cmd = "ip -6 route add " + rtEntry.destIPAddr.getHostAddress() + " via "				+ rtEntry.nextHopIPAddr.getHostAddress() + " dev " + rtEntry.ifaceName;                        proc = Runtime.getRuntime().exec(cmd);                        stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));                        stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));			// To see errors enable stdError print loop			//                        //while((s = stdInput.readLine()) != null) {                        //        System.out.println(s);                        //}			//                        //while((s = stdError.readLine()) != null) {                        //        System.out.println(s);                        //}                } catch(Exception e) {                        return 1;                }                return 0;	}	/**	* Method to remove a route entry in the routing environment of	* a Linux/IPv6 environment	* @param RouteEntry rtEntry - the route entry from which to get	*				information	* @return int - returns the success or failure	*/	public int deleteRoute(RouteEntry rtEntry) {                try {			cmd = "ip -6 route del " + rtEntry.destIPAddr.getHostAddress() + " via "				+ rtEntry.nextHopIPAddr.getHostAddress() + " dev " + rtEntry.ifaceName;                        proc = Runtime.getRuntime().exec(cmd);                        stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));                        stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));			// To see errors enable stdError print loop			//                        //while((s = stdInput.readLine()) != null) {                        //        System.out.println(s);                        //}			//                        //while((s = stdError.readLine()) != null) {                        //        System.out.println(s);                        //}                } catch(Exception e) {                        return 1;                }                return 0;	}	/**	* Method to put the route environment to the original state	* before terminating the protocol handler in Linux/IPv6	* environment.	* @return int - returns the success or failure	*/	public int finalizeRouteEnvironment() {                try {			cmd = "ip -6 neigh del " + cfgInfo.ipAddressGateway + " lladdr "				+ ConfigInfo.MAC_ADDRESS_OF_GATEWAY + " dev " + cfgInfo.ifaceNameVal;                        proc = Runtime.getRuntime().exec(cmd);                        stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));                        stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));			// To see errors enable stdError print loop			//                        //while((s = stdInput.readLine()) != null) {                        //        System.out.println(s);                        //}			//                        //while((s = stdError.readLine()) != null) {                        //        System.out.println(s);                        //}                } catch(Exception e) {                        return 1;                }                return 0;	}}

⌨️ 快捷键说明

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