blob: ffd316882453d568cb0ce91d53e60138ee2d82c0 [file] [log] [blame]
Phaneendra Manda8225ddb2016-02-05 20:54:04 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Phaneendra Manda8225ddb2016-02-05 20:54:04 +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 */
16package org.onosproject.vtnrsc;
17
Jian Lid79fb942016-02-29 13:42:23 -080018import org.onlab.util.Identifier;
19
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053020import static com.google.common.base.Preconditions.checkArgument;
21
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053022/*
23 * Representation of 5 bit load balance identifier for a service function
24 */
Jian Lid79fb942016-02-29 13:42:23 -080025public final class LoadBalanceId extends Identifier<Byte> {
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053026
27 private static final byte MAX_ID = 0x1F;
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053028
29 /**
30 * Default constructor.
31 *
32 * @param loadBalanceId service function chain path's load balance identifier
33 */
34 private LoadBalanceId(byte loadBalanceId) {
Jian Lid79fb942016-02-29 13:42:23 -080035 super(loadBalanceId);
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053036 checkArgument(loadBalanceId <= MAX_ID, "Load balance id should not be more than 5 bit identifier");
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053037 }
38
39 /**
40 * Returns the SfcLoadBalanceId by setting its value.
41 *
42 * @param loadBalanceId service function chain path's load balance identifier
43 * @return LoadBalanceId
44 */
45 public static LoadBalanceId of(byte loadBalanceId) {
46 return new LoadBalanceId(loadBalanceId);
47 }
48
49
50 /**
51 * Returns load balance identifier for a service function.
52 *
53 * @return loadBalanceId
54 */
55 public byte loadBalanceId() {
Jian Lid79fb942016-02-29 13:42:23 -080056 return identifier;
Phaneendra Manda8225ddb2016-02-05 20:54:04 +053057 }
58}