Skip to content

Commit 29b8a9d

Browse files
authored
kvm: when untagged vxlan is used, use the default guest/public bridge (#3037)
When vxlan://untagged is used for public (or guest) network, use the default public/guest bridge device same as how vlan://untagged works. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent d425a40 commit 29b8a9d

2 files changed

Lines changed: 71 additions & 6 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ private static boolean isInterface(final String fname) {
206206
return fname.matches(commonPattern.toString());
207207
}
208208

209+
protected boolean isBroadcastTypeVlanOrVxlan(final NicTO nic) {
210+
return nic != null && (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan
211+
|| nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan);
212+
}
213+
214+
protected boolean isValidProtocolAndVnetId(final String vNetId, final String protocol) {
215+
return vNetId != null && protocol != null && !vNetId.equalsIgnoreCase("untagged");
216+
}
217+
209218
@Override
210219
public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter) throws InternalErrorException, LibvirtException {
211220

@@ -220,7 +229,7 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicA
220229

221230
String vNetId = null;
222231
String protocol = null;
223-
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan) {
232+
if (isBroadcastTypeVlanOrVxlan(nic)) {
224233
vNetId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri());
225234
protocol = Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()).scheme();
226235
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
@@ -233,8 +242,7 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicA
233242
}
234243

235244
if (nic.getType() == Networks.TrafficType.Guest) {
236-
if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) ||
237-
(nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) {
245+
if (isBroadcastTypeVlanOrVxlan(nic) && isValidProtocolAndVnetId(vNetId, protocol)) {
238246
if (trafficLabel != null && !trafficLabel.isEmpty()) {
239247
s_logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel);
240248
String brName = createVnetBr(vNetId, trafficLabel, protocol);
@@ -257,8 +265,7 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicA
257265
createControlNetwork();
258266
intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
259267
} else if (nic.getType() == Networks.TrafficType.Public) {
260-
if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) ||
261-
(nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) {
268+
if (isBroadcastTypeVlanOrVxlan(nic) && isValidProtocolAndVnetId(vNetId, protocol)) {
262269
if (trafficLabel != null && !trafficLabel.isEmpty()) {
263270
s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel);
264271
String brName = createVnetBr(vNetId, trafficLabel, protocol);
@@ -276,7 +283,7 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicA
276283
String storageBrName = nic.getName() == null ? _bridges.get("private") : nic.getName();
277284
intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
278285
}
279-
if (nic.getPxeDisable() == true) {
286+
if (nic.getPxeDisable()) {
280287
intf.setPxeDisable(true);
281288
}
282289

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.hypervisor.kvm.resource;
18+
19+
import org.junit.Assert;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
import com.cloud.agent.api.to.NicTO;
24+
import com.cloud.network.Networks;
25+
26+
public class BridgeVifDriverTest {
27+
28+
private BridgeVifDriver driver;
29+
30+
@Before
31+
public void setUp() throws Exception {
32+
driver = new BridgeVifDriver();
33+
}
34+
35+
@Test
36+
public void isBroadcastTypeVlanOrVxlan() {
37+
final NicTO nic = new NicTO();
38+
nic.setBroadcastType(Networks.BroadcastDomainType.Native);
39+
Assert.assertFalse(driver.isBroadcastTypeVlanOrVxlan(null));
40+
Assert.assertFalse(driver.isBroadcastTypeVlanOrVxlan(nic));
41+
// Test VLAN
42+
nic.setBroadcastType(Networks.BroadcastDomainType.Vlan);
43+
Assert.assertTrue(driver.isBroadcastTypeVlanOrVxlan(nic));
44+
// Test VXLAN
45+
nic.setBroadcastType(Networks.BroadcastDomainType.Vxlan);
46+
Assert.assertTrue(driver.isBroadcastTypeVlanOrVxlan(nic));
47+
}
48+
49+
@Test
50+
public void isValidProtocolAndVnetId() {
51+
Assert.assertFalse(driver.isValidProtocolAndVnetId(null, null));
52+
Assert.assertFalse(driver.isValidProtocolAndVnetId("123", null));
53+
Assert.assertFalse(driver.isValidProtocolAndVnetId(null, "vlan"));
54+
Assert.assertFalse(driver.isValidProtocolAndVnetId("untagged", "vxlan"));
55+
Assert.assertTrue(driver.isValidProtocolAndVnetId("123", "vlan"));
56+
Assert.assertTrue(driver.isValidProtocolAndVnetId("456", "vxlan"));
57+
}
58+
}

0 commit comments

Comments
 (0)