Search in sources :

Example 41 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class TopologySimulator method createDevice.

/**
 * Creates simulated device.
 *
 * @param id        device identifier
 * @param chassisId chassis identifier number
 * @param type      device type
 * @param hw        hardware revision
 * @param sw        software revision
 * @param portCount number of device ports
 */
public void createDevice(DeviceId id, int chassisId, Device.Type type, String hw, String sw, int portCount) {
    DeviceDescription desc = new DefaultDeviceDescription(id.uri(), type, "ONF", hw, sw, "1234", new ChassisId(chassisId), DefaultAnnotations.builder().set(AnnotationKeys.NAME, "Switch " + chassisId).build());
    deviceIds.add(id);
    mastershipAdminService.setRoleSync(localNode, id, MASTER);
    deviceProviderService.deviceConnected(id, desc);
    deviceProviderService.updatePorts(id, buildPorts(portCount));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 42 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class DeviceDescriptionDiscoveryAristaImpl method discoverDeviceDetails.

@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;
    }
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) 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) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 43 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class SimpleDeviceStoreTest method putDevice.

private void putDevice(DeviceId deviceId, String swVersion, SparseAnnotations... annotations) {
    DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID, annotations);
    deviceStore.createOrUpdateDevice(PID, deviceId, description);
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 44 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class SimpleDeviceStoreTest method testCreateOrUpdateDevice.

@Test
public final void testCreateOrUpdateDevice() {
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
    DeviceEvent event = deviceStore.createOrUpdateDevice(PID, DID1, description);
    assertEquals(DEVICE_ADDED, event.type());
    assertDevice(DID1, SW1, event.subject());
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
    DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertEquals(DEVICE_UPDATED, event2.type());
    assertDevice(DID1, SW2, event2.subject());
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Test(org.junit.Test)

Example 45 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class SimpleDeviceStoreTest method testCreateOrUpdateDeviceAncillary.

@Test
public final void testCreateOrUpdateDeviceAncillary() {
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2);
    DeviceEvent event = deviceStore.createOrUpdateDevice(PIDA, DID1, description);
    assertEquals(DEVICE_ADDED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(PIDA, event.subject().providerId());
    assertAnnotationsEquals(event.subject().annotations(), A2);
    assertFalse("Ancillary will not bring device up", deviceStore.isAvailable(DID1));
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID, A1);
    DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertEquals(DEVICE_UPDATED, event2.type());
    assertDevice(DID1, SW2, event2.subject());
    assertEquals(PID, event2.subject().providerId());
    assertAnnotationsEquals(event2.subject().annotations(), A1, A2);
    assertTrue(deviceStore.isAvailable(DID1));
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));
    // For now, Ancillary is ignored once primary appears
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PIDA, DID1, description));
    // But, Ancillary annotations will be in effect
    DeviceDescription description3 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2_2);
    DeviceEvent event3 = deviceStore.createOrUpdateDevice(PIDA, DID1, description3);
    assertEquals(DEVICE_UPDATED, event3.type());
    // basic information will be the one from Primary
    assertDevice(DID1, SW2, event3.subject());
    assertEquals(PID, event3.subject().providerId());
    // but annotation from Ancillary will be merged
    assertAnnotationsEquals(event3.subject().annotations(), A1, A2, A2_2);
    assertTrue(deviceStore.isAvailable(DID1));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Test(org.junit.Test)

Aggregations

DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)52 ChassisId (org.onlab.packet.ChassisId)33 DeviceDescription (org.onosproject.net.device.DeviceDescription)26 DeviceId (org.onosproject.net.DeviceId)24 Device (org.onosproject.net.Device)20 SparseAnnotations (org.onosproject.net.SparseAnnotations)14 DeviceService (org.onosproject.net.device.DeviceService)11 NetconfException (org.onosproject.netconf.NetconfException)11 NetconfSession (org.onosproject.netconf.NetconfSession)11 Test (org.junit.Test)9 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)8 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)6 DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)6 DeviceEvent (org.onosproject.net.device.DeviceEvent)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 NetconfDevice (org.onosproject.netconf.NetconfDevice)5 List (java.util.List)4 BiFunction (java.util.function.BiFunction)4 Function (java.util.function.Function)4 XPath (javax.xml.xpath.XPath)4