blob: 552e9413f1e860fffd317eab6e690a93cc7e1899 [file] [log] [blame]
Thomas Vachuska7b438af2015-07-07 09:52:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska7b438af2015-07-07 09:52:07 -07003 *
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.incubator.net.virtual;
17
18import com.google.common.annotations.Beta;
Jian Lib6d998e2016-02-29 11:41:18 -080019import org.onlab.util.Identifier;
Thomas Vachuska7b438af2015-07-07 09:52:07 -070020
Kenji HIKICHIcfdf91b2016-05-25 13:04:45 +090021import java.util.Objects;
22
Thomas Vachuska7b438af2015-07-07 09:52:07 -070023/**
24 * Representation of network identity.
25 */
26@Beta
Jian Lib6d998e2016-02-29 11:41:18 -080027public final class NetworkId extends Identifier<Long> {
Thomas Vachuska7b438af2015-07-07 09:52:07 -070028
29 /**
30 * Represents no network, or an unspecified network.
31 */
32 public static final NetworkId NONE = networkId(-1L);
33
34 /**
35 * Represents the underlying physical network.
36 */
37 public static final NetworkId PHYSICAL = networkId(0L);
38
Kenji HIKICHIcfdf91b2016-05-25 13:04:45 +090039 /**
40 * Checks if the id is for virtual network.
41 *
42 * @return true if the id is for virtual network.
43 */
44 public final boolean isVirtualNetworkId() {
45 return (!Objects.equals(this, NONE) && !Objects.equals(this, PHYSICAL));
46 }
47
Thomas Vachuska7b438af2015-07-07 09:52:07 -070048 // Public construction is prohibited
49 private NetworkId(long id) {
Jian Lib6d998e2016-02-29 11:41:18 -080050 super(id);
Thomas Vachuska7b438af2015-07-07 09:52:07 -070051 }
52
53
54 // Default constructor for serialization
55 protected NetworkId() {
Jian Lib6d998e2016-02-29 11:41:18 -080056 super(-1L);
Thomas Vachuska7b438af2015-07-07 09:52:07 -070057 }
58
59 /**
60 * Creates a network id using the supplied backing id.
61 *
62 * @param id network id
63 * @return network identifier
64 */
65 public static NetworkId networkId(long id) {
66 return new NetworkId(id);
67 }
Thomas Vachuska7b438af2015-07-07 09:52:07 -070068}