@@ -3888,26 +3888,29 @@ public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile){
38883888 String privateIP = router .getPrivateIpAddress ();
38893889
38903890 if (privateIP != null ) {
3891+ boolean forVpc = router .getVpcId () != null ;
38913892 List <? extends Nic > routerNics = _nicDao .listByVmId (router .getId ());
38923893 for (Nic routerNic : routerNics ) {
38933894 Network network = _networkModel .getNetwork (routerNic .getNetworkId ());
3894- if (network .getTrafficType () == TrafficType .Public ) {
3895- boolean forVpc = router .getVpcId () != null ;
3895+ //Send network usage command for public nic in VPC VR
3896+ //Send network usage command for isolated guest nic of non VPC VR
3897+ if ((forVpc && network .getTrafficType () == TrafficType .Public ) || (!forVpc && network .getTrafficType () == TrafficType .Guest && network .getGuestType () == Network .GuestType .Isolated )) {
38963898 final NetworkUsageCommand usageCmd = new NetworkUsageCommand (privateIP , router .getHostName (),
38973899 forVpc , routerNic .getIp4Address ());
3900+ String routerType = router .getType ().toString ();
38983901 UserStatisticsVO previousStats = _userStatsDao .findBy (router .getAccountId (),
3899- router .getDataCenterId (), network .getId (), null , router . getId () , router .getType (). toString () );
3902+ router .getDataCenterId (), network .getId (), ( forVpc ? routerNic . getIp4Address () : null ) , router .getId (), routerType );
39003903 NetworkUsageAnswer answer = null ;
39013904 try {
39023905 answer = (NetworkUsageAnswer ) _agentMgr .easySend (router .getHostId (), usageCmd );
39033906 } catch (Exception e ) {
3904- s_logger .warn ("Error while collecting network stats from router: " + router .getInstanceName ()+ " from host: " + router .getHostId (), e );
3907+ s_logger .warn ("Error while collecting network stats from router: " + router .getInstanceName () + " from host: " + router .getHostId (), e );
39053908 continue ;
39063909 }
39073910
39083911 if (answer != null ) {
39093912 if (!answer .getResult ()) {
3910- s_logger .warn ("Error while collecting network stats from router: " + router .getInstanceName ()+ " from host: " + router .getHostId () + "; details: " + answer .getDetails ());
3913+ s_logger .warn ("Error while collecting network stats from router: " + router .getInstanceName () + " from host: " + router .getHostId () + "; details: " + answer .getDetails ());
39113914 continue ;
39123915 }
39133916 Transaction txn = Transaction .open (Transaction .CLOUD_DB );
@@ -3918,26 +3921,26 @@ public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile){
39183921 }
39193922 txn .start ();
39203923 UserStatisticsVO stats = _userStatsDao .lock (router .getAccountId (),
3921- router .getDataCenterId (), network .getId (), null , router . getId () , router .getType (). toString () );
3924+ router .getDataCenterId (), network .getId (), ( forVpc ? routerNic . getIp4Address () : null ) , router .getId (), routerType );
39223925 if (stats == null ) {
39233926 s_logger .warn ("unable to find stats for account: " + router .getAccountId ());
39243927 continue ;
39253928 }
39263929
3927- if (previousStats != null
3928- && ((previousStats .getCurrentBytesReceived () != stats .getCurrentBytesReceived ())
3929- || (previousStats .getCurrentBytesSent () != stats .getCurrentBytesSent ()))){
3930+ if (previousStats != null
3931+ && ((previousStats .getCurrentBytesReceived () != stats .getCurrentBytesReceived ())
3932+ || (previousStats .getCurrentBytesSent () != stats .getCurrentBytesSent ()))){
39303933 s_logger .debug ("Router stats changed from the time NetworkUsageCommand was sent. " +
3931- "Ignoring current answer. Router: " + answer .getRouterName ()+ " Rcvd: " +
3932- answer .getBytesReceived ()+ "Sent: " +answer .getBytesSent ());
3934+ "Ignoring current answer. Router: " + answer .getRouterName () + " Rcvd: " +
3935+ answer .getBytesReceived () + "Sent: " + answer .getBytesSent ());
39333936 continue ;
39343937 }
39353938
39363939 if (stats .getCurrentBytesReceived () > answer .getBytesReceived ()) {
39373940 if (s_logger .isDebugEnabled ()) {
39383941 s_logger .debug ("Received # of bytes that's less than the last one. " +
3939- "Assuming something went wrong and persisting it. Router: " +
3940- answer .getRouterName ()+ " Reported: " + answer .getBytesReceived ()
3942+ "Assuming something went wrong and persisting it. Router: " +
3943+ answer .getRouterName () + " Reported: " + answer .getBytesReceived ()
39413944 + " Stored: " + stats .getCurrentBytesReceived ());
39423945 }
39433946 stats .setNetBytesReceived (stats .getNetBytesReceived () + stats .getCurrentBytesReceived ());
@@ -3946,8 +3949,8 @@ public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile){
39463949 if (stats .getCurrentBytesSent () > answer .getBytesSent ()) {
39473950 if (s_logger .isDebugEnabled ()) {
39483951 s_logger .debug ("Received # of bytes that's less than the last one. " +
3949- "Assuming something went wrong and persisting it. Router: " +
3950- answer .getRouterName ()+ " Reported: " + answer .getBytesSent ()
3952+ "Assuming something went wrong and persisting it. Router: " +
3953+ answer .getRouterName () + " Reported: " + answer .getBytesSent ()
39513954 + " Stored: " + stats .getCurrentBytesSent ());
39523955 }
39533956 stats .setNetBytesSent (stats .getNetBytesSent () + stats .getCurrentBytesSent ());
0 commit comments