/** * 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; }
/** * 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; }
/** * 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; } }
if(genAlg == GenerationAlgorithmEnum.Random) { symmetric_id = pathid ^ (1 << 23); if(!check_suitable_pathid(symmetric_id)) { symmetric_id = -1;