blob: c3104f3ab206f9e7adf2277dc1e0d60aba946282 [file] [log] [blame]
Simon Huntc13082f2016-08-03 21:20:23 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Simon Huntc13082f2016-08-03 21:20:23 -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
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.PortNumber;
21import org.onosproject.net.region.RegionId;
22
23
24/**
25 * Designates a link between a region node and a device.
26 */
27public 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 Hunt3d712522016-08-11 11:20:44 -070066 // no port for end-point A
67
68 @Override
69 public String endPortB() {
70 return port.toString();
71 }
72
Simon Huntc13082f2016-08-03 21:20:23 -070073 /**
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}