blob: 2a5a19de08dec32de8d6915855187d780efa5e32 [file] [log] [blame]
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Phanendra Manda37b97fb2015-08-15 02:04:24 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Avantika-Huaweifc10dca2016-06-10 16:13:55 +053016package org.onosproject.pcep.controller;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053017
18import static org.slf4j.LoggerFactory.getLogger;
19
20import java.util.concurrent.atomic.AtomicInteger;
21
22import org.slf4j.Logger;
23
24/**
25 * Unique Srp Id generator for pcep messages.
26 */
27public final class SrpIdGenerators {
28
29 private static final Logger log = getLogger(SrpIdGenerators.class);
30 private static final AtomicInteger SRP_ID_GEN = new AtomicInteger();
31 private static final int MAX_SRP_ID = 0x7FFFFFFF;
32 private static int srpId;
33
34 /**
35 * Default constructor.
36 */
37 private SrpIdGenerators() {
38 }
39
40 /**
41 * Get the next srp id.
42 *
43 * @return srp id
44 */
45 public static int create() {
46 do {
47 if (srpId >= MAX_SRP_ID) {
48 if (SRP_ID_GEN.get() >= MAX_SRP_ID) {
49 SRP_ID_GEN.set(0);
50 }
51 }
52 srpId = SRP_ID_GEN.incrementAndGet();
53 } while (srpId > MAX_SRP_ID);
54 return srpId;
55 }
56}