SfcGeniusDataUtils { public static Optional<MacAddress> getServiceFunctionForwarderPortMacAddress(String ifName) { Interface theIf = SfcGeniusUtilsDataGetter.getServiceFunctionAttachedInterfaceState(ifName) .orElseThrow(() -> new RuntimeException("Interface is not present in the OPERATIONAL DS")); if (theIf.getPhysAddress() == null) { throw new RuntimeException( "Interface is present in the OPER DS, but it doesn't have a mac address"); } return Optional.of(new MacAddress(theIf.getPhysAddress().getValue())); } private  SfcGeniusDataUtils(); static Optional<MacAddress> getServiceFunctionMacAddress(String ifName); static Optional<MacAddress> getServiceFunctionForwarderPortMacAddress(String ifName); static boolean isSfUsingALogicalInterface(ServiceFunction sf); static String getSfLogicalInterface(ServiceFunction sf); static List<String> getInterfaceLowerLayerIf(String theIfName);  }
@Test public void readRemoteMacAddress() { Optional<MacAddress> mac = SfcGeniusDataUtils.getServiceFunctionForwarderPortMacAddress(ifName); Assert.assertTrue(mac.isPresent()); }
@Test(expected = RuntimeException.class) public void readRemoteMacAddressInterfaceDoesNotExist() { PowerMockito.when(SfcGeniusUtilsDataGetter.getServiceFunctionAttachedInterfaceState(ifName)).thenReturn(null); SfcGeniusDataUtils.getServiceFunctionForwarderPortMacAddress(ifName); }
@Test(expected = RuntimeException.class) public void readRemoteMacAddressPhysicalAddressDoesNotExists() { PowerMockito.when(SfcGeniusUtilsDataGetter.getServiceFunctionAttachedInterfaceState(ifName)) .thenReturn(Optional.of(new InterfaceBuilder() .setKey(new InterfaceKey(logicalIfName)) .setPhysAddress(null) .setLowerLayerIf(new ArrayList<String>() {{ add("openflow:79268612506848:1"); }}) .setType(L2vlan.class) .build())); SfcGeniusDataUtils.getServiceFunctionForwarderPortMacAddress(ifName); }