use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class ECDeviceStore method mergeAnnotations.
private DefaultAnnotations mergeAnnotations(DeviceId deviceId) {
ProviderId primaryProviderId = getPrimaryProviderId(deviceId);
DeviceDescription primaryDeviceDescription = deviceDescriptions.get(new DeviceKey(primaryProviderId, deviceId));
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
annotations = merge(annotations, primaryDeviceDescription.annotations());
for (ProviderId providerId : getAllProviders(deviceId)) {
if (!providerId.equals(primaryProviderId)) {
annotations = merge(annotations, deviceDescriptions.get(new DeviceKey(providerId, deviceId)).annotations());
}
}
return annotations;
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class ECDeviceStore method removeDevice.
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
NodeId master = mastershipService.getMasterFor(deviceId);
// if there exist a master, forward
// if there is no master, try to become one and process
boolean relinquishAtEnd = false;
if (master == null) {
final MastershipRole myRole = mastershipService.getLocalRole(deviceId);
if (myRole != MastershipRole.NONE) {
relinquishAtEnd = true;
}
log.debug("Temporarily requesting role for {} to remove", deviceId);
MastershipRole role = Futures.getUnchecked(mastershipService.requestRoleFor(deviceId));
if (role == MastershipRole.MASTER) {
master = localNodeId;
}
}
if (!localNodeId.equals(master)) {
log.debug("{} has control of {}, forwarding remove request", master, deviceId);
clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master).whenComplete((r, e) -> {
if (e != null) {
log.error("Failed to forward {} remove request to its master", deviceId, e);
}
});
return null;
}
// I have control..
DeviceEvent event = null;
final DeviceKey deviceKey = new DeviceKey(getPrimaryProviderId(deviceId), deviceId);
DeviceDescription removedDeviceDescription = deviceDescriptions.remove(deviceKey);
if (removedDeviceDescription != null) {
event = purgeDeviceCache(deviceId);
}
if (relinquishAtEnd) {
log.debug("Relinquishing temporary role acquired for {}", deviceId);
mastershipService.relinquishMastership(deviceId);
}
return event;
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class LumentumWaveReadyDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId deviceId = handler().data().deviceId();
Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
// Something reasonable, unavailable by default
DeviceDescription defaultDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, LUMENTUM, WAVEREADY, SWVERSION, SERIAL, new ChassisId(), false, DefaultAnnotations.EMPTY);
Optional<Tl1Device> device = ctrl.getDevice(deviceId);
if (!device.isPresent()) {
return defaultDescription;
}
// Login
Tl1Command loginCmd = DefaultTl1Command.builder().withVerb(ACT).withModifier(USER).withAid(device.get().username()).withCtag(100).withParameters(device.get().password()).build();
Future<String> login = ctrl.sendMsg(deviceId, loginCmd);
try {
String loginResponse = login.get(TIMEOUT, TimeUnit.MILLISECONDS);
if (loginResponse.contains("Access denied")) {
log.error("Access denied: {}", loginResponse);
return defaultDescription;
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Login failed", e);
return defaultDescription;
}
// Fetch device description
Tl1Command ddCmd = DefaultTl1Command.builder().withVerb(RTRV).withModifier(NETYPE).withCtag(101).build();
Future<String> dd = ctrl.sendMsg(deviceId, ddCmd);
try {
String ddResponse = dd.get(TIMEOUT, TimeUnit.MILLISECONDS);
return new DefaultDeviceDescription(defaultDescription, true, extractAnnotations(ddResponse));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Device description not found", e);
return defaultDescription;
}
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class StratumDeviceDescriptionDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
final DeviceDescription p4Descr = p4runtime.discoverDeviceDetails();
final DeviceDescription gnoiDescr = gnoi.discoverDeviceDetails();
final DeviceDescription gnmiDescr = gnmi.discoverDeviceDetails();
return new DefaultDeviceDescription(data().deviceId().uri(), Device.Type.SWITCH, data().driver().manufacturer(), data().driver().hwVersion(), data().driver().swVersion(), UNKNOWN, p4Descr.chassisId(), // Availability is mandated by P4Runtime.
p4Descr.isDefaultAvailable(), DefaultAnnotations.builder().putAll(p4Descr.annotations()).putAll(gnmiDescr.annotations()).putAll(gnoiDescr.annotations()).set(AnnotationKeys.PROTOCOL, format("%s, %s, %s", p4Descr.annotations().value(AnnotationKeys.PROTOCOL), gnmiDescr.annotations().value(AnnotationKeys.PROTOCOL), gnoiDescr.annotations().value(AnnotationKeys.PROTOCOL))).build());
}
use of org.onosproject.net.device.DeviceDescription 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));
}
Aggregations