Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 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 | package org.onosproject.incubator.net.virtual; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 19 | import org.onlab.util.Identifier; |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 20 | |
Kenji HIKICHI | cfdf91b | 2016-05-25 13:04:45 +0900 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Representation of network identity. |
| 25 | */ |
| 26 | @Beta |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 27 | public final class NetworkId extends Identifier<Long> { |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 28 | |
| 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 HIKICHI | cfdf91b | 2016-05-25 13:04:45 +0900 | [diff] [blame] | 39 | /** |
| 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 Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 48 | // Public construction is prohibited |
| 49 | private NetworkId(long id) { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 50 | super(id); |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
| 54 | // Default constructor for serialization |
| 55 | protected NetworkId() { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 56 | super(-1L); |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 57 | } |
| 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 Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 68 | } |