/** Build a new Switch from a configuration file */ public Switch(String name, File fich) { super(); ports = new OurPort[MAX_PORT]; LineNumberReader lnr; String line = ""; list = new ArrayList(CAPACITY); if ((lnr = SyntaxAnalyz.find(fich, "switch", name)) != null) { try { this.name = name; for (line = lnr.readLine(); line != null && !line.startsWith("["); line = lnr.readLine()) { if (line.startsWith("admin-port:")) this.admin_port = SyntaxAnalyz.readAdminPort(line); else if (line.startsWith("priority:")) this.priority = SyntaxAnalyz.readPriority(line); else if (line.startsWith("MAC-address:")) this.mac_address = SyntaxAnalyz.readMac(line); else if (line.startsWith("port-")) addPorts(line); } } catch (IOException e) { System.err.println("probleme d'E/S dans la construnction du switch " + name); } runAdmin(); } else System.err.println( "Switch <" + name + "> introuvable dans le fichier <" + fich.getAbsolutePath() + ">"); }
/** * Add a new port to the switch * * @param line the line of the configuration file containing the port information */ private void addPorts(String line) { String token = null; int i; try { if (line.startsWith("port-")) { StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { token = st.nextToken(); String tmp = token.substring("port-".length(), token.length() - 1); i = Integer.parseInt(tmp); if (st.hasMoreTokens()) { token = st.nextToken(); InetSocketAddress isa = SyntaxAnalyz.parseISA(token); setPort(i, new OurPort(isa, this)); } } } } catch (NumberFormatException e) { System.err.println("format incorrect : <" + token + "> n\'est pas un nombre ?"); } catch (IOException e) { System.err.println("Erreur d'entree sortie pendant l\'ajout d\'un port "); } }