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

📄 net.java

📁 Network Administration Visualized 网络管理可视化源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: Net.java 3859 2007-01-31 14:51:36Z 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.awt.Canvas;import java.awt.Choice;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Image;import java.awt.Polygon;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.util.Enumeration;import java.util.Hashtable;import java.util.Stack;import java.util.StringTokenizer;import java.util.Vector;class Net extends Canvas implements ItemListener{	/**	 * 	 */	private static final long serialVersionUID = 1L;	// Config	public static final boolean APPLY_LAST_BYNETT = true;	public static final boolean APPLY_LAST_VLANV = true;	Com com;	Color color = Color.black;	public static final int STRUKTUR_DONE = 0;	public static final int LAST_DONE = 10;	public static String netName;	public static String netLink;	public static String domainSuffix = "";	// Denne styrer om vi har satt konfigurasjon	public static boolean setConfig = false;	int x = 10;	int y = 10;	int lastx = 0;	int lasty = 0;	Nettel visNettel = null;	int visVlan = 0; // hvilket vlan det fokuseres på	int visGruppe = -1; // hvilken gruppe det fokuseres på	String visGruppeNavn = "";	Hashtable gruppeIdMap = new Hashtable(); // Convert between gruppe navn and gruppe id (db)	//Vector nettel;	Vector group = new Vector();	Hashtable nh = new Hashtable();	Hashtable lh = new Hashtable();	Hashtable gh = new Hashtable();	Stack history = new Stack();	Polygon backKnapp;	// Layout	LayoutNettel lnTop;	LayoutNettel lnMiddle;	LayoutNettel lnBottom;	boolean needReset = true;	boolean recordHistory = true;	// Disse forteller i hvilken modus vi er i	boolean vlanVandring = false;	boolean bynettView = false;	boolean hideCore = false;	boolean error = false;	String errorMsg;	public static int FONT_SIZE = 20;	//Font overskriftFont = new Font("Helvetica",Font.PLAIN, FONT_SIZE);	Font overskriftFont = new Font("Arial",Font.BOLD, FONT_SIZE);	String overskrift = "";	String preHeader = "Traffic map: ";	// Menyer	PopupMenus vlanMenu;	// statiske konstanter	public static final int UPLINK = 0;	public static final int HZLINK = 1;	public static final int DNLINK = 2;	public static final String gwMenuText[] = { "Device info", "Network Explorer", "CPU load", "Net-list" };	public static final String swMenuText[] = { "Device info", "Network Explorer", "Backplane load" };	public static final String linkMenuText[] = { "Load", "Packets", "Drops", "Errors" };	public static final String linkGwMenuText[] = { "Load", "Packets", "Drops", "Errors", "|"};	// Buffer drawing related variables	private int bufferWidth;	private int bufferHeight;	private Image bufferImage;	private Graphics bufferGraphics;	// FIXME: Denne skal være dynamisk!	//public static final String netNames[] = { "Bynett", "Kjernenett", "Testnett" };	public Net(Com InCom)	{		com = InCom;		Mouse mouse = new Mouse(com);		MouseMove mv = new MouseMove(com);		addMouseListener(mouse);		addMouseMotionListener(mv);		Input input = new Input(com);		com.setInput(input);		gruppeIdMap.put("", new Integer(0));		PopupMenuListener pmListener = new PopupMenuListener(com);		vlanMenu = new PopupMenus("VLAN_MENU", "Vlan menu", this, pmListener);		PopupMenus gwMenu = new PopupMenus("RUTER_MENU", "Router menu", gwMenuText, this, pmListener);		PopupMenus swMenu = new PopupMenus("SWITCH_MENU", "Switch menu", swMenuText, this, pmListener);		PopupMenus linkMenu = new PopupMenus("LINK_MENU", "Link menu", linkMenuText, this, pmListener);		PopupMenus linkGwMenu = new PopupMenus("LINK_GW_MENU", "Link Gw menu", linkGwMenuText, this, pmListener);		com.setGwMenu(gwMenu);		com.setSwMenu(swMenu);		com.setLinkMenu(linkMenu);		com.setLinkGwMenu(linkGwMenu);		lnTop = new LayoutNettel(this, com.getTopScroll(), "up", com);		lnMiddle = new LayoutNettel(this, com.getMidScroll(), "hz", com);		lnBottom = new LayoutNettel(this, com.getBottomScroll(), "dn", com);		//lnMiddle = new LayoutNettel(this, null, "hz", com);	}	public void buildBynett()	{		if (visGruppe < 0) {			visGruppe = 0;			visGruppeNavn = "";		}		com.d("Starter buildBynett(), gruppe " + visGruppe + " ("+visGruppeNavn+","+gruppeIdMap.get(visGruppeNavn)+")", 1);		com.d("------------", 1);		com.d("Blanker Nettel-hash", 1);		// Tar bort scrollbarer		com.getTopScroll().setVisible(false);		com.getMidScroll().setVisible(false);		com.getBottomScroll().setVisible(false);		// Klargjør for å bygge opp "verden" på nytt		com.d("Reseter group-vector", 1);		nh.clear();		lh.clear();		group.removeAllElements();		vlanVandring = false;		bynettView = true;		// Hent data		int visGruppeId = ((Integer)gruppeIdMap.get(visGruppeNavn)).intValue();		Hashtable h = com.getInput().getDefaultInput(visGruppeId);		if (!setConfig) {			Hashtable lConfig = (Hashtable)h.get("listConfig");			setConfig(lConfig);		}		Hashtable lRouters = (Hashtable)h.get("listRouters");		Hashtable lRouterLinks = (Hashtable)h.get("listRouterLinks");		Hashtable lRouterLinkInfo = (Hashtable)h.get("listRouterLinkInfo");		Hashtable lRouterGroups = (Hashtable)h.get("listRouterGroups");		Hashtable lRouterXY = (Hashtable)h.get("listRouterXY");		Hashtable lInGroup = new Hashtable();		com.d("listRouters size: " + lRouters.size(), 2);		com.d("listRouterLinks size: " + lRouterLinks.size(), 2);		com.d("listRouterXY size: " + lRouterXY.size(), 2);		if (visGruppe > 0)		{			// Bare ta med enheter som skal være med			Hashtable tmp = new Hashtable();			//Hashtable tmp2 = new Hashtable();			String[] s = (String[])lRouterGroups.get(""+visGruppeId);			for (int i = 4; i < s.length; i++) // Element 2 og 3 er X og Y for gruppen			{				// legg til enheten hvis den eksiterer				if (!lRouters.containsKey(s[i])) continue;				tmp.put(s[i], lRouters.get(s[i]) );				lInGroup.put(s[i], lRouters.get(s[i]) );				com.d("Added: " + s[i],2);				// sjekk hvilke enheter denne enheten har linker til, og legg til dem				String[] link = (String[])lRouterLinks.get(s[i]);				for (int j = 1; j < link.length; j++)				{					String[] linkIdS = misc.tokenize(link[j], ",");					String boksid = linkIdS[1];					if (!lRouters.containsKey(boksid)) continue;					tmp.put(boksid, lRouters.get(boksid) );				}			}			// Så må vi søke gjennom alle stam||elink for å sjekke om noen av dem skal være med			{				Enumeration e = lRouterLinks.elements();				while (e.hasMoreElements())				{					String[] link = (String[])e.nextElement();					if (link[0].charAt(0) == '-')					{						// stam||elink						for (int j = 1; j < link.length; j++)						{							String[] linkIdS = misc.tokenize(link[j], ",");							String boksid = linkIdS[1];							if (lInGroup.containsKey(boksid) && lRouters.containsKey(link[0]) )							{								tmp.put(link[0], lRouters.get(link[0]) );								break;							}						}					}				}			}			lRouters = tmp;		}		// Legg til rutere		Enumeration e = lRouters.elements();		int topLayoutCnt=0;		while (e.hasMoreElements()) {			String[] s = (String[])e.nextElement();			Nettel n = new Nettel(com, Integer.parseInt(s[0]), s[1], s[2], "1", 0);			n.setDrawVlan(false);			n.setHashKey(s[0]);			nh.put(s[0], n);			// Sett XY-koordinater			String[] xy;			if ( (xy = (String[])lRouterXY.get(s[0])) == null) {				xy = new String[3];				int[] topXY = topRowLayout(topLayoutCnt++);				xy[1] = ""+topXY[0];				xy[2] = ""+topXY[1];			} else {				n.locationSet();			}			n.setXY(Integer.parseInt(xy[1]), Integer.parseInt(xy[2]) );			com.d("   " + s[0] + ", " + s[1] + ", type: " + s[2] + " ("+xy[1]+","+xy[2]+")", 3);			//		}		// sett grupper		e = lRouterGroups.elements();		com.d("Antall ruter-grupper: " + lRouterGroups.size(), 2);		while (e.hasMoreElements() && visGruppe == 0)		{			String[] s = (String[])e.nextElement();			if (s.length <= 4 && !s[0].equals("0")) continue; // Det er ingen bokser i denne gruppen			// Legg til gruppenavnet til GUI-menyen			com.getLeft().addNettNavn(s[1]);			com.d("Adding gruppeIdMap: " + s[1] + " -> " + s[0], 3);			gruppeIdMap.put(s[1], new Integer(s[0]));			if (s[0].equals("0")) {				// Set global hideicons				hideCore = Boolean.valueOf(s[4]).booleanValue();				if (hideCore) {					// Clear all core					Enumeration ne = nh.elements();					while (ne.hasMoreElements()) {						Nettel n = (Nettel)ne.nextElement();						if (n.isCore()) n.setVisible(false);					}				}				continue; // Bynettet			}			Grp grp = new Grp(com, Integer.parseInt(s[0]), Boolean.valueOf(s[4]).booleanValue() );			grp.setName(s[1]);			grp.setIconName(s[5]);			{				int x = Integer.parseInt(s[2]);				int y = Integer.parseInt(s[3]);				if (x == 0 && y == 0) {					// Pen layout på topp					int[] topXY = topRowLayout(topLayoutCnt++);					x = topXY[0];					y = topXY[1];				}				grp.setXY(x, y);			}			group.addElement(grp);			com.d("   Added group (" + s[0] + "): " + s[1] + ", at ("+s[2]+","+s[3]+"), hideicons: " + s[4], 4);			for (int j = 4; j < s.length; j++)			{				if (!nh.containsKey(s[j])) continue;				Nettel n = (Nettel)nh.get(s[j]);				n.setGroupMember(true);				n.setGroup(Integer.parseInt(s[0]) );				grp.addMember(n);				com.d("     grp " + s[0] + ": " + n.getName(), 5);			}			grp.autoLayout();		}		com.getLeft().addNettNavn(null); // Listen blir sortert og lukket		setOverskrift(preHeader + com.getLeft().getNettNavn(visGruppe)); // Nå kan vi sette overskrift		// legg til linker		e = lRouterLinks.elements();		com.d("Antall linker     : " + lRouterLinks.size(), 2);		while (e.hasMoreElements())		{			String[] s = (String[])e.nextElement();			if (!nh.containsKey(s[0])) {				com.d("Error: Fant ikke boks med boksid: " + s[0], 3);				continue;			}			Nettel n = (Nettel)nh.get(s[0]);			com.d("  Legger til linker ut fra("+s[0]+"): " + n.getName() + " ("+(s.length-1)+" stk.)", 5);			for (int j = 1; j < s.length; j++)			{				String[] linkIdS = misc.tokenize(s[j], ",");				int linkId = Integer.parseInt(linkIdS[0] );				int boksId = Integer.parseInt(linkIdS[1] );				String[] linkInfo = (String[])lRouterLinkInfo.get(String.valueOf(linkId));				Double capacity = Double.valueOf(linkInfo[1] );				String ifName = (linkInfo.length >= 3) ? linkInfo[2] : "";				if (!nh.containsKey(""+boksId)) continue;				Nettel linkTo = (Nettel)nh.get(""+boksId);				com.d("    Link til ("+boksId+"): " + linkTo.getName() + "(linkId: "+linkId+")", 6);				// Dersom gruppe, sjekk om denne linken virkelig skal legges til				if (visGruppe > 0 && !lInGroup.containsKey(""+n.getBoksid()) && !lInGroup.containsKey(""+linkTo.getBoksid()) ) continue;				//com.d("from: " + n.getFullName() + " to: " + linkTo.getFullName() + " linkFrom: " + lInGroup.containsKey(""+n.getId()) + " linkTo: " + lInGroup.containsKey(""+linkTo.getId()),2);				Link l;				if (s[0].charAt(0) != '-')				{					// vanlig link					l = n.addLink( linkTo, linkId, capacity.doubleValue(), -1, ifName );				} else				{					if (hideCore && visGruppe == 0) continue;					// stam||elink					l = n.addLink( linkTo, linkId, capacity.doubleValue(), -1, ifName );					//l.setOspf(linkInfo[8]);					lh.put("-"+linkId, l);					l = linkTo.addLink( n, linkId, capacity.doubleValue(), -1, ifName );				}				lh.put(""+linkId, l);				//l.addIpRom(linkInfo[4], linkInfo[5], linkInfo[6], linkInfo[7] );				//l.setOspf(linkInfo[8]);			}		}		Hashtable lRouterText = (Hashtable)h.get("listBoksText");		Hashtable lRouterLinkText = (Hashtable)h.get("listLinkText");		if (APPLY_LAST_BYNETT) {			applyLast(lRouterText, lRouterLinkText);		}		applyText(lRouterText, lRouterLinkText);	}	private synchronized void applyText(Hashtable lRouterText, Hashtable lRouterLinkText)	{		// Så legger vi til tekst for alle bokser		String[] tList;		int tcnt=0;		//Hashtable lRouterText = (Hashtable)h.get("listBoksText");		while ( (tList = (String[])lRouterText.get("t"+tcnt)) != null) {			String text = tList[1];			for (int i=2; i < tList.length; i++) {				String[] data = (String[])lRouterText.get(tList[i]);				if (data == null) {					com.d("ERROR in buildBynett(), boksid "+tList[i]+" in t"+tcnt+" is not found in list, check vPServer", 2);					continue;				}				Nettel n = (Nettel)nh.get(tList[i]);				if (n == null) {					com.d("ERROR in buildBynett(), could not find boks with id "+tList[i], 2);

⌨️ 快捷键说明

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