blob: f52fbcb57759a9f3d83ebabccf3fe6671f9d3517 [file] [log] [blame]
Simon Huntc13082f2016-08-03 21:20:23 -07001/*
2 * Copyright 2016-present 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
17package org.onosproject.ui.model.topo;
18
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.EdgeLink;
21import org.onosproject.net.PortNumber;
22
23/**
24 * Designates a link between a device and a host; that is, an edge link.
25 */
26public class UiEdgeLink extends UiLink {
27
28 private static final String E_UNASSOC =
29 "backing link not associated with this UI edge link: ";
30
31 // private (synthetic) host link
32 private DeviceId edgeDevice;
33 private PortNumber edgePort;
34 private EdgeLink edgeLink;
35
36 /**
37 * Creates a UI link.
38 *
39 * @param topology parent topology
40 * @param id canonicalized link identifier
41 */
42 public UiEdgeLink(UiTopology topology, UiLinkId id) {
43 super(topology, id);
44 }
45
46 @Override
47 public String endPointA() {
48 return edgeLink.hostId().toString();
49 }
50
51 @Override
52 public String endPointB() {
53 return edgeDevice + UiLinkId.ID_PORT_DELIMITER + edgePort;
54 }
55
Simon Hunt3d712522016-08-11 11:20:44 -070056 // no port for end-point A
57
58 @Override
59 public String endPortB() {
60 return edgePort.toString();
61 }
62
Simon Huntc13082f2016-08-03 21:20:23 -070063 @Override
64 protected void destroy() {
65 edgeDevice = null;
66 edgePort = null;
67 edgeLink = null;
68 }
69
70 /**
71 * Attaches the given edge link to this UI link. This method will
72 * throw an exception if this UI link is not representative of the
73 * supplied link.
74 *
75 * @param elink edge link to attach
76 * @throws IllegalArgumentException if the link is not appropriate
77 */
78 public void attachEdgeLink(EdgeLink elink) {
79 UiLinkId.Direction d = id.directionOf(elink);
80 // Expected direction of edge links is A-to-B (Host to device)
81 // but checking not null is a sufficient test
82 if (d == null) {
83 throw new IllegalArgumentException(E_UNASSOC + elink);
84 }
85
86 edgeLink = elink;
87 edgeDevice = elink.hostLocation().deviceId();
88 edgePort = elink.hostLocation().port();
89 }
90
91}