Search in sources :

Example 1 with VlanQuery

use of org.onosproject.net.behaviour.VlanQuery in project onos by opennetworkinglab.

the class PortQueryVlansCommand method printVlans.

private void printVlans(Port port) {
    DeviceService deviceService = get(DeviceService.class);
    DriverService driverService = get(DriverService.class);
    DeviceId deviceId = (DeviceId) port.element().id();
    Device device = deviceService.getDevice(deviceId);
    if (!device.is(VlanQuery.class)) {
        // The relevant behavior is not supported by the device.
        print(NO_SUPPORT);
        return;
    }
    DriverHandler h = driverService.createHandler(deviceId);
    VlanQuery vlanQuery = h.behaviour(VlanQuery.class);
    try {
        Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number());
        if (vlanIds.isEmpty()) {
            print(VLAN_NOT_AVAILABLE);
        } else {
            print(AVAIL_VLANS, getRanges(vlanIds).toString());
        }
    } catch (Exception e) {
        print(FAILURE + e.getMessage());
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) DriverHandler(org.onosproject.net.driver.DriverHandler) VlanQuery(org.onosproject.net.behaviour.VlanQuery) VlanId(org.onlab.packet.VlanId) DriverService(org.onosproject.net.driver.DriverService)

Example 2 with VlanQuery

use of org.onosproject.net.behaviour.VlanQuery in project onos by opennetworkinglab.

the class ResourceDeviceListener method queryVlanIds.

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

Aggregations

VlanQuery (org.onosproject.net.behaviour.VlanQuery)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 VlanId (org.onlab.packet.VlanId)1 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 Device (org.onosproject.net.Device)1 DeviceId (org.onosproject.net.DeviceId)1 DeviceService (org.onosproject.net.device.DeviceService)1 DriverService (org.onosproject.net.driver.DriverService)1