SfcSffToOvsMappingAPI { public static OvsdbBridgeAugmentation buildOvsdbBridgeAugmentation( ServiceFunctionForwarder serviceFunctionForwarder, ExecutorService executor) { Preconditions.checkNotNull(serviceFunctionForwarder); OvsdbBridgeAugmentationBuilder ovsdbBridgeBuilder = new OvsdbBridgeAugmentationBuilder(); SffOvsBridgeAugmentation serviceForwarderOvsBridgeAugmentation = serviceFunctionForwarder.getAugmentation(SffOvsBridgeAugmentation.class); if (serviceForwarderOvsBridgeAugmentation != null) { OvsBridge serviceForwarderOvsBridge = serviceForwarderOvsBridgeAugmentation.getOvsBridge(); if (serviceForwarderOvsBridge != null) { ovsdbBridgeBuilder.setBridgeName(new OvsdbBridgeName(serviceForwarderOvsBridge.getBridgeName())); ovsdbBridgeBuilder.setBridgeUuid(serviceForwarderOvsBridge.getUuid()); } else { LOG.info("Cannot build OvsdbBridgeAugmentation. Missing OVS Bridge augmentation on SFF {}", serviceFunctionForwarder.getName()); return null; } } else { LOG.info("Cannot build OvsdbBridgeAugmentation. Missing OVS Bridge augmentation on SFF {}", serviceFunctionForwarder.getName()); return null; } SffOvsNodeAugmentation serviceForwarderOvsNodeAugmentation = serviceFunctionForwarder.getAugmentation(SffOvsNodeAugmentation.class); if (serviceForwarderOvsNodeAugmentation != null) { OvsNode serviceForwarderOvsNode = serviceForwarderOvsNodeAugmentation.getOvsNode(); if (serviceForwarderOvsNode != null) { ovsdbBridgeBuilder.setManagedBy(serviceForwarderOvsNode.getNodeId()); OvsdbNodeAugmentation ovsdbNodeAugmentation = SfcOvsUtil.getOvsdbNodeAugmentation(serviceForwarderOvsNode.getNodeId(), executor); if (ovsdbNodeAugmentation != null) { ovsdbBridgeBuilder.setControllerEntry(getControllerEntries(ovsdbNodeAugmentation)); } } else { LOG.info("Cannot build OvsdbBridgeAugmentation. Missing OVS Node augmentation on SFF {}", serviceFunctionForwarder.getName()); return null; } } else { Node node = SfcOvsUtil.lookupTopologyNode(serviceFunctionForwarder, executor); if (node == null || node.getNodeId() == null) { LOG.info("Cannot build OvsdbBridgeAugmentation. Missing OVS Node augmentation on SFF {}", serviceFunctionForwarder.getName()); return null; } OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(SfcOvsUtil.buildOvsdbNodeIID(node.getNodeId())); ovsdbBridgeBuilder.setManagedBy(ovsdbNodeRef); OvsdbNodeAugmentation ovsdbNodeAugmentation = SfcOvsUtil.getOvsdbNodeAugmentation(ovsdbNodeRef, executor); if (ovsdbNodeAugmentation != null) { ovsdbBridgeBuilder.setControllerEntry(getControllerEntries(ovsdbNodeAugmentation)); } } return ovsdbBridgeBuilder.build(); }  static OvsdbBridgeAugmentation buildOvsdbBridgeAugmentation(
            ServiceFunctionForwarder serviceFunctionForwarder, ExecutorService executor); static List<OvsdbTerminationPointAugmentation> buildTerminationPointAugmentationList(
            List<SffDataPlaneLocator> sffDataPlaneLocatorList);  }
@Test public void testBuildOvsdbBridgeAugmentation_NullOvsBridgeAugmentation() throws Exception { serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); ovsdbBridgeAugmentation = SfcSffToOvsMappingAPI.buildOvsdbBridgeAugmentation(serviceFunctionForwarderBuilder.build(), executor); assertNull("Must be null", ovsdbBridgeAugmentation); }
@Test public void testBuildOvsdbBridgeAugmentation_NullOvsBridge() throws Exception { serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); sffOvsBridgeAugmentationBuilder = new SffOvsBridgeAugmentationBuilder(); sffOvsBridgeAugmentationBuilder.setOvsBridge(null); serviceFunctionForwarderBuilder.addAugmentation(SffOvsBridgeAugmentation.class, sffOvsBridgeAugmentationBuilder.build()); ovsdbBridgeAugmentation = SfcSffToOvsMappingAPI.buildOvsdbBridgeAugmentation(serviceFunctionForwarderBuilder.build(), executor); assertNull("Must be null", ovsdbBridgeAugmentation); }
@Test public void testBuildOvsdbBridgeAugmentation_NullOvsNode() throws Exception { ovsBridgeBuilder = new OvsBridgeBuilder(); serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); sffOvsNodeAugmentationBuilder = new SffOvsNodeAugmentationBuilder(); sffOvsBridgeAugmentationBuilder = new SffOvsBridgeAugmentationBuilder(); ovsBridgeBuilder.setBridgeName(bridgeName).setUuid(new Uuid(uuid)); sffOvsBridgeAugmentationBuilder.setOvsBridge(ovsBridgeBuilder.build()); serviceFunctionForwarderBuilder.setName(new SffName(testString)) .addAugmentation(SffOvsBridgeAugmentation.class, sffOvsBridgeAugmentationBuilder.build()) .addAugmentation(SffOvsNodeAugmentation.class, sffOvsNodeAugmentationBuilder.build()); ovsdbBridgeAugmentation = SfcSffToOvsMappingAPI.buildOvsdbBridgeAugmentation(serviceFunctionForwarderBuilder.build(), executor); assertNull("Must be null", ovsdbBridgeAugmentation); }
@Test public void testBuildOvsdbBridgeAugmentation_nullNode() throws Exception { ovsBridgeBuilder = new OvsBridgeBuilder(); ovsdbNodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder(); serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); sffOvsBridgeAugmentationBuilder = new SffOvsBridgeAugmentationBuilder(); connectionInfoBuilder = new ConnectionInfoBuilder(); connectionInfoBuilder.setLocalIp(new IpAddress(new Ipv4Address(OVSDB_OPTION_LOCAL_IP_VALUE))); ovsdbNodeAugmentationBuilder.setConnectionInfo(connectionInfoBuilder.build()); ovsBridgeBuilder.setBridgeName(bridgeName).setUuid(new Uuid(uuid)); sffOvsBridgeAugmentationBuilder.setOvsBridge(ovsBridgeBuilder.build()); serviceFunctionForwarderBuilder.setName(new SffName(testString)).addAugmentation(SffOvsBridgeAugmentation.class, sffOvsBridgeAugmentationBuilder.build()); PowerMockito.stub(PowerMockito.method(SfcOvsUtil.class, "getOvsdbNodeAugmentation")) .toReturn(ovsdbNodeAugmentationBuilder.build()); ovsdbBridgeAugmentation = SfcSffToOvsMappingAPI.buildOvsdbBridgeAugmentation(serviceFunctionForwarderBuilder.build(), executor); assertNull("Must be null", ovsdbBridgeAugmentation); }
@Test public void testBuildOvsdbBridgeAugmentation1() throws Exception { ovsBridgeBuilder = new OvsBridgeBuilder(); ovsdbNodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder(); serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); sffOvsBridgeAugmentationBuilder = new SffOvsBridgeAugmentationBuilder(); connectionInfoBuilder = new ConnectionInfoBuilder(); NodeBuilder nodeBuilder = new NodeBuilder(); connectionInfoBuilder.setLocalIp(new IpAddress(new Ipv4Address(OVSDB_OPTION_LOCAL_IP_VALUE))); ovsdbNodeAugmentationBuilder.setConnectionInfo(connectionInfoBuilder.build()); ovsBridgeBuilder.setBridgeName(bridgeName).setUuid(new Uuid(uuid)); sffOvsBridgeAugmentationBuilder.setOvsBridge(ovsBridgeBuilder.build()); serviceFunctionForwarderBuilder.setName(new SffName(testString)).addAugmentation(SffOvsBridgeAugmentation.class, sffOvsBridgeAugmentationBuilder.build()); nodeBuilder.setNodeId(new NodeId("NodeId")); PowerMockito.stub(PowerMockito.method(SfcOvsUtil.class, "getOvsdbNodeAugmentation")) .toReturn(ovsdbNodeAugmentationBuilder.build()); PowerMockito.stub(PowerMockito.method(SfcOvsUtil.class, "lookupTopologyNode")).toReturn(nodeBuilder.build()); ovsdbBridgeAugmentation = SfcSffToOvsMappingAPI.buildOvsdbBridgeAugmentation(serviceFunctionForwarderBuilder.build(), executor); assertNotNull("Must not be null", ovsdbBridgeAugmentation); assertEquals("Must be equal", ovsdbBridgeAugmentation.getBridgeName().getValue(), bridgeName); assertEquals("Must be equal", ovsdbBridgeAugmentation.getBridgeUuid().getValue(), uuid); }
@Test public void testBuildOvsdbBridgeAugmentation2() throws Exception { ovsBridgeBuilder = new OvsBridgeBuilder(); OvsNodeBuilder ovsNodeBuilder = new OvsNodeBuilder(); ovsdbNodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder(); serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); sffOvsNodeAugmentationBuilder = new SffOvsNodeAugmentationBuilder(); sffOvsBridgeAugmentationBuilder = new SffOvsBridgeAugmentationBuilder(); connectionInfoBuilder = new ConnectionInfoBuilder(); connectionInfoBuilder.setLocalIp(new IpAddress(new Ipv4Address(OVSDB_OPTION_LOCAL_IP_VALUE))); ovsdbNodeAugmentationBuilder.setConnectionInfo(connectionInfoBuilder.build()); ovsBridgeBuilder.setBridgeName(bridgeName).setUuid(new Uuid(uuid)); sffOvsBridgeAugmentationBuilder.setOvsBridge(ovsBridgeBuilder.build()); ovsNodeBuilder.setNodeId(new OvsdbNodeRef(SfcOvsUtil.buildOvsdbNodeIID(testString))); sffOvsNodeAugmentationBuilder.setOvsNode(ovsNodeBuilder.build()); serviceFunctionForwarderBuilder.setName(new SffName(testString)) .addAugmentation(SffOvsBridgeAugmentation.class, sffOvsBridgeAugmentationBuilder.build()) .addAugmentation(SffOvsNodeAugmentation.class, sffOvsNodeAugmentationBuilder.build()); PowerMockito.stub(PowerMockito.method(SfcOvsUtil.class, "getOvsdbNodeAugmentation")) .toReturn(ovsdbNodeAugmentationBuilder.build()); ovsdbBridgeAugmentation = SfcSffToOvsMappingAPI.buildOvsdbBridgeAugmentation(serviceFunctionForwarderBuilder.build(), executor); assertNotNull("Must not be null", ovsdbBridgeAugmentation); assertEquals("Must be equal", ovsdbBridgeAugmentation.getBridgeName().getValue(), bridgeName); assertEquals("Must be equal", ovsdbBridgeAugmentation.getBridgeUuid().getValue(), uuid); assertEquals("Must be equal", ovsdbBridgeAugmentation.getControllerEntry().get(0).getTarget().getValue(), "tcp:" + OVSDB_OPTION_LOCAL_IP_VALUE + ":6653"); }