Search in sources :

Example 51 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class DomainIntentManager method initDomainIntentDriver.

private DomainIntentConfigurable initDomainIntentDriver(DeviceId deviceId) {
    // Attempt to lookup the handler in the cache
    DriverHandler handler = driverHandlers.get(deviceId);
    if (handler == null) {
        try {
            // Otherwise create it and if it has DomainIntentConfig behaviour, cache it
            handler = driverService.createHandler(deviceId);
            if (!handler.driver().hasBehaviour(DomainIntentConfigurable.class)) {
                log.warn("DomainIntentConfig behaviour not supported for device {}", deviceId);
                return null;
            }
        } catch (ItemNotFoundException e) {
            log.warn("No applicable driver for device {}", deviceId);
            return null;
        }
        driverHandlers.put(deviceId, handler);
    }
    // Always (re)initialize the pipeline behaviour
    log.info("Driver {} bound to device {} ... initializing driver", handler.driver().name(), deviceId);
    return handler.behaviour(DomainIntentConfigurable.class);
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) DomainIntentConfigurable(org.onosproject.net.behaviour.DomainIntentConfigurable) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 52 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class NetconfDeviceProvider method getDeviceDescription.

private DeviceDescription getDeviceDescription(DeviceId deviceId, NetconfDeviceConfig config) {
    Driver driver = driverService.getDriver(deviceId);
    if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
        final DriverData data = new DefaultDriverData(driver, deviceId);
        final DriverHandler handler = new DefaultDriverHandler(data);
        // creating the behaviour because the core has yet no notion of device.
        DeviceDescriptionDiscovery deviceDescriptionDiscovery = driver.createBehaviour(handler, DeviceDescriptionDiscovery.class);
        return getDeviceRepresentation(deviceId, config, deviceDescriptionDiscovery);
    } else {
        return existingOrEmptyDescription(deviceId, config);
    }
}
Also used : DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverData(org.onosproject.net.driver.DriverData) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 53 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OpenFlowPolicerConfigurable method allocatePolicerId.

@Override
public PolicerId allocatePolicerId() {
    // Init step
    DriverHandler handler = handler();
    // First step is to get MeterService
    MeterService meterService = handler.get(MeterService.class);
    // There was a problem, return none
    if (meterService == null) {
        log.warn("MeterService is null");
        return PolicerId.NONE;
    }
    // Let's get the device id
    DeviceId deviceId = handler.data().deviceId();
    // Double check correspondence between schemas
    if (!deviceId.uri().getScheme().equals(OF_SCHEME)) {
        log.warn("The device {} does not seem to be managed by OpenFlow", deviceId);
        return PolicerId.NONE;
    }
    // Get a new meter id
    MeterId meterId = meterService.allocateMeterId(deviceId);
    // There was a problem
    if (meterId == null) {
        log.warn("MeterService does not provide valid ids");
        return PolicerId.NONE;
    }
    // Create a policer id from the meter id
    return getPolicerIdFromMeterId(meterId);
}
Also used : DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MeterService(org.onosproject.net.meter.MeterService) MeterId(org.onosproject.net.meter.MeterId)

Example 54 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltAlarmConsumer method consumeAlarms.

@Override
public List<Alarm> consumeAlarms() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    dateFormat.setTimeZone(ZONE);
    List<Alarm> alarms = new ArrayList<>();
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_ALERTS)).append(buildEmptyTag(OLT_ACTIVE_ALERTS)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
        String reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), null);
        if (reply != null) {
            alarms = parseVoltActiveAlerts(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
        }
    } catch (NetconfException e) {
        log.error("Error reading alarms for device {} exception {}", ncDeviceId, e);
    }
    return ImmutableList.copyOf(alarms);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 55 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltAlertConfig method setAlertFilter.

@Override
public boolean setAlertFilter(String severity) {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return false;
    }
    if (!SEVERITYLEVELS.contains(severity)) {
        log.error("Invalid severity level: {}", severity);
        return false;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
        request.append(ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(VOLT_ALERTS)).append(buildStartTag(ALERT_FILTER, false)).append(severity).append(buildEndTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
        controller.getDevicesMap().get(ncDeviceId).getSession().editConfig(RUNNING, null, request.toString());
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
        return false;
    }
    return true;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

DriverHandler (org.onosproject.net.driver.DriverHandler)104 DeviceId (org.onosproject.net.DeviceId)46 DriverService (org.onosproject.net.driver.DriverService)22 NetconfController (org.onosproject.netconf.NetconfController)22 NetconfException (org.onosproject.netconf.NetconfException)22 MastershipService (org.onosproject.mastership.MastershipService)20 ArrayList (java.util.ArrayList)12 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)12 ItemNotFoundException (org.onlab.util.ItemNotFoundException)9 DeviceService (org.onosproject.net.device.DeviceService)9 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)9 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)8 Driver (org.onosproject.net.driver.Driver)8 Test (org.junit.Test)7 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)6 RestSBController (org.onosproject.protocol.rest.RestSBController)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PolicerConfigurable (org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable)5 PolicerId (org.onosproject.net.behaviour.trafficcontrol.PolicerId)5