@@ -890,6 +890,7 @@ def parse_meta(meta, hname):
890
890
switch_type = None
891
891
max_cores = None
892
892
kube_data = {}
893
+ macsec_profile = {}
893
894
device_metas = meta .find (str (QName (ns , "Devices" )))
894
895
for device in device_metas .findall (str (QName (ns1 , "DeviceMetadata" ))):
895
896
if device .find (str (QName (ns1 , "Name" ))).text .lower () == hname .lower ():
@@ -930,7 +931,9 @@ def parse_meta(meta, hname):
930
931
kube_data ["enable" ] = value
931
932
elif name == "KubernetesServerIp" :
932
933
kube_data ["ip" ] = value
933
- return syslog_servers , dhcp_servers , dhcpv6_servers , ntp_servers , tacacs_servers , mgmt_routes , erspan_dst , deployment_id , region , cloudtype , resource_type , downstream_subrole , switch_id , switch_type , max_cores , kube_data
934
+ elif name == 'MacSecProfile' :
935
+ macsec_profile = parse_macsec_profile (value )
936
+ return syslog_servers , dhcp_servers , dhcpv6_servers , ntp_servers , tacacs_servers , mgmt_routes , erspan_dst , deployment_id , region , cloudtype , resource_type , downstream_subrole , switch_id , switch_type , max_cores , kube_data , macsec_profile
934
937
935
938
936
939
def parse_system_defaults (meta ):
@@ -979,6 +982,7 @@ def parse_linkmeta(meta, hname):
979
982
upper_tor_hostname = ''
980
983
lower_tor_hostname = ''
981
984
auto_negotiation = None
985
+ macsec_enabled = False
982
986
983
987
properties = linkmeta .find (str (QName (ns1 , "Properties" )))
984
988
for device_property in properties .findall (str (QName (ns1 , "DeviceProperty" ))):
@@ -994,6 +998,8 @@ def parse_linkmeta(meta, hname):
994
998
lower_tor_hostname = value
995
999
elif name == "AutoNegotiation" :
996
1000
auto_negotiation = value
1001
+ elif name == "MacSecEnabled" :
1002
+ macsec_enabled = value
997
1003
998
1004
linkmetas [port ] = {}
999
1005
if fec_disabled :
@@ -1005,14 +1011,28 @@ def parse_linkmeta(meta, hname):
1005
1011
linkmetas [port ]["PeerSwitch" ] = upper_tor_hostname
1006
1012
if auto_negotiation :
1007
1013
linkmetas [port ]["AutoNegotiation" ] = auto_negotiation
1014
+ if macsec_enabled :
1015
+ linkmetas [port ]["MacSecEnabled" ] = macsec_enabled
1008
1016
return linkmetas
1009
1017
1018
+ def parse_macsec_profile (val_string ):
1019
+ macsec_profile = {}
1020
+ values = val_string .strip ().split ()
1021
+ for val in values :
1022
+ keys = val .strip ().split ('=' )
1023
+ if keys [0 ] == 'PrimaryKey' :
1024
+ macsec_profile ['PrimaryKey' ] = keys [1 ].strip ('\" ' )
1025
+ elif keys [0 ] == 'FallbackKey' :
1026
+ macsec_profile ['FallbackKey' ] = keys [1 ].strip ('\" ' )
1027
+
1028
+ return macsec_profile
1010
1029
1011
1030
def parse_asic_meta (meta , hname ):
1012
1031
sub_role = None
1013
1032
switch_id = None
1014
1033
switch_type = None
1015
1034
max_cores = None
1035
+ macsec_profile = {}
1016
1036
device_metas = meta .find (str (QName (ns , "Devices" )))
1017
1037
for device in device_metas .findall (str (QName (ns1 , "DeviceMetadata" ))):
1018
1038
if device .find (str (QName (ns1 , "Name" ))).text .lower () == hname .lower ():
@@ -1028,7 +1048,10 @@ def parse_asic_meta(meta, hname):
1028
1048
switch_type = value
1029
1049
elif name == "MaxCores" :
1030
1050
max_cores = value
1031
- return sub_role , switch_id , switch_type , max_cores
1051
+ elif name == 'MacSecProfile' :
1052
+ macsec_profile = parse_macsec_profile (value )
1053
+
1054
+ return sub_role , switch_id , switch_type , max_cores , macsec_profile
1032
1055
1033
1056
def parse_deviceinfo (meta , hwsku ):
1034
1057
port_speeds = {}
@@ -1289,6 +1312,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1289
1312
kube_data = {}
1290
1313
static_routes = {}
1291
1314
system_defaults = {}
1315
+ macsec_profile = {}
1292
1316
1293
1317
hwsku_qn = QName (ns , "HwSku" )
1294
1318
hostname_qn = QName (ns , "Hostname" )
@@ -1319,7 +1343,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1319
1343
elif child .tag == str (QName (ns , "UngDec" )):
1320
1344
(u_neighbors , u_devices , _ , _ , _ , _ , _ , _ ) = parse_png (child , hostname , None )
1321
1345
elif child .tag == str (QName (ns , "MetadataDeclaration" )):
1322
- (syslog_servers , dhcp_servers , dhcpv6_servers , ntp_servers , tacacs_servers , mgmt_routes , erspan_dst , deployment_id , region , cloudtype , resource_type , downstream_subrole , switch_id , switch_type , max_cores , kube_data ) = parse_meta (child , hostname )
1346
+ (syslog_servers , dhcp_servers , dhcpv6_servers , ntp_servers , tacacs_servers , mgmt_routes , erspan_dst , deployment_id , region , cloudtype , resource_type , downstream_subrole , switch_id , switch_type , max_cores , kube_data , macsec_profile ) = parse_meta (child , hostname )
1323
1347
elif child .tag == str (QName (ns , "LinkMetadataDeclaration" )):
1324
1348
linkmetas = parse_linkmeta (child , hostname )
1325
1349
elif child .tag == str (QName (ns , "DeviceInfos" )):
@@ -1335,7 +1359,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1335
1359
elif child .tag == str (QName (ns , "PngDec" )):
1336
1360
(neighbors , devices , port_speed_png ) = parse_asic_png (child , asic_name , hostname )
1337
1361
elif child .tag == str (QName (ns , "MetadataDeclaration" )):
1338
- (sub_role , switch_id , switch_type , max_cores ) = parse_asic_meta (child , asic_name )
1362
+ (sub_role , switch_id , switch_type , max_cores , macsec_profile ) = parse_asic_meta (child , asic_name )
1339
1363
elif child .tag == str (QName (ns , "LinkMetadataDeclaration" )):
1340
1364
linkmetas = parse_linkmeta (child , hostname )
1341
1365
elif child .tag == str (QName (ns , "DeviceInfos" )):
@@ -1538,6 +1562,11 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
1538
1562
if autoneg :
1539
1563
port ['autoneg' ] = 'on' if autoneg .lower () == 'true' else 'off'
1540
1564
1565
+ # If macsec is enabled on interface, and profile is valid, add the profile to port
1566
+ macsec_enabled = linkmetas .get (alias , {}).get ('MacSecEnabled' )
1567
+ if macsec_enabled and 'PrimaryKey' in macsec_profile :
1568
+ port ['macsec' ] = macsec_profile ['PrimaryKey' ]
1569
+
1541
1570
# If connected to a smart cable, get the connection position
1542
1571
for port_name , port in ports .items ():
1543
1572
if port_name in mux_cable_ports :
@@ -1872,15 +1901,15 @@ def parse_asic_sub_role(filename, asic_name):
1872
1901
root = ET .parse (filename ).getroot ()
1873
1902
for child in root :
1874
1903
if child .tag == str (QName (ns , "MetadataDeclaration" )):
1875
- sub_role , _ , _ , _ = parse_asic_meta (child , asic_name )
1904
+ sub_role , _ , _ , _ , _ = parse_asic_meta (child , asic_name )
1876
1905
return sub_role
1877
1906
1878
1907
def parse_asic_switch_type (filename , asic_name ):
1879
1908
if os .path .isfile (filename ):
1880
1909
root = ET .parse (filename ).getroot ()
1881
1910
for child in root :
1882
1911
if child .tag == str (QName (ns , "MetadataDeclaration" )):
1883
- _ , _ , switch_type , _ = parse_asic_meta (child , asic_name )
1912
+ _ , _ , switch_type , _ , _ = parse_asic_meta (child , asic_name )
1884
1913
return switch_type
1885
1914
return None
1886
1915
0 commit comments