Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.ui.model.topo; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.EdgeLink; |
| 21 | import org.onosproject.net.PortNumber; |
| 22 | |
| 23 | /** |
| 24 | * Designates a link between a device and a host; that is, an edge link. |
| 25 | */ |
| 26 | public 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 Hunt | 3d71252 | 2016-08-11 11:20:44 -0700 | [diff] [blame] | 56 | // no port for end-point A |
| 57 | |
| 58 | @Override |
| 59 | public String endPortB() { |
| 60 | return edgePort.toString(); |
| 61 | } |
| 62 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 63 | @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 | } |