blob: f749473812bff9438922781f203fa3e57e8cc486 [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.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
66 /**
67 * Returns the identity of the region.
68 *
69 * @return region ID
70 */
71 public RegionId region() {
72 return region;
73 }
74
75 /**
76 * Returns the identity of the device.
77 *
78 * @return device ID
79 */
80 public DeviceId device() {
81 return device;
82 }
83
84 /**
85 * Returns the identity of the device port.
86 *
87 * @return device port number
88 */
89 public PortNumber port() {
90 return port;
91 }
92}