Java Code Examples for org.onosproject.net.Device#is()

The following examples show how to use org.onosproject.net.Device#is() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenstackNodeUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Adds or removes a network interface (aka port) into a given bridge of openstack node.
 *
 * @param osNode openstack node
 * @param bridgeName bridge name
 * @param intfName interface name
 * @param deviceService device service
 * @param addOrRemove add port is true, remove it otherwise
 */
public static synchronized void addOrRemoveSystemInterface(OpenstackNode osNode,
                                                           String bridgeName,
                                                           String intfName,
                                                           DeviceService deviceService,
                                                           boolean addOrRemove) {


    Device device = deviceService.getDevice(osNode.ovsdb());
    if (device == null || !device.is(BridgeConfig.class)) {
        log.info("device is null or this device if not ovsdb device");
        return;
    }
    BridgeConfig bridgeConfig =  device.as(BridgeConfig.class);

    if (addOrRemove) {
        bridgeConfig.addPort(BridgeName.bridgeName(bridgeName), intfName);
    } else {
        bridgeConfig.deletePort(BridgeName.bridgeName(bridgeName), intfName);
    }
}
 
Example 2
Source File: DefaultK8sNodeHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a tunnel interface in a given kubernetes node.
 *
 * @param k8sNode       kubernetes node
 */
private void createTunnelInterface(K8sNode k8sNode,
                                   String type, String intfName) {
    if (isIntfEnabled(k8sNode, intfName)) {
        return;
    }

    Device device = deviceService.getDevice(k8sNode.ovsdb());
    if (device == null || !device.is(InterfaceConfig.class)) {
        log.error("Failed to create tunnel interface on {}", k8sNode.ovsdb());
        return;
    }

    TunnelDescription tunnelDesc = buildTunnelDesc(type, intfName);

    InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class);
    ifaceConfig.addTunnelMode(intfName, tunnelDesc);
}
 
Example 3
Source File: DefaultOpenstackNodeHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a tunnel interface in a given openstack node.
 *
 * @param osNode openstack node
 */
private void createTunnelInterface(OpenstackNode osNode,
                                   String type, String intfName) {
    if (isIntfEnabled(osNode, intfName)) {
        return;
    }

    Device device = deviceService.getDevice(osNode.ovsdb());
    if (device == null || !device.is(InterfaceConfig.class)) {
        log.error("Failed to create tunnel interface on {}", osNode.ovsdb());
        return;
    }

    TunnelDescription tunnelDesc = buildTunnelDesc(type, intfName);

    InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class);
    ifaceConfig.addTunnelMode(intfName, tunnelDesc);
}
 
Example 4
Source File: OpenstackVtapManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private ExtensionTreatment buildResubmitExtension(DeviceId deviceId, int tableId) {
    Device device = deviceService.getDevice(deviceId);
    if (device == null || !device.is(ExtensionTreatmentResolver.class)) {
        log.warn("Nicira extension treatment is not supported");
        return null;
    }

    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment =
            resolver.getExtensionInstruction(NICIRA_RESUBMIT_TABLE.type());

    try {
        treatment.setPropertyValue(TABLE_EXTENSION, ((short) tableId));
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.error("Failed to set nicira resubmit extension treatment for {}", deviceId);
        return null;
    }
}
 
Example 5
Source File: RulePopulatorUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
private static boolean checkTreatmentResolver(Device device) {
    if (device == null || !device.is(ExtensionTreatmentResolver.class)) {
        log.warn("Nicira extension treatment is not supported");
        return false;
    }

    return true;
}
 
Example 6
Source File: FlowRuleDriverProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private FlowRuleProgrammable getFlowRuleProgrammable(DeviceId deviceId) {
    Device device = deviceService.getDevice(deviceId);
    if (device.is(FlowRuleProgrammable.class)) {
        return device.as(FlowRuleProgrammable.class);
    } else {
        log.debug("Device {} is not flow rule programmable", deviceId);
        return null;
    }
}
 
Example 7
Source File: RoadmPortViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private String getPostFecBer(DeviceId deviceId, PortNumber portNumber) {
    Device device = deviceService.getDevice(deviceId);
    if (device == null || !device.is(BitErrorRateState.class)) {
        return RoadmUtil.UNKNOWN;
    }
    BitErrorRateState bitErrorRateState = device.as(BitErrorRateState.class);
    Optional<Double> postFecBer = bitErrorRateState.getPostFecBer(deviceId, portNumber);
    Double postFecBerVal = null;
    if (postFecBer.isPresent()) {
        postFecBerVal = postFecBer.orElse(Double.MIN_VALUE);
    }
    return RoadmUtil.objectToString(postFecBerVal, RoadmUtil.UNKNOWN);
}
 
Example 8
Source File: RestDeviceProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void updatePortStatistics(DeviceId deviceId) {
    Device device = deviceService.getDevice(deviceId);
    checkNotNull(device, "device cannot be null");

    if (device.is(PortStatisticsDiscovery.class)) {
        PortStatisticsDiscovery portStatisticsDiscovery = device.as(PortStatisticsDiscovery.class);
        Collection<PortStatistics> portStatistics = portStatisticsDiscovery.discoverPortStatistics();
        if (portStatistics != null && !portStatistics.isEmpty()) {
            providerService.updatePortStatistics(deviceId, portStatistics);
        }
    } else {
        log.debug("No port statistics getter behaviour for device {}", deviceId);
    }
}
 
Example 9
Source File: RestDeviceProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void checkAndUpdateDevice(DeviceId deviceId) {
    if (deviceService.getDevice(deviceId) == null) {
        log.warn("Device {} has not been added to store, maybe due to a problem in connectivity", deviceId);
    } else {
        boolean isReachable = isReachable(deviceId);
        if (isReachable && deviceService.isAvailable(deviceId)) {
            Device device = deviceService.getDevice(deviceId);
            if (device.is(DeviceDescriptionDiscovery.class)) {
                DeviceDescriptionDiscovery deviceDescriptionDiscovery =
                        device.as(DeviceDescriptionDiscovery.class);
                DeviceDescription updatedDeviceDescription =
                        deviceDescriptionDiscovery.discoverDeviceDetails();
                if (updatedDeviceDescription != null &&
                        !descriptionEquals(device, updatedDeviceDescription)) {
                    providerService.deviceConnected(
                            deviceId,
                            new DefaultDeviceDescription(
                                    updatedDeviceDescription, true,
                                    updatedDeviceDescription.annotations()));
                }
                //if ports are not discovered, retry the discovery
                if (deviceService.getPorts(deviceId).isEmpty()) {
                    discoverPorts(deviceId);
                }
            } else {
                log.warn("No DeviceDescriptionDiscovery behaviour for device {}", deviceId);
            }
        } else if (!isReachable && deviceService.isAvailable(deviceId)) {
            providerService.deviceDisconnected(deviceId);
        }
    }
}
 
Example 10
Source File: LinkDiscoveryProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
protected boolean isSupported(Device device) {
    boolean supported = mastershipService.isLocalMaster(device.id())
            && device.is(LinkDiscovery.class);
    if (!supported) {
        log.debug("Device {} does not support LinkDiscovery", device);
    }
    return supported;
}
 
Example 11
Source File: PiPipeconfWatchdogManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isLocalMaster(Device device) {
    if (mastershipService.isLocalMaster(device.id())) {
        return true;
    }
    // The device might have no master (e.g. after it has been disconnected
    // from core), hence we use device mastership state.
    final MastershipInfo info = mastershipService.getMastershipFor(device.id());
    return !info.master().isPresent() &&
            device.is(DeviceHandshaker.class) &&
            device.as(DeviceHandshaker.class).getRole()
                    .equals(MastershipRole.MASTER);
}
 
Example 12
Source File: PowerConfigWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
private PowerConfig<Object> getPowerConfig(String id) {
    Device device = get(DeviceService.class).getDevice(deviceId(id));
    if (device == null) {
        throw new IllegalArgumentException(DEVICE_NOT_FOUND);
    }
    if (device.is(PowerConfig.class)) {
        return device.as(PowerConfig.class);
    }
    return null;
}
 
Example 13
Source File: StatsPoller.java    From onos with Apache License 2.0 5 votes vote down vote up
private void updatePortStatistics(DeviceId deviceId) {
    final Device device = deviceService.getDevice(deviceId);
    if (!device.is(PortStatisticsDiscovery.class)) {
        log.error("Missing PortStatisticsDiscovery behaviour for {}", deviceId);
    }
    final Collection<PortStatistics> statistics = device.as(
            PortStatisticsDiscovery.class).discoverPortStatistics();
    if (!statistics.isEmpty()) {
        providerService.updatePortStatistics(deviceId, statistics);
    }
}
 
Example 14
Source File: RoadmManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private ProtectionConfigBehaviour getProtectionConfig(DeviceId deviceId) {
    Device device = deviceService.getDevice(deviceId);
    if (device != null && device.is(ProtectionConfigBehaviour.class)) {
        return device.as(ProtectionConfigBehaviour.class);
    }
    // Do not need warning here for port polling.
    log.debug("Unable to load ProtectionConfigBehaviour for {}", deviceId);
    return null;
}
 
Example 15
Source File: OpenstackVtapManager.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Creates/Removes a tunnel interface in a given openstack node by vtap network information.
 *
 * @param osNode openstack node
 * @param vtapNetwork openstack vtap network for making
 *
 */
private boolean setTunnelInterface(OpenstackNode osNode,
                                   OpenstackVtapNetwork vtapNetwork,
                                   boolean install) {
    String tunnelName = getTunnelName(vtapNetwork.mode());
    if (tunnelName == null) {
        return false;
    }

    if (!deviceService.isAvailable(osNode.ovsdb())) {
        log.warn("Not available osNode {} ovs {}", osNode.hostname(), osNode.ovsdb());
        return false;
    }

    if (install == isInterfaceEnabled(osNode.intgBridge(), tunnelName)) {
        log.warn("Already {} {} interface on osNode ovs {}, bridge {}",
                install ? "add" : "remove",
                tunnelName, osNode.ovsdb(), osNode.intgBridge());
        return true;
    }

    Device device = deviceService.getDevice(osNode.ovsdb());
    if (device == null || !device.is(InterfaceConfig.class)) {
        log.warn("Not able to get InterfaceConfig on osNode ovs {}", osNode.ovsdb());
        return false;
    }

    InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class);
    if (install) {
        TunnelDescription.Builder tunnelDesc = DefaultTunnelDescription.builder()
                .deviceId(INTEGRATION_BRIDGE)
                .ifaceName(tunnelName)
                .type(getTunnelType(vtapNetwork.mode()))
                .key((vtapNetwork.networkId() == 0) ? null : new TunnelKey<>(vtapNetwork.networkId()))
                .remote(TunnelEndPoints.ipTunnelEndpoint(vtapNetwork.serverIp()));
        if (!ifaceConfig.addTunnelMode(tunnelName, tunnelDesc.build())) {
            log.error("Fail to create {} interface on osNode ovs {}", tunnelName, osNode.ovsdb());
            return false;
        }
    } else {
        if (!ifaceConfig.removeTunnelMode(tunnelName)) {
            log.error("Fail to remove {} interface on osNode ovs {}", tunnelName, osNode.ovsdb());
            return false;
        }
    }

    // Wait for tunnel interface create/remove complete
    synchronized (syncInterface) {
        for (int i = 0; i < INTERFACE_MANIPULATION_RETRY; i++) {
            try {
                syncInterface.wait(INTERFACE_MANIPULATION_TIMEOUT);
                if (install == isInterfaceEnabled(osNode.intgBridge(), tunnelName)) {
                    log.debug("Success to {} {} interface on osNode ovs {}, bridge {}",
                            install ? "add" : "remove",
                            tunnelName, osNode.ovsdb(), osNode.intgBridge());
                    return true;
                }
            } catch (InterruptedException e) {
                break;
            }
        }
    }
    log.warn("Fail to {} {} interface on osNode ovs {}, bridge {}",
            install ? "add" : "remove",
            tunnelName, osNode.ovsdb(), osNode.intgBridge());
    return false;
}
 
Example 16
Source File: DefaultOpenstackNodeHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void createPhysicalPatchPorts(OpenstackNode osNode,
                                      OpenstackPhyInterface phyInterface) {
    Device device = deviceService.getDevice(osNode.ovsdb());

    if (device == null || !device.is(InterfaceConfig.class)) {
        log.error("Failed to create patch interface on {}", osNode.ovsdb());
        return;
    }

    String physicalDeviceId = BRIDGE_PREFIX + phyInterface.network();

    String intToPhyPatchPort = structurePortName(
            INTEGRATION_TO_PHYSICAL_PREFIX + phyInterface.network());
    String phyToIntPatchPort = structurePortName(
            phyInterface.network() + PHYSICAL_TO_INTEGRATION_SUFFIX);

    // integration bridge -> physical bridge
    PatchDescription intToPhyPatchDesc =
            DefaultPatchDescription.builder()
                    .deviceId(INTEGRATION_BRIDGE)
                    .ifaceName(intToPhyPatchPort)
                    .peer(phyToIntPatchPort)
                    .build();

    // physical bridge -> integration bridge
    PatchDescription phyToIntPatchDesc =
            DefaultPatchDescription.builder()
                    .deviceId(physicalDeviceId)
                    .ifaceName(phyToIntPatchPort)
                    .peer(intToPhyPatchPort)
                    .build();

    InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class);
    ifaceConfig.addPatchMode(INTEGRATION_TO_PHYSICAL_PREFIX +
            phyInterface.network(), intToPhyPatchDesc);
    ifaceConfig.addPatchMode(phyInterface.network() +
            PHYSICAL_TO_INTEGRATION_SUFFIX, phyToIntPatchDesc);

    addOrRemoveSystemInterface(osNode, physicalDeviceId,
            phyInterface.intf(), deviceService, true);
}
 
Example 17
Source File: GnpyManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private void setPathPower(Intent intent) {
    GnpyPowerInfo powerInfo = intentsPowerMap.get(intent.id());
    for (Link link : powerInfo.path()) {
        Device ingressDev = deviceService.getDevice(link.src().deviceId());
        if (ingressDev.is(PowerConfig.class)) {
            if (powerInfo.deviceAtoBPowerMap().get(link.src().deviceId()) != -99) {
                log.info("Configuring power {} for {}",
                         powerInfo.deviceAtoBPowerMap().get(link.src().deviceId()),
                         link.src().deviceId());
                ingressDev.as(PowerConfig.class)
                        .setTargetPower(link.src().port(), powerInfo.ochSignal(),
                                        powerInfo.deviceAtoBPowerMap()
                                                .get(link.src().deviceId()));
            } else {
                log.warn("Can't determine power for {}", link.src().deviceId());
            }
        }
        Device egressDev = deviceService.getDevice(link.dst().deviceId());
        if (egressDev.is(PowerConfig.class)) {
            if (powerInfo.deviceBtoAPowerMap().get(link.dst().deviceId()) != -99) {
                log.info("Configuring power {} for {}",
                         powerInfo.deviceBtoAPowerMap().get(link.dst().deviceId()),
                         link.dst().deviceId());
                egressDev.as(PowerConfig.class)
                        .setTargetPower(link.dst().port(), powerInfo.ochSignal(),
                                        powerInfo.deviceBtoAPowerMap()
                                                .get(link.dst().deviceId()));
            } else {
                log.warn("Can't determine power for {}", link.dst().deviceId());
            }
        }
    }
    Device ingressDevice = deviceService.getDevice(powerInfo.ingress().deviceId());
    if (ingressDevice.is(PowerConfig.class)) {
        if (powerInfo.launchPower() != -99) {
            log.info("Configuring ingress with power {} for {}",
                     powerInfo.launchPower(), ingressDevice);
            ingressDevice.as(PowerConfig.class)
                    .setTargetPower(powerInfo.ingress().port(), Direction.ALL, powerInfo.launchPower());
        }
    }
    Device egressDevice = deviceService.getDevice(powerInfo.ingress().deviceId());
    if (egressDevice.is(PowerConfig.class)) {
        if (powerInfo.launchPower() != -99) {
            log.info("Configuring egress with power {} for {}",
                     powerInfo.launchPower(), ingressDevice);
            ingressDevice.as(PowerConfig.class)
                    .setTargetPower(powerInfo.ingress().port(), Direction.ALL, powerInfo.launchPower());
        }
    }
}
 
Example 18
Source File: CfmMepManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId,
                         Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
    MepKeyId key = new MepKeyId(mdName, maName, mepId);

    //Will throw IllegalArgumentException if ma does not exist
    cfmMdService.getMaintenanceAssociation(mdName, maName);

    //Get the device ID from the MEP
    Optional<Mep> deletedMep = mepStore.getMep(key);
    if (!deletedMep.isPresent()) {
        log.warn("MEP {} not found when deleting Mep", key);
        return false;
    }

    DeviceId mepDeviceId = deletedMep.get().deviceId();
    boolean deleted = mepStore.deleteMep(key);

    Device mepDevice = deviceService.getDevice(mepDeviceId);
    if (mepDevice == null || !mepDevice.is(CfmMepProgrammable.class)) {
        throw new CfmConfigException("Unexpeced fault on device driver for "
                + mepDeviceId);
    }
    try {
        deleted = mepDevice.as(CfmMepProgrammable.class)
                .deleteMep(mdName, maName, mepId, oldMd);
    } catch (CfmConfigException e) {
        log.warn("MEP could not be deleted on device - perhaps it "
                + "does not exist. Continuing");
    }

    //Iterate through all other devices and remove as a Remote Mep
    int mepsOnMdCount = 0;
    int mepsOnMaCount = 0;
    List<DeviceId> alreadyHandledDevices = new ArrayList<>();
    for (Mep mep : mepStore.getAllMeps()) {
        if (mep.deviceId().equals(mepDeviceId) && mdName.equals(mep.mdId())) {
            mepsOnMdCount++;
            if (maName.equals(mep.maId())) {
                mepsOnMaCount++;
            }
        }
        if (mep.deviceId().equals(mepDeviceId) || !mep.mdId().equals(mdName) ||
                !mep.maId().equals(maName) ||
                alreadyHandledDevices.contains(mep.deviceId())) {
            continue;
        }
        deviceService.getDevice(mep.deviceId())
                .as(CfmMepProgrammable.class)
                .deleteMaRemoteMepOnDevice(mdName, maName, mepId);
        alreadyHandledDevices.add(mep.deviceId());
        log.info("Deleted RMep entry on {} on device {}",
                mdName.mdName() + "/" + maName.maName(), mep.deviceId());
    }

    //Also if this is the last MEP in this MA then delete this MA from device
    //If this is the last MA in this MD on device, then delete the MD from the device
    if (mepsOnMdCount == 0) {
        boolean deletedMd = deviceService.getDevice(mepDeviceId)
                .as(CfmMepProgrammable.class).deleteMdOnDevice(mdName, oldMd);
        log.info("Deleted MD {} from Device {}", mdName.mdName(), mepDeviceId);
    } else if (mepsOnMaCount == 0) {
        boolean deletedMa = deviceService.getDevice(mepDeviceId)
                .as(CfmMepProgrammable.class).deleteMaOnDevice(mdName, maName, oldMd);
        log.info("Deleted MA {} from Device {}",
                mdName.mdName() + "/" + maName.maName(), mepDeviceId);
    }

    return deleted;
}
 
Example 19
Source File: SimpleIntManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private boolean isIntProgrammable(DeviceId deviceId) {
    final Device device = deviceService.getDevice(deviceId);
    return device != null && device.is(IntProgrammable.class);
}
 
Example 20
Source File: FlowRuleDriverProvider.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRelevant(DeviceEvent event) {
    Device device = event.subject();
    return POSITIVE_DEVICE_EVENT.contains(event.type()) &&
           device.is(FlowRuleProgrammable.class);
}