IPv6: CLOUDSTACK-1107: Add support for createVlanIpRange to extend existed 
network


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

Branch: refs/heads/network-refactor
Commit: 931372e5ca40350fe75b3744e75150f85f6eb43c
Parents: f1c1241
Author: Sheng Yang <[email protected]>
Authored: Thu Feb 7 20:23:10 2013 -0800
Committer: Sheng Yang <[email protected]>
Committed: Thu Feb 7 20:23:10 2013 -0800

----------------------------------------------------------------------
 .../cloud/api/commands/CreateVlanIpRangeCmd.java   |   45 +++++++-
 api/src/com/cloud/network/NetworkModel.java        |    3 +
 .../configuration/ConfigurationManagerImpl.java    |   91 ++++++++++----
 server/src/com/cloud/network/NetworkModelImpl.java |   37 ++++++
 .../src/com/cloud/network/NetworkServiceImpl.java  |   35 +------
 .../com/cloud/network/MockNetworkModelImpl.java    |    9 ++
 6 files changed, 158 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/931372e5/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java 
b/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java
index 63eda63..4c4c730 100644
--- a/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java
+++ b/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java
@@ -69,7 +69,7 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
     @Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, 
description="optional parameter. Have to be specified for Direct Untagged vlan 
only.")
     private Long podId;
 
-    @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, 
required=true, description="the beginning IP address in the VLAN IP range")
+    @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, 
description="the beginning IP address in the VLAN IP range")
     private String startIp;
 
     @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, 
description="the ID or VID of the VLAN. If not specified," +
@@ -88,6 +88,19 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
     @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, 
description="the physical network id")
     private Long physicalNetworkId;
     
+    @Parameter(name=ApiConstants.START_IPV6, type=CommandType.STRING, 
description="the beginning IPv6 address in the IPv6 network range")
+    private String startIpv6;
+
+    @Parameter(name=ApiConstants.END_IPV6, type=CommandType.STRING, 
description="the ending IPv6 address in the IPv6 network range")
+    private String endIpv6;
+
+    @Parameter(name=ApiConstants.IP6_GATEWAY, type=CommandType.STRING, 
description="the gateway of the IPv6 network. Required " +
+            "for Shared networks and Isolated networks when it belongs to VPC")
+    private String ip6Gateway;
+    
+    @Parameter(name=ApiConstants.IP6_CIDR, type=CommandType.STRING, 
description="the CIDR of IPv6 network, must be at least /64")
+    private String ip6Cidr;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -135,6 +148,35 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
     public Long getProjectId() {
         return projectId;
     }
+    
+    public String getStartIpv6() {
+       if (startIpv6 == null) {
+               return null;
+       }
+        return startIpv6.toLowerCase();
+    }
+
+    public String getEndIpv6() {
+       if (endIpv6 == null) {
+               return null;
+       }
+        return endIpv6.toLowerCase();
+    }
+
+    public String getIp6Gateway() {
+       if (ip6Gateway == null) {
+               return null;
+       }
+        return ip6Gateway.toLowerCase();
+    }
+
+    public String getIp6Cidr() {
+       if (ip6Cidr == null) {
+               return null;
+       }
+        return ip6Cidr.toLowerCase();
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -146,7 +188,6 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
     public Long getPhysicalNetworkId() {
         return physicalNetworkId;
     }
-
     
     @Override
     public String getCommandName() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/931372e5/api/src/com/cloud/network/NetworkModel.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkModel.java 
b/api/src/com/cloud/network/NetworkModel.java
index d74a74e..d965a31 100644
--- a/api/src/com/cloud/network/NetworkModel.java
+++ b/api/src/com/cloud/network/NetworkModel.java
@@ -24,6 +24,7 @@ import java.util.Set;
 
 import com.cloud.dc.Vlan;
 import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.Provider;
@@ -250,4 +251,6 @@ public interface NetworkModel {
        boolean isIP6AddressAvailableInNetwork(long networkId);
 
        boolean isIP6AddressAvailableInVlan(long vlanId);
+
+       void checkIp6Parameters(String startIPv6, String endIPv6, String 
ip6Gateway, String ip6Cidr) throws InvalidParameterValueException;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/931372e5/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 a8eec4c..78087f2 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2078,8 +2078,20 @@ public class ConfigurationManagerImpl implements 
ConfigurationManager, Configura
         String accountName = cmd.getAccountName();
         Long projectId = cmd.getProjectId();
         Long domainId = cmd.getDomainId();
+        String startIPv6 = cmd.getStartIpv6();
+        String endIPv6 = cmd.getEndIpv6();
+        String ip6Gateway = cmd.getIp6Gateway();
+        String ip6Cidr = cmd.getIp6Cidr();
+        
         Account vlanOwner = null;
+        
+        boolean ipv4 = (startIP != null);
+        boolean ipv6 = (startIPv6 != null);
 
+        if (!ipv4 && !ipv6) {
+               throw new InvalidParameterValueException("StartIP or StartIPv6 
is missing in the parameters!");
+        }
+        
         if (projectId != null) {
             if (accountName != null) {
                 throw new InvalidParameterValueException("Account and 
projectId are mutually exclusive");
@@ -2109,6 +2121,8 @@ public class ConfigurationManagerImpl implements 
ConfigurationManager, Configura
                 zoneId = network.getDataCenterId();
                 physicalNetworkId = network.getPhysicalNetworkId();
             }
+        } else if (ipv6) {
+               throw new InvalidParameterValueException("Only support IPv6 on 
extending existed network");
         }
         
         // Verify that zone exists
@@ -2117,6 +2131,11 @@ public class ConfigurationManagerImpl implements 
ConfigurationManager, Configura
             throw new InvalidParameterValueException("Unable to find zone by 
id " + zoneId);
         }
 
+        if (ipv6) {
+               if (network.getGuestType() != GuestType.Shared || 
zone.isSecurityGroupEnabled()) {
+                       throw new InvalidParameterValueException("Only support 
IPv6 on extending existed share network without SG");
+               }
+        }
         // verify that physical network exists
         PhysicalNetworkVO pNtwk = null;
         if (physicalNetworkId != null) {
@@ -2163,7 +2182,7 @@ public class ConfigurationManagerImpl implements 
ConfigurationManager, Configura
         if (zone.isSecurityGroupEnabled() && zone.getNetworkType() != 
DataCenter.NetworkType.Basic && forVirtualNetwork) {
             throw new InvalidParameterValueException("Can't add virtual ip 
range into a zone with security group enabled");
         }
-
+        
         // If networkId is not specified, and vlan is Virtual or Direct 
Untagged, try to locate default networks
         if (forVirtualNetwork) {
             if (network == null) {
@@ -2195,37 +2214,55 @@ public class ConfigurationManagerImpl implements 
ConfigurationManager, Configura
             throw new InvalidParameterValueException("Network " + network + " 
doesn't support adding ip ranges");
         }
 
-        // if end ip is not specified, default it to startIp
-        if (endIP == null && startIP != null) {
-            endIP = startIP;
+        if (ipv4) {
+               // if end ip is not specified, default it to startIp
+               if (endIP == null && startIP != null) {
+                       endIP = startIP;
+               }
         }
-
+        
         if (forVirtualNetwork || zone.getNetworkType() == 
DataCenter.NetworkType.Basic || zone.isSecurityGroupEnabled()) {
             if (vlanGateway == null || vlanNetmask == null || zoneId == null) {
                 throw new InvalidParameterValueException("Gateway, netmask and 
zoneId have to be passed in for virtual and direct untagged networks");
             }
         } else {
-            // check if startIp and endIp belong to network Cidr
-            String networkCidr = network.getCidr();
-            String networkGateway = network.getGateway();
-            Long networkZoneId = network.getDataCenterId();
-            String networkNetmask = NetUtils.getCidrNetmask(networkCidr);
-
-            // Check if ip addresses are in network range
-            if (!NetUtils.sameSubnet(startIP, networkGateway, networkNetmask)) 
{
-                throw new InvalidParameterValueException("Start ip is not in 
network cidr: " + networkCidr);
-            }
+               if (ipv4) {
+                       // check if startIp and endIp belong to network Cidr
+                       String networkCidr = network.getCidr();
+                       String networkGateway = network.getGateway();
+                       Long networkZoneId = network.getDataCenterId();
+                       String networkNetmask = 
NetUtils.getCidrNetmask(networkCidr);
+
+                       // Check if ip addresses are in network range
+                       if (!NetUtils.sameSubnet(startIP, networkGateway, 
networkNetmask)) {
+                               throw new InvalidParameterValueException("Start 
ip is not in network cidr: " + networkCidr);
+                       }
 
-            if (endIP != null) {
-                if (!NetUtils.sameSubnet(endIP, networkGateway, 
networkNetmask)) {
-                    throw new InvalidParameterValueException("End ip is not in 
network cidr: " + networkCidr);
-                }
-            }
+                       if (endIP != null) {
+                               if (!NetUtils.sameSubnet(endIP, networkGateway, 
networkNetmask)) {
+                                       throw new 
InvalidParameterValueException("End ip is not in network cidr: " + networkCidr);
+                               }
+                       }
 
-            // set gateway, netmask, zone from network object
-            vlanGateway = networkGateway;
-            vlanNetmask = networkNetmask;
-            zoneId = networkZoneId;
+                       // set gateway, netmask, zone from network object
+                       vlanGateway = networkGateway;
+                       vlanNetmask = networkNetmask;
+                       zoneId = networkZoneId;
+               }
+               if (ipv6) {
+                       if (endIPv6 == null) {
+                               endIPv6 = startIPv6;
+                       }
+                       if (ip6Gateway != null && 
!ip6Gateway.equals(network.getIp6Gateway())) {
+                               throw new InvalidParameterValueException("The 
input gateway " + ip6Gateway + " is not same as network gateway " + 
network.getIp6Gateway());
+                       }
+                       if (ip6Cidr != null && 
!ip6Cidr.equals(network.getIp6Cidr())) {
+                               throw new InvalidParameterValueException("The 
input cidr " + ip6Cidr + " is not same as network ciddr " + 
network.getIp6Cidr());
+                       }
+                       ip6Gateway = network.getIp6Gateway();
+                       ip6Cidr = network.getIp6Cidr();
+                       _networkModel.checkIp6Parameters(startIPv6, endIPv6, 
ip6Gateway, ip6Cidr);
+               }
         }
 
         // if it's an account specific range, associate ip address list to the 
account
@@ -2244,12 +2281,14 @@ public class ConfigurationManagerImpl implements 
ConfigurationManager, Configura
         }
 
         // Check if the IP range overlaps with the private ip
-        checkOverlapPrivateIpRange(zoneId, startIP, endIP);
+        if (ipv4) {
+               checkOverlapPrivateIpRange(zoneId, startIP, endIP);
+        }
         Transaction txn = Transaction.currentTxn();
         txn.start();
 
         Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, 
physicalNetworkId, forVirtualNetwork, podId, startIP, 
-                endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner, null, 
null, null, null);
+                endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner, startIPv6, 
endIPv6, ip6Gateway, ip6Cidr);
 
         if (associateIpRangeToAccount) {
             _networkMgr.associateIpAddressListToAccount(userId, 
vlanOwner.getId(), zoneId, vlan.getId(), null);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/931372e5/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java 
b/server/src/com/cloud/network/NetworkModelImpl.java
index ac11a19..510b4cf 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -1867,4 +1867,41 @@ public class NetworkModelImpl  implements NetworkModel, 
Manager{
         
         return null;
     }
+    
+    @Override
+       public void checkIp6Parameters(String startIPv6, String endIPv6,
+                       String ip6Gateway, String ip6Cidr) throws 
InvalidParameterValueException {
+               if (!NetUtils.isValidIpv6(startIPv6)) {
+                       throw new InvalidParameterValueException("Invalid 
format for the startIPv6 parameter");
+               }
+               if (!NetUtils.isValidIpv6(endIPv6)) {
+                       throw new InvalidParameterValueException("Invalid 
format for the endIPv6 parameter");
+               }
+
+               if (!(ip6Gateway != null && ip6Cidr != null)) {
+                       throw new InvalidParameterValueException("ip6Gateway 
and ip6Cidr should be defined when startIPv6/endIPv6 are passed in");
+               }
+
+               if (!NetUtils.isValidIpv6(ip6Gateway)) {
+                       throw new InvalidParameterValueException("Invalid 
ip6Gateway");
+               }
+               if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
+                       throw new InvalidParameterValueException("Invalid 
ip6cidr");
+               }
+               if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
+                       throw new InvalidParameterValueException("startIPv6 is 
not in ip6cidr indicated network!");
+               }
+               if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
+                       throw new InvalidParameterValueException("endIPv6 is 
not in ip6cidr indicated network!");
+               }
+               if (!NetUtils.isIp6InNetwork(ip6Gateway, ip6Cidr)) {
+                       throw new InvalidParameterValueException("ip6Gateway is 
not in ip6cidr indicated network!");
+               }
+
+               int cidrSize = NetUtils.getIp6CidrSize(ip6Cidr);
+               // Ipv6 cidr limit should be at least /64
+               if (cidrSize < 64) {
+                       throw new InvalidParameterValueException("The cidr size 
of IPv6 network must be no less than 64 bits!");
+               }
+       }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/931372e5/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 045a333..eb91063 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -806,43 +806,11 @@ public class NetworkServiceImpl implements  
NetworkService, Manager {
         }
         
         if (ipv6) {
-               if (!NetUtils.isValidIpv6(startIPv6)) {
-                       throw new InvalidParameterValueException("Invalid 
format for the startIPv6 parameter");
-               }
                if (endIPv6 == null) {
                        endIPv6 = startIPv6;
-               } else if (!NetUtils.isValidIpv6(endIPv6)) {
-                       throw new InvalidParameterValueException("Invalid 
format for the endIPv6 parameter");
-               }
-               
-               if (!(ip6Gateway != null && ip6Cidr != null)) {
-                       throw new InvalidParameterValueException("ip6Gateway 
and ip6Cidr should be defined when startIPv6/endIPv6 are passed in");
-               }
-               
-               if (!NetUtils.isValidIpv6(ip6Gateway)) {
-                       throw new InvalidParameterValueException("Invalid 
ip6Gateway");
-               }
-               if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
-                       throw new InvalidParameterValueException("Invalid 
ip6cidr");
-               }
-               if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
-                       throw new InvalidParameterValueException("startIPv6 is 
not in ip6cidr indicated network!");
-               }
-               if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
-                       throw new InvalidParameterValueException("endIPv6 is 
not in ip6cidr indicated network!");
-               }
-               if (!NetUtils.isIp6InNetwork(ip6Gateway, ip6Cidr)) {
-                       throw new InvalidParameterValueException("ip6Gateway is 
not in ip6cidr indicated network!");
                }
+               _networkModel.checkIp6Parameters(startIPv6, endIPv6, 
ip6Gateway, ip6Cidr);
                
-               int cidrSize = NetUtils.getIp6CidrSize(ip6Cidr);
-               // Ipv6 cidr limit should be at least /64
-               if (cidrSize < 64) {
-                       throw new InvalidParameterValueException("The cidr size 
of IPv6 network must be no less than 64 bits!");
-               }
-        }
-
-        if (ipv6) {
                if (zone.getNetworkType() != NetworkType.Advanced || 
ntwkOff.getGuestType() != Network.GuestType.Shared) {
                        throw new InvalidParameterValueException("Can only 
support create IPv6 network with advance shared network!");
                }
@@ -2973,5 +2941,4 @@ public class NetworkServiceImpl implements  
NetworkService, Manager {
         }
         return null;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/931372e5/server/test/com/cloud/network/MockNetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java 
b/server/test/com/cloud/network/MockNetworkModelImpl.java
index 5c1343f..3566ab9 100644
--- a/server/test/com/cloud/network/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/network/MockNetworkModelImpl.java
@@ -27,6 +27,7 @@ import javax.naming.ConfigurationException;
 
 import com.cloud.dc.Vlan;
 import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.GuestType;
@@ -808,4 +809,12 @@ public class MockNetworkModelImpl implements NetworkModel, 
Manager {
                // TODO Auto-generated method stub
                return false;
        }
+
+       @Override
+       public void checkIp6Parameters(String startIPv6, String endIPv6,
+                       String ip6Gateway, String ip6Cidr)
+                       throws InvalidParameterValueException {
+               // TODO Auto-generated method stub
+               
+       }
 }

Reply via email to