Skip to content

Commit

Permalink
Merge branch 'master' into master_rw_eeprom
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox authored Oct 20, 2023
2 parents 3c5211e + 244ad2d commit 1fdacbe
Show file tree
Hide file tree
Showing 53 changed files with 2,702 additions and 2,230 deletions.
8 changes: 8 additions & 0 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ def convert_icmp(self, table_name, rule_idx, rule):
is_rule_v6 = True
except Exception as e:
pass
else:
# get the IP version type using IP_PROTOCOL.
try:
ip_protocol = rule.ip.config.protocol
if ip_protocol == "IP_ICMPV6" or int(ip_protocol) == self.ip_protocol_map["IP_ICMPV6"]:
is_rule_v6 = True
except Exception as e:
pass

type_key = "ICMPV6_TYPE" if is_rule_v6 else "ICMP_TYPE"
code_key = "ICMPV6_CODE" if is_rule_v6 else "ICMP_CODE"
Expand Down
3 changes: 1 addition & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ stages:

- script: |
set -xe
sudo apt-get -y purge libhiredis-dev libnl-3-dev libnl-route-3-dev || true
sudo apt-get -y purge libnl-3-dev libnl-route-3-dev || true
sudo dpkg -i libnl-3-200_*.deb
sudo dpkg -i libnl-genl-3-200_*.deb
sudo dpkg -i libnl-route-3-200_*.deb
sudo dpkg -i libnl-nf-3-200_*.deb
sudo dpkg -i libhiredis0.14_*.deb
sudo dpkg -i libyang_1.0.73_amd64.deb
sudo dpkg -i libyang-cpp_1.0.73_amd64.deb
sudo dpkg -i python3-yang_1.0.73_amd64.deb
Expand Down
125 changes: 93 additions & 32 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from .config_mgmt import ConfigMgmtDPB, ConfigMgmt
from . import mclag
from . import syslog
from . import switchport
from . import dns

# mock masic APIs for unit test
Expand Down Expand Up @@ -102,8 +101,6 @@
CFG_PORTCHANNEL_NO="<0-9999>"

PORT_MTU = "mtu"
PORT_MODE= "switchport_mode"

PORT_SPEED = "speed"
PORT_TPID = "tpid"
DEFAULT_TPID = "0x8100"
Expand Down Expand Up @@ -1193,7 +1190,6 @@ def config(ctx):
config.add_command(nat.nat)
config.add_command(vlan.vlan)
config.add_command(vxlan.vxlan)
config.add_command(switchport.switchport)

#add mclag commands
config.add_command(mclag.mclag)
Expand Down Expand Up @@ -4503,39 +4499,19 @@ def add(ctx, interface_name, ip_addr, gw):
if interface_name is None:
ctx.fail("'interface_name' is None!")

# Add a validation to check this interface is not a member in vlan before
# changing it to a router port
vlan_member_table = config_db.get_table('VLAN_MEMBER')
if (interface_is_in_vlan(vlan_member_table, interface_name)):
click.echo("Interface {} is a member of vlan\nAborting!".format(interface_name))
return

portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')

if interface_is_in_portchannel(portchannel_member_table, interface_name):
ctx.fail("{} is configured as a member of portchannel."
.format(interface_name))


# Add a validation to check this interface is in routed mode before
# assigning an IP address to it

sub_intf = False

if clicommon.is_valid_port(config_db, interface_name):
is_port = True
elif clicommon.is_valid_portchannel(config_db, interface_name):
is_port = False
else:
sub_intf = True

if not sub_intf:
interface_mode = "routed"
if is_port:
interface_data = config_db.get_entry('PORT',interface_name)
elif not is_port:
interface_data = config_db.get_entry('PORTCHANNEL',interface_name)

if "mode" in interface_data:
interface_mode = interface_data["mode"]

if interface_mode != "routed":
ctx.fail("Interface {} is not in routed mode!".format(interface_name))
return

try:
ip_address = ipaddress.ip_interface(ip_addr)
except ValueError as err:
Expand Down Expand Up @@ -5984,6 +5960,22 @@ def ecn(profile, rmax, rmin, ymax, ymin, gmax, gmin, rdrop, ydrop, gdrop, verbos
clicommon.run_command(command, display_cmd=verbose)


#
# 'mmu' command ('config mmu...')
#
@config.command()
@click.option('-p', metavar='<profile_name>', type=str, required=True, help="Profile name")
@click.option('-a', metavar='<alpha>', type=click.IntRange(-8,8), help="Set alpha for profile type dynamic")
@click.option('-s', metavar='<staticth>', type=int, help="Set staticth for profile type static")
def mmu(p, a, s):
"""mmuconfig configuration tasks"""
log.log_info("'mmuconfig -p {}' executing...".format(p))
command = ['mmuconfig', '-p', str(p)]
if a is not None: command += ['-a', str(a)]
if s is not None: command += ['-s', str(s)]
clicommon.run_command(command)


#
# 'pfc' group ('config interface pfc ...')
#
Expand Down Expand Up @@ -6670,6 +6662,41 @@ def polling_int(ctx, interval):
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

def is_port_egress_sflow_supported():
state_db = SonicV2Connector(use_unix_socket_path=True)
state_db.connect(state_db.STATE_DB, False)
entry_name="SWITCH_CAPABILITY|switch"
supported = state_db.get(state_db.STATE_DB, entry_name,"PORT_EGRESS_SAMPLE_CAPABLE")
return supported

#
# 'sflow' command ('config sflow sample-direction ...')
#
@sflow.command('sample-direction')
@click.argument('direction', metavar='<sample_direction>', required=True, type=str)
@click.pass_context
def global_sample_direction(ctx, direction):
"""Set sampling direction """
if ADHOC_VALIDATION:
if direction:
if direction not in ['rx', 'tx', 'both']:
ctx.fail("Error: Direction {} is invalid".format(direction))

if ((direction == 'tx' or direction == 'both') and (is_port_egress_sflow_supported() == 'false')):
ctx.fail("Sample direction {} is not supported on this platform".format(direction))

config_db = ValidatedConfigDBConnector(ctx.obj['db'])
sflow_tbl = config_db.get_table('SFLOW')

if not sflow_tbl:
sflow_tbl = {'global': {'admin_state': 'down'}}

sflow_tbl['global']['sample_direction'] = direction
try:
config_db.mod_entry('SFLOW', 'global', sflow_tbl['global'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

def is_valid_sample_rate(rate):
return rate.isdigit() and int(rate) in range(256, 8388608 + 1)

Expand Down Expand Up @@ -6779,6 +6806,40 @@ def sample_rate(ctx, ifname, rate):
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

#
# 'sflow' command ('config sflow interface sample-direction ...')
#
@interface.command('sample-direction')
@click.argument('ifname', metavar='<interface_name>', required=True, type=str)
@click.argument('direction', metavar='<sample_direction>', required=True, type=str)
@click.pass_context
def interface_sample_direction(ctx, ifname, direction):
config_db = ValidatedConfigDBConnector(ctx.obj['db'])
if ADHOC_VALIDATION:
if not interface_name_is_valid(config_db, ifname) and ifname != 'all':
click.echo('Invalid interface name')
return
if direction:
if direction not in ['rx', 'tx', 'both']:
ctx.fail("Error: Direction {} is invalid".format(direction))

if (direction == 'tx' or direction == 'both') and (is_port_egress_sflow_supported() == 'false'):
ctx.fail("Sample direction {} is not supported on this platform".format(direction))

sess_dict = config_db.get_table('SFLOW_SESSION')

if sess_dict and ifname in sess_dict.keys():
sess_dict[ifname]['sample_direction'] = direction
try:
config_db.mod_entry('SFLOW_SESSION', ifname, sess_dict[ifname])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
else:
try:
config_db.mod_entry('SFLOW_SESSION', ifname, {'sample_direction': direction})
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))


#
# 'sflow collector' group
Expand Down Expand Up @@ -7227,7 +7288,7 @@ def clock():


def get_tzs(ctx, args, incomplete):
ret = clicommon.run_command('timedatectl list-timezones',
ret = clicommon.run_command(['timedatectl', 'list-timezones'],
display_cmd=False, ignore_error=False,
return_cmd=True)
if len(ret) == 0:
Expand Down
138 changes: 0 additions & 138 deletions config/switchport.py

This file was deleted.

Loading

0 comments on commit 1fdacbe

Please sign in to comment.