Committed by
Gerrit Code Review
[ONOS-4294] AlarmConsumer for Lumentum e-cord device
Change-Id: I653c5136ae5d162e04d67d1a54ce0dd4b95b3866
Showing
7 changed files
with
159 additions
and
5 deletions
| ... | @@ -7,6 +7,8 @@ COMPILE_DEPS = [ | ... | @@ -7,6 +7,8 @@ COMPILE_DEPS = [ |
| 7 | '//lib:CORE_DEPS', | 7 | '//lib:CORE_DEPS', |
| 8 | '//lib:org.apache.servicemix.bundles.snmp4j', | 8 | '//lib:org.apache.servicemix.bundles.snmp4j', |
| 9 | '//drivers/utilities:onos-drivers-utilities', | 9 | '//drivers/utilities:onos-drivers-utilities', |
| 10 | + '//protocols/snmp/api:onos-snmp-api', | ||
| 11 | + '//incubator/api:onos-incubator-api', | ||
| 10 | ] | 12 | ] |
| 11 | 13 | ||
| 12 | osgi_jar( | 14 | osgi_jar( | ... | ... |
| ... | @@ -22,5 +22,7 @@ | ... | @@ -22,5 +22,7 @@ |
| 22 | 22 | ||
| 23 | <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle> | 23 | <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle> |
| 24 | 24 | ||
| 25 | + <bundle>mvn:${project.groupId}/onos-snmp-api/${project.version}</bundle> | ||
| 26 | + | ||
| 25 | </feature> | 27 | </feature> |
| 26 | </features> | 28 | </features> | ... | ... |
| ... | @@ -36,7 +36,8 @@ | ... | @@ -36,7 +36,8 @@ |
| 36 | <onos.app.title>Lumentum Device Drivers</onos.app.title> | 36 | <onos.app.title>Lumentum Device Drivers</onos.app.title> |
| 37 | <onos.app.url>http://onosproject.org</onos.app.url> | 37 | <onos.app.url>http://onosproject.org</onos.app.url> |
| 38 | <onos.app.requires> | 38 | <onos.app.requires> |
| 39 | - org.onosproject.snmp | 39 | + org.onosproject.snmp, |
| 40 | + org.onosproject.faultmanagement | ||
| 40 | </onos.app.requires> | 41 | </onos.app.requires> |
| 41 | </properties> | 42 | </properties> |
| 42 | 43 | ||
| ... | @@ -46,5 +47,10 @@ | ... | @@ -46,5 +47,10 @@ |
| 46 | <artifactId>org.apache.servicemix.bundles.snmp4j</artifactId> | 47 | <artifactId>org.apache.servicemix.bundles.snmp4j</artifactId> |
| 47 | <version>2.3.4_1</version> | 48 | <version>2.3.4_1</version> |
| 48 | </dependency> | 49 | </dependency> |
| 50 | + <dependency> | ||
| 51 | + <groupId>org.onosproject</groupId> | ||
| 52 | + <artifactId>onos-snmp-api</artifactId> | ||
| 53 | + <version>${project.version}</version> | ||
| 54 | + </dependency> | ||
| 49 | </dependencies> | 55 | </dependencies> |
| 50 | </project> | 56 | </project> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumAlarmConsumer.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 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 | + | ||
| 19 | +import com.google.common.collect.ImmutableList; | ||
| 20 | +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; | ||
| 21 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer; | ||
| 22 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; | ||
| 23 | +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; | ||
| 24 | +import org.onosproject.net.DeviceId; | ||
| 25 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
| 26 | +import org.onosproject.snmp.SnmpController; | ||
| 27 | +import org.onosproject.snmp.SnmpDevice; | ||
| 28 | +import org.slf4j.Logger; | ||
| 29 | +import org.snmp4j.smi.OID; | ||
| 30 | +import org.snmp4j.smi.VariableBinding; | ||
| 31 | +import org.snmp4j.util.TreeEvent; | ||
| 32 | + | ||
| 33 | +import java.io.IOException; | ||
| 34 | +import java.util.ArrayList; | ||
| 35 | +import java.util.List; | ||
| 36 | + | ||
| 37 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 38 | +import static org.onosproject.incubator.net.faultmanagement.alarm.Alarm.SeverityLevel; | ||
| 39 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 40 | + | ||
| 41 | +/** | ||
| 42 | + * Alarm Consumer for Lumentum devices. | ||
| 43 | + */ | ||
| 44 | +public class LumentumAlarmConsumer extends AbstractHandlerBehaviour implements AlarmConsumer { | ||
| 45 | + | ||
| 46 | + private final Logger log = getLogger(getClass()); | ||
| 47 | + | ||
| 48 | + private static final String ALARM_TABLE = ".1.3.6.1.4.1.46184.1.3.2"; | ||
| 49 | + private static final String ALARM_ID = ".1.3.6.1.4.1.46184.1.3.2.1.1"; | ||
| 50 | + private static final OID ALARMS_TABLE_OID = new OID(ALARM_TABLE); | ||
| 51 | + private static final OID ALARMS_ID_OID = new OID(ALARM_ID); | ||
| 52 | + private LumentumSnmpDevice snmp; | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public List<Alarm> consumeAlarms() { | ||
| 56 | + | ||
| 57 | + SnmpController controller = checkNotNull(handler().get(SnmpController.class)); | ||
| 58 | + List<Alarm> alarms = new ArrayList<>(); | ||
| 59 | + DeviceId deviceId = handler().data().deviceId(); | ||
| 60 | + SnmpDevice device = controller.getDevice(deviceId); | ||
| 61 | + try { | ||
| 62 | + snmp = new LumentumSnmpDevice(device.getSnmpHost(), device.getSnmpPort()); | ||
| 63 | + } catch (IOException e) { | ||
| 64 | + log.error("Failed to connect to device: ", e); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + // Gets the alarm table and for each entry get the ID and create the proper alarm. | ||
| 68 | + snmp.get(ALARMS_TABLE_OID).stream() | ||
| 69 | + .forEach(alarm -> snmp.get(ALARMS_ID_OID).forEach(alarmIdEvent -> { | ||
| 70 | + int alarmId = getAlarmId(alarmIdEvent); | ||
| 71 | + alarms.add(new DefaultAlarm.Builder(deviceId, getMessage(alarmId), | ||
| 72 | + getSeverity(alarmId), | ||
| 73 | + System.currentTimeMillis()) | ||
| 74 | + .withId(AlarmId.alarmId(alarmId)) | ||
| 75 | + .build()); | ||
| 76 | + })); | ||
| 77 | + return ImmutableList.copyOf(alarms); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + //Walks the tree and retrieves the alarmId | ||
| 81 | + private int getAlarmId(TreeEvent treeEvents) { | ||
| 82 | + VariableBinding[] varBindings = treeEvents.getVariableBindings(); | ||
| 83 | + for (VariableBinding varBinding : varBindings) { | ||
| 84 | + return varBinding.getVariable().toInt(); | ||
| 85 | + } | ||
| 86 | + return -1; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + //Returns the severity level. | ||
| 90 | + private SeverityLevel getSeverity(int alarmId) { | ||
| 91 | + switch (alarmId) { | ||
| 92 | + case 14: | ||
| 93 | + return SeverityLevel.INDETERMINATE; | ||
| 94 | + default: | ||
| 95 | + return SeverityLevel.MAJOR; | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + //Returns a string message based on the id of the alarm as per .mib file. | ||
| 100 | + private String getMessage(int alarmId) { | ||
| 101 | + switch (alarmId) { | ||
| 102 | + case 1: | ||
| 103 | + return "Port Los"; | ||
| 104 | + case 2: | ||
| 105 | + return "Port Degrade"; | ||
| 106 | + case 3: | ||
| 107 | + return "Port High Power"; | ||
| 108 | + case 4: | ||
| 109 | + return "Ta Failure"; | ||
| 110 | + case 5: | ||
| 111 | + return "Force Apr"; | ||
| 112 | + case 6: | ||
| 113 | + return "Force Shutoff"; | ||
| 114 | + case 7: | ||
| 115 | + return "Gain Oor"; | ||
| 116 | + case 8: | ||
| 117 | + return "Low Orl"; | ||
| 118 | + case 9: | ||
| 119 | + return "Apr"; | ||
| 120 | + case 10: | ||
| 121 | + return "Los Shutoff"; | ||
| 122 | + case 11: | ||
| 123 | + return "Amp Degrade"; | ||
| 124 | + case 12: | ||
| 125 | + return "Channel Los"; | ||
| 126 | + case 13: | ||
| 127 | + return "Channel Degrade"; | ||
| 128 | + case 14: | ||
| 129 | + return "Unsupported"; | ||
| 130 | + default: | ||
| 131 | + return "Unknown"; | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | +} |
| ... | @@ -58,10 +58,10 @@ import java.util.stream.Collectors; | ... | @@ -58,10 +58,10 @@ import java.util.stream.Collectors; |
| 58 | import static com.google.common.base.Preconditions.checkArgument; | 58 | import static com.google.common.base.Preconditions.checkArgument; |
| 59 | 59 | ||
| 60 | // TODO: need to convert between OChSignal and XC channel number | 60 | // TODO: need to convert between OChSignal and XC channel number |
| 61 | -public class LumentumFlowRuleDriver extends AbstractHandlerBehaviour implements FlowRuleProgrammable { | 61 | +public class LumentumFlowRuleProgrammable extends AbstractHandlerBehaviour implements FlowRuleProgrammable { |
| 62 | 62 | ||
| 63 | private static final Logger log = | 63 | private static final Logger log = |
| 64 | - LoggerFactory.getLogger(LumentumFlowRuleDriver.class); | 64 | + LoggerFactory.getLogger(LumentumFlowRuleProgrammable.class); |
| 65 | 65 | ||
| 66 | // Default values | 66 | // Default values |
| 67 | private static final int DEFAULT_TARGET_GAIN_PREAMP = 150; | 67 | private static final int DEFAULT_TARGET_GAIN_PREAMP = 150; | ... | ... |
| ... | @@ -40,7 +40,7 @@ import java.util.List; | ... | @@ -40,7 +40,7 @@ import java.util.List; |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | * Quick and dirty device abstraction for SNMP-based Lumentum devices. | 42 | * Quick and dirty device abstraction for SNMP-based Lumentum devices. |
| 43 | - * | 43 | + * <p> |
| 44 | * TODO: Refactor once SnmpDevice is finished | 44 | * TODO: Refactor once SnmpDevice is finished |
| 45 | */ | 45 | */ |
| 46 | public class LumentumSnmpDevice { | 46 | public class LumentumSnmpDevice { |
| ... | @@ -67,6 +67,14 @@ public class LumentumSnmpDevice { | ... | @@ -67,6 +67,14 @@ public class LumentumSnmpDevice { |
| 67 | String ipAddress = deviceComponents[1]; | 67 | String ipAddress = deviceComponents[1]; |
| 68 | String port = deviceComponents[2]; | 68 | String port = deviceComponents[2]; |
| 69 | 69 | ||
| 70 | + createDevice(ipAddress, Integer.parseInt(port)); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public LumentumSnmpDevice(String ipAddress, int port) throws IOException { | ||
| 74 | + createDevice(ipAddress, port); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + private void createDevice(String ipAddress, int port) throws IOException { | ||
| 70 | Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port); | 78 | Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port); |
| 71 | TransportMapping transport = new DefaultUdpTransportMapping(); | 79 | TransportMapping transport = new DefaultUdpTransportMapping(); |
| 72 | transport.listen(); | 80 | transport.listen(); | ... | ... |
| ... | @@ -21,7 +21,9 @@ | ... | @@ -21,7 +21,9 @@ |
| 21 | <behaviour api="org.onosproject.net.behaviour.LambdaQuery" | 21 | <behaviour api="org.onosproject.net.behaviour.LambdaQuery" |
| 22 | impl="org.onosproject.drivers.lumentum.LambdaQueryLumentumRoadm"/> | 22 | impl="org.onosproject.drivers.lumentum.LambdaQueryLumentumRoadm"/> |
| 23 | <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable" | 23 | <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable" |
| 24 | - impl="org.onosproject.drivers.lumentum.LumentumFlowRuleDriver"/> | 24 | + impl="org.onosproject.drivers.lumentum.LumentumFlowRuleProgrammable"/> |
| 25 | + <behaviour api="org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer" | ||
| 26 | + impl="org.onosproject.drivers.lumentum.LumentumAlarmConsumer"/> | ||
| 25 | </driver> | 27 | </driver> |
| 26 | </drivers> | 28 | </drivers> |
| 27 | 29 | ... | ... |
-
Please register or login to post a comment