SNMPv3 protocol support for onos.
Implement RFC-rfc3414 standard.
Change-Id: Ibe8d10aaaf569274b922a7500ed237a9813c0428
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 587e2b1..14f954a 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
@@ -107,4 +107,11 @@
* @return DeviceId
*/
DeviceId deviceId();
+
+ /**
+ * Return the SNMP protocol version.
+ *
+ * @return SNMP protocol version
+ */
+ int getVersion();
}
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
index 47446ea..8776b3d 100644
--- a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDeviceConfig.java
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpDeviceConfig.java
@@ -21,6 +21,7 @@
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.config.Config;
+import org.snmp4j.mp.SnmpConstants;
/**
* Configuration to push devices to the SNMP provider.
@@ -36,6 +37,15 @@
private static final String NOTIFICATION_PORT = "notificationPort";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
+ public static final String VERSION = "version";
+ public static final String SECURITY_NAME = "securityName";
+ public static final String SECURITY_LEVEL = "securityLevel";
+ public static final String AUTH_PROTOCOL = "authProtocol";
+ public static final String AUTH_PASSWORD = "authPassword";
+ public static final String PRIVACY_PROTOCOL = "privacyProtocol";
+ public static final String PRIVACY_PASSWORD = "privacyPassword";
+ public static final String CONTEXT_NAME = "contextName";
+
@Override
public boolean isValid() {
@@ -107,6 +117,77 @@
return get(PASSWORD, "");
}
+ /**
+ * Gets the version of the SNMP device.
+ *
+ * @return snmp version
+ */
+ public int version() {
+ return get(VERSION, SnmpConstants.version2c);
+ }
+
+ /**
+ * Gets the securityName of the SNMPv3 device.
+ *
+ * @return securityName
+ */
+ public String securityName() {
+ return get(SECURITY_NAME, "");
+ }
+
+ /**
+ * Gets the securityLevel of the SNMPv3 device.
+ *
+ * @return securityLevel
+ */
+ public String securityLevel() {
+ return get(SECURITY_LEVEL, "");
+ }
+
+ /**
+ * Gets the authProtocol of the SNMPv3 device.
+ *
+ * @return authProtocol
+ */
+ public String authProtocol() {
+ return get(AUTH_PROTOCOL, "");
+ }
+
+ /**
+ * Gets the authPassword of the SNMPv3 device.
+ *
+ * @return authPassword
+ */
+ public String authPassword() {
+ return get(AUTH_PASSWORD, "");
+ }
+
+ /**
+ * Gets the privacyProtocol of the SNMPv3 device.
+ *
+ * @return privacyProtocol
+ */
+ public String privacyProtocol() {
+ return get(PRIVACY_PROTOCOL, "");
+ }
+
+ /**
+ * Gets the privacyPassword of the SNMPv3 device.
+ *
+ * @return privacyPassword
+ */
+ public String privacyPassword() {
+ return get(PRIVACY_PASSWORD, "");
+ }
+
+ /**
+ * Gets the context name of the SNMPv3 device.
+ *
+ * @return context name
+ */
+ public String contextName() {
+ return get(CONTEXT_NAME, "");
+ }
private Pair<String, Integer> extractIpPort() {
String info = subject.uri().getSchemeSpecificPart();
diff --git a/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpException.java b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpException.java
new file mode 100644
index 0000000..ad22916
--- /dev/null
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/SnmpException.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2021-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;
+
+/**
+ * Custom Exception for SNMP.
+ */
+public class SnmpException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor to create a new snmp exception.
+ */
+ public SnmpException() {
+ super();
+ }
+
+ /**
+ * Constructor to create exception from message and cause.
+ *
+ * @param text the detail of exception in string
+ * @param variables underlying cause of exception variables
+ */
+ public SnmpException(String text, String... variables) {
+ super(format(text, variables));
+ }
+
+ private static String format(String text, String... variables) {
+ return String.format(text, (Object[]) variables);
+ }
+
+ /**
+ * Constructor to create exception from message and cause.
+ *
+ * @param cause underlying cause of the error
+ * @param text the detail of exception in string
+ * @param variables underlying cause of exception variables
+ */
+ public SnmpException(Throwable cause, String text, String... variables) {
+ super(format(text, variables), cause);
+
+ }
+}
\ No newline at end of file
diff --git a/protocols/snmp/api/src/main/java/org/onosproject/snmp/Snmpv3Configuration.java b/protocols/snmp/api/src/main/java/org/onosproject/snmp/Snmpv3Configuration.java
new file mode 100644
index 0000000..4fdafa0
--- /dev/null
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/Snmpv3Configuration.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2021-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.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
+import org.onlab.packet.IpAddress;
+import org.snmp4j.security.SecurityLevel;
+import org.snmp4j.smi.OID;
+import org.snmp4j.util.PDUFactory;
+
+import java.io.Serializable;
+
+/**
+ * Abstraction of SNMPv3 configuration.
+ */
+public interface Snmpv3Configuration extends Serializable, ISnmpConfiguration {
+
+ /**
+ * Returns the ip address.
+ *
+ * @return ip address
+ */
+ IpAddress getAddress();
+
+ /**
+ * Returns the snmpv3 security name of the device.
+ * the SNMPv3 username.
+ *
+ * @return security name
+ */
+ String getSecurityName();
+
+ /**
+ * Returns the snmpv3 security level of the device.
+ * the security level is noAuthNoPriv or authNoPriv or authPriv
+ *
+ * @return security level
+ */
+ SecurityLevel getSecurityLevel();
+
+ /**
+ * Returns the snmpv3 authentication protocol of the device.
+ * the authentication method (either MD5 or SHA)
+ *
+ * @return authentication protocol
+ */
+ OID getAuthenticationProtocol();
+
+ /**
+ * Returns the snmpv3 authentication password of the device.
+ * the authentication password must be at least eight characters long
+ *
+ * @return authentication password
+ */
+ String getAuthenticationPassword();
+
+ /**
+ * Returns the snmpv3 privacy protocol of the device.
+ * the privacy method (either AES or DES)
+ *
+ * @return privacy protocol
+ */
+ OID getPrivacyProtocol();
+
+ /**
+ * Returns the snmpv3 privacy password of the device.
+ * the privacy password must be at least eight characters long
+ *
+ * @return privacy password
+ */
+ String getPrivacyPassword();
+
+ /**
+ * Returns the snmpv3 authoritative engine id of the device.
+ *
+ * @return authoritative engine id
+ */
+ byte[] getAuthoritativeEngineId();
+
+ /**
+ * Returns the snmpv3 context name of the device.
+ * An SNMP context name or "context" in short,
+ * is a collection of management information accessible by an SNMP entity.
+ * An item of management information may exist in more than one context.
+ * An SNMP entity potentially has access to many contexts. In other words,
+ * if a management information has been defined under certain context by an SNMPv3 entity,
+ * then any management application can access that information by giving that context name.
+ * The "context name" is an octet string, which has at least one management information
+ *
+ * @return snmpv3 context name
+ */
+ String getContextName();
+
+ /**
+ * Create snmp session PDU factory.
+ *
+ * @return session PDU factory
+ */
+ PDUFactory createPduFactory();
+
+ /**
+ * Remove Snmp user security model when close connection to device.
+ */
+ void removeUsm();
+
+}
diff --git a/protocols/snmp/api/src/main/java/org/onosproject/snmp/Snmpv3Device.java b/protocols/snmp/api/src/main/java/org/onosproject/snmp/Snmpv3Device.java
new file mode 100644
index 0000000..7e48c51
--- /dev/null
+++ b/protocols/snmp/api/src/main/java/org/onosproject/snmp/Snmpv3Device.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2021-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;
+
+
+/**
+ * Abstraction a Snmpv3 Device.
+ */
+public interface Snmpv3Device extends SnmpDevice {
+
+ /**
+ * Retrieves the security name of SNMPv3 device.
+ *
+ * @return security name
+ */
+ String getSecurityName();
+
+ /**
+ * Retrieves the security level of SNMPv3 device.
+ *
+ * @return security level
+ */
+ String getSecurityLevel();
+
+ /**
+ * Retrieves the authentication protocol of SNMPv3 device.
+ *
+ * @return authentication protocol
+ */
+ String getAuthProtocol();
+
+ /**
+ * Retrieves the authentication password of SNMPv3 device.
+ *
+ * @return authentication password
+ */
+ String getAuthPassword();
+
+ /**
+ * Retrieves the privacy protocol of SNMPv3 device.
+ *
+ * @return privacy protocol
+ */
+ String getPrivProtocol();
+
+ /**
+ * Retrieves the privacy password of SNMPv3 device.
+ *
+ * @return privacy password
+ */
+ String getPrivPassword();
+
+ /**
+ * Retrieves the context name of SNMPv3 device.
+ *
+ * @return context name
+ */
+ String getContextName();
+
+}