Java Code Examples for org.onosproject.net.device.DeviceService#isAvailable()

The following examples show how to use org.onosproject.net.device.DeviceService#isAvailable() . 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: DeviceViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void populateRow(TableModel.Row row, Device dev,
                         DeviceService ds, MastershipService ms) {
    DeviceId id = dev.id();
    boolean available = ds.isAvailable(id);
    String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;

    row.cell(ID, id)
        .cell(NAME, deviceName(dev))
        .cell(AVAILABLE, available)
        .cell(AVAILABLE_IID, iconId)
        .cell(TYPE_IID, getTypeIconId(dev))
        .cell(MFR, dev.manufacturer())
        .cell(HW, dev.hwVersion())
        .cell(SW, dev.swVersion())
        .cell(PROTOCOL, deviceProtocol(dev))
        .cell(NUM_PORTS, ds.getPorts(id).size())
        .cell(MASTER_ID, ms.getMasterFor(id));
}
 
Example 2
Source File: OplinkHandshakerUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
private boolean linkValidation(DeviceService deviceService, OplinkPortAdjacency neighbor) {
    // check neighbor object
    if (neighbor == null) {
        return false;
    }
    // check src device is validate or not
    if (!deviceService.isAvailable(neighbor.getDeviceId())) {
        log.debug("Invalid adjacency device. devId = {}", neighbor.getDeviceId());
        return false;
    }
    // check src port is validate or not
    if (deviceService.getPort(neighbor.getDeviceId(), neighbor.getPort()) == null) {
        log.debug("Invalid adjacency port. devId = {}, port = {}",
                  neighbor.getDeviceId(), neighbor.getPort());
        return false;
    }
    // validate link
    return true;
}
 
Example 3
Source File: Ovs.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code true} if this bridge is available;
 * returns {@code false} otherwise.
 *
 * @param context workflow context
 * @param devId   device id
 * @return {@code true} if this bridge is available; {@code false} otherwise.
 * @throws WorkflowException workflow exception
 */
public static final boolean isAvailableBridge(WorkflowContext context, DeviceId devId)
        throws WorkflowException {

    if (Objects.isNull(devId)) {
        throw new WorkflowException("Invalid device id in data model");
    }

    DeviceService deviceService = context.getService(DeviceService.class);
    Device dev = deviceService.getDevice(devId);
    if (Objects.isNull(dev)) {
        return false;
    }

    return deviceService.isAvailable(devId);
}
 
Example 4
Source File: VirtualNetworkDeviceManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the isAvailable method using a null device identifier.
 */
@Test(expected = NullPointerException.class)
public void testIsAvailableByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);

    // test the isAvailable() method with null device id value.
    deviceService.isAvailable(null);
}
 
Example 5
Source File: PipeconfViewMessageHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    PiPipeconfService piPipeconfService = get(PiPipeconfService.class);
    DeviceService deviceService = get(DeviceService.class);
    ObjectNode responseData = objectNode();
    String devId = string(payload, DEVICE_ID);
    if (devId == null || devId.isEmpty()) {
        log.warn("{}: Invalid device id", PIPECONF_REQUEST);
        sendMessage(NO_PIPECONF_RESP, null);
        return;
    }
    DeviceId deviceId = DeviceId.deviceId(devId);
    Optional<PiPipeconfId> pipeconfId = piPipeconfService.ofDevice(deviceId);
    if (!pipeconfId.isPresent()) {
        log.warn("{}: Can't find pipeconf id for device {}", PIPECONF_REQUEST, deviceId);
        sendMessage(NO_PIPECONF_RESP, null);
        return;
    }

    Optional<PiPipeconf> pipeconf = piPipeconfService.getPipeconf(pipeconfId.get());
    if (!pipeconf.isPresent()) {
        log.warn("{}: Can't find pipeconf {}", PIPECONF_REQUEST, pipeconfId);
        sendMessage(NO_PIPECONF_RESP, null);
        return;
    }
    CodecContext codecContext = getJsonCodecContext();

    ObjectNode pipeconfData = codecContext.encode(pipeconf.get(), PiPipeconf.class);
    responseData.set(PIPECONF, pipeconfData);

    // Filtered out models not exists in interpreter
    // usually they generated by compiler automatically
    Device device = deviceService.getDevice(deviceId);
    if (device == null || !deviceService.isAvailable(deviceId)) {
        log.warn("{}: Device {} is not available", PIPECONF_REQUEST, deviceId);
        sendMessage(NO_PIPECONF_RESP, null);
        return;
    }
    PiPipelineModel pipelineModel = pipeconf.get().pipelineModel();

    ObjectNode pipelineModelData =
            codecContext.encode(pipelineModel, PiPipelineModel.class);
    responseData.set(PIPELINE_MODEL, pipelineModelData);

    sendMessage(PIPECONF_RESP, responseData);
}
 
Example 6
Source File: K8sNodeUtil.java    From onos with Apache License 2.0 3 votes vote down vote up
/**
 * Checks whether the controller has a connection with an OVSDB that resides
 * inside the given kubernetes node.
 *
 * @param node              kubernetes node
 * @param ovsdbPort         OVSDB port
 * @param ovsdbController   OVSDB controller
 * @param deviceService     device service
 * @return true if the controller is connected to the OVSDB, false otherwise
 */
public static boolean isOvsdbConnected(K8sNode node,
                                       int ovsdbPort,
                                       OvsdbController ovsdbController,
                                       DeviceService deviceService) {
    OvsdbClientService client = getOvsdbClient(node, ovsdbPort, ovsdbController);
    return deviceService.isAvailable(node.ovsdb()) &&
            client != null &&
            client.isConnected();
}
 
Example 7
Source File: OpenstackNodeUtil.java    From onos with Apache License 2.0 3 votes vote down vote up
/**
 * Checks whether the controller has a connection with an OVSDB that resides
 * inside the given openstack node.
 *
 * @param osNode openstack node
 * @param ovsdbPort ovsdb port
 * @param ovsdbController ovsdb controller
 * @param deviceService device service
 * @return true if the controller is connected to the OVSDB, false otherwise
 */
public static boolean isOvsdbConnected(OpenstackNode osNode,
                                       int ovsdbPort,
                                       OvsdbController ovsdbController,
                                       DeviceService deviceService) {
    OvsdbClientService client = getOvsdbClient(osNode, ovsdbPort, ovsdbController);
    return deviceService.isAvailable(osNode.ovsdb()) &&
            client != null &&
            client.isConnected();
}