blob: ff2862d95051e1edb4c1aa2de66a3e816811cb46 [file] [log] [blame]
Laszlo Papp504510d2018-05-22 15:38:24 +01001/*
2 * Copyright 2018-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.polatis.snmp;
18
19import com.google.common.collect.Lists;
20import org.onosproject.net.Device;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.SparseAnnotations;
23import org.onosproject.net.device.DefaultDeviceDescription;
24import org.onosproject.net.device.DeviceDescription;
25import org.onosproject.net.device.DeviceDescriptionDiscovery;
26import org.onosproject.net.device.DeviceService;
27import org.onosproject.net.device.PortDescription;
28import org.onosproject.net.driver.AbstractHandlerBehaviour;
29
30import org.onlab.packet.ChassisId;
31
32import org.slf4j.Logger;
33
34import java.io.IOException;
35import java.util.List;
36
37import static com.google.common.base.Preconditions.checkNotNull;
38import static org.slf4j.LoggerFactory.getLogger;
39
40import static org.onosproject.drivers.polatis.snmp.PolatisSnmpUtility.getOid;
41
42/**
43 * Representation of device information and ports via SNMP for all Polatis
44 * optical circuit switches.
45 */
46public class PolatisDeviceDescription extends AbstractHandlerBehaviour
47 implements DeviceDescriptionDiscovery {
48
49 private static final String DEFAULT_MANUFACTURER = "Polatis";
50 private static final String DEFAULT_DESCRIPTION_DATA = "Unknown";
51
52 private static final String SOFTWARE_VERSION_OID = ".1.3.6.1.4.1.26592.2.1.2.2.3.0";
53 private static final String PRODUCT_CODE_OID = ".1.3.6.1.4.1.26592.2.1.2.2.1.0";
54 private static final String SERIAL_NUMBER_OID = ".1.3.6.1.4.1.26592.2.1.2.2.2.0";
55
56 private final Logger log = getLogger(getClass());
57
58 /**
59 * Discovers device details, for Polatis Snmp device by getting the system
60 * information.
61 *
62 * @return device description
63 */
64 @Override
65 public DeviceDescription discoverDeviceDetails() {
66 DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
67 DeviceId deviceId = handler().data().deviceId();
68 Device device = deviceService.getDevice(deviceId);
69 if (device == null) {
70 return new DefaultDeviceDescription(deviceId.uri(), Device.Type.FIBER_SWITCH,
71 DEFAULT_MANUFACTURER, DEFAULT_DESCRIPTION_DATA,
72 DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA,
73 new ChassisId());
74 }
75 String hardwareVersion = DEFAULT_DESCRIPTION_DATA;
76 try {
77 hardwareVersion = hardwareVersion();
78 } catch (IOException e) {
79 log.error("Error reading hardware version for device {} exception {}", deviceId, e);
80 }
81
82 String softwareVersion = DEFAULT_DESCRIPTION_DATA;
83 try {
84 softwareVersion = softwareVersion();
85 } catch (IOException e) {
86 log.error("Error reading software version for device {} exception {}", deviceId, e);
87 }
88
89 String serialNumber = DEFAULT_DESCRIPTION_DATA;
90 try {
91 serialNumber = serialNumber();
92 } catch (IOException e) {
93 log.error("Error reading serial number for device {} exception {}", deviceId, e);
94 }
95
96 return new DefaultDeviceDescription(deviceId.uri(), Device.Type.FIBER_SWITCH,
97 DEFAULT_MANUFACTURER, hardwareVersion,
98 softwareVersion, serialNumber,
99 device.chassisId(), (SparseAnnotations) device.annotations());
100 }
101
102 /**
103 * Discovers port details, for Polatis Snmp device.
104 *
105 * @return port list
106 */
107 @Override
108 public List<PortDescription> discoverPortDetails() {
109 // TODO: Implement me
110 return Lists.newLinkedList();
111 // return ImmutableList.copyOf(this.getPorts());
112 }
113
114 private String hardwareVersion() throws IOException {
115 return getOid(handler(), PRODUCT_CODE_OID);
116 }
117
118 private String softwareVersion() throws IOException {
119 return getOid(handler(), SOFTWARE_VERSION_OID);
120 }
121
122 private String serialNumber() throws IOException {
123 return getOid(handler(), SERIAL_NUMBER_OID);
124 }
125}