IosXeRspProcessor { public void updateRsp(RenderedServicePath renderedServicePath) { RspStatus status = new RspStatus(dataBroker, renderedServicePath.getName()); status.writeStatus(InProgress); Preconditions.checkNotNull(renderedServicePath); Long pathId = renderedServicePath.getPathId(); Short serviceIndex = renderedServicePath.getStartingIndex(); DataBroker previousMountPoint; DataBroker currentMountpoint; SffName previousSffName; SffName currentSffName; if (renderedServicePath.getRenderedServicePathHop() == null || renderedServicePath.getRenderedServicePathHop().isEmpty()) { LOG.warn("Rendered path {} does not contain any hop", renderedServicePath.getName().getValue()); status.writeStatus(Failure); return; } Iterator<RenderedServicePathHop> rspHopIterator = renderedServicePath.getRenderedServicePathHop() .iterator(); RenderedServicePathHop hop = rspHopIterator.next(); currentSffName = hop.getServiceFunctionForwarder(); currentMountpoint = getSffMountpoint(currentSffName); if (currentMountpoint == null) { LOG.error("Resolving of RSP {} failed, mountpoint for SFF {} is null", renderedServicePath.getName() .getValue(), currentSffName.getValue()); deleteRsp(renderedServicePath); status.writeStatus(Failure); return; } List<Services> services = new ArrayList<>(); SfName sfName = hop.getServiceFunctionName(); ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); if (serviceFunction == null) { LOG.error("Service function {} not present in datastore", sfName.getValue()); return; } ServiceTypeChoice serviceTypeChoice = buildServiceFunctionChoice(serviceFunction); Services serviceEntry = createServicesEntry(serviceIndex, serviceTypeChoice); services.add(serviceEntry); serviceIndex--; while (rspHopIterator.hasNext()) { hop = rspHopIterator.next(); previousSffName = currentSffName; currentSffName = hop.getServiceFunctionForwarder(); if (previousSffName.equals(currentSffName)) { sfName = hop.getServiceFunctionName(); serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); if (serviceFunction == null) { LOG.error("Service function {} not present in datastore", sfName.getValue()); return; } serviceTypeChoice = buildServiceFunctionChoice(serviceFunction); serviceEntry = createServicesEntry(serviceIndex, serviceTypeChoice); services.add(serviceEntry); serviceIndex--; } else { previousMountPoint = currentMountpoint; currentSffName = hop.getServiceFunctionForwarder(); currentMountpoint = getSffMountpoint(currentSffName); if (currentMountpoint == null) { LOG.error("Resolving of RSP {} failed, mountpoint for SFF {} is null", renderedServicePath.getName() .getValue(), currentSffName.getValue()); deleteRsp(renderedServicePath); status.writeStatus(Failure); return; } ServiceFfName currentRemoteForwarder = SfcIosXeUtils.createRemoteForwarder(currentSffName); if (currentRemoteForwarder == null) { LOG.error("SFF {} ip address is null", currentSffName.getValue()); deleteRsp(renderedServicePath); status.writeStatus(Failure); return; } new IosXeDataStoreAPI(previousMountPoint, currentRemoteForwarder, WRITE_REMOTE, LogicalDatastoreType.CONFIGURATION).call(); serviceTypeChoice = buildServiceFunctionForwarderChoice(currentSffName.getValue()); serviceEntry = createServicesEntry(serviceIndex, serviceTypeChoice); services.add(serviceEntry); ServicePath servicePath = createServicePath(pathId, services); new IosXeDataStoreAPI(previousMountPoint, servicePath, WRITE_PATH, LogicalDatastoreType.CONFIGURATION).call(); services = new ArrayList<>(); sfName = hop.getServiceFunctionName(); serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); if (serviceFunction == null) { LOG.error("Service function {} not present in datastore", sfName.getValue()); return; } serviceTypeChoice = buildServiceFunctionChoice(serviceFunction); serviceEntry = createServicesEntry(serviceIndex, serviceTypeChoice); services.add(serviceEntry); serviceIndex--; } } serviceTypeChoice = buildTerminateChoice(); serviceEntry = createServicesEntry(serviceIndex, serviceTypeChoice); services.add(serviceEntry); ServicePath servicePath = createServicePath(pathId, services); new IosXeDataStoreAPI(currentMountpoint, servicePath, WRITE_PATH, LogicalDatastoreType.CONFIGURATION).call(); LOG.info("Rendered service path {} successfully processed", renderedServicePath.getName().getValue()); status.writeStatus(Success); } IosXeRspProcessor(DataBroker dataBroker, NodeManager nodeManager); void updateRsp(RenderedServicePath renderedServicePath); void deleteRsp(RenderedServicePath renderedServicePath); void unregisterRspListener();  }
@Test public void updateRsp() { when(nodeManager.getMountpointFromIpAddress(new IpAddress(new Ipv4Address(mgmtIp)))).thenReturn(dataBroker); IosXeRspProcessor processor = new IosXeRspProcessor(dataBroker, nodeManager); processor.updateRsp(createTestRenderedServicePath()); verify(nodeManager, times(1)).getMountpointFromIpAddress(new IpAddress(new Ipv4Address(mgmtIp))); ServicePath servicePath = (ServicePath) new IosXeDataStoreAPI(dataBroker, new ServicePathKey(10L), READ_PATH, LogicalDatastoreType.CONFIGURATION).call(); assertNotNull(servicePath); ConfigServiceChainPathMode chainPathMode = servicePath.getConfigServiceChainPathMode(); assertTrue(chainPathMode.getServiceIndex().getServices().size() == 4); }