Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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.domain; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 20 | import org.onlab.graph.Vertex; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | /** |
| 26 | * Representation of the intent domain or a device that is part of the intent |
| 27 | * domain graph. |
| 28 | */ |
| 29 | @Beta |
| 30 | public class DomainVertex implements Vertex { |
| 31 | // FIXME we will want to add a type enum or subclasses for the two different types |
| 32 | |
| 33 | // A domain vertex is either an intent domain or a device: |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame] | 34 | private final IntentDomainId domainId; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 35 | // ----- or ----- |
Aaron Kruglikov | c61d2d1 | 2015-09-01 11:10:48 -0700 | [diff] [blame] | 36 | |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 37 | private final DeviceId deviceId; |
| 38 | |
| 39 | // Serialization constructor |
| 40 | private DomainVertex() { |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame] | 41 | this.domainId = null; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 42 | this.deviceId = null; |
| 43 | } |
| 44 | |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame] | 45 | public DomainVertex(IntentDomainId id) { |
| 46 | this.domainId = checkNotNull(id, "Intent domain ID cannot be null."); |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 47 | this.deviceId = null; |
| 48 | } |
| 49 | |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame] | 50 | public DomainVertex(DeviceId id) { |
| 51 | this.domainId = null; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 52 | this.deviceId = checkNotNull(id, "Device ID cannot be null."); |
| 53 | } |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame] | 54 | |
| 55 | @Override |
| 56 | public String toString() { |
| 57 | if (domainId != null) { |
| 58 | return MoreObjects.toStringHelper(this) |
| 59 | .add("domainId", domainId) |
| 60 | .toString(); |
| 61 | } else if (deviceId != null) { |
| 62 | return MoreObjects.toStringHelper(this) |
| 63 | .add("deviceId", deviceId) |
| 64 | .toString(); |
| 65 | } else { |
| 66 | return MoreObjects.toStringHelper(this) |
| 67 | .toString(); |
| 68 | } |
| 69 | } |
Aaron Kruglikov | c61d2d1 | 2015-09-01 11:10:48 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Returns the device ID of this vertex if it is a device, returns null if it is a domain. |
| 73 | * |
| 74 | * @return the device ID of this vertex if applicable, else null |
| 75 | */ |
| 76 | public DeviceId deviceId() { |
| 77 | return deviceId; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the domain ID of this vertex if it is a domain, returns null if it is a device. |
| 82 | * |
| 83 | * @return the domain ID of this vertex if applicable, else null |
| 84 | */ |
| 85 | public IntentDomainId domainId() { |
| 86 | return domainId; |
| 87 | } |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 88 | } |