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(); |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 55 | this.regionId = RegionId.regionId(UiRegion.NULL_NAME); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 58 | @Override |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 59 | public String toString() { |
| 60 | return toStringHelper(this) |
| 61 | .add("id", id()) |
| 62 | .add("dev", locDevice) |
| 63 | .add("port", locPort) |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 64 | .add("Region", regionId) |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 65 | .toString(); |
Simon Hunt | 23fb135 | 2016-04-11 12:15:19 -0700 | [diff] [blame] | 66 | } |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Returns the identity of the host. |
| 70 | * |
| 71 | * @return host ID |
| 72 | */ |
| 73 | public HostId id() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 74 | return hostId; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Steven Burrows | 19e6e4f | 2016-10-05 13:27:07 -0500 | [diff] [blame] | 77 | /** |
Sean Condon | ee54576 | 2019-03-09 10:43:58 +0000 | [diff] [blame] | 78 | * Returns the identifier of the region to which this device belongs. |
| 79 | * This will be null if the device does not belong to any region. |
| 80 | * |
| 81 | * @return region ID |
| 82 | */ |
| 83 | public RegionId regionId() { |
| 84 | return regionId; |
| 85 | } |
| 86 | |
| 87 | /** |
Steven Burrows | 19e6e4f | 2016-10-05 13:27:07 -0500 | [diff] [blame] | 88 | * Sets the ID of the region to which this device belongs. |
| 89 | * |
| 90 | * @param regionId region identifier |
| 91 | */ |
| 92 | public void setRegionId(RegionId regionId) { |
| 93 | this.regionId = regionId; |
| 94 | } |
| 95 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 96 | @Override |
| 97 | public String idAsString() { |
| 98 | return id().toString(); |
| 99 | } |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Sets the host's current location. |
| 103 | * |
| 104 | * @param deviceId ID of device |
| 105 | * @param port port number |
| 106 | */ |
| 107 | public void setLocation(DeviceId deviceId, PortNumber port) { |
| 108 | locDevice = deviceId; |
| 109 | locPort = port; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Sets the ID of the edge link between this host and the device to which |
| 114 | * it connects. |
| 115 | * |
| 116 | * @param id edge link identifier to set |
| 117 | */ |
| 118 | public void setEdgeLinkId(UiLinkId id) { |
| 119 | this.edgeLinkId = id; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns the host instance backing this UI host. |
| 124 | * |
| 125 | * @return the backing host instance |
| 126 | */ |
| 127 | public Host backingHost() { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 128 | return topology.services.host().getHost(hostId); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** |
Simon Hunt | eae81ee | 2016-05-19 12:33:22 -0700 | [diff] [blame] | 132 | * Returns the identifier for the edge link between this host and |
| 133 | * the device to which it is connected. |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 134 | * |
| 135 | * @return edge link identifier |
| 136 | */ |
| 137 | public UiLinkId edgeLinkId() { |
Simon Hunt | eae81ee | 2016-05-19 12:33:22 -0700 | [diff] [blame] | 138 | return edgeLinkId; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Returns the identifier of the device to which the host is connected. |
| 143 | * |
| 144 | * @return device identifier |
| 145 | */ |
| 146 | public DeviceId locationDevice() { |
| 147 | return locDevice; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Returns the port number of the device to which the host is connected. |
| 152 | * |
| 153 | * @return port number |
| 154 | */ |
| 155 | public PortNumber locationPort() { |
| 156 | return locPort; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 157 | } |
Simon Hunt | 5f6dbf8 | 2016-03-30 08:53:33 -0700 | [diff] [blame] | 158 | } |