blob: 8c95e15d8264cb215e3bfe0c46f2037704962ec1 [file] [log] [blame]
Simon Hunta17fa672015-08-19 18:42:22 -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 *
16 */
17
Simon Hunt191c84a2015-08-21 08:24:48 -070018package org.onosproject.ui.topo;
Simon Hunta17fa672015-08-19 18:42:22 -070019
20import org.onosproject.net.Link;
21import org.onosproject.net.LinkKey;
Simon Hunta17fa672015-08-19 18:42:22 -070022
Simon Hunt4fc86852015-08-20 17:57:52 -070023import static com.google.common.base.Preconditions.checkNotNull;
Simon Hunta17fa672015-08-19 18:42:22 -070024
25/**
Simon Hunt4fc86852015-08-20 17:57:52 -070026 * Representation of a link and its inverse, as a partial implementation.
27 * <p>
28 * Subclasses will decide how to generate the link highlighting (coloring
29 * and labeling) for the topology view.
Simon Hunta17fa672015-08-19 18:42:22 -070030 */
Simon Hunt4fc86852015-08-20 17:57:52 -070031public abstract class BiLink {
Simon Hunta17fa672015-08-19 18:42:22 -070032
33 private final LinkKey key;
34 private final Link one;
35 private Link two;
36
Simon Hunta17fa672015-08-19 18:42:22 -070037 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070038 * Constructs a bi-link for the given key and initial link. It is expected
39 * that the caller will have used {@link TopoUtils#canonicalLinkKey(Link)}
40 * to generate the key.
Simon Hunta17fa672015-08-19 18:42:22 -070041 *
Simon Hunt4fc86852015-08-20 17:57:52 -070042 * @param key canonical key for this bi-link
Simon Hunta17fa672015-08-19 18:42:22 -070043 * @param link first link
44 */
45 public BiLink(LinkKey key, Link link) {
Simon Hunt4fc86852015-08-20 17:57:52 -070046 this.key = checkNotNull(key);
47 this.one = checkNotNull(link);
Simon Hunta17fa672015-08-19 18:42:22 -070048 }
49
50 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070051 * Sets the second link for this bi-link.
Simon Hunta17fa672015-08-19 18:42:22 -070052 *
53 * @param link second link
54 */
55 public void setOther(Link link) {
Simon Hunt4fc86852015-08-20 17:57:52 -070056 this.two = checkNotNull(link);
Simon Hunta17fa672015-08-19 18:42:22 -070057 }
58
59 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070060 * Returns the link identifier in the form expected on the Topology View
61 * in the web client.
Simon Hunta17fa672015-08-19 18:42:22 -070062 *
Simon Hunt4fc86852015-08-20 17:57:52 -070063 * @return link identifier
Simon Hunta17fa672015-08-19 18:42:22 -070064 */
Simon Hunt4fc86852015-08-20 17:57:52 -070065 public String linkId() {
Simon Hunta17fa672015-08-19 18:42:22 -070066 return TopoUtils.compactLinkString(one);
67 }
68
Simon Hunt4fc86852015-08-20 17:57:52 -070069 /**
70 * Returns the key for this bi-link.
71 *
72 * @return the key
73 */
Simon Hunta17fa672015-08-19 18:42:22 -070074 public LinkKey key() {
75 return key;
76 }
77
Simon Hunt4fc86852015-08-20 17:57:52 -070078 /**
79 * Returns the first link in this bi-link.
80 *
81 * @return the first link
82 */
Simon Hunta17fa672015-08-19 18:42:22 -070083 public Link one() {
84 return one;
85 }
86
Simon Hunt4fc86852015-08-20 17:57:52 -070087 /**
88 * Returns the second link in this bi-link.
89 *
90 * @return the second link
91 */
Simon Hunta17fa672015-08-19 18:42:22 -070092 public Link two() {
93 return two;
94 }
95
Simon Hunt4fc86852015-08-20 17:57:52 -070096 /**
97 * Returns the link highlighting to use, based on this bi-link's current
98 * state.
99 *
100 * @param type optional highlighting type parameter
101 * @return link highlighting model
102 */
103 public abstract LinkHighlight highlight(Enum<?> type);
Simon Hunta17fa672015-08-19 18:42:22 -0700104}