blob: b133de0cc1f82e13f6d93dcd791b503f7059669a [file] [log] [blame]
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -07003 *
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
17package org.onosproject.net;
18
Andrey Komarov2398d962016-09-26 15:11:23 +030019import org.onlab.graph.Weight;
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070020import org.onosproject.net.provider.ProviderId;
21
22import java.util.List;
23import java.util.Objects;
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070024
25/**
26 * Default implementation of a network disjoint path pair.
27 */
28public class DefaultDisjointPath extends DefaultPath implements DisjointPath {
29
30 private final DefaultPath path1;
31 private final DefaultPath path2;
32
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070033 /**
34 * Creates a disjoint path pair from two default paths.
35 *
36 * @param providerId provider identity
37 * @param path1 primary path
38 * @param path2 backup path
39 */
40 public DefaultDisjointPath(ProviderId providerId, DefaultPath path1, DefaultPath path2) {
Yuta HIGUCHIdf970132016-08-09 11:18:30 -070041 // Note: cost passed to super will never be used
Andrey Komarov2398d962016-09-26 15:11:23 +030042 super(providerId, path1.links(), path1.weight());
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070043 this.path1 = path1;
44 this.path2 = path2;
45 }
46
Jayasree Ghoshd3ff5402016-08-17 18:41:19 +053047 /**
48 * Creates a disjoint path pair from single default paths.
49 *
50 * @param providerId provider identity
51 * @param path1 primary path
52 */
53 public DefaultDisjointPath(ProviderId providerId, DefaultPath path1) {
54 this(providerId, path1, null);
55 }
56
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070057 @Override
58 public List<Link> links() {
Yuta HIGUCHI6deacbd2017-05-22 23:25:05 -070059 return path1.links();
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070060 }
61
62 @Override
63 public double cost() {
Yuta HIGUCHI6deacbd2017-05-22 23:25:05 -070064 return path1.cost();
Andrey Komarov2398d962016-09-26 15:11:23 +030065 }
66
67 @Override
68 public Weight weight() {
Yuta HIGUCHI6deacbd2017-05-22 23:25:05 -070069 return path1.weight();
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070070 }
71
72 @Override
73 public Path primary() {
74 return path1;
75 }
76
77 @Override
78 public Path backup() {
79 return path2;
80 }
81
82 @Override
83 public int hashCode() {
Yuta HIGUCHIdf970132016-08-09 11:18:30 -070084 // Note: DisjointPath with primary and secondary swapped
85 // must result in same hashCode
86 return Objects.hash(Objects.hashCode(path1) + Objects.hashCode(path2), src(), dst());
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070087 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj instanceof DefaultDisjointPath) {
95 final DefaultDisjointPath other = (DefaultDisjointPath) obj;
Yuta HIGUCHIdf970132016-08-09 11:18:30 -070096 return (Objects.equals(this.path1, other.path1) && Objects.equals(this.path2, other.path2)) ||
97 (Objects.equals(this.path1, other.path2) && Objects.equals(this.path2, other.path1));
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -070098 }
99 return false;
100 }
101
Yuta HIGUCHI6deacbd2017-05-22 23:25:05 -0700102 @Deprecated
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -0700103 @Override
104 public boolean useBackup() {
Yuta HIGUCHI6deacbd2017-05-22 23:25:05 -0700105 return false;
Nikhil Cheerla1cf0f9a2015-07-09 12:26:48 -0700106 }
107}