Removing old SNMPAllarmReleated classes
Change-Id: I27c0e5e30596d77d9099094a1ebda0f50d4b29ac
diff --git a/providers/snmp/alarm/pom.xml b/providers/snmp/alarm/pom.xml
deleted file mode 100644
index 9188f59..0000000
--- a/providers/snmp/alarm/pom.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-~ Copyright 2015-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.6.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>onos-snmp-provider-alarm</artifactId>
- <packaging>bundle</packaging>
-
- <description>ONOS SNMP protocol alarm provider</description>
-
- <dependencies>
- <dependency>
- <groupId>com.btisystems</groupId>
- <artifactId>snmp-core</artifactId>
- <version>1.3-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>com.btisystems.mibbler.mibs</groupId>
- <artifactId>bti7000</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>com.btisystems.mibbler.mibs</groupId>
- <artifactId>net-snmp</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <type>jar</type>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-api</artifactId>
- </dependency>
-
-
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onlab-junit</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onlab-osgi</artifactId>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-api</artifactId>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
-
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/NetSnmpAlarmProvider.java b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/NetSnmpAlarmProvider.java
deleted file mode 100644
index 47e62de..0000000
--- a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/NetSnmpAlarmProvider.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-package org.onosproject.provider.snmp.alarm.impl;
-
-import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device;
-import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry;
-import com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.interfaces.IfTable;
-import com.btisystems.pronx.ems.core.model.ClassRegistry;
-import com.btisystems.pronx.ems.core.model.IClassRegistry;
-import com.btisystems.pronx.ems.core.model.NetworkDevice;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
-import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
-import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
-import org.onosproject.net.DeviceId;
-import org.slf4j.Logger;
-import static org.slf4j.LoggerFactory.getLogger;
-import org.snmp4j.smi.OID;
-
-/**
- * Net SNMP specific implementation to provide a list of current alarms.
- * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
- */
-@Deprecated
-public class NetSnmpAlarmProvider implements SnmpDeviceAlarmProvider {
- private final Logger log = getLogger(getClass());
- protected static final IClassRegistry CLASS_REGISTRY =
- new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
- @Override
- public Collection<Alarm> getAlarms(ISnmpSession session, DeviceId deviceId) {
- Set<Alarm> alarms = new HashSet<>();
-
- NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
- session.getAddress().getHostAddress());
- try {
- session.walkDevice(networkDevice, Arrays.asList(new OID[]{
- CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)}));
-
- IfTable interfaceTable = (IfTable) networkDevice.getRootObject()
- .getEntity(CLASS_REGISTRY.getClassToOidMap().get(IfTable.class));
- if (interfaceTable != null) {
- interfaceTable.getEntries().values().stream().forEach((ifEntry) -> {
- //TODO will raise alarm for each interface as a demo.
- // if (ifEntry.getIfAdminStatus() == 1 && ifEntry.getIfOperStatus() == 2){
- alarms.add(new DefaultAlarm.Builder(deviceId, "Link Down.",
- Alarm.SeverityLevel.CRITICAL, System.currentTimeMillis())
- .forSource(AlarmEntityId.alarmEntityId("port:" + ifEntry.getIfDescr())).build());
- // }
- log.info("Interface: " + ifEntry);
- });
- }
- } catch (IOException ex) {
- log.error("Error reading alarms for device {}.", deviceId, ex);
- }
- return alarms;
- }
-}
diff --git a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProviderService.java b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProviderService.java
deleted file mode 100644
index 4ee3da2..0000000
--- a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpAlarmProviderService.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-package org.onosproject.provider.snmp.alarm.impl;
-
-import com.btisystems.pronx.ems.core.snmp.DefaultSnmpConfigurationFactory;
-import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory;
-import com.btisystems.pronx.ems.core.snmp.SnmpSessionFactory;
-import com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration;
-import com.google.common.collect.Sets;
-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.apache.felix.scr.annotations.Service;
-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.AlarmEvent;
-import org.onosproject.incubator.net.faultmanagement.alarm.AlarmListener;
-import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider;
-import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
-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.provider.AbstractProvider;
-import org.onosproject.net.provider.ProviderId;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * SNMP alarms provider.
- * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
- */
-@Deprecated
-@Component(immediate = true)
-@Service
-public class SnmpAlarmProviderService extends AbstractProvider implements AlarmProvider {
-
- private final Logger log = getLogger(getClass());
-
- private final InternalDeviceListener internalDeviceListener = new InternalDeviceListener();
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- private ApplicationId appId;
-
- private final ISnmpSessionFactory sessionFactory;
-
- // TODO convert to standard ONOS listener service approach ?
- protected Set<AlarmListener> alarmEventListener = Sets.newHashSet();
-
- private ExecutorService eventHandlingExecutor;
-
- // TODO Could be replaced with a service lookup, and bundles per device variant.
- Map<String, SnmpDeviceAlarmProvider> providers = new HashMap<>();
-
- @Deprecated
- public SnmpAlarmProviderService() {
- super(new ProviderId("snmp", "org.onosproject.provider.alarm"));
- log.info("SnmpAlarmProviderService ...");
- sessionFactory = new SnmpSessionFactory(
- new DefaultSnmpConfigurationFactory(new V2cSnmpConfiguration()));
- providers.put("1.3.6.1.4.1.18070.2.2", new Bti7000SnmpAlarmProvider());
- providers.put("1.3.6.1.4.1.20408", new NetSnmpAlarmProvider());
- }
-
- @Activate
- public void activate(ComponentContext context) {
- appId = coreService.registerApplication("org.onosproject.snmp");
- eventHandlingExecutor = Executors.newSingleThreadExecutor(
- groupedThreads("onos/alarms", "event-handler"));
- deviceService.addListener(internalDeviceListener);
- log.info("activated SNMP provider with appId = {} and context props {}", appId, context.getProperties());
- modified(context);
-
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- log.info("deactivate SNMP provider {}", appId);
- deviceService.removeListener(internalDeviceListener);
- }
-
- @Modified
- public void modified(ComponentContext context) {
- log.info("modified {}", context);
-
- if (context == null) {
- log.info("No configuration file");
- }
-
- }
-
- @Override
- public void triggerProbe(DeviceId deviceId) {
- log.info("SNMP walk request for alarms at deviceId={}", deviceId);
- if (!isSnmpDevice(deviceId)) {
- log.info("Ignore non-snmp device!");
- return;
- }
- String[] deviceComponents = deviceId.toString().split(":");
- Set<Alarm> alarms = new HashSet<>(Sets.newHashSet());
-
- if (deviceComponents.length > 1) {
- String ipAddress = deviceComponents[1];
- String port = deviceComponents[2];
- ISnmpConfiguration config = new V2cSnmpConfiguration();
- config.setPort(Integer.parseInt(port));
-
- try (ISnmpSession session = getSessionFactory().createSession(config, ipAddress)) {
- // Each session will be auto-closed.
- String deviceOid = session.identifyDevice();
- alarms.addAll(getAlarmsForDevice(deviceOid, session, deviceId));
- log.info("SNMP walk completed ok for deviceId={}", deviceId);
- } catch (IOException | RuntimeException ex) {
- log.error("Failed to walk device.", ex.getMessage());
- log.debug("Detailed problem was ", ex);
- alarms.add(
- buildWalkFailedAlarm(deviceId)
- );
- }
- }
-
- AlarmEvent alarmEvent = new AlarmEvent(alarms, deviceId);
-
- alarmEventListener.stream().forEach((listener) -> {
- listener.event(alarmEvent);
- log.info("Successfully event with discovered alarms for deviceId={} to {}", deviceId, listener);
- });
-
- }
-
- private static DefaultAlarm buildWalkFailedAlarm(DeviceId deviceId) {
- return new DefaultAlarm.Builder(
- deviceId, "SNMP alarm retrieval failed",
- Alarm.SeverityLevel.CRITICAL,
- System.currentTimeMillis()).build();
- }
-
- protected ISnmpSessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- private Collection<Alarm> getAlarmsForDevice(String deviceOid, ISnmpSession session,
- DeviceId deviceID) throws IOException {
- Collection<Alarm> alarms = new HashSet<>();
- if (providers.containsKey(deviceOid)) {
- alarms.addAll(providers.get(deviceOid).getAlarms(session, deviceID));
- }
- return alarms;
- }
-
- @Override
- public void addAlarmListener(AlarmListener listener) {
- alarmEventListener.add(checkNotNull(listener, "Listener cannot be null"));
- }
-
- @Override
- public void removeAlarmListener(AlarmListener listener) {
- alarmEventListener.remove(checkNotNull(listener, "Listener cannot be null"));
- }
-
- /**
- * Internal listener for device service events.
- */
- private class InternalDeviceListener implements DeviceListener {
-
- @Override
- public void event(DeviceEvent event) {
- log.info("InternalDeviceListener has got event from device-service{} with ", event);
- eventHandlingExecutor.execute(() -> {
- try {
- DeviceId deviceId = event.subject().id();
- log.info("From device {}", deviceId);
- if (!isSnmpDevice(deviceId)) {
- log.info("Ignore non-snmp device event for {}", deviceId);
- return;
- }
-
- switch (event.type()) {
- case DEVICE_ADDED:
- case DEVICE_UPDATED:
- case DEVICE_AVAILABILITY_CHANGED:
- if (deviceService.isAvailable(event.subject().id())) {
- triggerProbe(deviceId);
- }
- break;
- case DEVICE_REMOVED:
- case DEVICE_SUSPENDED:
- default:
- // Could potentially remove all alarms when eg DEVICE_REMOVED or DEVICE_SUSPENDED
- // however for now ignore and fall through
- break;
- }
- } catch (Exception e) {
- log.warn("Failed to process {}", event, e);
- }
- });
- }
-
- }
-
- private static boolean isSnmpDevice(DeviceId deviceId) {
- return deviceId.uri().getScheme().equalsIgnoreCase("snmp");
- }
-}
diff --git a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpDeviceAlarmProvider.java b/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpDeviceAlarmProvider.java
deleted file mode 100644
index 1e4096e..0000000
--- a/providers/snmp/alarm/src/main/java/org/onosproject/provider/snmp/alarm/impl/SnmpDeviceAlarmProvider.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-package org.onosproject.provider.snmp.alarm.impl;
-
-import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
-import java.util.Collection;
-import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
-import org.onosproject.net.DeviceId;
-
-/**
- * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
- */
-@Deprecated
-public interface SnmpDeviceAlarmProvider {
- /**
- * Implemented by device specific implementations which query the current
- * alarms from a device.
- * @deprecated 1.5.0 Falcon
- * @param snmpSession SNMP Session
- * @param deviceId device identifier
- * @return device alarms
- */
- @Deprecated
- Collection<Alarm> getAlarms(ISnmpSession snmpSession, DeviceId deviceId);
-}
diff --git a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/Bti7000SnmpAlarmProviderTest.java b/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/Bti7000SnmpAlarmProviderTest.java
deleted file mode 100644
index ea84627..0000000
--- a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/Bti7000SnmpAlarmProviderTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-package org.onosproject.provider.snmp.alarm.impl;
-
-import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.btisystems.btiproducts.bti7000.objects.conditions.ActAlarmTable;
-import com.btisystems.mibbler.mibs.bti7000.interfaces.btisystems.btiproducts.bti7000.objects.conditions.actalarmtable.IActAlarmEntry;
-import com.btisystems.pronx.ems.core.model.NetworkDevice;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.Collection;
-import org.easymock.Capture;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
-import org.onosproject.net.DeviceId;
-import org.snmp4j.smi.OID;
-
-
-public class Bti7000SnmpAlarmProviderTest {
- private Bti7000SnmpAlarmProvider alarmProvider;
- private ISnmpSession mockSession;
- private ActAlarmTable alarmsTable;
-
- public Bti7000SnmpAlarmProviderTest() {
- }
-
- @Before
- public void setUp() {
- mockSession = createMock(ISnmpSession.class);
-
- alarmProvider = new Bti7000SnmpAlarmProvider();
- }
-
- @Test
- public void shouldWalkDevice() throws UnknownHostException, IOException {
- expect(mockSession.getAddress()).andReturn(InetAddress.getLoopbackAddress());
- expect(mockSession.walkDevice(isA(NetworkDevice.class),
- eq(Arrays.asList(new OID[]{
- Bti7000SnmpAlarmProvider.CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class)}))))
- .andReturn(null);
-
- replay(mockSession);
-
- assertNotNull(alarmProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1")));
-
- verify(mockSession);
- }
-
- @Test
- public void shouldFindAlarms() throws UnknownHostException, IOException {
- alarmsTable = new ActAlarmTable();
- alarmsTable.createEntry("14.1.3.6.1.4.1.18070.2.2.2.2.20.0.1.13.1.3.6.1.4.1."
- + "18070.2.2.1.4.14.1.7.49.46.55.46.50.46.53");
- IActAlarmEntry entry = alarmsTable.getEntries().values().iterator().next();
- entry.setActAlarmDescription("XFP Missing.");
- entry.setActAlarmDateAndTime("07:df:0c:01:03:0d:30:00");
- entry.setActAlarmSeverity(1);
-
- Capture<NetworkDevice> networkDeviceCapture = new Capture<>();
-
- expect(mockSession.getAddress()).andReturn(InetAddress.getLoopbackAddress());
- expect(mockSession.walkDevice(capture(networkDeviceCapture),
- eq(Arrays.asList(new OID[]{
- Bti7000SnmpAlarmProvider.CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class)}))))
- .andAnswer(() -> {
- networkDeviceCapture.getValue().getRootObject().setObject(alarmsTable);
- return null;
- });
-
- replay(mockSession);
-
- Collection<Alarm> alarms = alarmProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1"));
- assertEquals(1, alarms.size());
- assertEquals("XFP Missing.", alarms.iterator().next().description());
- verify(mockSession);
- }
-
- @Test
- public void shouldHandleException() throws UnknownHostException, IOException {
- expect(mockSession.getAddress()).andReturn(InetAddress.getLoopbackAddress());
- expect(mockSession.walkDevice(isA(NetworkDevice.class),
- eq(Arrays.asList(new OID[]{
- Bti7000SnmpAlarmProvider.CLASS_REGISTRY.getClassToOidMap().get(ActAlarmTable.class)}))))
- .andThrow(new IOException());
-
- replay(mockSession);
-
- assertNotNull(alarmProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1")));
-
- verify(mockSession);
- }
-
-}
diff --git a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/NetSnmpSnmpAlarmProviderTest.java b/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/NetSnmpSnmpAlarmProviderTest.java
deleted file mode 100644
index d63c0fe..0000000
--- a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/NetSnmpSnmpAlarmProviderTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-package org.onosproject.provider.snmp.alarm.impl;
-
-import com.btisystems.mibbler.mibs.netsnmp.interfaces.mib_2.interfaces.iftable.IIfEntry;
-import com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.interfaces.IfTable;
-import com.btisystems.pronx.ems.core.model.NetworkDevice;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.Collection;
-import org.easymock.Capture;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
-import org.onosproject.net.DeviceId;
-import org.snmp4j.smi.OID;
-
-
-public class NetSnmpSnmpAlarmProviderTest {
- private NetSnmpAlarmProvider alarmProvider;
- private ISnmpSession mockSession;
- private IfTable interfaceTable;
-
- public NetSnmpSnmpAlarmProviderTest() {
- }
-
- @Before
- public void setUp() {
- mockSession = createMock(ISnmpSession.class);
-
- alarmProvider = new NetSnmpAlarmProvider();
- }
-
- @Test
- public void shouldWalkDevice() throws UnknownHostException, IOException {
- expect(mockSession.getAddress()).andReturn(InetAddress.getLoopbackAddress());
- expect(mockSession.walkDevice(isA(NetworkDevice.class),
- eq(Arrays.asList(new OID[]{
- NetSnmpAlarmProvider.CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)}))))
- .andReturn(null);
-
- replay(mockSession);
-
- assertNotNull(alarmProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1")));
-
- verify(mockSession);
- }
-
- @Test
- public void shouldFindAlarms() throws UnknownHostException, IOException {
- interfaceTable = new IfTable();
- interfaceTable.createEntry("1");
- IIfEntry entry = interfaceTable.getEntry("1");
- entry.setIfDescr("eth1");
- entry.setIfAdminStatus(1);
- entry.setIfOperStatus(2);
-
- Capture<NetworkDevice> networkDeviceCapture = new Capture<>();
-
- expect(mockSession.getAddress()).andReturn(InetAddress.getLoopbackAddress());
- expect(mockSession.walkDevice(capture(networkDeviceCapture),
- eq(Arrays.asList(new OID[]{
- NetSnmpAlarmProvider.CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)}))))
- .andAnswer(() -> {
- networkDeviceCapture.getValue().getRootObject().setObject(interfaceTable);
- return null;
- });
-
- replay(mockSession);
-
- Collection<Alarm> alarms = alarmProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1"));
- assertEquals(1, alarms.size());
- assertEquals("Link Down.", alarms.iterator().next().description());
- verify(mockSession);
- }
-
- @Test
- public void shouldHandleException() throws UnknownHostException, IOException {
- expect(mockSession.getAddress()).andReturn(InetAddress.getLoopbackAddress());
- expect(mockSession.walkDevice(isA(NetworkDevice.class),
- eq(Arrays.asList(new OID[]{
- NetSnmpAlarmProvider.CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)}))))
- .andThrow(new IOException());
-
- replay(mockSession);
-
- assertNotNull(alarmProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1")));
-
- verify(mockSession);
- }
-
-}
diff --git a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/SnmpDeviceAlarmProviderTest.java b/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/SnmpDeviceAlarmProviderTest.java
deleted file mode 100644
index 39f3d94..0000000
--- a/providers/snmp/alarm/src/test/java/org/onosproject/provider/snmp/alarm/impl/SnmpDeviceAlarmProviderTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-package org.onosproject.provider.snmp.alarm.impl;
-
-import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
-import com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory;
-import java.io.IOException;
-import java.util.HashSet;
-import org.easymock.EasyMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEvent;
-import org.onosproject.net.DeviceId;
-
-public class SnmpDeviceAlarmProviderTest {
- private SnmpAlarmProviderService alarmProvider;
- private ISnmpSessionFactory mockSessionFactory;
- private ISnmpSession mockSession;
- private SnmpDeviceAlarmProvider mockProvider;
- private AlarmEvent alarmEvent;
-
- public SnmpDeviceAlarmProviderTest() {}
-
- @Before
- public void setUp() {
- mockSessionFactory = EasyMock.createMock(ISnmpSessionFactory.class);
- mockSession = EasyMock.createMock(ISnmpSession.class);
- mockProvider = EasyMock.createMock(SnmpDeviceAlarmProvider.class);
-
- alarmProvider = new SnmpAlarmProviderService() {
- @Override
- protected ISnmpSessionFactory getSessionFactory() {
- return mockSessionFactory;
- }
- };
-
- alarmProvider.addAlarmListener((AlarmEvent event) -> {
- alarmEvent = event;
- });
- }
-
- @Test
- public void shouldPopulateAlarmsForNetSnmp() throws IOException {
- alarmProvider.providers.put("1.2.3.4", mockProvider);
- expect(mockSessionFactory.createSession(EasyMock.isA(ISnmpConfiguration.class),
- EasyMock.eq("1.1.1.1"))).andReturn(mockSession);
- expect(mockSession.identifyDevice()).andReturn("1.2.3.4");
- expect(mockProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1:161")))
- .andReturn(new HashSet<>());
-
- mockSession.close();
- EasyMock.expectLastCall().once();
-
- replay(mockSessionFactory, mockSession, mockProvider);
-
- alarmProvider.triggerProbe(DeviceId.deviceId("snmp:1.1.1.1:161"));
-
- verify(mockSessionFactory, mockSession, mockProvider);
- Assert.assertNotNull(alarmEvent);
- }
-
-}