blob: 410a5b43708713a3a7933351ba377ddb51007a0b [file] [log] [blame]
Georgios Katsikas83600982017-05-28 20:41:45 +02001/*
2 * Copyright 2017-present Open Networking Foundation
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
17package org.onosproject.drivers.server.impl.devices;
18
19import org.onosproject.drivers.server.devices.CpuDevice;
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020020import org.onosproject.drivers.server.devices.nic.NicDevice;
Georgios Katsikas83600982017-05-28 20:41:45 +020021import org.onosproject.drivers.server.devices.RestServerSBDevice;
22
23import org.onosproject.protocol.rest.DefaultRestSBDevice;
24import org.onosproject.protocol.rest.RestSBDevice.AuthenticationScheme;
25import org.onlab.packet.IpAddress;
26
27import com.google.common.base.MoreObjects;
28import com.google.common.collect.Lists;
29
30import java.util.Objects;
31import java.util.Collection;
32
33import static com.google.common.base.Preconditions.checkNotNull;
34
35/**
36 * Default implementation for REST server devices.
37 */
38public class DefaultRestServerSBDevice
39 extends DefaultRestSBDevice implements RestServerSBDevice {
40
41 private Collection<CpuDevice> cpus = Lists.newArrayList();
42 private Collection<NicDevice> nics = Lists.newArrayList();
43
44 public DefaultRestServerSBDevice(
45 IpAddress ip, int port, String name, String password,
46 String protocol, String url, boolean isActive,
47 Collection<CpuDevice> cpus, Collection<NicDevice> nics) {
48 this(
49 ip, port, name, password, protocol, url, isActive,
50 "", "", "", "", AuthenticationScheme.BASIC, "", cpus, nics
51 );
52 }
53
54 public DefaultRestServerSBDevice(
55 IpAddress ip, int port, String name, String password,
56 String protocol, String url, boolean isActive, String testUrl,
57 String manufacturer, String hwVersion, String swVersion,
58 AuthenticationScheme authenticationScheme, String token,
59 Collection<CpuDevice> cpus, Collection<NicDevice> nics) {
60 super(
61 ip, port, name, password, protocol, url, isActive,
62 testUrl, manufacturer, hwVersion, swVersion,
63 authenticationScheme, token
64 );
65
66 checkNotNull(cpus, "Device's set of CPUs cannot be null");
67 checkNotNull(nics, "Device's set of NICs cannot be null");
68
69 this.cpus = cpus;
70 this.nics = nics;
71 }
72
73 @Override
74 public Collection<CpuDevice> cpus() {
75 return this.cpus;
76 }
77
78 @Override
79 public int numberOfCpus() {
80 return this.cpus.size();
81 }
82
83 @Override
84 public Collection<NicDevice> nics() {
85 return this.nics;
86 }
87
88 @Override
89 public int numberOfNics() {
90 return this.nics.size();
91 }
92
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(this)
96 .omitNullValues()
97 .add("url", url())
98 .add("testUrl", testUrl())
99 .add("protocol", protocol())
100 .add("username", username())
101 .add("port", port())
102 .add("ip", ip())
103 .add("manufacturer", manufacturer().orElse(null))
104 .add("hwVersion", hwVersion().orElse(null))
105 .add("swVersion", swVersion().orElse(null))
106 .add("cpus", cpus())
107 .add("nics", nics())
108 .toString();
109
110 }
111
112 @Override
113 public boolean equals(Object obj) {
114 if (obj == this) {
115 return true;
116 }
117 if (!(obj instanceof RestServerSBDevice)) {
118 return false;
119 }
120 RestServerSBDevice device = (RestServerSBDevice) obj;
121
122 return this.username().equals(device.username()) &&
123 this.ip().equals(device.ip()) &&
124 this.port() == device.port();
125 }
126
127 @Override
128 public int hashCode() {
129 return Objects.hash(ip(), port(), cpus(), nics());
130 }
131
132}