blob: 8ccf543e262365a8aa67d8e248e1c1dbdbdde1f1 [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
18package org.onosproject.ui.impl.topo;
19
20import org.onosproject.net.Link;
21import org.onosproject.net.LinkKey;
Simon Hunta17fa672015-08-19 18:42:22 -070022import org.onosproject.ui.topo.LinkHighlight;
23
Simon Hunt4fc86852015-08-20 17:57:52 -070024import static com.google.common.base.Preconditions.checkNotNull;
Simon Hunta17fa672015-08-19 18:42:22 -070025
26/**
Simon Hunt4fc86852015-08-20 17:57:52 -070027 * Representation of a link and its inverse, as a partial implementation.
28 * <p>
29 * Subclasses will decide how to generate the link highlighting (coloring
30 * and labeling) for the topology view.
Simon Hunta17fa672015-08-19 18:42:22 -070031 */
Simon Hunt4fc86852015-08-20 17:57:52 -070032public abstract class BiLink {
Simon Hunta17fa672015-08-19 18:42:22 -070033
34 private final LinkKey key;
35 private final Link one;
36 private Link two;
37
Simon Hunta17fa672015-08-19 18:42:22 -070038 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070039 * Constructs a bi-link for the given key and initial link. It is expected
40 * that the caller will have used {@link TopoUtils#canonicalLinkKey(Link)}
41 * to generate the key.
Simon Hunta17fa672015-08-19 18:42:22 -070042 *
Simon Hunt4fc86852015-08-20 17:57:52 -070043 * @param key canonical key for this bi-link
Simon Hunta17fa672015-08-19 18:42:22 -070044 * @param link first link
45 */
46 public BiLink(LinkKey key, Link link) {
Simon Hunt4fc86852015-08-20 17:57:52 -070047 this.key = checkNotNull(key);
48 this.one = checkNotNull(link);
Simon Hunta17fa672015-08-19 18:42:22 -070049 }
50
51 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070052 * Sets the second link for this bi-link.
Simon Hunta17fa672015-08-19 18:42:22 -070053 *
54 * @param link second link
55 */
56 public void setOther(Link link) {
Simon Hunt4fc86852015-08-20 17:57:52 -070057 this.two = checkNotNull(link);
Simon Hunta17fa672015-08-19 18:42:22 -070058 }
59
60 /**
Simon Hunt4fc86852015-08-20 17:57:52 -070061 * Returns the link identifier in the form expected on the Topology View
62 * in the web client.
Simon Hunta17fa672015-08-19 18:42:22 -070063 *
Simon Hunt4fc86852015-08-20 17:57:52 -070064 * @return link identifier
Simon Hunta17fa672015-08-19 18:42:22 -070065 */
Simon Hunt4fc86852015-08-20 17:57:52 -070066 public String linkId() {
Simon Hunta17fa672015-08-19 18:42:22 -070067 return TopoUtils.compactLinkString(one);
68 }
69
Simon Hunt4fc86852015-08-20 17:57:52 -070070 /**
71 * Returns the key for this bi-link.
72 *
73 * @return the key
74 */
Simon Hunta17fa672015-08-19 18:42:22 -070075 public LinkKey key() {
76 return key;
77 }
78
Simon Hunt4fc86852015-08-20 17:57:52 -070079 /**
80 * Returns the first link in this bi-link.
81 *
82 * @return the first link
83 */
Simon Hunta17fa672015-08-19 18:42:22 -070084 public Link one() {
85 return one;
86 }
87
Simon Hunt4fc86852015-08-20 17:57:52 -070088 /**
89 * Returns the second link in this bi-link.
90 *
91 * @return the second link
92 */
Simon Hunta17fa672015-08-19 18:42:22 -070093 public Link two() {
94 return two;
95 }
96
Simon Hunt4fc86852015-08-20 17:57:52 -070097 /**
98 * Returns the link highlighting to use, based on this bi-link's current
99 * state.
100 *
101 * @param type optional highlighting type parameter
102 * @return link highlighting model
103 */
104 public abstract LinkHighlight highlight(Enum<?> type);
Simon Hunta17fa672015-08-19 18:42:22 -0700105}