Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rel1.8 - Attribute collector changes for PDP #212

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
FABRIC Information Model library and utilities
"""
__VERSION__ = "1.7.2"
__VERSION__ = "1.8.0"
__version__ = __VERSION__
27 changes: 22 additions & 5 deletions fim/authz/attribute_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import json

from fim.user.topology import ExperimentTopology
from fim.user.node import Node
from fim.user.node import Node, NodeType
from fim.user.network_service import NetworkService, ServiceType
from fim.graph.slices.networkx_asm import NetworkxASM
from fim.slivers.base_sliver import BaseSliver
Expand Down Expand Up @@ -134,6 +134,8 @@ def attributes(self):
return ViewOnlyDict(self._attributes)

def _collect_attributes_from_node_sliver(self, sliver: NodeSliver):
if sliver.get_type() == NodeType.Switch:
self._attributes[self.RESOURCE_TYPE] = ["switch-p4"]
if sliver.capacities:
self._attributes[self.RESOURCE_CPU].append(sliver.capacities.core)
self._attributes[self.RESOURCE_RAM].append(sliver.capacities.ram)
Expand All @@ -145,7 +147,8 @@ def _collect_attributes_from_node_sliver(self, sliver: NodeSliver):
for c in sliver.attached_components_info.list_devices():
self._attributes[self.RESOURCE_COMPONENT].append(str(c.get_type()))

def _collect_attributes_from_ns_sliver(self, sliver: NetworkServiceSliver):
def _collect_attributes_from_ns_sliver(self, sliver: NetworkServiceSliver,
in_slice_ports: set = set()):
if sliver.capacities:
self._attributes[self.RESOURCE_BW].append(sliver.capacities.bw)
if sliver.site:
Expand All @@ -160,6 +163,16 @@ def _collect_attributes_from_ns_sliver(self, sliver: NetworkServiceSliver):
if sliver.site not in self._attributes[resource_name]:
self._attributes[resource_name].append(sliver.site)

# Additional condition for PortMirror to not throw an error if the
# port being mirrored is within the same slice
if sliver.resource_type == ServiceType.PortMirror and \
sliver.mirror_port in in_slice_ports and \
len(self._attributes[resource_name]):
# Specific logic for PortMirror if needed
self._attributes[resource_name].pop()
if len(self._attributes[resource_name]) == 0:
self._attributes.pop(resource_name)

def _collect_attributes_from_base_sliver(self, sliver: BaseSliver):
if isinstance(sliver, NetworkServiceSliver):
self._collect_attributes_from_ns_sliver(sliver)
Expand All @@ -169,16 +182,20 @@ def _collect_attributes_from_base_sliver(self, sliver: BaseSliver):
def _collect_attributes_from_topo(self, topo: ExperimentTopology):
for n in topo.nodes.values():
self._collect_attributes_from_node(n)
in_slice_ports = set()
for ifs in topo.interface_list:
if ifs.get_peers() and ifs.get_peers()[0] and ifs.get_peers()[0].labels:
in_slice_ports.add(ifs.get_peers()[0].labels.local_name)
for ns in topo.network_services.values():
self._collect_attributes_from_ns(ns)
self._collect_attributes_from_ns(ns, in_slice_ports)
for fac in topo.facilities.values():
self._attributes[self.RESOURCE_FACILITY_PORT].append(fac.name)

def _collect_attributes_from_node(self, node: Node):
self._collect_attributes_from_node_sliver(node.get_sliver())

def _collect_attributes_from_ns(self, ns: NetworkService):
self._collect_attributes_from_ns_sliver(ns.get_sliver())
def _collect_attributes_from_ns(self, ns: NetworkService, in_slice_ports: set = set()):
self._collect_attributes_from_ns_sliver(ns.get_sliver(), in_slice_ports)

def _collect_attributes_from_asm(self, asm: NetworkxASM):
# convert to experiment topology
Expand Down
Loading