Skip to content

Port Configuration Utility High Level Design

Liat Grozovik edited this page Apr 18, 2018 · 1 revision

[DRAFT - under development]

Scope

Design document of the port parameters configuration utility in SONiC

Purpose

Configure port parameters.
Currently only speed set is covered in this design

General utility design

  • Like many other SONiC CLI utilities implemented in Python.
  • Return code: 0 if succeeded, not 0 otherwise.
  • Set parameters as a value of an appropriate command line option.
    E.g. '-s' for speed ('-m' for MTU, '-a' for auto negotiation, etc)
    It is mandatory to specify [at least one] option. If no options specified, help is printed and return code is not 0.

Usage syntax

	portconfig <portname> <options>
	Options:  
	  -s <speed> - set port speed. Speed should be specified in gigabits
	  -h         - display this help and exit

Usage examples

	portconfig Ethernet4 -s 40  # Set speed 40G for port Ethernet4

Implementation details

Utility parses and validates input arguments. If no error field speed in table PORT_TABLE:<portname> is updated with the provided value. In the future utility will rely on the validation implemented in the trigger activated by write to database. The database speed is written to is CONF_DB.

Arguments parsing

argparse module can be used to parse utility input arguments. It is easy to utilize and provides auto generated program help(usage) message.
Initialization example:

	import argparse
	...
	parser = argparse.ArgumentParser(description='Set SONiC port parameters',
                                 version='1.0.0',
                                 formatter_class=argparse.RawTextHelpFormatter)
	parser.add_argument('-s', '--speed', type='str', help='port speed value', default=None)

Connect to SONiC Redis DB

swsssdk is the SONiC python module which unifies access to the SONiC Redis DB.
An example how to set speed 56G ton port Ethernet0:

	import swsssdk
	db = swsssdk.SonicV2Connector(host="127.0.0.1")
	db.connect(db.APPL_DB)
	db.set(db.CONF_DB, "PORT_TABLE:Ethernet0", "speed", "56000")

Connection with 'config' shorthand

Utility config (sonic-buildimage/src/sonic-utilities/config/main.py) needs to be updated in order to provide unified system configuration.
New command is added under existing group interface. New command name is speed. It will invoke the portconfig utility to set speed.
Port speed change via config utility syntax is:

	config interface speed Ethernet0 100
Clone this wiki locally