use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class GossipDeviceStoreTest method testCreateOrUpdateDevice.
@Test
public final void testCreateOrUpdateDevice() throws IOException {
DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
Capture<InternalDeviceEvent> message = Capture.newInstance();
Capture<MessageSubject> subject = Capture.newInstance();
Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
DeviceEvent event = deviceStore.createOrUpdateDevice(PID, DID1, description);
assertEquals(DEVICE_ADDED, event.type());
assertDevice(DID1, SW1, event.subject());
verify(clusterCommunicator);
assertInternalDeviceEvent(NID1, DID1, PID, description, message, subject, encoder);
DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
assertEquals(DEVICE_UPDATED, event2.type());
assertDevice(DID1, SW2, event2.subject());
verify(clusterCommunicator);
assertInternalDeviceEvent(NID1, DID1, PID, description2, message, subject, encoder);
reset(clusterCommunicator);
assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class NetconfDeviceProvider method existingOrEmptyDescription.
private DeviceDescription existingOrEmptyDescription(DeviceId deviceId, NetconfDeviceConfig config) {
Device device = deviceService.getDevice(deviceId);
if (deviceService.getDevice(deviceId) != null) {
// getting the previous description
return new DefaultDeviceDescription(device.id().uri(), device.type(), device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId(), (SparseAnnotations) device.annotations());
}
ChassisId cid = new ChassisId();
String ipAddress = config.ip().toString();
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(PORT, String.valueOf(config.port())).set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase());
if (config.path().isPresent()) {
annotations.set(PATH, config.path().get());
}
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, true, annotations.build());
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class NetconfDeviceProvider method getDeviceRepresentation.
private DeviceDescription getDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config, DeviceDescriptionDiscovery deviceDescriptionDiscovery) {
DeviceDescription existingOrEmptyDescription = existingOrEmptyDescription(deviceId, config);
DeviceDescription newDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
if (newDescription == null) {
return existingOrEmptyDescription;
}
// merging and returning
return new DefaultDeviceDescription(newDescription, true, DefaultAnnotations.merge((DefaultAnnotations) newDescription.annotations(), existingOrEmptyDescription.annotations()));
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class DeviceInjectionConfigMonitor method injectDevice.
private void injectDevice(DeviceId did) {
Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
if (discovery.isPresent()) {
providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
providerService.updatePorts(did, discovery.get().discoverPortDetails());
} else {
String unk = "UNKNOWN";
DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
providerService.deviceConnected(did, desc);
Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
int numPorts = Integer.parseInt(ports);
List<PortDescription> portDescs = new ArrayList<>(numPorts);
for (int i = 1; i <= numPorts; ++i) {
// TODO inject port details if something like BasicPortConfig was created
PortNumber number = portNumber(i);
boolean isEnabled = true;
portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
}
providerService.updatePorts(did, portDescs);
}
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class ConfigOpticalDeviceDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
DeviceId did = data().deviceId();
String unk = "UNKNOWN";
Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfg.getConfig(did, DeviceInjectionConfig.class));
Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfg.getConfig(did, BasicDeviceConfig.class));
Device.Type type = basic.map(BasicDeviceConfig::type).orElse(Device.Type.SWITCH);
String manufacturer = basic.map(BasicDeviceConfig::manufacturer).orElse(unk);
String hwVersion = basic.map(BasicDeviceConfig::hwVersion).orElse(unk);
String swVersion = basic.map(BasicDeviceConfig::swVersion).orElse(unk);
String serialNumber = basic.map(BasicDeviceConfig::serial).orElse(unk);
ChassisId chassis = new ChassisId();
// if inject is not specified, return default unavailable device
boolean defaultAvailable = inject.isPresent();
return new DefaultDeviceDescription(did.uri(), type, manufacturer, hwVersion, swVersion, serialNumber, chassis, defaultAvailable);
}
Aggregations