Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,13 @@ def add(ctx, interface_name, ip_addr):
ipaddress.ip_network(unicode(ip_addr), strict=False)
if interface_name.startswith("Ethernet"):
config_db.set_entry("INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
config_db.set_entry("INTERFACE", interface_name, {"NULL": "NULL"})
elif interface_name.startswith("PortChannel"):
config_db.set_entry("PORTCHANNEL_INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
config_db.set_entry("PORTCHANNEL_INTERFACE", interface_name, {"NULL": "NULL"})
elif interface_name.startswith("Vlan"):
config_db.set_entry("VLAN_INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
config_db.set_entry("VLAN_INTERFACE", interface_name, {"NULL": "NULL"})
elif interface_name.startswith("Loopback"):
config_db.set_entry("LOOPBACK_INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
else:
Expand All @@ -982,20 +985,38 @@ def remove(ctx, interface_name, ip_addr):
if interface_name is None:
ctx.fail("'interface_name' is None!")

if_table = ""
try:
ipaddress.ip_network(unicode(ip_addr), strict=False)
if interface_name.startswith("Ethernet"):
config_db.set_entry("INTERFACE", (interface_name, ip_addr), None)
if_table = "INTERFACE"
elif interface_name.startswith("PortChannel"):
config_db.set_entry("PORTCHANNEL_INTERFACE", (interface_name, ip_addr), None)
if_table = "PORTCHANNEL_INTERFACE"
elif interface_name.startswith("Vlan"):
config_db.set_entry("VLAN_INTERFACE", (interface_name, ip_addr), None)
if_table = "VLAN_INTERFACE"
elif interface_name.startswith("Loopback"):
config_db.set_entry("LOOPBACK_INTERFACE", (interface_name, ip_addr), None)
else:
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback]")
except ValueError:
ctx.fail("'ip_addr' is not valid.")

exists = False
if if_table:
interfaces = config_db.get_table(if_table)
for key in interfaces.keys():
if not isinstance(key, tuple):
continue
if interface_name in key:
exists = True
break

if not exists:
config_db.set_entry(if_table, interface_name, None)

#
# 'acl' group ('config acl ...')
#
Expand Down
42 changes: 41 additions & 1 deletion scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,51 @@ def __init__(self):


def migrate_pfc_wd_table(self):
# Migrate all data entries from table PFC_WD_TABLE to PFC_WD
'''
Migrate all data entries from table PFC_WD_TABLE to PFC_WD
'''
data = self.configDB.get_table('PFC_WD_TABLE')
for key in data.keys():
self.configDB.set_entry('PFC_WD', key, data[key])
self.configDB.delete_table('PFC_WD_TABLE')

def is_ip_prefix_in_key(self, key):
'''
Function to check if IP address is present in the key. If it
is present, then the key would be a tuple or else, it shall be
be string
'''
return (isinstance(key, tuple))

def migrate_interface_table(self):
'''
Migrate all data from existing INTERFACE table with IP Prefix
to have an additional ONE entry without IP Prefix. For. e.g, for an entry
"Vlan1000|192.168.0.1/21": {}", this function shall add an entry without
IP prefix as ""Vlan1000": {}". This is for VRF compatibility.
'''
if_db = []
if_tables = {
'INTERFACE',
'PORTCHANNEL_INTERFACE',
'VLAN_INTERFACE'
}
for table in if_tables:
data = self.configDB.get_table(table)
for key in data.keys():
if not self.is_ip_prefix_in_key(key):
if_db.append(key)
continue

for table in if_tables:
data = self.configDB.get_table(table)
for key in data.keys():
if not self.is_ip_prefix_in_key(key) or key[0] in if_db:
continue
log_info('Migrating interface table for ' + key[0])
self.configDB.set_entry(table, key[0], data[key])
if_db.append(key[0])


def version_unknown(self):
"""
Expand All @@ -69,6 +108,7 @@ def version_unknown(self):
# If new DB version is added in the future, the incremental
# upgrade will take care of the subsequent migrations.
self.migrate_pfc_wd_table()
self.migrate_interface_table()
self.set_version('version_1_0_1')
return 'version_1_0_1'

Expand Down
13 changes: 13 additions & 0 deletions scripts/neighbor_advertiser
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,22 @@ def extract_ip_ver_addr(ip_prefix):
return (ver, addr)


def is_ip_prefix_in_key(key):
'''
Function to check if IP address is present in the key. If it
is present, then the key would be a tuple or else, it shall be
be string
'''
return (isinstance(key, tuple))


def get_loopback_addr(ip_ver):
loopback_intfs = config_db.get_table('LOOPBACK_INTERFACE')
loopback_addr = ''

for intf in loopback_intfs.keys():
if not is_ip_prefix_in_key(intf):
continue
if 'Loopback0' in intf:
intf_ip_prefix = intf[1]
(intf_ip_ver, intf_ip_addr) = extract_ip_ver_addr(intf_ip_prefix)
Expand Down Expand Up @@ -170,6 +181,8 @@ def get_vlan_addr(vlan_intf_name, ip_ver):
vlan_addr = []

for intf in vlan_intfs.keys():
if not is_ip_prefix_in_key(intf):
continue
if vlan_intf_name in intf:
intf_ip_prefix = intf[1]
(intf_ip_ver, intf_ip_addr) = extract_ip_ver_addr(intf_ip_prefix)
Expand Down
10 changes: 9 additions & 1 deletion scripts/pcmping
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,21 @@ def get_portchannel(interface):
sys.stderr.write("Interface %s is not a portchannel member. Please Check!\n" % interface)
sys.exit(1)

def is_ip_prefix_in_key(key):
'''
Function to check if IP address is present in the key. If it
is present, then the key would be a tuple or else, it shall be
be string
'''
return (isinstance(key, tuple))

def get_portchannel_ipv4(portchannel_name):
configdb = swsssdk.ConfigDBConnector()
configdb.connect()
config = configdb.get_config()
portchannel_interfaces = config["PORTCHANNEL_INTERFACE"]
for key in portchannel_interfaces.keys():
if len(key) == 1:
if not is_ip_prefix_in_key(key):
continue
pc, ip = key
ip = ip.split("/")[0]
Expand Down
11 changes: 10 additions & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ def get_interface_mode():
return mode


def is_ip_prefix_in_key(key):
'''
Function to check if IP address is present in the key. If it
is present, then the key would be a tuple or else, it shall be
be string
'''
return (isinstance(key, tuple))


# Global class instance for SONiC interface name to alias conversion
iface_alias_converter = InterfaceAliasConverter()

Expand Down Expand Up @@ -1480,7 +1489,7 @@ def brief(verbose):

# Parsing VLAN Gateway info
for key in natsorted(vlan_ip_data.keys()):
if len(key) == 1:
if not is_ip_prefix_in_key(key):
continue
interface_key = str(key[0].strip("Vlan"))
interface_value = str(key[1])
Expand Down