blob: 16e8dc5f5ee2295d219c7cdf076ecabe6ce9b139 [file] [log] [blame]
Simon Hunta17fa672015-08-19 18:42:22 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunta17fa672015-08-19 18:42:22 -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.
Simon Hunta17fa672015-08-19 18:42:22 -070015 */
16
Simon Hunt191c84a2015-08-21 08:24:48 -070017package org.onosproject.ui.topo;
Simon Hunta17fa672015-08-19 18:42:22 -070018
19import org.onosproject.net.Link;
20import org.onosproject.net.LinkKey;
Simon Hunta17fa672015-08-19 18:42:22 -070021
Simon Hunt4fc86852015-08-20 17:57:52 -070022import static com.google.common.base.Preconditions.checkNotNull;
Simon Hunta17fa672015-08-19 18:42:22 -070023
24/**
Simon Hunt4fc86852015-08-20 17:57:52 -070025 * Representation of a link and its inverse, as a partial implementation.
26 * <p>
27 * Subclasses will decide how to generate the link highlighting (coloring
28 * and labeling) for the topology view.
Simon Hunta17fa672015-08-19 18:42:22 -070029 */
Simon Hunt4fc86852015-08-20 17:57:52 -070030public abstract class BiLink {
Simon Hunta17fa672015-08-19 18:42:22 -070031
32 private final LinkKey key;
33 private final Link one;
34 private Link two;
35
Simon Hunta17fa672015-08-19 18:42:22 -070036 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070037 * Constructs a bi-link for the given key and initial link. It is expected
38 * that the caller will have used {@link TopoUtils#canonicalLinkKey(Link)}
39 * to generate the key.
Simon Hunta17fa672015-08-19 18:42:22 -070040 *
Simon Hunt4fc86852015-08-20 17:57:52 -070041 * @param key canonical key for this bi-link
Simon Hunta17fa672015-08-19 18:42:22 -070042 * @param link first link
43 */
44 public BiLink(LinkKey key, Link link) {
Simon Hunt4fc86852015-08-20 17:57:52 -070045 this.key = checkNotNull(key);
46 this.one = checkNotNull(link);
Simon Hunta17fa672015-08-19 18:42:22 -070047 }
48
49 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070050 * Sets the second link for this bi-link.
Simon Hunta17fa672015-08-19 18:42:22 -070051 *
52 * @param link second link
53 */
54 public void setOther(Link link) {
Simon Hunt4fc86852015-08-20 17:57:52 -070055 this.two = checkNotNull(link);
Simon Hunta17fa672015-08-19 18:42:22 -070056 }
57
58 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070059 * Returns the link identifier in the form expected on the Topology View
60 * in the web client.
Simon Hunta17fa672015-08-19 18:42:22 -070061 *
Simon Hunt4fc86852015-08-20 17:57:52 -070062 * @return link identifier
Simon Hunta17fa672015-08-19 18:42:22 -070063 */
Simon Hunt4fc86852015-08-20 17:57:52 -070064 public String linkId() {
Simon Hunta17fa672015-08-19 18:42:22 -070065 return TopoUtils.compactLinkString(one);
66 }
67
Simon Hunt4fc86852015-08-20 17:57:52 -070068 /**
69 * Returns the key for this bi-link.
70 *
71 * @return the key
72 */
Simon Hunta17fa672015-08-19 18:42:22 -070073 public LinkKey key() {
74 return key;
75 }
76
Simon Hunt4fc86852015-08-20 17:57:52 -070077 /**
78 * Returns the first link in this bi-link.
79 *
80 * @return the first link
81 */
Simon Hunta17fa672015-08-19 18:42:22 -070082 public Link one() {
83 return one;
84 }
85
Simon Hunt4fc86852015-08-20 17:57:52 -070086 /**
87 * Returns the second link in this bi-link.
88 *
89 * @return the second link
90 */
Simon Hunta17fa672015-08-19 18:42:22 -070091 public Link two() {
92 return two;
93 }
94
Simon Hunt4fc86852015-08-20 17:57:52 -070095 /**
96 * Returns the link highlighting to use, based on this bi-link's current
97 * state.
98 *
99 * @param type optional highlighting type parameter
100 * @return link highlighting model
101 */
102 public abstract LinkHighlight highlight(Enum<?> type);
Simon Hunta17fa672015-08-19 18:42:22 -0700103}