blob: 0da7bfc63b30d75fe1501339715b543edff65d7d [file] [log] [blame]
Michele Santuari38dd82e2017-01-04 09:23:49 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Michele Santuari38dd82e2017-01-04 09:23:49 +01003 *
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.domain;
18
19import org.onlab.util.Identifier;
20
Jordan Halterman0d89ea32017-06-13 10:42:36 -070021import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23
Michele Santuari38dd82e2017-01-04 09:23:49 +010024/**
25 * Representation of a domain identity.
26 */
27public class DomainId extends Identifier<String> {
28
Jordan Halterman0d89ea32017-06-13 10:42:36 -070029 private static final int DOMAIN_ID_MAX_LENGTH = 1024;
30
Michele Santuari38dd82e2017-01-04 09:23:49 +010031 /**
32 * Represents the domain directly managed by ONOS.
33 */
34 public static final DomainId LOCAL = domainId("local");
35
36 /**
37 * Constructor of the peer id.
38 *
39 * @param identifier of the peer
40 */
41 public DomainId(String identifier) {
42 super(identifier);
43 }
44
45 /**
46 * Creates a peer id from the string identifier.
47 *
48 * @param identifier string identifier
49 * @return instance of the class DomainId
50 */
51 public static DomainId domainId(String identifier) {
Jordan Halterman0d89ea32017-06-13 10:42:36 -070052 checkNotNull(identifier, "identifier cannot be null");
53 checkArgument(identifier.length() <= DOMAIN_ID_MAX_LENGTH,
54 "identifier exceeds maximum length " + DOMAIN_ID_MAX_LENGTH);
Michele Santuari38dd82e2017-01-04 09:23:49 +010055 return new DomainId(identifier);
56 }
57}