You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ya...@apache.org on 2013/02/08 23:48:20 UTC
[1/2] git commit: refs/heads/master - IPv6: CLOUDSTACK-1107: Add
support for createVlanIpRange to extend existed network
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/0c5c08b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0c5c08b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0c5c08b7
Branch: refs/heads/master
Commit: 0c5c08b78b099707c76b4e8dccde169ec9675ebe
Parents: 1cf85aa
Author: Sheng Yang <sh...@citrix.com>
Authored: Thu Feb 7 20:23:10 2013 -0800
Committer: Sheng Yang <sh...@citrix.com>
Committed: Fri Feb 8 14:48:08 2013 -0800
----------------------------------------------------------------------
api/src/com/cloud/network/NetworkModel.java | 3 +
.../command/admin/vlan/CreateVlanIpRangeCmd.java | 45 ++++++++-
.../configuration/ConfigurationManagerImpl.java | 76 ++++++++++++---
server/src/com/cloud/network/NetworkModelImpl.java | 36 +++++++
.../src/com/cloud/network/NetworkServiceImpl.java | 36 +-------
.../com/cloud/network/MockNetworkModelImpl.java | 9 ++
.../test/com/cloud/vpc/MockNetworkModelImpl.java | 7 ++
7 files changed, 159 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0c5c08b7/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 0432e4f..783e5cc 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;
@@ -252,4 +253,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/0c5c08b7/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java
index c5037df..541da1e 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java
@@ -75,7 +75,7 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
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," +
@@ -94,6 +94,19 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
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 ///////////////////////
/////////////////////////////////////////////////////
@@ -141,6 +154,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///////////////////
/////////////////////////////////////////////////////
@@ -153,7 +195,6 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
return physicalNetworkId;
}
-
@Override
public String getCommandName() {
return s_name;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0c5c08b7/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 750b8b8..074675c 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2073,13 +2073,34 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
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;
- // if end ip is not specified, default it to startIp
- if (endIP == null && startIP != null) {
- endIP = startIP;
+ boolean ipv4 = (startIP != null);
+ boolean ipv6 = (startIPv6 != null);
+
+ if (!ipv4 && !ipv6) {
+ throw new InvalidParameterValueException("StartIP or StartIPv6 is missing in the parameters!");
}
-
+
+ if (ipv4) {
+ // if end ip is not specified, default it to startIp
+ if (endIP == null && startIP != null) {
+ endIP = startIP;
+ }
+ }
+
+ if (ipv6) {
+ // if end ip is not specified, default it to startIp
+ if (endIPv6 == null && startIPv6 != null) {
+ endIPv6 = startIPv6;
+ }
+ }
+
if (projectId != null) {
if (accountName != null) {
throw new InvalidParameterValueException("Account and projectId are mutually exclusive");
@@ -2109,6 +2130,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
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 +2140,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
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 +2191,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
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) {
@@ -2196,11 +2224,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
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 ( zone.getNetworkType() == DataCenter.NetworkType.Advanced ) {
if (network.getTrafficType() == TrafficType.Guest) {
if (network.getGuestType() != GuestType.Shared) {
@@ -2216,19 +2239,38 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" +
+ network.getId() + ", only one vlan is allowed on guest network");
}
- vlanGateway = vlan.getVlanGateway();
- vlanNetmask = vlan.getVlanNetmask();
+ if (ipv4) {
+ vlanGateway = vlan.getVlanGateway();
+ vlanNetmask = vlan.getVlanNetmask();
+ // Check if ip addresses are in network range
+ if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) {
+ throw new InvalidParameterValueException("Start ip is not in vlan range!");
+ }
+ if (!NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) {
+ throw new InvalidParameterValueException("End ip is not in vlan range!");
+ }
+ }
+ if (ipv6) {
+ 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);
+ }
}
} else if (network.getTrafficType() == TrafficType.Management) {
throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
}
}
- if (vlanGateway == null || vlanNetmask == null || zoneId == null) {
+ if (zoneId == null || (ipv4 && (vlanGateway == null || vlanNetmask == null)) || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
}
-
// if it's an account specific range, associate ip address list to the account
boolean associateIpRangeToAccount = false;
@@ -2245,12 +2287,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
// 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/0c5c08b7/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 ce8fac7..ce48e84 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -1876,4 +1876,40 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
return offering.isInline();
}
+ @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!");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0c5c08b7/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 d38d1f8..050a1fe 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -761,43 +761,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
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");
}
+ _networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
- 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!");
- }
- }
-
- 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!");
}
@@ -2942,10 +2910,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return null;
}
-
@Override
public Network getNetwork(String networkUuid) {
return _networksDao.findByUuid(networkUuid);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0c5c08b7/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 1088321..a2bef63 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;
@@ -820,4 +821,12 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
// 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
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0c5c08b7/server/test/com/cloud/vpc/MockNetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java b/server/test/com/cloud/vpc/MockNetworkModelImpl.java
index aed54c7..3fad338 100644
--- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java
@@ -28,6 +28,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.IpAddress;
import com.cloud.network.Network;
@@ -835,4 +836,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
return false;
}
+ @Override
+ public void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr)
+ throws InvalidParameterValueException {
+ // TODO Auto-generated method stub
+ }
+
}