blob: 76ed5ff8a3c2157e33491c55acf0988e5e382ab3 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Hunt5f6dbf82016-03-30 08:53:33 -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.ui.model.topo;
18
Simon Huntc0f20c12016-05-09 09:30:20 -070019import static com.google.common.base.MoreObjects.toStringHelper;
20
Simon Hunt5f6dbf82016-03-30 08:53:33 -070021/**
Simon Huntc13082f2016-08-03 21:20:23 -070022 * Represents a link (line between two elements). This may be one of
23 * several concrete subclasses:
Simon Huntc0f20c12016-05-09 09:30:20 -070024 * <ul>
25 * <li>
26 * An infrastructure link:
27 * two backing unidirectional links between two devices.
28 * </li>
29 * <li>
30 * An edge link:
31 * representing the connection between a host and a device.
32 * </li>
33 * <li>
34 * An aggregation link:
Simon Huntc13082f2016-08-03 21:20:23 -070035 * representing multiple underlying UI link instances, for example
36 * the link between two sub-regions in a region (layout).
Simon Huntc0f20c12016-05-09 09:30:20 -070037 * </li>
38 * </ul>
Simon Hunt5f6dbf82016-03-30 08:53:33 -070039 */
Simon Huntc13082f2016-08-03 21:20:23 -070040public abstract class UiLink extends UiElement {
Simon Hunt23fb1352016-04-11 12:15:19 -070041
Simon Huntc13082f2016-08-03 21:20:23 -070042 protected final UiTopology topology;
43 protected final UiLinkId id;
Simon Huntc0f20c12016-05-09 09:30:20 -070044
45 /**
46 * Creates a UI link.
47 *
48 * @param topology parent topology
49 * @param id canonicalized link identifier
50 */
51 public UiLink(UiTopology topology, UiLinkId id) {
52 this.topology = topology;
53 this.id = id;
54 }
55
Simon Hunt23fb1352016-04-11 12:15:19 -070056 @Override
Simon Huntc0f20c12016-05-09 09:30:20 -070057 public String toString() {
58 return toStringHelper(this)
59 .add("id", id)
60 .toString();
61 }
62
Simon Huntc0f20c12016-05-09 09:30:20 -070063 /**
64 * Returns the canonicalized link identifier for this link.
65 *
66 * @return the link identifier
67 */
68 public UiLinkId id() {
69 return id;
70 }
71
Simon Hunt642bc452016-05-04 19:34:45 -070072 @Override
73 public String idAsString() {
Simon Huntc0f20c12016-05-09 09:30:20 -070074 return id.toString();
75 }
76
77 /**
Simon Huntc13082f2016-08-03 21:20:23 -070078 * Returns the implementing class name as the type of link.
Simon Huntc0f20c12016-05-09 09:30:20 -070079 *
Simon Huntc13082f2016-08-03 21:20:23 -070080 * @return link type
Simon Huntc0f20c12016-05-09 09:30:20 -070081 */
Simon Huntc13082f2016-08-03 21:20:23 -070082 public String type() {
83 return getClass().getSimpleName();
Simon Huntc0f20c12016-05-09 09:30:20 -070084 }
85
86 /**
Simon Huntc13082f2016-08-03 21:20:23 -070087 * Returns the identifier of end-point A in string form.
Simon Huntc0f20c12016-05-09 09:30:20 -070088 *
Simon Huntc13082f2016-08-03 21:20:23 -070089 * @return end point A identifier
Simon Huntc0f20c12016-05-09 09:30:20 -070090 */
Simon Huntc13082f2016-08-03 21:20:23 -070091 public abstract String endPointA();
Simon Huntc0f20c12016-05-09 09:30:20 -070092
93 /**
Simon Huntc13082f2016-08-03 21:20:23 -070094 * Returns the identifier of end-point B in string form.
Simon Huntc0f20c12016-05-09 09:30:20 -070095 *
Simon Huntc13082f2016-08-03 21:20:23 -070096 * @return end point B identifier
Simon Huntc0f20c12016-05-09 09:30:20 -070097 */
Simon Huntc13082f2016-08-03 21:20:23 -070098 public abstract String endPointB();
Simon Hunt3d712522016-08-11 11:20:44 -070099
100 /**
101 * Returns the port number (as a string) for end-point A, if applicable.
102 * This default implementation returns null, indicating not-applicable.
103 * Subclasses only need to override this method if end-point A has an
104 * associated port.
105 *
106 * @return port number for end-point A
107 */
108 public String endPortA() {
109 return null;
110 }
111
112 /**
113 * Returns the port number (as a string) for end-point B, if applicable.
114 * This default implementation returns null, indicating not-applicable.
115 * Subclasses only need to override this method if end-point B has an
116 * associated port.
117 *
118 * @return port number for end-point B
119 */
120 public String endPortB() {
121 return null;
122 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700123}