blob: fcf500612dda572d90c5747c230352e85095419b [file] [log] [blame]
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Priyanka Bbae0eeb12016-11-30 11:59:48 +05303 *
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.pce.pceservice;
17
18import org.onosproject.net.NetworkResource;
19
20import com.google.common.annotations.Beta;
21
22import java.util.Objects;
23
24/**
25 * Representation of explicit path info consists of contraints (strict / loose) to compute path.
26 */
27@Beta
28public final class ExplicitPathInfo {
29
30 private final Type type;
31
32 //Can be Link or DeviceId
33 private final NetworkResource value;
34
35 public enum Type {
36 /**
37 * Signifies that path includes strict node or link.
38 */
39 STRICT(0),
40
41 /**
42 * Signifies that path includes loose node or link.
43 */
44 LOOSE(1);
45
46 int value;
47
48 /**
49 * Assign val with the value as the type.
50 *
51 * @param val type
52 */
53 Type(int val) {
54 value = val;
55 }
56
57 /**
58 * Returns value of type.
59 *
60 * @return type
61 */
62 public byte type() {
63 return (byte) value;
64 }
65 }
66
67 /**
68 * Creates instance of explicit path object.
69 *
70 * @param type specifies whether strict or loose node/link
71 * @param value specifies deviceId or link
72 */
73 public ExplicitPathInfo(Type type, NetworkResource value) {
74 this.type = type;
75 this.value = value;
76 }
77
78 /**
79 * Returns explicit path type.
80 *
81 * @return explicit path type as strict/loose
82 */
83 public Type type() {
84 return type;
85 }
86
87 /**
88 * Returns deviceId or link.
89 *
90 * @return deviceId or link
91 */
92 public NetworkResource value() {
93 return value;
94 }
95
96 @Override
97 public int hashCode() {
98 return Objects.hash(type, value);
99 }
100
101 @Override
102 public boolean equals(Object obj) {
103 if (this == obj) {
104 return true;
105 }
106 if (obj instanceof ExplicitPathInfo) {
107 final ExplicitPathInfo other = (ExplicitPathInfo) obj;
108 return Objects.equals(this.type, other.type)
109 && Objects.equals(this.value, other.value);
110 }
111 return false;
112 }
113}