Search in sources :

Example 6 with Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class DeviceProtoTranslator method translate.

/**
 * Translates gRPC DeviceDescription to {@link DeviceDescriptionProtoOuterClass}.
 *
 * @param deviceDescription gRPC message
 * @return {@link DeviceDescriptionProtoOuterClass}
 */
public static DeviceDescription translate(DeviceDescriptionProto deviceDescription) {
    URI uri = URI.create(deviceDescription.getDeviceUri());
    Type type = translate(deviceDescription.getType());
    String manufacturer = deviceDescription.getManufacturer();
    String hwVersion = deviceDescription.getHwVersion();
    String swVersion = deviceDescription.getSwVersion();
    String serialNumber = deviceDescription.getSerialNumber();
    ChassisId chassis = new ChassisId(deviceDescription.getChassisId());
    boolean defaultAvailable = deviceDescription.getIsDefaultAvailable();
    return new DefaultDeviceDescription(uri, type, manufacturer, hwVersion, swVersion, serialNumber, chassis, defaultAvailable, AnnotationsTranslator.asAnnotations(deviceDescription.getAnnotationsMap()));
}
Also used : Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) URI(java.net.URI)

Example 7 with Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class DeviceCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: ProviderId is not part of JSON representation.
 *       Returned object will have random ProviderId set.
 */
@Override
public Device decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    DeviceId id = deviceId(json.get(ID).asText());
    // TODO: add providerId to JSON if we need to recover them.
    ProviderId pid = new ProviderId(id.uri().getScheme(), "DeviceCodec");
    Type type = Type.valueOf(json.get(TYPE).asText());
    String mfr = json.get(MFR).asText();
    String hw = json.get(HW).asText();
    String sw = json.get(SW).asText();
    String serial = json.get(SERIAL).asText();
    ChassisId chassisId = new ChassisId(json.get(CHASSIS_ID).asText());
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultDevice(pid, id, type, mfr, hw, sw, serial, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice)

Example 8 with Type

use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.

the class SimpleDeviceStore method composeDevice.

/**
 * Returns a Device, merging description given from multiple Providers.
 *
 * @param deviceId      device identifier
 * @param providerDescs Collection of Descriptions from multiple providers
 * @return Device instance
 */
private Device composeDevice(DeviceId deviceId, Map<ProviderId, DeviceDescriptions> providerDescs) {
    checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied");
    ProviderId primary = pickPrimaryPid(providerDescs);
    DeviceDescriptions desc = providerDescs.get(primary);
    final DeviceDescription base = desc.getDeviceDesc();
    Type type = base.type();
    String manufacturer = base.manufacturer();
    String hwVersion = base.hwVersion();
    String swVersion = base.swVersion();
    String serialNumber = base.serialNumber();
    ChassisId chassisId = base.chassisId();
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    annotations = merge(annotations, base.annotations());
    for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
    }
    return new DefaultDevice(primary, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDevice(org.onosproject.net.DefaultDevice)

Aggregations

Type (org.onosproject.net.Device.Type)8 ChassisId (org.onlab.packet.ChassisId)6 ProviderId (org.onosproject.net.provider.ProviderId)5 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)4 DefaultDevice (org.onosproject.net.DefaultDevice)4 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)3 DeviceDescription (org.onosproject.net.device.DeviceDescription)3 DeviceId (org.onosproject.net.DeviceId)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)2 PortDescPropertyType (org.onosproject.openflow.controller.PortDescPropertyType)2 Beta (com.google.common.annotations.Beta)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1