Example #1
0
    def setUp(self):
        self.simulation_bus = SimulationBus(packetencoder=NdnTlvEncoder())

        self.fetch_tool1 = Fetch(
            "nfn0",
            None,
            255,
            NdnTlvEncoder(),
            interfaces=[self.simulation_bus.add_interface("fetchtoo11")])

        self.nfn0 = NFNForwarder(
            port=0,
            encoder=NdnTlvEncoder(),
            interfaces=[self.simulation_bus.add_interface("nfn0")],
            log_level=255,
            executors={"PYTHONSTREAM": NFNPythonExecutorStreaming()},
            ageing_interval=1)

        self.nfn0.executors["PYTHONSTREAM"].initialize_executor(
            self.nfn0.nfnlayer.queue_to_lower,
            self.nfn0.nfnlayer.queue_from_lower, self.nfn0.nfnlayer.cs, False)
        self.nfn0.icnlayer.pit.ageing = self.ageing
        self.nfn0.timeoutpreventionlayer.ageing = self.ageing

        self.nfn1 = NFNForwarder(
            port=0,
            encoder=NdnTlvEncoder(),
            interfaces=[self.simulation_bus.add_interface("nfn1")],
            log_level=255,
            executors={"PYTHONSTREAM": NFNPythonExecutorStreaming()},
            ageing_interval=1)

        self.nfn1.executors["PYTHONSTREAM"].initialize_executor(
            self.nfn1.nfnlayer.queue_to_lower,
            self.nfn1.nfnlayer.queue_from_lower, self.nfn1.nfnlayer.cs, False)
        self.nfn1.icnlayer.pit.ageing = self.ageing
        self.nfn1.timeoutpreventionlayer.ageing = self.ageing

        self.nfn12 = NFNForwarder(
            port=0,
            encoder=NdnTlvEncoder(),
            interfaces=[self.simulation_bus.add_interface("nfn12")],
            log_level=255,
            executors={"PYTHONSTREAM": NFNPythonExecutorStreaming()},
            ageing_interval=1)

        self.nfn12.executors["PYTHONSTREAM"].initialize_executor(
            self.nfn12.nfnlayer.queue_to_lower,
            self.nfn12.nfnlayer.queue_from_lower, self.nfn12.nfnlayer.cs,
            False)
        self.nfn12.icnlayer.pit.ageing = self.ageing
        self.nfn12.timeoutpreventionlayer.ageing = self.ageing

        self.repo1 = ICNDataRepository(
            "/tmp/repo1",
            Name("/repo/r1"),
            0,
            255,
            NdnTlvEncoder(),
            False,
            False,
            interfaces=[self.simulation_bus.add_interface("repo1")])

        self.mgmt_client0 = MgmtClient(
            self.nfn0.mgmt.mgmt_sock.getsockname()[1])
        self.mgmt_client1 = MgmtClient(
            self.nfn1.mgmt.mgmt_sock.getsockname()[1])
        self.mgmt_client01 = MgmtClient(
            self.nfn12.mgmt.mgmt_sock.getsockname()[1])
Example #2
0
def simulation(classic, amount_of_parts):
    generateExampleFiles("../InputFiles/exampleInputFile", amount_of_parts)

    simulation_bus = SimulationBus(packetencoder=NdnTlvEncoder())

    nfn_fwd0 = NFNForwarder(
        port=0,
        encoder=NdnTlvEncoder(),
        interfaces=[simulation_bus.add_interface("nfn0")],
        log_level=255,
        executors={"PYTHONSTREAM": NFNPythonExecutorStreaming()},
        ageing_interval=1)
    nfn_fwd0.executors["PYTHONSTREAM"].initialize_executor(
        nfn_fwd0.nfnlayer.queue_to_lower, nfn_fwd0.nfnlayer.queue_from_lower,
        nfn_fwd0.nfnlayer.cs, classic)
    nfn_fwd0.icnlayer.pit.ageing = ageing
    nfn_fwd0.timeoutpreventionlayer.ageing = ageing

    nfn_fwd1 = NFNForwarder(
        port=0,
        encoder=NdnTlvEncoder(),
        interfaces=[simulation_bus.add_interface("nfn1")],
        log_level=255,
        executors={"PYTHONSTREAM": NFNPythonExecutorStreaming()},
        ageing_interval=1)
    nfn_fwd1.executors["PYTHONSTREAM"].initialize_executor(
        nfn_fwd1.nfnlayer.queue_to_lower, nfn_fwd1.nfnlayer.queue_from_lower,
        nfn_fwd1.nfnlayer.cs, classic)
    nfn_fwd1.icnlayer.pit.ageing = ageing
    nfn_fwd1.timeoutpreventionlayer.ageing = ageing

    nfn_fwd2 = NFNForwarder(
        port=0,
        encoder=NdnTlvEncoder(),
        interfaces=[simulation_bus.add_interface("nfn2")],
        log_level=255,
        executors={"PYTHONSTREAM": NFNPythonExecutorStreaming()},
        ageing_interval=1)
    nfn_fwd2.executors["PYTHONSTREAM"].initialize_executor(
        nfn_fwd2.nfnlayer.queue_to_lower, nfn_fwd2.nfnlayer.queue_from_lower,
        nfn_fwd2.nfnlayer.cs, classic)
    nfn_fwd2.icnlayer.pit.ageing = ageing
    nfn_fwd2.timeoutpreventionlayer.ageing = ageing

    repo = ICNDataRepository("../InputFiles",
                             Name("/repo/r1"),
                             0,
                             255,
                             NdnTlvEncoder(),
                             False,
                             False,
                             interfaces=[simulation_bus.add_interface("repo")])
    repo.start_repo()

    mgmt_client0 = MgmtClient(nfn_fwd0.mgmt.mgmt_sock.getsockname()[1])
    mgmt_client1 = MgmtClient(nfn_fwd1.mgmt.mgmt_sock.getsockname()[1])
    mgmt_client2 = MgmtClient(nfn_fwd2.mgmt.mgmt_sock.getsockname()[1])

    fetch_tool = Fetch("nfn0",
                       None,
                       255,
                       NdnTlvEncoder(),
                       interfaces=[simulation_bus.add_interface("fetchtoo1")])

    nfn_fwd0.start_forwarder()
    nfn_fwd1.start_forwarder()
    nfn_fwd2.start_forwarder()

    simulation_bus.start_process()

    mgmt_client0.add_face("nfn1", None, 0)
    mgmt_client0.add_forwarding_rule(Name("/lib"), [0])
    mgmt_client1.add_face("nfn2", None, 0)
    mgmt_client1.add_forwarding_rule(Name("/lib"), [0])
    mgmt_client2.add_face("repo", None, 0)
    mgmt_client2.add_forwarding_rule(Name("/repo/r1"), [0])

    mgmt_client0.add_new_content(
        Name("/lib/node0"),
        "PYTHONSTREAM\ngetnext_on_writeout\ndef getnext_on_writeout(arg):\n    print('Start dritte')\n    res = ''\n    a = get_next(arg)\n    while a != None:\n        res = res + a\n        a = get_next(arg)\n    print('Ende dritte')\n    return res"
    )

    mgmt_client1.add_new_content(
        Name("/lib/node1"),
        "PYTHONSTREAM\nwriteout_on_getnext\ndef writeout_on_getnext(arg):\n    print('Start zweite')\n    a = get_next(arg)\n    while a and check_end_streaming(a) is False:\n        a = a.upper()\n        sleep(1)\n        write_out(a)\n        a = get_next(arg)\n    last_write_out()\n    return print('Ende zweite')\n"
    )

    mgmt_client2.add_new_content(
        Name("/lib/node2"),
        "PYTHONSTREAM\nwriteout_on_getnext\ndef writeout_on_getnext(arg):\n    print('Start erste')\n    write_out_on_get_next(arg)\n    return print('Ende erste')\n"
    )

    scenario_node_2 = Name("/lib/node2")
    scenario_node_2 += "#(=/repo/r1/exampleInputFile=)"
    scenario_node_2 += "NFN"

    scenario_node_1 = Name("/lib/node1")
    scenario_node_1 += "#(=" + str(scenario_node_2) + "=)"
    scenario_node_1 += "NFN"

    scenario_node_0 = Name("/lib/node0")
    scenario_node_0 += '_("' + str(scenario_node_1) + '")'
    scenario_node_0 += "NFN"

    start_time = time.perf_counter()
    res = fetch_tool.fetch_data(scenario_node_0, timeout=60)
    end_time = time.perf_counter()
    time_needed = end_time - start_time

    if res.startswith("CONTENT OF NAME"):
        print("Time:", time_needed, res)
        return time_needed
    else:
        print("Something went wrong")
        None