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