blob: 909ef1aa3ec53a6086d8bb0362cdb263412a450c [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
56 @Override
57 protected void destroy() {
58 edgeDevice = null;
59 edgePort = null;
60 edgeLink = null;
61 }
62
63 /**
64 * Attaches the given edge link to this UI link. This method will
65 * throw an exception if this UI link is not representative of the
66 * supplied link.
67 *
68 * @param elink edge link to attach
69 * @throws IllegalArgumentException if the link is not appropriate
70 */
71 public void attachEdgeLink(EdgeLink elink) {
72 UiLinkId.Direction d = id.directionOf(elink);
73 // Expected direction of edge links is A-to-B (Host to device)
74 // but checking not null is a sufficient test
75 if (d == null) {
76 throw new IllegalArgumentException(E_UNASSOC + elink);
77 }
78
79 edgeLink = elink;
80 edgeDevice = elink.hostLocation().deviceId();
81 edgePort = elink.hostLocation().port();
82 }
83
84}