blob: c373dbeb6e5a90e9b044b62f517f329516845c6c [file] [log] [blame]
Pier Luigi09220c22017-09-14 22:00:30 +02001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16
17package org.onosproject.net.behaviour.trafficcontrol;
18
19
20import com.google.common.annotations.Beta;
21import org.onlab.util.Identifier;
22
23import java.net.URI;
24
25import static com.google.common.base.Preconditions.checkArgument;
26
27/**
28 * Unique identifier for an ONOS Policer {@link org.onosproject.net.behaviour.trafficcontrol.Policer}.
29 * It uniquely identifies a Policer in the scope of a single device inside ONOS. There may not be any
30 * correspondence with the identifiers of the technology implementing the Policer in the device.
31 * Mapping (if necessary) is left to the specific implementation.
32 */
33@Beta
34public final class PolicerId extends Identifier<String> {
35
36 /**
37 * Represents either no id, or an unspecified id.
38 */
39 public static final PolicerId NONE = policerId("none:none");
40
41 private static final int POLICER_ID_MAX_LENGTH = 1024;
42
43 private final URI uri;
44
45 // Not allowed
46 private PolicerId(URI u) {
47 super(u.toString());
48 uri = u;
49 }
50
51 // Needed for serialization
52 private PolicerId() {
53 super();
54 uri = null;
55 }
56
57 /**
58 * Creates a policer id using the supplied URI.
59 *
60 * @param uri policer id URI
61 * @return PolicerId
62 */
63 public static PolicerId policerId(URI uri) {
64 return new PolicerId(uri);
65 }
66
67 /**
68 * Creates a policer id using the supplied URI string.
69 *
70 * @param string policer id URI string
71 * @return PolicerID
72 */
73 public static PolicerId policerId(String string) {
74 checkArgument(string.length() <= POLICER_ID_MAX_LENGTH,
75 "URI string exceeds maximum length " + POLICER_ID_MAX_LENGTH);
76 return policerId(URI.create(string));
77 }
78
79 /**
80 * Returns the backing URI.
81 *
82 * @return backing URI
83 */
84 public URI uri() {
85 return uri;
86 }
87
88}