BwmonitorImpl implements AltoBwmonitorService { @Override public Future<RpcResult<BwmonitorQueryOutput>> bwmonitorQuery(BwmonitorQueryInput input) { ReadTransaction transaction = db.newReadOnlyTransaction(); InstanceIdentifier<Speeds> iid = InstanceIdentifier.create(Speeds.class); BwmonitorQueryOutputBuilder builder = new BwmonitorQueryOutputBuilder(); List<String> queriedPorts = input.getPortId(); if (queriedPorts == null) { queriedPorts = new ArrayList<>(); } try { Optional<Speeds> nodeData = transaction.read(LogicalDatastoreType.OPERATIONAL, iid).get(); if(nodeData.isPresent()){ List<PortSpeed> portSpeeds = new ArrayList<>(); builder.setPortSpeed(portSpeeds); List<Port> allPorts = nodeData.get().getPort(); if (allPorts != null) { for (Port port : allPorts) { if (queriedPorts.contains(port.getPortId())) { portSpeeds.add(new PortSpeedBuilder() .setPortId(port.getPortId()) .setRxSpeed(port.getRxSpeed()) .setTxSpeed(port.getTxSpeed()) .setCapacity(port.getCapacity()) .setAvailBw(port.getAvailBw()) .build()); LOG.debug("Query node: {}, RxSpeed: {}, TxSpeed: {}, Capacity: {}, " + "AvailBw: {}", port.getPortId(), port.getRxSpeed(), port.getTxSpeed(), port.getCapacity(), port.getAvailBw()); } } } return RpcResultBuilder.success(builder.build()).buildFuture(); } } catch (InterruptedException|ExecutionException e){ LOG.error(e.getMessage()); } return RpcResultBuilder.success(builder.build()).buildFuture(); } BwmonitorImpl(DataBroker dataBroker); @Override Future<RpcResult<BwmonitorSubscribeOutput>> bwmonitorSubscribe(BwmonitorSubscribeInput input); @Override Future<RpcResult<BwmonitorQueryOutput>> bwmonitorQuery(BwmonitorQueryInput input); @Override Future<RpcResult<BwmonitorUnsubscribeOutput>> bwmonitorUnsubscribe(BwmonitorUnsubscribeInput input); void close();  }
@Test public void testBwmonitorQuery() throws Exception { BwmonitorQueryInput input = new BwmonitorQueryInputBuilder() .setPortId(Arrays.asList("testPort1", "testPort3")) .build(); service1.bwmonitorQuery(input); service2.bwmonitorQuery(input); }