blob: b74694a420b3d346a97df7b990748eb1d0ed43c2 [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Henry Yu4b4a7eb2016-11-09 20:07:53 -05003 *
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.tetopology.management.api.link;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.Lists;
22
23import java.util.List;
24
25/**
26 * Represents the common attributes of a TE path or segment.
27 */
28public class TePathAttributes {
29 private final Long cost;
30 private final Long delay;
31 private final List<Long> srlgs;
32
33 /**
34 * Creates an instance of TE path attributes.
35 *
36 * @param cost the path's cost
37 * @param delay the path's delay
38 * @param srlgs the path's shared risk link groups (SRLGs)
39 */
40 public TePathAttributes(Long cost, Long delay, List<Long> srlgs) {
41 this.cost = cost;
42 this.delay = delay;
43 this.srlgs = srlgs != null ? Lists.newArrayList(srlgs) : null;
44 }
45
46 /**
47 * Creates an instance of TE path attributes based on a given TE link.
48 *
49 * @param link the TE link
50 */
51 public TePathAttributes(TeLink link) {
52 this.cost = link.cost();
53 this.delay = link.delay();
54 this.srlgs = link.srlgs() != null ?
55 Lists.newArrayList(link.srlgs()) : null;
56 }
57
58 /**
59 * Returns the path cost.
60 *
61 * @return the cost
62 */
Hesam Rahimi41208102016-12-09 17:54:03 -050063 public Long cost() {
Henry Yu4b4a7eb2016-11-09 20:07:53 -050064 return cost;
65 }
66
67 /**
68 * Returns the path delay.
69 *
70 * @return the delay
71 */
Hesam Rahimi41208102016-12-09 17:54:03 -050072 public Long delay() {
Henry Yu4b4a7eb2016-11-09 20:07:53 -050073 return delay;
74 }
75
76 /**
77 * Returns the path SRLG values.
78 *
79 * @return the srlgs
80 */
81 public List<Long> srlgs() {
82 if (srlgs == null) {
83 return null;
84 }
85 return ImmutableList.copyOf(srlgs);
86 }
87
88 @Override
89 public int hashCode() {
90 return Objects.hashCode(cost, delay, srlgs);
91 }
92
93 @Override
94 public boolean equals(Object object) {
95 if (this == object) {
96 return true;
97 }
98 if (object instanceof TePathAttributes) {
99 TePathAttributes that = (TePathAttributes) object;
100 return Objects.equal(cost, that.cost) &&
101 Objects.equal(delay, that.delay) &&
102 Objects.equal(srlgs, that.srlgs);
103 }
104 return false;
105 }
106
107 @Override
108 public String toString() {
109 return MoreObjects.toStringHelper(getClass())
110 .add("cost", cost)
111 .add("delay", delay)
112 .add("srlgs", srlgs)
113 .toString();
114 }
115
116}