Search in sources :

Example 41 with DriverHandler

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

the class RestDeviceProvider method getDesc.

private DeviceDescription getDesc(RestSBDevice restSBDev) {
    DeviceId deviceId = restSBDev.deviceId();
    Driver driver = getDriver(restSBDev);
    if (restSBDev.isProxy()) {
        if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
            // Creates the driver to communicate with the server
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            return devicesDiscovery.deviceDetails(deviceId);
        } else {
            log.warn("Driver not found for {}", restSBDev);
            return null;
        }
    } else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
        DriverHandler h = driverService.createHandler(deviceId);
        DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
        return deviceDiscovery.discoverDeviceDetails();
    }
    ChassisId cid = new ChassisId();
    String ipAddress = restSBDev.ip().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
    String manufacturer = UNKNOWN;
    String hwVersion = UNKNOWN;
    String swVersion = UNKNOWN;
    String serialNumber = UNKNOWN;
    Device device = deviceService.getDevice(deviceId);
    if (device != null) {
        manufacturer = device.manufacturer();
        hwVersion = device.hwVersion();
        swVersion = device.swVersion();
        serialNumber = device.serialNumber();
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DeviceId(org.onosproject.net.DeviceId) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DevicesDiscovery(org.onosproject.net.behaviour.DevicesDiscovery)

Example 42 with DriverHandler

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

the class RestDeviceProvider method deviceAdded.

private void deviceAdded(RestSBDevice restSBDev) {
    checkNotNull(restSBDev, DEVICENULL);
    Driver driver = getDriver(restSBDev);
    // Check if the server is controlling a single or multiple devices
    if (restSBDev.isProxy()) {
        if (driver.hasBehaviour(DevicesDiscovery.class)) {
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            Set<DeviceId> deviceIds = devicesDiscovery.deviceIds();
            restSBDev.setActive(true);
            deviceIds.forEach(deviceId -> {
                controller.addProxiedDevice(deviceId, restSBDev);
                DeviceDescription devDesc = devicesDiscovery.deviceDetails(deviceId);
                checkNotNull(devDesc, "DeviceDescription cannot be null");
                providerService.deviceConnected(deviceId, mergeAnn(restSBDev.deviceId(), devDesc));
                if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
                    DriverHandler h = driverService.createHandler(deviceId);
                    DeviceDescriptionDiscovery devDisc = h.behaviour(DeviceDescriptionDiscovery.class);
                    providerService.updatePorts(deviceId, devDisc.discoverPortDetails());
                }
                checkAndUpdateDevice(deviceId);
            });
        } else {
            log.warn("Device is proxy but driver does not have proxy discovery behaviour {}", restSBDev);
        }
    } else {
        DeviceId deviceId = restSBDev.deviceId();
        if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
            restSBDev.setActive(true);
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            DeviceDescription deviceDescription = devicesDiscovery.deviceDetails(deviceId);
            checkNotNull(deviceDescription, "DeviceDescription cannot be null");
            providerService.deviceConnected(deviceId, deviceDescription);
            if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
                DriverHandler h = driverService.createHandler(deviceId);
                DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
                providerService.updatePorts(deviceId, deviceDiscovery.discoverPortDetails());
            }
        } else {
            DeviceDescription deviceDescription = getDesc(restSBDev);
            restSBDev.setActive(true);
            providerService.deviceConnected(deviceId, deviceDescription);
        }
        checkAndUpdateDevice(deviceId);
    }
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DeviceId(org.onosproject.net.DeviceId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DevicesDiscovery(org.onosproject.net.behaviour.DevicesDiscovery)

Example 43 with DriverHandler

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

the class NetconfControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId deviceId = handler.data().deviceId();
    Preconditions.checkNotNull(controller, "Netconf controller is null");
    List<ControllerInfo> controllers = new ArrayList<>();
    if (mastershipService.isLocalMaster(deviceId)) {
        try {
            String reply = controller.getNetconfDevice(deviceId).getSession().getConfig(DatastoreId.RUNNING);
            log.debug("Reply XML {}", reply);
            controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
        } catch (NetconfException e) {
            log.error("Cannot communicate with device {} ", deviceId, e);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
    }
    return controllers;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 44 with DriverHandler

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

the class NetconfControllerConfig method setControllers.

@Override
public void setControllers(List<ControllerInfo> controllers) {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    DeviceId deviceId = handler.data().deviceId();
    Preconditions.checkNotNull(controller, "Netconf controller is null");
    MastershipService mastershipService = handler.get(MastershipService.class);
    if (mastershipService.isLocalMaster(deviceId)) {
        try {
            NetconfDevice device = controller.getNetconfDevice(deviceId);
            String config = null;
            try {
                String reply = device.getSession().getConfig(DatastoreId.RUNNING);
                log.info("reply XML {}", reply);
                config = XmlConfigParser.createControllersConfig(XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")), XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))), "running", "merge", "create", controllers);
            } catch (NetconfException e) {
                log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
                return;
            }
            device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
        } catch (NullPointerException e) {
            log.warn("No NETCONF device with requested parameters " + e);
            throw new NullPointerException("No NETCONF device with requested parameters " + e);
        } catch (NetconfException e) {
            log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 45 with DriverHandler

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

the class ResourceDeviceListener method queryMplsLabels.

private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) {
    try {
        DriverHandler handler = driverService.createHandler(device);
        if (handler == null || !handler.hasBehaviour(MplsQuery.class)) {
            return ImmutableSet.of();
        }
        MplsQuery query = handler.behaviour(MplsQuery.class);
        if (query == null) {
            return ImmutableSet.of();
        }
        return query.queryMplsLabels(port);
    } catch (ItemNotFoundException e) {
        return ImmutableSet.of();
    }
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) MplsQuery(org.onosproject.net.behaviour.MplsQuery) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

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