Search in sources :

Example 16 with SparseAnnotations

use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.

the class RestDeviceProvider method getDesc.

private DeviceDescription getDesc(RestSBDevice restSBDev) {
    DeviceId deviceId = restSBDev.deviceId();
    Driver driver = getDriver(restSBDev);
    if (restSBDev.isProxy()) {
        if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
            // Creates the driver to communicate with the server
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            return devicesDiscovery.deviceDetails(deviceId);
        } else {
            log.warn("Driver not found for {}", restSBDev);
            return null;
        }
    } else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
        DriverHandler h = driverService.createHandler(deviceId);
        DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
        return deviceDiscovery.discoverDeviceDetails();
    }
    ChassisId cid = new ChassisId();
    String ipAddress = restSBDev.ip().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
    String manufacturer = UNKNOWN;
    String hwVersion = UNKNOWN;
    String swVersion = UNKNOWN;
    String serialNumber = UNKNOWN;
    Device device = deviceService.getDevice(deviceId);
    if (device != null) {
        manufacturer = device.manufacturer();
        hwVersion = device.hwVersion();
        swVersion = device.swVersion();
        serialNumber = device.serialNumber();
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DeviceId(org.onosproject.net.DeviceId) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DevicesDiscovery(org.onosproject.net.behaviour.DevicesDiscovery)

Example 17 with SparseAnnotations

use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.

the class DeviceDescriptions method putPortDesc.

/**
 * Puts PortDescription, merging annotations as necessary.
 *
 * @param newDesc new PortDescription
 */
public void putPortDesc(Timestamped<PortDescription> newDesc) {
    Timestamped<PortDescription> oldOne = portDescs.get(newDesc.value().portNumber());
    Timestamped<PortDescription> newOne = newDesc;
    if (oldOne != null) {
        SparseAnnotations merged = union(oldOne.value().annotations(), newDesc.value().annotations());
        newOne = new Timestamped<>(DefaultPortDescription.builder(newDesc.value()).annotations(merged).build(), newDesc.timestamp());
    }
    portDescs.put(newOne.value().portNumber(), newOne);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortDescription(org.onosproject.net.device.PortDescription)

Example 18 with SparseAnnotations

use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.

the class TerminalDeviceDiscovery method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 *
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <data>
 * <components xmlns="http://openconfig.net/yang/platform">
 *  <component>
 *   <state>
 *     <name>FIRMWARE</name>
 *     <type>oc-platform-types:OPERATING_SYSTEM</type>
 *     <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
 *     <version>0.0.1</version>
 *   </state>
 *  </component>
 * </components>
 * </data>
 *}</pre>
 * //CHECKSTYLE:ON
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    log.info("TerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
    boolean defaultAvailable = true;
    SparseAnnotations annotations = DefaultAnnotations.builder().build();
    // Other option "OTHER", we use ROADM for now
    org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
    // Some defaults
    String vendor = "NOVENDOR";
    String hwVersion = "0.2.1";
    String swVersion = "0.2.1";
    String serialNumber = "0xCAFEBEEF";
    String chassisId = "128";
    // Get the session,
    NetconfSession session = getNetconfSession(did());
    if (session != null) {
        try {
            String reply = session.get(getDeviceDetailsBuilder());
            // <rpc-reply> as root node
            XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
            vendor = xconf.getString("data/components/component/state/mfg-name", vendor);
            serialNumber = xconf.getString("data/components/component/state/serial-no", serialNumber);
            // Requires OpenConfig >= 2018
            swVersion = xconf.getString("data/components/component/state/software-version", swVersion);
            hwVersion = xconf.getString("data/components/component/state/hardware-version", hwVersion);
        } catch (Exception e) {
            throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
        }
    } else {
        log.info("TerminalDeviceDiscovery::discoverDeviceDetails - No netconf session for {}", did());
    }
    log.info("VENDOR    {}", vendor);
    log.info("HWVERSION {}", hwVersion);
    log.info("SWVERSION {}", swVersion);
    log.info("SERIAL    {}", serialNumber);
    log.info("CHASSISID {}", chassisId);
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ChassisId(org.onlab.packet.ChassisId) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfException(org.onosproject.netconf.NetconfException) SparseAnnotations(org.onosproject.net.SparseAnnotations) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 19 with SparseAnnotations

use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.

the class TunnelCreateCommand method doExecute.

@Override
protected void doExecute() {
    TunnelProvider service = get(TunnelProvider.class);
    ProviderId producerName = new ProviderId("default", "org.onosproject.provider.tunnel.default");
    TunnelEndPoint srcPoint = null;
    TunnelEndPoint dstPoint = null;
    Tunnel.Type trueType = null;
    if ("MPLS".equals(type)) {
        trueType = Tunnel.Type.MPLS;
        srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
        dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
    } else if ("VLAN".equals(type)) {
        trueType = Tunnel.Type.VLAN;
        String[] srcArray = src.split("/");
        String[] dstArray = dst.split("/");
        srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, null, OpticalLogicId.logicId(0), true);
        dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, null, OpticalLogicId.logicId(0), true);
    } else if ("VXLAN".equals(type)) {
        trueType = Tunnel.Type.VXLAN;
        srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
        dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
    } else if ("GRE".equals(type)) {
        trueType = Tunnel.Type.GRE;
        srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
        dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
    } else if ("ODUK".equals(type)) {
        trueType = Tunnel.Type.ODUK;
        String[] srcArray = src.split("/");
        String[] dstArray = dst.split("/");
        srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
        dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
    } else if ("OCH".equals(type)) {
        trueType = Tunnel.Type.OCH;
        String[] srcArray = src.split("/");
        String[] dstArray = dst.split("/");
        srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
        dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
    } else {
        print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
        return;
    }
    SparseAnnotations annotations = DefaultAnnotations.builder().set("bandwidth", bandwidth == null || "".equals(bandwidth) ? "0" : bandwidth).build();
    TunnelDescription tunnel = new DefaultTunnelDescription(null, srcPoint, dstPoint, trueType, new GroupId(Integer.parseInt(groupId)), producerName, TunnelName.tunnelName(tunnelName), null, annotations);
    TunnelId tunnelId = service.tunnelAdded(tunnel);
    if (tunnelId == null) {
        error("Create tunnel failed.");
        return;
    }
    print(FMT, tunnelId.id());
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) TunnelProvider(org.onosproject.incubator.net.tunnel.TunnelProvider) OpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) TunnelEndPoint(org.onosproject.incubator.net.tunnel.TunnelEndPoint) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) IpTunnelEndPoint(org.onosproject.incubator.net.tunnel.IpTunnelEndPoint) TunnelDescription(org.onosproject.incubator.net.tunnel.TunnelDescription) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) GroupId(org.onosproject.core.GroupId) SparseAnnotations(org.onosproject.net.SparseAnnotations) Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)

Example 20 with SparseAnnotations

use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.

the class TunnelUpdateCommand method doExecute.

@Override
protected void doExecute() {
    TunnelProvider service = get(TunnelProvider.class);
    TunnelId id = TunnelId.valueOf(tunnelId);
    SparseAnnotations annotations = DefaultAnnotations.builder().set("bandwidth", bandwidth).build();
    TunnelDescription tunnel = new DefaultTunnelDescription(id, null, null, null, null, null, null, null, annotations);
    service.tunnelUpdated(tunnel);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) TunnelProvider(org.onosproject.incubator.net.tunnel.TunnelProvider) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) TunnelDescription(org.onosproject.incubator.net.tunnel.TunnelDescription) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId)

Aggregations

SparseAnnotations (org.onosproject.net.SparseAnnotations)30 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)12 ChassisId (org.onlab.packet.ChassisId)10 DeviceId (org.onosproject.net.DeviceId)8 Device (org.onosproject.net.Device)6 Test (org.junit.Test)5 DefaultTunnelDescription (org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)4 TunnelDescription (org.onosproject.incubator.net.tunnel.TunnelDescription)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 PortDescription (org.onosproject.net.device.PortDescription)4 NetconfException (org.onosproject.netconf.NetconfException)4 NetconfSession (org.onosproject.netconf.NetconfSession)4 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)3 GroupId (org.onosproject.core.GroupId)3 IpTunnelEndPoint (org.onosproject.incubator.net.tunnel.IpTunnelEndPoint)3 TunnelEndPoint (org.onosproject.incubator.net.tunnel.TunnelEndPoint)3 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)3 Link (org.onosproject.net.Link)3 PortNumber (org.onosproject.net.PortNumber)3 NetconfDevice (org.onosproject.netconf.NetconfDevice)3