/** * Generate pathid, check and allocate if available * * <p> * @return True if allocated, otherwise false. */ public static long check_and_allocate_pathid() { if (SfcConcurrencyAPI.getPathIdLock()) { try { long pathId = -1; GenerationAlgorithmEnum genAlg = getGenerationAlgorithm(); if(genAlg == GenerationAlgorithmEnum.Random) { pathId = generatePathIdRandomIncrements(); } else if(genAlg == GenerationAlgorithmEnum.Sequential) { pathId = generatePathIdSequentialIncrements(); } if ((pathId >= MIN_PATH_ID) && allocate_pathid(pathId)) { return pathId; } else { return -1; } } finally { SfcConcurrencyAPI.releasePathIdLock(); } } else { return -1; } }
try { long symmetric_id = -1; GenerationAlgorithmEnum genAlg = getGenerationAlgorithm(); if(genAlg == GenerationAlgorithmEnum.Random) { symmetric_id = pathid ^ (1 << 23); if(!check_suitable_pathid(symmetric_id)) { symmetric_id = -1; symmetric_id = generatePathIdSequentialIncrements(); if ((symmetric_id >= MIN_PATH_ID) && allocate_pathid(symmetric_id)) { return symmetric_id; } else {
/** * Set the PathId Generate-algorithm in the data-store. * * <p> * @param genAlgorithm integer value as taken from service-path-id.yang * @return True if successful, otherwise false */ public static boolean setGenerationAlgorithm(int genAlgorithm) { return setGenerationAlgorithm(GenerationAlgorithmEnum.forValue(genAlgorithm)); }
/** * Algorithm to sequentially generate pathIds. * * <p> * @return Pathid or error if none available */ public static int generatePathIdSequentialIncrements() { int pathid; int count = num_pathid; do { next_pathid = next_pathid + 1; pathid = MIN_PATH_ID + next_pathid; if (check_suitable_pathid(pathid) && allocate_pathid(pathid)) { return pathid; } count--; } while (count > 0); return -1; }
/** * Algorithm to randomize the generation of pathIds. Provides * security by making path-id less predictable. Adapted * from NAT port allocation algorithm * * <p> * @return Pathid or error if none available */ public static int generatePathIdRandomIncrements() { int pathid; int count = num_pathid; do { next_pathid = next_pathid + (randomGenerator.nextInt(num_pathid) % N) + 1; pathid = MIN_PATH_ID + (next_pathid % num_pathid); if (check_suitable_pathid(pathid)) { return pathid; } count--; } while (count > 0); return -1; }
ret = true; SfcServicePathId.free_pathid(pathId); } else { LOG.error("{}: Failed to delete RSP: {}", Thread.currentThread().getStackTrace()[1],
List<RenderedServicePathHop> revRenderedServicePathHopArrayList = new ArrayList<>(); long pathId = SfcServicePathId.check_and_allocate_symmetric_pathid(renderedServicePath.getPathId()); printTraceStart(LOG);
pathId = SfcServicePathId.check_and_allocate_pathid(); } else { pathId = SfcServicePathId.check_and_allocate_pathid(serviceFunctionPath.getPathId());
/** * Check and allocate Pathid if available * * <p> * @param pathid Candidate Path Id * @return True if allocated, otherwise false. */ public static long check_and_allocate_pathid(long pathid) { if (SfcConcurrencyAPI.getPathIdLock()) { try { if (check_suitable_pathid(pathid) && allocate_pathid(pathid)) { return pathid; } else { return -1; } } finally { SfcConcurrencyAPI.releasePathIdLock(); } } else { return -1; } }
@Override public Future<RpcResult<SetGenerationAlgorithmOutput>> setGenerationAlgorithm(SetGenerationAlgorithmInput input) { boolean result = SfcServicePathId.setGenerationAlgorithm(input.getGenerationAlgorithm()); SetGenerationAlgorithmOutputBuilder setGenerationAlgorithmOutputBuilder = new SetGenerationAlgorithmOutputBuilder(); setGenerationAlgorithmOutputBuilder.setResult(result); RpcResultBuilder<SetGenerationAlgorithmOutput> rpcResultBuilder = RpcResultBuilder.success(setGenerationAlgorithmOutputBuilder.build()); return Futures.immediateFuture(rpcResultBuilder.build()); }
/** * Get the Path-Id Generation-algorithm from the data-store. * * If its not present, create it with the default value. * * <p> * @return generation-algorithm enum value */ public static GenerationAlgorithmEnum getGenerationAlgorithm() { InstanceIdentifier<ServicePathIds> spIID = InstanceIdentifier.builder(ServicePathIds.class).build(); ServicePathIds servicePathIds = SfcDataStoreAPI. readTransactionAPI(spIID, LogicalDatastoreType.OPERATIONAL); if(servicePathIds == null) { setGenerationAlgorithm(DEFAULT_GENERATION_ALGORITHM); return GenerationAlgorithmEnum.forValue(DEFAULT_GENERATION_ALGORITHM); } GenerationAlgorithmEnum genAlgorithm = servicePathIds.getGenerationAlgorithm(); if(genAlgorithm == null) { setGenerationAlgorithm(DEFAULT_GENERATION_ALGORITHM); return GenerationAlgorithmEnum.forValue(DEFAULT_GENERATION_ALGORITHM); } else { return genAlgorithm; } }