Skip to content

Commit

Permalink
[config] Add 'config interface mtu' command (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
okuzovych committed Feb 20, 2020
1 parent 659a935 commit caa2773
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
21 changes: 21 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,27 @@ def mgmt_ip_restart_services():
cmd="systemctl restart ntp-config"
os.system (cmd)

#
# 'mtu' subcommand
#

@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_mtu', metavar='<interface_mtu>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def mtu(ctx, interface_name, interface_mtu, verbose):
"""Set interface mtu"""
if get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

command = "portconfig -p {} -m {}".format(interface_name, interface_mtu)
if verbose:
command += " -vv"
run_command(command, display_cmd=verbose)

#
# 'ip' subgroup ('config interface ip ...')
#
Expand Down
16 changes: 16 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,22 @@ Dynamic breakout feature is yet to be supported in SONiC and hence uses cannot c
admin@sonic:~$ sudo config interface Ethernet63 speed 40000
```

**config interface mtu <interface_name> (Versions >= 201904)**

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.

- Usage:

*Versions >= 201904*
```
config interface mtu <interface_name> <mtu_value>
```

- Example (Versions >= 201904):
```
admin@sonic:~$ sudo config interface mtu Ethernet64 1500
```

Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)


Expand Down
14 changes: 12 additions & 2 deletions scripts/portconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
portconfig is the utility to show and change ECN configuration
usage: portconfig [-h] [-v] [-s] [-f] [-p PROFILE] [-gmin GREEN_MIN]
usage: portconfig [-h] [-v] [-s] [-f] [-m] [-p PROFILE] [-gmin GREEN_MIN]
[-gmax GREEN_MAX] [-ymin YELLOW_MIN] [-ymax YELLOW_MAX]
[-rmin RED_MIN] [-rmax RED_MAX] [-vv]
Expand All @@ -13,6 +13,7 @@ optional arguments:
-p --port port name
-s --speed port speed in Mbits
-f --fec port fec mode
-m --mtu port mtu in bytes
"""
from __future__ import print_function

Expand All @@ -25,6 +26,7 @@ import swsssdk
PORT_TABLE_NAME = "PORT"
PORT_SPEED_CONFIG_FIELD_NAME = "speed"
PORT_FEC_CONFIG_FIELD_NAME = "fec"
PORT_MTU_CONFIG_FIELD_NAME = "mtu"

class portconfig(object):
"""
Expand Down Expand Up @@ -57,6 +59,11 @@ class portconfig(object):
print("Setting fec %s on port %s" % (fec, port))
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_FEC_CONFIG_FIELD_NAME: fec})

def set_mtu(self, port, mtu):
if self.verbose:
print("Setting mtu %s on port %s" % (mtu, port))
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_MTU_CONFIG_FIELD_NAME: mtu})

def main():
parser = argparse.ArgumentParser(description='Set SONiC port parameters',
version='1.0.0',
Expand All @@ -65,18 +72,21 @@ def main():
parser.add_argument('-l', '--list', action='store_true', help='list port parametars', default=False)
parser.add_argument('-s', '--speed', type=int, help='port speed value in Mbit', default=None)
parser.add_argument('-f', '--fec', type=str, help='port fec mode value in (none, rs, fc)', default=None)
parser.add_argument('-m', '--mtu', type=int, help='port mtu value in bytes', default=None)
parser.add_argument('-vv', '--verbose', action='store_true', help='Verbose output', default=False)
args = parser.parse_args()

try:
port = portconfig(args.verbose, args.port)
if args.list:
port.list_params(args.port)
elif args.speed or args.fec:
elif args.speed or args.fec or args.mtu:
if args.speed:
port.set_speed(args.port, args.speed)
if args.fec:
port.set_fec(args.port, args.fec)
if args.mtu:
port.set_mtu(args.port, args.mtu)
else:
parser.print_help()
sys.exit(1)
Expand Down

0 comments on commit caa2773

Please sign in to comment.