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

📄 ciscogw.java

📁 Network Administration Visualized 网络管理可视化源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		MultiMap prefixMap = util.reverse(ipMap);		boolean addedGwport = false;		if (prefixMap != null) {			Map netmaskMap = sSnmp.getAllMap(nb.getOid("ipAdEntIfNetMask"));			// Collect ospf			Map ospfMap = new HashMap();			String ospfOid = nb.getOid("ospfIfMetricMetric");			if (ospfOid != null) {				for (Iterator it = prefixMap.keySet().iterator(); it.hasNext();) {					String ifidx = (String)it.next();					String ifip = (String)prefixMap.get(ifidx).iterator().next();					List l = sSnmp.getAll(ospfOid+"."+ifip+".0.0", false, false);					if (l != null && !l.isEmpty()) ospfMap.put(ifidx, ((String[])l.get(0))[1]);				}			}						// From Mib-II			Map speedMap = sSnmp.getAllMap(nb.getOid("ifSpeed"));			Map highSpeedMap = sSnmp.getAllMap(nb.getOid("ifHighSpeed"));			//Map operStatusMap = sSnmp.getAllMap(nb.getOid("ifOperStatus"));			Map admStatusMap = sSnmp.getAllMap(nb.getOid("ifAdminStatus"));			/*  ifAlias = description					Hvis $netttype = 'lan' eller 'stam' : 					  lan,$org,$anv[$n,$kommentar,$vlan] 					Hvis $netttype = 'link': 					   link,$tilruter[,$kommentar,$vlan] 					Hvis $netttype = 'elink': 					   elink,$tilruter,$tilorg[,$kommentar,$vlan] 					$netttype = 'loopback' utgår, ingen description her.			*/			Map ifAliasMap = sSnmp.getAllMap(nb.getOid("ifAlias"), true);			Map ifDescrMap = sSnmp.getAllMap(nb.getOid("ifDescr"), true);			// Masterindex			Set masterinterfSet = new HashSet();			Map subinterfMap = new HashMap();			// Only create masterindex if inOctets = 0			Map ifInOctetsMap = sSnmp.getAllMap(nb.getOid("ifInOctets"));			// Create a reverse map for masterindex processing			MultiMap ifInterfMM = util.reverse(ifDescrMap);			// Find all masterinterfaces			for (Iterator it = ifDescrMap.entrySet().iterator(); it.hasNext();) {				Map.Entry me = (Map.Entry)it.next();				String ifindex = (String)me.getKey();				String interf = (String)me.getValue();				String masterinterf = interf.split("\\.")[0];				if (ifInOctetsMap.containsKey(ifindex) &&						Long.parseLong((String)ifInOctetsMap.get(ifindex)) == 0 &&						interf.indexOf(".") >= 0 &&						ifInterfMM.containsKey(masterinterf)) {										masterinterfSet.add(masterinterf);					subinterfMap.put(interf, masterinterf);				}			}			List l = sSnmp.getAll(nb.getOid("ifDescr"), true);			for (Iterator it = l.iterator(); it.hasNext();) {				String[] s = (String[])it.next();				String ifindex = s[0];				String interf = s[1];				if (!masterinterfSet.contains(interf) &&					(interf == null || interf.startsWith("EOBC") || interf.equals("Vlan0") ||					 !prefixMap.containsKey(ifindex))) continue;				// Ignore any admDown interfaces				String link = (String)admStatusMap.get(ifindex);				if (!"1".equals(link)) continue;				// Determine and create the module				int module = 1;				String modulePattern = ".*?(\\d+)/.*";				if (interf.matches(modulePattern)) {					Matcher m = Pattern.compile(modulePattern).matcher(interf);					m.matches();					module = Integer.parseInt(m.group(1));				} else {					boolean sup = false;					for (Iterator modIt = mc.getModules(); modIt.hasNext();) {						Module mod = (Module)modIt.next();						String modDescr = mod.getDescr();						if (modDescr != null && modDescr.toLowerCase().indexOf("supervisor") >= 0) {							module = mod.getModule();							sup = true;							break;						}					}					if (!sup) {						Log.w("CGW_MATCH-MODULE", "Supervisor not found and could not match module pattern to if: " + interf);					}					if (mc.getModule(module) == null && mc.getModule(0) != null) {						Log.w("CGW_MATCH-MODULE", "No module match from interf, defaulting to module 0");						module = 0;					}				}				if (mc.getModule(module) == null) {					// Create module 1					Log.w("CGW_MATCH-MODULE", "Module " + module + " does not exist on netbox " + nb.getSysname() + ", default to 1");					module = 1;					/*					// Not allowed to create module					Log.w("CGW_MATCH-MODULE", "Module " + module + " does not exist on netbox " + nb.getSysname() + ", skipping");					continue;					*/				}				GwModule gwm = gwc.gwModuleFactory(module);				String nettype = Vlan.UNKNOWN_NETTYPE;				/*				String netident = "null";				String orgid = "null";				String usageid = "null";				String vlan = "null";				String description = "null";				*/				String netident = null;				String orgid = null;				String usageid = null;				String vlan = null;				String description = null;				int convention = Vlan.CONVENTION_NTNU;				// Parse the description (ifAlias)				String descr = null;				if (ifAliasMap != null) {					descr = (String)ifAliasMap.get(ifindex);					try {						s = descr.split(",");						for (int i=0; i < s.length; i++) if (s[i] != null) s[i] = s[i].trim();						// Try to recognize NTNU description						// FIXME!!!! Nettype should be core when descr starts with stam or core						if (descr.startsWith("lan") || descr.startsWith("stam") || descr.startsWith("core")) {							nettype = "lan";							orgid = s[1];							usageid = s[2];							netident = orgid+","+usageid;							if (s.length >= 4) netident += ","+s[3];							if (s.length >= 5) description = s[4];							if (s.length >= 6) vlan = s[5];						} else if (descr.startsWith("link")) {							nettype = "link";							netident = nb.getSysname()+","+s[1];							if (s.length >= 3) description = s[2];							if (s.length >= 4) vlan = s[3];						} else if (descr.startsWith("elink")) {							nettype = "elink";							netident = nb.getSysname()+","+s[1];							orgid = s[2];							if (s.length >= 4) description = s[3];							if (s.length >= 5) vlan = s[4];						} else if (ifDescrMap.containsKey(ifindex) && ((String)ifDescrMap.get(ifindex)).startsWith("Loopback")) {							nettype = "loopback";						} else if (s.length > 1) {							// Interpret as UNINETT description							convention = Vlan.CONVENTION_UNINETT;							nettype = Vlan.UNKNOWN_NETTYPE;							netident = s[1];							description = s[0];						} else {							nettype = Vlan.UNKNOWN_NETTYPE;							netident = descr;						}					} catch (Exception e) {						Log.w("PROCESS_CGW", "Cannot parse ifAlias (ifindex " + ifindex + " on " + nb.getSysname() + "): " + descr);						nettype = Vlan.UNKNOWN_NETTYPE;						netident = descr;					}				}				String pattern = "Vlan(\\d+).*";				if (interf.matches(pattern)) {					Matcher m = Pattern.compile(pattern).matcher(interf);					m.matches();					vlan = m.group(1);				}				// Check that vlan is number:				if (vlan != null && !"null".equals(vlan) && !isNumber(vlan)) {					Log.w("PROCESS_CGW", "Vlan ("+vlan+") from ifAlias (ifindex " + ifindex + " on " + nb.getSysname() + ") is not a number");					vlan = null;				}				// Create Vlan				Vlan vl;				if (vlan != null && !"null".equals(vlan)) {					vl = gwm.vlanFactory(netident, Integer.parseInt(vlan));				} else {					vl = gwm.vlanFactory(netident);				}				vl.setNettype(nettype);				vl.setOrgid(orgid);				vl.setUsageid(usageid);				vl.setDescription(description);				vl.setConvention(convention);				// Create Gwport				Gwport gwp = gwm.gwportFactory(ifindex, (String)ifDescrMap.get(ifindex));				addedGwport = true;				// We can now ignore this ifindex as an swport				sc.ignoreSwport(ifindex);				// Set port name (ifAlias)				gwp.setPortname(descr);								// Set OSPF				if (ospfMap.containsKey(ifindex)) {					String ospf = (String)ospfMap.get(ifindex);					if (ospf == null || ospf.length() == 0) {						System.err.println("Error, ospf is empty for " + nb.getSysname() + " ifindex: " + ifindex);						Log.e("PROCESS_CGW", "OSPF is empty for " + nb.getSysname() + " ifindex: " + ifindex);					} else {						try {							gwp.setOspf(Integer.parseInt((String)ospfMap.get(ifindex)));						} catch (NumberFormatException e) {							System.err.println("Malformed OSPF: " + ospfMap.get(ifindex));						}					}				}				// Check if masterindex				if (subinterfMap.containsKey(interf)) {					gwp.setMasterinterf((String)subinterfMap.get(interf));				}				// Set speed from Mib-II				double speed;				// If the ifSpeed value is maxed out (a 32 bit unsigned value), get the speed value from ifHighSpeed (if available)				if (speedMap.containsKey(ifindex) && Long.parseLong((String)speedMap.get(ifindex)) == 4294967295L && highSpeedMap != null && highSpeedMap.containsKey(ifindex)) {					speed = Long.parseLong((String)highSpeedMap.get(ifindex));					Log.d("PROCESS_CGW", "Set gwport speed from ifHighSpeed for ifindex " + ifindex);				} else {					speed = speedMap.containsKey(ifindex) ? Long.parseLong((String)speedMap.get(ifindex)) / 1000000.0 : 0.0;				}				gwp.setSpeed(speed);				// Create prefices				for (Iterator prefixIt = prefixMap.get(ifindex).iterator(); prefixIt.hasNext();) {					String gwip = (String)prefixIt.next();					String mask = (String)netmaskMap.get(gwip);					boolean hsrp = hsrpIpMap != null && hsrpIpMap.containsKey( Prefix.ipToHex(gwip) );					Prefix p = gwp.prefixFactory(gwip, hsrp, mask, vl);				}							}		}		return addedGwport;	}	private static boolean isNumber(String s) {		try {			Integer.parseInt(s);		} catch (NumberFormatException e) {			return false;		}		return true;	}}

⌨️ 快捷键说明

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