blob: a84a43c72b5c62a096cf96e5a0b087711171d3e1 [file] [log] [blame]
kmcpeakeb172d5f2015-12-10 11:30:43 +00001/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package org.onosproject.provider.snmp.device.impl;
15
16import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device;
17import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry;
18import com.btisystems.pronx.ems.core.model.ClassRegistry;
19import com.btisystems.pronx.ems.core.model.IClassRegistry;
20import com.btisystems.pronx.ems.core.model.NetworkDevice;
21import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
kmcpeakeb172d5f2015-12-10 11:30:43 +000022import org.apache.commons.lang.StringUtils;
23import org.onosproject.net.device.DefaultDeviceDescription;
24import org.onosproject.net.device.DeviceDescription;
25import org.slf4j.Logger;
kmcpeakeb172d5f2015-12-10 11:30:43 +000026import org.snmp4j.smi.OID;
27
Marc De Leenheerc662d322016-02-18 16:05:10 -080028import java.io.IOException;
29import java.util.Arrays;
30
31import static org.slf4j.LoggerFactory.getLogger;
32
kmcpeakeb172d5f2015-12-10 11:30:43 +000033/**
34 * A agent-specific implementation supporting NET-SNMP agents.
Andrea Campanella3eca4a82016-02-10 17:35:14 -080035 * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
kmcpeakeb172d5f2015-12-10 11:30:43 +000036 */
Andrea Campanella3eca4a82016-02-10 17:35:14 -080037@Deprecated
kmcpeakeb172d5f2015-12-10 11:30:43 +000038public class NetSnmpDeviceDescriptionProvider implements SnmpDeviceDescriptionProvider {
39 private final Logger log = getLogger(getClass());
40 protected static final IClassRegistry CLASS_REGISTRY =
41 new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
42 private static final String UNKNOWN = "unknown";
43
44 @Override
45 public DeviceDescription populateDescription(ISnmpSession session, DeviceDescription description) {
46 NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
47 session.getAddress().getHostAddress());
48 try {
49 session.walkDevice(networkDevice, Arrays.asList(new OID[]{
50 CLASS_REGISTRY.getClassToOidMap().get(
51 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class)}));
52
53 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System systemTree =
54 (com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System)
55 networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get(
56 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class));
57 if (systemTree != null) {
58 // TODO SNMP sys-contacts may be verbose; ONOS-GUI doesn't abbreviate fields neatly;
59 // so cut it here until supported in prop displayer
60 String manufacturer = StringUtils.abbreviate(systemTree.getSysContact(), 20);
61 return new DefaultDeviceDescription(description.deviceUri(), description.type(), manufacturer,
Marc De Leenheerc662d322016-02-18 16:05:10 -080062 UNKNOWN, UNKNOWN, UNKNOWN, description.chassisId(), description.annotations());
kmcpeakeb172d5f2015-12-10 11:30:43 +000063 }
64 } catch (IOException ex) {
65 log.error("Error reading details for device {}.", session.getAddress(), ex);
66 }
67 return description;
68 }
69
70}