cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject [1/48] IPv6: Accept IPv6 parameter for createNetworkCmd
Date Fri, 01 Feb 2013 06:11:34 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index b290c1d..d6a8812 100755
--- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
@@ -42,7 +42,9 @@ import com.cloud.network.NetworkVO;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.Mode;
 import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.PublicIpv6AddressVO;
 import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.PublicIpv6AddressDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.user.Account;
@@ -72,6 +74,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
     IPAddressDao _ipAddressDao;
     @Inject
     NetworkOfferingDao _networkOfferingDao;
+    @Inject
+    PublicIpv6AddressDao _ipv6Dao;
     
     private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
     
@@ -120,11 +124,20 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
                 throw new InvalidParameterValueException("cidr and gateway must be specified
together.");
             }
 
+            if ((userSpecified.getIp6Cidr() == null && userSpecified.getIp6Gateway()
!= null) || (userSpecified.getIp6Cidr() != null && userSpecified.getIp6Gateway() ==
null)) {
+                throw new InvalidParameterValueException("cidrv6 and gatewayv6 must be specified
together.");
+            }
+
             if (userSpecified.getCidr() != null) {
                 config.setCidr(userSpecified.getCidr());
                 config.setGateway(userSpecified.getGateway());
             }
 
+            if (userSpecified.getIp6Cidr() != null) {
+                config.setIp6Cidr(userSpecified.getIp6Cidr());
+                config.setIp6Gateway(userSpecified.getIp6Gateway());
+            }
+
             if (userSpecified.getBroadcastUri() != null) {
                 config.setBroadcastUri(userSpecified.getBroadcastUri());
                 config.setState(State.Setup);
@@ -137,6 +150,9 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
 
         boolean isSecurityGroupEnabled = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(),
Service.SecurityGroup);
         if (isSecurityGroupEnabled) {
+        	if (userSpecified.getIp6Cidr() != null) {
+                throw new InvalidParameterValueException("Didn't support security group with
IPv6");
+        	}
             config.setName("SecurityGroupEnabledNetwork");
             config.setDisplayText("SecurityGroupEnabledNetwork");
         }
@@ -165,13 +181,13 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
 
         if (nic == null) {
             nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
-        } else if (nic.getIp4Address() == null) {
+        } else if (nic.getIp4Address() == null && nic.getIp6Address() == null) {
             nic.setStrategy(ReservationStrategy.Start);
         } else {
             nic.setStrategy(ReservationStrategy.Create);
         }
 
-        _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp());
+        _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIpv4(), nic.getRequestedIpv6());
         nic.setStrategy(ReservationStrategy.Create);
 
         return nic;
@@ -180,8 +196,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
     @Override
     public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends
VirtualMachine> vm, DeployDestination dest, ReservationContext context)
             throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException,
ConcurrentOperationException {
-        if (nic.getIp4Address() == null) {
-            _networkMgr.allocateDirectIp(nic, dest.getDataCenter(), vm, network, null);
+        if (nic.getIp4Address() == null && nic.getIp6Address() == null) {
+            _networkMgr.allocateDirectIp(nic, dest.getDataCenter(), vm, network, null, null);
             nic.setStrategy(ReservationStrategy.Create);
         }
     }
@@ -202,14 +218,23 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
             s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip:
" + nic.getIp4Address());
         }
     	
-        IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
-        if (ip != null) {
-            Transaction txn = Transaction.currentTxn();
-            txn.start();
-            _networkMgr.markIpAsUnavailable(ip.getId());
-            _ipAddressDao.unassignIpAddress(ip.getId());
-            txn.commit();
-        }
+    	if (nic.getIp4Address() != null) {
+    		IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
+    		if (ip != null) {
+    			Transaction txn = Transaction.currentTxn();
+    			txn.start();
+    			_networkMgr.markIpAsUnavailable(ip.getId());
+    			_ipAddressDao.unassignIpAddress(ip.getId());
+    			txn.commit();
+    		}
+    	}
+    	
+    	if (nic.getIp6Address() != null) {
+    		PublicIpv6AddressVO ip = _ipv6Dao.findByDcIdAndIp(network.getDataCenterId(), nic.getIp6Address());
+    		if (ip != null) {
+    			_ipv6Dao.remove(ip.getId());
+    		}
+    	}
         nic.deallocate();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
index 8ca4547..709d280 100755
--- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
@@ -96,7 +96,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
             rsStrategy = ReservationStrategy.Create;
         }
         
-        if (nic != null && nic.getRequestedIp() != null) {
+        if (nic != null && nic.getRequestedIpv4() != null) {
             throw new CloudRuntimeException("Does not support custom ip allocation at this
time: " + nic);
         }
        

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
index f8a8a95..7a09d94 100644
--- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
@@ -195,7 +195,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
     public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile<?
extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
             InsufficientAddressCapacityException {
 
-        if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(),
config.getId()) && nic != null && nic.getRequestedIp() != null) {
+        if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(),
config.getId()) && nic != null && nic.getRequestedIpv4() != null) {
             throw new CloudRuntimeException("Does not support custom ip allocation at this
time: " + nic);
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/guru/GuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
index 9587885..79ab87b 100755
--- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
@@ -352,7 +352,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements
NetworkGur
 
             String guestIp = null;
             if (network.getSpecifyIpRanges()) {
-                _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp());
+                _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIpv4(),
null);
             } else {
                 //if Vm is router vm and source nat is enabled in the network, set ip4 to
the network gateway
                 boolean isGateway = false;
@@ -371,7 +371,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements
NetworkGur
                 if (isGateway) {
                     guestIp = network.getGateway();
                 } else {
-                    guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp());
+                    guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIpv4());
                     if (guestIp == null) {
                         throw new InsufficientVirtualNetworkCapcityException("Unable to acquire
Guest IP" +
                                 " address for network " + network, DataCenter.class, dc.getId());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java
index b513325..bbe568d 100755
--- a/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java
@@ -100,7 +100,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru
{
         assert trafficType == TrafficType.Management || trafficType == TrafficType.Storage:
"Well, I can't take care of this config now can I? " + config; 
         
         if (nic != null) {
-            if (nic.getRequestedIp() != null) {
+            if (nic.getRequestedIpv4() != null) {
                 throw new CloudRuntimeException("Does not support custom ip allocation at
this time: " + nic);
             }
             nic.setStrategy(nic.getIp4Address() != null ? ReservationStrategy.Create : ReservationStrategy.Start);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/guru/PublicNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/PublicNetworkGuru.java b/server/src/com/cloud/network/guru/PublicNetworkGuru.java
index ddee5a5..8e912d6 100755
--- a/server/src/com/cloud/network/guru/PublicNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/PublicNetworkGuru.java
@@ -142,7 +142,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru
{
 
         DataCenter dc = _dcDao.findById(network.getDataCenterId());       
 
-        if (nic != null && nic.getRequestedIp() != null) {
+        if (nic != null && nic.getRequestedIpv4() != null) {
             throw new CloudRuntimeException("Does not support custom ip allocation at this
time: " + nic);
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index e1c78e1..c0e7888 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -1656,7 +1656,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
                 }
             }
 
-            NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp);
+            NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, null);
             if (setupPublicNetwork) {
                 if (isRedundant) {
                     gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork,
null));
@@ -3018,11 +3018,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
     }
     
     private void createDhcpEntryCommand(VirtualRouter router, UserVm vm, NicVO nic, Commands
cmds) {
-        DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(),
vm.getHostName());
+        DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(),
vm.getHostName(), nic.getIp6Address());
         DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn());
         String gatewayIp = findGatewayIp(vm.getId());
         boolean needGateway = true;
-        if (!gatewayIp.equals(nic.getGateway())) {
+        if (gatewayIp != null && !gatewayIp.equals(nic.getGateway())) {
             needGateway = false;
             GuestOSVO guestOS = _guestOSDao.findById(vm.getGuestOSId());
             // Do set dhcp:router option for non-default nic on certain OS(including Windows),
and leave other OS unset.
@@ -3038,7 +3038,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             gatewayIp = "0.0.0.0";
         }
         dhcpCommand.setDefaultRouter(gatewayIp);
+        dhcpCommand.setIp6Gateway(nic.getIp6Gateway());
         dhcpCommand.setDefaultDns(findDefaultDnsIp(vm.getId()));
+        dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
 
         dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
         dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index fa6bd30..26e882e 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -1884,7 +1884,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
 
         //2) Create network
         Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText,
gateway, cidr, vlanId, 
-                networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess,
vpcId);
+                networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess,
vpcId, null, null);
 
         return guestNetwork;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/vm/NicVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/NicVO.java b/server/src/com/cloud/vm/NicVO.java
index 64b9153..8e2edda 100644
--- a/server/src/com/cloud/vm/NicVO.java
+++ b/server/src/com/cloud/vm/NicVO.java
@@ -99,6 +99,12 @@ public class NicVO implements Nic {
     @Column(name = "default_nic")
     boolean defaultNic;
 
+    @Column(name = "ip6_gateway")
+    String ip6Gateway;
+
+    @Column(name = "ip6_cidr")
+    String ip6Cidr;
+
     @Column(name = "strategy")
     @Enumerated(value = EnumType.STRING)
     ReservationStrategy reservationStrategy;
@@ -156,6 +162,7 @@ public class NicVO implements Nic {
         this.defaultNic = defaultNic;
     }
 
+    @Override
     public String getIp6Address() {
         return ip6Address;
     }
@@ -324,4 +331,22 @@ public class NicVO implements Nic {
     public void setUuid(String uuid) {
     	this.uuid = uuid;
     }
+
+    @Override
+	public String getIp6Gateway() {
+		return ip6Gateway;
+	}
+
+	public void setIp6Gateway(String ip6Gateway) {
+		this.ip6Gateway = ip6Gateway;
+	}
+
+    @Override
+	public String getIp6Cidr() {
+		return ip6Cidr;
+	}
+
+	public void setIp6Cidr(String ip6Cidr) {
+		this.ip6Cidr = ip6Cidr;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 5891056..870eecc 100644
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2184,7 +2184,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                     s_logger.debug("Creating network for account " + owner + " from the network
offering id=" +requiredOfferings.get(0).getId() + " as a part of deployVM process");
                     Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(),
                             owner.getAccountName() + "-network", owner.getAccountName() +
"-network", null, null,
-                            null, null, owner, null, physicalNetwork, zone.getId(), ACLType.Account,
null, null);
+                            null, null, owner, null, physicalNetwork, zone.getId(), ACLType.Account,
null, null, null, null);
                     defaultNetwork = _networkDao.findById(newNetwork.getId());
                 } else if (virtualNetworks.size() > 1) {
                     throw new InvalidParameterValueException("More than 1 default Isolated
networks are found for account " + owner + "; please specify networkIds");
@@ -2372,13 +2372,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                 requestedIp = requestedIps.get(network.getId());
             }
 
-            NicProfile profile = new NicProfile(requestedIp);
+            NicProfile profile = new NicProfile(requestedIp, null);
 
             if (defaultNetworkNumber == 0) {
                 defaultNetworkNumber++;
                 // if user requested specific ip for default network, add it
                 if (defaultNetworkIp != null) {
-                    profile = new NicProfile(defaultNetworkIp);
+                    profile = new NicProfile(defaultNetworkIp, null);
                 }
 
                 profile.setDefaultNic(true);
@@ -3543,7 +3543,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                         requiredOfferings.get(0).getId() + " as a part of deployVM process");
                             Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(),
                                     newAccount.getAccountName() + "-network", newAccount.getAccountName()
+ "-network", null, null,
-                                    null, null, newAccount, null, physicalNetwork, zone.getId(),
ACLType.Account, null, null);
+                                    null, null, newAccount, null, physicalNetwork, zone.getId(),
ACLType.Account, null, null, null, null);
                             defaultNetwork = _networkDao.findById(newNetwork.getId());
                         } else if (virtualNetworks.size() > 1) {
                             throw new InvalidParameterValueException("More than 1 default
Isolated networks are found " +

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index ef5b9c9..df409a8 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -247,7 +247,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager,
NetworkS
 
     @Override
     public Network createGuestNetwork(long networkOfferingId, String name, String displayText,
String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId,
-            PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess,
Long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException
{
+            PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess,
Long vpcId, String gatewayv6, String cidrv6) throws ConcurrentOperationException, InsufficientCapacityException,
ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -660,7 +660,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager,
NetworkS
      */
     @Override
     public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<?
extends VirtualMachine> vm,
-            Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
+            Network network, String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException,
             InsufficientAddressCapacityException {
         // TODO Auto-generated method stub
         
@@ -818,4 +818,12 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager,
NetworkS
         // TODO Auto-generated method stub
         return null;
     }
+
+	@Override
+	public PublicIpv6Address assignPublicIp6Address(long dcId, Long podId,
+			Account owner, VlanType type, Long networkId, String requestedIpv6,
+			boolean isSystem) throws InsufficientAddressCapacityException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/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 1771660..07c6247 100644
--- a/server/test/com/cloud/network/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/network/MockNetworkModelImpl.java
@@ -806,4 +806,10 @@ public class MockNetworkModelImpl implements NetworkModel, Manager {
         return false;
     }
 
+	@Override
+	public Vlan getVlanForNetwork(long networkId) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
index 3989ecf..d0f0c62 100644
--- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
@@ -493,7 +493,7 @@ public class MockConfigurationManagerImpl implements ConfigurationManager,
Confi
      */
     @Override
     public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId,
boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, String
vlanNetmask, String vlanId,
-            Account vlanOwner) throws InsufficientCapacityException, ConcurrentOperationException,
InvalidParameterValueException {
+            Account vlanOwner, String startIPv6, String endIPv6, String vlanGatewayv6, String
vlanCidrv6) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException
{
         // TODO Auto-generated method stub
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index b4e1794..13426e6 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -56,6 +56,7 @@ import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetworkServiceProvider;
 import com.cloud.network.PhysicalNetworkTrafficType;
 import com.cloud.network.PublicIpAddress;
+import com.cloud.network.PublicIpv6Address;
 import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.network.element.LoadBalancingServiceProvider;
@@ -846,7 +847,7 @@ public class MockNetworkManagerImpl implements NetworkManager, NetworkService,
M
     @Override
     public Network createGuestNetwork(long networkOfferingId, String name, String displayText,
String gateway,
             String cidr, String vlanId, String networkDomain, Account owner, Long domainId,
-            PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess,
Long vpcId)
+            PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess,
Long vpcId, String gatewayv6, String cidrv6)
             throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException
{
         // TODO Auto-generated method stub
         return null;
@@ -1011,10 +1012,9 @@ public class MockNetworkManagerImpl implements NetworkManager, NetworkService,
M
      */
     @Override
     public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<?
extends VirtualMachine> vm,
-            Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
+            Network network, String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException,
             InsufficientAddressCapacityException {
         // TODO Auto-generated method stub
-        
     }
 
 
@@ -1313,10 +1313,6 @@ public class MockNetworkManagerImpl implements NetworkManager, NetworkService,
M
         return null;
     }
 
-
-
-
-
     /* (non-Javadoc)
      * @see com.cloud.network.NetworkService#getNetwork(java.lang.String)
      */
@@ -1325,4 +1321,12 @@ public class MockNetworkManagerImpl implements NetworkManager, NetworkService,
M
         // TODO Auto-generated method stub
         return null;
     }
+
+	@Override
+	public PublicIpv6Address assignPublicIp6Address(long dcId, Long podId,
+			Account owner, VlanType type, Long networkId, String requestedIpv6,
+			boolean isSystem) throws InsufficientAddressCapacityException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/setup/db/create-schema.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 174f53c..db3a8a5 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -207,6 +207,8 @@ CREATE TABLE `cloud`.`networks` (
   `broadcast_uri` varchar(255) COMMENT 'broadcast domain specifier',
   `gateway` varchar(15) COMMENT 'gateway for this network configuration',
   `cidr` varchar(18) COMMENT 'network cidr', 
+  `ip6_gateway` varchar(50) COMMENT 'IPv6 gateway for this network', 
+  `ip6_cidr` varchar(50) COMMENT 'IPv6 cidr for this network',
   `mode` varchar(32) COMMENT 'How to retrieve ip address in this network',
   `network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id that this configuration
is created from',
   `physical_network_id` bigint unsigned COMMENT 'physical network id that this configuration
is based on',
@@ -270,6 +272,8 @@ CREATE TABLE `cloud`.`nics` (
   `update_time` timestamp NOT NULL COMMENT 'time the state was changed',
   `isolation_uri` varchar(255) COMMENT 'id for isolation',
   `ip6_address` char(40) COMMENT 'ip6 address',
+  `ip6_gateway` varchar(50) COMMENT 'gateway for ip6 address',
+  `ip6_cidr` varchar(50) COMMENT 'cidr for ip6 address',
   `default_nic` tinyint NOT NULL COMMENT "None", 
   `vm_type` varchar(32) COMMENT 'type of vm: System or User vm',
   `created` datetime NOT NULL COMMENT 'date created',
@@ -500,7 +504,10 @@ CREATE TABLE `cloud`.`vlan` (
   `vlan_id` varchar(255),
   `vlan_gateway` varchar(255),
   `vlan_netmask` varchar(255),
+  `ip6_gateway` varchar(255),
+  `ip6_cidr` varchar(255),
   `description` varchar(255),
+  `ip6_range` varchar(255),
   `vlan_type` varchar(255),
   `data_center_id` bigint unsigned NOT NULL,
   `network_id` bigint unsigned NOT NULL COMMENT 'id of corresponding network offering',
@@ -2543,5 +2550,30 @@ INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created)
VALUES (2,
 INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (3, UUID(),
'snmp','Linux CPU Idle - percentage', '1.3.6.1.4.1.2021.11.11.0', now());
 INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (100, UUID(),
'netscaler','Response Time - microseconds', 'RESPTIME', now());
 
+CREATE TABLE  `cloud`.`public_ipv6_address` (
+  `id` bigint unsigned NOT NULL UNIQUE auto_increment,
+  `uuid` varchar(40),
+  `account_id` bigint unsigned NULL,
+  `domain_id` bigint unsigned NULL,
+  `ip_address` char(50) NOT NULL,
+  `data_center_id` bigint unsigned NOT NULL COMMENT 'zone that it belongs to',
+  `vlan_id` bigint unsigned NOT NULL,
+  `state` char(32) NOT NULL default 'Free' COMMENT 'state of the ip address',
+  `mac_address` varchar(40) NOT NULL COMMENT 'mac address of this ip',
+  `source_network_id` bigint unsigned NOT NULL COMMENT 'network id ip belongs to',
+  `network_id` bigint unsigned COMMENT 'network this public ip address is associated with',
+  `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id that this configuration
is based on',
+  `created` datetime NULL COMMENT 'Date this ip was allocated to someone',
+  PRIMARY KEY (`id`),
+  UNIQUE (`ip_address`, `source_network_id`),
+  CONSTRAINT `fk_public_ipv6_address__source_network_id` FOREIGN KEY (`source_network_id`)
REFERENCES `networks`(`id`),
+  CONSTRAINT `fk_public_ipv6_address__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`),
+  CONSTRAINT `fk_public_ipv6_address__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`),
+  CONSTRAINT `fk_public_ipv6_address__vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `vlan`(`id`)
ON DELETE CASCADE,
+  CONSTRAINT `fk_public_ipv6_address__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES
`data_center`(`id`) ON DELETE CASCADE,
+  CONSTRAINT `uc_public_ipv6_address__uuid` UNIQUE (`uuid`),
+  CONSTRAINT `fk_public_ipv6_address__physical_network_id` FOREIGN KEY (`physical_network_id`)
REFERENCES `physical_network`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 SET foreign_key_checks = 1;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/utils/pom.xml
----------------------------------------------------------------------
diff --git a/utils/pom.xml b/utils/pom.xml
index 87c078a..6f45044 100644
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -129,6 +129,11 @@
       <version>${cs.ejb.version}</version>
     </dependency>
     <dependency>
+        <groupId>com.googlecode.java-ipv6</groupId>
+        <artifactId>java-ipv6</artifactId>
+        <version>${cs.java-ipv6.version}</version>
+    </dependency>
+    <dependency>
       <groupId>commons-configuration</groupId>
       <artifactId>commons-configuration</artifactId>
       <version>${cs.configuration.version}</version>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/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 c456cdc..8bfd376 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -41,6 +41,9 @@ import java.util.regex.Pattern;
 import org.apache.log4j.Logger;
 import org.apache.log4j.xml.DOMConfigurator;
 
+import com.googlecode.ipv6.IPv6Address;
+import com.googlecode.ipv6.IPv6Network;
+
 import com.cloud.utils.IteratorUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.script.Script;
@@ -1142,4 +1145,73 @@ public class NetUtils {
         
         return true;
     }
+
+	public static boolean isValidIPv6(String ip) {
+		try {
+			IPv6Address address = IPv6Address.fromString(ip);
+		} catch (IllegalArgumentException ex) {
+			return false;
+		}
+		return true;
+	}
+
+	public static boolean isValidIp6Cidr(String ip6Cidr) {
+		try {
+			IPv6Network network = IPv6Network.fromString(ip6Cidr);
+		} catch (IllegalArgumentException ex) {
+			return false;
+		}
+		return true;
+	}
+
+	public static int getIp6CidrSize(String ip6Cidr) {
+		IPv6Network network = null;
+		try {
+			network = IPv6Network.fromString(ip6Cidr);
+		} catch (IllegalArgumentException ex) {
+			return 0;
+		}
+		return network.getNetmask().asPrefixLength();
+	}
+
+	//FIXME: only able to cover lower 32 bits
+	public static String getIp6FromRange(String ip6Range) {
+    	String[] ips = ip6Range.split("-");
+    	String startIp = ips[0];
+    	long gap = countIp6InRange(ip6Range);
+    	IPv6Address start = IPv6Address.fromString(startIp);
+    	// Find a random number based on lower 32 bits
+    	int d = _rand.nextInt((int)(gap % Integer.MAX_VALUE));
+    	// And a number based on the difference of lower 32 bits
+    	IPv6Address ip = start.add(d);
+    	return ip.toString();
+	}
+
+	//RFC3315, section 9.4
+	public static String getDuidLL(String macAddress) {
+		String duid = "00:03:00:06:" + macAddress;
+		return duid;
+	}
+	
+	//FIXME: only able to cover lower 64 bits
+	public static long countIp6InRange(String ip6Range) {
+    	String[] ips = ip6Range.split("-");
+    	String startIp = ips[0];
+    	String endIp = null;
+    	if (ips.length > 1) {
+    		endIp = ips[1];
+    	}
+    	IPv6Address start, end;
+    	try {
+    		start = IPv6Address.fromString(startIp);
+    		end = IPv6Address.fromString(endIp);
+		} catch (IllegalArgumentException ex) {
+			return 0;
+		}
+    	long startLow = start.getLowBits(), endLow = end.getLowBits();
+    	if (startLow > endLow) {
+    		return 0;
+    	}
+    	return endLow - startLow + 1;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4bc025/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 1eccba3..6290cd6 100644
--- a/utils/test/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java
@@ -69,4 +69,18 @@ public class NetUtilsTest extends TestCase {
         assertFalse(NetUtils.isValidS2SVpnPolicy(";modp1536"));
         assertFalse(NetUtils.isValidS2SVpnPolicy(",aes;modp1536,,,"));
     }
+    
+    public void testIpv6() {
+    	assertTrue(NetUtils.isValidIPv6("fc00::1"));
+    	assertFalse(NetUtils.isValidIPv6(""));
+    	assertFalse(NetUtils.isValidIPv6(null));
+    	assertFalse(NetUtils.isValidIPv6("1234:5678::1/64"));
+    	assertTrue(NetUtils.isValidIp6Cidr("1234:5678::1/64"));
+    	assertFalse(NetUtils.isValidIp6Cidr("1234:5678::1"));
+    	assertEquals(NetUtils.getIp6CidrSize("1234:5678::1/32"), 32);
+    	assertEquals(NetUtils.getIp6CidrSize("1234:5678::1"), 0);
+    	assertEquals(NetUtils.countIp6InRange("1234:5678::1-1234:5678::2"), 2);
+    	assertEquals(NetUtils.countIp6InRange("1234:5678::2-1234:5678::0"), 0);
+    	assertEquals(NetUtils.getIp6FromRange("1234:5678::1-1234:5678::1"), "1234:5678::1");
+    }
 }


Mime
View raw message