--- ../tmp/nav-3.1.0/src/getDeviceData/device-plugins/3Com/src/no/ntnu/nav/getDeviceData/deviceplugins/_3Com/_3Com.java	Fri Mar 10 13:12:12 2006
+++ ./src/getDeviceData/device-plugins/3Com/src/no/ntnu/nav/getDeviceData/deviceplugins/_3Com/_3Com.java	Fri Sep  1 12:25:48 2006
@@ -191,6 +191,7 @@
 
 		*/
 
+		Set matchIfindex = new HashSet();
 		// (type.equals("off8") || type.equals("ps40")) {
 		{
 			// OID: 1.3.6.1.2.1.26.1.1.1.6.<modul>.<port>.1 = 3|4
@@ -295,6 +296,7 @@
 			}
 		}
 
+		ArrayList maybeTrunkVlindex = new ArrayList();
  		// Fetch ifDescr
 		List ifDescrList = sSnmp.getAll(nb.getOid("3cIfDescr"), true);
 		if (ifDescrList != null) {
@@ -302,6 +304,7 @@
 				String[] s = (String[])it.next();
 				String ifindex = s[0];
 				String ifdescr = s[1];
+				matchIfindex.add(s[0]);
 
 				// Use regex for extracting unit and port
 				String port = null;
@@ -309,6 +312,10 @@
 					String k = extractPortFromDescr(ifdescr);
 					if (k != null) port = k;
 				}
+				{
+				    String k = extractTrunkFromDescr(ifdescr); // for 3300, not 4200
+				    if (k != null) maybeTrunkVlindex.add(s[0]);
+				}
 
 				int module = 1;
 				{
@@ -422,6 +429,108 @@
 			}
 		}
 
+		/*
+		l = sSnmp.getAll(nb.getOid("3cifVlan")); // bare for 4200, vil erstattes av generisk 3com
+		if (l != null) {
+			for (Iterator it = l.iterator(); it.hasNext();) {
+				String[] s = (String[])it.next();
+				String ifindex = s[0];
+				if (!matchIfindex.contains(ifindex)) continue;
+				int vlan = 0;
+				try{
+					vlan = Integer.parseInt(s[1]);
+				} catch	 (NumberFormatException e) {
+					Log.w("PROCESS_3COM", "netboxid: " + netboxid + " ifindex: " + s[0] + " NumberFormatException on vlan: " + s[1]);
+				}
+				sc.swportFactory(ifindex).setVlan(vlan);
+			}
+		}
+		*/
+
+		// 3com support for 3com vlan port probe by roart
+
+		ArrayList Vlindex = new ArrayList();
+		l = sSnmp.getAll(nb.getOid("3cVlanIndex"));
+		if (l != null) {
+			for (Iterator it = l.iterator(); it.hasNext();) {
+			    String[] s = (String[])it.next();
+			    Vlindex.add(s);
+			}
+		}
+
+		boolean is_3300_or_something = false;
+
+		if (maybeTrunkVlindex != null) { // for 3300 at least. not 4200
+		    for (Iterator it = maybeTrunkVlindex.iterator(); it.hasNext();) {
+			String s = (String)it.next();
+			l = sSnmp.getAll(nb.getOid("ifStackEntry")+"."+s); 
+			if (l != null) {
+			    for (Iterator it2 = l.iterator(); it2.hasNext();) {
+				String[] s2 = (String[])it2.next();
+				String ifindex = s2[0];
+				sc.swportFactory(ifindex).setTrunk(true);
+				is_3300_or_something = true;
+			    }
+			}
+		    }
+		}
+
+		HashMap portMap = new HashMap();
+		if (Vlindex != null) {
+		    for (Iterator it = Vlindex.iterator(); it.hasNext();) {
+			String[] s = (String[])it.next();
+			int vlan = Integer.parseInt(s[0]);
+			String index = s[1];
+			l = sSnmp.getAll(nb.getOid("ifStackEntry")+"."+index); 
+			if (l != null) {
+			    for (Iterator it2 = l.iterator(); it2.hasNext();) {
+				String[] s2 = (String[])it2.next();
+				String ifindex = s2[0];
+				if (!is_3300_or_something) {
+				    Matcher m = Pattern.compile("[0-9][0-9][0-9][0-9][0-9]").matcher(ifindex);
+				    if (m.find()) {
+					List l2 = sSnmp.getAll(nb.getOid("ifStackEntry")+"."+ifindex);
+					if (l2 != null) {
+					    for (Iterator it3 = l2.iterator(); it3.hasNext();) {
+						String[] s3 = (String[])it3.next();
+						ifindex = s3[0];
+					    }
+					}
+				    }
+				}
+				if (portMap.containsKey(ifindex)) {
+				    Object objval = portMap.get(ifindex);
+				    Integer val = ((Integer) objval);
+				    int intval = val.intValue();
+				    Integer newval = new Integer(intval + 1);
+				    portMap.put(ifindex, newval);
+				} else
+				    portMap.put(ifindex, new Integer(1));
+				Swport swp = sc.swportFactory(ifindex); // here
+				if (!swp.getTrunk().booleanValue()) swp.setVlan(vlan); // where is this?
+				Log.w("PROCESS_3COM", "netboxid: " + netboxid + " ifindex: " + ifindex + " vlan: " + vlan);
+			    }
+			}
+		    }
+		}
+		if (portMap != null) {
+		    Set portSet = portMap.keySet();
+		    if (portSet != null) {
+			for (Iterator it4 = portSet.iterator(); it4.hasNext();) {
+			    String s4 = (String)it4.next();
+			    //			    String s5 = portMap.get(s4);
+			    //			    Integer I = new Integer.parseInt(s5);
+			    Object objval = portMap.get(s4);
+			    Integer val = ((Integer) objval);
+			    int value = val.intValue();
+			    /*String value =*/
+			    if (value == Vlindex.size()) {
+				Log.w("PROCESS_3COM", "netboxid: " + netboxid + " ifindex: " + s4 + " trunk true");
+				sc.swportFactory(s4).setTrunk(true);
+			    }
+			}
+		    }
+		}
 	}
 
 	private int extractModuleFromDescr(String ifdescr) {
@@ -432,6 +541,12 @@
 
 	private String extractPortFromDescr(String ifdescr) {
 		Matcher m = Pattern.compile("Port +(\\d+)\\b").matcher(ifdescr);
+		if (m.find()) return m.group(1);
+		return null;
+	}
+
+	private String extractTrunkFromDescr(String ifdescr) {
+		Matcher m = Pattern.compile("Trunk +(\\d+)\\b").matcher(ifdescr);
 		if (m.find()) return m.group(1);
 		return null;
 	}
