Skip to content

Commit 6d0dbf5

Browse files
committed
check for BroadcastDomainTypes on sourceNatIp
1 parent beb9f2d commit 6d0dbf5

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

api/test/com/cloud/network/NetworksTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.Before;
2323
import org.junit.Test;
2424

25+
import com.cloud.dc.Vlan;
2526
import com.cloud.network.Networks.BroadcastDomainType;
2627
import com.cloud.network.Networks.IsolationType;
2728
import com.cloud.utils.exception.CloudRuntimeException;
@@ -55,6 +56,20 @@ public void vlanBroadcastDomainTypeTest() throws URISyntaxException {
5556
Assert.assertEquals("id2 should be \"2\"", "2", id2);
5657
}
5758

59+
@Test
60+
public void vlanValueTest() throws URISyntaxException {
61+
String uri1 = "vlan://1";
62+
String uri2 = "1";
63+
String vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(uri1));
64+
Assert.assertEquals("vtag should be \"1\"", "1", vtag);
65+
BroadcastDomainType tiep1 = BroadcastDomainType.getTypeOf(uri1);
66+
Assert.assertEquals("the type of uri1 should be 'Vlan'", BroadcastDomainType.Vlan, tiep1);
67+
BroadcastDomainType tiep2 = BroadcastDomainType.getTypeOf(uri2);
68+
Assert.assertEquals("the type of uri1 should be 'Undecided'", BroadcastDomainType.UnDecided, tiep2);
69+
BroadcastDomainType tiep3 = BroadcastDomainType.getTypeOf(Vlan.UNTAGGED);
70+
Assert.assertEquals("the type of uri1 should be 'vlan'", BroadcastDomainType.Native, tiep3);
71+
}
72+
5873
@Test
5974
public void vlanIsolationTypeTest() throws URISyntaxException {
6075
String uri1 = "vlan://1";

plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.network.element;
1818

19+
import java.net.URISyntaxException;
1920
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.HashMap;
@@ -247,13 +248,18 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
247248
String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
248249
// assuming a vlan:
249250
String vtag = sourceNatIp.getVlanTag();
250-
BroadcastDomainType tiep = BroadcastDomainType.toEnumValue(vtag);
251+
BroadcastDomainType tiep = null;
252+
try {
253+
tiep = BroadcastDomainType.getTypeOf(vtag);
254+
} catch (URISyntaxException use) {
255+
throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
256+
}
251257
if (tiep == BroadcastDomainType.Vlan) {
252258
vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
253-
} else if (tiep != BroadcastDomainType.UnDecided) {
259+
} else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
254260
throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
255261
}
256-
long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0 : Long.parseLong(vtag);
262+
long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
257263

258264
CreateLogicalRouterCommand cmd =
259265
new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()),

0 commit comments

Comments
 (0)