Search in sources :

Example 1 with SnmpDevice

use of org.onosproject.snmp.SnmpDevice in project onos by opennetworkinglab.

the class PolatisSnmpUtility method getTarget.

private static CommunityTarget getTarget(DriverHandler handler) {
    SnmpDevice device = getDevice(handler);
    Address targetAddress = GenericAddress.parse(device.getProtocol() + ":" + device.getSnmpHost() + "/" + device.getSnmpPort());
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString(getDevice(handler).getCommunity()));
    target.setAddress(targetAddress);
    target.setRetries(3);
    target.setTimeout(1000L * 3L);
    target.setVersion(SnmpConstants.version2c);
    target.setMaxSizeRequestPDU(MAX_SIZE_RESPONSE_PDU);
    return target;
}
Also used : OctetString(org.snmp4j.smi.OctetString) Address(org.snmp4j.smi.Address) GenericAddress(org.snmp4j.smi.GenericAddress) SnmpDevice(org.onosproject.snmp.SnmpDevice) CommunityTarget(org.snmp4j.CommunityTarget)

Example 2 with SnmpDevice

use of org.onosproject.snmp.SnmpDevice in project onos by opennetworkinglab.

the class DefaultSnmpController method getSession.

@Override
@Deprecated
public ISnmpSession getSession(DeviceId deviceId) throws IOException {
    if (!sessionMap.containsKey(deviceId)) {
        SnmpDevice device = snmpDeviceMap.get(deviceId);
        ISnmpSessionFactory sessionFactory = factoryMap.get(device.getVersion());
        if (Objects.isNull(sessionFactory)) {
            log.error("Invalid session factory", deviceId);
            throw new SnmpException("Invalid session factory");
        }
        String ipAddress = null;
        int port = -1;
        if (device != null) {
            ipAddress = device.getSnmpHost();
            port = device.getSnmpPort();
        } else {
            String[] deviceComponents = deviceId.toString().split(":");
            if (deviceComponents.length > 1) {
                ipAddress = deviceComponents[1];
                port = Integer.parseInt(deviceComponents[2]);
            } else {
                log.error("Cannot obtain correct information from device id", deviceId);
            }
        }
        Preconditions.checkNotNull(ipAddress, "ip address is empty, cannot start session");
        Preconditions.checkArgument(port != -1, "port is incorrect, cannot start session");
        ISnmpConfiguration config;
        if (device.getVersion() == SnmpConstants.version2c) {
            config = new V2cSnmpConfiguration();
            config.setCommunity(device.getCommunity());
        } else if (device.getVersion() == SnmpConstants.version3) {
            DefaultSnmpv3Device v3Device = (DefaultSnmpv3Device) device;
            config = V3SnmpConfiguration.builder().setAddress(ipAddress).setSecurityName(v3Device.getSecurityName()).setSecurityLevel(v3Device.getSecurityLevel()).setAuthenticationProtocol(v3Device.getAuthProtocol()).setAuthenticationPassword(v3Device.getAuthPassword()).setPrivacyProtocol(v3Device.getPrivProtocol()).setPrivacyPassword(v3Device.getPrivPassword()).setContextName(v3Device.getContextName()).build();
        } else {
            throw new SnmpException(String.format("Invalid snmp version %d", device.getVersion()));
        }
        config.setPort(port);
        sessionMap.put(deviceId, sessionFactory.createSession(config, ipAddress));
    }
    return sessionMap.get(deviceId);
}
Also used : SnmpException(org.onosproject.snmp.SnmpException) SnmpDevice(org.onosproject.snmp.SnmpDevice) ISnmpSessionFactory(com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory) V2cSnmpConfiguration(com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration) ISnmpConfiguration(com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration)

Example 3 with SnmpDevice

use of org.onosproject.snmp.SnmpDevice in project onos by opennetworkinglab.

the class SnmpAlarmProvider method requestTraps.

private boolean requestTraps(DeviceId deviceId) {
    SnmpDevice device = controller.getDevice(deviceId);
    DeviceAlarmConfig alarmTranslator = getAlarmTranslator(device);
    if (alarmTranslator != null) {
        return alarmTranslator.configureDevice(localIp, device.getNotificationPort(), device.getNotificationProtocol());
    } else {
        log.warn("Device {} does not support alarms.", deviceId);
        return false;
    }
}
Also used : SnmpDevice(org.onosproject.snmp.SnmpDevice) DeviceAlarmConfig(org.onosproject.alarm.DeviceAlarmConfig)

Example 4 with SnmpDevice

use of org.onosproject.snmp.SnmpDevice in project onos by opennetworkinglab.

the class LumentumAlarmConsumer method consumeAlarms.

@Override
public List<Alarm> consumeAlarms() {
    SnmpController controller = checkNotNull(handler().get(SnmpController.class));
    List<Alarm> alarms = new ArrayList<>();
    DeviceId deviceId = handler().data().deviceId();
    SnmpDevice device = controller.getDevice(deviceId);
    try {
        snmp = new LumentumSnmpDevice(device.getSnmpHost(), device.getSnmpPort());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);
    }
    // Gets the alarm table and for each entry get the ID and create the proper alarm.
    snmp.get(ALARMS_TABLE_OID).forEach(alarm -> snmp.get(ALARMS_ID_OID).forEach(alarmIdEvent -> {
        int alarmId = getAlarmId(alarmIdEvent);
        alarms.add(new DefaultAlarm.Builder(AlarmId.alarmId(deviceId, String.valueOf(alarmId)), deviceId, getMessage(alarmId), getSeverity(alarmId), System.currentTimeMillis()).build());
    }));
    return ImmutableList.copyOf(alarms);
}
Also used : Logger(org.slf4j.Logger) TreeEvent(org.snmp4j.util.TreeEvent) Alarm(org.onosproject.alarm.Alarm) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SeverityLevel(org.onosproject.alarm.Alarm.SeverityLevel) AlarmId(org.onosproject.alarm.AlarmId) IOException(java.io.IOException) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) SnmpController(org.onosproject.snmp.SnmpController) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) SnmpDevice(org.onosproject.snmp.SnmpDevice) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) VariableBinding(org.snmp4j.smi.VariableBinding) AlarmConsumer(org.onosproject.alarm.AlarmConsumer) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DeviceId(org.onosproject.net.DeviceId) OID(org.snmp4j.smi.OID) SnmpDevice(org.onosproject.snmp.SnmpDevice) DeviceId(org.onosproject.net.DeviceId) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SnmpController(org.onosproject.snmp.SnmpController) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 5 with SnmpDevice

use of org.onosproject.snmp.SnmpDevice in project onos by opennetworkinglab.

the class PolatisSnmpUtility method getDevice.

private static SnmpDevice getDevice(DriverHandler handler) {
    SnmpController controller = checkNotNull(handler.get(SnmpController.class));
    SnmpDevice device = controller.getDevice(handler.data().deviceId());
    return device;
}
Also used : SnmpDevice(org.onosproject.snmp.SnmpDevice) SnmpController(org.onosproject.snmp.SnmpController)

Aggregations

SnmpDevice (org.onosproject.snmp.SnmpDevice)5 SnmpController (org.onosproject.snmp.SnmpController)2 ISnmpConfiguration (com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration)1 ISnmpSessionFactory (com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory)1 V2cSnmpConfiguration (com.btisystems.pronx.ems.core.snmp.V2cSnmpConfiguration)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Alarm (org.onosproject.alarm.Alarm)1 SeverityLevel (org.onosproject.alarm.Alarm.SeverityLevel)1 AlarmConsumer (org.onosproject.alarm.AlarmConsumer)1 AlarmId (org.onosproject.alarm.AlarmId)1 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)1 DeviceAlarmConfig (org.onosproject.alarm.DeviceAlarmConfig)1 DeviceId (org.onosproject.net.DeviceId)1 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)1 SnmpException (org.onosproject.snmp.SnmpException)1 Logger (org.slf4j.Logger)1