@@ -83,7 +83,6 @@ def __init__(self):
8383 self .asic_topo_config = {}
8484
8585 def parse_topo_defintion (self , topo_definition , po_map , dut_num , neigh_type = 'VMs' ):
86- dut_asn = topo_definition ['configuration_properties' ]['common' ]['dut_asn' ]
8786 vmconfig = dict ()
8887 for vm in topo_definition ['topology' ][neigh_type ]:
8988 vmconfig [vm ] = dict ()
@@ -106,77 +105,93 @@ def parse_topo_defintion(self, topo_definition, po_map, dut_num, neigh_type='VMs
106105 for asic_intf in topo_definition ['topology' ][neigh_type ][vm ]['asic_intfs' ]:
107106 vmconfig [vm ]['asic_intfs' ][dut_index ].append (asic_intf )
108107
108+
109109 # physical interface
110- for intf in topo_definition ['configuration' ][vm ]['interfaces' ]:
111- if (neigh_type == 'VMs' and 'Ethernet' in intf ) or \
112- (neigh_type == 'NEIGH_ASIC' and re .match ("Eth(\d+)-" , intf )):
113- dut_index = 0
114- if 'dut_index' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ]:
115- dut_index = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['dut_index' ]
116- if 'lacp' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ]:
117- po_map [topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['lacp' ]] = dut_index
118-
119- vmconfig [vm ]['intfs' ][dut_index ].append (intf )
110+ if 'configuration' in topo_definition :
111+ if 'interfaces' in topo_definition ['configuration' ][vm ]:
112+ for intf in topo_definition ['configuration' ][vm ]['interfaces' ]:
113+ dut_index = 0
114+ if neigh_type == 'NEIGH_ASIC' and re .match ("Eth(\d+)-" , intf ):
115+ vmconfig [vm ]['intfs' ][dut_index ].append (intf )
116+ elif 'Ethernet' in intf :
117+ if 'dut_index' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ]:
118+ dut_index = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['dut_index' ]
119+ if 'lacp' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ]:
120+ po_map [topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['lacp' ]] = dut_index
121+ vmconfig [vm ]['intfs' ][dut_index ].append (intf )
120122
121123 # ip interface
122124 vmconfig [vm ]['ip_intf' ] = [None ] * dut_num
123125 vmconfig [vm ]['peer_ipv4' ] = [None ] * dut_num
124126 vmconfig [vm ]['ipv4mask' ] = [None ] * dut_num
125127 vmconfig [vm ]['peer_ipv6' ] = [None ] * dut_num
126128 vmconfig [vm ]['ipv6mask' ] = [None ] * dut_num
127-
128-
129- for intf in topo_definition ['configuration' ][vm ]['interfaces' ]:
130- dut_index = 0
131- if (neigh_type == 'VMs' and 'Ethernet' in intf ) or \
132- (neigh_type == 'NEIGH_ASIC' and re .match ("Eth(\d+)-" , intf )):
133- if 'dut_index' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ]:
134- dut_index = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['dut_index' ]
135- elif 'Port-Channel' in intf :
136- m = re .search ("(\d+)" , intf )
137- dut_index = po_map [int (m .group (1 ))]
138-
139- if 'ipv4' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ] and ('loopback' not in intf .lower ()):
140- (peer_ipv4 , ipv4_mask ) = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['ipv4' ].split ('/' )
141- vmconfig [vm ]['peer_ipv4' ][dut_index ] = peer_ipv4
142- vmconfig [vm ]['ipv4mask' ][dut_index ] = ipv4_mask
143- vmconfig [vm ]['ip_intf' ][dut_index ] = intf
144- if 'ipv6' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ] and ('loopback' not in intf .lower ()):
145- (ipv6_addr , ipv6_mask ) = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['ipv6' ].split ('/' )
146- vmconfig [vm ]['peer_ipv6' ][dut_index ] = ipv6_addr .upper ()
147- vmconfig [vm ]['ipv6mask' ][dut_index ] = ipv6_mask
148- vmconfig [vm ]['ip_intf' ][dut_index ] = intf
149-
150- # bgp
151129 vmconfig [vm ]['bgp_ipv4' ] = [None ] * dut_num
152130 vmconfig [vm ]['bgp_ipv6' ] = [None ] * dut_num
153- vmconfig [vm ]['bgp_asn' ] = topo_definition ['configuration' ][vm ]['bgp' ]['asn' ]
154- for ipstr in topo_definition ['configuration' ][vm ]['bgp' ]['peers' ][dut_asn ]:
155- if sys .version_info < (3 , 0 ):
156- ip = ipaddress .ip_address (ipstr .decode ('utf8' ))
157- else :
158- ip = ipaddress .ip_address (ipstr )
159- for dut_index in range (0 , dut_num ):
160- if ip .version == 4 :
161- # Each VM might not be connected to all the DUT's, so check if this VM is a peer to DUT at dut_index
162- if vmconfig [vm ]['peer_ipv4' ][dut_index ]:
163- ipsubnet_str = vmconfig [vm ]['peer_ipv4' ][dut_index ]+ '/' + vmconfig [vm ]['ipv4mask' ][dut_index ]
164- if sys .version_info < (3 , 0 ):
165- ipsubnet = ipaddress .ip_interface (ipsubnet_str .decode ('utf8' ))
166- else :
167- ipsubnet = ipaddress .ip_interface (ipsubnet_str )
168- if ip in ipsubnet .network :
131+ vmconfig [vm ]['bgp_asn' ] = None
132+
133+
134+ if 'configuration' in topo_definition :
135+ if 'interfaces' in topo_definition ['configuration' ][vm ]:
136+ for intf in topo_definition ['configuration' ][vm ]['interfaces' ]:
137+ dut_index = 0
138+ if neigh_type == 'NEIGH_ASIC' :
139+ pass
140+ elif 'Ethernet' in intf :
141+ if 'dut_index' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ]:
142+ dut_index = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['dut_index' ]
143+ elif 'Port-Channel' in intf :
144+ m = re .search ("(\d+)" , intf )
145+ dut_index = po_map [int (m .group (1 ))]
146+
147+ if isinstance (topo_definition ['configuration' ][vm ]['interfaces' ],dict ) and 'ipv4' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ] and ('loopback' not in intf .lower ()):
148+ (peer_ipv4 , ipv4_mask ) = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['ipv4' ].split ('/' )
149+ vmconfig [vm ]['peer_ipv4' ][dut_index ] = peer_ipv4
150+ vmconfig [vm ]['ipv4mask' ][dut_index ] = ipv4_mask
151+ vmconfig [vm ]['ip_intf' ][dut_index ] = intf
152+ if isinstance (topo_definition ['configuration' ][vm ]['interfaces' ],dict ) and 'ipv6' in topo_definition ['configuration' ][vm ]['interfaces' ][intf ] and ('loopback' not in intf .lower ()):
153+ (ipv6_addr , ipv6_mask ) = topo_definition ['configuration' ][vm ]['interfaces' ][intf ]['ipv6' ].split ('/' )
154+ vmconfig [vm ]['peer_ipv6' ][dut_index ] = ipv6_addr .upper ()
155+ vmconfig [vm ]['ipv6mask' ][dut_index ] = ipv6_mask
156+ vmconfig [vm ]['ip_intf' ][dut_index ] = intf
157+ # bgp
158+ vmconfig [vm ]['bgp_asn' ] = topo_definition ['configuration' ][vm ]['bgp' ]['asn' ]
159+ dut_asn = topo_definition ['configuration_properties' ]['common' ]['dut_asn' ]
160+ for ipstr in topo_definition ['configuration' ][vm ]['bgp' ]['peers' ][dut_asn ]:
161+ ip_mask = None
162+ if '/' in ipstr :
163+ (ipstr , ip_mask ) = ipstr .split ('/' )
164+ if sys .version_info < (3 , 0 ):
165+ ip = ipaddress .ip_address (ipstr .decode ('utf8' ))
166+ else :
167+ ip = ipaddress .ip_address (ipstr )
168+ for dut_index in range (0 , dut_num ):
169+ if ip .version == 4 :
170+ # Each VM might not be connected to all the DUT's, so check if this VM is a peer to DUT at dut_index
171+ if vmconfig [vm ]['peer_ipv4' ][dut_index ]:
172+ ipsubnet_str = vmconfig [vm ]['peer_ipv4' ][dut_index ]+ '/' + vmconfig [vm ]['ipv4mask' ][dut_index ]
173+ if sys .version_info < (3 , 0 ):
174+ ipsubnet = ipaddress .ip_interface (ipsubnet_str .decode ('utf8' ))
175+ else :
176+ ipsubnet = ipaddress .ip_interface (ipsubnet_str )
177+ if ip in ipsubnet .network :
178+ vmconfig [vm ]['bgp_ipv4' ][dut_index ] = ipstr .upper ()
179+ elif neigh_type == "NEIGH_ASIC" :
169180 vmconfig [vm ]['bgp_ipv4' ][dut_index ] = ipstr .upper ()
170- elif ip .version == 6 :
171- # Each VM might not be connected to all the DUT's, so check if this VM is a peer to DUT at dut_index
172- if vmconfig [vm ]['peer_ipv6' ][dut_index ]:
173- ipsubnet_str = vmconfig [vm ]['peer_ipv6' ][dut_index ]+ '/' + vmconfig [vm ]['ipv6mask' ][dut_index ]
174- if sys .version_info < (3 , 0 ):
175- ipsubnet = ipaddress .ip_interface (ipsubnet_str .decode ('utf8' ))
176- else :
177- ipsubnet = ipaddress .ip_interface (ipsubnet_str )
178- if ip in ipsubnet .network :
181+ vmconfig [vm ]['ipv4mask' ][dut_index ] = ip_mask if ip_mask else '32'
182+ elif ip .version == 6 :
183+ # Each VM might not be connected to all the DUT's, so check if this VM is a peer to DUT at dut_index
184+ if vmconfig [vm ]['peer_ipv6' ][dut_index ]:
185+ ipsubnet_str = vmconfig [vm ]['peer_ipv6' ][dut_index ]+ '/' + vmconfig [vm ]['ipv6mask' ][dut_index ]
186+ if sys .version_info < (3 , 0 ):
187+ ipsubnet = ipaddress .ip_interface (ipsubnet_str .decode ('utf8' ))
188+ else :
189+ ipsubnet = ipaddress .ip_interface (ipsubnet_str )
190+ if ip in ipsubnet .network :
191+ vmconfig [vm ]['bgp_ipv6' ][dut_index ] = ipstr .upper ()
192+ elif neigh_type == "NEIGH_ASIC" :
179193 vmconfig [vm ]['bgp_ipv6' ][dut_index ] = ipstr .upper ()
194+ vmconfig [vm ]['ipv6mask' ][dut_index ] = ip_mask if ip_mask else '128'
180195 return vmconfig
181196
182197 def get_topo_config (self , topo_name , hwsku ):
@@ -201,10 +216,10 @@ def get_topo_config(self, topo_name, hwsku):
201216 topo_definition = yaml .load (f )
202217
203218 if not os .path .isfile (asic_topo_filename ):
204- asic_definition = {}
219+ slot_definition = {}
205220 else :
206221 with open (asic_topo_filename ) as f :
207- asic_definition = yaml .load (f )
222+ slot_definition = yaml .load (f )
208223
209224 ### parse topo file specified in vars/ to reverse as dut config
210225 dut_num = 1
@@ -225,17 +240,13 @@ def get_topo_config(self, topo_name, hwsku):
225240 vm_topo_config ['dut_type' ] = topo_definition ['configuration_properties' ]['common' ]['dut_type' ]
226241 vm_topo_config ['dut_asn' ] = dut_asn
227242
228-
229- for asic in asic_definition :
230- po_map_asic = [None ] * 16 # maximum 16 port channel interfaces
231- asic_topo_config [asic ] = dict ()
232- asic_topo_config [asic ]['dut_asn' ] = asic_definition [asic ]['configuration_properties' ]['common' ]['dut_asn' ]
233- asic_topo_config [asic ]['asic_type' ] = asic_definition [asic ]['configuration_properties' ]['common' ]['asic_type' ]
234- asic_topo_config [asic ]['Loopback4096' ] = []
235- for lo4096 in asic_definition [asic ]['configuration_properties' ]['common' ]['Loopback4096' ]:
236- asic_topo_config [asic ]['Loopback4096' ].append (lo4096 )
237-
238- asic_topo_config [asic ]['neigh_asic' ] = self .parse_topo_defintion (asic_definition [asic ], po_map_asic , 1 , 'NEIGH_ASIC' )
243+ for slot ,asic_definition in slot_definition .items ():
244+ asic_topo_config [slot ] = dict ()
245+ for asic in asic_definition :
246+ po_map_asic = [None ] * 16 # maximum 16 port channel interfaces
247+ asic_topo_config [slot ][asic ] = dict ()
248+ asic_topo_config [slot ][asic ]['asic_type' ] = asic_definition [asic ]['configuration_properties' ]['common' ]['asic_type' ]
249+ asic_topo_config [slot ][asic ]['neigh_asic' ] = self .parse_topo_defintion (asic_definition [asic ], po_map_asic , 1 , 'NEIGH_ASIC' )
239250
240251 vm_topo_config ['host_interfaces_by_dut' ] = [[] for i in range (dut_num )]
241252 if 'host_interfaces' in topo_definition ['topology' ]:
0 commit comments