Skip to content

Commit

Permalink
changes to request specific subnet for fabnet services
Browse files Browse the repository at this point in the history
  • Loading branch information
kthare10 committed Sep 3, 2024
1 parent faa6d20 commit 9fa7b41
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
6 changes: 3 additions & 3 deletions fabric_cf/actor/core/kernel/rpc_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ def do_dispatch_incoming_rpc(self, *, actor: ABCActorMixin, rpc: IncomingRPC):
rpc.set_response_handler(response_handler=request.handler)

actor.get_logger().debug(f"Inbound {rpc.get_request_type()} request from "
f"<{rpc.get_caller().get_name()}>:{rpc.get()}")
f"<{rpc.get_caller().get_name()}>:{rpc.get()}")

self.__log_sliver(reservation=rpc.get(), logger=actor.get_logger())
#self.__log_sliver(reservation=rpc.get(), logger=actor.get_logger())

if rpc.get_request_type() == RPCRequestType.QueryResult:
if request is None:
Expand Down Expand Up @@ -564,7 +564,7 @@ def enqueue(self, *, rpc: RPCRequest):
from fabric_cf.actor.core.container.globals import GlobalsSingleton
logger = GlobalsSingleton.get().get_logger()
logger.debug(f"Outbound {rpc.get_request_type()} : {rpc.get()}")
self.__log_sliver(reservation=rpc.get(), logger=logger)
#self.__log_sliver(reservation=rpc.get(), logger=logger)
if not self.started:
logger.warning("Ignoring RPC request: container is shutting down")
return
Expand Down
2 changes: 1 addition & 1 deletion fabric_cf/actor/core/policy/broker_simpler_units_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def __allocate_services(self, *, rid: ID, inv: NetworkServiceInventory, sliver:
owner_switch.get_label_delegations())
else:
delegation_id, delegated_label = InventoryForType.get_delegations(lab_cap_delegations=
owner_ns.get_label_delegations())
owner_ns.get_label_delegations())

# Set the Subnet and gateway from the Owner Switch (a)
existing_reservations = self.get_existing_reservations(node_id=owner_ns_id,
Expand Down
28 changes: 22 additions & 6 deletions fabric_cf/actor/core/policy/network_service_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def allocate(self, *, rid: ID, requested_ns: NetworkServiceSliver, owner_ns: Net
return requested_ns

gateway_labels = self._assign_gateway_labels(ip_network=ip_network, subnet_list=subnet_list,
requested_ns_type=requested_ns.get_type())
requested_ns=requested_ns)

self.logger.debug(f"Gateway Labels: {gateway_labels}")

Expand Down Expand Up @@ -487,25 +487,41 @@ def _get_allocated_sliver(self, reservation: ABCReservationMixin) -> NetworkServ
self.logger.error("Could not find the allocated Sliver - should not reach here!")

def _assign_gateway_labels(self, *, ip_network: Union[IPv4Network, IPv6Network], subnet_list: List,
requested_ns_type: str) -> Labels:
requested_ns: NetworkServiceSliver) -> Labels:
"""
Assign gateway labels based on the requested network service type.
:param ip_network: The IP network from which subnets are derived, either IPv4Network or IPv6Network.
:param subnet_list: A list of subnets derived from the ip_network.
:param requested_ns_type: The type of the requested network service.
:param requested_ns: Network Service sliver.
:return: Gateway labels populated with the appropriate subnet and IP address.
"""
gateway_labels = Labels()
if requested_ns_type == ServiceType.FABNetv4:
if requested_ns.get_type() == ServiceType.FABNetv4:
# Allocate the requested network if available else allocate new network
if requested_ns.gateway and requested_ns.gateway.lab and requested_ns.gateway.lab.ipv4_subnet:
requested_subnet = IPv4Network(requested_ns.gateway.lab.ipv4_subnet)
if requested_subnet in subnet_list:
gateway_labels.ipv4_subnet = requested_subnet.with_prefixlen
gateway_labels.ipv4 = str(next(requested_subnet.hosts()))
return gateway_labels

gateway_labels.ipv4_subnet = subnet_list[0].with_prefixlen
gateway_labels.ipv4 = str(list(subnet_list[0].hosts())[0])

elif requested_ns_type == ServiceType.FABNetv4Ext:
elif requested_ns.get_type() == ServiceType.FABNetv4Ext:
gateway_labels.ipv4_subnet = ip_network.with_prefixlen
gateway_labels.ipv4 = str(subnet_list[0])

elif requested_ns_type in Constants.L3_FABNETv6_SERVICES:
elif requested_ns.get_type() in Constants.L3_FABNETv6_SERVICES:
# Allocate the requested network if available else allocate new network
if requested_ns.gateway and requested_ns.gateway.lab and requested_ns.gateway.lab.ipv6_subnet:
requested_subnet = IPv6Network(requested_ns.gateway.lab.ipv6_subnet)
if requested_subnet in subnet_list:
gateway_labels.ipv6_subnet = requested_subnet.with_prefixlen
gateway_labels.ipv6 = str(next(requested_subnet.hosts()))
return gateway_labels

gateway_labels.ipv6_subnet = subnet_list[0].with_prefixlen
gateway_labels.ipv6 = str(next(subnet_list[0].hosts()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ def pass_authority_reservation(self, reservation: ABCReservationMixin, caller: A

avro_reservation.resource_set = rset
if self.logger:
self.logger.info(f"Outgoing Resource Set: {rset}")
self.logger.debug(f"Resource Set: {rset}")
return avro_reservation
2 changes: 1 addition & 1 deletion fabric_cf/actor/core/proxies/kafka/kafka_retun.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def pass_reservation(self, reservation: ABCServerReservation, auth: AuthToken) -

avro_reservation.resource_set = rset
if self.logger:
self.logger.info(f"Outgoing Resource Set: {rset}")
self.logger.info(f"Resource Set: {rset}")
return avro_reservation

@staticmethod
Expand Down

0 comments on commit 9fa7b41

Please sign in to comment.