Example #1
0
    def test_add_computation(self):
        """Test adding a computation to the List"""
        name = Name("/test")
        self.computationList.add_computation(name, 0, Interest(name))
        self.assertTrue(NFNComputationTableEntry(name) in self.computationList.container)

        name1 = Name("/test")
        self.computationList.add_computation(name1, 0, Interest(name1))
        self.assertTrue(NFNComputationTableEntry(name1) in self.computationList.container)
        self.assertEqual(len(self.computationList.container), 1)

        name2 = Name("/data")
        self.computationList.add_computation(name2, 0, Interest(name2))
        self.assertTrue(NFNComputationTableEntry(name) in self.computationList.container)
        self.assertTrue(NFNComputationTableEntry(name2) in self.computationList.container)
        self.assertEqual(len(self.computationList.container), 2)
Example #2
0
 def test_ready_computations_excludes_r2c(self):
     """Test if the list of ready computations excludes R2C"""
     name = Name("/test/NFN")
     request_name = Name("/test/R2C")
     self.computationList.add_computation(name, 0, Interest(name))
     self.computationList.container[0].add_name_to_await_list(request_name)
     self.assertEqual(len(self.computationList.container[0].awaiting_data), 1)
     ready_comps = self.computationList.get_ready_computations()
     self.assertEqual(ready_comps, [NFNComputationTableEntry(name)])
Example #3
0
    def fetch_parameter_and_compute_local(
            self, interest: Interest,
            computation_table_entry: NFNComputationTableEntry):
        self.logger.info("Compute Local: " + str(interest.name))
        computation_table_entry.comp_state = NFNComputationState.EXEC
        if not isinstance(computation_table_entry.ast, AST_FuncCall):
            self.logger.error("AST is no function call but: " +
                              str(computation_table_entry.ast))
            nack = Nack(interest.name,
                        reason=NackReason.COMP_NOT_PARSED,
                        interest=interest)
            self.handleNack(computation_table_entry.id, nack)
            self.queue_to_lower.put([computation_table_entry.id, nack])
            return

        func_name = Name(computation_table_entry.ast._element)
        computation_table_entry.add_name_to_await_list(func_name)
        self.queue_to_lower.put(
            [computation_table_entry.id,
             Interest(func_name)])

        for p in computation_table_entry.ast.params:
            name = None
            if isinstance(p, AST_Name):
                name = Name(p._element)
                self.queue_to_lower.put(
                    [computation_table_entry.id,
                     Interest(name)])
            elif isinstance(p, AST_FuncCall):
                #p._prepend = True
                name = self.parser.nfn_str_to_network_name((str(p)))
                #p._prepend = False
                self.logger.info("Subcomputation: " + str(name))
                self.handleInterest(computation_table_entry.id, Interest(name))
            else:
                continue
            computation_table_entry.add_name_to_await_list(name)

        self.computation_table.append_computation(computation_table_entry)
        if (computation_table_entry.awaiting_data == []):
            self.compute(interest)