Skip to content

Commit

Permalink
Merge branch 'master' into master-cisco-8000-config_command
Browse files Browse the repository at this point in the history
  • Loading branch information
yucgu committed Jul 14, 2022
2 parents d87dfa1 + 1dacb7f commit 6995cba
Show file tree
Hide file tree
Showing 35 changed files with 1,249 additions and 81 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Currently, this list of dependencies is as follows:
- libyang-cpp_1.0.73_amd64.deb
- python3-yang_1.0.73_amd64.deb
- redis_dump_load-1.1-py3-none-any.whl
- swsssdk-2.0.1-py3-none-any.whl
- sonic_py_common-1.0-py3-none-any.whl
- sonic_config_engine-1.0-py3-none-any.whl
- sonic_yang_mgmt-1.0-py3-none-any.whl
- sonic_yang_models-1.0-py3-none-any.whl
- python-swsscommon_1.0.0_amd64.deb


A convenient alternative is to let the SONiC build system configure a build enviroment for you. This can be done by cloning the [sonic-buildimage](https://github.com/Azure/sonic-buildimage) repo, building the sonic-utilities package inside the Debian Buster slave container, and staying inside the container once the build finishes. During the build process, the SONiC build system will build and install all the necessary dependencies inside the container. After following the instructions to clone and initialize the sonic-buildimage repo, this can be done as follows:
Expand All @@ -40,9 +40,9 @@ A convenient alternative is to let the SONiC build system configure a build envi
make configure PLATFORM=generic
```
2. Build the sonic-utilities Python wheel package inside the Buster slave container, and tell the build system to keep the container alive when finished
2. Build the sonic-utilities Python wheel package inside the Bullseye slave container, and tell the build system to keep the container alive when finished
```
make NOJESSIE=1 NOSTRETCH=1 KEEP_SLAVE_ON=yes target/python-wheels/sonic_utilities-1.2-py3-none-any.whl
make NOSTRETCH=1 NOBUSTER=1 KEEP_SLAVE_ON=yes target/python-wheels/bullseye/sonic_utilities-1.2-py3-none-any.whl
```
3. When the build finishes, your prompt will change to indicate you are inside the slave container. Change into the `src/sonic-utilities/` directory
Expand Down
2 changes: 1 addition & 1 deletion config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import sonic_yang
from jsondiff import diff
from swsssdk import port_util
from sonic_py_common import port_util
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from utilities_common.general import load_module_from_source

Expand Down
113 changes: 97 additions & 16 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,41 @@ def validate_gre_type(ctx, _, value):
except ValueError:
raise click.UsageError("{} is not a valid GRE type".format(value))

def _is_storage_device(cfg_db):
"""
Check if the device is a storage device or not
"""
device_metadata = cfg_db.get_entry("DEVICE_METADATA", "localhost")
return device_metadata.get("storage_device", "Unknown") == "true"

def _is_acl_table_present(cfg_db, acl_table_name):
"""
Check if acl table exists
"""
return acl_table_name in cfg_db.get_keys("ACL_TABLE")

def load_backend_acl(cfg_db, device_type):
"""
Load acl on backend storage device
"""

BACKEND_ACL_TEMPLATE_FILE = os.path.join('/', "usr", "share", "sonic", "templates", "backend_acl.j2")
BACKEND_ACL_FILE = os.path.join('/', "etc", "sonic", "backend_acl.json")

if device_type and device_type == "BackEndToRRouter" and _is_storage_device(cfg_db) and _is_acl_table_present(cfg_db, "DATAACL"):
if os.path.isfile(BACKEND_ACL_TEMPLATE_FILE):
clicommon.run_command(
"{} -d -t {},{}".format(
SONIC_CFGGEN_PATH,
BACKEND_ACL_TEMPLATE_FILE,
BACKEND_ACL_FILE
),
display_cmd=True
)
if os.path.isfile(BACKEND_ACL_FILE):
clicommon.run_command("acl-loader update incremental {}".format(BACKEND_ACL_FILE), display_cmd=True)


# This is our main entrypoint - the main 'config' command
@click.group(cls=clicommon.AbbreviationGroup, context_settings=CONTEXT_SETTINGS)
@click.pass_context
Expand Down Expand Up @@ -1629,24 +1664,34 @@ def load_mgmt_config(filename):
config_data = parse_device_desc_xml(filename)
hostname = config_data['DEVICE_METADATA']['localhost']['hostname']
_change_hostname(hostname)
mgmt_conf = netaddr.IPNetwork(list(config_data['MGMT_INTERFACE'].keys())[0][1])
gw_addr = list(config_data['MGMT_INTERFACE'].values())[0]['gwaddr']
command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask))
clicommon.run_command(command, display_cmd=True)
command = "ip route add default via {} dev eth0 table default".format(gw_addr)
clicommon.run_command(command, display_cmd=True, ignore_error=True)
command = "ip rule add from {} table default".format(str(mgmt_conf.ip))
clicommon.run_command(command, display_cmd=True, ignore_error=True)
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
clicommon.run_command(command, display_cmd=True, ignore_error=True)
for key in list(config_data['MGMT_INTERFACE'].keys()):
# key: (eth0, ipprefix)
# value: { gwaddr: ip }
mgmt_conf = netaddr.IPNetwork(key[1])
gw_addr = config_data['MGMT_INTERFACE'][key]['gwaddr']
if mgmt_conf.version == 4:
command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask))
clicommon.run_command(command, display_cmd=True)
else:
command = "ifconfig eth0 add {}".format(str(mgmt_conf))
# Ignore error for IPv6 configuration command due to it not allows config the same IP twice
clicommon.run_command(command, display_cmd=True, ignore_error=True)
command = "ip{} route add default via {} dev eth0 table default".format(" -6" if mgmt_conf.version == 6 else "", gw_addr)
clicommon.run_command(command, display_cmd=True, ignore_error=True)
command = "ip{} rule add from {} table default".format(" -6" if mgmt_conf.version == 6 else "", str(mgmt_conf.ip))
clicommon.run_command(command, display_cmd=True, ignore_error=True)
if len(config_data['MGMT_INTERFACE'].keys()) > 0:
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
clicommon.run_command(command, display_cmd=True, ignore_error=True)
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")

@config.command("load_minigraph")
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Reload config from minigraph?')
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
@click.option('-t', '--traffic_shift_away', default=False, is_flag=True, help='Keep device in maintenance with TSA')
@clicommon.pass_db
def load_minigraph(db, no_service_restart):
def load_minigraph(db, no_service_restart, traffic_shift_away):
"""Reconfigure based on minigraph."""
log.log_info("'load_minigraph' executing...")

Expand Down Expand Up @@ -1688,6 +1733,12 @@ def load_minigraph(db, no_service_restart):
if os.path.isfile('/etc/sonic/acl.json'):
clicommon.run_command("acl-loader update full /etc/sonic/acl.json", display_cmd=True)

# get the device type
device_type = _get_device_type()

# Load backend acl
load_backend_acl(db.cfgdb, device_type)

# Load port_config.json
try:
load_port_config(db.cfgdb, '/etc/sonic/port_config.json')
Expand All @@ -1697,8 +1748,6 @@ def load_minigraph(db, no_service_restart):
# generate QoS and Buffer configs
clicommon.run_command("config qos reload --no-dynamic-buffer", display_cmd=True)

# get the device type
device_type = _get_device_type()
if device_type != 'MgmtToRRouter' and device_type != 'MgmtTsToR' and device_type != 'BmcMgmtToRRouter' and device_type != 'EPMS':
clicommon.run_command("pfcwd start_default", display_cmd=True)

Expand All @@ -1712,6 +1761,13 @@ def load_minigraph(db, no_service_restart):
cfggen_namespace_option = " -n {}".format(namespace)
clicommon.run_command(db_migrator + ' -o set_version' + cfggen_namespace_option)

# Keep device isolated with TSA
if traffic_shift_away:
clicommon.run_command("TSA", display_cmd=True)
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
log.log_warning("Golden configuration may override System Maintenance state. Please execute TSC to check the current System mode")
click.secho("[WARNING] Golden configuration may override Traffic-shift-away state. Please execute TSC to check the current System mode")

# Load golden_config_db.json
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)
Expand Down Expand Up @@ -4164,7 +4220,7 @@ def fec(ctx, interface_name, interface_fec, verbose):
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def ip(ctx):
"""Add or remove IP address"""
"""Set IP interface attributes"""
pass

#
Expand Down Expand Up @@ -4295,6 +4351,32 @@ def remove(ctx, interface_name, ip_addr):
command = "ip neigh flush dev {} {}".format(interface_name, str(ip_address))
clicommon.run_command(command)

#
# 'loopback-action' subcommand
#

@ip.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('action', metavar='<action>', required=True)
@click.pass_context
def loopback_action(ctx, interface_name, action):
"""Set IP interface loopback action"""
config_db = ctx.obj['config_db']

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail('Interface {} is invalid'.format(interface_name))

if not clicommon.is_interface_in_config_db(config_db, interface_name):
ctx.fail('Interface {} is not an IP interface'.format(interface_name))

allowed_actions = ['drop', 'forward']
if action not in allowed_actions:
ctx.fail('Invalid action')

table_name = get_interface_table_name(interface_name)
config_db.mod_entry(table_name, interface_name, {"loopback_action": action})

#
# buffer commands and utilities
Expand Down Expand Up @@ -4816,7 +4898,6 @@ def unbind(ctx, interface_name):
remove_router_interface_ip_address(config_db, interface_name, ipaddress)
config_db.set_entry(table_name, interface_name, None)


#
# 'ipv6' subgroup ('config interface ipv6 ...')
#
Expand Down Expand Up @@ -6534,7 +6615,7 @@ def rate():
@click.argument('rates_type', type=click.Choice(['all', 'port', 'rif', 'flowcnt-trap']), default='all')
def smoothing_interval(interval, rates_type):
"""Set rates smoothing interval """
counters_db = swsssdk.SonicV2Connector()
counters_db = SonicV2Connector()
counters_db.connect('COUNTERS_DB')

alpha = 2.0/(interval + 1)
Expand Down
49 changes: 47 additions & 2 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3657,6 +3657,25 @@ This command is used to display the configured MPLS state for the list of config
Ethernet4 enable
```
**show interfaces loopback-action**
This command displays the configured loopback action
- Usage:
```
show ip interfaces loopback-action
```
- Example:
```
root@sonic:~# show ip interfaces loopback-action
Interface Action
------------ ----------
Ethernet232 drop
Vlan100 forward
```
**show interfaces tpid**
This command displays the key fields of the interfaces such as Operational Status, Administrative Status, Alias and TPID.
Expand Down Expand Up @@ -3803,6 +3822,7 @@ This sub-section explains the following list of configuration on the interfaces.
9) advertised-types - to set interface advertised types
10) type - to set interface type
11) mpls - To add or remove MPLS operation for the interface
12) loopback-action - to set action for packet that ingress and gets routed on the same IP interface
From 201904 release onwards, the “config interface” command syntax is changed and the format is as follows:
Expand Down Expand Up @@ -4336,6 +4356,29 @@ MPLS operation for either physical, portchannel, or VLAN interface can be config
admin@sonic:~$ sudo config interface mpls remove Ethernet4
```
**config interface ip loopback-action <interface_name> <action> (Versions >= 202205)**
This command is used for setting the action being taken on packets that ingress and get routed on the same IP interface.
Loopback action can be set on IP interface from type physical, portchannel, VLAN interface and VLAN subinterface.
Loopback action can be drop or forward.
- Usage:
```
config interface ip loopback-action --help
Usage: config interface ip loopback-action [OPTIONS] <interface_name> <action>

Set IP interface loopback action

Options:
-?, -h, --help Show this message and exit.
```
- Example:
```
admin@sonic:~$ config interface ip loopback-action Ethernet0 drop
admin@sonic:~$ config interface ip loopback-action Ethernet0 forward

```
Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)
## Interface Naming Mode
Expand Down Expand Up @@ -5106,9 +5149,11 @@ When user specifies the optional argument "-n" or "--no-service-restart", this c
running on the device. One use case for this option is during boot time when config-setup service loads minigraph configuration and there is no services
running on the device.
When user specifies the optional argument "-t" or "--traffic-shift-away", this command executes TSA command at the end to ensure the device remains in maintenance after loading minigraph.
- Usage:
```
config load_minigraph [-y|--yes] [-n|--no-service-restart]
config load_minigraph [-y|--yes] [-n|--no-service-restart] [-t|--traffic-shift-away]
```
- Example:
Expand Down Expand Up @@ -5192,7 +5237,7 @@ When user specifies the optional argument "-f" or "--force", this command ignore
This command is used to reconfigure hostname and mgmt interface based on device description file.
This command either uses the optional file specified as arguement or looks for the file "/etc/sonic/device_desc.xml".
If the file does not exist or if the file does not have valid fields for "hostname" and "ManagementAddress", it fails.
If the file does not exist or if the file does not have valid fields for "hostname" and "ManagementAddress" (or "ManagementAddressV6"), it fails.
When user specifies the optional argument "-y" or "--yes", this command forces the loading without prompting the user for confirmation.
If the argument is not specified, it prompts the user to confirm whether user really wants to load this configuration file.
Expand Down
3 changes: 2 additions & 1 deletion pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tabulate import tabulate
from utilities_common import multi_asic as multi_asic_util
from utilities_common import constants
from utilities_common.general import load_db_config
from sonic_py_common import logger

SYSLOG_IDENTIFIER = "config"
Expand Down Expand Up @@ -62,7 +63,7 @@
@click.group()
def cli():
""" SONiC PFC Watchdog """

load_db_config()

def get_all_queues(db, namespace=None, display=constants.DISPLAY_ALL):
queue_names = db.get_all(db.COUNTERS_DB, 'COUNTERS_QUEUE_NAME_MAP')
Expand Down
2 changes: 1 addition & 1 deletion scripts/fdbshow
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ try: # pragma: no cover
except KeyError: # pragma: no cover
pass

from swsssdk import port_util
from sonic_py_common import port_util
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate

Expand Down
29 changes: 29 additions & 0 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,31 @@ collect_broadcom() {
copy_from_masic_docker "syncd" "/var/log/bcm_diag_post" "/var/log/bcm_diag_post"
}

###############################################################################
# Collect Barefoot specific information
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
collect_barefoot() {
local bf_logs="/tmp/bf_logs"
$( rm -rf ${bf_logs} )
$( mkdir ${bf_logs} )
unset array
array=( $(docker exec -ti syncd ls -1 | grep bf_drivers.log) )
for y in "${array[@]}"; do
itstr=`echo ${y} | tr -d "\r\n"`
copy_from_masic_docker "syncd" "/${itstr}" "${bf_logs}"
done

for file in $(find /tmp/bf_logs -type f); do
save_file "${file}" log true true
done
}

###############################################################################
# Save log file
# Globals:
Expand Down Expand Up @@ -1371,6 +1396,10 @@ main() {

save_saidump

if [ "$asic" = "barefoot" ]; then
collect_barefoot
fi

if [[ "$asic" = "mellanox" ]]; then
collect_mellanox
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/nbrshow
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import subprocess
import re

from natsort import natsorted
from swsssdk import port_util
from sonic_py_common import port_util
from swsscommon.swsscommon import SonicV2Connector
from tabulate import tabulate

Expand Down
Loading

0 comments on commit 6995cba

Please sign in to comment.