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));
}
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;
}
}
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);
}
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));
}
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));
}
Aggregations