Search in sources :

Example 11 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class Ciena5170DeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    try {
        Node systemInfo = TEMPLATE_MANAGER.doRequest(session, "systemInfo");
        Node chassisMac = TEMPLATE_MANAGER.doRequest(session, "chassis-mac");
        Node softwareVersion = TEMPLATE_MANAGER.doRequest(session, "softwareVersion");
        XPath xp = XPathFactory.newInstance().newXPath();
        String mac = xp.evaluate("lldp-global-operational/chassis-id/text()", chassisMac).toUpperCase();
        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", xp.evaluate("components/component/name/text()", systemInfo), xp.evaluate("software-state/running-package/package-version/text()", softwareVersion), mac, new ChassisId(Long.valueOf(mac, 16)));
    } catch (XPathExpressionException | NetconfException ne) {
        log.error("failed to query system info from device {} : {}", handler().data().deviceId(), ne.getMessage(), ne);
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", "5170", "Unknown", "Unknown", new ChassisId());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) NetconfController(org.onosproject.netconf.NetconfController)

Example 12 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class Ciena5162DeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    try {
        Node systemInfo = TEMPLATE_MANAGER.doRequest(session, "systemInfo");
        Node softwareVersion = TEMPLATE_MANAGER.doRequest(session, "softwareVersion");
        XPath xp = XPathFactory.newInstance().newXPath();
        String mac = xp.evaluate("components/component/properties/property/state/value/text()", systemInfo).toUpperCase();
        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, xp.evaluate("components/component/state/mfg-name/text()", systemInfo), xp.evaluate("components/component/state/name/text()", systemInfo), xp.evaluate("software-state/running-package/package-version/text()", softwareVersion), xp.evaluate("components/component/state/serial-no/text()", systemInfo), new ChassisId(Long.valueOf(mac, 16)));
    } catch (XPathExpressionException | NetconfException ne) {
        log.error("failed to query system info from device {}", handler().data().deviceId(), ne);
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", "5162", "Unknown", "Unknown", new ChassisId());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) NetconfController(org.onosproject.netconf.NetconfController)

Example 13 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class CienaWaveserverDeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    log.debug("getting device description");
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = handler().data().deviceId();
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, "Ciena", "WaveServer", "Unknown", "Unknown", new ChassisId());
    } else {
        return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId());
    }
}
Also used : ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceService(org.onosproject.net.device.DeviceService)

Example 14 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class SoamManagerTest method testCreateDmNoBehavior.

@Test
public void testCreateDmNoBehavior() throws CfmConfigException, SoamConfigException {
    final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
    final MepId mepId3 = MepId.valueOf((short) 3);
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    Driver testDriver3 = new DefaultDriver(TEST_DRIVER_3, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_3, behaviours, new HashMap<>());
    Device device3 = new DefaultDevice(ProviderId.NONE, deviceId3, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_3, TEST_SN, new ChassisId(2), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER_3).build());
    expect(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
    replay(deviceService);
    MepEntry mep3 = DefaultMepEntry.builder(mepId3, deviceId3, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
    expect(mepService.getMep(MDNAME1, MANAME1, mepId3)).andReturn(mep3).anyTimes();
    replay(mepService);
    expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
    replay(driverService);
    DelayMeasurementCreate dmCreate1 = DefaultDelayMeasurementCreate.builder(DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO3).binsPerFdInterval((short) 4).binsPerFdrInterval((short) 5).binsPerIfdvInterval((short) 6).build();
    try {
        soamManager.createDm(MDNAME1, MANAME1, mepId3, dmCreate1);
        fail("Expecting exception since device does not support behavior");
    } catch (CfmConfigException e) {
        assertEquals("Device netconf:3.2.3.4:830 from MEP :md-1/" + "ma-1-1/3 does not implement SoamDmProgrammable", e.getMessage());
    }
}
Also used : ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) Driver(org.onosproject.net.driver.Driver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) DefaultDelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 15 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getDeviceDetails.

/**
 * Query a server to retrieve its features.
 *
 * @param deviceId the device ID to be queried
 * @return a DeviceDescription with the device's features
 */
private DeviceDescription getDeviceDetails(DeviceId deviceId) {
    // Retrieve the device ID, if null given
    if (deviceId == null) {
        deviceId = getDeviceId();
        checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    }
    // Get the device
    RestSBDevice device = getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides the server's resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_RESOURCE_DISCOVERY, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    if (jsonMap == null) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    // Get all the attributes
    String id = get(jsonNode, PARAM_ID);
    String vendor = get(jsonNode, PARAM_MANUFACTURER);
    String hw = get(jsonNode, PARAM_HW_VENDOR);
    String sw = get(jsonNode, PARAM_SW_VENDOR);
    String serial = get(jsonNode, PARAM_SERIAL);
    long chassisId = objNode.path(PARAM_CHASSIS_ID).asLong();
    // Pass the southbound protocol as an annotation
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    annotations.set(AnnotationKeys.PROTOCOL, "REST");
    // Parse CPU devices
    Collection<CpuDevice> cpuSet = parseCpuDevices(objNode);
    // Parse memory hierarchy device
    MemoryHierarchyDevice memHierarchyDev = parseMemoryHierarchyDevice(objNode);
    // Parse CPU cache hierachy device
    CpuCacheHierarchyDevice cacheHierarchyDev = parseCpuCacheHierarchyDevice(objNode);
    // NICs are composite attributes too
    Collection<NicDevice> nicSet = parseNicDevices(mapper, objNode, annotations);
    // Construct a server device,
    // i.e., a RestSBDevice extended with CPU, cache, memory, and NIC information
    RestServerSBDevice dev = new DefaultRestServerSBDevice(device.ip(), device.port(), device.username(), device.password(), device.protocol(), device.url(), device.isActive(), device.testUrl().orElse(""), vendor, hw, sw, cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet);
    checkNotNull(dev, MSG_DEVICE_NULL);
    // Set alive
    raiseDeviceReconnect(dev);
    // Updates the controller with the complete device information
    getController().removeDevice(deviceId);
    getController().addDevice((RestSBDevice) dev);
    // Create a description for this server device
    ServerDeviceDescription desc = null;
    try {
        desc = new DefaultServerDeviceDescription(new URI(id), Device.Type.SERVER, vendor, hw, sw, serial, new ChassisId(chassisId), cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet, annotations.build());
    } catch (URISyntaxException uEx) {
        log.error("Failed to create a server device description for: {}", deviceId);
        return null;
    }
    log.info("Device's {} details sent to the controller", deviceId);
    return desc;
}
Also used : DefaultServerDeviceDescription(org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription) ServerDeviceDescription(org.onosproject.drivers.server.devices.ServerDeviceDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) CpuCacheHierarchyDevice(org.onosproject.drivers.server.devices.cpu.CpuCacheHierarchyDevice) DefaultCpuCacheHierarchyDevice(org.onosproject.drivers.server.impl.devices.DefaultCpuCacheHierarchyDevice) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultCpuDevice(org.onosproject.drivers.server.impl.devices.DefaultCpuDevice) CpuDevice(org.onosproject.drivers.server.devices.cpu.CpuDevice) URISyntaxException(java.net.URISyntaxException) DefaultServerDeviceDescription(org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription) URI(java.net.URI) NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException) MemoryHierarchyDevice(org.onosproject.drivers.server.devices.memory.MemoryHierarchyDevice) DefaultMemoryHierarchyDevice(org.onosproject.drivers.server.impl.devices.DefaultMemoryHierarchyDevice) ChassisId(org.onlab.packet.ChassisId) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Map(java.util.Map)

Aggregations

ChassisId (org.onlab.packet.ChassisId)48 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)32 DeviceId (org.onosproject.net.DeviceId)24 Device (org.onosproject.net.Device)19 DefaultDevice (org.onosproject.net.DefaultDevice)13 DeviceDescription (org.onosproject.net.device.DeviceDescription)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)11 DeviceService (org.onosproject.net.device.DeviceService)11 Test (org.junit.Test)10 SparseAnnotations (org.onosproject.net.SparseAnnotations)10 NetconfException (org.onosproject.netconf.NetconfException)10 NetconfSession (org.onosproject.netconf.NetconfSession)10 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)6 Type (org.onosproject.net.Device.Type)6 ProviderId (org.onosproject.net.provider.ProviderId)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayList (java.util.ArrayList)5 NetconfDevice (org.onosproject.netconf.NetconfDevice)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4