Skip to content

Commit 5243cc5

Browse files
okuzovychabdosi
authored andcommitted
[config] Add 'config interface mtu' command (#793)
1 parent 6e7cdae commit 5243cc5

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
@@ -1922,6 +1922,27 @@ def mgmt_ip_restart_services():
19221922
cmd="systemctl restart ntp-config"
19231923
os.system (cmd)
19241924

1925+
#
1926+
# 'mtu' subcommand
1927+
#
1928+
1929+
@interface.command()
1930+
@click.pass_context
1931+
@click.argument('interface_name', metavar='<interface_name>', required=True)
1932+
@click.argument('interface_mtu', metavar='<interface_mtu>', required=True)
1933+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
1934+
def mtu(ctx, interface_name, interface_mtu, verbose):
1935+
"""Set interface mtu"""
1936+
if get_interface_naming_mode() == "alias":
1937+
interface_name = interface_alias_to_name(interface_name)
1938+
if interface_name is None:
1939+
ctx.fail("'interface_name' is None!")
1940+
1941+
command = "portconfig -p {} -m {}".format(interface_name, interface_mtu)
1942+
if verbose:
1943+
command += " -vv"
1944+
run_command(command, display_cmd=verbose)
1945+
19251946
#
19261947
# 'ip' subgroup ('config interface ip ...')
19271948
#

doc/Command-Reference.md

+16
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,22 @@ This command is used to reset an SFP transceiver
27032703
Resetting port Ethernet0... OK
27042704
```
27052705
2706+
**config interface mtu <interface_name> (Versions >= 201904)**
2707+
2708+
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.
2709+
2710+
- Usage:
2711+
2712+
*Versions >= 201904*
2713+
```
2714+
config interface mtu <interface_name> <mtu_value>
2715+
```
2716+
2717+
- Example (Versions >= 201904):
2718+
```
2719+
admin@sonic:~$ sudo config interface mtu Ethernet64 1500
2720+
```
2721+
27062722
Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)
27072723
27082724

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)