blob: 5b5a5fb2f0791eff98b680be31412f529beef2bf [file] [log] [blame]
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 */
16package org.onosproject.provider.pcep.tunnel.impl;
17
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}