Skip to content

Commit 11bdf29

Browse files
committed
add support to update interface mtu
1 parent 61a07bd commit 11bdf29

22 files changed

Lines changed: 384 additions & 31 deletions

File tree

api/src/main/java/com/cloud/agent/api/to/IpAddressTO.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstI
5858
this.oneToOneNat = isOneToOneNat;
5959
}
6060

61+
public IpAddressTO(String ipAddress, Integer mtu, String vlanNetmask ) {
62+
this.publicIp = ipAddress;
63+
this.mtu = mtu;
64+
this.vlanNetmask = vlanNetmask;
65+
}
66+
6167
protected IpAddressTO() {
6268
}
6369

api/src/main/java/com/cloud/network/element/NetworkElement.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,8 @@ boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, Reser
137137
* @return true/false
138138
*/
139139
boolean verifyServicesCombination(Set<Service> services);
140+
141+
// default boolean update(Network network) throws ResourceUnavailableException {
142+
// return true;
143+
// }
140144
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ public class ApiConstants {
912912
public static final String PUBLIC_MTU = "publicmtu";
913913
public static final String PRIVATE_MTU = "privatemtu";
914914

915+
public static final Integer DEFAULT_MTU = 1500;
915916
public enum BootType {
916917
UEFI, BIOS;
917918

api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,15 @@ public Long getAclId() {
335335
}
336336

337337
public Integer getPublicMtu() {
338-
return publicMtu != null ? publicMtu : 0;
338+
return publicMtu != null ? publicMtu : ApiConstants.DEFAULT_MTU;
339339
}
340340

341341
public void setPublicMtu(Integer publicMtu) {
342342
this.publicMtu = publicMtu;
343343
}
344344

345345
public Integer getPrivateMtu() {
346-
return privateMtu != null ? privateMtu : 0;
346+
return privateMtu != null ? privateMtu : ApiConstants.DEFAULT_MTU;
347347
}
348348

349349
public void setPrivateMtu(Integer privateMtu) {

core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand {
3636
String routerIpv6Gateway = null;
3737
String routerIpv6Cidr = null;
3838

39-
Integer mtu = null;
40-
4139
public NicTO getNic() {
4240
return nic;
4341
}
@@ -116,12 +114,4 @@ public void setDefaultIp6Dns1(String defaultIp6Dns1) {
116114
public void setDefaultIp6Dns2(String defaultIp6Dns2) {
117115
this.defaultIp6Dns2 = defaultIp6Dns2;
118116
}
119-
120-
public Integer getMtu() {
121-
return mtu;
122-
}
123-
124-
public void setMtu(Integer mtu) {
125-
this.mtu = mtu;
126-
}
127117
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.agent.api.routing;
18+
19+
import com.cloud.agent.api.to.IpAddressTO;
20+
import com.cloud.hypervisor.Hypervisor;
21+
22+
public class UpdateNetworkCommand extends NetworkElementCommand{
23+
IpAddressTO[] ipAddresses;
24+
25+
Hypervisor.HypervisorType hypervisorType;
26+
27+
public UpdateNetworkCommand(IpAddressTO[] ips) {
28+
this.ipAddresses = ips;
29+
}
30+
31+
@Override
32+
public boolean executeInSequence() {
33+
return false;
34+
}
35+
36+
public IpAddressTO[] getIpAddresses() {
37+
return ipAddresses;
38+
}
39+
40+
@Override
41+
public int getAnswersCount() {
42+
return ipAddresses.length;
43+
}
44+
45+
public Hypervisor.HypervisorType getHypervisorType() {
46+
return hypervisorType;
47+
}
48+
49+
public void setHypervisorType(Hypervisor.HypervisorType hypervisorType) {
50+
this.hypervisorType = hypervisorType;
51+
}
52+
}

core/src/main/java/com/cloud/agent/resource/virtualnetwork/VRScripts.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,7 @@ public class VRScripts {
7878
public static final String RETRIEVE_DIAGNOSTICS = "get_diagnostics_files.py";
7979
public static final String VR_FILE_CLEANUP = "cleanup.sh";
8080

81+
public static final String VR_UPDATE_MTU = "update_interface_config.sh";
82+
8183
public static final String ROUTER_FILESYSTEM_WRITABLE_CHECK = "filesystem_writable_check.py";
8284
}

core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import javax.naming.ConfigurationException;
3636

37+
import com.cloud.agent.api.routing.UpdateNetworkCommand;
38+
import com.cloud.agent.api.to.IpAddressTO;
3739
import com.cloud.utils.PasswordGenerator;
3840
import org.apache.cloudstack.ca.SetupCertificateAnswer;
3941
import org.apache.cloudstack.ca.SetupCertificateCommand;
@@ -134,6 +136,10 @@ public Answer executeRequest(final NetworkElementCommand cmd) {
134136
return execute((AggregationControlCommand)cmd);
135137
}
136138

139+
if (cmd instanceof UpdateNetworkCommand) {
140+
return execute((UpdateNetworkCommand) cmd);
141+
}
142+
137143
if (_vrAggregateCommandsSet.containsKey(routerName)) {
138144
_vrAggregateCommandsSet.get(routerName).add(cmd);
139145
aggregated = true;
@@ -216,6 +222,44 @@ private Answer executeQueryCommand(NetworkElementCommand cmd) {
216222
}
217223
}
218224

225+
private static String getRouterSshControlIp(NetworkElementCommand cmd) {
226+
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
227+
if (s_logger.isDebugEnabled())
228+
s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp);
229+
return routerIp;
230+
}
231+
232+
private Answer execute(UpdateNetworkCommand cmd) {
233+
IpAddressTO[] ipAddresses = cmd.getIpAddresses();
234+
String routerIp = getRouterSshControlIp(cmd);
235+
boolean finalResult = true;
236+
for (IpAddressTO ipAddressTO : ipAddresses) {
237+
try {
238+
ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.VR_UPDATE_MTU,
239+
ipAddressTO.getPublicIp() + " " + ipAddressTO.getVlanNetmask() + " " + ipAddressTO.getMtu() + " " + 15);
240+
if (s_logger.isDebugEnabled())
241+
s_logger.debug("result: " + result.isSuccess() + ", output: " + result.getDetails());
242+
if (!result.isSuccess()) {
243+
s_logger.warn(String.format("Failed to update interface mtu to %s on interface with ip: %s",
244+
ipAddressTO.getMtu(), ipAddressTO.getPublicIp()));
245+
finalResult = false;
246+
continue;
247+
}
248+
s_logger.info(String.format("Successfully updated mtu to %s on interface with ip: %s",
249+
ipAddressTO.getMtu(), ipAddressTO.getPublicIp()));
250+
finalResult &= true;
251+
} catch (Exception e) {
252+
String msg = "Prepare UpdateNetwork failed due to " + e.toString();
253+
s_logger.error(msg, e);
254+
return new Answer(cmd, e);
255+
}
256+
}
257+
if (finalResult) {
258+
return new Answer(cmd, true, null);
259+
}
260+
return new Answer(cmd, new CloudRuntimeException("Failed to update interface mtu"));
261+
}
262+
219263
private ExecutionResult applyConfigToVR(String routerAccessIp, ConfigItem c) {
220264
return applyConfigToVR(routerAccessIp, c, VRScripts.VR_SCRIPT_EXEC_TIMEOUT);
221265
}

core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/IpAddress.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class IpAddress {
3535
private boolean isPrivateGateway;
3636

3737
private Integer mtu;
38-
3938
public IpAddress() {
4039
// Empty constructor for (de)serialization
4140
}

engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,6 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
9494
IPAddressVO findByVmIdAndNetworkId(long networkId, long vmId);
9595

9696
IPAddressVO findByAccountIdAndZoneIdAndStateAndIpAddress(long accountId, long dcId, State state, String ipAddress);
97+
98+
List<IPAddressVO> listByNetworkId(long networkId);
9799
}

0 commit comments

Comments
 (0)