blob: 377dc16c08a5f08f7d067558085743e20ee13352 [file] [log] [blame]
Simon Hunt5f6dbf82016-03-30 08:53:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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 /**
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 Hunt642bc452016-05-04 19:34:45 -070084 @Override
85 public String idAsString() {
86 return id().toString();
87 }
Simon Huntc0f20c12016-05-09 09:30:20 -070088
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 Vachuskab877a6f2017-04-14 11:43:30 -0700116 return topology.services.host().getHost(hostId);
Simon Huntc0f20c12016-05-09 09:30:20 -0700117 }
118
119 /**
Simon Hunteae81ee2016-05-19 12:33:22 -0700120 * Returns the identifier for the edge link between this host and
121 * the device to which it is connected.
Simon Huntc0f20c12016-05-09 09:30:20 -0700122 *
123 * @return edge link identifier
124 */
125 public UiLinkId edgeLinkId() {
Simon Hunteae81ee2016-05-19 12:33:22 -0700126 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 Huntc0f20c12016-05-09 09:30:20 -0700145 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700146}