@@ -360,7 +360,7 @@ def allocate(self, *, rid: ID, requested_ns: NetworkServiceSliver, owner_ns: Net
360
360
return requested_ns
361
361
362
362
gateway_labels = self ._assign_gateway_labels (ip_network = ip_network , subnet_list = subnet_list ,
363
- requested_ns_type = requested_ns . get_type () )
363
+ requested_ns = requested_ns )
364
364
365
365
self .logger .debug (f"Gateway Labels: { gateway_labels } " )
366
366
@@ -487,25 +487,41 @@ def _get_allocated_sliver(self, reservation: ABCReservationMixin) -> NetworkServ
487
487
self .logger .error ("Could not find the allocated Sliver - should not reach here!" )
488
488
489
489
def _assign_gateway_labels (self , * , ip_network : Union [IPv4Network , IPv6Network ], subnet_list : List ,
490
- requested_ns_type : str ) -> Labels :
490
+ requested_ns : NetworkServiceSliver ) -> Labels :
491
491
"""
492
492
Assign gateway labels based on the requested network service type.
493
493
494
494
:param ip_network: The IP network from which subnets are derived, either IPv4Network or IPv6Network.
495
495
:param subnet_list: A list of subnets derived from the ip_network.
496
- :param requested_ns_type: The type of the requested network service .
496
+ :param requested_ns: Network Service sliver .
497
497
:return: Gateway labels populated with the appropriate subnet and IP address.
498
498
"""
499
499
gateway_labels = Labels ()
500
- if requested_ns_type == ServiceType .FABNetv4 :
500
+ if requested_ns .get_type () == ServiceType .FABNetv4 :
501
+ # Allocate the requested network if available else allocate new network
502
+ if requested_ns .gateway and requested_ns .gateway .lab and requested_ns .gateway .lab .ipv4_subnet :
503
+ requested_subnet = IPv4Network (requested_ns .gateway .lab .ipv4_subnet )
504
+ if requested_subnet in subnet_list :
505
+ gateway_labels .ipv4_subnet = requested_subnet .with_prefixlen
506
+ gateway_labels .ipv4 = str (next (requested_subnet .hosts ()))
507
+ return gateway_labels
508
+
501
509
gateway_labels .ipv4_subnet = subnet_list [0 ].with_prefixlen
502
510
gateway_labels .ipv4 = str (list (subnet_list [0 ].hosts ())[0 ])
503
511
504
- elif requested_ns_type == ServiceType .FABNetv4Ext :
512
+ elif requested_ns . get_type () == ServiceType .FABNetv4Ext :
505
513
gateway_labels .ipv4_subnet = ip_network .with_prefixlen
506
514
gateway_labels .ipv4 = str (subnet_list [0 ])
507
515
508
- elif requested_ns_type in Constants .L3_FABNETv6_SERVICES :
516
+ elif requested_ns .get_type () in Constants .L3_FABNETv6_SERVICES :
517
+ # Allocate the requested network if available else allocate new network
518
+ if requested_ns .gateway and requested_ns .gateway .lab and requested_ns .gateway .lab .ipv6_subnet :
519
+ requested_subnet = IPv6Network (requested_ns .gateway .lab .ipv6_subnet )
520
+ if requested_subnet in subnet_list :
521
+ gateway_labels .ipv6_subnet = requested_subnet .with_prefixlen
522
+ gateway_labels .ipv6 = str (next (requested_subnet .hosts ()))
523
+ return gateway_labels
524
+
509
525
gateway_labels .ipv6_subnet = subnet_list [0 ].with_prefixlen
510
526
gateway_labels .ipv6 = str (next (subnet_list [0 ].hosts ()))
511
527
0 commit comments