Java Code Examples for org.onosproject.net.DeviceId#uri()
The following examples show how to use
org.onosproject.net.DeviceId#uri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolatisDeviceDescription.java From onos with Apache License 2.0 | 6 votes |
private DeviceDescription parseProductInformation() { DeviceService devsvc = checkNotNull(handler().get(DeviceService.class)); DeviceId devid = handler().data().deviceId(); Device dev = devsvc.getDevice(devid); if (dev == null) { return new DefaultDeviceDescription(devid.uri(), FIBER_SWITCH, DEFAULT_MANUFACTURER, DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA, new ChassisId()); } String reply = netconfGet(handler(), getProductInformationFilter()); subscribe(handler()); HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF); return new DefaultDeviceDescription(dev.id().uri(), FIBER_SWITCH, cfg.getString(KEY_MANUFACTURER), cfg.getString(KEY_HWVERSION), cfg.getString(KEY_SWVERSION), cfg.getString(KEY_SERIALNUMBER), dev.chassisId()); }
Example 2
Source File: XmppDeviceProvider.java From onos with Apache License 2.0 | 6 votes |
private void connectDevice(XmppDeviceId xmppDeviceId) { DeviceId deviceId = DeviceId.deviceId(xmppDeviceId.id()); String ipAddress = controller.getDevice(xmppDeviceId).getIpAddress().getAddress().getHostAddress(); // Assumption: manufacturer is uniquely identified by domain part of JID String manufacturer = xmppDeviceId.getJid().getDomain(); ChassisId cid = new ChassisId(); SparseAnnotations annotations = DefaultAnnotations.builder() .set(AnnotationKeys.PROTOCOL, XMPP.toUpperCase()) .set("IpAddress", ipAddress) .build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( deviceId.uri(), Device.Type.OTHER, manufacturer, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, true, annotations); if (deviceService.getDevice(deviceId) == null) { providerService.deviceConnected(deviceId, deviceDescription); } }
Example 3
Source File: LispDeviceProvider.java From onos with Apache License 2.0 | 6 votes |
/** * Adds a LISP router into device store. */ private void connectDevice(LispRouterId routerId) { DeviceId deviceId = getDeviceId(routerId.id().toString()); Preconditions.checkNotNull(deviceId, IS_NULL_MSG); // formulate LISP router object ChassisId cid = new ChassisId(); String ipAddress = routerId.id().toString(); SparseAnnotations annotations = DefaultAnnotations.builder() .set(IPADDRESS, ipAddress) .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()) .build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( deviceId.uri(), Device.Type.ROUTER, MANUFACTURER, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, false, annotations); if (deviceService.getDevice(deviceId) == null) { providerService.deviceConnected(deviceId, deviceDescription); } checkAndUpdateDevice(deviceId, deviceDescription); }
Example 4
Source File: Tl1DeviceProvider.java From onos with Apache License 2.0 | 6 votes |
private void connectDevice(Tl1Device device) { try { // Add device to TL1 controller DeviceId deviceId = DeviceId.deviceId( new URI(Tl1DeviceConfig.TL1, device.ip() + ":" + device.port(), null)); if (controller.addDevice(deviceId, device)) { SparseAnnotations ann = DefaultAnnotations.builder() .set(AnnotationKeys.PROTOCOL, Tl1DeviceConfig.TL1.toUpperCase()) .build(); // Register device in the core with default parameters and mark it as unavailable DeviceDescription dd = new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), false, ann); providerService.deviceConnected(deviceId, dd); } } catch (URISyntaxException e) { log.error("Skipping device {}", device, e); } }
Example 5
Source File: GeneralDeviceProvider.java From onos with Apache License 2.0 | 6 votes |
private DeviceDescription forgeDeviceDescription( DeviceId deviceId, boolean defaultAvailable) { // Uses handshaker and provider config to get driver data. final DeviceHandshaker handshaker = getBehaviour( deviceId, DeviceHandshaker.class); final Driver driver = handshaker != null ? handshaker.handler().driver() : null; return new DefaultDeviceDescription( deviceId.uri(), Device.Type.SWITCH, driver != null ? driver.manufacturer() : UNKNOWN, driver != null ? driver.hwVersion() : UNKNOWN, driver != null ? driver.swVersion() : UNKNOWN, UNKNOWN, new ChassisId(), defaultAvailable, DefaultAnnotations.EMPTY); }
Example 6
Source File: JuniperUtils.java From onos with Apache License 2.0 | 6 votes |
/** * Parses device configuration and returns the device description. * * @param deviceId the id of the device * @param sysInfoCfg system configuration * @param chassisMacAddresses chassis MAC addresses response. Its format depends on JUNOS version of device. * @return device description */ public static DeviceDescription parseJuniperDescription(DeviceId deviceId, HierarchicalConfiguration sysInfoCfg, String chassisMacAddresses) { HierarchicalConfiguration info = sysInfoCfg.configurationAt(SYS_INFO); String hw = info.getString(HW_MODEL) == null ? UNKNOWN : info.getString(HW_MODEL); String sw = UNKNOWN; if (info.getString(OS_NAME) != null || info.getString(OS_VER) != null) { sw = info.getString(OS_NAME) + " " + info.getString(OS_VER); } String serial = info.getString(SER_NUM) == null ? UNKNOWN : info.getString(SER_NUM); return new DefaultDeviceDescription(deviceId.uri(), ROUTER, JUNIPER, hw, sw, serial, extractChassisId(chassisMacAddresses), DefaultAnnotations.EMPTY); }
Example 7
Source File: Ciena5162DeviceDescription.java From onos with Apache License 2.0 | 6 votes |
@Override public DeviceDescription discoverDeviceDetails() { DeviceId deviceId = handler().data().deviceId(); NetconfController controller = checkNotNull(handler().get(NetconfController.class)); NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); try { Node systemInfo = TEMPLATE_MANAGER.doRequest(session, "systemInfo"); Node softwareVersion = TEMPLATE_MANAGER.doRequest(session, "softwareVersion"); XPath xp = XPathFactory.newInstance().newXPath(); String mac = xp.evaluate("components/component/properties/property/state/value/text()", systemInfo) .toUpperCase(); return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, xp.evaluate("components/component/state/mfg-name/text()", systemInfo), xp.evaluate("components/component/state/name/text()", systemInfo), xp.evaluate("software-state/running-package/package-version/text()", softwareVersion), xp.evaluate("components/component/state/serial-no/text()", systemInfo), new ChassisId(Long.valueOf(mac, 16))); } catch (XPathExpressionException | NetconfException ne) { log.error("failed to query system info from device {}", handler().data().deviceId(), ne); } return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", "5162", "Unknown", "Unknown", new ChassisId()); }
Example 8
Source File: Ciena5170DeviceDescription.java From onos with Apache License 2.0 | 6 votes |
@Override public DeviceDescription discoverDeviceDetails() { DeviceId deviceId = handler().data().deviceId(); NetconfController controller = checkNotNull(handler().get(NetconfController.class)); NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); try { Node systemInfo = TEMPLATE_MANAGER.doRequest(session, "systemInfo"); Node chassisMac = TEMPLATE_MANAGER.doRequest(session, "chassis-mac"); Node softwareVersion = TEMPLATE_MANAGER.doRequest(session, "softwareVersion"); XPath xp = XPathFactory.newInstance().newXPath(); String mac = xp.evaluate("lldp-global-operational/chassis-id/text()", chassisMac).toUpperCase(); return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", xp.evaluate("components/component/name/text()", systemInfo), xp.evaluate("software-state/running-package/package-version/text()", softwareVersion), mac, new ChassisId(Long.valueOf(mac, 16))); } catch (XPathExpressionException | NetconfException ne) { log.error("failed to query system info from device {} : {}", handler().data().deviceId(), ne.getMessage(), ne); } return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, "Ciena", "5170", "Unknown", "Unknown", new ChassisId()); }
Example 9
Source File: ConfigOpticalDeviceDiscovery.java From onos with Apache License 2.0 | 5 votes |
@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); }
Example 10
Source File: DeviceDescriptionDiscoveryAristaImpl.java From onos with Apache License 2.0 | 5 votes |
@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; } }
Example 11
Source File: ZteDeviceDiscoveryImpl.java From onos with Apache License 2.0 | 5 votes |
@Override public DeviceDescription discoverDeviceDetails() { DeviceId deviceId = handler().data().deviceId(); log.info("Discovering ZTE device {}", deviceId); NetconfController controller = handler().get(NetconfController.class); NetconfSession session = controller.getDevicesMap().get(deviceId).getSession(); String hwVersion = "ZTE hw"; String swVersion = "ZTE sw"; String serialNumber = "000000000000"; try { String reply = session.requestSync(buildDeviceInfoRequest()); XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply)); hwVersion = cfg.getString("components.component.state.hardware-version"); swVersion = cfg.getString("components.component.state.software-version"); serialNumber = cfg.getString("components.component.state.serial-no"); } catch (NetconfException e) { log.error("ZTE device discovery error.", e); } return new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, "ZTE", hwVersion, swVersion, serialNumber, new ChassisId(1)); }
Example 12
Source File: GossipDeviceStoreTest.java From onos with Apache License 2.0 | 5 votes |
private void putDeviceAncillary(DeviceId deviceId, String swVersion, SparseAnnotations... annotations) { DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID, annotations); deviceStore.createOrUpdateDevice(PIDA, deviceId, description); }
Example 13
Source File: TopologySimulator.java From onos with Apache License 2.0 | 5 votes |
/** * 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)); deviceIds.add(id); mastershipAdminService.setRoleSync(localNode, id, MASTER); deviceProviderService.deviceConnected(id, desc); deviceProviderService.updatePorts(id, buildPorts(portCount)); }
Example 14
Source File: PcepTopologyProvider.java From onos with Apache License 2.0 | 5 votes |
@Override public void switchAdded(PcepDpid dpid) { if (deviceProviderService == null) { return; } DeviceId deviceId = deviceId(uri(dpid)); PcepSwitch sw = controller.getSwitch(dpid); checkNotNull(sw, "device should not null."); // The default device type is switch. ChassisId cId = new ChassisId(dpid.value()); Device.Type deviceType; switch (sw.getDeviceType()) { case ROADM: deviceType = Device.Type.ROADM; break; case OTN: deviceType = Device.Type.SWITCH; break; case ROUTER: deviceType = Device.Type.ROUTER; break; default: deviceType = Device.Type.OTHER; } DeviceDescription description = new DefaultDeviceDescription( deviceId.uri(), deviceType, sw.manufacturerDescription(), sw.hardwareDescription(), sw.softwareDescription(), sw.serialNumber(), cId); deviceProviderService.deviceConnected(deviceId, description); }
Example 15
Source File: SimpleDeviceStoreTest.java From onos with Apache License 2.0 | 5 votes |
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); }
Example 16
Source File: TapiDeviceDescriptionDiscovery.java From onos with Apache License 2.0 | 5 votes |
@Override public DeviceDescription discoverDeviceDetails() { log.debug("Getting device description"); DeviceService deviceService = checkNotNull(handler().get(DeviceService.class)); DeviceId deviceId = handler().data().deviceId(); Device device = deviceService.getDevice(deviceId); if (device == null) { //TODO need to obtain from the device. return new DefaultDeviceDescription(deviceId.uri(), Device.Type.OLS, "Tapi", "0", "2.1", "Unknown", new ChassisId(), DefaultAnnotations.builder().set("protocol", "REST").build()); } else { return new DefaultDeviceDescription(device.id().uri(), Device.Type.OLS, device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId()); } }
Example 17
Source File: SimpleDeviceStoreTest.java From onos with Apache License 2.0 | 5 votes |
private void putDeviceAncillary(DeviceId deviceId, String swVersion, SparseAnnotations... annotations) { DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID, annotations); deviceStore.createOrUpdateDevice(PIDA, deviceId, description); }
Example 18
Source File: OpenFlowDeviceProvider.java From onos with Apache License 2.0 | 4 votes |
@Override public void switchAdded(Dpid dpid) { if (providerService == null) { return; } DeviceId did = deviceId(uri(dpid)); OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null) { LOG.error("Switch {} is not found", dpid); return; } ChassisId cId = new ChassisId(dpid.value()); DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() .set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString()) .set(AnnotationKeys.CHANNEL_ID, sw.channelId()) .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0]); // FIXME following ignores driver specified by name Driver driver = driverService.getDriver(sw.manufacturerDescription(), sw.hardwareDescription(), sw.softwareDescription()); // FIXME: The following breaks the STC tests and will require to be revisited. // if (driver != null) { // annotationsBuilder.set(AnnotationKeys.DRIVER, driver.name()); // } SparseAnnotations annotations = annotationsBuilder.build(); DeviceDescription description = new DefaultDeviceDescription(did.uri(), sw.deviceType(), sw.manufacturerDescription(), sw.hardwareDescription(), sw.softwareDescription(), sw.serialNumber(), cId, annotations); providerService.deviceConnected(did, description); providerService.updatePorts(did, buildPortDescriptions(sw)); //sends port description stats request again if OF version supports if (sw.features().getVersion().compareTo(OFVersion.OF_13) >= 0) { sendPortDescStatsRequest(sw); } if (sw.features().getCapabilities().contains(OFCapabilities.PORT_STATS)) { PortStatsCollector psc = new PortStatsCollector(timer, sw, portStatsPollFrequency); stopCollectorIfNeeded(collectors.put(dpid, psc)); psc.start(); } //figure out race condition for collectors.remove() and collectors.put() if (controller.getSwitch(dpid) == null) { switchRemoved(dpid); } }
Example 19
Source File: SnmpDeviceProvider.java From onos with Apache License 2.0 | 4 votes |
/** * Initialize SNMP Device object, and notify core saying device connected. */ private void advertiseDevices() { try { if (device == null) { log.warn("The Request SNMP Device is null, cannot proceed further"); return; } DeviceId did = device.deviceId(); ChassisId cid = new ChassisId(); SparseAnnotations annotations = DefaultAnnotations.builder() .set(AnnotationKeys.PROTOCOL, SCHEME.toUpperCase()) .build(); DeviceDescription desc = new DefaultDeviceDescription( did.uri(), Device.Type.OTHER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); log.debug("Persisting Device " + did.uri().toString()); controller.addDevice(device); providerService.deviceConnected(did, desc); log.info("Added device to ONOS core. Device Info: " + device.deviceInfo() + " " + did.uri().toString()); //FIXME this description will be populated only if driver is pushed from outside // because otherwise default driver is used Device d = deviceService.getDevice(did); if (d.is(DeviceDescriptionDiscovery.class)) { DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class); DeviceDescription description = descriptionDiscovery.discoverDeviceDetails(); if (description != null) { deviceStore.createOrUpdateDevice( new ProviderId("snmp", "org.onosproject.provider.device"), did, description); } else { log.info("No other description given for device {}", d.id()); } providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails()); } else { log.warn("No populate description and ports behaviour for device {}", did); } } catch (Exception e) { log.error("Error while initializing session for the device: " + (device != null ? device.deviceInfo() : null), e); } }
Example 20
Source File: DeviceInjectionConfigMonitor.java From onos with Apache License 2.0 | 4 votes |
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); } }