blob: 5ca86e3d2441860d5ea5ad7d26384704d1c3b8d4 [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();
Simon Huntc0f20c12016-05-09 09:30:20 -070055 }
56
Simon Hunt23fb1352016-04-11 12:15:19 -070057 @Override
Simon Huntc0f20c12016-05-09 09:30:20 -070058 public String toString() {
59 return toStringHelper(this)
60 .add("id", id())
61 .add("dev", locDevice)
62 .add("port", locPort)
63 .toString();
Simon Hunt23fb1352016-04-11 12:15:19 -070064 }
Simon Hunt642bc452016-05-04 19:34:45 -070065
66 /**
67 * Returns the identity of the host.
68 *
69 * @return host ID
70 */
71 public HostId id() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070072 return hostId;
Simon Hunt642bc452016-05-04 19:34:45 -070073 }
74
Steven Burrows19e6e4f2016-10-05 13:27:07 -050075 /**
Sean Condonee545762019-03-09 10:43:58 +000076 * Returns the identifier of the region to which this device belongs.
77 * This will be null if the device does not belong to any region.
78 *
79 * @return region ID
80 */
81 public RegionId regionId() {
82 return regionId;
83 }
84
85 /**
Steven Burrows19e6e4f2016-10-05 13:27:07 -050086 * Sets the ID of the region to which this device belongs.
87 *
88 * @param regionId region identifier
89 */
90 public void setRegionId(RegionId regionId) {
91 this.regionId = regionId;
92 }
93
Simon Hunt642bc452016-05-04 19:34:45 -070094 @Override
95 public String idAsString() {
96 return id().toString();
97 }
Simon Huntc0f20c12016-05-09 09:30:20 -070098
99 /**
100 * Sets the host's current location.
101 *
102 * @param deviceId ID of device
103 * @param port port number
104 */
105 public void setLocation(DeviceId deviceId, PortNumber port) {
106 locDevice = deviceId;
107 locPort = port;
108 }
109
110 /**
111 * Sets the ID of the edge link between this host and the device to which
112 * it connects.
113 *
114 * @param id edge link identifier to set
115 */
116 public void setEdgeLinkId(UiLinkId id) {
117 this.edgeLinkId = id;
118 }
119
120 /**
121 * Returns the host instance backing this UI host.
122 *
123 * @return the backing host instance
124 */
125 public Host backingHost() {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -0700126 return topology.services.host().getHost(hostId);
Simon Huntc0f20c12016-05-09 09:30:20 -0700127 }
128
129 /**
Simon Hunteae81ee2016-05-19 12:33:22 -0700130 * Returns the identifier for the edge link between this host and
131 * the device to which it is connected.
Simon Huntc0f20c12016-05-09 09:30:20 -0700132 *
133 * @return edge link identifier
134 */
135 public UiLinkId edgeLinkId() {
Simon Hunteae81ee2016-05-19 12:33:22 -0700136 return edgeLinkId;
137 }
138
139 /**
140 * Returns the identifier of the device to which the host is connected.
141 *
142 * @return device identifier
143 */
144 public DeviceId locationDevice() {
145 return locDevice;
146 }
147
148 /**
149 * Returns the port number of the device to which the host is connected.
150 *
151 * @return port number
152 */
153 public PortNumber locationPort() {
154 return locPort;
Simon Huntc0f20c12016-05-09 09:30:20 -0700155 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700156}