/** * Puts DeviceDescription, merging annotations as necessary. * * @param newDesc new DeviceDescription * @return previous DeviceDescription */ public synchronized DeviceDescription putDeviceDesc(DeviceDescription newDesc) { DeviceDescription oldOne = deviceDesc.get(); DeviceDescription newOne = newDesc; if (oldOne != null) { SparseAnnotations merged = union(oldOne.annotations(), newDesc.annotations()); newOne = new DefaultDeviceDescription(newOne, merged); } return deviceDesc.getAndSet(newOne); }
@Override public DeviceDescription combine(DeviceId deviceId, DeviceDescription descr, Optional<Config> prevConfig) { DeviceAnnotationConfig cfg = lookupConfig(deviceId); if (cfg == null) { return descr; } Map<String, String> annotations = cfg.annotations(); Builder builder = DefaultAnnotations.builder(); builder.putAll(descr.annotations()); if (prevConfig.isPresent()) { DeviceAnnotationConfig prevDeviceAnnotationConfig = (DeviceAnnotationConfig) prevConfig.get(); for (String key : prevDeviceAnnotationConfig.annotations().keySet()) { if (!annotations.containsKey(key)) { builder.remove(key); } } } builder.putAll(annotations); return DefaultDeviceDescription.copyReplacingAnnotation(descr, builder.build()); }
DefaultDeviceDescription desc = new DefaultDeviceDescription( did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH),
private void deviceAdded(RestSBDevice nodeId) { Preconditions.checkNotNull(nodeId, ISNOTNULL); DeviceId deviceId = nodeId.deviceId(); ChassisId cid = new ChassisId(); String ipAddress = nodeId.ip().toString(); SparseAnnotations annotations = DefaultAnnotations.builder() .set(IPADDRESS, ipAddress) .set(AnnotationKeys.PROTOCOL, REST.toUpperCase()) .build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( deviceId.uri(), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); nodeId.setActive(true); providerService.deviceConnected(deviceId, deviceDescription); addedDevices.add(deviceId); }
@Override public void nodeAdded(OvsdbNodeId nodeId) { checkNotNull(nodeId, ISNOTNULL); DeviceId deviceId = DeviceId.deviceId(nodeId.toString()); URI uri = URI.create(nodeId.toString()); ChassisId cid = new ChassisId(); String ipAddress = nodeId.getIpAddress(); SparseAnnotations annotations = DefaultAnnotations.builder() .set("ipaddress", ipAddress).build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( uri, Device.Type.CONTROLLER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); providerService.deviceConnected(deviceId, deviceDescription); }
/** * Returns a description of the given device. * * @param device the device * @return a description of the device */ public static DeviceDescription descriptionOf(Device device) { checkNotNull(device, "Must supply non-null Device"); return new DefaultDeviceDescription(device.id().uri(), device.type(), device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId(), (SparseAnnotations) device.annotations()); } }
@Override public void routerAdded(IsisRouter isisRouter) { String systemId = isisRouter.systemId(); log.info("Added device {}", systemId); DeviceId deviceId = DeviceId.deviceId(IsisRouterId.uri(systemId)); Device.Type deviceType = Device.Type.ROUTER; //If our routerType is Dr or Bdr type is PSEUDO if (isisRouter.isDis()) { deviceType = Device.Type.ROUTER; } else { deviceType = Device.Type.VIRTUAL; } ChassisId cId = new ChassisId(); DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); newBuilder.set(AnnotationKeys.TYPE, "L3"); newBuilder.set("RouterId", systemId); DeviceDescription description = new DefaultDeviceDescription(IsisRouterId.uri(systemId), deviceType, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build()); deviceProviderService.deviceConnected(deviceId, description); System.out.println("Device added: " + systemId); }
.build(); DeviceDescription desc = new DefaultDeviceDescription( did.uri(), Device.Type.OTHER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations);
@Override public void routerAdded(OspfRouter ospfRouter) { String routerId = ospfRouter.routerIp().toString(); log.info("Added device {}", routerId); DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp())); Device.Type deviceType = Device.Type.ROUTER; //If our routerType is Dr or Bdr type is PSEUDO if (ospfRouter.isDr()) { deviceType = Device.Type.ROUTER; } else { deviceType = Device.Type.VIRTUAL; } //deviceId = DeviceId.deviceId(routerDetails); ChassisId cId = new ChassisId(); DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); newBuilder.set(AnnotationKeys.TYPE, "l3"); newBuilder.set("routerId", routerId); DeviceDescription description = new DefaultDeviceDescription(OspfRouterId.uri(ospfRouter.routerIp()), deviceType, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build()); deviceProviderService.deviceConnected(deviceId, description); }
return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer, hwVersion, swVersion, serial, descr.chassisId(),
new DefaultDeviceDescription(did.uri(), sw.deviceType(), sw.manufacturerDescription(), sw.hardwareDescription(),