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

The following examples show how to use org.onosproject.net.Device#annotations() . 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: TopologyViewMessageHandlerBase.java    From onos with Apache License 2.0 6 votes vote down vote up
protected PropertyPanel deviceDetails(DeviceId deviceId) {
    log.debug("generate prop panel data for device {}", deviceId);
    Device device = services.device().getDevice(deviceId);
    Annotations annot = device.annotations();
    String proto = annot.value(AnnotationKeys.PROTOCOL);
    String title = friendlyDevice(deviceId);
    LionBundle lion = getLionBundle(LION_TOPO);

    PropertyPanel pp = new PropertyPanel(title, lookupGlyph(device))
            .navPath(DEVICE_NAV_PATH)
            .id(deviceId.toString());
    addDeviceBasicProps(pp, deviceId, device, proto, lion);
    addLocationProps(pp, annot, lion);
    addDeviceCountStats(pp, deviceId, lion);
    addDeviceCoreButtons(pp);
    return pp;
}
 
Example 2
Source File: PceccSrTeBeHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve lsr-id from device annotation.
 *
 * @param deviceId specific device id from which lsr-id needs to be retrieved
 * @return lsr-id of a device
 */
public String getLsrId(DeviceId deviceId) {
    checkNotNull(deviceId, DEVICE_ID_NULL);
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        log.debug("Device is not available for device id {} in device service.", deviceId.toString());
        return null;
    }

    // Retrieve lsr-id from device
    if (device.annotations() == null) {
        log.debug("Device {} does not have annotation.", device.toString());
        return null;
    }

    String lsrId = device.annotations().value(LSR_ID);
    if (lsrId == null) {
        log.debug("The lsr-id of device {} is null.", device.toString());
        return null;
    }
    return lsrId;
}
 
Example 3
Source File: CiscoNxosDeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public DeviceDescription discoverDeviceDetails() {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();

    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(SHOW_VERSION_CMD);

    String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);

    String response = NxApiRequest.post(controller, deviceId, req);

    String mrf = UNKNOWN;
    String hwVer = UNKNOWN;
    String swVer = UNKNOWN;
    String serialNum = UNKNOWN;

    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);

        JsonNode body = json.findValue("body");
        if (body != null) {
            mrf = body.get(MANUFACTURER).asText();
            hwVer = body.get(CHASSIS_ID).asText();
            swVer = body.get(KICKSTART_VER).asText();
        }
    } catch (IOException e) {
        log.error("Failed to to retrieve Device Information {}", e);
    }

    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceId);
    return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH,
            mrf, hwVer, swVer, serialNum,
            new ChassisId(), (SparseAnnotations) device.annotations());
}
 
Example 4
Source File: DeviceDescriptionDiscoveryAristaImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public DeviceDescription discoverDeviceDetails() {
    try {
        Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_VERSION);

        if (!result.isPresent()) {
            return null;
        }

        JsonNode jsonNode = result.get().get(AristaUtils.RESULT_START_INDEX);
        String hwVer = jsonNode.get(MODEL_NAME).asText(UNKNOWN);
        String swVer = jsonNode.get(SW_VERSION).asText(UNKNOWN);
        String serialNum = jsonNode.get(SERIAL_NUMBER).asText(UNKNOWN);
        String systemMacAddress = jsonNode.get(SYSTEM_MAC_ADDRESS).asText("").replace(":", "");
        DeviceId deviceId = checkNotNull(handler().data().deviceId());
        DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
        Device device = deviceService.getDevice(deviceId);
        ChassisId chassisId = systemMacAddress.isEmpty() ? new ChassisId() : new ChassisId(systemMacAddress);

        log.debug("systemMacAddress: {}", systemMacAddress);

        SparseAnnotations annotations = device == null ?
                DefaultAnnotations.builder().build() : (SparseAnnotations) device.annotations();

        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH,
                MANUFACTURER, hwVer, swVer, serialNum, chassisId, annotations);
    } catch (Exception e) {
        log.error("Exception occurred because of {}, trace: {}", e, e.getStackTrace());
        return null;
    }
}
 
Example 5
Source File: LumentumRoadmDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public DeviceDescription discoverDeviceDetails() {
    //TODO get device description
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = handler().data().deviceId();
    Device device = deviceService.getDevice(deviceId);
    return new DefaultDeviceDescription(device.id().uri(), Device.Type.ROADM,
                                        "Lumentum", "SDN ROADM", "1.0", "v1",
                                        device.chassisId(), (SparseAnnotations) device.annotations());
}
 
Example 6
Source File: PcepClientControllerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates node label to specific device.
 *
 * @param specificDevice device to which node label needs to be allocated
 */
public void allocateNodeLabel(Device specificDevice) {
    checkNotNull(specificDevice, DEVICE_NULL);

    DeviceId deviceId = specificDevice.id();

    // Retrieve lsrId of a specific device
    if (specificDevice.annotations() == null) {
        log.debug("Device {} does not have annotations.", specificDevice.toString());
        return;
    }

    String lsrId = specificDevice.annotations().value(LSRID);
    if (lsrId == null) {
        log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
        return;
    }

    // Get capability config from netconfig
    DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
    if (cfg == null) {
        log.error("Unable to find corresponding capability for a lsrd {} from NetConfig.", lsrId);
        // Save info. When PCEP session is comes up then allocate node-label
        lsrIdDeviceIdMap.put(lsrId, specificDevice.id());
        return;
    }

    // Check whether device has SR-TE Capability
    if (cfg.labelStackCap()) {
        srTeHandler.allocateNodeLabel(deviceId, lsrId);
    }
}
 
Example 7
Source File: PcepClientControllerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Releases node label of a specific device.
 *
 * @param specificDevice this device label and lsr-id information will be
 *            released in other existing devices
 */
public void releaseNodeLabel(Device specificDevice) {
    checkNotNull(specificDevice, DEVICE_NULL);

    DeviceId deviceId = specificDevice.id();

    // Retrieve lsrId of a specific device
    if (specificDevice.annotations() == null) {
        log.debug("Device {} does not have annotations.", specificDevice.toString());
        return;
    }

    String lsrId = specificDevice.annotations().value(LSRID);
    if (lsrId == null) {
        log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
        return;
    }

    // Get capability config from netconfig
    DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
    if (cfg == null) {
        log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
        return;
    }

    // Check whether device has SR-TE Capability
    if (cfg.labelStackCap()) {
        if (!srTeHandler.releaseNodeLabel(deviceId, lsrId)) {
            log.error("Unable to release node label for a device id {}.", deviceId.toString());
        }
    }
}
 
Example 8
Source File: PcepClientControllerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates adjacency label for a link.
 *
 * @param link link
 */
public void allocateAdjacencyLabel(Link link) {
    checkNotNull(link, LINK_NULL);

    Device specificDevice = deviceService.getDevice(link.src().deviceId());

    // Retrieve lsrId of a specific device
    if (specificDevice.annotations() == null) {
        log.debug("Device {} does not have annotations.", specificDevice.toString());
        return;
    }

    String lsrId = specificDevice.annotations().value(LSRID);
    if (lsrId == null) {
        log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
        return;
    }

    // Get capability config from netconfig
    DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
    if (cfg == null) {
        log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
        // Save info. When PCEP session comes up then allocate adjacency
        // label
        if (lsrIdDeviceIdMap.get(lsrId) != null) {
            lsrIdDeviceIdMap.put(lsrId, specificDevice.id());
        }
        return;
    }

    // Check whether device has SR-TE Capability
    if (cfg.labelStackCap()) {
        srTeHandler.allocateAdjacencyLabel(link);
    }
}
 
Example 9
Source File: PcepClientControllerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Releases allocated adjacency label of a link.
 *
 * @param link link
 */
public void releaseAdjacencyLabel(Link link) {
    checkNotNull(link, LINK_NULL);

    Device specificDevice = deviceService.getDevice(link.src().deviceId());

    // Retrieve lsrId of a specific device
    if (specificDevice.annotations() == null) {
        log.debug("Device {} does not have annotations.", specificDevice.toString());
        return;
    }

    String lsrId = specificDevice.annotations().value(LSRID);
    if (lsrId == null) {
        log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
        return;
    }

    // Get capability config from netconfig
    DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
    if (cfg == null) {
        log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
        return;
    }

    // Check whether device has SR-TE Capability
    if (cfg.labelStackCap()) {
        if (!srTeHandler.releaseAdjacencyLabel(link)) {
            log.error("Unable to release adjacency labels for a link {}.", link.toString());
        }
    }
}
 
Example 10
Source File: SuppressionRules.java    From onos with Apache License 2.0 5 votes vote down vote up
public boolean isSuppressed(Device device) {
    if (suppressedDeviceType.contains(device.type())) {
        return true;
    }
    final Annotations annotations = device.annotations();
    if (containsSuppressionAnnotation(annotations)) {
        return true;
    }
    return false;
}
 
Example 11
Source File: MicroOnosTopoManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void list(ListRequest request,
                 StreamObserver<ListResponse> responseObserver) {
    for (Device d : deviceService.getDevices()) {
        Annotations annotations = d.annotations();
        DeviceOuterClass.Device.Builder db = DeviceOuterClass.Device.newBuilder()
                .setId(d.id().toString())
                .setVersion(d.swVersion())
                .setType(d.type().toString());
        String value = annotations.value(AnnotationKeys.MANAGEMENT_ADDRESS);
        if (!isNullOrEmpty(value)) {
            db.setAddress(value);
        }
        String role = annotations.value("role");
        if (!isNullOrEmpty(role)) {
            db.setRole(role);
        }

        // TODO: populate protocols, etc.

        ListResponse resp = ListResponse.newBuilder()
                .setType(ListResponse.Type.NONE)
                .setDevice(db.build())
                .build();
        responseObserver.onNext(resp);
    }
    responseObserver.onCompleted();
}
 
Example 12
Source File: GeoDistanceLinkWeight.java    From onos with Apache License 2.0 5 votes vote down vote up
private GeoLocation getLocation(DeviceId deviceId) {
    Device d = deviceService.getDevice(deviceId);
    Annotations a = d != null ? d.annotations() : null;
    double latitude = getDouble(a, AnnotationKeys.LATITUDE);
    double longitude = getDouble(a, AnnotationKeys.LONGITUDE);
    return latitude == MAX_VALUE || longitude == MAX_VALUE ? null :
            new GeoLocation(latitude, longitude);
}
 
Example 13
Source File: BasicDeviceOperator.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a description of the given device.
 *
 * @param device the device
 * @return a description of the device
 */
public static DeviceDescription descriptionOf(Device device) {
    checkNotNull(device, "Must supply non-null Device");
    return new DefaultDeviceDescription(device.id().uri(), device.type(),
            device.manufacturer(), device.hwVersion(),
            device.swVersion(), device.serialNumber(),
            device.chassisId(), (SparseAnnotations) device.annotations());
}
 
Example 14
Source File: TopologyViewMessageHandlerBase.java    From onos with Apache License 2.0 4 votes vote down vote up
private String friendlyDevice(DeviceId deviceId) {
    Device device = services.device().getDevice(deviceId);
    Annotations annot = device.annotations();
    String name = annot.value(AnnotationKeys.NAME);
    return isNullOrEmpty(name) ? deviceId.toString() : name;
}
 
Example 15
Source File: PceWebTopovOverlay.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) {

     pp.title(MY_TITLE);
     DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
     pp.removeAllProps();
     pp.removeButtons(CoreButtons.SHOW_PORT_VIEW)
            .removeButtons(CoreButtons.SHOW_GROUP_VIEW)
            .removeButtons(CoreButtons.SHOW_METER_VIEW);

     if (deviceService != null) {

        Device device = deviceService.getDevice(deviceId);
        Annotations annots = device.annotations();

        String type = annots.value(AnnotationKeys.TYPE);
        String asNumber = annots.value(AS_NUMBER);
        String lsrId = annots.value(LSR_ID);
        String abrStatus = annots.value(ABR_BIT);
        String asbrStatus = annots.value(ASBR_BIT);

        if (type != null) {
            pp.addProp(TYPE_LABEL, TYPE_LABEL, type);
        }

        if (asNumber != null) {
            pp.addProp(AS_NUMBER_LABEL, AS_NUMBER_LABEL, asNumber);
        }

        if (lsrId != null) {
            pp.addProp(LSR_ID_LABEL, LSR_ID_LABEL, lsrId);
        }

        if (Boolean.valueOf(abrStatus).equals(true) && Boolean.valueOf(asbrStatus).equals(true)) {
            pp.addProp(POSITION_LABEL, POSITION_LABEL, ABR_ASBR);
        } else if (Boolean.valueOf(abrStatus).equals(true)) {
            pp.addProp(POSITION_LABEL, POSITION_LABEL, ABR);
        } else if (Boolean.valueOf(asbrStatus).equals(true)) {
            pp.addProp(POSITION_LABEL, POSITION_LABEL, ASBR);
        } else {
            pp.addProp(POSITION_LABEL, POSITION_LABEL, INNER);
        }
    }
}