ServiceFunctionForwarderListener extends AbstractDataTreeChangeListener<ServiceFunctionForwarder> { @Override protected void add(ServiceFunctionForwarder serviceFunctionForwarder) { LOG.info("Adding Service Function Forwarder: {}", serviceFunctionForwarder.getName()); } ServiceFunctionForwarderListener(final DataBroker dataBroker); void init(); @Override void close();  }
@Test public void testOnServiceFunctionForwarderCreated() throws Exception { ServiceFunctionForwarder serviceFunctionForwarder = build_service_function_forwarder(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.WRITE); when(dataObjectModification.getDataBefore()).thenReturn(null); when(dataObjectModification.getDataAfter()).thenReturn(serviceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); }
@Test public void testOnServiceFunctionForwarderRemoved() throws Exception { ServiceFunctionForwarder serviceFunctionForwarder = build_service_function_forwarder(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.DELETE); when(dataObjectModification.getDataBefore()).thenReturn(serviceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); }
@Test public void testOnServiceFunctionForwarderRemovedWithRSP() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SffName sffName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionForwarder(); ServiceFunctionForwarder serviceFunctionForwarder = SfcProviderServiceForwarderAPI .readServiceFunctionForwarder(sffName); assertNotNull(serviceFunctionForwarder); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.DELETE); when(dataObjectModification.getDataBefore()).thenReturn(serviceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(2000); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNull(sffServicePathList); }
@Test public void testOnServiceFunctionForwarderUpdated_UpdateIpMgmt() throws Exception { String UPDATED_IP_MGMT_ADDRESS = "196.168.55.110"; RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SffName sffName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionForwarder(); ServiceFunctionForwarder originalServiceFunctionForwarder = SfcProviderServiceForwarderAPI .readServiceFunctionForwarder(sffName); assertNotNull(originalServiceFunctionForwarder); ServiceFunctionForwarderBuilder updatedServiceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder( originalServiceFunctionForwarder); IpAddress updatedIpMgmtAddress = new IpAddress(new Ipv4Address(UPDATED_IP_MGMT_ADDRESS)); updatedServiceFunctionForwarderBuilder.setIpMgmtAddress(updatedIpMgmtAddress); ServiceFunctionForwarder updatedServiceFunctionForwarder = updatedServiceFunctionForwarderBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionForwarder); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNull(sffServicePathList); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionForwarderUpdated_UpdateServiceNode() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SffName sffName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionForwarder(); ServiceFunctionForwarder originalServiceFunctionForwarder = SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sffName); assertNotNull(originalServiceFunctionForwarder); ServiceFunctionForwarderBuilder updatedServiceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(originalServiceFunctionForwarder); updatedServiceFunctionForwarderBuilder.setServiceNode(null); ServiceFunctionForwarder updatedServiceFunctionForwarder = updatedServiceFunctionForwarderBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionForwarder); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNull(sffServicePathList); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionForwarderUpdated_UpdateAddAndRemoveSfDict() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SffName sffName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionForwarder(); ServiceFunctionForwarder originalServiceFunctionForwarder = SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sffName); assertNotNull(originalServiceFunctionForwarder); ServiceFunctionForwarderBuilder updatedServiceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(originalServiceFunctionForwarder); addSfToSfDict(updatedServiceFunctionForwarderBuilder); ServiceFunctionForwarder updatedServiceFunctionForwarder = updatedServiceFunctionForwarderBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionForwarder); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(500); assertNotNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNotNull(sffServicePathList); updatedServiceFunctionForwarder = originalServiceFunctionForwarder; originalServiceFunctionForwarder = updatedServiceFunctionForwarderBuilder.build(); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionForwarder); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionForwarder); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(500); assertNotNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNotNull(sffServicePathList); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionForwarderUpdated_UpdateRemoveUsedSfDict() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SffName sffName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionForwarder(); ServiceFunctionForwarder originalServiceFunctionForwarder = SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sffName); assertNotNull(originalServiceFunctionForwarder); ServiceFunctionForwarderBuilder updatedServiceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(originalServiceFunctionForwarder); updatedServiceFunctionForwarderBuilder.setServiceFunctionDictionary(Collections.emptyList()); ServiceFunctionForwarder updatedServiceFunctionForwarder = updatedServiceFunctionForwarderBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionForwarder); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNull(sffServicePathList); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }
@Test public void testOnServiceFunctionForwarderUpdated_UpdateSffDpl() throws Exception { RenderedServicePath renderedServicePath = build_and_commit_rendered_service_path(); assertNotNull(renderedServicePath); SffName sffName = renderedServicePath.getRenderedServicePathHop().get(0).getServiceFunctionForwarder(); ServiceFunctionForwarder originalServiceFunctionForwarder = SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sffName); assertNotNull(originalServiceFunctionForwarder); ServiceFunctionForwarderBuilder updatedServiceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(originalServiceFunctionForwarder); removeSffDpl(updatedServiceFunctionForwarderBuilder); ServiceFunctionForwarder updatedServiceFunctionForwarder = updatedServiceFunctionForwarderBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionForwarder); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionForwarder); collection.add(dataTreeModification); serviceFunctionForwarderListener.onDataTreeChanged(collection); Thread.sleep(500); assertNull(SfcProviderRenderedPathAPI.readRenderedServicePath(renderedServicePath.getName())); List<SffServicePath> sffServicePathList = SfcProviderServiceForwarderAPI.readSffState(sffName); assertNull(sffServicePathList); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SF_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFC_IID, LogicalDatastoreType.CONFIGURATION)); assertTrue(SfcDataStoreAPI.deleteTransactionAPI(SfcInstanceIdentifiers.SFP_IID, LogicalDatastoreType.CONFIGURATION)); }