blob: 7d11a76c1ebe695830589cf697d4cc363e54efd3 [file] [log] [blame]
Brian O'Connorb7baf712015-07-28 23:27:03 -07001/*
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 */
16package org.onosproject.incubator.net.domain;
17
18import com.google.common.annotations.Beta;
Brian O'Connorce2d8b52015-07-29 16:24:13 -070019import com.google.common.base.MoreObjects;
Brian O'Connorb7baf712015-07-28 23:27:03 -070020import org.onlab.graph.Vertex;
21import org.onosproject.net.DeviceId;
22
23import 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
30public 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'Connorce2d8b52015-07-29 16:24:13 -070034 private final IntentDomainId domainId;
Brian O'Connorb7baf712015-07-28 23:27:03 -070035 // ----- or -----
Aaron Kruglikovc61d2d12015-09-01 11:10:48 -070036
Brian O'Connorb7baf712015-07-28 23:27:03 -070037 private final DeviceId deviceId;
38
39 // Serialization constructor
40 private DomainVertex() {
Brian O'Connorce2d8b52015-07-29 16:24:13 -070041 this.domainId = null;
Brian O'Connorb7baf712015-07-28 23:27:03 -070042 this.deviceId = null;
43 }
44
Brian O'Connorce2d8b52015-07-29 16:24:13 -070045 public DomainVertex(IntentDomainId id) {
46 this.domainId = checkNotNull(id, "Intent domain ID cannot be null.");
Brian O'Connorb7baf712015-07-28 23:27:03 -070047 this.deviceId = null;
48 }
49
Brian O'Connorce2d8b52015-07-29 16:24:13 -070050 public DomainVertex(DeviceId id) {
51 this.domainId = null;
Brian O'Connorb7baf712015-07-28 23:27:03 -070052 this.deviceId = checkNotNull(id, "Device ID cannot be null.");
53 }
Brian O'Connorce2d8b52015-07-29 16:24:13 -070054
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 Kruglikovc61d2d12015-09-01 11:10:48 -070070
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'Connorb7baf712015-07-28 23:27:03 -070088}