Andrea Campanella
Committed by Gerrit Code Review

[ONOS-3943] SNMP protocol and provider refactoring according to ONOS architecture

Change-Id: Ie87ee6c181c9550ffac602397f2ee74a691bbdfa
Showing 33 changed files with 1194 additions and 448 deletions
1 +SRC = 'src/main/java/org/onosproject/**/'
2 +
3 +CURRENT_NAME = 'onos-drivers-bti'
4 +CURRENT_TARGET = ':' + CURRENT_NAME
5 +
6 +COMPILE_DEPS = [
7 + '//lib:CORE_DEPS',
8 + '//protocols/netconf/api:onos-snmp-api',
9 + '//incubator/api:onos-incubator-api'
10 +]
11 +
12 +java_library(
13 + name = CURRENT_NAME,
14 + srcs = glob([SRC + '/*.java']),
15 + deps = COMPILE_DEPS,
16 + visibility = ['PUBLIC'],
17 + resources_root = 'src/main/resources',
18 + resources = glob(['src/main/resources/**']),
19 +)
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +
3 +<!--
4 + ~ Copyright 2016 Open Networking Laboratory
5 + ~
6 + ~ Licensed under the Apache License, Version 2.0 (the "License");
7 + ~ you may not use this file except in compliance with the License.
8 + ~ You may obtain a copy of the License at
9 + ~
10 + ~ http://www.apache.org/licenses/LICENSE-2.0
11 + ~
12 + ~ Unless required by applicable law or agreed to in writing, software
13 + ~ distributed under the License is distributed on an "AS IS" BASIS,
14 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + ~ See the License for the specific language governing permissions and
16 + ~ limitations under the License.
17 + -->
18 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
19 + <feature name="${project.artifactId}" version="${project.version}"
20 + description="${project.description}">
21 + <feature>onos-api</feature>
22 +
23 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
24 +
25 + <bundle>mvn:${project.groupId}/onos-snmp-api/${project.version}</bundle>
26 +
27 + <bundle>mvn:${project.groupId}/onos-incubator-api/${project.version}</bundle>
28 +
29 + </feature>
30 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-drivers-general</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.6.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-drivers-bti</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <properties>
32 + <onos.app.name>org.onosproject.drivers.bti</onos.app.name>
33 + <onos.app.origin>ON.Lab</onos.app.origin>
34 + <onos.app.category>Drivers</onos.app.category>
35 + <onos.app.title>Bti Device Drivers</onos.app.title>
36 + <onos.app.url>http://onosproject.org</onos.app.url>
37 + <onos.app.requires>
38 + org.onosproject.snmp
39 + </onos.app.requires>
40 + </properties>
41 +
42 + <dependencies>
43 + <dependency>
44 + <groupId>org.onosproject</groupId>
45 + <artifactId>onos-snmp-api</artifactId>
46 + <version>1.6.0-SNAPSHOT</version>
47 + </dependency>
48 + <dependency>
49 + <groupId>org.onosproject</groupId>
50 + <artifactId>onos-incubator-api</artifactId>
51 + <version>1.6.0-SNAPSHOT</version>
52 + </dependency>
53 + </dependencies>
54 +
55 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 /* 1 /*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
2 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
5 * 7 *
6 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
7 * 9 *
8 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
...@@ -11,58 +13,102 @@ ...@@ -11,58 +13,102 @@
11 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
12 * limitations under the License. 14 * limitations under the License.
13 */ 15 */
14 -package org.onosproject.provider.snmp.device.impl; 16 +
17 +package org.onosproject.drivers.bti;
15 18
16 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.I_Device; 19 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.I_Device;
17 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0._OidRegistry; 20 import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0._OidRegistry;
21 +import com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System;
18 import com.btisystems.pronx.ems.core.model.ClassRegistry; 22 import com.btisystems.pronx.ems.core.model.ClassRegistry;
19 import com.btisystems.pronx.ems.core.model.IClassRegistry; 23 import com.btisystems.pronx.ems.core.model.IClassRegistry;
20 import com.btisystems.pronx.ems.core.model.NetworkDevice; 24 import com.btisystems.pronx.ems.core.model.NetworkDevice;
25 +import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
21 import com.btisystems.pronx.ems.core.snmp.ISnmpSession; 26 import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
27 +import com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration;
28 +import com.google.common.collect.ImmutableList;
29 +import org.onosproject.net.Device;
30 +import org.onosproject.net.DeviceId;
31 +import org.onosproject.net.SparseAnnotations;
22 import org.onosproject.net.device.DefaultDeviceDescription; 32 import org.onosproject.net.device.DefaultDeviceDescription;
23 import org.onosproject.net.device.DeviceDescription; 33 import org.onosproject.net.device.DeviceDescription;
34 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
35 +import org.onosproject.net.device.DeviceService;
36 +import org.onosproject.net.device.PortDescription;
37 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
38 +import org.onosproject.snmp.SnmpController;
39 +import org.onosproject.snmp.SnmpDevice;
24 import org.slf4j.Logger; 40 import org.slf4j.Logger;
25 -import org.snmp4j.smi.OID;
26 41
27 import java.io.IOException; 42 import java.io.IOException;
28 -import java.util.Arrays; 43 +import java.util.Collections;
44 +import java.util.List;
29 45
46 +import static com.google.common.base.Preconditions.checkNotNull;
30 import static org.slf4j.LoggerFactory.getLogger; 47 import static org.slf4j.LoggerFactory.getLogger;
31 48
32 /** 49 /**
33 - * A vendor-specific implementation supporting BTI Systems BTI-7000 equipment. 50 + * Bti 7000 SNMP device description behaviour. Provides device description and port information.
34 - * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
35 */ 51 */
36 -@Deprecated 52 +public class Bti7000DeviceDescriptor extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery {
37 -public class Bti7000DeviceDescriptionProvider implements SnmpDeviceDescriptionProvider { 53 +
38 private final Logger log = getLogger(getClass()); 54 private final Logger log = getLogger(getClass());
39 protected static final IClassRegistry CLASS_REGISTRY = 55 protected static final IClassRegistry CLASS_REGISTRY =
40 new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class); 56 new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
41 private static final String UNKNOWN = "unknown"; 57 private static final String UNKNOWN = "unknown";
42 58
43 @Override 59 @Override
44 - public DeviceDescription populateDescription(ISnmpSession session, DeviceDescription description) { 60 + public DeviceDescription discoverDeviceDetails() {
61 + SnmpController controller = checkNotNull(handler().get(SnmpController.class));
62 + DeviceId deviceId = handler().data().deviceId();
63 + SnmpDevice snmpDevice = controller.getDevice(deviceId);
64 + DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
65 + Device device = deviceService.getDevice(deviceId);
66 + DeviceDescription desc = null;
67 + String ipAddress = snmpDevice.getSnmpHost();
68 + int port = snmpDevice.getSnmpPort();
69 +
70 + ISnmpConfiguration config = new V2cSnmpConfiguration();
71 + config.setPort(port);
72 +
73 + try (ISnmpSession session = controller.getSession(deviceId)) {
74 + // Each session will be auto-closed.
75 + String deviceOid = session.identifyDevice();
76 + desc = populateDescription(session, device);
77 +
78 + } catch (IOException | RuntimeException ex) {
79 + log.error("Failed to walk device.", ex.getMessage());
80 + log.debug("Detailed problem was ", ex);
81 + }
82 + return desc;
83 + }
84 +
85 + @Override
86 + public List<PortDescription> discoverPortDetails() {
87 + //TODO implement
88 + return ImmutableList.of();
89 + }
90 +
91 + private DeviceDescription populateDescription(ISnmpSession session, Device device) {
45 NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY, 92 NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
46 - session.getAddress().getHostAddress()); 93 + session.getAddress().getHostAddress());
47 try { 94 try {
48 - session.walkDevice(networkDevice, Arrays.asList(new OID[]{ 95 + session.walkDevice(networkDevice, Collections.singletonList(CLASS_REGISTRY.getClassToOidMap().get(
49 - CLASS_REGISTRY.getClassToOidMap().get( 96 + System.class)));
50 - com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System.class)}));
51 97
52 com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System systemTree = 98 com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System systemTree =
53 (com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System) 99 (com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System)
54 - networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get( 100 + networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get(
55 com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System.class)); 101 com.btisystems.mibbler.mibs.bti7000.bti7000_13_2_0.mib_2.System.class));
56 if (systemTree != null) { 102 if (systemTree != null) {
57 String[] systemComponents = systemTree.getSysDescr().split(";"); 103 String[] systemComponents = systemTree.getSysDescr().split(";");
58 - return new DefaultDeviceDescription(description.deviceUri(), description.type(), 104 + return new DefaultDeviceDescription(device.id().uri(), device.type(),
59 - systemComponents[0], systemComponents[2], systemComponents[3], 105 + systemComponents[0], systemComponents[2],
60 - UNKNOWN, description.chassisId(), description.annotations()); 106 + systemComponents[3], UNKNOWN, device.chassisId(),
107 + (SparseAnnotations) device.annotations());
61 } 108 }
62 } catch (IOException ex) { 109 } catch (IOException ex) {
63 - log.error("Error reading details for device {}.", session.getAddress(), ex); 110 + throw new IllegalArgumentException("Error reading details for device." + session.getAddress(), ex);
64 } 111 }
65 - return description; 112 + return null;
66 } 113 }
67 -
68 } 114 }
......
1 +/*
2 + * Copyright 2016 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.bti;
18 +
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.onosproject.net.driver.AbstractDriverLoader;
21 +
22 +/**
23 + * Loader for BTI device drivers.
24 + */
25 +@Component(immediate = true)
26 +public class BtiDriversLoader extends AbstractDriverLoader {
27 +
28 + public BtiDriversLoader() {
29 + super("/bti-drivers.xml");
30 + }
31 +}
1 /* 1 /*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
2 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
5 * 7 *
6 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
7 * 9 *
8 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
...@@ -11,60 +13,107 @@ ...@@ -11,60 +13,107 @@
11 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
12 * limitations under the License. 14 * limitations under the License.
13 */ 15 */
14 -package org.onosproject.provider.snmp.device.impl; 16 +
17 +package org.onosproject.drivers.bti;
15 18
16 import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device; 19 import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device;
17 import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry; 20 import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry;
21 +import com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System;
18 import com.btisystems.pronx.ems.core.model.ClassRegistry; 22 import com.btisystems.pronx.ems.core.model.ClassRegistry;
19 import com.btisystems.pronx.ems.core.model.IClassRegistry; 23 import com.btisystems.pronx.ems.core.model.IClassRegistry;
20 import com.btisystems.pronx.ems.core.model.NetworkDevice; 24 import com.btisystems.pronx.ems.core.model.NetworkDevice;
25 +import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
21 import com.btisystems.pronx.ems.core.snmp.ISnmpSession; 26 import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
27 +import com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration;
28 +import com.google.common.collect.ImmutableList;
22 import org.apache.commons.lang.StringUtils; 29 import org.apache.commons.lang.StringUtils;
30 +import org.onosproject.net.Device;
31 +import org.onosproject.net.DeviceId;
32 +import org.onosproject.net.SparseAnnotations;
23 import org.onosproject.net.device.DefaultDeviceDescription; 33 import org.onosproject.net.device.DefaultDeviceDescription;
24 import org.onosproject.net.device.DeviceDescription; 34 import org.onosproject.net.device.DeviceDescription;
35 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
36 +import org.onosproject.net.device.DeviceService;
37 +import org.onosproject.net.device.PortDescription;
38 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
39 +import org.onosproject.snmp.SnmpController;
40 +import org.onosproject.snmp.SnmpDevice;
25 import org.slf4j.Logger; 41 import org.slf4j.Logger;
26 -import org.snmp4j.smi.OID;
27 42
28 import java.io.IOException; 43 import java.io.IOException;
29 -import java.util.Arrays; 44 +import java.util.Collections;
45 +import java.util.List;
30 46
47 +import static com.google.common.base.Preconditions.checkNotNull;
31 import static org.slf4j.LoggerFactory.getLogger; 48 import static org.slf4j.LoggerFactory.getLogger;
32 49
33 /** 50 /**
34 - * A agent-specific implementation supporting NET-SNMP agents. 51 + * Net SNMP device description behaviour. Provides device description and port information.
35 - * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
36 */ 52 */
37 -@Deprecated 53 +public class NetSnmpDeviceDescriptor extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery {
38 -public class NetSnmpDeviceDescriptionProvider implements SnmpDeviceDescriptionProvider {
39 private final Logger log = getLogger(getClass()); 54 private final Logger log = getLogger(getClass());
40 protected static final IClassRegistry CLASS_REGISTRY = 55 protected static final IClassRegistry CLASS_REGISTRY =
41 new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class); 56 new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
42 private static final String UNKNOWN = "unknown"; 57 private static final String UNKNOWN = "unknown";
43 58
59 +
60 + //TODO evaluate a common abstract class for all Snmp description discovery
61 + @Override
62 + public DeviceDescription discoverDeviceDetails() {
63 + SnmpController controller = checkNotNull(handler().get(SnmpController.class));
64 + DeviceId deviceId = handler().data().deviceId();
65 + SnmpDevice snmpDevice = controller.getDevice(deviceId);
66 + DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
67 + Device device = deviceService.getDevice(deviceId);
68 + DeviceDescription desc = null;
69 + String ipAddress = snmpDevice.getSnmpHost();
70 + int port = snmpDevice.getSnmpPort();
71 +
72 + ISnmpConfiguration config = new V2cSnmpConfiguration();
73 + config.setPort(port);
74 +
75 + try (ISnmpSession session = controller.getSession(deviceId)) {
76 + // Each session will be auto-closed.
77 + String deviceOid = session.identifyDevice();
78 + //TODO obtain desctiption
79 + desc = populateDescription(session, device);
80 +
81 + } catch (IOException | RuntimeException ex) {
82 + log.error("Failed to walk device.", ex.getMessage());
83 + log.debug("Detailed problem was ", ex);
84 + }
85 +
86 + return desc;
87 + }
88 +
44 @Override 89 @Override
45 - public DeviceDescription populateDescription(ISnmpSession session, DeviceDescription description) { 90 + public List<PortDescription> discoverPortDetails() {
91 + //TODO implement
92 + return ImmutableList.of();
93 + }
94 +
95 + private DeviceDescription populateDescription(ISnmpSession session, Device device) {
46 NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY, 96 NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
47 - session.getAddress().getHostAddress()); 97 + session.getAddress().getHostAddress());
48 try { 98 try {
49 - session.walkDevice(networkDevice, Arrays.asList(new OID[]{ 99 + session.walkDevice(networkDevice, Collections.singletonList(CLASS_REGISTRY.getClassToOidMap().get(
50 - CLASS_REGISTRY.getClassToOidMap().get( 100 + System.class)));
51 - com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class)}));
52 101
53 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System systemTree = 102 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System systemTree =
54 (com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System) 103 (com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System)
55 - networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get( 104 + networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get(
56 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class)); 105 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class));
57 if (systemTree != null) { 106 if (systemTree != null) {
58 // TODO SNMP sys-contacts may be verbose; ONOS-GUI doesn't abbreviate fields neatly; 107 // TODO SNMP sys-contacts may be verbose; ONOS-GUI doesn't abbreviate fields neatly;
59 // so cut it here until supported in prop displayer 108 // so cut it here until supported in prop displayer
60 String manufacturer = StringUtils.abbreviate(systemTree.getSysContact(), 20); 109 String manufacturer = StringUtils.abbreviate(systemTree.getSysContact(), 20);
61 - return new DefaultDeviceDescription(description.deviceUri(), description.type(), manufacturer, 110 + return new DefaultDeviceDescription(device.id().uri(), device.type(),
62 - UNKNOWN, UNKNOWN, UNKNOWN, description.chassisId(), description.annotations()); 111 + manufacturer, UNKNOWN, UNKNOWN, UNKNOWN,
112 + device.chassisId(), (SparseAnnotations) device.annotations());
63 } 113 }
64 } catch (IOException ex) { 114 } catch (IOException ex) {
65 - log.error("Error reading details for device {}.", session.getAddress(), ex); 115 + throw new IllegalArgumentException("Error reading details for device." + session.getAddress(), ex);
66 } 116 }
67 - return description; 117 + return null;
68 } 118 }
69 -
70 } 119 }
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with 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 6 * You may obtain a copy of the License at
7 * 7 *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
...@@ -14,17 +14,7 @@ ...@@ -14,17 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.provider.snmp.device.impl; 17 +/**
18 - /** 18 + * Package for BTI device drivers.
19 - * The Device State is used to determine whether the device is active or inactive. This state information will help 19 + */
20 - * Device Creator to add or delete the device from the core. 20 +package org.onosproject.drivers.bti;
21 - */
22 - public enum DeviceState {
23 - /* Used to specify Active state of the device */
24 -
25 - ACTIVE,
26 - /* Used to specify inactive state of the device */
27 - INACTIVE,
28 - /* Used to specify invalid state of the device */
29 - INVALID
30 - }
...\ No newline at end of file ...\ No newline at end of file
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +
3 +<!--
4 + ~ Copyright 2016 Open Networking Laboratory
5 + ~
6 + ~ Licensed under the Apache License, Version 2.0 (the "License");
7 + ~ you may not use this file except in compliance with the License.
8 + ~ You may obtain a copy of the License at
9 + ~
10 + ~ http://www.apache.org/licenses/LICENSE-2.0
11 + ~
12 + ~ Unless required by applicable law or agreed to in writing, software
13 + ~ distributed under the License is distributed on an "AS IS" BASIS,
14 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + ~ See the License for the specific language governing permissions and
16 + ~ limitations under the License.
17 + -->
18 +<drivers>
19 + <driver name="bti7000" manufacturer="bti" hwVersion="1.0.0" swVersion="1.0.0">
20 + <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
21 + impl="org.onosproject.drivers.bti.Bti7000DeviceDescriptor"/>
22 + </driver>
23 + <driver name="NetSnmp" manufacturer="bti" hwVersion="1.0.0" swVersion="1.0.0">
24 + <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
25 + impl="org.onosproject.drivers.bti.NetSnmpDeviceDescriptor"/>
26 + </driver>
27 +</drivers>
28 +
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
20 <feature>onos-api</feature> 20 <feature>onos-api</feature>
21 <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle> 21 <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
22 22
23 - <bundle>mvn:${project.groupId}/onos-restsb-api/${project.version}</bundle>
24 -
25 <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>
26 24
27 </feature> 25 </feature>
......
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
35 <onos.app.category>Drivers</onos.app.category> 35 <onos.app.category>Drivers</onos.app.category>
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>
39 + org.onosproject.snmp
40 + </onos.app.requires>
38 </properties> 41 </properties>
39 42
40 <dependencies> 43 <dependencies>
......
...@@ -19,9 +19,14 @@ package org.onosproject.drivers.lumentum; ...@@ -19,9 +19,14 @@ package org.onosproject.drivers.lumentum;
19 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import org.onosproject.net.AnnotationKeys; 20 import org.onosproject.net.AnnotationKeys;
21 import org.onosproject.net.DefaultAnnotations; 21 import org.onosproject.net.DefaultAnnotations;
22 +import org.onosproject.net.Device;
23 +import org.onosproject.net.DeviceId;
22 import org.onosproject.net.PortNumber; 24 import org.onosproject.net.PortNumber;
23 import org.onosproject.net.SparseAnnotations; 25 import org.onosproject.net.SparseAnnotations;
24 -import org.onosproject.net.behaviour.PortDiscovery; 26 +import org.onosproject.net.device.DefaultDeviceDescription;
27 +import org.onosproject.net.device.DeviceDescription;
28 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
29 +import org.onosproject.net.device.DeviceService;
25 import org.onosproject.net.device.OmsPortDescription; 30 import org.onosproject.net.device.OmsPortDescription;
26 import org.onosproject.net.device.PortDescription; 31 import org.onosproject.net.device.PortDescription;
27 import org.onosproject.net.driver.AbstractHandlerBehaviour; 32 import org.onosproject.net.driver.AbstractHandlerBehaviour;
...@@ -34,22 +39,37 @@ import java.io.IOException; ...@@ -34,22 +39,37 @@ import java.io.IOException;
34 import java.util.Collections; 39 import java.util.Collections;
35 import java.util.List; 40 import java.util.List;
36 41
42 +import static com.google.common.base.Preconditions.checkNotNull;
37 import static org.slf4j.LoggerFactory.getLogger; 43 import static org.slf4j.LoggerFactory.getLogger;
38 44
39 /** 45 /**
40 - * Discovers the ports of a Lumentum SDN ROADM device using SNMP. 46 + * Device description behaviour for Lumentum Snmp devices.
41 */ 47 */
42 -public class PortDiscoveryLumentumRoadm extends AbstractHandlerBehaviour 48 +public class LumentumRoadmDeviceDescription extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery {
43 - implements PortDiscovery {
44 49
45 - private final Logger log = getLogger(PortDiscoveryLumentumRoadm.class); 50 + private final Logger log = getLogger(getClass());
46 51
47 private static final String CTRL_PORT_STATE = ".1.3.6.1.4.1.46184.1.4.1.1.3."; 52 private static final String CTRL_PORT_STATE = ".1.3.6.1.4.1.46184.1.4.1.1.3.";
48 53
49 private LumentumSnmpDevice snmp; 54 private LumentumSnmpDevice snmp;
50 55
51 @Override 56 @Override
52 - public List<PortDescription> getPorts() { 57 + public DeviceDescription discoverDeviceDetails() {
58 + //TODO get device description
59 + DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
60 + DeviceId deviceId = handler().data().deviceId();
61 + Device device = deviceService.getDevice(deviceId);
62 + return new DefaultDeviceDescription(device.id().uri(), Device.Type.ROADM,
63 + "Lumentum", "SDN ROADM", "1.0", "v1",
64 + device.chassisId(), (SparseAnnotations) device.annotations());
65 + }
66 +
67 + @Override
68 + public List<PortDescription> discoverPortDetails() {
69 + return this.getPorts();
70 + }
71 +
72 + private List<PortDescription> getPorts() {
53 try { 73 try {
54 snmp = new LumentumSnmpDevice(handler().data().deviceId()); 74 snmp = new LumentumSnmpDevice(handler().data().deviceId());
55 } catch (IOException e) { 75 } catch (IOException e) {
...@@ -119,5 +139,3 @@ public class PortDiscoveryLumentumRoadm extends AbstractHandlerBehaviour ...@@ -119,5 +139,3 @@ public class PortDiscoveryLumentumRoadm extends AbstractHandlerBehaviour
119 return ports; 139 return ports;
120 } 140 }
121 } 141 }
122 -
123 -
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 --> 16 -->
17 <drivers> 17 <drivers>
18 <driver name="lumentum" manufacturer="Lumentum" hwVersion="SDN ROADM" swVersion="1.0"> 18 <driver name="lumentum" manufacturer="Lumentum" hwVersion="SDN ROADM" swVersion="1.0">
19 - <behaviour api="org.onosproject.net.behaviour.PortDiscovery" 19 + <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
20 - impl="org.onosproject.drivers.lumentum.PortDiscoveryLumentumRoadm"/> 20 + impl="org.onosproject.drivers.lumentum.LumentumRoadmDeviceDescription"/>
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"
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
40 <module>ovsdb</module> 40 <module>ovsdb</module>
41 <module>utilities</module> 41 <module>utilities</module>
42 <module>lumentum</module> 42 <module>lumentum</module>
43 + <module>bti</module>
43 </modules> 44 </modules>
44 45
45 <!--<properties> 46 <!--<properties>
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
40 <module>rest</module> 40 <module>rest</module>
41 <module>ospf</module> 41 <module>ospf</module>
42 <module>isis</module> 42 <module>isis</module>
43 + <module>snmp</module>
43 </modules> 44 </modules>
44 45
45 <dependencies> 46 <dependencies>
......
1 +SRC = 'src/main/java/org/onosproject/**/'
2 +
3 +CURRENT_NAME = 'onos-snmp-api'
4 +CURRENT_TARGET = ':' + CURRENT_NAME
5 +
6 +COMPILE_DEPS = [
7 + '//lib:CORE_DEPS',
8 + '//incubator/api:onos-incubator-api',
9 + '//lib:org.apache.servicemix.bundles.snmp4j',
10 + '//lib:snmp-core',
11 + '//lib:bti7000',
12 + '//lib:mibs-net-snmp',
13 + '//lib:mibs-rfc',
14 +]
15 +
16 +java_library(
17 + name = CURRENT_NAME,
18 + srcs = glob([SRC + '/*.java']),
19 + deps = COMPILE_DEPS,
20 + visibility = ['PUBLIC'],
21 +)
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-snmp-protocol</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.6.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
26 + </parent>
27 + <modelVersion>4.0.0</modelVersion>
28 +
29 + <artifactId>onos-snmp-api</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <dependencies>
33 + <dependency>
34 + <groupId>org.onosproject</groupId>
35 + <artifactId>onos-incubator-api</artifactId>
36 + <version>1.6.0-SNAPSHOT</version>
37 + </dependency>
38 + </dependencies>
39 +
40 +
41 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.snmp;
18 +
19 +import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
20 +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
21 +import org.onosproject.net.DeviceId;
22 +
23 +import java.io.IOException;
24 +import java.util.Collection;
25 +
26 +/**
27 + * Snmp Controller.
28 + */
29 +public interface SnmpController {
30 +
31 + /**
32 + * Return all the devices that this controller has notion of.
33 + * @return Set of all Snmp devices
34 + */
35 + Collection<SnmpDevice> getDevices();
36 +
37 + /**
38 + * Gets a device for a specific deviceId.
39 + * @param deviceId device id of the device
40 + * @return SnmpDevice for given deviceId
41 + */
42 + SnmpDevice getDevice(DeviceId deviceId);
43 +
44 + /**
45 + * Removes a specific device.
46 + * @param deviceId device id of the device to be removed
47 + */
48 + void removeDevice(DeviceId deviceId);
49 +
50 + /**
51 + * Add a device with a specific DeviceId.
52 + * @param deviceId deviceId of the device
53 + * @param device device to add to this controller
54 + */
55 + void addDevice(DeviceId deviceId, SnmpDevice device);
56 +
57 + /**
58 + * Gets an Instance of ISnmpSession for a specific device.
59 + *
60 + * @param deviceId device to retrieve the session for.
61 + * @return ISnmp session.
62 + * @throws IOException if the session can't be established.
63 + */
64 + ISnmpSession getSession(DeviceId deviceId) throws IOException;
65 +
66 + /**
67 + * Creates an error alarm if the interaction with the device failed.
68 + *
69 + * @param deviceId the device with a failed interaction
70 + * @return default alarm error
71 + */
72 + DefaultAlarm buildWalkFailedAlarm(DeviceId deviceId);
73 +}
1 +/*
2 + * Copyright 2016 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.snmp;
18 +
19 +import org.onosproject.net.DeviceId;
20 +
21 +/**
22 + * Abstraction a default Snmp Device.
23 + */
24 +public interface SnmpDevice {
25 +
26 + /**
27 + * Returns host IP and host Port, used by this particular SNMP Device.
28 + *
29 + * @return Device Information.
30 + */
31 + String deviceInfo();
32 +
33 + /**
34 + * Terminates the device connection.
35 + */
36 + void disconnect();
37 +
38 + /**
39 + * Retrieves the device state.
40 + *
41 + * @return true if connected
42 + */
43 + boolean isReachable();
44 +
45 + /**
46 + * Returns the IP used connect ssh on the device.
47 + *
48 + * @return SNMP Device IP
49 + */
50 + String getSnmpHost();
51 +
52 + /**
53 + * Returns the SSH Port used connect the device.
54 + *
55 + * @return SSH Port number
56 + */
57 + int getSnmpPort();
58 +
59 + /**
60 + * Retrieves the username of the device.
61 + *
62 + * @return username
63 + */
64 + String getUsername();
65 +
66 + /**
67 + * Retrieves the community (password) of the device.
68 + *
69 + * @return password
70 + */
71 + String getCommunity();
72 +
73 + /**
74 + * Return the SNMP device deviceID.
75 + *
76 + * @return DeviceId
77 + */
78 + DeviceId deviceId();
79 +}
...@@ -13,27 +13,8 @@ ...@@ -13,27 +13,8 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.provider.snmp.device.impl;
17 -
18 -import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
19 -import org.onosproject.net.Device;
20 -import org.onosproject.net.device.DefaultDeviceDescription;
21 -import org.onosproject.net.device.DeviceDescription;
22 -import org.slf4j.Logger;
23 -import org.slf4j.LoggerFactory;
24 16
25 /** 17 /**
26 - * Device description provider for Lumentum SDN ROADMs. 18 + * Package for SNMP apis interfaces.
27 - * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
28 */ 19 */
29 -@Deprecated 20 +package org.onosproject.snmp;
30 -public class LumentumDeviceDescriptionProvider implements SnmpDeviceDescriptionProvider {
31 -
32 - private static final Logger log = LoggerFactory.getLogger(LumentumDeviceDescriptionProvider.class);
33 -
34 - @Override
35 - public DeviceDescription populateDescription(ISnmpSession session, DeviceDescription description) {
36 - return new DefaultDeviceDescription(description.deviceUri(), Device.Type.ROADM,
37 - "Lumentum", "SDN ROADM", "1.0", "v1", description.chassisId(), description.annotations());
38 - }
39 -}
......
1 +SRC = 'src/main/java/org/onosproject/**/'
2 +TEST = 'src/test/java/org/onosproject/**/'
3 +CURRENT_NAME = 'onos-snmp-ctl'
4 +CURRENT_TARGET = ':' + CURRENT_NAME
5 +
6 +COMPILE_DEPS = [
7 + '//lib:CORE_DEPS',
8 + '//incubator/api:onos-incubator-api',
9 + '//protocols/snmp/api:onos-snmp-api',
10 + '//lib:org.apache.servicemix.bundles.snmp4j',
11 + '//lib:snmp-core',
12 + '//lib:bti7000',
13 + '//lib:mibs-net-snmp',
14 + '//lib:mibs-rfc',
15 +]
16 +
17 +TEST_DEPS = [
18 + '//lib:TEST',
19 +]
20 +
21 +java_library(
22 + name = CURRENT_NAME,
23 + srcs = glob([SRC + '/*.java']),
24 + deps = COMPILE_DEPS,
25 + visibility = ['PUBLIC'],
26 +)
27 +
28 +java_test(
29 + name = 'tests',
30 + srcs = glob([TEST + '/*.java']),
31 + deps = COMPILE_DEPS +
32 + TEST_DEPS +
33 + [CURRENT_TARGET],
34 + source_under_test = [CURRENT_TARGET],
35 +)
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-snmp-protocol</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.6.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-snmp-ctl</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <dependencies>
32 + <dependency>
33 + <groupId>org.onosproject</groupId>
34 + <artifactId>onos-snmp-api</artifactId>
35 + <version>1.6.0-SNAPSHOT</version>
36 + </dependency>
37 + <dependency>
38 + <groupId>org.osgi</groupId>
39 + <artifactId>org.osgi.compendium</artifactId>
40 + </dependency>
41 + <dependency>
42 + <groupId>org.apache.felix</groupId>
43 + <artifactId>org.apache.felix.scr.annotations</artifactId>
44 + </dependency>
45 +
46 + <dependency>
47 + <groupId>org.onosproject</groupId>
48 + <artifactId>onos-incubator-api</artifactId>
49 + <version>1.6.0-SNAPSHOT</version>
50 + </dependency>
51 + </dependencies>
52 +
53 +
54 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.snmp.ctl;
18 +
19 +import com.btisystems.pronx.ems.core.snmp.DefaultSnmpConfigurationFactory;
20 +import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
21 +import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
22 +import com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory;
23 +import com.btisystems.pronx.ems.core.snmp.SnmpSessionFactory;
24 +import com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration;
25 +import com.google.common.base.Preconditions;
26 +import org.apache.felix.scr.annotations.Activate;
27 +import org.apache.felix.scr.annotations.Deactivate;
28 +import org.apache.felix.scr.annotations.Service;
29 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
30 +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
31 +import org.onosproject.net.DeviceId;
32 +import org.onosproject.snmp.SnmpController;
33 +import org.onosproject.snmp.SnmpDevice;
34 +import org.osgi.service.component.ComponentContext;
35 +import org.osgi.service.component.annotations.Component;
36 +import org.slf4j.Logger;
37 +import org.slf4j.LoggerFactory;
38 +
39 +import java.io.IOException;
40 +import java.util.Collection;
41 +import java.util.HashMap;
42 +import java.util.Map;
43 +import java.util.concurrent.ConcurrentHashMap;
44 +
45 +/**
46 + * Default implementation of the SNMP sub-controller.
47 + */
48 +@Component(immediate = true)
49 +@Service
50 +public class DefaultSnmpController implements SnmpController {
51 +
52 + private final Logger log = LoggerFactory
53 + .getLogger(getClass());
54 +
55 + private ISnmpSessionFactory sessionFactory;
56 +
57 + private final Map<DeviceId, ISnmpSession> sessionMap = new HashMap<>();
58 + protected Map<DeviceId, SnmpDevice> snmpDeviceMap = new ConcurrentHashMap<>();
59 +
60 + @Activate
61 + public void activate(ComponentContext context) {
62 + sessionFactory = new SnmpSessionFactory(
63 + new DefaultSnmpConfigurationFactory(new V2cSnmpConfiguration()));
64 + log.info("Started");
65 + }
66 +
67 + @Deactivate
68 + public void deactivate() {
69 + snmpDeviceMap.clear();
70 + log.info("Stopped");
71 + }
72 +
73 + @Override
74 + public ISnmpSession getSession(DeviceId deviceId) throws IOException {
75 + if (!sessionMap.containsKey(deviceId)) {
76 + SnmpDevice device = snmpDeviceMap.get(deviceId);
77 + String ipAddress = null;
78 + int port = -1;
79 + if (device != null) {
80 + ipAddress = device.getSnmpHost();
81 + port = device.getSnmpPort();
82 + } else {
83 + String[] deviceComponents = deviceId.toString().split(":");
84 + if (deviceComponents.length > 1) {
85 + ipAddress = deviceComponents[1];
86 + port = Integer.parseInt(deviceComponents[2]);
87 +
88 + } else {
89 + log.error("Cannot obtain correct information from device id", deviceId);
90 + }
91 + }
92 + Preconditions.checkNotNull(ipAddress, "ip address is empty, cannot start session");
93 + Preconditions.checkArgument(port != -1, "port is incorrect, cannot start session");
94 +
95 + ISnmpConfiguration config = new V2cSnmpConfiguration();
96 + config.setPort(port);
97 + sessionMap.put(deviceId, sessionFactory.createSession(config, ipAddress));
98 + }
99 + return sessionMap.get(deviceId);
100 + }
101 +
102 + @Override
103 + public Collection<SnmpDevice> getDevices() {
104 + return snmpDeviceMap.values();
105 + }
106 +
107 + @Override
108 + public SnmpDevice getDevice(DeviceId did) {
109 + return snmpDeviceMap.get(did);
110 + }
111 +
112 + @Override
113 + public void removeDevice(DeviceId did) {
114 + snmpDeviceMap.remove(did);
115 + }
116 +
117 + @Override
118 + public void addDevice(DeviceId did, SnmpDevice device) {
119 + snmpDeviceMap.put(did, device);
120 + }
121 +
122 + @Override
123 + public DefaultAlarm buildWalkFailedAlarm(DeviceId deviceId) {
124 + return new DefaultAlarm.Builder(
125 + deviceId, "SNMP alarm retrieval failed",
126 + Alarm.SeverityLevel.CRITICAL,
127 + System.currentTimeMillis()).build();
128 + }
129 +}
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,122 +13,105 @@ ...@@ -13,122 +13,105 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.provider.snmp.device.impl; 16 +package org.onosproject.snmp.ctl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import org.onosproject.net.DeviceId;
19 -import static org.slf4j.LoggerFactory.getLogger; 19 +import org.onosproject.snmp.SnmpDevice;
20 +import org.slf4j.Logger;
20 21
22 +import java.net.URI;
23 +import java.net.URISyntaxException;
21 24
22 -import org.slf4j.Logger; 25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +import static org.slf4j.LoggerFactory.getLogger;
23 27
24 /** 28 /**
25 * This is a logical representation of actual SNMP device, carrying all the necessary information to connect and execute 29 * This is a logical representation of actual SNMP device, carrying all the necessary information to connect and execute
26 * SNMP operations. 30 * SNMP operations.
27 */ 31 */
28 -public class SnmpDevice { 32 +public class DefaultSnmpDevice implements SnmpDevice {
29 33
30 - private final Logger log = getLogger(SnmpDevice.class); 34 + private final Logger log = getLogger(DefaultSnmpDevice.class);
31 35
32 36
33 private static final int DEFAULT_SNMP_PORT = 161; 37 private static final int DEFAULT_SNMP_PORT = 161;
34 38
39 + private static final String SCHEME = "snmp";
40 +
35 private final String snmpHost; 41 private final String snmpHost;
42 + private final DeviceId deviceId;
36 private int snmpPort = DEFAULT_SNMP_PORT; 43 private int snmpPort = DEFAULT_SNMP_PORT;
44 + private final String username;
45 + //Community is a conventional name for password in SNMP.
37 private final String community; 46 private final String community;
38 private boolean reachable = false; 47 private boolean reachable = false;
39 48
40 - private DeviceState deviceState = DeviceState.INVALID;
41 49
42 - protected SnmpDevice(String snmpHost, int snmpPort, String community) { 50 + public DefaultSnmpDevice(String snmpHost, int snmpPort, String username, String community) {
43 51
44 this.snmpHost = checkNotNull(snmpHost, "SNMP Device IP cannot be null"); 52 this.snmpHost = checkNotNull(snmpHost, "SNMP Device IP cannot be null");
45 - this.snmpPort = checkNotNull(snmpPort, "SNMP Device snmp port cannot be null"); 53 + this.snmpPort = checkNotNull(snmpPort, "SNMP Device port cannot be null");
54 + this.username = username;
46 this.community = community; 55 this.community = community;
47 - } 56 + this.deviceId = createDeviceId();
48 -
49 - /**
50 - * This will try to connect to SNMP device.
51 - *
52 - */
53 - public void init() {
54 -
55 reachable = true; 57 reachable = true;
56 } 58 }
57 59
58 - /** 60 + @Override
59 - * This would return host IP and host Port, used by this particular SNMP Device.
60 - *
61 - * @return Device Information.
62 - */
63 public String deviceInfo() { 61 public String deviceInfo() {
64 return new StringBuilder("host: ").append(snmpHost).append(". port: ") 62 return new StringBuilder("host: ").append(snmpHost).append(". port: ")
65 .append(snmpPort).toString(); 63 .append(snmpPort).toString();
66 } 64 }
67 65
68 - /** 66 + @Override
69 - * This will terminate the device connection.
70 - */
71 public void disconnect() { 67 public void disconnect() {
72 log.info("disconnect"); 68 log.info("disconnect");
73 reachable = false; 69 reachable = false;
74 } 70 }
75 71
76 - /** 72 + @Override
77 - * This api is intended to know whether the device is connected or not.
78 - *
79 - * @return true if connected
80 - */
81 public boolean isReachable() { 73 public boolean isReachable() {
82 return reachable; 74 return reachable;
83 } 75 }
84 76
85 - /** 77 + @Override
86 - * This will return the IP used connect ssh on the device.
87 - *
88 - * @return SNMP Device IP
89 - */
90 public String getSnmpHost() { 78 public String getSnmpHost() {
91 return snmpHost; 79 return snmpHost;
92 } 80 }
93 81
94 - /** 82 +
95 - * This will return the SSH Port used connect the device. 83 + @Override
96 - *
97 - * @return SSH Port number
98 - */
99 public int getSnmpPort() { 84 public int getSnmpPort() {
100 return snmpPort; 85 return snmpPort;
101 } 86 }
102 87
103 - public String getCommunity() { 88 + @Override
104 - return community; 89 + public String getUsername() {
90 + return username;
105 } 91 }
106 92
107 - /** 93 + @Override
108 - * Retrieve current state of the device. 94 + public String getCommunity() {
109 - * 95 + return community;
110 - * @return Current Device State
111 - */
112 - public DeviceState getDeviceState() {
113 - return deviceState;
114 } 96 }
115 97
116 - /** 98 + @Override
117 - * This is set the state information for the device. 99 + public DeviceId deviceId() {
118 - * 100 + return deviceId;
119 - * @param deviceState Next Device State
120 - */
121 - public void setDeviceState(DeviceState deviceState) {
122 - this.deviceState = deviceState;
123 } 101 }
124 102
125 - /** 103 + private DeviceId createDeviceId() {
126 - * Check whether the device is in Active state. 104 + String additionalSsp = new StringBuilder(
127 - * 105 + snmpHost).append(":")
128 - * @return true if the device is Active 106 + .append(snmpPort).toString();
129 - */ 107 + try {
130 - public boolean isActive() { 108 + return DeviceId.deviceId(new URI(SCHEME, additionalSsp,
131 - return deviceState == DeviceState.ACTIVE; 109 + null));
110 + } catch (URISyntaxException e) {
111 + log.error("Syntax Error while creating URI for the device: "
112 + + additionalSsp
113 + + " couldn't persist the device onto the store", e);
114 + throw new IllegalArgumentException("Can't create device ID from " + additionalSsp, e);
115 + }
132 } 116 }
133 -
134 } 117 }
......
1 /* 1 /*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
2 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
5 * 7 *
6 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
7 * 9 *
8 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
...@@ -11,25 +13,8 @@ ...@@ -11,25 +13,8 @@
11 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
12 * limitations under the License. 14 * limitations under the License.
13 */ 15 */
14 -package org.onosproject.provider.snmp.device.impl;
15 -
16 -import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
17 -import org.onosproject.net.device.DeviceDescription;
18 16
19 /** 17 /**
20 - * Abstraction of an entity which updates a device description with information retrieved via SNMP. 18 + * Package for implementation fo SNMP elements.
21 - * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
22 */ 19 */
23 -@Deprecated 20 +package org.onosproject.snmp.ctl;
24 -public interface SnmpDeviceDescriptionProvider {
25 -
26 - /**
27 - * Generated an updated device description.
28 - * @deprecated 1.5.0 Falcon
29 - * @param session SNMP session
30 - * @param description old device description
31 - * @return new updated description
32 - */
33 - @Deprecated
34 - DeviceDescription populateDescription(ISnmpSession session, DeviceDescription description);
35 -}
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-protocols</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.6.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-snmp-protocol</artifactId>
29 + <packaging>pom</packaging>
30 + <modules>
31 + <module>api</module>
32 + <module>ctl</module>
33 + </modules>
34 + <dependencies>
35 + <dependency>
36 + <groupId>com.btisystems</groupId>
37 + <artifactId>snmp-core</artifactId>
38 + <version>1.3-SNAPSHOT</version>
39 + </dependency>
40 + <dependency>
41 + <groupId>com.btisystems.mibbler.mibs</groupId>
42 + <artifactId>bti7000</artifactId>
43 + <version>1.0-SNAPSHOT</version>
44 + </dependency>
45 + <dependency>
46 + <groupId>com.btisystems.mibbler.mibs</groupId>
47 + <artifactId>net-snmp</artifactId>
48 + <version>1.0-SNAPSHOT</version>
49 + </dependency>
50 + <dependency>
51 + <groupId>org.onosproject</groupId>
52 + <artifactId>onos-api</artifactId>
53 + <version>1.6.0-SNAPSHOT</version>
54 + </dependency>
55 + </dependencies>
56 +
57 +
58 +</project>
...\ No newline at end of file ...\ No newline at end of file
...@@ -11,9 +11,8 @@ COMPILE_DEPS = [ ...@@ -11,9 +11,8 @@ COMPILE_DEPS = [
11 '//lib:bti7000', 11 '//lib:bti7000',
12 '//lib:mibs-net-snmp', 12 '//lib:mibs-net-snmp',
13 '//lib:mibs-rfc', 13 '//lib:mibs-rfc',
14 - '//protocols/ovsdb/api:onos-ovsdb-api',
15 - '//protocols/ovsdb/rfc:onos-ovsdb-rfc',
16 '//incubator/api:onos-incubator-api', 14 '//incubator/api:onos-incubator-api',
15 + '//protocols/snmp/api:onos-snmp-api',
17 ] 16 ]
18 17
19 TEST_DEPS = [ 18 TEST_DEPS = [
......
...@@ -21,4 +21,12 @@ ...@@ -21,4 +21,12 @@
21 <description>${project.description}</description> 21 <description>${project.description}</description>
22 <artifact>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</artifact> 22 <artifact>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</artifact>
23 <artifact>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</artifact> 23 <artifact>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</artifact>
24 +
25 + <artifact>mvn:${project.groupId}/onos-snmp-api/${project.version}</artifact>
26 + <artifact>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</artifact>
27 +
28 + <artifact>mvn:com.btisystems/snmp-core/1.3-SNAPSHOT</artifact>
29 + <artifact>mvn:com.btisystems.mibbler.mibs/bti7000/1.0-SNAPSHOT</artifact>
30 + <artifact>mvn:com.btisystems.mibbler.mibs/net-snmp/1.0-SNAPSHOT</artifact>
31 +
24 </app> 32 </app>
......
...@@ -19,9 +19,12 @@ ...@@ -19,9 +19,12 @@
19 description="${project.description}"> 19 description="${project.description}">
20 <feature>onos-api</feature> 20 <feature>onos-api</feature>
21 <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> 21 <bundle>mvn:io.netty/netty/3.9.2.Final</bundle>
22 - <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle> 22 + <bundle>mvn:${project.groupId}/onos-snmp-api/${project.version}</bundle>
23 + <bundle>mvn:${project.groupId}/onos-snmp-ctl/${project.version}</bundle>
23 <bundle>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</bundle> 24 <bundle>mvn:${project.groupId}/onos-snmp-provider-device/${project.version}</bundle>
24 <bundle>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</bundle> 25 <bundle>mvn:${project.groupId}/onos-snmp-provider-alarm/${project.version}</bundle>
26 +
27 + <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j/2.3.4_1</bundle>
25 <bundle>mvn:com.btisystems/snmp-core/1.3-SNAPSHOT</bundle> 28 <bundle>mvn:com.btisystems/snmp-core/1.3-SNAPSHOT</bundle>
26 <bundle>mvn:com.btisystems.mibbler.mibs/bti7000/1.0-SNAPSHOT</bundle> 29 <bundle>mvn:com.btisystems.mibbler.mibs/bti7000/1.0-SNAPSHOT</bundle>
27 <bundle>mvn:com.btisystems.mibbler.mibs/net-snmp/1.0-SNAPSHOT</bundle> 30 <bundle>mvn:com.btisystems.mibbler.mibs/net-snmp/1.0-SNAPSHOT</bundle>
......
...@@ -11,9 +11,9 @@ COMPILE_DEPS = [ ...@@ -11,9 +11,9 @@ COMPILE_DEPS = [
11 '//lib:bti7000', 11 '//lib:bti7000',
12 '//lib:mibs-net-snmp', 12 '//lib:mibs-net-snmp',
13 '//lib:mibs-rfc', 13 '//lib:mibs-rfc',
14 - '//protocols/ovsdb/api:onos-ovsdb-api',
15 - '//protocols/ovsdb/rfc:onos-ovsdb-rfc',
16 '//incubator/api:onos-incubator-api', 14 '//incubator/api:onos-incubator-api',
15 + '//protocols/snmp/api:onos-snmp-api',
16 + '//protocols/snmp/ctl:onos-snmp-ctl',
17 ] 17 ]
18 18
19 TEST_DEPS = [ 19 TEST_DEPS = [
......
...@@ -36,20 +36,50 @@ ...@@ -36,20 +36,50 @@
36 <groupId>org.osgi</groupId> 36 <groupId>org.osgi</groupId>
37 <artifactId>org.osgi.compendium</artifactId> 37 <artifactId>org.osgi.compendium</artifactId>
38 </dependency> 38 </dependency>
39 - <!-- <dependency> 39 + <dependency>
40 - <groupId>javax.ws.rs</groupId> 40 + <groupId>org.onosproject</groupId>
41 - <artifactId>javax.ws.rs-api</artifactId> 41 + <artifactId>onos-snmp-api</artifactId>
42 - <version>2.0.1</version> 42 + <version>1.6.0-SNAPSHOT</version>
43 </dependency> 43 </dependency>
44 <dependency> 44 <dependency>
45 <groupId>org.onosproject</groupId> 45 <groupId>org.onosproject</groupId>
46 - <artifactId>onos-incubator-api</artifactId> 46 + <artifactId>onos-snmp-ctl</artifactId>
47 + <version>1.6.0-SNAPSHOT</version>
48 + </dependency>
49 + <dependency>
50 + <groupId>org.apache.servicemix.bundles</groupId>
51 + <artifactId>org.apache.servicemix.bundles.snmp4j</artifactId>
52 + <version>2.3.4_1</version>
53 + <exclusions>
54 + <exclusion>
55 + <artifactId>log4j</artifactId>
56 + <groupId>log4j</groupId>
57 + </exclusion>
58 + </exclusions>
59 + </dependency>
60 +
61 + <dependency>
62 + <groupId>com.btisystems</groupId>
63 + <artifactId>snmp-core</artifactId>
64 + <version>1.3-SNAPSHOT</version>
65 + </dependency>
66 +
67 + <dependency>
68 + <groupId>com.btisystems.mibbler.mibs</groupId>
69 + <artifactId>bti7000</artifactId>
70 + <version>1.0-SNAPSHOT</version>
71 + </dependency>
72 +
73 + <dependency>
74 + <groupId>com.btisystems.mibbler.mibs</groupId>
75 + <artifactId>net-snmp</artifactId>
76 + <version>1.0-SNAPSHOT</version>
47 </dependency> 77 </dependency>
48 <dependency> 78 <dependency>
49 <groupId>org.onosproject</groupId> 79 <groupId>org.onosproject</groupId>
50 - <artifactId>onos-core-serializers</artifactId> 80 + <artifactId>onos-core-net</artifactId>
51 - <version>${project.version}</version> 81 + <version>1.6.0-SNAPSHOT</version>
52 - </dependency>--> 82 + </dependency>
53 </dependencies> 83 </dependencies>
54 <build> 84 <build>
55 <plugins> 85 <plugins>
......
...@@ -15,23 +15,16 @@ ...@@ -15,23 +15,16 @@
15 */ 15 */
16 package org.onosproject.provider.snmp.device.impl; 16 package org.onosproject.provider.snmp.device.impl;
17 17
18 -import com.btisystems.pronx.ems.core.snmp.DefaultSnmpConfigurationFactory;
19 -import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration;
20 -import com.btisystems.pronx.ems.core.snmp.ISnmpConfigurationFactory;
21 -import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
22 -import com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory;
23 -import com.btisystems.pronx.ems.core.snmp.SnmpSessionFactory;
24 -import com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration;
25 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
28 import org.apache.felix.scr.annotations.Modified; 21 import org.apache.felix.scr.annotations.Modified;
29 -import org.apache.felix.scr.annotations.Property;
30 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
31 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
32 import org.onlab.packet.ChassisId; 24 import org.onlab.packet.ChassisId;
33 -import org.onosproject.cfg.ComponentConfigService; 25 +import org.onosproject.core.ApplicationId;
34 -import org.onosproject.cluster.ClusterService; 26 +import org.onosproject.core.CoreService;
27 +import org.onosproject.incubator.net.config.basics.ConfigException;
35 import org.onosproject.net.AnnotationKeys; 28 import org.onosproject.net.AnnotationKeys;
36 import org.onosproject.net.DefaultAnnotations; 29 import org.onosproject.net.DefaultAnnotations;
37 import org.onosproject.net.Device; 30 import org.onosproject.net.Device;
...@@ -39,33 +32,32 @@ import org.onosproject.net.DeviceId; ...@@ -39,33 +32,32 @@ import org.onosproject.net.DeviceId;
39 import org.onosproject.net.MastershipRole; 32 import org.onosproject.net.MastershipRole;
40 import org.onosproject.net.PortNumber; 33 import org.onosproject.net.PortNumber;
41 import org.onosproject.net.SparseAnnotations; 34 import org.onosproject.net.SparseAnnotations;
42 -import org.onosproject.net.behaviour.PortDiscovery; 35 +import org.onosproject.net.config.ConfigFactory;
36 +import org.onosproject.net.config.NetworkConfigEvent;
37 +import org.onosproject.net.config.NetworkConfigListener;
38 +import org.onosproject.net.config.NetworkConfigRegistry;
43 import org.onosproject.net.device.DefaultDeviceDescription; 39 import org.onosproject.net.device.DefaultDeviceDescription;
44 import org.onosproject.net.device.DeviceDescription; 40 import org.onosproject.net.device.DeviceDescription;
41 +import org.onosproject.net.device.DeviceDescriptionDiscovery;
45 import org.onosproject.net.device.DeviceProvider; 42 import org.onosproject.net.device.DeviceProvider;
46 import org.onosproject.net.device.DeviceProviderRegistry; 43 import org.onosproject.net.device.DeviceProviderRegistry;
47 import org.onosproject.net.device.DeviceProviderService; 44 import org.onosproject.net.device.DeviceProviderService;
48 import org.onosproject.net.device.DeviceService; 45 import org.onosproject.net.device.DeviceService;
46 +import org.onosproject.net.device.DeviceStore;
49 import org.onosproject.net.provider.AbstractProvider; 47 import org.onosproject.net.provider.AbstractProvider;
50 import org.onosproject.net.provider.ProviderId; 48 import org.onosproject.net.provider.ProviderId;
49 +import org.onosproject.snmp.SnmpController;
50 +import org.onosproject.snmp.SnmpDevice;
51 +import org.onosproject.snmp.ctl.DefaultSnmpDevice;
51 import org.osgi.service.component.ComponentContext; 52 import org.osgi.service.component.ComponentContext;
52 import org.slf4j.Logger; 53 import org.slf4j.Logger;
53 54
54 -import java.io.IOException;
55 -import java.net.URI;
56 -import java.net.URISyntaxException;
57 -import java.util.Dictionary;
58 -import java.util.HashMap;
59 -import java.util.Map;
60 -import java.util.concurrent.ConcurrentHashMap;
61 import java.util.concurrent.ExecutorService; 55 import java.util.concurrent.ExecutorService;
62 import java.util.concurrent.Executors; 56 import java.util.concurrent.Executors;
63 import java.util.concurrent.TimeUnit; 57 import java.util.concurrent.TimeUnit;
64 58
65 -import static com.google.common.base.Strings.isNullOrEmpty;
66 -import static org.onlab.util.Tools.delay;
67 -import static org.onlab.util.Tools.get;
68 import static org.onlab.util.Tools.groupedThreads; 59 import static org.onlab.util.Tools.groupedThreads;
60 +import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
69 import static org.slf4j.LoggerFactory.getLogger; 61 import static org.slf4j.LoggerFactory.getLogger;
70 62
71 /** 63 /**
...@@ -79,81 +71,81 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -79,81 +71,81 @@ public class SnmpDeviceProvider extends AbstractProvider
79 private final Logger log = getLogger(SnmpDeviceProvider.class); 71 private final Logger log = getLogger(SnmpDeviceProvider.class);
80 72
81 private static final String UNKNOWN = "unknown"; 73 private static final String UNKNOWN = "unknown";
82 - 74 + private static final String APP_NAME = "org.onosproject.snmp";
83 - protected Map<DeviceId, SnmpDevice> snmpDeviceMap = new ConcurrentHashMap<>(); 75 + private static final String SCHEME = "snmp";
84 76
85 private DeviceProviderService providerService; 77 private DeviceProviderService providerService;
86 78
87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 79 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 + protected SnmpController controller;
81 +
82 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
88 protected DeviceProviderRegistry providerRegistry; 83 protected DeviceProviderRegistry providerRegistry;
89 84
90 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 protected DeviceService deviceService; 86 protected DeviceService deviceService;
92 87
93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
94 - protected ClusterService clusterService; 89 + protected DeviceStore deviceStore;
95 90
96 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
97 - protected ComponentConfigService cfgService; 92 + protected CoreService coreService;
98 -
99 - private final ExecutorService deviceBuilder = Executors
100 - .newFixedThreadPool(1, groupedThreads("onos/snmp", "device-creator", log));
101 93
102 - // Delay between events in ms. 94 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 - private static final int EVENTINTERVAL = 5; 95 + protected NetworkConfigRegistry netCfgService;
104 96
105 - private static final String SCHEME = "snmp"; 97 + private final ExecutorService deviceBuilderExecutor = Executors
98 + .newFixedThreadPool(5, groupedThreads("onos/snmp", "device-creator", log));
106 99
107 - @Property(name = "devConfigs", value = "", label = "Instance-specific configurations") 100 + private final NetworkConfigListener cfgLister = new InternalNetworkConfigListener();
108 - private String devConfigs = null;
109 101
110 - @Property(name = "devPasswords", value = "", label = "Instance-specific password") 102 + private ApplicationId appId;
111 - private String devPasswords = null;
112 103
113 - //TODO Could be replaced with a service lookup, and bundles per device variant. 104 + private final ConfigFactory factory =
114 - Map<String, SnmpDeviceDescriptionProvider> providers = new HashMap<>(); 105 + new ConfigFactory<ApplicationId, SnmpProviderConfig>(APP_SUBJECT_FACTORY,
106 + SnmpProviderConfig.class,
107 + "devices",
108 + true) {
109 + @Override
110 + public SnmpProviderConfig createConfig() {
111 + return new SnmpProviderConfig();
112 + }
113 + };
115 114
116 - private final ISnmpSessionFactory sessionFactory;
117 115
118 /** 116 /**
119 * Creates a provider with the supplier identifier. 117 * Creates a provider with the supplier identifier.
120 */ 118 */
121 public SnmpDeviceProvider() { 119 public SnmpDeviceProvider() {
122 super(new ProviderId("snmp", "org.onosproject.provider.device")); 120 super(new ProviderId("snmp", "org.onosproject.provider.device"));
123 - sessionFactory = new SnmpSessionFactory( 121 + //FIXME multiple type of SNMP sessions
124 - new DefaultSnmpConfigurationFactory(new V2cSnmpConfiguration()));
125 - //TODO refactor, no hardcoding in provider, device information should be in drivers
126 - providers.put("1.3.6.1.4.1.18070.2.2", new Bti7000DeviceDescriptionProvider());
127 - providers.put("1.3.6.1.4.1.20408", new NetSnmpDeviceDescriptionProvider());
128 - providers.put("1.3.6.1.4.562.73.6", new LumentumDeviceDescriptionProvider());
129 } 122 }
130 123
131 @Activate 124 @Activate
132 public void activate(ComponentContext context) { 125 public void activate(ComponentContext context) {
133 - log.info("activating for snmp devices ..."); 126 +
134 - cfgService.registerProperties(getClass());
135 providerService = providerRegistry.register(this); 127 providerService = providerRegistry.register(this);
128 + appId = coreService.registerApplication(APP_NAME);
129 + netCfgService.registerConfigFactory(factory);
130 + netCfgService.addListener(cfgLister);
136 modified(context); 131 modified(context);
137 - log.info("activated ok"); 132 + log.info("Started");
138 } 133 }
139 134
140 @Deactivate 135 @Deactivate
141 public void deactivate(ComponentContext context) { 136 public void deactivate(ComponentContext context) {
142 137
143 - log.info("deactivating for snmp devices ...");
144 -
145 - cfgService.unregisterProperties(getClass(), false);
146 try { 138 try {
147 - snmpDeviceMap 139 + controller.getDevices().stream().forEach(device -> {
148 - .entrySet().stream().forEach((deviceEntry) -> { 140 + deviceBuilderExecutor.execute(new DeviceFactory(device, false));
149 - deviceBuilder.execute(new DeviceCreator(deviceEntry.getValue(), false)); 141 + });
150 - }); 142 + deviceBuilderExecutor.awaitTermination(1000, TimeUnit.MILLISECONDS);
151 - deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
152 } catch (InterruptedException e) { 143 } catch (InterruptedException e) {
153 log.error("Device builder did not terminate"); 144 log.error("Device builder did not terminate");
154 } 145 }
155 - deviceBuilder.shutdownNow(); 146 + deviceBuilderExecutor.shutdownNow();
156 - snmpDeviceMap.clear(); 147 + netCfgService.unregisterConfigFactory(factory);
148 + netCfgService.removeListener(cfgLister);
157 providerRegistry.unregister(this); 149 providerRegistry.unregister(this);
158 providerService = null; 150 providerService = null;
159 log.info("Stopped"); 151 log.info("Stopped");
...@@ -161,100 +153,36 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -161,100 +153,36 @@ public class SnmpDeviceProvider extends AbstractProvider
161 153
162 @Modified 154 @Modified
163 public void modified(ComponentContext context) { 155 public void modified(ComponentContext context) {
164 - log.info("modified ..."); 156 + log.info("Modified");
165 -
166 - if (context == null) {
167 - log.info("No configuration file");
168 - return;
169 - }
170 - Dictionary<?, ?> properties = context.getProperties();
171 -
172 - log.info("properties={}", context.getProperties());
173 -
174 - String deviceCfgValue = get(properties, "devConfigs");
175 - log.info("Settings: devConfigs={}", deviceCfgValue);
176 - if (!isNullOrEmpty(deviceCfgValue)) {
177 - addOrRemoveDevicesConfig(deviceCfgValue);
178 - }
179 - log.info("... modified");
180 -
181 } 157 }
182 158
183 - private void addOrRemoveDevicesConfig(String deviceConfig) { 159 + private void addOrRemoveDevicesConfig() {
184 - for (String deviceEntry : deviceConfig.split(",")) { 160 + SnmpProviderConfig cfg = netCfgService.getConfig(appId, SnmpProviderConfig.class);
185 - SnmpDevice device = processDeviceEntry(deviceEntry); 161 + if (cfg != null) {
186 - if (device != null) { 162 + try {
187 - log.info("Device Detail:host={}, port={}, state={}", 163 + cfg.getDevicesInfo().stream().forEach(info -> {
188 - new Object[]{device.getSnmpHost(), 164 + SnmpDevice device = new DefaultSnmpDevice(info.ip().toString(),
189 - device.getSnmpPort(), 165 + info.port(), info.username(), info.password());
190 - device.getDeviceState().name()} 166 + buildDevice(device);
191 - ); 167 + });
192 - if (device.isActive()) { 168 + } catch (ConfigException e) {
193 - deviceBuilder.execute(new DeviceCreator(device, true)); 169 + log.error("Cannot read config error " + e);
194 - } else {
195 - deviceBuilder.execute(new DeviceCreator(device, false));
196 - }
197 } 170 }
198 } 171 }
199 } 172 }
200 173
201 - private SnmpDevice processDeviceEntry(String deviceEntry) { 174 + private void buildDevice(SnmpDevice device) {
202 - if (deviceEntry == null) { 175 + if (device != null) {
203 - log.info("No content for Device Entry, so cannot proceed further."); 176 + log.debug("Device Detail:host={}, port={}, state={}",
204 - return null; 177 + device.getSnmpHost(),
205 - } 178 + device.getSnmpPort(),
206 - log.info("Trying to convert {} to a SNMP Device Object", deviceEntry); 179 + device.isReachable());
207 - SnmpDevice device = null; 180 + if (device.isReachable()) {
208 - try { 181 + deviceBuilderExecutor.execute(new DeviceFactory(device, true));
209 - String userInfo = deviceEntry.substring(0, deviceEntry
210 - .lastIndexOf('@'));
211 - String hostInfo = deviceEntry.substring(deviceEntry
212 - .lastIndexOf('@') + 1);
213 - String[] infoSplit = userInfo.split(":");
214 - String username = infoSplit[0];
215 - String password = infoSplit[1];
216 - infoSplit = hostInfo.split(":");
217 - String hostIp = infoSplit[0];
218 - Integer hostPort;
219 - try {
220 - hostPort = Integer.parseInt(infoSplit[1]);
221 - } catch (NumberFormatException nfe) {
222 - log.error("Bad Configuration Data: Failed to parse host port number string: "
223 - + infoSplit[1]);
224 - throw nfe;
225 - }
226 - String deviceState = infoSplit[2];
227 - if (isNullOrEmpty(username) || isNullOrEmpty(password)
228 - || isNullOrEmpty(hostIp) || hostPort == 0) {
229 - log.warn("Bad Configuration Data: both user and device information parts of Configuration "
230 - + deviceEntry + " should be non-nullable");
231 } else { 182 } else {
232 - device = new SnmpDevice(hostIp, hostPort, password); 183 + deviceBuilderExecutor.execute(new DeviceFactory(device, false));
233 - if (!isNullOrEmpty(deviceState)) {
234 - if (deviceState.toUpperCase().equals(DeviceState.ACTIVE.name())) {
235 - device.setDeviceState(DeviceState.ACTIVE);
236 - } else if (deviceState.toUpperCase()
237 - .equals(DeviceState.INACTIVE.name())) {
238 - device.setDeviceState(DeviceState.INACTIVE);
239 - } else {
240 - log.warn("Device State Information can not be empty, so marking the state as INVALID");
241 - device.setDeviceState(DeviceState.INVALID);
242 - }
243 - } else {
244 - log.warn("The device entry do not specify state information, so marking the state as INVALID");
245 - device.setDeviceState(DeviceState.INVALID);
246 - }
247 } 184 }
248 - } catch (ArrayIndexOutOfBoundsException aie) {
249 - log.error("Error while reading config infromation from the config file: "
250 - + "The user, host and device state infomation should be "
251 - + "in the order 'userInfo@hostInfo:deviceState'"
252 - + deviceEntry, aie);
253 - } catch (Exception e) {
254 - log.error("Error while parsing config information for the device entry: "
255 - + deviceEntry, e);
256 } 185 }
257 - return device;
258 } 186 }
259 187
260 @Override 188 @Override
...@@ -265,16 +193,16 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -265,16 +193,16 @@ public class SnmpDeviceProvider extends AbstractProvider
265 193
266 @Override 194 @Override
267 public void roleChanged(DeviceId deviceId, MastershipRole newRole) { 195 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
268 - 196 + // TODO Implement Masterhsip Service
269 } 197 }
270 198
271 @Override 199 @Override
272 public boolean isReachable(DeviceId deviceId) { 200 public boolean isReachable(DeviceId deviceId) {
273 - SnmpDevice snmpDevice = snmpDeviceMap.get(deviceId); 201 + SnmpDevice snmpDevice = controller.getDevice(deviceId);
274 if (snmpDevice == null) { 202 if (snmpDevice == null) {
275 log.warn("BAD REQUEST: the requested device id: " 203 log.warn("BAD REQUEST: the requested device id: "
276 - + deviceId.toString() 204 + + deviceId.toString()
277 - + " is not associated to any SNMP Device"); 205 + + " is not associated to any SNMP Device");
278 return false; 206 return false;
279 } 207 }
280 return snmpDevice.isReachable(); 208 return snmpDevice.isReachable();
...@@ -285,12 +213,13 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -285,12 +213,13 @@ public class SnmpDeviceProvider extends AbstractProvider
285 * 'SnmpDevice' content. The functionality runs as a thread and depending on the 'createFlag' value it will create 213 * 'SnmpDevice' content. The functionality runs as a thread and depending on the 'createFlag' value it will create
286 * or remove Device entry from the core. 214 * or remove Device entry from the core.
287 */ 215 */
288 - private class DeviceCreator implements Runnable { 216 + //FIXME consider rework.
217 + private class DeviceFactory implements Runnable {
289 218
290 private SnmpDevice device; 219 private SnmpDevice device;
291 private boolean createFlag; 220 private boolean createFlag;
292 221
293 - public DeviceCreator(SnmpDevice device, boolean createFlag) { 222 + public DeviceFactory(SnmpDevice device, boolean createFlag) {
294 this.device = device; 223 this.device = device;
295 this.createFlag = createFlag; 224 this.createFlag = createFlag;
296 } 225 }
...@@ -298,10 +227,10 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -298,10 +227,10 @@ public class SnmpDeviceProvider extends AbstractProvider
298 @Override 227 @Override
299 public void run() { 228 public void run() {
300 if (createFlag) { 229 if (createFlag) {
301 - log.info("Trying to create Device Info on ONOS core"); 230 + log.debug("Trying to create Device Info on ONOS core");
302 advertiseDevices(); 231 advertiseDevices();
303 } else { 232 } else {
304 - log.info("Trying to remove Device Info on ONOS core"); 233 + log.debug("Trying to remove Device Info on ONOS core");
305 removeDevices(); 234 removeDevices();
306 } 235 }
307 } 236 }
...@@ -314,24 +243,16 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -314,24 +243,16 @@ public class SnmpDeviceProvider extends AbstractProvider
314 log.warn("The Request SNMP Device is null, cannot proceed further"); 243 log.warn("The Request SNMP Device is null, cannot proceed further");
315 return; 244 return;
316 } 245 }
317 - try { 246 + DeviceId did = device.deviceId();
318 - DeviceId did = getDeviceId(); 247 + if (controller.getDevice(did) == null) {
319 - if (!snmpDeviceMap.containsKey(did)) { 248 + log.error("BAD Request: 'Currently device is not discovered, "
320 - log.error("BAD Request: 'Currently device is not discovered, " 249 + + "so cannot remove/disconnect the device: "
321 - + "so cannot remove/disconnect the device: " 250 + + device.deviceInfo() + "'");
322 - + device.deviceInfo() + "'"); 251 + return;
323 - return;
324 - }
325 - providerService.deviceDisconnected(did);
326 - device.disconnect();
327 - snmpDeviceMap.remove(did);
328 - delay(EVENTINTERVAL);
329 - } catch (URISyntaxException uriSyntaxExcpetion) {
330 - log.error("Syntax Error while creating URI for the device: "
331 - + device.deviceInfo()
332 - + " couldn't remove the device from the store",
333 - uriSyntaxExcpetion);
334 } 252 }
253 + providerService.deviceDisconnected(did);
254 + device.disconnect();
255 + controller.removeDevice(did);
335 } 256 }
336 257
337 /** 258 /**
...@@ -343,8 +264,7 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -343,8 +264,7 @@ public class SnmpDeviceProvider extends AbstractProvider
343 log.warn("The Request SNMP Device is null, cannot proceed further"); 264 log.warn("The Request SNMP Device is null, cannot proceed further");
344 return; 265 return;
345 } 266 }
346 - device.init(); 267 + DeviceId did = device.deviceId();
347 - DeviceId did = getDeviceId();
348 ChassisId cid = new ChassisId(); 268 ChassisId cid = new ChassisId();
349 269
350 SparseAnnotations annotations = DefaultAnnotations.builder() 270 SparseAnnotations annotations = DefaultAnnotations.builder()
...@@ -354,79 +274,46 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -354,79 +274,46 @@ public class SnmpDeviceProvider extends AbstractProvider
354 DeviceDescription desc = new DefaultDeviceDescription( 274 DeviceDescription desc = new DefaultDeviceDescription(
355 did.uri(), Device.Type.OTHER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); 275 did.uri(), Device.Type.OTHER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations);
356 276
357 - desc = populateDescriptionFromDevice(did, desc); 277 + log.debug("Persisting Device " + did.uri().toString());
358 278
359 - log.info("Persisting Device " + did.uri().toString()); 279 + controller.addDevice(did, device);
360 -
361 - snmpDeviceMap.put(did, device);
362 providerService.deviceConnected(did, desc); 280 providerService.deviceConnected(did, desc);
363 - log.info("Done with Device Info Creation on ONOS core. Device Info: " 281 + log.info("Added device to ONOS core. Device Info: "
364 - + device.deviceInfo() + " " + did.uri().toString()); 282 + + device.deviceInfo() + " " + did.uri().toString());
365 - 283 + //FIXME this description will be populated only if driver is pushed from outside
366 - // Do port discovery if driver supports it 284 + // becuase otherwise default driver is used
367 Device d = deviceService.getDevice(did); 285 Device d = deviceService.getDevice(did);
368 - if (d.is(PortDiscovery.class)) { 286 + if (d.is(DeviceDescriptionDiscovery.class)) {
369 - PortDiscovery portConfig = d.as(PortDiscovery.class); 287 + DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class);
370 - if (portConfig != null) { 288 + DeviceDescription description = descriptionDiscovery.discoverDeviceDetails();
371 - providerService.updatePorts(did, portConfig.getPorts()); 289 + deviceStore.createOrUpdateDevice(
372 - } 290 + new ProviderId("snmp", "org.onosproject.provider.device"),
291 + did, description);
292 + providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails());
373 } else { 293 } else {
374 - log.warn("No port discovery behaviour for device {}", did); 294 + log.warn("No populate description and ports behaviour for device {}", did);
375 } 295 }
376 -
377 - delay(EVENTINTERVAL);
378 - } catch (URISyntaxException e) {
379 - log.error("Syntax Error while creating URI for the device: "
380 - + device.deviceInfo()
381 - + " couldn't persist the device onto the store", e);
382 } catch (Exception e) { 296 } catch (Exception e) {
383 log.error("Error while initializing session for the device: " 297 log.error("Error while initializing session for the device: "
384 - + (device != null ? device.deviceInfo() : null), e); 298 + + (device != null ? device.deviceInfo() : null), e);
385 } 299 }
386 } 300 }
387 - /** 301 + }
388 - * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
389 - */
390 - @Deprecated
391 - private DeviceDescription populateDescriptionFromDevice(DeviceId did, DeviceDescription desc) {
392 - String[] deviceComponents = did.toString().split(":");
393 - if (deviceComponents.length > 1) {
394 - String ipAddress = deviceComponents[1];
395 - String port = deviceComponents[2];
396 -
397 - ISnmpConfiguration config = new V2cSnmpConfiguration();
398 - config.setPort(Integer.parseInt(port));
399 -
400 - try (ISnmpSession session = sessionFactory.createSession(config, ipAddress)) {
401 - // Each session will be auto-closed.
402 - String deviceOid = session.identifyDevice();
403 -
404 - if (providers.containsKey(deviceOid)) {
405 - desc = providers.get(deviceOid).populateDescription(session, desc);
406 - }
407 -
408 - } catch (IOException | RuntimeException ex) {
409 - log.error("Failed to walk device.", ex.getMessage());
410 - log.debug("Detailed problem was ", ex);
411 - }
412 - }
413 - return desc;
414 - }
415 302
416 - /** 303 + private class InternalNetworkConfigListener implements NetworkConfigListener {
417 - * This will build a device id for the device. 304 +
418 - */ 305 +
419 - private DeviceId getDeviceId() throws URISyntaxException { 306 + @Override
420 - String additionalSsp = new StringBuilder( 307 + public void event(NetworkConfigEvent event) {
421 - device.getSnmpHost()).append(":") 308 + addOrRemoveDevicesConfig();
422 - .append(device.getSnmpPort()).toString();
423 - return DeviceId.deviceId(new URI(SCHEME, additionalSsp,
424 - null));
425 } 309 }
426 - }
427 310
428 - protected ISnmpSessionFactory getSessionFactory(ISnmpConfigurationFactory configurationFactory) { 311 + @Override
429 - return new SnmpSessionFactory(configurationFactory); 312 + public boolean isRelevant(NetworkConfigEvent event) {
313 + return event.configClass().equals(SnmpProviderConfig.class) &&
314 + (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
315 + event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED);
316 + }
430 } 317 }
431 318
432 @Override 319 @Override
......
1 +/*
2 + * Copyright 2016 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.provider.snmp.device.impl;
18 +
19 +/*
20 + * Copyright 2015 Open Networking Laboratory
21 + *
22 + * Licensed under the Apache License, Version 2.0 (the "License");
23 + * you may not use this file except in compliance with the License.
24 + * You may obtain a copy of the License at
25 + *
26 + * http://www.apache.org/licenses/LICENSE-2.0
27 + *
28 + * Unless required by applicable law or agreed to in writing, software
29 + * distributed under the License is distributed on an "AS IS" BASIS,
30 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 + * See the License for the specific language governing permissions and
32 + * limitations under the License.
33 + */
34 +
35 +import com.fasterxml.jackson.databind.JsonNode;
36 +import com.google.common.annotations.Beta;
37 +import com.google.common.collect.Sets;
38 +import org.onlab.packet.IpAddress;
39 +import org.onosproject.core.ApplicationId;
40 +import org.onosproject.incubator.net.config.basics.ConfigException;
41 +import org.onosproject.net.config.Config;
42 +
43 +import java.util.Set;
44 +
45 +/**
46 + * Configuration decoder for SNMP provider.
47 + */
48 +@Beta
49 +public class SnmpProviderConfig extends Config<ApplicationId> {
50 +
51 + public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
52 + private static final String IP = "ip";
53 + private static final int DEFAULT_TCP_PORT = 830;
54 + private static final String PORT = "port";
55 + private static final String NAME = "username";
56 + private static final String PASSWORD = "password";
57 +
58 + /**
59 + * Retrieves a set of SnmpDeviceInfo containing all the device
60 + * configuration pertaining to the SNMP device provider.
61 + * @return set of device configurations.
62 + *
63 + * @throws ConfigException if configuration can't be read
64 + */
65 + public Set<SnmpDeviceInfo> getDevicesInfo() throws ConfigException {
66 + Set<SnmpDeviceInfo> deviceInfos = Sets.newHashSet();
67 +
68 + try {
69 + for (JsonNode node : array) {
70 + String ip = node.path(IP).asText();
71 + IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
72 + int port = node.path(PORT).asInt(DEFAULT_TCP_PORT);
73 + String name = node.path(NAME).asText();
74 + String password = node.path(PASSWORD).asText();
75 + deviceInfos.add(new SnmpDeviceInfo(ipAddr, port, name, password));
76 +
77 + }
78 + } catch (IllegalArgumentException e) {
79 + throw new ConfigException(CONFIG_VALUE_ERROR, e);
80 + }
81 +
82 + return deviceInfos;
83 + }
84 +
85 + /**
86 + * Contains information about a SNMP device retrieved form the net-cfg subsystem.
87 + */
88 + public class SnmpDeviceInfo {
89 + private final IpAddress ip;
90 + private final int port;
91 + private final String username;
92 + private final String password;
93 +
94 + /**
95 + * Build an information object containing the given device specifics.
96 + * @param ip ip
97 + * @param port port
98 + * @param username username
99 + * @param password password (a.k.a community in SNMP)
100 + */
101 + public SnmpDeviceInfo(IpAddress ip, int port, String username, String password) {
102 + this.ip = ip;
103 + this.port = port;
104 + this.username = username;
105 + this.password = password;
106 + }
107 +
108 + /**
109 + * Returns IpAddress of the device.
110 + * @return ip
111 + */
112 + public IpAddress ip() {
113 + return ip;
114 + }
115 +
116 + /**
117 + * Returns port of the device.
118 + * @return port
119 + */
120 + public int port() {
121 + return port;
122 + }
123 +
124 + /**
125 + * Returns username of the device.
126 + * @return username
127 + */
128 + public String username() {
129 + return username;
130 + }
131 +
132 + /**
133 + * Returns password of the device.
134 + * @return password
135 + */
136 + public String password() {
137 + return password;
138 + }
139 + }
140 +
141 +}
142 +
...@@ -36,38 +36,7 @@ ...@@ -36,38 +36,7 @@
36 <module>app</module> 36 <module>app</module>
37 <module>alarm</module> 37 <module>alarm</module>
38 </modules> 38 </modules>
39 - 39 +
40 - <dependencies>
41 - <dependency>
42 - <groupId>org.apache.servicemix.bundles</groupId>
43 - <artifactId>org.apache.servicemix.bundles.snmp4j</artifactId>
44 - <version>2.3.4_1</version>
45 - <exclusions>
46 - <exclusion>
47 - <artifactId>log4j</artifactId>
48 - <groupId>log4j</groupId>
49 - </exclusion>
50 - </exclusions>
51 - </dependency>
52 -
53 - <dependency>
54 - <groupId>com.btisystems</groupId>
55 - <artifactId>snmp-core</artifactId>
56 - <version>1.3-SNAPSHOT</version>
57 - </dependency>
58 -
59 - <dependency>
60 - <groupId>com.btisystems.mibbler.mibs</groupId>
61 - <artifactId>bti7000</artifactId>
62 - <version>1.0-SNAPSHOT</version>
63 - </dependency>
64 -
65 - <dependency>
66 - <groupId>com.btisystems.mibbler.mibs</groupId>
67 - <artifactId>net-snmp</artifactId>
68 - <version>1.0-SNAPSHOT</version>
69 - </dependency>
70 - </dependencies>
71 <repositories> 40 <repositories>
72 <repository> 41 <repository>
73 <!-- TODO move over to release snmp-core when it becomes available. ONOS-3646 --> 42 <!-- TODO move over to release snmp-core when it becomes available. ONOS-3646 -->
......