ServiceFunctionListener extends AbstractDataTreeChangeListener<ServiceFunction> { @Override public void add(ServiceFunction serviceFunction) { if (serviceFunction != null) { LOG.debug("Adding Service Function: {}", serviceFunction.getName()); if (!SfcProviderServiceTypeAPI.createServiceFunctionTypeEntry(serviceFunction)) { LOG.error("Failed to create Service Function: ", serviceFunction.getName()); } } } ServiceFunctionListener(final DataBroker dataBroker); void init(); @Override void close(); @Override void add(ServiceFunction serviceFunction); @Override void remove(ServiceFunction serviceFunction);  }
@Test public void testOnServiceFunctionCreated() throws Exception { ServiceFunction serviceFunction = build_service_function(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.WRITE); when(dataObjectModification.getDataBefore()).thenReturn(null); when(dataObjectModification.getDataAfter()).thenReturn(serviceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); SftServiceFunctionName sftServiceFunctionName = SfcProviderServiceTypeAPI .readServiceFunctionTypeEntry(serviceFunction); assertNotNull(sftServiceFunctionName); assertEquals(sftServiceFunctionName.getName().getValue(), serviceFunction.getName().getValue()); assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(serviceFunction)); }
@Test public void testOnServiceFunctionRemoved() throws Exception { ServiceFunction serviceFunction = build_service_function(); assertTrue(SfcProviderServiceTypeAPI.createServiceFunctionTypeEntry(serviceFunction)); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.DELETE); when(dataObjectModification.getDataBefore()).thenReturn(serviceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(serviceFunction)); }
@Test public void testOnServiceFunctionUpdated() throws Exception { String UPDATED_IP_MGMT_ADDRESS = "196.168.55.102"; ServiceFunction originalServiceFunction = build_service_function(); assertTrue(SfcProviderServiceFunctionAPI.putServiceFunction(originalServiceFunction)); ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction); IpAddress updatedIpMgmtAddress = new IpAddress(new Ipv4Address(UPDATED_IP_MGMT_ADDRESS)); SftTypeName updatedType = new SftTypeName("dpi"); updatedServiceFunctionBuilder.setIpMgmtAddress(updatedIpMgmtAddress).setType(updatedType); ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunction); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction)); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction)); assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction)); Thread.sleep(500); assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction)); }
@Test public void testOnServiceFunctionRemovedWithRSP() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SfName sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName(); ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); assertNotNull(serviceFunction); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.DELETE); when(dataObjectModification.getDataBefore()).thenReturn(serviceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<RspName> rspNameList = SfcProviderServiceFunctionAPI.getRspsBySfName(serviceFunction.getName()); if (rspNameList != null) { for (RspName rspName : rspNameList) { assertNotEquals(rspName, renderedServicePath.getName()); } } assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionUpdatedWithRSP_updateIpMgmt() throws Exception { String UPDATED_IP_MGMT_ADDRESS = "196.168.55.112"; RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SfName sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName(); ServiceFunction originalServiceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); assertNotNull(originalServiceFunction); ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction); IpAddress updatedIpMgmtAddress = new IpAddress(new Ipv4Address(UPDATED_IP_MGMT_ADDRESS)); updatedServiceFunctionBuilder.setIpMgmtAddress(updatedIpMgmtAddress); ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunction); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction)); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction)); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction)); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<RspName> rspNameList = SfcProviderServiceFunctionAPI.getRspsBySfName(originalServiceFunction.getName()); if (rspNameList != null) { for (RspName rspName : rspNameList) { assertNotEquals(rspName, renderedServicePath.getName()); } } assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionUpdatedWithRSP_UpdateSfType() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SfName sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName(); ServiceFunction originalServiceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); assertNotNull(originalServiceFunction); ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction); updatedServiceFunctionBuilder.setType(new SftTypeName("dpi")); ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunction); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction)); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction)); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction)); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<RspName> rspNameList = SfcProviderServiceFunctionAPI.getRspsBySfName(originalServiceFunction.getName()); if (rspNameList != null) { for (RspName rspName : rspNameList) { assertNotEquals(rspName, renderedServicePath.getName()); } } assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionUpdatedWithRSP_UpdateDpl() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SfName sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName(); ServiceFunction originalServiceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); assertNotNull(originalServiceFunction); ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction); removeSfDpl(updatedServiceFunctionBuilder); ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunction); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction)); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction)); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction)); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<RspName> rspNameList = SfcProviderServiceFunctionAPI.getRspsBySfName(originalServiceFunction.getName()); if (rspNameList != null) { for (RspName rspName : rspNameList) { assertNotEquals(rspName, renderedServicePath.getName()); } } assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionUpdatedWithRSP_UpdateNoDeleteRsp() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SfName sfName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionName(); ServiceFunction originalServiceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); assertNotNull(originalServiceFunction); ServiceFunctionBuilder updatedServiceFunctionBuilder = new ServiceFunctionBuilder(originalServiceFunction); updatedServiceFunctionBuilder .setTenantId(new TenantId("EMPTY")) .setRestUri(new Uri("EMPTY")); ServiceFunction updatedServiceFunction = updatedServiceFunctionBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunction); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunction); collection.add(dataTreeModification); serviceFunctionListener.onDataTreeChanged(collection); Thread.sleep(500); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(originalServiceFunction)); assertNotNull(SfcProviderServiceTypeAPI.readServiceFunctionTypeEntry(updatedServiceFunction)); assertNotNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); assertTrue(SfcProviderServiceTypeAPI.deleteServiceFunctionTypeEntry(updatedServiceFunction)); assertTrue(SfcProviderRenderedPathAPI.deleteRenderedServicePath(renderedServicePath.getName())); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }