@Override public InterfaceStatus getStatus() { return getOriginalIface().getStatistics().getStatus(); }
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; }
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; }
@Test public void testMasshUpdateStatisticsForVds() { List<VdsNetworkInterface> interfaces = dao.getAllInterfacesForVds(VDS_ID); List<VdsNetworkStatistics> statistics = new ArrayList<>(interfaces.size()); for (VdsNetworkInterface iface : interfaces) { VdsNetworkStatistics stats = iface.getStatistics(); stats.setReceiveDropRate(RandomUtils.instance().nextInt() * 1.0); stats.setStatus(RandomUtils.instance().nextEnum(InterfaceStatus.class)); statistics.add(stats); } dao.massUpdateStatisticsForVds(statistics); List<VdsNetworkInterface> after = dao.getAllInterfacesForVds(VDS_ID); for (VdsNetworkInterface iface : after) { boolean found = false; for (VdsNetworkStatistics stats : statistics) { if (iface.getId().equals(stats.getId())) { found = true; assertEquals(stats.getReceiveDropRate(), iface.getStatistics().getReceiveDropRate()); assertEquals(stats.getStatus(), iface.getStatistics().getStatus()); } } assertTrue(found); } }
/** * Ensures that get works as expected. */ @Test public void testGet() { newVdsInterface.setVdsId(VDS_ID); dao.saveInterfaceForVds(newVdsInterface); dao.saveStatisticsForVds(newVdsInterface.getStatistics()); VdsNetworkInterface result = dao.get(newVdsInterface.getId()); assertEquals(newVdsInterface, result); }
public static VdsNetworkInterface getEntitySpecific(int index) { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(GUIDS[index]); entity.setName(NAMES[index]); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity = setUpStatistics(entity, GUIDS[index]); entity.getStatistics().setStatus(NIC_STATUS); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); 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())); }
model.getMac().setAddress(entity.getMacAddress()); if (entity.getStatistics().getStatus()!=InterfaceStatus.NONE) { NicStatus nicStatus = mapNicStatus(entity.getStatistics().getStatus()); if (nicStatus != null) { model.setStatus(nicStatus);
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); existingVdsInterface = dao.get(FixturesTool.VDS_NETWORK_INTERFACE); newQos = new HostNetworkQos(); newQos.setOutAverageLinkshare(30); newQos.setOutAverageUpperlimit(30); newQos.setOutAverageRealtime(30); newVdsInterface = new VdsNetworkInterface(); newVdsInterface.setStatistics(new VdsNetworkStatistics()); newVdsInterface.setId(Guid.newGuid()); newVdsInterface.setName("eth77"); newVdsInterface.setNetworkName("enginet"); newVdsInterface.setSpeed(1000); newVdsInterface.setType(3); newVdsInterface.setMacAddress("01:C0:81:21:71:17"); newVdsInterface.setIpv4BootProtocol(Ipv4BootProtocol.STATIC_IP); newVdsInterface.setIpv4Address("192.168.122.177"); newVdsInterface.setIpv4Subnet("255.255.255.0"); newVdsInterface.setIpv4Gateway("192.168.122.1"); newVdsInterface.setIpv6BootProtocol(Ipv6BootProtocol.AUTOCONF); newVdsInterface.setIpv6Address("ipv6 address"); newVdsInterface.setIpv6Prefix(666); newVdsInterface.setIpv6Gateway("ipv6 gateway"); newVdsInterface.setMtu(1500); newVdsInterface.setQos(newQos); newVdsStatistics = newVdsInterface.getStatistics(); }