diff --git a/api/src/com/cloud/network/Site2SiteCustomerGateway.java b/api/src/com/cloud/network/Site2SiteCustomerGateway.java index 2de4ff2bcc8..f9a88bdd845 100644 --- a/api/src/com/cloud/network/Site2SiteCustomerGateway.java +++ b/api/src/com/cloud/network/Site2SiteCustomerGateway.java @@ -39,6 +39,8 @@ public interface Site2SiteCustomerGateway extends ControlledEntity, Identity, In public Boolean getDpd(); + public Boolean getEncap(); + public Date getRemoved(); String getName(); diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 4f689303705..ef4ff9a0fe9 100644 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -492,6 +492,7 @@ public class ApiConstants { public static final String IKE_LIFETIME = "ikelifetime"; public static final String ESP_LIFETIME = "esplifetime"; public static final String DPD = "dpd"; + public static final String FORCE_ENCAP = "forceencap"; public static final String FOR_VPC = "forvpc"; public static final String SHRINK_OK = "shrinkok"; public static final String NICIRA_NVP_DEVICE_ID = "nvpdeviceid"; @@ -642,4 +643,4 @@ public class ApiConstants { public enum VMDetails { all, group, nics, stats, secgrp, tmpl, servoff, diskoff, iso, volume, min, affgrp; } -} \ No newline at end of file +} diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java index 8bd0646ed39..0fb496cc043 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java @@ -75,6 +75,9 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { @Parameter(name = ApiConstants.DPD, type = CommandType.BOOLEAN, required = false, description = "If DPD is enabled for VPN connection") private Boolean dpd; + @Parameter(name = ApiConstants.FORCE_ENCAP, type = CommandType.BOOLEAN, required = false, description = "Force Encapsulation for NAT traversal") + private Boolean encap; + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account associated with the gateway. Must be used with the domainId parameter.") private String accountName; @@ -129,6 +132,8 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { return dpd; } + public Boolean getEncap() { return encap; } + public String getAccountName() { return accountName; } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java index ceb67d510a0..3b188b85ca9 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java @@ -81,6 +81,9 @@ public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd { @Parameter(name = ApiConstants.DPD, type = CommandType.BOOLEAN, required = false, description = "If DPD is enabled for VPN connection") private Boolean dpd; + @Parameter(name = ApiConstants.FORCE_ENCAP, type = CommandType.BOOLEAN, required = false, description = "Force encapsulation for Nat Traversal") + private Boolean encap; + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account associated with the gateway. Must be used with the domainId parameter.") private String accountName; @@ -135,6 +138,8 @@ public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd { return dpd; } + public Boolean getEncap() { return encap; } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/org/apache/cloudstack/api/response/Site2SiteCustomerGatewayResponse.java b/api/src/org/apache/cloudstack/api/response/Site2SiteCustomerGatewayResponse.java index 2bda8f93f4d..232c3f21261 100644 --- a/api/src/org/apache/cloudstack/api/response/Site2SiteCustomerGatewayResponse.java +++ b/api/src/org/apache/cloudstack/api/response/Site2SiteCustomerGatewayResponse.java @@ -74,6 +74,10 @@ public class Site2SiteCustomerGatewayResponse extends BaseResponse implements Co @Param(description = "if DPD is enabled for customer gateway") private Boolean dpd; + @SerializedName(ApiConstants.FORCE_ENCAP) + @Param(description = "if Force NAT Encapsulation is enabled for customer gateway") + private Boolean encap; + @SerializedName(ApiConstants.ACCOUNT) @Param(description = "the owner") private String accountName; @@ -142,6 +146,8 @@ public class Site2SiteCustomerGatewayResponse extends BaseResponse implements Co this.dpd = dpd; } + public void setEncap(Boolean encap) { this.encap = encap; } + public void setRemoved(Date removed) { this.removed = removed; } diff --git a/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java b/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java index c00a4d4aa52..c5450a69607 100644 --- a/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java +++ b/api/src/org/apache/cloudstack/api/response/Site2SiteVpnConnectionResponse.java @@ -87,6 +87,11 @@ public class Site2SiteVpnConnectionResponse extends BaseResponse implements Cont //from CustomerGateway private Boolean dpd; + @SerializedName(ApiConstants.FORCE_ENCAP) + @Param(description = "if Force NAT Encapsulation is enabled for customer gateway") + //from CustomerGateway + private Boolean encap; + @SerializedName(ApiConstants.STATE) @Param(description = "State of vpn connection") private String state; @@ -175,6 +180,10 @@ public class Site2SiteVpnConnectionResponse extends BaseResponse implements Cont this.dpd = dpd; } + public void setEncap(Boolean encap) { + this.encap = encap; + } + public void setState(String state) { this.state = state; } diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index a487ea7b198..a48236d9e0d 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -2259,3 +2259,4 @@ message.please.select.ssh.key.pair.use.with.this.vm=Please select a ssh key pair message.configure.firewall.rules.allow.traffic=Configure the rules to allow Traffic message.configure.firewall.rules.block.traffic=Configure the rules to block Traffic message.ldap.group.import=All The users from the given group name will be imported +label.vpn.force.encapsulation=Force UDP Encapsulation of ESP Packets diff --git a/client/WEB-INF/classes/resources/messages_nl_NL.properties b/client/WEB-INF/classes/resources/messages_nl_NL.properties index 363be5f05ff..a4e199153ad 100644 --- a/client/WEB-INF/classes/resources/messages_nl_NL.properties +++ b/client/WEB-INF/classes/resources/messages_nl_NL.properties @@ -1726,6 +1726,7 @@ label.vpc=VPC label.VPN.connection=VPN Connectie label.vpn.customer.gateway=VPN Customer Gateway label.VPN.customer.gateway=VPN Customer Gateway +label.vpn.force.encapsulation=Forceer UDP Encapsulatie van ESP Packets label.VPN.gateway=VPN Gateway label.vpn=VPN label.vsmctrlvlanid=Controle VLAN ID diff --git a/core/src/com/cloud/agent/api/routing/Site2SiteVpnCfgCommand.java b/core/src/com/cloud/agent/api/routing/Site2SiteVpnCfgCommand.java index 68b38091a94..685cf4049c7 100644 --- a/core/src/com/cloud/agent/api/routing/Site2SiteVpnCfgCommand.java +++ b/core/src/com/cloud/agent/api/routing/Site2SiteVpnCfgCommand.java @@ -34,6 +34,7 @@ public class Site2SiteVpnCfgCommand extends NetworkElementCommand { private long espLifetime; private boolean dpd; private boolean passive; + private boolean encap; @Override public boolean executeInSequence() { @@ -45,7 +46,7 @@ public class Site2SiteVpnCfgCommand extends NetworkElementCommand { } public Site2SiteVpnCfgCommand(boolean create, String localPublicIp, String localPublicGateway, String localGuestCidr, String peerGatewayIp, String peerGuestCidrList, - String ikePolicy, String espPolicy, String ipsecPsk, Long ikeLifetime, Long espLifetime, Boolean dpd, boolean passive) { + String ikePolicy, String espPolicy, String ipsecPsk, Long ikeLifetime, Long espLifetime, Boolean dpd, boolean passive, boolean encap) { this.create = create; this.setLocalPublicIp(localPublicIp); this.setLocalPublicGateway(localPublicGateway); @@ -59,6 +60,7 @@ public class Site2SiteVpnCfgCommand extends NetworkElementCommand { this.espLifetime = espLifetime; this.dpd = dpd; this.passive = passive; + this.encap = encap; } public boolean isCreate() { @@ -117,6 +119,14 @@ public class Site2SiteVpnCfgCommand extends NetworkElementCommand { this.dpd = dpd; } + public Boolean getEncap() { + return encap; + } + + public void setEncap(Boolean encap) { + this.encap = encap; + } + public String getLocalPublicIp() { return localPublicIp; } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/facade/Site2SiteVpnConfigItem.java b/core/src/com/cloud/agent/resource/virtualnetwork/facade/Site2SiteVpnConfigItem.java index 6509b78019d..5bb466c5935 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/facade/Site2SiteVpnConfigItem.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/facade/Site2SiteVpnConfigItem.java @@ -36,7 +36,7 @@ public class Site2SiteVpnConfigItem extends AbstractConfigItemFacade { final Site2SiteVpn site2siteVpn = new Site2SiteVpn(command.getLocalPublicIp(), command.getLocalGuestCidr(), command.getLocalPublicGateway(), command.getPeerGatewayIp(), command.getPeerGuestCidrList(), command.getEspPolicy(), command.getIkePolicy(), command.getIpsecPsk(), command.getIkeLifetime(), command.getEspLifetime(), command.isCreate(), command.getDpd(), - command.isPassive()); + command.isPassive(), command.getEncap()); return generateConfigItems(site2siteVpn); } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/Site2SiteVpn.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/Site2SiteVpn.java index 63b04c5a65a..232e99f099a 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/model/Site2SiteVpn.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/Site2SiteVpn.java @@ -23,7 +23,7 @@ public class Site2SiteVpn extends ConfigBase { private String localPublicIp, localGuestCidr, localPublicGateway, peerGatewayIp, peerGuestCidrList, espPolicy, ikePolicy, ipsecPsk; private Long ikeLifetime, espLifetime; - private boolean create, dpd, passive; + private boolean create, dpd, passive, encap; public Site2SiteVpn() { super(ConfigBase.SITE2SITEVPN); @@ -31,7 +31,7 @@ public class Site2SiteVpn extends ConfigBase { public Site2SiteVpn(String localPublicIp, String localGuestCidr, String localPublicGateway, String peerGatewayIp, String peerGuestCidrList, String espPolicy, String ikePolicy, - String ipsecPsk, Long ikeLifetime, Long espLifetime, boolean create, Boolean dpd, boolean passive) { + String ipsecPsk, Long ikeLifetime, Long espLifetime, boolean create, Boolean dpd, boolean passive, boolean encap) { super(ConfigBase.SITE2SITEVPN); this.localPublicIp = localPublicIp; this.localGuestCidr = localGuestCidr; @@ -46,6 +46,7 @@ public class Site2SiteVpn extends ConfigBase { this.create = create; this.dpd = dpd; this.passive = passive; + this.encap = encap; } public String getLocalPublicIp() { @@ -152,4 +153,12 @@ public class Site2SiteVpn extends ConfigBase { this.passive = passive; } + public boolean getEncap() { + return encap; + } + + public void setEncap(boolean encap) { + this.encap = encap; + } + } diff --git a/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java b/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java index c4e134bd261..6b5f1d1baf5 100644 --- a/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java +++ b/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java @@ -494,17 +494,17 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer { public void testSite2SiteVpnCfgCommand() { _count = 0; - Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(true, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), true, false); + Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(true, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), true, false, false); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME); Answer answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); - cmd = new Site2SiteVpnCfgCommand(true, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), false, true); + cmd = new Site2SiteVpnCfgCommand(true, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), false, true, false); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME); answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); - cmd = new Site2SiteVpnCfgCommand(false, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), false, true); + cmd = new Site2SiteVpnCfgCommand(false, "64.10.1.10", "64.10.1.1", "192.168.1.1/16", "124.10.1.10", "192.168.100.1/24", "3des-sha1,aes128-sha1;modp1536", "3des-sha1,aes128-md5", "psk", Long.valueOf(1800), Long.valueOf(1800), false, true, false); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME); answer = _resource.executeRequest(cmd); assertTrue(answer.getResult()); diff --git a/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java b/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java index 5bcf361836f..f1d3ef32712 100644 --- a/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java +++ b/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java @@ -70,6 +70,9 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { @Column(name = "dpd") private boolean dpd; + @Column(name = "force_encap") + private boolean encap; + @Column(name = "domain_id") private Long domainId; @@ -83,7 +86,7 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { } public Site2SiteCustomerGatewayVO(String name, long accountId, long domainId, String gatewayIp, String guestCidrList, String ipsecPsk, String ikePolicy, - String espPolicy, long ikeLifetime, long espLifetime, boolean dpd) { + String espPolicy, long ikeLifetime, long espLifetime, boolean dpd, boolean encap) { this.name = name; this.gatewayIp = gatewayIp; this.guestCidrList = guestCidrList; @@ -93,6 +96,7 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { this.ikeLifetime = ikeLifetime; this.espLifetime = espLifetime; this.dpd = dpd; + this.encap = encap; uuid = UUID.randomUUID().toString(); this.accountId = accountId; this.domainId = domainId; @@ -193,6 +197,15 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { this.dpd = dpd; } + @Override + public Boolean getEncap() { + return encap; + } + + public void setEncap(boolean encap) { + this.encap = encap; + } + @Override public String getUuid() { return uuid; diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 8c9e4379816..1c256440d4b 100644 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -3001,7 +3001,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setIkeLifetime(result.getIkeLifetime()); response.setEspLifetime(result.getEspLifetime()); response.setDpd(result.getDpd()); - + response.setEncap(result.getEncap()); response.setRemoved(result.getRemoved()); response.setObjectName("vpncustomergateway"); @@ -3041,6 +3041,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setIkeLifetime(customerGateway.getIkeLifetime()); response.setEspLifetime(customerGateway.getEspLifetime()); response.setDpd(customerGateway.getDpd()); + response.setEncap(customerGateway.getEncap()); } } diff --git a/server/src/com/cloud/network/router/CommandSetupHelper.java b/server/src/com/cloud/network/router/CommandSetupHelper.java index 925961d3fb7..04427baf749 100644 --- a/server/src/com/cloud/network/router/CommandSetupHelper.java +++ b/server/src/com/cloud/network/router/CommandSetupHelper.java @@ -857,9 +857,10 @@ public class CommandSetupHelper { final Long ikeLifetime = gw.getIkeLifetime(); final Long espLifetime = gw.getEspLifetime(); final Boolean dpd = gw.getDpd(); + final Boolean encap = gw.getEncap(); final Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(isCreate, localPublicIp, localPublicGateway, localGuestCidr, peerGatewayIp, peerGuestCidrList, ikePolicy, - espPolicy, ipsecPsk, ikeLifetime, espLifetime, dpd, conn.isPassive()); + espPolicy, ipsecPsk, ikeLifetime, espLifetime, dpd, conn.isPassive(), encap); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 41cc5586115..ac8b86816a2 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -907,6 +907,9 @@ Configurable, StateListener 0, "No VPC based network offering") + + # Create and Enable VPC offering + vpc_offering = self._create_vpc_offering('vpc_offering') + self.assert_(vpc_offering is not None, "Failed to create VPC Offering") + vpc_offering.update(self.apiclient, state='Enabled') + + vpc1 = None + # Create VPC 1 + try: + vpc1 = VPC.create( + apiclient=self.apiclient, + services=self.services["vpc"], + networkDomain="vpc1.vpn", + vpcofferingid=vpc_offering.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.domain.id + ) + except Exception as e: + self.fail(e) + finally: + self.assert_(vpc1 is not None, "VPC1 creation failed") + + self.logger.debug("VPC1 %s created" % vpc1.id) + + vpc2 = None + # Create VPC 2 + try: + vpc2 = VPC.create( + apiclient=self.apiclient, + services=self.services["vpc2"], + networkDomain="vpc2.vpn", + vpcofferingid=vpc_offering.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) + except Exception as e: + self.fail(e) + finally: + self.assert_(vpc2 is not None, "VPC2 creation failed") + + self.logger.debug("VPC2 %s created" % vpc2.id) + + default_acl = NetworkACLList.list( + self.apiclient, name="default_allow")[0] + + ntwk1 = None + # Create network in VPC 1 + try: + ntwk1 = Network.create( + apiclient=self.apiclient, + services=self.services["network_1"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=networkOffering[0].id, + zoneid=self.zone.id, + vpcid=vpc1.id, + aclid=default_acl.id + ) + except Exception as e: + self.fail(e) + finally: + self.assertIsNotNone(ntwk1, "Network failed to create") + + self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id)) + + ntwk2 = None + # Create network in VPC 2 + try: + ntwk2 = Network.create( + apiclient=self.apiclient, + services=self.services["network_2"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=networkOffering[0].id, + zoneid=self.zone.id, + vpcid=vpc2.id, + aclid=default_acl.id + ) + except Exception as e: + self.fail(e) + finally: + self.assertIsNotNone(ntwk2, "Network failed to create") + + self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id)) + + vm1 = None + # Deploy a vm in network 2 + try: + vm1 = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"], + templateid=self.template.id, + zoneid=self.zone.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.compute_offering.id, + networkids=ntwk1.id, + hypervisor=self.hypervisor + ) + except Exception as e: + self.fail(e) + finally: + self.assert_(vm1 is not None, "VM failed to deploy") + self.assert_(vm1.state == 'Running', "VM is not running") + + self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id)) + + vm2 = None + # Deploy a vm in network 2 + try: + vm2 = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"], + templateid=self.template.id, + zoneid=self.zone.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.compute_offering.id, + networkids=ntwk2.id, + hypervisor=self.hypervisor + ) + except Exception as e: + self.fail(e) + finally: + self.assert_(vm2 is not None, "VM failed to deploy") + self.assert_(vm2.state == 'Running', "VM is not running") + + self.debug("VM %s deployed in VPC %s" % (vm2.id, vpc2.id)) + + # 4) Enable Site-to-Site VPN for VPC + vpn1_response = Vpn.createVpnGateway(self.apiclient, vpc1.id) + self.assert_( + vpn1_response is not None, "Failed to enable VPN Gateway 1") + self.logger.debug("VPN gateway for VPC %s enabled" % vpc1.id) + + vpn2_response = Vpn.createVpnGateway(self.apiclient, vpc2.id) + self.assert_( + vpn2_response is not None, "Failed to enable VPN Gateway 2") + self.logger.debug("VPN gateway for VPC %s enabled" % vpc2.id) + + # 5) Add VPN Customer gateway info + src_nat_list = PublicIPAddress.list( + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True, + issourcenat=True, + vpcid=vpc1.id + ) + ip1 = src_nat_list[0] + src_nat_list = PublicIPAddress.list( + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True, + issourcenat=True, + vpcid=vpc2.id + ) + ip2 = src_nat_list[0] + + services = self.services["vpncustomergateway"] + customer1_response = VpnCustomerGateway.create( + self.apiclient, services, "Peer VPC1", ip1.ipaddress, vpc1.cidr, self.account.name, self.domain.id) + self.debug("VPN customer gateway added for VPC %s enabled" % vpc1.id) + self.logger.debug(vars(customer1_response)) + + customer2_response = VpnCustomerGateway.create( + self.apiclient, services, "Peer VPC2", ip2.ipaddress, vpc2.cidr, self.account.name, self.domain.id) + self.debug("VPN customer gateway added for VPC %s enabled" % vpc2.id) + self.logger.debug(vars(customer2_response)) + + # 6) Connect two VPCs + vpnconn1_response = Vpn.createVpnConnection( + self.apiclient, customer1_response.id, vpn2_response['id'], True) + self.debug("VPN passive connection created for VPC %s" % vpc2.id) + + vpnconn2_response = Vpn.createVpnConnection( + self.apiclient, customer2_response.id, vpn1_response['id']) + self.debug("VPN connection created for VPC %s" % vpc1.id) + + self.assertEqual( + vpnconn2_response['state'], "Connected", "Failed to connect between VPCs!") + + # acquire an extra ip address to use to ssh into vm2 + try: + vm2.public_ip = PublicIPAddress.create( + apiclient=self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + services=self.services, + networkid=ntwk2.id, + vpcid=vpc2.id) + except Exception as e: + self.fail(e) + finally: + self.assert_( + vm2.public_ip is not None, "Failed to aqcuire public ip for vm2") + + natrule = None + # Create port forward to be able to ssh into vm2 + try: + natrule = self._create_natrule( + vpc2, vm2, 22, 22, vm2.public_ip, ntwk2) + except Exception as e: + self.fail(e) + finally: + self.assert_( + natrule is not None, "Failed to create portforward for vm2") + time.sleep(20) + + # setup ssh connection to vm2 + ssh_client = self._get_ssh_client(vm2, self.services, 10) + + if ssh_client: + # run ping test + packet_loss = ssh_client.execute( + "/bin/ping -c 3 -t 10 " + vm1.nic[0].ipaddress + " |grep packet|cut -d ' ' -f 7| cut -f1 -d'%'")[0] + self.assert_(int(packet_loss) == 0, "Ping did not succeed") + else: + self.fail("Failed to setup ssh connection to %s" % vm2.public_ip) + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.apiclient, cls.cleanup) + except Exception, e: + raise Exception("Cleanup failed with %s" % e) + + +class TestRVPCSite2SiteVpn(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.logger = logging.getLogger('TestRVPCSite2SiteVPN') + cls.stream_handler = logging.StreamHandler() + cls.logger.setLevel(logging.DEBUG) + cls.logger.addHandler(cls.stream_handler) + + testClient = super(TestRVPCSite2SiteVpn, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = Services().services + + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) + cls.domain = get_domain(cls.apiclient) + + cls.compute_offering = ServiceOffering.create( + cls.apiclient, + cls.services["compute_offering"] + ) + + cls.account = Account.create( + cls.apiclient, services=cls.services["account"]) + + cls.hypervisor = testClient.getHypervisorInfo() + + cls.logger.debug("Downloading Template: %s from: %s" % (cls.services["template"][ + cls.hypervisor.lower()], cls.services["template"][cls.hypervisor.lower()]["url"])) + cls.template = Template.register(cls.apiclient, cls.services["template"][cls.hypervisor.lower( + )], cls.zone.id, hypervisor=cls.hypervisor.lower(), account=cls.account.name, domainid=cls.domain.id) + cls.template.download(cls.apiclient) + + if cls.template == FAILED: + assert False, "get_template() failed to return template" + + cls.logger.debug("Successfully created account: %s, id: \ + %s" % (cls.account.name, + cls.account.id)) + + cls.cleanup = [cls.template, cls.account, cls.compute_offering] + return + + def _validate_vpc_offering(self, vpc_offering): + + self.logger.debug("Check if the VPC offering is created successfully?") + vpc_offs = VpcOffering.list( + self.apiclient, + id=vpc_offering.id + ) + offering_list = validateList(vpc_offs) + self.assertEqual(offering_list[0], + PASS, + "List VPC offerings should return a valid list" + ) + self.assertEqual( + vpc_offering.name, + vpc_offs[0].name, + "Name of the VPC offering should match with listVPCOff data" + ) + self.logger.debug( + "VPC offering is created successfully - %s" % + vpc_offering.name) + return + + def _create_vpc_offering(self, offering_name): + + vpc_off = None + if offering_name is not None: + + self.logger.debug("Creating VPC offering: %s", offering_name) + vpc_off = VpcOffering.create( + self.apiclient, + self.services[offering_name] + ) + + self._validate_vpc_offering(vpc_off) + self.cleanup.append(vpc_off) + + return vpc_off + + def _get_ssh_client(self, virtual_machine, services, retries): + """ Setup ssh client connection and return connection + vm requires attributes public_ip, public_port, username, password """ + + try: + ssh_client = SshClient( + virtual_machine.public_ip, + services["virtual_machine"]["ssh_port"], + services["virtual_machine"]["username"], + services["virtual_machine"]["password"], + retries) + + except Exception as e: + self.fail("Unable to create ssh connection: " % e) + + self.assertIsNotNone( + ssh_client, "Failed to setup ssh connection to vm=%s on public_ip=%s" % (virtual_machine.name, virtual_machine.public_ip)) + + return ssh_client + + def _create_natrule(self, vpc, vm, public_port, private_port, public_ip, network, services=None): self.logger.debug("Creating NAT rule in network for vm with public IP") if not services: self.services["natrule"]["privateport"] = private_port @@ -495,8 +929,9 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): return nat_rule @attr(tags=["advanced"], required_hardware="true") - def test_vpc_site2site_vpn(self): - """Test VPN in VPC""" + def test_01_redundant_vpc_site2site_vpn(self): + """Test Site 2 Site VPN Across redundant VPCs""" + self.logger.debug("Starting test: test_02_redundant_vpc_site2site_vpn") # 0) Get the default network offering for VPC networkOffering = NetworkOffering.list( @@ -504,18 +939,22 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): self.assert_(networkOffering is not None and len( networkOffering) > 0, "No VPC based network offering") - # 1) Create VPC offering - vpcOffering = VpcOffering.list(self.apiclient, isdefault=True) - self.assert_(vpcOffering is not None and len( - vpcOffering) > 0, "No VPC offerings found") + # Create and enable redundant VPC offering + redundant_vpc_offering = self._create_vpc_offering( + 'redundant_vpc_offering') + self.assert_(redundant_vpc_offering is not None, + "Failed to create redundant VPC Offering") + + redundant_vpc_offering.update(self.apiclient, state='Enabled') # Create VPC 1 + vpc1 = None try: vpc1 = VPC.create( apiclient=self.apiclient, services=self.services["vpc"], networkDomain="vpc1.vpn", - vpcofferingid=vpcOffering[0].id, + vpcofferingid=redundant_vpc_offering.id, zoneid=self.zone.id, account=self.account.name, domainid=self.domain.id @@ -525,15 +964,16 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): finally: self.assert_(vpc1 is not None, "VPC1 creation failed") - self.logger.debug("VPC1 %s created" % (vpc1.id)) + self.logger.debug("VPC1 %s created" % vpc1.id) # Create VPC 2 + vpc2 = None try: vpc2 = VPC.create( apiclient=self.apiclient, services=self.services["vpc2"], networkDomain="vpc2.vpn", - vpcofferingid=vpcOffering[0].id, + vpcofferingid=redundant_vpc_offering.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid @@ -543,12 +983,13 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): finally: self.assert_(vpc2 is not None, "VPC2 creation failed") - self.logger.debug("VPC2 %s created" % (vpc2.id)) + self.logger.debug("VPC2 %s created" % vpc2.id) default_acl = NetworkACLList.list( self.apiclient, name="default_allow")[0] # Create network in VPC 1 + ntwk1 = None try: ntwk1 = Network.create( apiclient=self.apiclient, @@ -568,6 +1009,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id)) # Create network in VPC 2 + ntwk2 = None try: ntwk2 = Network.create( apiclient=self.apiclient, @@ -587,16 +1029,16 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id)) # Deploy a vm in network 2 + vm1 = None try: vm1 = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"], templateid=self.template.id, zoneid=self.zone.id, accountid=self.account.name, domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, + serviceofferingid=self.compute_offering.id, networkids=ntwk1.id, - hypervisor=self.services[ - "virtual_machine"]["hypervisor"] + hypervisor=self.hypervisor ) except Exception as e: self.fail(e) @@ -607,16 +1049,16 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id)) # Deploy a vm in network 2 + vm2 = None try: vm2 = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"], templateid=self.template.id, zoneid=self.zone.id, accountid=self.account.name, domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, + serviceofferingid=self.compute_offering.id, networkids=ntwk2.id, - hypervisor=self.services[ - "virtual_machine"]["hypervisor"] + hypervisor=self.hypervisor ) except Exception as e: self.fail(e) @@ -697,8 +1139,9 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): vm2.public_ip is not None, "Failed to aqcuire public ip for vm2") # Create port forward to be able to ssh into vm2 + natrule = None try: - natrule = self.create_natrule( + natrule = self._create_natrule( vpc2, vm2, 22, 22, vm2.public_ip, ntwk2) except Exception as e: self.fail(e) @@ -708,7 +1151,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): time.sleep(20) # setup ssh connection to vm2 - ssh_client = self.get_ssh_client(vm2, self.services, 10) + ssh_client = self._get_ssh_client(vm2, self.services, 10) if ssh_client: # run ping test diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py index 35d0b2732e2..30bbcdaf0a0 100755 --- a/tools/marvin/marvin/lib/base.py +++ b/tools/marvin/marvin/lib/base.py @@ -3572,6 +3572,8 @@ class VpnCustomerGateway: cmd.esplifetime = services["esplifetime"] if "dpd" in services: cmd.dpd = services["dpd"] + if "forceencap" in services: + cmd.forceencap = services["forceencap"] if account: cmd.account = account if domainid: @@ -3599,6 +3601,8 @@ class VpnCustomerGateway: cmd.esplifetime = services["esplifetime"] if "dpd" in services: cmd.dpd = services["dpd"] + if "forceencap" in services: + cmd.forceencap = services["forceencap"] return(apiclient.updateVpnCustomerGateway(cmd)) def delete(self, apiclient): diff --git a/ui/dictionary2.jsp b/ui/dictionary2.jsp index 9d68974f045..4268104d825 100644 --- a/ui/dictionary2.jsp +++ b/ui/dictionary2.jsp @@ -1124,6 +1124,7 @@ under the License. 'message.desc.create.ssh.key.pair': '', 'message.removed.ssh.key.pair': '', 'message.please.select.ssh.key.pair.use.with.this.vm': '', -'message.ldap.group.import': '' +'message.ldap.group.import': '', +'label.vpn.force.encapsulation': '' }); diff --git a/ui/scripts/docs.js b/ui/scripts/docs.js index ed6ab0c938c..e02cbdac6f4 100755 --- a/ui/scripts/docs.js +++ b/ui/scripts/docs.js @@ -1118,6 +1118,10 @@ cloudStack.docs = { desc: 'Check this to make the virtual router query its IKE peer at regular intervals to ensure continued availability. It is recommended to have the same DPD setting on both sides of the VPN connection.', externalLink: '' }, + helpVPNGatewayForceEncapsulation: { + desc: 'Force UDP encapsulation for ESP packets even if no NAT situation is detected. This may help to surmount restrictive firewalls. In order to force the peer to encapsulate packets, NAT detection payloads are faked', + externalLink: '' + }, // Copy template helpCopyTemplateDestination: { desc: 'The zone to which you want to copy the template', @@ -1329,4 +1333,4 @@ cloudStack.docs = { helpLdapLinkDomainAdmin: { desc: 'domain admin of the linked domain. Specify a username in GROUP/OU of LDAP' } -}; +}; \ No newline at end of file diff --git a/ui/scripts/network.js b/ui/scripts/network.js index cdfbcaa2d5a..9f327833766 100755 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -6133,6 +6133,14 @@ docID: 'helpVPNGatewayDeadPeerDetection', isBoolean: true, isChecked: false + }, + + forceencap: { + label: 'label.vpn.force.encapsulation', + docID: 'helpVPNGatewayForceEncapsulation', + docID: 'helpVPNGatewayForceEncapsulation', + isBoolean: true, + isChecked: false } } }, @@ -6144,7 +6152,8 @@ ipsecpsk: args.data.ipsecpsk, ikelifetime: args.data.ikelifetime, esplifetime: args.data.esplifetime, - dpd: (args.data.dpd == "on") + dpd: (args.data.dpd == "on"), + forceencap: (args.data.forceencap == "on") }; var ikepolicy = args.data.ikeEncryption + '-' + args.data.ikeHash; @@ -6200,7 +6209,8 @@ ipsecpsk: args.data.ipsecpsk, ikelifetime: args.data.ikelifetime, esplifetime: args.data.esplifetime, - dpd: (args.data.dpd == "on") + dpd: (args.data.dpd == "on"), + forceencap: (args.data.forceencap == "on") }; var ikepolicy = args.data.ikeEncryption + '-' + args.data.ikeHash; @@ -6223,7 +6233,7 @@ url: createURL('updateVpnCustomerGateway'), data: data, success: function(json) { - var jobId = json.updatecustomergatewayresponse.jobid; + var jobId = json.updatevpncustomergatewayresponse.jobid; args.response.success({ _custom: { jobId: jobId, @@ -6235,6 +6245,9 @@ } } }); + }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); } }); }, @@ -6469,6 +6482,13 @@ converter: cloudStack.converters.toBooleanText }, + forceencap: { + label: 'label.vpn.force.encapsulation', + isBoolean: true, + isEditable: true, + converter: cloudStack.converters.toBooleanText + }, + id: { label: 'label.id' }, diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js index 4b10d8baeaf..d1a093ad090 100644 --- a/ui/scripts/vpc.js +++ b/ui/scripts/vpc.js @@ -748,7 +748,8 @@ $.ajax({ url: createURL('listLoadBalancers'), data: { - networkid: args.context.networks[0].id + networkid: args.context.networks[0].id, + listAll: true }, success: function(json) { var items = json.listloadbalancersresponse.loadbalancer; @@ -1132,7 +1133,8 @@ async: false, data: { associatednetworkid: args.context.networks[0].id, - forloadbalancing: true + forloadbalancing: true, + listall: true }, success: function(json) { var items = json.listpublicipaddressesresponse.publicipaddress; @@ -2904,6 +2906,12 @@ return str ? 'Yes' : 'No'; } }, + forceencap: { + label: 'label.vpn.force.encapsulation', + converter: function(str) { + return str ? 'Yes' : 'No'; + } + }, state: { label: 'label.state' }, diff --git a/utils/src/main/java/com/cloud/utils/ssh/SSHCmdHelper.java b/utils/src/main/java/com/cloud/utils/ssh/SSHCmdHelper.java index e35a3ea680b..61d01c4ebd9 100644 --- a/utils/src/main/java/com/cloud/utils/ssh/SSHCmdHelper.java +++ b/utils/src/main/java/com/cloud/utils/ssh/SSHCmdHelper.java @@ -29,6 +29,8 @@ import com.trilead.ssh2.Session; public class SSHCmdHelper { private static final Logger s_logger = Logger.getLogger(SSHCmdHelper.class); + private static final int DEFAULT_CONNECT_TIMEOUT = 180000; + private static final int DEFAULT_KEX_TIMEOUT = 60000; public static com.trilead.ssh2.Connection acquireAuthorizedConnection(String ip, String username, String password) { return acquireAuthorizedConnection(ip, 22, username, password); @@ -37,7 +39,7 @@ public class SSHCmdHelper { public static com.trilead.ssh2.Connection acquireAuthorizedConnection(String ip, int port, String username, String password) { com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(ip, port); try { - sshConnection.connect(null, 60000, 60000); + sshConnection.connect(null, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT); if (!sshConnection.authenticateWithPassword(username, password)) { String[] methods = sshConnection.getRemainingAuthMethods(username); StringBuffer mStr = new StringBuffer(); diff --git a/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java b/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java index 3aac4270163..d3c88c8367a 100644 --- a/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java +++ b/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java @@ -29,14 +29,14 @@ import com.trilead.ssh2.ChannelCondition; import com.cloud.utils.Pair; public class SshHelper { - private static final int DEFAULT_CONNECT_TIMEOUT = 60000; + private static final int DEFAULT_CONNECT_TIMEOUT = 180000; private static final int DEFAULT_KEX_TIMEOUT = 60000; private static final Logger s_logger = Logger.getLogger(SshHelper.class); public static Pair sshExecute(String host, int port, String user, File pemKeyFile, String password, String command) throws Exception { - return sshExecute(host, port, user, pemKeyFile, password, command, 60000, 60000, 120000); + return sshExecute(host, port, user, pemKeyFile, password, command, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT, 120000); } public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, String localFile, String fileMode)