mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
check for BroadcastDomainTypes on sourceNatIp
This commit is contained in:
parent
beb9f2d9b3
commit
6d0dbf5968
@ -22,6 +22,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;
|
||||
@ -55,6 +56,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";
|
||||
|
||||
@ -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;
|
||||
@ -247,13 +248,18 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||
String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
|
||||
// assuming a vlan:
|
||||
String vtag = sourceNatIp.getVlanTag();
|
||||
BroadcastDomainType tiep = BroadcastDomainType.toEnumValue(vtag);
|
||||
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) {
|
||||
} 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(sourceNatIp.getVlanTag())) ? 0 : Long.parseLong(vtag);
|
||||
long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
|
||||
|
||||
CreateLogicalRouterCommand cmd =
|
||||
new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user