Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 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.PortNumber; |
| 21 | import org.onosproject.net.region.RegionId; |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * Designates a link between a region node and a device. |
| 26 | */ |
| 27 | public class UiRegionDeviceLink extends UiLink { |
| 28 | |
| 29 | private static final String E_NOT_REGION_DEVICE_ID = |
| 30 | "UI link identifier not region to device"; |
| 31 | |
| 32 | // private (synthetic) region-device link |
| 33 | private final RegionId region; |
| 34 | private final DeviceId device; |
| 35 | private final PortNumber port; |
| 36 | |
| 37 | /** |
| 38 | * Creates a region to device UI link. Note that it is expected that the |
| 39 | * link identifier is one that has a region ID at one end, and a device |
| 40 | * ID at the other |
| 41 | * |
| 42 | * @param topology parent topology |
| 43 | * @param id canonicalized link identifier |
| 44 | * @throws IllegalArgumentException if the link ID is not region-region |
| 45 | */ |
| 46 | public UiRegionDeviceLink(UiTopology topology, UiLinkId id) { |
| 47 | super(topology, id); |
| 48 | region = id.regionA(); |
| 49 | device = (DeviceId) id.elementB(); |
| 50 | port = id.portB(); |
| 51 | if (region == null || device == null || port == null) { |
| 52 | throw new IllegalArgumentException(E_NOT_REGION_DEVICE_ID); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String endPointA() { |
| 58 | return region.id(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public String endPointB() { |
| 63 | return device + UiLinkId.ID_PORT_DELIMITER + port; |
| 64 | } |
| 65 | |
Simon Hunt | 3d71252 | 2016-08-11 11:20:44 -0700 | [diff] [blame] | 66 | // no port for end-point A |
| 67 | |
| 68 | @Override |
| 69 | public String endPortB() { |
| 70 | return port.toString(); |
| 71 | } |
| 72 | |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Returns the identity of the region. |
| 75 | * |
| 76 | * @return region ID |
| 77 | */ |
| 78 | public RegionId region() { |
| 79 | return region; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the identity of the device. |
| 84 | * |
| 85 | * @return device ID |
| 86 | */ |
| 87 | public DeviceId device() { |
| 88 | return device; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns the identity of the device port. |
| 93 | * |
| 94 | * @return device port number |
| 95 | */ |
| 96 | public PortNumber port() { |
| 97 | return port; |
| 98 | } |
| 99 | } |