Skip to content

Commit

Permalink
[sonic_sku_create] Add SKU creation support for Arista devices (sonic…
Browse files Browse the repository at this point in the history
…-net#1841)

What I did
Let's add Arista support to the SKU creator tool
NOTE: only creation from XML file is supported now

How I did it
Enable the SKU creator tool to parse Arista port alias

Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
  • Loading branch information
lolyu authored Oct 5, 2021
1 parent bed8f72 commit 88baf3d
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 46 deletions.
65 changes: 43 additions & 22 deletions scripts/sonic_sku_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""

import argparse
import itertools
import json
import os
import re
Expand Down Expand Up @@ -74,6 +75,11 @@ class SkuCreate(object):
Tool for SKU creator
"""

PORT_ALIAS_PATTERNS = (
re.compile(r"^etp(?P<port_index>\d+)(?P<lane>[a-d]?)"),
re.compile(r"^Ethernet(?P<port_index>\d+)(/)?(?(2)(?P<lane>[1-4]+))")
)

def __init__(self):

self.portconfig_dict = {}
Expand All @@ -96,7 +102,7 @@ def __init__(self):
self.bko_dict = {}

def sku_def_parser(self, sku_def):
# Parsing XML sku definition file to extract Interface speed and InterfaceName(alias) <etp<#><a/b/c/d> to be used to analyze split configuration
# Parsing XML sku definition file to extract Interface speed and InterfaceName(alias) <etp<#><a/b/c/d>|<Ethernet<#>/<#> to be used to analyze split configuration
# Rest of the fields are used as placeholders for portconfig_dict [name,lanes,SPEED,ALIAS,index]
try:
f = open(str(sku_def),"r")
Expand Down Expand Up @@ -525,20 +531,28 @@ def break_a_port(self, port_name, port_split):
exit(1)
self.break_in_cfg(self.cfg_file,port_name,port_split,lanes_str_result)

def _parse_interface_alias(self, alias):
"""Analyze the front panel port index and split index based on the alias."""
for alias_pattern in self.PORT_ALIAS_PATTERNS:
m = alias_pattern.match(alias)
if m:
return m.group("port_index"), m.group("lane")
return None, None

def split_analyze(self):
# Analyze the front panl ports split based on the interfaces alias names
# fpp_split is a hash with key=front panel port and values is a list of lists ([alias],[index])
alias_index = PORTCONFIG_HEADER.index('alias')
for idx, ifc in self.portconfig_dict.items():
pattern = '^etp([0-9]{1,})([a-d]?)'
m = re.match(pattern,str(ifc[alias_index]))
if int(m.group(1)) not in self.fpp_split :
self.fpp_split[int(m.group(1))] = [[ifc[alias_index]],[idx]] #1
pi, _ = self._parse_interface_alias(ifc[alias_index])
pi = int(pi)
if pi not in self.fpp_split :
self.fpp_split[pi] = [[ifc[alias_index]],[idx]] #1
else:
self.fpp_split[int(m.group(1))][0].append(str(ifc[alias_index])) #+= 1
self.fpp_split[int(m.group(1))][1].append(idx)
self.fpp_split[pi][0].append(str(ifc[alias_index])) #+= 1
self.fpp_split[pi][1].append(idx)
if (self.verbose):
print("split_analyze -> ",m.group(1), " : ", self.fpp_split[int(m.group(1))])
print("split_analyze -> ", pi, " : ", self.fpp_split[pi])
self.num_of_fpp = len(list(self.fpp_split.keys()))

def get_default_lanes(self):
Expand All @@ -549,14 +563,14 @@ def get_default_lanes(self):
if line_header[0] == "#" : del line_header[0] # if hashtag is in a different column, remove it to align column header and data
alias_index = line_header.index('alias')
lanes_index = line_header.index('lanes')
pattern = '^etp([0-9]{1,})'
for line in f:
line_arr = line.split()
m = re.match(pattern,line_arr[alias_index])
self.default_lanes_per_port.insert(int(m.group(1))-1,line_arr[lanes_index])
pi, _ = self._parse_interface_alias(line_arr[alias_index])
pi = int(pi)
self.default_lanes_per_port.insert(pi - 1, line_arr[lanes_index])
if (self.verbose):
print("get_default_lanes -> ",m.group(1), " : ", self.default_lanes_per_port[int(m.group(1))-1])
f.close()
print("get_default_lanes -> ", pi, " : ", self.default_lanes_per_port[pi - 1])

except IOError:
print("Could not open file "+ self.base_file_path, file=sys.stderr)
exit(1)
Expand All @@ -572,19 +586,26 @@ def set_lanes(self):
idx_arr = sorted(values[1])

splt = len(splt_arr)
pattern = '(\d+),(\d+),(\d+),(\d+)' #Currently the assumption is that the default(base) is 4 lanes
lanes = [_.strip() for _ in self.default_lanes_per_port[fp - 1].split(",")]
lanes_count = len(lanes)
if lanes_count % splt != 0:
print("Lanes(%s) could not be evenly splitted by %d." % (self.default_lanes_per_port[fp - 1], splt))
exit(1)

# split the lanes
it = iter(lanes)
lanes_splitted = list(iter(lambda: tuple(itertools.islice(it, lanes_count // splt)), ()))

m = re.match(pattern,self.default_lanes_per_port[fp-1])
if (splt == 1):
self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)+","+m.group(2)+","+m.group(3)+","+m.group(4)
self.portconfig_dict[idx_arr[0]][lanes_index] = ",".join(lanes_splitted[0])
self.portconfig_dict[idx_arr[0]][index_index] = str(fp)
self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4)
if (self.verbose):
print("set_lanes -> FP: ",fp, "Split: ",splt)
print("PortConfig_dict ",idx_arr[0],":", self.portconfig_dict[idx_arr[0]])
elif (splt == 2):
self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)+","+m.group(2)
self.portconfig_dict[idx_arr[1]][lanes_index] = m.group(3)+","+m.group(4)
self.portconfig_dict[idx_arr[0]][lanes_index] = ",".join(lanes_splitted[0])
self.portconfig_dict[idx_arr[1]][lanes_index] = ",".join(lanes_splitted[1])
self.portconfig_dict[idx_arr[0]][index_index] = str(fp)
self.portconfig_dict[idx_arr[1]][index_index] = str(fp)
self.portconfig_dict[idx_arr[0]][name_index] = "Ethernet"+str((fp-1)*4)
Expand All @@ -594,10 +615,10 @@ def set_lanes(self):
print("PortConfig_dict ",idx_arr[0],":", self.portconfig_dict[idx_arr[0]])
print("PortConfig_dict ",idx_arr[1],":", self.portconfig_dict[idx_arr[1]])
elif (splt == 4):
self.portconfig_dict[idx_arr[0]][lanes_index] = m.group(1)
self.portconfig_dict[idx_arr[1]][lanes_index] = m.group(2)
self.portconfig_dict[idx_arr[2]][lanes_index] = m.group(3)
self.portconfig_dict[idx_arr[3]][lanes_index] = m.group(4)
self.portconfig_dict[idx_arr[0]][lanes_index] = ",".join(lanes_splitted[0])
self.portconfig_dict[idx_arr[1]][lanes_index] = ",".join(lanes_splitted[1])
self.portconfig_dict[idx_arr[2]][lanes_index] = ",".join(lanes_splitted[2])
self.portconfig_dict[idx_arr[3]][lanes_index] = ",".join(lanes_splitted[3])
self.portconfig_dict[idx_arr[0]][index_index] = str(fp)
self.portconfig_dict[idx_arr[1]][index_index] = str(fp)
self.portconfig_dict[idx_arr[2]][index_index] = str(fp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# name lanes alias index speed
Ethernet0 1,2,3,4 Ethernet1/1 1 100000
Ethernet4 5,6,7,8 Ethernet2/1 2 100000
Ethernet8 9,10,11,12 Ethernet3/1 3 100000
Ethernet12 13,14,15,16 Ethernet4/1 4 100000
Ethernet16 21,22,23,24 Ethernet5/1 5 100000
Ethernet20 17,18,19,20 Ethernet6/1 6 100000
Ethernet24 25,26,27,28 Ethernet7/1 7 100000
Ethernet28 29,30,31,32 Ethernet8/1 8 100000
Ethernet32 37,38,39,40 Ethernet9/1 9 100000
Ethernet36 33,34,35,36 Ethernet10/1 10 100000
Ethernet40 41,42,43,44 Ethernet11/1 11 100000
Ethernet44 45,46,47,48 Ethernet12/1 12 100000
Ethernet48 53,54,55,56 Ethernet13/1 13 100000
Ethernet52 49,50,51,52 Ethernet14/1 14 100000
Ethernet56 57,58,59,60 Ethernet15/1 15 100000
Ethernet60 61,62,63,64 Ethernet16/1 16 100000
Ethernet64 69,70,71,72 Ethernet17/1 17 100000
Ethernet68 65,66,67,68 Ethernet18/1 18 100000
Ethernet72 73,74,75,76 Ethernet19/1 19 100000
Ethernet76 77,78,79,80 Ethernet20/1 20 100000
Ethernet80 85,86,87,88 Ethernet21/1 21 100000
Ethernet84 81,82,83,84 Ethernet22/1 22 100000
Ethernet88 89,90,91,92 Ethernet23/1 23 100000
Ethernet92 93,94,95,96 Ethernet24/1 24 100000
Ethernet96 101,102,103,104 Ethernet25/1 25 100000
Ethernet100 97,98,99,100 Ethernet26/1 26 100000
Ethernet104 105,106,107,108 Ethernet27/1 27 100000
Ethernet108 109,110,111,112 Ethernet28/1 28 100000
Ethernet112 117,118,119,120 Ethernet29/1 29 100000
Ethernet116 113,114,115,116 Ethernet30/1 30 100000
Ethernet120 121,122,123,124 Ethernet31/1 31 100000
Ethernet124 125,126,127,128 Ethernet32/1 32 100000
Ethernet128 129 Ethernet33 33 10000
Ethernet132 128 Ethernet34 34 10000
61 changes: 61 additions & 0 deletions tests/sku_create_input/7050_files/Arista-7050CX3-32S-D48C8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0"?>
<DeviceInfo Vendor="Arista" BaseSku="Arista-7050CX3-32S" HwSku="Arista-7050CX3-32S-D48C8_NEW" ClusterSku="Arista-7050CX3-32S">
<Ethernet>
<Interface Index="1" PortName="0" InterfaceName="Ethernet1/1" Speed="50000" />
<Interface Index="2" PortName="2" InterfaceName="Ethernet1/3" Speed="50000" />
<Interface Index="3" PortName="4" InterfaceName="Ethernet2/1" Speed="50000" />
<Interface Index="4" PortName="6" InterfaceName="Ethernet2/3" Speed="50000" />
<Interface Index="5" PortName="8" InterfaceName="Ethernet3/1" Speed="50000" />
<Interface Index="6" PortName="10" InterfaceName="Ethernet3/3" Speed="50000" />
<Interface Index="7" PortName="12" InterfaceName="Ethernet4/1" Speed="50000" />
<Interface Index="8" PortName="14" InterfaceName="Ethernet4/3" Speed="50000" />
<Interface Index="9" PortName="16" InterfaceName="Ethernet5/1" Speed="50000" />
<Interface Index="10" PortName="18" InterfaceName="Ethernet5/3" Speed="50000" />
<Interface Index="11" PortName="20" InterfaceName="Ethernet6/1" Speed="50000" />
<Interface Index="12" PortName="22" InterfaceName="Ethernet6/3" Speed="50000" />
<Interface Index="13" PortName="24" InterfaceName="Ethernet7/1" Speed="100000" />
<Interface Index="14" PortName="28" InterfaceName="Ethernet8/1" Speed="100000" />
<Interface Index="15" PortName="32" InterfaceName="Ethernet9/1" Speed="100000" />
<Interface Index="16" PortName="36" InterfaceName="Ethernet10/1" Speed="100000" />
<Interface Index="17" PortName="40" InterfaceName="Ethernet11/1" Speed="50000" />
<Interface Index="18" PortName="42" InterfaceName="Ethernet11/3" Speed="50000" />
<Interface Index="19" PortName="44" InterfaceName="Ethernet12/1" Speed="50000" />
<Interface Index="20" PortName="46" InterfaceName="Ethernet12/3" Speed="50000" />
<Interface Index="21" PortName="48" InterfaceName="Ethernet13/1" Speed="50000" />
<Interface Index="22" PortName="50" InterfaceName="Ethernet13/3" Speed="50000" />
<Interface Index="23" PortName="52" InterfaceName="Ethernet14/1" Speed="50000" />
<Interface Index="24" PortName="54" InterfaceName="Ethernet14/3" Speed="50000" />
<Interface Index="25" PortName="56" InterfaceName="Ethernet15/1" Speed="50000" />
<Interface Index="26" PortName="58" InterfaceName="Ethernet15/3" Speed="50000" />
<Interface Index="27" PortName="60" InterfaceName="Ethernet16/1" Speed="50000" />
<Interface Index="28" PortName="62" InterfaceName="Ethernet16/3" Speed="50000" />
<Interface Index="29" PortName="64" InterfaceName="Ethernet17/1" Speed="50000" />
<Interface Index="30" PortName="66" InterfaceName="Ethernet17/3" Speed="50000" />
<Interface Index="31" PortName="68" InterfaceName="Ethernet18/1" Speed="50000" />
<Interface Index="32" PortName="70" InterfaceName="Ethernet18/3" Speed="50000" />
<Interface Index="33" PortName="72" InterfaceName="Ethernet19/1" Speed="50000" />
<Interface Index="34" PortName="74" InterfaceName="Ethernet19/3" Speed="50000" />
<Interface Index="35" PortName="76" InterfaceName="Ethernet20/1" Speed="50000" />
<Interface Index="36" PortName="78" InterfaceName="Ethernet20/3" Speed="50000" />
<Interface Index="37" PortName="80" InterfaceName="Ethernet21/1" Speed="50000" />
<Interface Index="38" PortName="82" InterfaceName="Ethernet21/3" Speed="50000" />
<Interface Index="39" PortName="84" InterfaceName="Ethernet22/1" Speed="50000" />
<Interface Index="40" PortName="86" InterfaceName="Ethernet22/3" Speed="50000" />
<Interface Index="41" PortName="88" InterfaceName="Ethernet23/1" Speed="100000" />
<Interface Index="42" PortName="92" InterfaceName="Ethernet24/1" Speed="100000" />
<Interface Index="43" PortName="96" InterfaceName="Ethernet25/1" Speed="100000" />
<Interface Index="44" PortName="100" InterfaceName="Ethernet26/1" Speed="100000" />
<Interface Index="45" PortName="104" InterfaceName="Ethernet27/1" Speed="50000" />
<Interface Index="46" PortName="106" InterfaceName="Ethernet27/3" Speed="50000" />
<Interface Index="47" PortName="108" InterfaceName="Ethernet28/1" Speed="50000" />
<Interface Index="48" PortName="110" InterfaceName="Ethernet28/3" Speed="50000" />
<Interface Index="49" PortName="112" InterfaceName="Ethernet29/1" Speed="50000" />
<Interface Index="50" PortName="114" InterfaceName="Ethernet29/3" Speed="50000" />
<Interface Index="51" PortName="116" InterfaceName="Ethernet30/1" Speed="50000" />
<Interface Index="52" PortName="118" InterfaceName="Ethernet30/3" Speed="50000" />
<Interface Index="53" PortName="120" InterfaceName="Ethernet31/1" Speed="50000" />
<Interface Index="54" PortName="122" InterfaceName="Ethernet31/3" Speed="50000" />
<Interface Index="55" PortName="124" InterfaceName="Ethernet32/1" Speed="50000" />
<Interface Index="56" PortName="126" InterfaceName="Ethernet32/3" Speed="50000" />
</Ethernet>
</DeviceInfo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# name lanes alias index speed
Ethernet0 1,2 Ethernet1/1 1 50000
Ethernet2 3,4 Ethernet1/3 1 50000
Ethernet4 5,6 Ethernet2/1 2 50000
Ethernet6 7,8 Ethernet2/3 2 50000
Ethernet8 9,10 Ethernet3/1 3 50000
Ethernet10 11,12 Ethernet3/3 3 50000
Ethernet12 13,14 Ethernet4/1 4 50000
Ethernet14 15,16 Ethernet4/3 4 50000
Ethernet16 21,22 Ethernet5/1 5 50000
Ethernet18 23,24 Ethernet5/3 5 50000
Ethernet20 17,18 Ethernet6/1 6 50000
Ethernet22 19,20 Ethernet6/3 6 50000
Ethernet24 25,26,27,28 Ethernet7/1 7 100000
Ethernet28 29,30,31,32 Ethernet8/1 8 100000
Ethernet32 37,38,39,40 Ethernet9/1 9 100000
Ethernet36 33,34,35,36 Ethernet10/1 10 100000
Ethernet40 41,42 Ethernet11/1 11 50000
Ethernet42 43,44 Ethernet11/3 11 50000
Ethernet44 45,46 Ethernet12/1 12 50000
Ethernet46 47,48 Ethernet12/3 12 50000
Ethernet48 53,54 Ethernet13/1 13 50000
Ethernet50 55,56 Ethernet13/3 13 50000
Ethernet52 49,50 Ethernet14/1 14 50000
Ethernet54 51,52 Ethernet14/3 14 50000
Ethernet56 57,58 Ethernet15/1 15 50000
Ethernet58 59,60 Ethernet15/3 15 50000
Ethernet60 61,62 Ethernet16/1 16 50000
Ethernet62 63,64 Ethernet16/3 16 50000
Ethernet64 69,70 Ethernet17/1 17 50000
Ethernet66 71,72 Ethernet17/3 17 50000
Ethernet68 65,66 Ethernet18/1 18 50000
Ethernet70 67,68 Ethernet18/3 18 50000
Ethernet72 73,74 Ethernet19/1 19 50000
Ethernet74 75,76 Ethernet19/3 19 50000
Ethernet76 77,78 Ethernet20/1 20 50000
Ethernet78 79,80 Ethernet20/3 20 50000
Ethernet80 85,86 Ethernet21/1 21 50000
Ethernet82 87,88 Ethernet21/3 21 50000
Ethernet84 81,82 Ethernet22/1 22 50000
Ethernet86 83,84 Ethernet22/3 22 50000
Ethernet88 89,90,91,92 Ethernet23/1 23 100000
Ethernet92 93,94,95,96 Ethernet24/1 24 100000
Ethernet96 101,102,103,104 Ethernet25/1 25 100000
Ethernet100 97,98,99,100 Ethernet26/1 26 100000
Ethernet104 105,106 Ethernet27/1 27 50000
Ethernet106 107,108 Ethernet27/3 27 50000
Ethernet108 109,110 Ethernet28/1 28 50000
Ethernet110 111,112 Ethernet28/3 28 50000
Ethernet112 117,118 Ethernet29/1 29 50000
Ethernet114 119,120 Ethernet29/3 29 50000
Ethernet116 113,114 Ethernet30/1 30 50000
Ethernet118 115,116 Ethernet30/3 30 50000
Ethernet120 121,122 Ethernet31/1 31 50000
Ethernet122 123,124 Ethernet31/3 31 50000
Ethernet124 125,126 Ethernet32/1 32 50000
Ethernet126 127,128 Ethernet32/3 32 50000
1 change: 1 addition & 0 deletions tests/sku_create_input/7050_files/default_sku
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Arista-7050CX3-32S-C32 t1
Loading

0 comments on commit 88baf3d

Please sign in to comment.