@Test void getInterfaceByPort() throws IOException { assertEquals(ovs.getInterfaceByPort(1), "faux"); assertEquals(ovs.getInterfaceByPort(2), "faux-2"); assertEquals(ovs.getInterfaceByPort(7), "sec-eth7"); }
protected String getInterfaceByPort(int devicePort) throws IOException { URL file = OpenVSwitch.class.getClassLoader().getResource(OVS_OUTPUT_FILE); if (file == null) { throw new FileNotFoundException(OVS_OUTPUT_FILE + " is not found!"); } FileReader reader = new FileReader(file.getFile()); try (BufferedReader bufferedReader = new BufferedReader(reader)) { Pattern pattern = Pattern.compile("(^\\s*" + devicePort + ")(\\((.+)\\))(:.*)", 'g'); String interfaceLine = bufferedReader.lines().filter(line -> { Matcher m = pattern.matcher(line); return m.find(); }).findFirst().get(); Matcher m = pattern.matcher(interfaceLine); m.matches(); return m.group(3); } }
OpenVSwitch implements SwitchController { protected String getInterfaceByPort(int devicePort) throws IOException { URL file = OpenVSwitch.class.getClassLoader().getResource(OVS_OUTPUT_FILE); if (file == null) { throw new FileNotFoundException(OVS_OUTPUT_FILE + " is not found!"); } FileReader reader = new FileReader(file.getFile()); try (BufferedReader bufferedReader = new BufferedReader(reader)) { Pattern pattern = Pattern.compile("(^\\s*" + devicePort + ")(\\((.+)\\))(:.*)", 'g'); String interfaceLine = bufferedReader.lines().filter(line -> { Matcher m = pattern.matcher(line); return m.find(); }).findFirst().get(); Matcher m = pattern.matcher(interfaceLine); m.matches(); return m.group(3); } } }
OpenVSwitch implements SwitchController { protected String getInterfaceByPort(int devicePort) throws IOException { URL file = OpenVSwitch.class.getClassLoader().getResource(OVS_OUTPUT_FILE); if (file == null) { throw new FileNotFoundException(OVS_OUTPUT_FILE + " is not found!"); } FileReader reader = new FileReader(file.getFile()); try (BufferedReader bufferedReader = new BufferedReader(reader)) { Pattern pattern = Pattern.compile("(^\\s*" + devicePort + ")(\\((.+)\\))(:.*)", 'g'); String interfaceLine = bufferedReader.lines().filter(line -> { Matcher m = pattern.matcher(line); return m.find(); }).findFirst().get(); Matcher m = pattern.matcher(interfaceLine); m.matches(); return m.group(3); } }  }
OpenVSwitch implements SwitchController { protected String getInterfaceByPort(int devicePort) throws IOException { URL file = OpenVSwitch.class.getClassLoader().getResource(OVS_OUTPUT_FILE); if (file == null) { throw new FileNotFoundException(OVS_OUTPUT_FILE + " is not found!"); } FileReader reader = new FileReader(file.getFile()); try (BufferedReader bufferedReader = new BufferedReader(reader)) { Pattern pattern = Pattern.compile("(^\\s*" + devicePort + ")(\\((.+)\\))(:.*)", 'g'); String interfaceLine = bufferedReader.lines().filter(line -> { Matcher m = pattern.matcher(line); return m.find(); }).findFirst().get(); Matcher m = pattern.matcher(interfaceLine); m.matches(); return m.group(3); } }  @Override void getPower(int devicePort, ResponseHandler<PowerResponse> handler); @Override void getInterface(int devicePort, ResponseHandler<InterfaceResponse> handler); @Override void connect(int devicePort, ResponseHandler<SwitchActionResponse> handler); @Override void disconnect(int devicePort, ResponseHandler<SwitchActionResponse> handler); void start(); }
OpenVSwitch implements SwitchController { protected String getInterfaceByPort(int devicePort) throws IOException { URL file = OpenVSwitch.class.getClassLoader().getResource(OVS_OUTPUT_FILE); if (file == null) { throw new FileNotFoundException(OVS_OUTPUT_FILE + " is not found!"); } FileReader reader = new FileReader(file.getFile()); try (BufferedReader bufferedReader = new BufferedReader(reader)) { Pattern pattern = Pattern.compile("(^\\s*" + devicePort + ")(\\((.+)\\))(:.*)", 'g'); String interfaceLine = bufferedReader.lines().filter(line -> { Matcher m = pattern.matcher(line); return m.find(); }).findFirst().get(); Matcher m = pattern.matcher(interfaceLine); m.matches(); return m.group(3); } }  @Override void getPower(int devicePort, ResponseHandler<PowerResponse> handler); @Override void getInterface(int devicePort, ResponseHandler<InterfaceResponse> handler); @Override void connect(int devicePort, ResponseHandler<SwitchActionResponse> handler); @Override void disconnect(int devicePort, ResponseHandler<SwitchActionResponse> handler); void start();  }