Skip to content

Commit c2ebb3a

Browse files
committed
Support multi-VLAN trunk NICs
1 parent e45ea95 commit c2ebb3a

14 files changed

Lines changed: 372 additions & 2 deletions

File tree

‎api/src/main/java/com/cloud/host/Host.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static String[] toStrings(Host.Type... types) {
6464
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
6565
String HOST_SSH_PORT = "host.ssh.port";
6666
String HOST_CDROM_MAX_COUNT = "host.cdrom.max.count";
67+
String HOST_VLAN_FILTERING_ENABLED = "vlan.filtering.enabled";
68+
String HOST_VLAN_TRUNK_XML_SUPPORTED = "vlan.trunk.xml.supported";
6769
String GUEST_OS_CATEGORY_ID = "guest.os.category.id";
6870
String GUEST_OS_RULE = "guest.os.rule";
6971

‎api/src/main/java/com/cloud/vm/Nic.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public enum ReservationStrategy {
146146

147147
boolean getSecondaryIp();
148148

149+
boolean getMultiNetwork();
150+
149151
//
150152
// IPv4
151153
//

‎api/src/main/java/org/apache/cloudstack/api/ApiConstants.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ public class ApiConstants {
318318
public static final String MOVE_ACL_CONSISTENCY_HASH = "aclconsistencyhash";
319319
public static final String IMAGE_PATH = "imagepath";
320320
public static final String INSTANCE_CONVERSION_SUPPORTED = "instanceconversionsupported";
321+
public static final String VLAN_FILTERING_ENABLED = "vlanfilteringenabled";
322+
public static final String VLAN_TRUNK_XML_SUPPORTED = "vlantrunkxmlsupported";
321323
public static final String INTERNAL_DNS1 = "internaldns1";
322324
public static final String INTERNAL_DNS2 = "internaldns2";
323325
public static final String INTERNET_PROTOCOL = "internetprotocol";

‎api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ public class HostResponse extends BaseResponseWithAnnotations {
315315
@Param(description = "true if the host supports instance conversion (using virt-v2v)", since = "4.19.1")
316316
private Boolean instanceConversionSupported;
317317

318+
@SerializedName(ApiConstants.VLAN_FILTERING_ENABLED)
319+
@Param(description = "true if vlan_filtering is enabled on this host's guest bridge, so it can accept multi-VLAN trunk nics", since = "24.0.0")
320+
private Boolean vlanFilteringEnabled;
321+
322+
@SerializedName(ApiConstants.VLAN_TRUNK_XML_SUPPORTED)
323+
@Param(description = "true if this host's libvirt version supports trunk vlan tap membership natively", since = "24.0.0")
324+
private Boolean vlanTrunkXmlSupported;
325+
318326
@SerializedName(ApiConstants.ARCH)
319327
@Param(description = "CPU Arch of the host", since = "4.20")
320328
private String arch;
@@ -904,6 +912,14 @@ public void setInstanceConversionSupported(Boolean instanceConversionSupported)
904912
this.instanceConversionSupported = instanceConversionSupported;
905913
}
906914

915+
public void setVlanFilteringEnabled(Boolean vlanFilteringEnabled) {
916+
this.vlanFilteringEnabled = vlanFilteringEnabled;
917+
}
918+
919+
public void setVlanTrunkXmlSupported(Boolean vlanTrunkXmlSupported) {
920+
this.vlanTrunkXmlSupported = vlanTrunkXmlSupported;
921+
}
922+
907923
public Boolean getIsTagARule() {
908924
return isTagARule;
909925
}
@@ -1000,6 +1016,14 @@ public Boolean getInstanceConversionSupported() {
10001016
return instanceConversionSupported;
10011017
}
10021018

1019+
public Boolean getVlanFilteringEnabled() {
1020+
return vlanFilteringEnabled;
1021+
}
1022+
1023+
public Boolean getVlanTrunkXmlSupported() {
1024+
return vlanTrunkXmlSupported;
1025+
}
1026+
10031027
public void setExtensionId(String extensionId) {
10041028
this.extensionId = extensionId;
10051029
}

‎engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,10 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
808808
String vddkSupport = detailsMap.get(Host.HOST_VDDK_SUPPORT);
809809
String vddkLibDir = detailsMap.get(Host.HOST_VDDK_LIB_DIR);
810810
String vddkVersion = detailsMap.get(Host.HOST_VDDK_VERSION);
811+
String vlanFilteringEnabled = detailsMap.get(Host.HOST_VLAN_FILTERING_ENABLED);
812+
String vlanTrunkXmlSupported = detailsMap.get(Host.HOST_VLAN_TRUNK_XML_SUPPORTED);
811813
logger.debug("Got HOST_UEFI_ENABLE [{}] for host [{}]:", uefiEnabled, host);
812-
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion, vddkSupport, vddkLibDir, vddkVersion)) {
814+
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion, vddkSupport, vddkLibDir, vddkVersion, vlanFilteringEnabled, vlanTrunkXmlSupported)) {
813815
_hostDao.loadDetails(host);
814816
boolean updateNeeded = false;
815817
if (StringUtils.isNotBlank(uefiEnabled) && !uefiEnabled.equals(host.getDetails().get(Host.HOST_UEFI_ENABLE))) {
@@ -828,6 +830,14 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
828830
host.getDetails().put(Host.HOST_VDDK_SUPPORT, vddkSupport);
829831
updateNeeded = true;
830832
}
833+
if (StringUtils.isNotBlank(vlanFilteringEnabled) && !vlanFilteringEnabled.equals(host.getDetails().get(Host.HOST_VLAN_FILTERING_ENABLED))) {
834+
host.getDetails().put(Host.HOST_VLAN_FILTERING_ENABLED, vlanFilteringEnabled);
835+
updateNeeded = true;
836+
}
837+
if (StringUtils.isNotBlank(vlanTrunkXmlSupported) && !vlanTrunkXmlSupported.equals(host.getDetails().get(Host.HOST_VLAN_TRUNK_XML_SUPPORTED))) {
838+
host.getDetails().put(Host.HOST_VLAN_TRUNK_XML_SUPPORTED, vlanTrunkXmlSupported);
839+
updateNeeded = true;
840+
}
831841
if (!StringUtils.defaultString(vddkLibDir).equals(StringUtils.defaultString(host.getDetails().get(Host.HOST_VDDK_LIB_DIR)))) {
832842
if (StringUtils.isBlank(vddkLibDir)) {
833843
host.getDetails().remove(Host.HOST_VDDK_LIB_DIR);

‎engine/schema/src/main/java/com/cloud/vm/NicVO.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ protected NicVO() {
128128
@Column(name = "secondary_ip")
129129
boolean secondaryIp;
130130

131+
@Column(name = "multi_network")
132+
boolean multiNetwork;
133+
131134
@Column(name = "mtu")
132135
Integer mtu;
133136

@@ -337,7 +340,7 @@ public String toString() {
337340
return String.format("Nic %s",
338341
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
339342
this, "id", "uuid", "instanceId",
340-
"deviceId", "broadcastUri", "reservationId", "iPv4Address"));
343+
"deviceId", "broadcastUri", "reservationId", "iPv4Address", "multiNetwork"));
341344
}
342345

343346
@Override
@@ -381,6 +384,15 @@ public void setSecondaryIp(boolean secondaryIp) {
381384
this.secondaryIp = secondaryIp;
382385
}
383386

387+
@Override
388+
public boolean getMultiNetwork() {
389+
return multiNetwork;
390+
}
391+
392+
public void setMultiNetwork(boolean multiNetwork) {
393+
this.multiNetwork = multiNetwork;
394+
}
395+
384396
public void setVmType(VirtualMachine.Type vmType) {
385397
this.vmType = vmType;
386398
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.vm.dao;
18+
19+
import java.util.List;
20+
21+
import com.cloud.utils.db.GenericDao;
22+
23+
public interface NicNetworkMapDao extends GenericDao<NicNetworkMapVO, Long> {
24+
25+
List<NicNetworkMapVO> listByNicId(long nicId);
26+
27+
List<NicNetworkMapVO> listByNetworkId(long networkId);
28+
29+
NicNetworkMapVO findByNicIdAndNetworkId(long nicId, long networkId);
30+
31+
List<Long> listNicIdsByNetworkId(long networkId);
32+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.vm.dao;
18+
19+
import java.util.List;
20+
21+
import org.springframework.stereotype.Component;
22+
23+
import com.cloud.utils.db.GenericDaoBase;
24+
import com.cloud.utils.db.GenericSearchBuilder;
25+
import com.cloud.utils.db.SearchBuilder;
26+
import com.cloud.utils.db.SearchCriteria;
27+
import com.cloud.utils.db.SearchCriteria.Func;
28+
import com.cloud.utils.db.SearchCriteria.Op;
29+
30+
@Component
31+
public class NicNetworkMapDaoImpl extends GenericDaoBase<NicNetworkMapVO, Long> implements NicNetworkMapDao {
32+
33+
private final SearchBuilder<NicNetworkMapVO> AllFieldsSearch;
34+
private final GenericSearchBuilder<NicNetworkMapVO, Long> NicIdsByNetworkSearch;
35+
36+
public NicNetworkMapDaoImpl() {
37+
super();
38+
AllFieldsSearch = createSearchBuilder();
39+
AllFieldsSearch.and("nicId", AllFieldsSearch.entity().getNicId(), Op.EQ);
40+
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
41+
AllFieldsSearch.done();
42+
43+
NicIdsByNetworkSearch = createSearchBuilder(Long.class);
44+
NicIdsByNetworkSearch.select(null, Func.DISTINCT, NicIdsByNetworkSearch.entity().getNicId());
45+
NicIdsByNetworkSearch.and("networkId", NicIdsByNetworkSearch.entity().getNetworkId(), Op.EQ);
46+
NicIdsByNetworkSearch.done();
47+
}
48+
49+
@Override
50+
public List<NicNetworkMapVO> listByNicId(long nicId) {
51+
SearchCriteria<NicNetworkMapVO> sc = AllFieldsSearch.create();
52+
sc.setParameters("nicId", nicId);
53+
return listBy(sc);
54+
}
55+
56+
@Override
57+
public List<NicNetworkMapVO> listByNetworkId(long networkId) {
58+
SearchCriteria<NicNetworkMapVO> sc = AllFieldsSearch.create();
59+
sc.setParameters("networkId", networkId);
60+
return listBy(sc);
61+
}
62+
63+
@Override
64+
public NicNetworkMapVO findByNicIdAndNetworkId(long nicId, long networkId) {
65+
SearchCriteria<NicNetworkMapVO> sc = AllFieldsSearch.create();
66+
sc.setParameters("nicId", nicId);
67+
sc.setParameters("networkId", networkId);
68+
return findOneBy(sc);
69+
}
70+
71+
@Override
72+
public List<Long> listNicIdsByNetworkId(long networkId) {
73+
SearchCriteria<Long> sc = NicIdsByNetworkSearch.create();
74+
sc.setParameters("networkId", networkId);
75+
return customSearch(sc, null);
76+
}
77+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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.vm.dao;
18+
19+
import java.util.Date;
20+
import java.util.UUID;
21+
22+
import javax.persistence.Column;
23+
import javax.persistence.Entity;
24+
import javax.persistence.GeneratedValue;
25+
import javax.persistence.GenerationType;
26+
import javax.persistence.Id;
27+
import javax.persistence.Table;
28+
29+
import org.apache.cloudstack.api.Identity;
30+
import org.apache.cloudstack.api.InternalIdentity;
31+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
32+
33+
import com.cloud.utils.db.GenericDao;
34+
35+
@Entity
36+
@Table(name = "nic_network_map")
37+
public class NicNetworkMapVO implements Identity, InternalIdentity {
38+
39+
@Id
40+
@GeneratedValue(strategy = GenerationType.IDENTITY)
41+
@Column(name = "id")
42+
private long id;
43+
44+
@Column(name = "uuid")
45+
private String uuid = UUID.randomUUID().toString();
46+
47+
@Column(name = "nic_id")
48+
private long nicId;
49+
50+
@Column(name = "network_id")
51+
private long networkId;
52+
53+
@Column(name = "ip4_address")
54+
private String ip4Address;
55+
56+
@Column(name = "ip6_address")
57+
private String ip6Address;
58+
59+
@Column(name = GenericDao.CREATED_COLUMN)
60+
private Date created;
61+
62+
@Column(name = GenericDao.REMOVED_COLUMN)
63+
private Date removed;
64+
65+
protected NicNetworkMapVO() {
66+
}
67+
68+
public NicNetworkMapVO(long nicId, long networkId) {
69+
this.nicId = nicId;
70+
this.networkId = networkId;
71+
}
72+
73+
public NicNetworkMapVO(long nicId, long networkId, String ip4Address, String ip6Address) {
74+
this.nicId = nicId;
75+
this.networkId = networkId;
76+
this.ip4Address = ip4Address;
77+
this.ip6Address = ip6Address;
78+
}
79+
80+
@Override
81+
public long getId() {
82+
return id;
83+
}
84+
85+
@Override
86+
public String getUuid() {
87+
return uuid;
88+
}
89+
90+
public void setUuid(String uuid) {
91+
this.uuid = uuid;
92+
}
93+
94+
public long getNicId() {
95+
return nicId;
96+
}
97+
98+
public void setNicId(long nicId) {
99+
this.nicId = nicId;
100+
}
101+
102+
public long getNetworkId() {
103+
return networkId;
104+
}
105+
106+
public void setNetworkId(long networkId) {
107+
this.networkId = networkId;
108+
}
109+
110+
public String getIp4Address() {
111+
return ip4Address;
112+
}
113+
114+
public void setIp4Address(String ip4Address) {
115+
this.ip4Address = ip4Address;
116+
}
117+
118+
public String getIp6Address() {
119+
return ip6Address;
120+
}
121+
122+
public void setIp6Address(String ip6Address) {
123+
this.ip6Address = ip6Address;
124+
}
125+
126+
public Date getCreated() {
127+
return created;
128+
}
129+
130+
public Date getRemoved() {
131+
return removed;
132+
}
133+
134+
@Override
135+
public String toString() {
136+
return String.format("NicNetworkMap %s",
137+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
138+
this, "id", "uuid", "nicId", "networkId", "ip4Address", "ip6Address"));
139+
}
140+
}

‎engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<bean id="networkServiceMapDaoImpl" class="com.cloud.network.dao.NetworkServiceMapDaoImpl" />
136136
<bean id="nicDetailsDaoImpl" class="com.cloud.vm.dao.NicDetailsDaoImpl" />
137137
<bean id="nicExtraDhcpOptionDaoImpl" class="com.cloud.vm.dao.NicExtraDhcpOptionDaoImpl" />
138+
<bean id="nicNetworkMapDaoImpl" class="com.cloud.vm.dao.NicNetworkMapDaoImpl" />
138139
<bean id="nicSecondaryIpDaoImpl" class="com.cloud.vm.dao.NicSecondaryIpDaoImpl" />
139140
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
140141
<bean id="objectInDataStoreDaoImpl" class="org.apache.cloudstack.storage.db.ObjectInDataStoreDaoImpl" />

0 commit comments

Comments
 (0)