protected VdsNetworkInterface setUpStatisticalExpectations() { VdsNetworkStatistics stats = mock(VdsNetworkStatistics.class); VdsNetworkInterface entity = mock(VdsNetworkInterface.class); when(entity.getSpeed()).thenReturn(SPEED); when(entity.getStatistics()).thenReturn(stats); when(entity.getId()).thenReturn(NIC_ID); when(stats.getReceiveRate()).thenReturn(RECEIVE_RATE); when(stats.getTransmitRate()).thenReturn(TRANSMIT_RATE); when(stats.getReceiveDropRate()).thenReturn(RECEIVE_DROP_RATE); when(stats.getTransmitDropRate()).thenReturn(TRANSMIT_DROP_RATE); when(stats.getReceivedBytes()).thenReturn(RECEIVED_BYTES); when(stats.getTransmittedBytes()).thenReturn(TRANSMITTED_BYTES); List<VdsNetworkInterface> ifaces = new ArrayList<>(); ifaces.add(entity); setUpEntityQueryExpectations(QueryType.GetVdsInterfacesByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { PARENT_GUID }, ifaces); return entity; }
@Override public List<Statistic> getStatistics(VdsNetworkInterface iface) { NetworkStatistics s = iface.getStatistics(); return asList(setDatum(clone(DATA_RX), RxTxCalculator.percent2bytes(iface.getSpeed(), s.getReceiveRate())), setDatum(clone(DATA_TX), RxTxCalculator.percent2bytes(iface.getSpeed(), s.getTransmitRate())), setDatum(clone(DATA_RX_BITS), RxTxCalculator.percent2bits(iface.getSpeed(), s.getReceiveRate())), setDatum(clone(DATA_TX_BITS), RxTxCalculator.percent2bits(iface.getSpeed(), s.getTransmitRate())), setDatum(clone(TOTAL_RX), s.getReceivedBytes()), setDatum(clone(TOTAL_TX), s.getTransmittedBytes()), setDatum(clone(ERRS_RX), s.getReceiveDropRate()), setDatum(clone(ERRS_TX), s.getTransmitDropRate())); }
private HostInterface hostInterfaceFromNic(VdsNetworkInterface nic) { HostInterface hi = new HostInterface(); hi.setInterface(nic); hi.setName(nic.getName()); hi.setIpv4Address(nic.getIpv4Address()); hi.setIpv6Address(nic.getIpv6Address()); hi.setMAC(nic.getMacAddress()); hi.setSpeed(nic.getSpeed()); hi.setRxRate(nic.getStatistics().getReceiveRate()); hi.setRxTotal(nic.getStatistics().getReceivedBytes()); hi.setRxDrop(nic.getStatistics().getReceiveDropRate()); hi.setTxRate(nic.getStatistics().getTransmitRate()); hi.setTxTotal(nic.getStatistics().getTransmittedBytes()); hi.setTxDrop(nic.getStatistics().getTransmitDropRate()); hi.setStatus(nic.getStatistics().getStatus()); hi.getPropertyChangedEvent().addListener(this); return hi; }
.addValue("name", nic.getName()) .addValue("network_name", nic.getNetworkName()) .addValue("speed", nic.getSpeed()) .addValue("subnet", nic.getIpv4Subnet()) .addValue("ipv6_prefix", nic.getIpv6Prefix())