Skip to content

Commit caa2773

Browse files
authored
[config] Add 'config interface mtu' command (#793)
1 parent 659a935 commit caa2773

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

config/main.py

+21
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,27 @@ def mgmt_ip_restart_services():
14241424
cmd="systemctl restart ntp-config"
14251425
os.system (cmd)
14261426

1427+
#
1428+
# 'mtu' subcommand
1429+
#
1430+
1431+
@interface.command()
1432+
@click.pass_context
1433+
@click.argument('interface_name', metavar='<interface_name>', required=True)
1434+
@click.argument('interface_mtu', metavar='<interface_mtu>', required=True)
1435+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
1436+
def mtu(ctx, interface_name, interface_mtu, verbose):
1437+
"""Set interface mtu"""
1438+
if get_interface_naming_mode() == "alias":
1439+
interface_name = interface_alias_to_name(interface_name)
1440+
if interface_name is None:
1441+
ctx.fail("'interface_name' is None!")
1442+
1443+
command = "portconfig -p {} -m {}".format(interface_name, interface_mtu)
1444+
if verbose:
1445+
command += " -vv"
1446+
run_command(command, display_cmd=verbose)
1447+
14271448
#
14281449
# 'ip' subgroup ('config interface ip ...')
14291450
#

doc/Command-Reference.md

+16
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,22 @@ Dynamic breakout feature is yet to be supported in SONiC and hence uses cannot c
25632563
admin@sonic:~$ sudo config interface Ethernet63 speed 40000
25642564
```
25652565
2566+
**config interface mtu <interface_name> (Versions >= 201904)**
2567+
2568+
This command is used to configure the mtu for the Physical interface. Use the value 1500 for setting max transfer unit size to 1500 bytes.
2569+
2570+
- Usage:
2571+
2572+
*Versions >= 201904*
2573+
```
2574+
config interface mtu <interface_name> <mtu_value>
2575+
```
2576+
2577+
- Example (Versions >= 201904):
2578+
```
2579+
admin@sonic:~$ sudo config interface mtu Ethernet64 1500
2580+
```
2581+
25662582
Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)
25672583
25682584

scripts/portconfig

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
portconfig is the utility to show and change ECN configuration
44
5-
usage: portconfig [-h] [-v] [-s] [-f] [-p PROFILE] [-gmin GREEN_MIN]
5+
usage: portconfig [-h] [-v] [-s] [-f] [-m] [-p PROFILE] [-gmin GREEN_MIN]
66
[-gmax GREEN_MAX] [-ymin YELLOW_MIN] [-ymax YELLOW_MAX]
77
[-rmin RED_MIN] [-rmax RED_MAX] [-vv]
88
@@ -13,6 +13,7 @@ optional arguments:
1313
-p --port port name
1414
-s --speed port speed in Mbits
1515
-f --fec port fec mode
16+
-m --mtu port mtu in bytes
1617
"""
1718
from __future__ import print_function
1819

@@ -25,6 +26,7 @@ import swsssdk
2526
PORT_TABLE_NAME = "PORT"
2627
PORT_SPEED_CONFIG_FIELD_NAME = "speed"
2728
PORT_FEC_CONFIG_FIELD_NAME = "fec"
29+
PORT_MTU_CONFIG_FIELD_NAME = "mtu"
2830

2931
class portconfig(object):
3032
"""
@@ -57,6 +59,11 @@ class portconfig(object):
5759
print("Setting fec %s on port %s" % (fec, port))
5860
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_FEC_CONFIG_FIELD_NAME: fec})
5961

62+
def set_mtu(self, port, mtu):
63+
if self.verbose:
64+
print("Setting mtu %s on port %s" % (mtu, port))
65+
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_MTU_CONFIG_FIELD_NAME: mtu})
66+
6067
def main():
6168
parser = argparse.ArgumentParser(description='Set SONiC port parameters',
6269
version='1.0.0',
@@ -65,18 +72,21 @@ def main():
6572
parser.add_argument('-l', '--list', action='store_true', help='list port parametars', default=False)
6673
parser.add_argument('-s', '--speed', type=int, help='port speed value in Mbit', default=None)
6774
parser.add_argument('-f', '--fec', type=str, help='port fec mode value in (none, rs, fc)', default=None)
75+
parser.add_argument('-m', '--mtu', type=int, help='port mtu value in bytes', default=None)
6876
parser.add_argument('-vv', '--verbose', action='store_true', help='Verbose output', default=False)
6977
args = parser.parse_args()
7078

7179
try:
7280
port = portconfig(args.verbose, args.port)
7381
if args.list:
7482
port.list_params(args.port)
75-
elif args.speed or args.fec:
83+
elif args.speed or args.fec or args.mtu:
7684
if args.speed:
7785
port.set_speed(args.port, args.speed)
7886
if args.fec:
7987
port.set_fec(args.port, args.fec)
88+
if args.mtu:
89+
port.set_mtu(args.port, args.mtu)
8090
else:
8191
parser.print_help()
8292
sys.exit(1)

0 commit comments

Comments
 (0)