You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by an...@apache.org on 2013/07/22 23:29:52 UTC

git commit: updated refs/heads/master to 04cdd90

Updated Branches:
  refs/heads/master 8a6892d54 -> 04cdd90a8


in one zone, Admin should not be allowed to add a Shared Network with a subnet that is already associated with another Vlan.


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

Branch: refs/heads/master
Commit: 04cdd90a84f4be5ba02778fe0cd352a4b1c39a13
Parents: 8a6892d
Author: Anthony Xu <an...@citrix.com>
Authored: Mon Jul 22 14:16:20 2013 -0700
Committer: Anthony Xu <an...@citrix.com>
Committed: Mon Jul 22 14:29:38 2013 -0700

----------------------------------------------------------------------
 .../configuration/ConfigurationManagerImpl.java | 115 +++++++------------
 .../com/cloud/network/NetworkServiceImpl.java   |   7 +-
 2 files changed, 41 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04cdd90a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 92178c9..9bc8efd 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2978,30 +2978,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
         }
 
         if (ipv4) {
-            String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask);
+            String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask);
 
             // Check if the new VLAN's subnet conflicts with the guest network
             // in
             // the specified zone (guestCidr is null for basic zone)
             String guestNetworkCidr = zone.getGuestNetworkCidr();
-            if (guestNetworkCidr != null) {
-                String[] cidrPair = guestNetworkCidr.split("\\/");
-                String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrPair[0], Long.parseLong(cidrPair[1]));
-                long guestCidrSize = Long.parseLong(cidrPair[1]);
-                long vlanCidrSize = NetUtils.getCidrSize(vlanNetmask);
-
-                long cidrSizeToUse = -1;
-                if (vlanCidrSize < guestCidrSize) {
-                    cidrSizeToUse = vlanCidrSize;
-                } else {
-                    cidrSizeToUse = guestCidrSize;
-                }
-
-                String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse);
-
-                if (newVlanSubnet.equals(guestSubnet)) {
+            if ( guestNetworkCidr != null ) {
+                if (NetUtils.isNetworksOverlap(newCidr, guestNetworkCidr)) {
                     throw new InvalidParameterValueException(
-                            "The new IP range you have specified has the same subnet as the guest network in zone: "
+                            "The new IP range you have specified has  overlapped with the guest network in zone: "
                                     + zone.getName() + ". Please specify a different gateway/netmask.");
                 }
             }
@@ -3009,29 +2995,36 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
             // Check if there are any errors with the IP range
             checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
 
-            // Throw an exception if any of the following is true:
-            // 1. Another VLAN in the same zone has a different tag but the same
-            // subnet as the new VLAN. Make an exception for the
-            // case when both vlans are Direct.
-            // 2. Another VLAN in the same zone that has the same tag and subnet
-            // as
-            // the new VLAN has IPs that overlap with the IPs
-            // being added
-            // 3. Another VLAN in the same zone that has the same tag and subnet
-            // as
-            // the new VLAN has a different gateway than the
-            // new VLAN
-            // 4. If VLAN is untagged and Virtual, and there is existing
-            // UNTAGGED
-            // vlan with different subnet
+            // Throw an exception if this subnet overlaps with subnet on other VLAN,
+            // if this is ip range extension, gateway, network mask should be same and ip range should not overlap
+
             List<VlanVO> vlans = _vlanDao.listByZone(zone.getId());
             for (VlanVO vlan : vlans) {
                 String otherVlanGateway = vlan.getVlanGateway();
+                String otherVlanNetmask = vlan.getVlanNetmask();
                 // Continue if it's not IPv4
-                if (otherVlanGateway == null) {
+                if ( otherVlanGateway == null || otherVlanNetmask == null ) {
+                    continue;
+                }
+                if ( vlan.getNetworkId() == null ) {
                     continue;
                 }
-                 String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask());
+                String otherCidr = NetUtils.getCidrFromGatewayAndNetmask(otherVlanGateway, otherVlanNetmask);
+                if( !NetUtils.isNetworksOverlap(newCidr,  otherCidr)) {
+                    continue;
+                }
+                // from here, subnet overlaps
+                if ( !vlanId.equals(vlan.getVlanTag()) ) {
+                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
+                            + " in zone " + zone.getName()
+                            + " has overlapped with the subnet. Please specify a different gateway/netmask.");
+                }
+                if ( vlan.getNetworkId() != networkId) {
+                    throw new InvalidParameterValueException("This subnet is overlapped with subnet in other network " + vlan.getNetworkId()
+                            + " in zone " + zone.getName()
+                            + " . Please specify a different gateway/netmask.");
+                   
+                }
                 String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
                 String otherVlanStartIP = otherVlanIpRange[0];
                 String otherVlanEndIP = null;
@@ -3039,34 +3032,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                     otherVlanEndIP = otherVlanIpRange[1];
                 }
 
-                if (forVirtualNetwork && !vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)
-                        && !allowIpRangeOverlap(vlan, forVirtualNetwork, networkId)) {
-                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
-                            + " in zone " + zone.getName()
-                            + " has the same subnet. Please specify a different gateway/netmask.");
-                }
-
-                boolean vlansUntaggedAndVirtual = (vlanId.equals(Vlan.UNTAGGED) && vlanId.equals(vlan.getVlanTag())
-                        && forVirtualNetwork && vlan.getVlanType() == VlanType.VirtualNetwork);
-
-                if (vlansUntaggedAndVirtual && !newVlanSubnet.equals(otherVlanSubnet)) {
-                    throw new InvalidParameterValueException(
-                            "The Untagged ip range with different subnet already exists in zone " + zone.getId());
+                //extend IP range
+                if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
+                    throw new InvalidParameterValueException("The IP range has already been added with gateway " 
+                            + otherVlanGateway + " ,and netmask " + otherVlanNetmask
+                            + ", Please specify the gateway/netmask if you want to extend ip range" );
                 }
-
-                if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) {
-                    if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
-                        throw new InvalidParameterValueException(
-                                "The IP range with tag: "
-                                        + vlan.getVlanTag()
-                                        + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
-                    }
-
-                    if (!vlanGateway.equals(otherVlanGateway)) {
-                        throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
-                                + " has already been added with gateway " + otherVlanGateway
-                                + ". Please specify a different tag.");
-                    }
+                if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
+                    throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." +
+                    		" Please specify a different start IP/end IP.");
                 }
             }
         }
@@ -3085,15 +3059,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                 }
                 if (vlanId.equals(vlan.getVlanTag())) {
                     if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) {
-                        throw new InvalidParameterValueException(
-                                "The IPv6 range with tag: "
-                                        + vlan.getVlanTag()
-                                        + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
+                        throw new InvalidParameterValueException("The IPv6 range with tag: " + vlan.getVlanTag()
+                                + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
                     }
 
                     if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) {
-                        throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
-                                + " has already been added with gateway " + vlan.getIp6Gateway()
+                        throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + vlan.getIp6Gateway()
                                 + ". Please specify a different tag.");
                     }
                 }
@@ -4911,14 +4882,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
         }
     }
 
-    private boolean allowIpRangeOverlap(VlanVO vlan, boolean forVirtualNetwork, long networkId) {
-        // FIXME - delete restriction for virtual network in the future
-        if (vlan.getVlanType() == VlanType.DirectAttached && !forVirtualNetwork) {
-            return true;
-        } else {
-            return false;
-        }
-    }
 
     @Override
     public ServiceOffering getServiceOffering(long serviceOfferingId) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04cdd90a/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 f1f71ca..23bed01 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -1233,13 +1233,10 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             }
         }
 
-        // Vlan is created in 2 cases - works in Advance zone only:
+        // Vlan is created in 1 cases - works in Advance zone only:
         // 1) GuestType is Shared
-        // 2) GuestType is Isolated, but SourceNat service is disabled
         boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced
-                && ((ntwkOff.getGuestType() == Network.GuestType.Shared)
-                || (ntwkOff.getGuestType() == GuestType.Isolated &&
-                !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))));
+                && (ntwkOff.getGuestType() == Network.GuestType.Shared));
 
         if (!createVlan) {
         	// Only support advance shared network in IPv6, which means createVlan is a must