Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer 2 Forwarding Enhancements #529

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
eee827e
Update main.py
anilkpandey May 9, 2019
d4e5346
Update main.py
anilkpandey May 9, 2019
b63e795
Update main.py
anilkpandey May 9, 2019
a4beefc
added configuration validations
anilkpandey May 10, 2019
1564302
'show mac' performance improvement
anilkpandey Jun 5, 2019
f567fbb
revert changes
anilkpandey Jun 5, 2019
0bfb742
Delete .DS_Store
anilkpandey Jun 5, 2019
d544203
revert validation related changes
anilkpandey Jun 6, 2019
186b295
removed code repetition
anilkpandey Jun 26, 2019
6742c63
Merge remote-tracking branch 'upstream/master'
anilkpandey Sep 7, 2019
a8935af
Layer 2 Forwarding Enhancements
anilkpandey Sep 8, 2019
7d272ed
Layer 2 Forwarding Enhancements
anilkpandey Sep 8, 2019
863fb4e
Merge remote-tracking branch 'upstream/master'
anilkpandey Oct 15, 2019
224ea6a
Merge remote-tracking branch 'upstream/master'
anilkpandey Nov 8, 2019
2c504a3
Update main.py
anilkpandey Nov 8, 2019
714001d
Update main.py
anilkpandey Nov 8, 2019
83cbba4
Update main.py
anilkpandey Nov 8, 2019
c5892c5
Merge remote-tracking branch 'upstream/master'
anilkpandey Nov 14, 2019
c7fc6e2
Merge remote-tracking branch 'upstream/master'
anilkpandey Nov 14, 2019
14acb2b
Merge remote-tracking branch 'upstream/master'
anilkpandey Dec 3, 2019
851963e
Merge remote-tracking branch 'upstream/master'
anilkpandey Apr 21, 2020
ed5961d
Merge remote-tracking branch 'upstream/master'
anilkpandey Aug 14, 2020
0dde163
Merge remote-tracking branch 'upstream/master'
anilkpandey Aug 14, 2020
ff828a8
move "show vlan count" command to vlan.py
anilkpandey Aug 14, 2020
1289a59
Update main.py
anilkpandey Aug 14, 2020
91ffc2c
Update main.py
anilkpandey Aug 14, 2020
463f738
Update main.py
anilkpandey Aug 16, 2020
325327d
moved vlan commands to vlan.py
anilkpandey Aug 17, 2020
4eda4a5
fixed lgtm
anilkpandey Aug 17, 2020
3689a4d
fixed lgtm
anilkpandey Aug 17, 2020
e642d83
fix lgtm
anilkpandey Aug 17, 2020
e9ab1d6
updated as per review comments
anilkpandey Aug 21, 2020
a6fbfc3
Merge remote-tracking branch 'upstream/master'
anilkpandey Aug 21, 2020
d087bcf
Merge remote-tracking branch 'upstream/master'
anilkpandey Sep 11, 2020
b49e6af
Update main.py
anilkpandey Sep 11, 2020
4b4d16d
Update main.py
anilkpandey Sep 11, 2020
aa927ce
addressed review comments
anilkpandey Sep 18, 2020
d98e16c
Update main.py
anilkpandey Oct 1, 2020
c3252ea
Update fast-reboot-dump.py
anilkpandey Oct 1, 2020
59ffd0e
Merge remote-tracking branch 'upstream/master'
anilkpandey Oct 15, 2020
820cb10
Merge remote-tracking branch 'upstream/master'
anilkpandey Oct 21, 2020
d9fd950
Merge remote-tracking branch 'upstream/master'
anilkpandey Oct 26, 2020
cb7a37d
include latest changes after syncing to master
anilkpandey Dec 4, 2020
ad620a2
Merge remote-tracking branch 'upstream/master'
anilkpandey Dec 4, 2020
afc5321
Update vlan.py
anilkpandey Dec 4, 2020
82d8c88
Update fdbshow
anilkpandey Dec 4, 2020
588db37
Update vlan.py
anilkpandey Dec 4, 2020
349c5a1
Update fdbshow
anilkpandey Dec 7, 2020
243c85a
Update fdbshow
anilkpandey Dec 7, 2020
36fa108
Update main.py
anilkpandey Dec 7, 2020
12e7482
Update main.py
anilkpandey Dec 7, 2020
65b1b18
fixed LGTM issue
anilkpandey Dec 7, 2020
38fd881
Merge remote-tracking branch 'upstream/master'
anilkpandey Dec 9, 2020
2a9ab88
added pytests
anilkpandey Dec 9, 2020
a8c651e
added more tests for vlan range and fdb config commands
anilkpandey Dec 17, 2020
2800171
fix lgtm
anilkpandey Dec 18, 2020
2fcd83d
Merge remote-tracking branch 'upstream/master'
anilkpandey Nov 3, 2021
b037b7d
fixed test failures
anilkpandey Nov 9, 2021
3a28e06
Fix lgtm error
anilkpandey Nov 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,6 @@ def clear_all_fdb():
command = 'fdbclear'
run_command(command)

# 'sonic-clear fdb port' and 'sonic-clear fdb vlan' will be added later
'''
@fdb.command('port')
@click.argument('portid', required=True)
def clear_port_fdb(portid):
Expand All @@ -416,7 +414,6 @@ def clear_vlan_fdb(vlanid):
"""Clear FDB entries learned in one VLAN"""
command = 'fdbclear' + ' -v ' + vlanid
run_command(command)
'''

#
# 'line' command
Expand Down
119 changes: 119 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import jsonpatch
import netaddr
import time
import netifaces
import os
import re
Expand All @@ -16,6 +17,10 @@
from collections import OrderedDict
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat
from minigraph import parse_device_desc_xml
from itertools import count, groupby
from utilities_common.intf_filter import parse_interface_in_filter
from portconfig import get_child_ports
from sonic_py_common import device_info
from natsort import natsorted
from portconfig import get_child_ports
from socket import AF_INET, AF_INET6
Expand Down Expand Up @@ -319,6 +324,15 @@ def interface_name_is_valid(config_db, interface_name):
return True
return False

def vlan_id_is_valid(vid):
"""Check if the vlan id is in acceptable range (between 1 and 4094)
"""

if vid>0 and vid<4095:
return True

return False

def interface_name_to_alias(config_db, interface_name):
"""Return alias interface name if default name is given as argument
"""
Expand Down Expand Up @@ -2534,6 +2548,111 @@ def delete_snmptrap_server(ctx, ver):
cmd="systemctl restart snmp"
os.system (cmd)

# Validate VLAN range.
#
def vlan_range_validate(ctx, vid1, vid2):
vlan1 = 'Vlan{}'.format(vid1)
vlan2 = 'Vlan{}'.format(vid2)

if vlan_id_is_valid(vid1) is False:
ctx.fail("{} is not within allowed range of 1 through 4094".format(vlan1))
if vlan_id_is_valid(vid2) is False:
ctx.fail("{} is not within allowed range of 1 through 4094".format(vlan2))

if vid2 <= vid1:
ctx.fail(" vid2 should be greater than vid1")

#
# Return a string with ranges separated by hyphen.
#
def get_hyphenated_string(vlan_list):
vlan_list.sort()
G = (list(x) for _,x in groupby(vlan_list, lambda x,c=count(): next(c)-x))
hyphenated_string = ",".join("-".join(map(str,(g[0],g[-1])[:len(g)])) for g in G)
return hyphenated_string

#
# 'mac' group ('config mac ...')
#
@config.group()
@click.pass_context
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
def mac(ctx, redis_unix_socket_path):
"""Mac-related configuration tasks"""
kwargs = {}
if redis_unix_socket_path:
kwargs['unix_socket_path'] = redis_unix_socket_path
config_db = ConfigDBConnector(**kwargs)
config_db.connect(wait_for_init=False)
ctx.obj = {'db': config_db}

@mac.command('aging_time')
@click.argument('interval', metavar='<aging interval in sec [0-1000000], 0 to disable aging>', required=True, type=int)
@clicommon.pass_db
def set_aging_time(db, interval):
if interval not in range(0,1000001):
ctx.fail("Aging timer must be in range [0-1000000]")
db.cfgdb.set_entry('SWITCH', 'switch', {'fdb_aging_time': interval})

def mac_address_is_valid(mac):
"""Check if the mac address is valid
"""
return bool(re.match('^' + '[\:\-]'.join(['([0-9a-f]{2})']*6) + '$', mac.lower()))

@mac.command('add')
@click.argument('mac', metavar='<mac-address as xx:xx:xx:xx:xx:xx>', required=True)
@click.argument('vlan', metavar='<vlan>', required=True, type=int)
@click.argument('interface_name', metavar='<interface name>', required=True)
@clicommon.pass_db
def add_mac(db, mac, vlan, interface_name):
mac_valid = bool(mac_address_is_valid(mac))
if mac_valid == False:
anilkpandey marked this conversation as resolved.
Show resolved Hide resolved
click.echo("Incorrect mac-address format!!")

mac_valid = not bool(re.match('^' + '[\:\-]'.join(['([00]{2})']*6) + '$', mac.lower()))
if mac_valid == False:
click.echo("Invalid (Zero) mac-address!!")

mac_valid = not bool(re.match('^' + '[\:\-]'.join(['([ff]{2})']*6) + '$', mac.lower()))
if mac_valid == False:
click.echo("Invalid (Bcast) mac-address!!")

mac_is_multicast = int(mac[:2]) & 1;
if mac_is_multicast == True:
click.echo("Invalid (Multicast) mac-address!!")

vlan_valid = bool(vlan_id_is_valid(vlan))
if vlan_valid == False:
click.echo("Invalid VlanId!!")

vlan_name = 'Vlan{}'.format(vlan)

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(db.cfgdb, interface_name)
if interface_name is None:
click.echo("'interface_name' is None!")

if interface_name_is_valid(db.cfgdb, interface_name) is False:
click.echo("Interface name is invalid!!")

db.cfgdb.set_entry('FDB', (vlan_name, mac), {'port': interface_name })

@mac.command('del')
@click.argument('mac', metavar='<mac-address as xx:xx:xx:xx:xx:xx>', required=True)
@click.argument('vlan', metavar='<vlan>', required=True, type=int)
@clicommon.pass_db
def del_mac(db, mac, vlan):
mac_valid = bool(mac_address_is_valid(mac))
if mac_valid == False:
click.echo("Incorrect mac-address format!!")

vlan_valid = bool(vlan_id_is_valid(vlan))
if vlan_valid == False:
click.echo("Invalid VlanId!!")

vlan_name = 'Vlan{}'.format(vlan)

db.cfgdb.set_entry('FDB', (vlan_name, mac), None)


#
Expand Down
Loading