check for BroadcastDomainTypes on sourceNatIp(cherry picked from commit

6d0dbf5968)

Conflicts:
	plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
(cherry picked from commit d38a503431)

Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
This commit is contained in:
Daan Hoogland 2014-01-29 18:20:16 +01:00 committed by Animesh Chaturvedi
parent adf4dd5927
commit 307ad15bb6
2 changed files with 38 additions and 18 deletions

View File

@ -23,6 +23,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.cloud.dc.Vlan;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.utils.exception.CloudRuntimeException;
@ -59,6 +60,20 @@ public class NetworksTest {
Assert.assertEquals("id2 should be \"2\"", "2", id2);
}
@Test
public void vlanValueTest() throws URISyntaxException {
String uri1 = "vlan://1";
String uri2 = "1";
String vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(uri1));
Assert.assertEquals("vtag should be \"1\"", "1", vtag);
BroadcastDomainType tiep1 = BroadcastDomainType.getTypeOf(uri1);
Assert.assertEquals("the type of uri1 should be 'Vlan'", BroadcastDomainType.Vlan, tiep1);
BroadcastDomainType tiep2 = BroadcastDomainType.getTypeOf(uri2);
Assert.assertEquals("the type of uri1 should be 'Undecided'", BroadcastDomainType.UnDecided, tiep2);
BroadcastDomainType tiep3 = BroadcastDomainType.getTypeOf(Vlan.UNTAGGED);
Assert.assertEquals("the type of uri1 should be 'vlan'", BroadcastDomainType.Native, tiep3);
}
@Test
public void vlanIsolationTypeTest() throws URISyntaxException {
String uri1 = "vlan://1";

View File

@ -16,6 +16,7 @@
// under the License.
package com.cloud.network.element;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -253,25 +254,29 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
PublicIp sourceNatIp = _ipAddrMgr
.assignSourceNatIpAddressToGuestNetwork(owner, network);
String publicCidr = sourceNatIp.getAddress().addr() + "/"
+ NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
String internalCidr = network.getGateway() + "/"
+ network.getCidr().split("/")[1];
long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0
: Long.parseLong(sourceNatIp.getVlanTag());
PublicIp sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
// assuming a vlan:
String vtag = sourceNatIp.getVlanTag();
BroadcastDomainType tiep = null;
try {
tiep = BroadcastDomainType.getTypeOf(vtag);
} catch (URISyntaxException use) {
throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
}
if (tiep == BroadcastDomainType.Vlan) {
vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
} else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
}
long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(
niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid,
BroadcastDomainType.getValue(network.getBroadcastUri()),
"router-" + network.getDisplayText(), publicCidr,
sourceNatIp.getGateway(), internalCidr, context
.getDomain().getName()
+ "-"
+ context.getAccount().getAccountName());
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)_agentMgr
.easySend(niciraNvpHost.getId(), cmd);
CreateLogicalRouterCommand cmd =
new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()),
"router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" +
context.getAccount().getAccountName());
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) {
s_logger.error("Failed to create Logical Router for network "
+ network.getDisplayText());