cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weiz...@apache.org
Subject [16/50] [abbrv] git commit: updated refs/heads/disk_io_throttling to 8b8a0d3
Date Mon, 10 Jun 2013 17:27:10 GMT
CLOUDSTACK-1647: IP Reservation should not happen if the guest-vm cidr and network cidr is
not same but their start ip and end ip are same.

Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5dc7387d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5dc7387d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5dc7387d

Branch: refs/heads/disk_io_throttling
Commit: 5dc7387d3b6b1abd841abc92e3c76a3894213d82
Parents: 5233e32
Author: Saksham Srivastava <saksham.srivastava@citrix.com>
Authored: Wed Jun 5 16:28:05 2013 +0530
Committer: Sateesh Chodapuneedi <sateesh@apache.org>
Committed: Fri Jun 7 16:54:40 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/network/NetworkServiceImpl.java   | 15 +++++++++++
 utils/src/com/cloud/utils/net/NetUtils.java     | 28 ++++++++++++++++++++
 .../test/com/cloud/utils/net/NetUtilsTest.java  | 19 +++++++++++++
 3 files changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5dc7387d/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 29a36b9..c2af8e8 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -2116,6 +2116,21 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
                         }
                     }
 
+                // In some scenarios even though guesVmCidr and network CIDR do not appear
similar but
+                // the IP ranges exactly matches, in these special cases make sure no Reservation
gets applied
+                if (network.getNetworkCidr() == null) {
+                    if (NetUtils.isSameIpRange(guestVmCidr, network.getCidr()) &&
!guestVmCidr.equals(network.getCidr())) {
+                        throw new InvalidParameterValueException("The Start IP and End IP
of guestvmcidr: "+ guestVmCidr + " and CIDR: " + network.getCidr() + " are same, " +
+                                "even though both the cidrs appear to be different. As a
precaution no IP Reservation will be applied.");
+                    }
+                } else {
+                    if(NetUtils.isSameIpRange(guestVmCidr, network.getNetworkCidr()) &&
!guestVmCidr.equals(network.getNetworkCidr())) {
+                        throw new InvalidParameterValueException("The Start IP and End IP
of guestvmcidr: "+ guestVmCidr + " and Network CIDR: " + network.getNetworkCidr() + " are
same, " +
+                                "even though both the cidrs appear to be different. As a
precaution IP Reservation will not be affected. If you want to reset IP Reservation, " +
+                                "specify guestVmCidr to be: " + network.getNetworkCidr());
+                    }
+                }
+
                 // When reservation is applied for the first time, network_cidr will be null
                 // Populate it with the actual network cidr
                 if (network.getNetworkCidr() == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5dc7387d/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index 8c094c8..12ac3e6 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -1023,6 +1023,34 @@ public class NetUtils {
         return NetUtils.getIpRangeStartIpFromCidr(splitResult[0], size);
     }
 
+    // Check if 2 CIDRs have exactly same IP Range
+    public static boolean isSameIpRange (String cidrA, String cidrB) {
+
+        if(!NetUtils.isValidCIDR(cidrA)) {
+            s_logger.info("Invalid value of cidr " + cidrA);
+            return false;
+        }
+         if (!NetUtils.isValidCIDR(cidrB)) {
+            s_logger.info("Invalid value of cidr " + cidrB);
+            return false;
+        }
+        String[] cidrPairFirst = cidrA.split("\\/");
+        String[] cidrPairSecond = cidrB.split("\\/");
+
+        Long networkSizeFirst = Long.valueOf(cidrPairFirst[1]);
+        Long networkSizeSecond = Long.valueOf(cidrPairSecond[1]);
+        String ipRangeFirst [] = NetUtils.getIpRangeFromCidr(cidrPairFirst[0], networkSizeFirst);
+        String ipRangeSecond [] = NetUtils.getIpRangeFromCidr(cidrPairFirst[0], networkSizeSecond);
+
+        long startIpFirst = NetUtils.ip2Long(ipRangeFirst[0]);
+        long endIpFirst = NetUtils.ip2Long(ipRangeFirst[1]);
+        long startIpSecond = NetUtils.ip2Long(ipRangeSecond[0]);
+        long endIpSecond = NetUtils.ip2Long(ipRangeSecond[1]);
+        if(startIpFirst == startIpSecond && endIpFirst == endIpSecond) {
+            return true;
+        }
+        return false;
+    }
     public static boolean validateGuestCidr(String cidr) {
         // RFC 1918 - The Internet Assigned Numbers Authority (IANA) has reserved the
         // following three blocks of the IP address space for private internets:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5dc7387d/utils/test/com/cloud/utils/net/NetUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java
index 16d3402..9952d3c 100644
--- a/utils/test/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java
@@ -136,4 +136,23 @@ public class NetUtilsTest extends TestCase {
     	assertTrue(NetUtils.getPrimaryPvlanFromUri(uri).equals("123"));
     	assertTrue(NetUtils.getIsolatedPvlanFromUri(uri).equals("456"));
     }
+
+    public void testIsSameIpRange() {
+        //Test to check IP Range of 2 CIDRs
+        String cidrFirst = "10.0.144.0/20";
+        String cidrSecond = "10.0.151.0/20";
+        String cidrThird = "10.0.144.0/21";
+        assertTrue(NetUtils.isValidCIDR(cidrFirst));
+        assertTrue(NetUtils.isValidCIDR(cidrSecond));
+        assertTrue(NetUtils.isValidCIDR(cidrThird));
+
+        //Check for exactly same CIDRs
+        assertTrue(NetUtils.isSameIpRange(cidrFirst, cidrFirst));
+        //Check for 2 different CIDRs, but same IP Range
+        assertTrue(NetUtils.isSameIpRange(cidrFirst, cidrSecond));
+        //Check for 2 different CIDRs and different IP Range
+        assertFalse(NetUtils.isSameIpRange(cidrFirst, cidrThird));
+        //Check for Incorrect format of CIDR
+        assertFalse(NetUtils.isSameIpRange(cidrFirst, "10.3.6.5/50"));
+    }
 }


Mime
View raw message