Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -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 | 5f6dbf8 | 2016-03-30 08:53:33 -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 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 20 | import org.onosproject.net.Host; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 21 | import org.onosproject.net.HostId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 22 | import org.onosproject.net.PortNumber; |
Steven Burrows | 19e6e4f | 2016-10-05 13:27:07 -0500 | [diff] [blame] | 23 | import org.onosproject.net.region.RegionId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 26 | import static com.google.common.base.Preconditions.checkNotNull; |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 27 | |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Represents an end-station host. |
| 30 | */ |
| 31 | public class UiHost extends UiNode { |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 32 | |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 33 | private static final String HOST_CANNOT_BE_NULL = "Host cannot be null"; |
| 34 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 35 | private final UiTopology topology; |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 36 | private final HostId hostId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 37 | |
| 38 | // Host location |
| 39 | private DeviceId locDevice; |
| 40 | private PortNumber locPort; |
| 41 | |
| 42 | private UiLinkId edgeLinkId; |
Steven Burrows | 19e6e4f | 2016-10-05 13:27:07 -0500 | [diff] [blame] | 43 | private RegionId regionId; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Creates a new UI host. |
| 47 | * |
| 48 | * @param topology parent topology |
| 49 | * @param host backing host |
| 50 | */ |
| 51 | public UiHost(UiTopology topology, Host host) { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 52 | checkNotNull(host, HOST_CANNOT_BE_NULL); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 53 | this.topology = topology; |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 54 | this.hostId = host.id(); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 57 | @Override |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 58 | public String toString() { |
| 59 | return toStringHelper(this) |
| 60 | .add("id", id()) |
| 61 | .add("dev", locDevice) |
| 62 | .add("port", locPort) |
| 63 | .toString(); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 64 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Returns the identity of the host. |
| 68 | * |
| 69 | * @return host ID |
| 70 | */ |
| 71 | public HostId id() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 72 | return hostId; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Steven Burrows | 19e6e4f | 2016-10-05 13:27:07 -0500 | [diff] [blame] | 75 | /** |
| 76 | * Sets the ID of the region to which this device belongs. |
| 77 | * |
| 78 | * @param regionId region identifier |
| 79 | */ |
| 80 | public void setRegionId(RegionId regionId) { |
| 81 | this.regionId = regionId; |
| 82 | } |
| 83 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 84 | @Override |
| 85 | public String idAsString() { |
| 86 | return id().toString(); |
| 87 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Sets the host's current location. |
| 91 | * |
| 92 | * @param deviceId ID of device |
| 93 | * @param port port number |
| 94 | */ |
| 95 | public void setLocation(DeviceId deviceId, PortNumber port) { |
| 96 | locDevice = deviceId; |
| 97 | locPort = port; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Sets the ID of the edge link between this host and the device to which |
| 102 | * it connects. |
| 103 | * |
| 104 | * @param id edge link identifier to set |
| 105 | */ |
| 106 | public void setEdgeLinkId(UiLinkId id) { |
| 107 | this.edgeLinkId = id; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the host instance backing this UI host. |
| 112 | * |
| 113 | * @return the backing host instance |
| 114 | */ |
| 115 | public Host backingHost() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 116 | return topology.services.host().getHost(hostId); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
Simon Hunt | eae81ee | 2016-05-19 12:33:22 -0700 | [diff] [blame] | 120 | * Returns the identifier for the edge link between this host and |
| 121 | * the device to which it is connected. |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 122 | * |
| 123 | * @return edge link identifier |
| 124 | */ |
| 125 | public UiLinkId edgeLinkId() { |
Simon Hunt | eae81ee | 2016-05-19 12:33:22 -0700 | [diff] [blame] | 126 | return edgeLinkId; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns the identifier of the device to which the host is connected. |
| 131 | * |
| 132 | * @return device identifier |
| 133 | */ |
| 134 | public DeviceId locationDevice() { |
| 135 | return locDevice; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Returns the port number of the device to which the host is connected. |
| 140 | * |
| 141 | * @return port number |
| 142 | */ |
| 143 | public PortNumber locationPort() { |
| 144 | return locPort; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 145 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 146 | } |