blob: 1d9c7ffe648dc691dfca6cfaee03645b2060afe5 [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;
22import java.io.IOException;
23import java.util.Arrays;
24import org.apache.commons.lang.StringUtils;
25import org.onosproject.net.device.DefaultDeviceDescription;
26import org.onosproject.net.device.DeviceDescription;
27import org.slf4j.Logger;
28import static org.slf4j.LoggerFactory.getLogger;
29import org.snmp4j.smi.OID;
30
31/**
32 * A agent-specific implementation supporting NET-SNMP agents.
Andrea Campanella3eca4a82016-02-10 17:35:14 -080033 * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
kmcpeakeb172d5f2015-12-10 11:30:43 +000034 */
Andrea Campanella3eca4a82016-02-10 17:35:14 -080035@Deprecated
kmcpeakeb172d5f2015-12-10 11:30:43 +000036public class NetSnmpDeviceDescriptionProvider implements SnmpDeviceDescriptionProvider {
37 private final Logger log = getLogger(getClass());
38 protected static final IClassRegistry CLASS_REGISTRY =
39 new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class);
40 private static final String UNKNOWN = "unknown";
41
42 @Override
43 public DeviceDescription populateDescription(ISnmpSession session, DeviceDescription description) {
44 NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
45 session.getAddress().getHostAddress());
46 try {
47 session.walkDevice(networkDevice, Arrays.asList(new OID[]{
48 CLASS_REGISTRY.getClassToOidMap().get(
49 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class)}));
50
51 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System systemTree =
52 (com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System)
53 networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get(
54 com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class));
55 if (systemTree != null) {
56 // TODO SNMP sys-contacts may be verbose; ONOS-GUI doesn't abbreviate fields neatly;
57 // so cut it here until supported in prop displayer
58 String manufacturer = StringUtils.abbreviate(systemTree.getSysContact(), 20);
59 return new DefaultDeviceDescription(description.deviceUri(), description.type(), manufacturer,
60 UNKNOWN, UNKNOWN, UNKNOWN, description.chassisId());
61 }
62 } catch (IOException ex) {
63 log.error("Error reading details for device {}.", session.getAddress(), ex);
64 }
65 return description;
66 }
67
68}