Exemplo n.º 1
0
    def get_interface_sliver_by_id(
            ifs_node_id: str,
            graph: ABCPropertyGraph,
            itype: InterfaceType = None) -> List[InterfaceSliver]:
        """
        Finds Peer Interface Sliver and parent information upto Network Node
        @param ifs_node_id node id of the Interface Sliver
        @param graph Slice ASM
        @param itype Interface Type
        @returns Interface Sliver Mapping
        """
        result = []
        candidates = graph.find_peer_connection_points(node_id=ifs_node_id)
        for c in candidates:
            clazzes, node_props = graph.get_node_properties(node_id=c)

            # Peer Connection point maps to Interface Sliver
            # Build Interface Sliver
            peer_ifs = FimHelper.build_ifs_from_props(node_props=node_props)
            if itype is not None and peer_ifs.get_type() == itype:
                result.append(peer_ifs)
                break
            else:
                result.append(peer_ifs)
        return result
Exemplo n.º 2
0
 def network_service_sliver_from_json(s: str) -> NetworkServiceSliver:
     """
     Recover a network service sliver from JSON
     :param s:
     :return:
     """
     d = json.loads(s)
     if not isinstance(d, dict):
         raise RuntimeError(f'Unable to decode NetworkServiceSliver from {s=}')
     return ABCPropertyGraph.build_deep_ns_sliver_from_dict(props=d)
Exemplo n.º 3
0
 def sliver_to_json(sliver) -> str:
     """
     Take an object that is a descendant of a BaseSliver and
     convert it to JSON
     :param sliver:
     :return:
     """
     d = ABCPropertyGraph.sliver_to_dict(sliver)
     if d is not None:
         return json.dumps(d)
Exemplo n.º 4
0
    def advertise(self, *, delegation: ABCPropertyGraph, delegation_name: str, client: AuthToken) -> str:
        slice_obj = SliceFactory.create(slice_id=ID(), name=client.get_name())
        slice_obj.set_owner(owner=client)
        slice_obj.set_broker_client()

        dlg_obj = DelegationFactory.create(did=delegation.get_graph_id(), slice_id=slice_obj.get_slice_id(),
                                           delegation_name=delegation_name)
        dlg_obj.set_slice_object(slice_object=slice_obj)
        dlg_obj.set_graph(graph=delegation)
        self.wrapper.advertise(delegation=dlg_obj, client=client)
        return dlg_obj.get_delegation_id()
    def testNodeAndServiceSlivers(self):
        t = f.ExperimentTopology()
        t.add_node(name='n1', site='RENC')
        t.nodes['n1'].capacities = f.Capacities(core=1)
        t.nodes['n1'].add_component(name='c1',
                                    ctype=f.ComponentType.SmartNIC,
                                    model='ConnectX-6')
        d = ABCPropertyGraph.sliver_to_dict(t.nodes['n1'].get_sliver())
        t.add_node(name='n2', site='RENC')
        t.nodes['n2'].add_component(name='c2',
                                    ctype=f.ComponentType.SmartNIC,
                                    model='ConnectX-6')
        t.nodes['n2'].add_component(name='c3',
                                    ctype=f.ComponentType.NVME,
                                    model='P4510')
        t.add_network_service(name='s1',
                              nstype=f.ServiceType.L2Bridge,
                              interfaces=t.interface_list)
        jns = JSONSliver.sliver_to_json(t.nodes['n1'].get_sliver())
        ns1 = JSONSliver.node_sliver_from_json(jns)
        jns = JSONSliver.sliver_to_json(t.nodes['n2'].get_sliver())
        ns2 = JSONSliver.node_sliver_from_json(jns)
        ness = JSONSliver.sliver_to_json(t.network_services['s1'].get_sliver())
        nss1 = JSONSliver.network_service_sliver_from_json(ness)

        self.assertEqual(ns1.capacities.core, 1)
        self.assertEqual(len(ns1.attached_components_info.list_devices()), 1)
        self.assertEqual(len(ns2.attached_components_info.list_devices()), 2)
        self.assertEqual(len(nss1.interface_info.list_interfaces()), 4)
        inames = [
            i.resource_name for i in nss1.interface_info.list_interfaces()
        ]
        self.assertTrue('n2-c2-p1' in inames)
        self.assertEqual(
            ns1.attached_components_info.list_devices()
            [0].network_service_info.list_services()
            [0].interface_info.list_interfaces()[0].capacities.bw, 100)