SfcGeniusDataUtils { public static String getSfLogicalInterface(ServiceFunction sf) { List<LogicalInterface> theDpls = Optional.ofNullable(sf) .map(SfcGeniusDataUtils::getSfLogicalInterfaceDataplaneLocators) .orElse(Collections.emptyList()); if (theDpls.size() == 1) { return theDpls.get(0).getInterfaceName(); } else { throw new IllegalArgumentException( String.format("We *must* have a single LogicalInterface locator. Got %d", theDpls.size())); } } 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(expected = IllegalArgumentException.class) public void getSfLogicalInterfaceNegativeTestNoDpl() { SfName sf1Name = new SfName("dpi"); String dpiIpAddress = "192.168.1.30"; ServiceFunctionKey dpiKey = new ServiceFunctionKey(sf1Name); List<SfDataPlaneLocator> dpLocators = new ArrayList<SfDataPlaneLocator>() { { add(new SfDataPlaneLocatorBuilder() .setKey(new SfDataPlaneLocatorKey(new SfDataPlaneLocatorName("dpi-1-dpl"))) .setServiceFunctionForwarder(new SffName("sfflogical1")) .build()); }}; ServiceFunction dpiNode = new ServiceFunctionBuilder() .setKey(dpiKey) .setIpMgmtAddress(new IpAddress(dpiIpAddress.toCharArray())) .setRestUri(new Uri(dpiIpAddress.concat(":5000"))) .setType(new SftTypeName("dpi")) .setSfDataPlaneLocator(dpLocators) .build(); SfcGeniusDataUtils.getSfLogicalInterface(dpiNode); }
@Test public void getSfLogicalInterface() { SfName sf1Name = new SfName("dpi"); String dpiIpAddress = "192.168.1.30"; ServiceFunctionKey dpiKey = new ServiceFunctionKey(sf1Name); List<SfDataPlaneLocator> dpLocators = new ArrayList<SfDataPlaneLocator>() { { add(new SfDataPlaneLocatorBuilder() .setKey(new SfDataPlaneLocatorKey(new SfDataPlaneLocatorName("dpi-1-dpl"))) .setServiceFunctionForwarder(new SffName("sfflogical1")) .setLocatorType(new LogicalInterfaceBuilder() .setInterfaceName("40c552e0-3695-472d-bace-7618786aba27").build()) .build()); }}; ServiceFunction dpiNode = new ServiceFunctionBuilder() .setKey(dpiKey) .setIpMgmtAddress(new IpAddress(dpiIpAddress.toCharArray())) .setRestUri(new Uri(dpiIpAddress.concat(":5000"))) .setType(new SftTypeName("dpi")) .setSfDataPlaneLocator(dpLocators) .build(); Assert.assertTrue(SfcGeniusDataUtils.isSfUsingALogicalInterface(dpiNode)); Assert.assertEquals("40c552e0-3695-472d-bace-7618786aba27", SfcGeniusDataUtils.getSfLogicalInterface(dpiNode)); }