ONOS-5917 SNMP Alarm Provider
Change-Id: I9eb39021584f3b1a5baed9dfa638569818901197
diff --git a/protocols/snmp/api/BUCK b/protocols/snmp/api/BUCK
index 067c6ea..897a0ac 100644
--- a/protocols/snmp/api/BUCK
+++ b/protocols/snmp/api/BUCK
@@ -1,5 +1,6 @@
COMPILE_DEPS = [
'//lib:CORE_DEPS',
+ '//lib:JACKSON',
'//incubator/api:onos-incubator-api',
'//lib:org.apache.servicemix.bundles.snmp4j',
'//lib:snmp-core',
diff --git a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpController.java b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpController.java
index 0369fc2..4868ea0 100644
--- a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpController.java
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpController.java
@@ -17,15 +17,19 @@
package org.onosproject.snmp;
import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
+import com.google.common.annotations.Beta;
+
import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
import org.onosproject.net.DeviceId;
import java.io.IOException;
+import java.net.URI;
import java.util.Collection;
/**
* Snmp Controller.
*/
+@Beta
public interface SnmpController {
/**
@@ -42,6 +46,14 @@
SnmpDevice getDevice(DeviceId deviceId);
/**
+ * Gets a device for a specific host address.
+ *
+ * @param uri URI of the device
+ * @return SnmpDevice for given deviceId
+ */
+ SnmpDevice getDevice(URI uri);
+
+ /**
* Removes a specific device.
* @param deviceId device id of the device to be removed
*/
@@ -50,9 +62,18 @@
/**
* Add a device with a specific DeviceId.
* @param deviceId deviceId of the device
+ * @param device device to add to this controller
+ * @deprecated 1.10.0 moved to single parameter method with boolean return
+ */
+ @Deprecated
+ void addDevice(DeviceId deviceId, SnmpDevice device);
+
+ /**
+ * Add a snmp device.
+ *
* @param device device to add to this controller
*/
- void addDevice(DeviceId deviceId, SnmpDevice device);
+ void addDevice(SnmpDevice device);
/**
* Gets an Instance of ISnmpSession for a specific device.
@@ -60,7 +81,9 @@
* @param deviceId device to retrieve the session for.
* @return ISnmp session.
* @throws IOException if the session can't be established.
+ * @deprecated 1.14.0 moved to snmp4j
*/
+ @Deprecated
ISnmpSession getSession(DeviceId deviceId) throws IOException;
/**
@@ -70,4 +93,6 @@
* @return default alarm error
*/
DefaultAlarm buildWalkFailedAlarm(DeviceId deviceId);
+
+
}
diff --git a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDevice.java b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDevice.java
index bd7b3c4..587e2b1 100644
--- a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDevice.java
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDevice.java
@@ -16,11 +16,14 @@
package org.onosproject.snmp;
+import com.google.common.annotations.Beta;
import org.onosproject.net.DeviceId;
+import org.snmp4j.Snmp;
/**
* Abstraction a default Snmp Device.
*/
+@Beta
public interface SnmpDevice {
/**
@@ -31,6 +34,13 @@
String deviceInfo();
/**
+ * Returns an Snmp session context for this device.
+ *
+ * @return snmp session
+ */
+ Snmp getSession();
+
+ /**
* Terminates the device connection.
*/
void disconnect();
@@ -57,6 +67,13 @@
int getSnmpPort();
/**
+ * Returns the notification port for asynchronous messages from the device.
+ *
+ * @return notification port
+ */
+ int getNotificationPort();
+
+ /**
* Retrieves the username of the device.
*
* @return username
@@ -71,6 +88,20 @@
String getCommunity();
/**
+ * Returns the protocol of the device.
+ *
+ * @return protocol
+ */
+ String getProtocol();
+
+ /**
+ * Returns the notification protocol of the device.
+ *
+ * @return notification protocol
+ */
+ String getNotificationProtocol();
+
+ /**
* Return the SNMP device deviceID.
*
* @return DeviceId
diff --git a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDeviceConfig.java b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDeviceConfig.java
new file mode 100644
index 0000000..b39180a
--- /dev/null
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDeviceConfig.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.snmp;
+
+import com.google.common.annotations.Beta;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.Config;
+
+/**
+ * Configuration to push devices to the SNMP provider.
+ */
+@Beta
+public class SnmpDeviceConfig extends Config<DeviceId> {
+
+ private static final String PROTOCOL = "protocol";
+ private static final String NOTIFICATION_PROTOCOL = "notificationProtocol";
+ private static final String IP = "ip";
+ private static final String PORT = "port";
+ private static final int DEFAULT_PORT = 161;
+ private static final String NOTIFICATION_PORT = "notificationPort";
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+
+ @Override
+ public boolean isValid() {
+ return hasOnlyFields(IP, PORT, USERNAME, PASSWORD) &&
+ ip() != null;
+ }
+
+ /**
+ * Gets the protocol of the SNMP device.
+ *
+ * @return protocol
+ */
+ public String protocol() {
+ return get(PROTOCOL, "udp");
+ }
+
+ /**
+ * Gets the notification protocol of the SNMP device.
+ *
+ * @return notification protocol
+ */
+ public String notificationProtocol() {
+ return get(NOTIFICATION_PROTOCOL, "udp");
+ }
+
+ /**
+ * Gets the Ip of the SNMP device.
+ *
+ * @return ip
+ */
+ public IpAddress ip() {
+ return IpAddress.valueOf(get(IP, extractIpPort().getKey()));
+ }
+
+ /**
+ * Gets the port of the SNMP device.
+ *
+ * @return port
+ */
+ public int port() {
+ return get(PORT, extractIpPort().getValue());
+ }
+
+ /**
+ * Gets the notification port of the SNMP device.
+ *
+ * @return notification port
+ */
+ public int notificationPort() {
+ return get(NOTIFICATION_PORT, 0);
+ }
+
+ /**
+ * Gets the username of the SNMP device.
+ *
+ * @return username
+ */
+ public String username() {
+ return get(USERNAME, "");
+ }
+
+ /**
+ * Gets the password of the SNMP device.
+ *
+ * @return password
+ */
+ public String password() {
+ return get(PASSWORD, "");
+ }
+
+
+ private Pair<String, Integer> extractIpPort() {
+ String info = subject.uri().getSchemeSpecificPart();
+ int portSeparator = info.lastIndexOf(':');
+ if (portSeparator == -1) {
+ return Pair.of(info, DEFAULT_PORT);
+ }
+
+ String ip = info.substring(0, portSeparator);
+ int port = Integer.parseInt(info.substring(portSeparator + 1));
+ return Pair.of(ip, port);
+ }
+}