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

📄 input.java

📁 监控大型网络的软件。能够自动发现拓扑结构
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: Input.java 3757 2006-11-24 12:31:59Z mortenv $  * * Copyright 2000-2005 Norwegian University of Science and Technology *  * This file is part of Network Administration Visualized (NAV) *  * NAV is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * NAV is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with NAV; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * * Authors: Kristian Eide <kreide@gmail.com> */import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.URL;import java.net.URLConnection;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;class Input{	// Default verdier	public static String vPServerURLDefault = "https://beta.nav.ntnu.no/vPServer/servlet/vPServer";	public static String lastURLDefault = "http://www.nav.ntnu.no/vlanPlotNG/common/vPLast/last_ny.pl";	public static String cricketURLDefault = "http://www.nav.ntnu.no/~cricket/";	public static String netflowURLDefault = "http://manwe.itea.ntnu.no/";	// URL for vPServer-modulen	public static String vPServerURL;		public static String rootURL;	// URL for last-scriptet	public static String lastURL;	// URL til cricket	public static String cricketURL;	// URL til Netflow, hvis det er aktivt	public static String netflowURL;	public static String sessionid;	public static String authuser;	Com com;	// Caches	Hashtable netCache = new Hashtable();	Hashtable boksCache = new Hashtable();	Vector listRouters;	Vector listRouterLinks;	Vector listNetRouters;	Vector listNetLinks;	Vector listRouterGroups;	Vector listLinkInfo;	Vector listCPULast;	Vector listLinkLast;	Vector listNetLast;	int[][] nettelXY = new int[3][];	int[] index;	//boolean fetchConfig = true;	boolean fetchConfig = false;	ServerFetcher serverFetcher;	Vector inputQ;	public Input(Com InCom)	{		com = InCom;	}	public void getDefaultInputNotify(int grp)	{	}	public Hashtable getDefaultInput(int grp)	{		// Ikke i cache, så vi må hente struktur-info fra server		Vector v = new Vector();		if (!Net.setConfig) v.addElement("listConfig");		String[] def = {			"listRouters",			"listRouterGroups",			"listRouterXY"		};		String[] s = new String[v.size()+def.length];		for (int i=0; i < v.size(); i++) {			s[i] = (String)v.elementAt(i);		}		for (int i=0; i < def.length; i++) {			s[v.size()+i] = def[i];		}		String param = "gruppeid=" + grp;		Hashtable h = fetch(s, param, vPServerURL);		netCache.put(new Integer(grp), h);		return h;	}	// Fetch fra vPServer	public Hashtable fetch(String[] req, String param, String serverURL)	{		return fetch(req, param, serverURL, null);	}	public Hashtable fetch(String[] req, String param, String serverURL, String hashKey)	{		Hashtable ret;		try		{			StringBuffer b = new StringBuffer();			// lag URL			b.append(serverURL);			b.append("?section=boks&");			if (param.length() > 0)			{				b.append(param + "&");			}			b.append("request=");			for (int i = 0; i < req.length; i++)			{				b.append(req[i]);				if ((i+1) < req.length)				{					b.append(",");				}			}			{				long[] lastInterval = com.getLastInterval();				b.append("&time=" + lastInterval[0] + ",");				b.append( (lastInterval[1] >= 0 ? "0" : ""+lastInterval[1]) );				b.append("&" + (com.getTidAvg() ? "type=avg" : "type=max"));			}			com.d("URL: " + b.toString(), 2);			URL url = new URL(b.toString() );			inputQ = new Vector();			com.d("Create new ServerFetcher",2);			serverFetcher = new ServerFetcher(url, inputQ);			serverFetcher.start();			synchronized (inputQ) {				if (inputQ.isEmpty()) {					com.d("Waiting on inputQ...",2);					inputQ.wait();				}				com.d("Wait over",2);				ret = (Hashtable)inputQ.elementAt(0);				inputQ.removeElementAt(0);			}		} catch (Exception e) {			com.d("Error: " + e.getMessage(), 0);			throw new ServerFetchException("Error: " + e.getMessage());		}		if (hashKey != null) boksCache.put(hashKey, ret);		return ret;	}	class ServerFetcher extends Thread {		private URL url;		private Vector q;		public ServerFetcher(URL myUrl, Vector queue) {			url = myUrl;			q = queue;		}		public void run() {			try {				String name = null;				Hashtable ret = new Hashtable();				URLConnection connection = url.openConnection();				connection.setRequestProperty("Cookie", "nav_sessid="+sessionid);				connection.connect();				BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));				String line;				Hashtable hash = null;				while ((line = in.readLine()) != null) {						if (line.equals("---")) {							synchronized (q) {								System.out.println("  Adding 1");								q.addElement(ret);								q.notify();							}							ret = new Hashtable();							continue;						} else						if (line.length() >= 4 && line.substring(0, 4).equals("list")) {							ret.put(line, hash = new Hashtable());							continue;						} else {							String[] s = misc.tokenize(line, "^");							hash.put(s[0], s);						}				}				System.out.println("About to enter q");				synchronized (q) {					q.addElement(ret);					q.notify();				}			} catch (Exception e) {				com.d("Exception: " + e.getMessage(), 0);			}		}	}	public Hashtable getDefaultLast()	{		try {			synchronized (inputQ) {				if (inputQ.isEmpty()) {					inputQ.wait();				}				Hashtable ht = (Hashtable)inputQ.elementAt(0);				inputQ.removeElementAt(0);				return ht;			}		} catch (Exception e) {			com.d("Error: " + e.getMessage(), 0);		}		return null;	}	public Hashtable getDefaultLast2()	{		// kun ruter-linker		String[] param = new String[4];		StringBuffer b = new StringBuffer();		Hashtable dup = new Hashtable();		com.d("Now in getDefaultLast", 4);		com.d("  Adding links", 4);		// Legg til linkId'ene		String type;		if (com.getNet().getVisNettel() == null || com.getNet().getVisNettel().getKat().equals("gw"))		{			type = "net=";		} else		{			type = "sw=";		}		b.append(type);		Enumeration e = com.getNet().getLinkHash().elements();		while (e.hasMoreElements())		{			Link l = (Link)e.nextElement();			if (!dup.containsKey(""+l.getId()) )			{				b.append(l.getId() + ",");				dup.put(""+l.getId(),"");			}		}		if (!b.toString().equals(type)) b.setLength(b.length()-1); else b.append("0");		if (com.getNet().getVisNettel() == null || com.getNet().getVisNettel().getKat().equals("gw"))		{			param[0] = b.toString();			param[1] = "sw=0";		} else		{			param[0] = "net=0";			param[1] = b.toString();		}		long[] lastInterval = com.getLastInterval();		param[2] = "time=" + lastInterval[0] + ",";		param[2] += (lastInterval[1] >= 0) ? "now" : ""+lastInterval[1];		param[3] = com.getTidAvg() ? "type=avg" : "type=max";		Hashtable h = fetch(param, lastURL);		return h;	}	// Fetch fra last-script	public Hashtable fetch(String param[], String serverURL)	{		Hashtable ret = new Hashtable();		String name = null;		Hashtable hash = null;		try		{			StringBuffer b = new StringBuffer();			// lag URL			b.append(serverURL + "?");			for (int i = 0; i < param.length; i++)			{				b.append(param[i]);				if ((i+1) < param.length)				{					b.append("&");				}			}			com.d("URL: " + b.toString(), 2);			URL url = new URL(b.toString() );			URLConnection connection = url.openConnection();			connection.connect();			BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));			String line;			while ((line = in.readLine()) != null)			{				if (line.length() >= 4 && line.substring(0, 4).equals("list"))				{					if (name != null) ret.put(name, hash);					name = line;					hash = new Hashtable();					continue;				}				String[] s = misc.tokenize(line, ",");				hash.put(s[0], s);			}			if (name != null) ret.put(name, hash);		}		catch (Exception e)		{			com.d("Error: " + e.getMessage(), 0);		}		return ret;	}/*	public void getDefaultInput()	{		String[] s;		if (fetchConfig)		{			s = new String[8];		} else		{			s = new String[7];		}		s[0] = "listRouters";		s[1] = "listRouterLinks";		s[2] = "listNetRouters";		s[3] = "listNetLinks";		s[4] = "listRouterGroups";		s[5] = "listLinkInfo";		s[6] = "listRouterXY";		if (fetchConfig)		{			s[7] = "listConfig";		}		String param = "gruppeId=" + com.getNet().getVisGruppe();		Vector[] v = fetch(s, param, "http://bigbud.itea.ntnu.no/vlanPlot/vPServer/vPServer");		listRouters = v[0];		listRouterLinks = v[1];		listNetRouters = v[2];		listNetLinks = v[3];		listRouterGroups = v[4];		listLinkInfo = v[5];		nettelXY[0] = new int[v[0].size()+v[3].size() ];		nettelXY[1] = new int[v[0].size()+v[3].size() ];		nettelXY[2] = new int[v[0].size()+v[3].size() ];		for (int i = 0; i < v[6].size(); i++)		{			s = (String[])v[6].elementAt(i);			nettelXY[0][i] = Integer.parseInt(s[0]);			nettelXY[1][i] = Integer.parseInt(s[1]);			nettelXY[2][i] = Integer.parseInt(s[2]);		}		if (fetchConfig)		{			fetchConfig = false;			Cnf cnf = new Cnf(v[7]);			com.setCnf(cnf);			//String[] scnf = cnf.get("dbCnf.nettel.1");			//for (int i = 0; i < scnf.length; i++)			//{			//	com.d("cnf: " + scnf[i] + "|\n", 2);			//}		}	}*//*	public void getDefaultLast()	{		// kun ruter-linker		String[] param = new String[4];		StringBuffer b = new StringBuffer();		Vector routerLinks = com.getInput().getListRouterLinks();		Vector netLinks = com.getInput().getListNetLinks();		b.append("net=");		// legg til id for vanlige linker		for (int i = 0; i < routerLinks.size(); i++)		{			String[] s = (String[])routerLinks.elementAt(i);			for (int j = 1; j < s.length; j++)			{				String[] linkInfo = misc.tokenize(s[j], ",");				b.append(linkInfo[1] + ",");			}		}		// legg til id for stam-linker		for (int i = 0; i < netLinks.size(); i++)		{			String[] s = (String[])netLinks.elementAt(i);			for (int j = 1; j < s.length; j++)			{				String[] linkInfo = misc.tokenize(s[j], ",");				b.append(linkInfo[1] + ",");			}		}		b.setLength(b.length()-1);		param[0] = b.toString();		param[1] = "sw=0";		//param[2] = "time=-3600,now";		long[] lastTid = com.getLastTid();		if (lastTid[1] >= 0)		{			param[2] = "time=" + lastTid[0] + ",now";		} else		{			param[2] = "time=" + lastTid[0] + "," + lastTid[1];

⌨️ 快捷键说明

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