blob: c05d27bbcee1e254a6e96ba211877d2e02e668a5 [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 com.google.common.base.MoreObjects;
Simon Huntd5b96732016-07-08 13:22:27 -070020import org.onosproject.cluster.NodeId;
Simon Hunt23fb1352016-04-11 12:15:19 -070021import org.onosproject.net.Device;
Simon Hunt642bc452016-05-04 19:34:45 -070022import org.onosproject.net.DeviceId;
Simon Huntc0f20c12016-05-09 09:30:20 -070023import org.onosproject.net.region.RegionId;
Simon Hunt23fb1352016-04-11 12:15:19 -070024
Simon Hunt5f6dbf82016-03-30 08:53:33 -070025/**
26 * Represents a device.
27 */
28public class UiDevice extends UiNode {
Simon Hunt23fb1352016-04-11 12:15:19 -070029
Simon Huntc0f20c12016-05-09 09:30:20 -070030 private final UiTopology topology;
31 private final Device device;
32
33 private RegionId regionId;
Simon Huntd5b96732016-07-08 13:22:27 -070034 private NodeId masterId;
Simon Huntc0f20c12016-05-09 09:30:20 -070035
36 /**
37 * Creates a new UI device.
38 *
39 * @param topology parent topology
40 * @param device backing device
41 */
42 public UiDevice(UiTopology topology, Device device) {
43 this.topology = topology;
44 this.device = device;
45 }
46
47 /**
48 * Sets the ID of the region to which this device belongs.
49 *
50 * @param regionId region identifier
51 */
52 public void setRegionId(RegionId regionId) {
53 this.regionId = regionId;
54 }
Simon Hunt23fb1352016-04-11 12:15:19 -070055
Simon Huntd5b96732016-07-08 13:22:27 -070056 /**
57 * Sets the ID of the controller node that holds mastership for this device.
58 *
59 * @param masterId master identifier
60 */
61 public void setMasterId(NodeId masterId) {
62 this.masterId = masterId;
63 }
64
Simon Hunt23fb1352016-04-11 12:15:19 -070065 @Override
Simon Huntc0f20c12016-05-09 09:30:20 -070066 public String toString() {
67 return MoreObjects.toStringHelper(this)
68 .add("id", id())
69 .add("region", regionId)
70 .toString();
Simon Hunt23fb1352016-04-11 12:15:19 -070071 }
Simon Hunt642bc452016-05-04 19:34:45 -070072
Simon Huntc0f20c12016-05-09 09:30:20 -070073 // @Override
74// protected void destroy() {
75// }
76
Simon Hunt642bc452016-05-04 19:34:45 -070077 /**
78 * Returns the identity of the device.
79 *
80 * @return device ID
81 */
82 public DeviceId id() {
83 return device.id();
84 }
85
86 @Override
87 public String idAsString() {
88 return id().toString();
89 }
Simon Huntc0f20c12016-05-09 09:30:20 -070090
91 /**
92 * Returns the device instance backing this UI device.
93 *
94 * @return the backing device instance
95 */
96 public Device backingDevice() {
97 return device;
98 }
99
100 /**
Simon Hunt58a0dd02016-05-17 11:54:23 -0700101 * Returns the identifier of the region to which this device belongs.
102 * This will be null if the device does not belong to any region.
103 *
104 * @return region identity
105 */
106 public RegionId regionId() {
107 return regionId;
108 }
109
110 /**
Simon Huntc0f20c12016-05-09 09:30:20 -0700111 * Returns the UI region to which this device belongs.
112 *
113 * @return the UI region
114 */
115 public UiRegion uiRegion() {
116 return topology.findRegion(regionId);
117 }
Simon Huntd5b96732016-07-08 13:22:27 -0700118
119 /**
120 * Returns a string representation of the type of the backing device.
121 *
122 * @return the device type
123 */
124 public String type() {
125 return device.type().toString().toLowerCase();
126 }
127
128 /**
Simon Huntd5b96732016-07-08 13:22:27 -0700129 * Returns the identifier for the cluster member that has
130 * mastership over this device.
131 *
132 * @return master cluster member identifier
133 */
134 public NodeId master() {
135 return masterId;
136 }
Simon Hunt5f6dbf82016-03-30 08:53:33 -0700137}