Skip to content

Commit cd7f771

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-721: Fixed network usage. Send network usage command for isolated guest nic of non VPC VR. Send network usage command for public nic in VPC VR.
1 parent 7f8262d commit cd7f771

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -823,26 +823,29 @@ public void run() {
823823
String privateIP = router.getPrivateIpAddress();
824824

825825
if (privateIP != null) {
826+
boolean forVpc = router.getVpcId() != null;
826827
List<? extends Nic> routerNics = _nicDao.listByVmId(router.getId());
827828
for (Nic routerNic : routerNics) {
828829
Network network = _networkMgr.getNetwork(routerNic.getNetworkId());
829-
if (network.getTrafficType() == TrafficType.Public) {
830-
boolean forVpc = router.getVpcId() != null;
830+
//Send network usage command for public nic in VPC VR
831+
//Send network usage command for isolated guest nic of non VPC VR
832+
if ((forVpc && network.getTrafficType() == TrafficType.Public) || (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
831833
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
832834
forVpc, routerNic.getIp4Address());
833-
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
834-
router.getDataCenterIdToDeployIn(), network.getId(), null, router.getId(), router.getType().toString());
835+
String routerType = router.getType().toString();
836+
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
837+
router.getDataCenterIdToDeployIn(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
835838
NetworkUsageAnswer answer = null;
836839
try {
837840
answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
838841
} catch (Exception e) {
839-
s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId(), e);
842+
s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(), e);
840843
continue;
841844
}
842845

843846
if (answer != null) {
844847
if (!answer.getResult()) {
845-
s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId() + "; details: " + answer.getDetails());
848+
s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() + "; details: " + answer.getDetails());
846849
continue;
847850
}
848851
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
@@ -852,27 +855,27 @@ public void run() {
852855
continue;
853856
}
854857
txn.start();
855-
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
856-
router.getDataCenterIdToDeployIn(), network.getId(), routerNic.getIp4Address(), router.getId(), router.getType().toString());
858+
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
859+
router.getDataCenterIdToDeployIn(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
857860
if (stats == null) {
858861
s_logger.warn("unable to find stats for account: " + router.getAccountId());
859862
continue;
860863
}
861864

862-
if(previousStats != null
863-
&& ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
864-
|| (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){
865+
if (previousStats != null
866+
&& ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
867+
|| (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))) {
865868
s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
866-
"Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " +
867-
answer.getBytesReceived()+ "Sent: " +answer.getBytesSent());
869+
"Ignoring current answer. Router: " + answer.getRouterName() + " Rcvd: " +
870+
answer.getBytesReceived() + "Sent: " + answer.getBytesSent());
868871
continue;
869872
}
870873

871874
if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
872875
if (s_logger.isDebugEnabled()) {
873876
s_logger.debug("Received # of bytes that's less than the last one. " +
874-
"Assuming something went wrong and persisting it. Router: " +
875-
answer.getRouterName()+" Reported: " + answer.getBytesReceived()
877+
"Assuming something went wrong and persisting it. Router: " +
878+
answer.getRouterName() + " Reported: " + answer.getBytesReceived()
876879
+ " Stored: " + stats.getCurrentBytesReceived());
877880
}
878881
stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
@@ -881,8 +884,8 @@ public void run() {
881884
if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
882885
if (s_logger.isDebugEnabled()) {
883886
s_logger.debug("Received # of bytes that's less than the last one. " +
884-
"Assuming something went wrong and persisting it. Router: " +
885-
answer.getRouterName()+" Reported: " + answer.getBytesSent()
887+
"Assuming something went wrong and persisting it. Router: " +
888+
answer.getRouterName() + " Reported: " + answer.getBytesSent()
886889
+ " Stored: " + stats.getCurrentBytesSent());
887890
}
888891
stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());

0 commit comments

Comments
 (0)