blob: 10dfbf1fb93b3a3486c643f1b94b3076721c5976 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Simon Hunt5f6dbf82016-03-30 08:53:33 -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
Simon Huntc0f20c12016-05-09 09:30:20 -070019import org.onosproject.net.DeviceId;
Simon Hunt23fb1352016-04-11 12:15:19 -070020import org.onosproject.net.Host;
Simon Hunt642bc452016-05-04 19:34:45 -070021import org.onosproject.net.HostId;
Simon Huntc0f20c12016-05-09 09:30:20 -070022import org.onosproject.net.PortNumber;
Steven Burrows19e6e4f2016-10-05 13:27:07 -050023import org.onosproject.net.region.RegionId;
Simon Huntc0f20c12016-05-09 09:30:20 -070024
25import static com.google.common.base.MoreObjects.toStringHelper;
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070026import static com.google.common.base.Preconditions.checkNotNull;
Simon Hunt23fb1352016-04-11 12:15:19 -070027
Simon Hunt5f6dbf82016-03-30 08:53:33 -070028/**
29 * Represents an end-station host.
30 */
31public class UiHost extends UiNode {
Simon Hunt23fb1352016-04-11 12:15:19 -070032
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070033 private static final String HOST_CANNOT_BE_NULL = "Host cannot be null";
34
Simon Huntc0f20c12016-05-09 09:30:20 -070035 private final UiTopology topology;
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070036 private final HostId hostId;
Simon Huntc0f20c12016-05-09 09:30:20 -070037
38 // Host location
39 private DeviceId locDevice;
40 private PortNumber locPort;
41
42 private UiLinkId edgeLinkId;
Steven Burrows19e6e4f2016-10-05 13:27:07 -050043 private RegionId regionId;
Simon Huntc0f20c12016-05-09 09:30:20 -070044
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 Vachuskab877a6f2017-04-14 11:43:30 -070052 checkNotNull(host, HOST_CANNOT_BE_NULL);
Simon Huntc0f20c12016-05-09 09:30:20 -070053 this.topology = topology;
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070054 this.hostId = host.id();
Sean Condon28884332019-03-21 14:07:00 +000055 this.regionId = RegionId.regionId(UiRegion.NULL_NAME);
Simon Huntc0f20c12016-05-09 09:30:20 -070056 }
57
Simon Hunt23fb1352016-04-11 12:15:19 -070058 @Override
Simon Huntc0f20c12016-05-09 09:30:20 -070059 public String toString() {
60 return toStringHelper(this)
61 .add("id", id())
62 .add("dev", locDevice)
63 .add("port", locPort)
Sean Condon28884332019-03-21 14:07:00 +000064 .add("Region", regionId)
Simon Huntc0f20c12016-05-09 09:30:20 -070065 .toString();
Simon Hunt23fb1352016-04-11 12:15:19 -070066 }
Simon Hunt642bc452016-05-04 19:34:45 -070067
68 /**
69 * Returns the identity of the host.
70 *
71 * @return host ID
72 */
73 public HostId id() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070074 return hostId;
Simon Hunt642bc452016-05-04 19:34:45 -070075 }
76
Steven Burrows19e6e4f2016-10-05 13:27:07 -050077 /**
Sean Condonee545762019-03-09 10:43:58 +000078 * 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 Burrows19e6e4f2016-10-05 13:27:07 -050088 * 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 Hunt642bc452016-05-04 19:34:45 -070096 @Override
97 public String idAsString() {
98 return id().toString();
99 }
Simon Huntc0f20c12016-05-09 09:30:20 -0700100
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 Vachuskab877a6f2017-04-14 11:43:30 -0700128 return topology.services.host().getHost(hostId);
Simon Huntc0f20c12016-05-09 09:30:20 -0700129 }
130
131 /**
Simon Hunteae81ee2016-05-19 12:33:22 -0700132 * Returns the identifier for the edge link between this host and
133 * the device to which it is connected.
Simon Huntc0f20c12016-05-09 09:30:20 -0700134 *
135 * @return edge link identifier
136 */
137 public UiLinkId edgeLinkId() {
Simon Hunteae81ee2016-05-19 12:33:22 -0700138 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 Huntc0f20c12016-05-09 09:30:20 -0700157 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700158}