ONOS-5917 SNMP Alarm Provider
Change-Id: I9eb39021584f3b1a5baed9dfa638569818901197
diff --git a/providers/snmp/BUCK b/providers/snmp/BUCK
index 24d8a97..598515d 100644
--- a/providers/snmp/BUCK
+++ b/providers/snmp/BUCK
@@ -1,5 +1,6 @@
BUNDLES = [
'//providers/snmp/device:onos-providers-snmp-device',
+ '//providers/snmp/alarm:onos-providers-snmp-alarm',
'//protocols/snmp/api:onos-protocols-snmp-api',
'//protocols/snmp/ctl:onos-protocols-snmp-ctl',
'//lib:org.apache.servicemix.bundles.snmp4j',
@@ -16,4 +17,5 @@
included_bundles = BUNDLES,
description = 'Provides means for ONOS to discover and trigger the initial handshake procedure ' +
'with SNMP enabled devices from information given by network configuration.',
+ required_apps = [ 'org.onosproject.faultmanagement'],
)
diff --git a/providers/snmp/alarm/BUCK b/providers/snmp/alarm/BUCK
new file mode 100644
index 0000000..a5f0c4b
--- /dev/null
+++ b/providers/snmp/alarm/BUCK
@@ -0,0 +1,13 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//lib:JACKSON',
+ '//incubator/api:onos-incubator-api',
+ '//protocols/snmp/api:onos-protocols-snmp-api',
+ '//protocols/snmp/ctl:onos-protocols-snmp-ctl',
+ '//providers/snmp/device:onos-providers-snmp-device',
+ '//lib:org.apache.servicemix.bundles.snmp4j',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+)
diff --git a/providers/snmp/alarm/pom.xml b/providers/snmp/alarm/pom.xml
new file mode 100644
index 0000000..bebe648
--- /dev/null
+++ b/providers/snmp/alarm/pom.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-present Open Networking Laboratory
+ ~
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-snmp-providers</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-snmp-provider-alarm</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS SNMP protocol alarm provider</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-snmp-api</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-snmp-ctl</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.snmp4j</artifactId>
+ <version>2.3.4_1</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>snmp-core</artifactId>
+ <version>1.3-20161021.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>mibbler-mibs-bti7000</artifactId>
+ <version>1.0-20151221.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>mibbler-mibs-net-snmp</artifactId>
+ <version>1.0-20151221.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-net</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-snmp-provider-device</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProvider.java b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProvider.java
new file mode 100644
index 0000000..3a3c964
--- /dev/null
+++ b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProvider.java
@@ -0,0 +1,295 @@
+/*
+ * 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.provider.snmp.alarm.impl;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
+import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider;
+import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderRegistry;
+import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderService;
+import org.onosproject.incubator.net.faultmanagement.alarm.DeviceAlarmConfig;
+import org.onosproject.mastership.MastershipEvent;
+import org.onosproject.mastership.MastershipListener;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.DefaultDriverData;
+import org.onosproject.net.driver.DefaultDriverHandler;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverData;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.snmp.SnmpController;
+import org.onosproject.snmp.SnmpDevice;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.snmp4j.CommandResponder;
+import org.snmp4j.CommandResponderEvent;
+import org.snmp4j.Snmp;
+import org.snmp4j.TransportMapping;
+import org.snmp4j.smi.Address;
+import org.snmp4j.smi.GenericAddress;
+import org.snmp4j.smi.TcpAddress;
+import org.snmp4j.smi.UdpAddress;
+import org.snmp4j.transport.DefaultTcpTransportMapping;
+import org.snmp4j.transport.DefaultUdpTransportMapping;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provider which will listen for traps generated SNMP devices and configure
+ * the devices with the Ip and Protocol fo the end point to send traps to.
+ */
+@Component(immediate = true)
+public class SnmpAlarmProvider extends AbstractProvider
+ implements AlarmProvider {
+
+ public static final String COLON = ":";
+ private final Logger log = getLogger(SnmpAlarmProvider.class);
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected SnmpController controller;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected AlarmProviderRegistry providerRegistry;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DriverService driverService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipService mastershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ClusterService clusterService;
+
+ private static final String APP_NAME = "org.onosproject.snmp";
+ private static final String SCHEME = "snmp";
+
+ protected AlarmProviderService providerService;
+
+ protected ApplicationId appId;
+
+ protected final DeviceListener deviceListener = new InternalDeviceListener();
+
+ protected final MastershipListener mastershipListener = new InternalMastershipListener();
+
+ protected final CommandResponder internalCommandResponder = new InternalCommandResponder();
+
+ private IpAddress localIp;
+
+ private final Map<Integer, Snmp> portSessionMap = new HashMap<>();
+
+ private Snmp snmp;
+
+
+ /**
+ * Creates a provider with the supplier identifier.
+ */
+ public SnmpAlarmProvider() {
+ super(new ProviderId("snmp", "org.onosproject.provider.alarm"));
+ }
+
+ @Activate
+ public void activate(ComponentContext context) {
+
+ providerService = providerRegistry.register(this);
+ appId = coreService.registerApplication(APP_NAME);
+ deviceService.addListener(deviceListener);
+ mastershipService.addListener(mastershipListener);
+ controller.getDevices().stream().forEach(d -> {
+ triggerProbe(d.deviceId());
+ configureListeningConnection(d);
+ });
+ localIp = clusterService.getLocalNode().ip();
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate(ComponentContext context) {
+ for (Map.Entry<Integer, Snmp> entry : portSessionMap.entrySet()) {
+ try {
+ entry.getValue().close();
+ } catch (IOException e) {
+ log.warn("Can't close SNMP notification session on Ip {} and Port {}",
+ localIp, entry.getKey(), e);
+ }
+ }
+ mastershipService.addListener(mastershipListener);
+ deviceService.removeListener(deviceListener);
+ providerRegistry.unregister(this);
+ providerService = null;
+ log.info("Stopped");
+ }
+
+ @Modified
+ public void modified() {
+ log.info("Modified");
+ }
+
+ @Override
+ public void triggerProbe(DeviceId deviceId) {
+ requestTraps(deviceId);
+ }
+
+ private void configureListeningConnection(SnmpDevice device) {
+ int notificationPort = device.getNotificationPort();
+ if (notificationPort == 0 || portSessionMap.containsKey(notificationPort)) {
+ return;
+ }
+ String protocol = device.getProtocol();
+ try {
+ Address listenAddress = GenericAddress.parse(protocol +
+ ":" + localIp.toString() +
+ "/" + notificationPort);
+ TransportMapping tm;
+ if (protocol == GenericAddress.TYPE_TCP) {
+ tm = new DefaultTcpTransportMapping((TcpAddress) listenAddress);
+ } else {
+ tm = new DefaultUdpTransportMapping((UdpAddress) listenAddress);
+ }
+ snmp = new Snmp(tm);
+ snmp.addCommandResponder(internalCommandResponder);
+ snmp.listen();
+ log.info("Initiated SNMP notification connection on Ip {} and Port {}",
+ localIp.toString(), notificationPort);
+ } catch (IOException e) {
+ log.error("Can't initiate SNMP transport on Protocol {}, Ip {} and Port {}",
+ protocol, localIp, notificationPort, e);
+ return;
+ }
+
+ portSessionMap.put(notificationPort, snmp);
+ }
+
+ private boolean requestTraps(DeviceId deviceId) {
+ SnmpDevice device = controller.getDevice(deviceId);
+ DeviceAlarmConfig alarmTranslator = getAlarmTranslator(device);
+ if (alarmTranslator != null) {
+ return alarmTranslator.configureDevice(localIp, device.getNotificationPort(),
+ device.getNotificationProtocol());
+ } else {
+ log.warn("Device {} does not support alarms.", deviceId);
+ return false;
+ }
+ }
+
+ private DeviceAlarmConfig getAlarmTranslator(SnmpDevice device) {
+ Driver deviceDriver = driverService.getDriver(device.deviceId());
+ if (deviceDriver != null && deviceDriver.hasBehaviour(DeviceAlarmConfig.class)) {
+ DriverData driverData = new DefaultDriverData(deviceDriver, device.deviceId());
+ DeviceAlarmConfig alarmTranslator = deviceDriver
+ .createBehaviour(driverData, DeviceAlarmConfig.class);
+ alarmTranslator.setHandler(new DefaultDriverHandler(driverData));
+ return alarmTranslator;
+ } else {
+ log.warn("Device does not support alarm {}", device.deviceId());
+ }
+ return null;
+ }
+
+ private class InternalCommandResponder implements CommandResponder {
+ @Override
+ public void processPdu(CommandResponderEvent event) {
+ try {
+ log.debug("received trap {}", event);
+ String[] deviceInfo = event.getPeerAddress().toString().split("/");
+
+ //TODO This should be done via device service.
+ //searching only for Ip since the port from which the trap is sent
+ // could be different from the one used for SNMP
+ SnmpDevice device = controller.getDevice(new URI(deviceInfo[0]));
+ if (device != null) {
+ DeviceId deviceId = DeviceId.deviceId(SCHEME + COLON + deviceInfo[0]
+ + COLON + device.getSnmpPort());
+ DeviceAlarmConfig alarmTranslator = getAlarmTranslator(controller.getDevice(deviceId));
+ if (alarmTranslator != null) {
+ Set<Alarm> alarms = alarmTranslator.translateAlarms(ImmutableList.of(event));
+ providerService.updateAlarmList(deviceId, alarms);
+ } else {
+ log.warn("Device {} does not support alarm", device.deviceId());
+ }
+ } else {
+ log.error("Device {} does not exist in ONOS SNMP subsystem", deviceInfo[0]);
+ }
+ //Catching generic exception due to otherwise hidden URISyntax
+ } catch (Exception e) {
+ log.error("Exception while processing PDU {}", e);
+ }
+ }
+ }
+
+ private class InternalDeviceListener implements DeviceListener {
+
+ @Override
+ public void event(DeviceEvent event) {
+ DeviceId deviceId = event.subject().id();
+ switch (event.type()) {
+ case DEVICE_ADDED:
+ triggerProbe(deviceId);
+ case DEVICE_UPDATED:
+ triggerProbe(deviceId);
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public boolean isRelevant(DeviceEvent event) {
+ return event.subject().id().toString().startsWith(SCHEME)
+ && mastershipService.isLocalMaster(event.subject().id());
+ }
+ }
+
+ private class InternalMastershipListener implements MastershipListener {
+
+ @Override
+ public void event(MastershipEvent event) {
+ triggerProbe(event.subject());
+ }
+
+ @Override
+ public boolean isRelevant(MastershipEvent event) {
+ return event.subject().toString().startsWith(SCHEME)
+ && mastershipService.isLocalMaster(event.subject());
+ }
+ }
+}
diff --git a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/package-info.java b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/package-info.java
new file mode 100644
index 0000000..ee22ea7
--- /dev/null
+++ b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provider that uses SNMP capability to configure and receive alarms from devices.
+ */
+package org.onosproject.provider.snmp.alarm.impl;
diff --git a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProviderTest.java b/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProviderTest.java
new file mode 100644
index 0000000..2ac50b8
--- /dev/null
+++ b/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProviderTest.java
@@ -0,0 +1,25 @@
+/*
+ * 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.provider.snmp.alarm.impl;
+
+/**
+ * Testing class for SnmpDeviceProvider.
+ */
+public class SnmpAlarmProviderTest {
+
+ //TODO unitests
+}
diff --git a/providers/snmp/app/app.xml b/providers/snmp/app/app.xml
index 848ceff..fd39042 100644
--- a/providers/snmp/app/app.xml
+++ b/providers/snmp/app/app.xml
@@ -17,9 +17,10 @@
<app name="org.onosproject.snmp" origin="BTI Systems" version="${project.version}"
category="Provider" url="http://onosproject.org" title="SNMP Provider"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
- features="${project.artifactId}">
+ features="${project.artifactId}" apps="org.onosproject.faultmanagement">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-snmp-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</artifact>
diff --git a/providers/snmp/app/features.xml b/providers/snmp/app/features.xml
index 212ddca..a130030 100644
--- a/providers/snmp/app/features.xml
+++ b/providers/snmp/app/features.xml
@@ -22,6 +22,7 @@
<bundle>mvn:${project.groupId}/onos-snmp-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle>
<bundle>mvn:org.onosproject/snmp-core/1.3-20161021.1</bundle>
diff --git a/providers/snmp/app/pom.xml b/providers/snmp/app/pom.xml
index 51c26f7..20d29d0 100644
--- a/providers/snmp/app/pom.xml
+++ b/providers/snmp/app/pom.xml
@@ -36,6 +36,11 @@
<artifactId>onos-snmp-provider-device</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-snmp-provider-alarm</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceConfig.java b/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceConfig.java
deleted file mode 100644
index f1085c0..0000000
--- a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceConfig.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.provider.snmp.device.impl;
-
-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 IP = "ip";
- private static final String PORT = "port";
- 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 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 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.toString();
- if (info.startsWith(SnmpDeviceProvider.SCHEME)) {
- //+1 is due to length of colon separator
- String ip = info.substring(info.indexOf(":") + 1, info.lastIndexOf(":"));
- int port = Integer.parseInt(info.substring(info.lastIndexOf(":") + 1));
- return Pair.of(ip, port);
- }
- return null;
- }
-}
\ No newline at end of file
diff --git a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java b/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java
index c4fdcd1..c81ba59 100644
--- a/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java
+++ b/providers/snmp/device/src/main/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProvider.java
@@ -48,6 +48,7 @@
import org.onosproject.net.provider.ProviderId;
import org.onosproject.snmp.SnmpController;
import org.onosproject.snmp.SnmpDevice;
+import org.onosproject.snmp.SnmpDeviceConfig;
import org.onosproject.snmp.ctl.DefaultSnmpDevice;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
@@ -165,8 +166,7 @@
deviceSubjects.forEach(deviceId -> {
SnmpDeviceConfig config =
netCfgService.getConfig(deviceId, SnmpDeviceConfig.class);
- buildDevice(new DefaultSnmpDevice(config.ip().toString(),
- config.port(), config.username(), config.password()));
+ buildDevice(new DefaultSnmpDevice(config));
});
}
diff --git a/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpControllerAdapter.java b/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpControllerAdapter.java
index 5dfedd3..a3534ec 100644
--- a/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpControllerAdapter.java
+++ b/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpControllerAdapter.java
@@ -23,6 +23,7 @@
import org.onosproject.snmp.SnmpDevice;
import java.io.IOException;
+import java.net.URI;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -44,6 +45,11 @@
}
@Override
+ public SnmpDevice getDevice(URI uri) {
+ return null;
+ }
+
+ @Override
public void removeDevice(DeviceId deviceId) {
devices.remove(deviceId);
}
@@ -54,6 +60,11 @@
}
@Override
+ public void addDevice(SnmpDevice device) {
+ devices.put(device.deviceId(), device);
+ }
+
+ @Override
public ISnmpSession getSession(DeviceId deviceId) throws IOException {
return null;
}
diff --git a/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java b/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java
index 49374cc..cfd39db 100644
--- a/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java
+++ b/providers/snmp/device/src/test/java/org/onosproject/provider/snmp/device/impl/SnmpDeviceProviderTest.java
@@ -52,6 +52,7 @@
import org.onosproject.net.driver.DriverServiceAdapter;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.snmp.SnmpController;
+import org.onosproject.snmp.SnmpDeviceConfig;
import java.io.InputStream;
import java.util.HashMap;
diff --git a/providers/snmp/pom.xml b/providers/snmp/pom.xml
index 429dcf4..c952ad2 100644
--- a/providers/snmp/pom.xml
+++ b/providers/snmp/pom.xml
@@ -33,5 +33,6 @@
<modules>
<module>device</module>
<module>app</module>
+ <module>alarm</module>
</modules>
</project>