Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [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.drivers.lumentum; |
| 18 | |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Lists; |
| 21 | import org.onosproject.net.AnnotationKeys; |
| 22 | import org.onosproject.net.DefaultAnnotations; |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 23 | import org.onosproject.net.Device; |
| 24 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 25 | import org.onosproject.net.PortNumber; |
| 26 | import org.onosproject.net.SparseAnnotations; |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 27 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 28 | import org.onosproject.net.device.DeviceDescription; |
| 29 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
| 30 | import org.onosproject.net.device.DeviceService; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 31 | import org.onosproject.net.device.PortDescription; |
| 32 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 33 | import org.slf4j.Logger; |
| 34 | import org.snmp4j.smi.OID; |
| 35 | import org.snmp4j.smi.VariableBinding; |
| 36 | import org.snmp4j.util.TreeEvent; |
| 37 | |
| 38 | import java.io.IOException; |
| 39 | import java.util.Collections; |
| 40 | import java.util.List; |
| 41 | |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 42 | import static com.google.common.base.Preconditions.checkNotNull; |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 43 | import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 44 | import static org.slf4j.LoggerFactory.getLogger; |
| 45 | |
| 46 | /** |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 47 | * Device description behaviour for Lumentum Snmp devices. |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 48 | */ |
Marc De Leenheer | 57a5af0 | 2016-12-02 20:54:41 -0800 | [diff] [blame] | 49 | public class LumentumRoadmDiscovery extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery { |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 50 | |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 51 | private final Logger log = getLogger(getClass()); |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 52 | |
| 53 | private static final String CTRL_PORT_STATE = ".1.3.6.1.4.1.46184.1.4.1.1.3."; |
| 54 | |
| 55 | private LumentumSnmpDevice snmp; |
| 56 | |
| 57 | @Override |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 58 | public DeviceDescription discoverDeviceDetails() { |
| 59 | //TODO get device description |
| 60 | DeviceService deviceService = checkNotNull(handler().get(DeviceService.class)); |
| 61 | DeviceId deviceId = handler().data().deviceId(); |
| 62 | Device device = deviceService.getDevice(deviceId); |
| 63 | return new DefaultDeviceDescription(device.id().uri(), Device.Type.ROADM, |
| 64 | "Lumentum", "SDN ROADM", "1.0", "v1", |
| 65 | device.chassisId(), (SparseAnnotations) device.annotations()); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public List<PortDescription> discoverPortDetails() { |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 70 | return ImmutableList.copyOf(this.getPorts()); |
Andrea Campanella | c2d754b | 2016-03-29 17:51:07 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | private List<PortDescription> getPorts() { |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 74 | try { |
| 75 | snmp = new LumentumSnmpDevice(handler().data().deviceId()); |
| 76 | } catch (IOException e) { |
| 77 | log.error("Failed to connect to device: ", e); |
| 78 | |
| 79 | return Collections.emptyList(); |
| 80 | } |
| 81 | |
| 82 | List<PortDescription> ports = Lists.newLinkedList(); |
| 83 | |
| 84 | OID[] oids = { |
| 85 | new OID(CTRL_PORT_STATE + "1"), |
| 86 | new OID(CTRL_PORT_STATE + "2") |
| 87 | }; |
| 88 | |
| 89 | for (OID oid : oids) { |
| 90 | |
| 91 | for (TreeEvent event : snmp.get(oid)) { |
| 92 | if (event != null) { |
| 93 | VariableBinding[] varBindings = event.getVariableBindings(); |
| 94 | for (VariableBinding varBinding : varBindings) { |
| 95 | if (varBinding.getVariable().toInt() == 1) { |
| 96 | int portNumber = varBinding.getOid().removeLast(); |
| 97 | int portDirection = varBinding.getOid().removeLast(); |
| 98 | SparseAnnotations ann = DefaultAnnotations.builder() |
| 99 | .set(AnnotationKeys.PORT_NAME, portDirection + "-" + portNumber) |
| 100 | .build(); |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 101 | PortDescription p = omsPortDescription( |
Ray Milkey | 3717e60 | 2018-02-01 13:49:47 -0800 | [diff] [blame] | 102 | PortNumber.portNumber(ports.size() + 1L), |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 103 | true, |
| 104 | LumentumSnmpDevice.START_CENTER_FREQ, |
| 105 | LumentumSnmpDevice.END_CENTER_FREQ, |
| 106 | LumentumSnmpDevice.CHANNEL_SPACING.frequency(), |
| 107 | ann); |
| 108 | ports.add(p); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // Create LINE IN and LINE OUT ports as these are not reported through SNMP |
| 116 | SparseAnnotations annLineIn = DefaultAnnotations.builder() |
| 117 | .set(AnnotationKeys.PORT_NAME, "LINE IN") |
| 118 | .build(); |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 119 | ports.add(omsPortDescription( |
Ray Milkey | 3717e60 | 2018-02-01 13:49:47 -0800 | [diff] [blame] | 120 | PortNumber.portNumber(ports.size() + 1L), |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 121 | true, |
| 122 | LumentumSnmpDevice.START_CENTER_FREQ, |
| 123 | LumentumSnmpDevice.END_CENTER_FREQ, |
| 124 | LumentumSnmpDevice.CHANNEL_SPACING.frequency(), |
| 125 | annLineIn |
| 126 | )); |
| 127 | |
| 128 | SparseAnnotations annLineOut = DefaultAnnotations.builder() |
| 129 | .set(AnnotationKeys.PORT_NAME, "LINE OUT") |
| 130 | .build(); |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 131 | ports.add(omsPortDescription( |
Ray Milkey | 3717e60 | 2018-02-01 13:49:47 -0800 | [diff] [blame] | 132 | PortNumber.portNumber(ports.size() + 1L), |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 133 | true, |
| 134 | LumentumSnmpDevice.START_CENTER_FREQ, |
| 135 | LumentumSnmpDevice.END_CENTER_FREQ, |
| 136 | LumentumSnmpDevice.CHANNEL_SPACING.frequency(), |
| 137 | annLineOut |
| 138 | )); |
| 139 | |
| 140 | return ports; |
| 141 | } |
| 142 | } |