Ejemplo n.º 1
0
    def test_packet_loss_classical(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.network.packet_drop_rate = 0.75
        self.network.delay = 0
        self.hosts = hosts

        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        # ACKs for 1 hop take at most 2 seconds
        hosts['alice'].max_ack_wait = 3
        num_acks = 0
        num_messages = 15
        for _ in range(num_messages):
            ack = hosts['alice'].send_classical(hosts['bob'].host_id, 'Hello Bob', await_ack=True)
            if ack:
                num_acks += 1

        num_messages_bob_received = len(hosts['bob'].classical)
        self.assertTrue(num_acks != num_messages)
        self.assertTrue(num_acks < num_messages)
        self.assertTrue(num_messages_bob_received < num_messages)

        # ACKs can also get dropped
        self.assertTrue(num_messages_bob_received > num_acks)
        self.assertTrue(float(num_acks) / num_messages < 0.9)
Ejemplo n.º 2
0
    def test_superdense(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}
        self.hosts = hosts

        # A <-> B
        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        hosts['alice'].send_superdense(hosts['bob'].host_id, '01')

        messages = hosts['bob'].classical
        i = 0
        while i < TestOneHop.MAX_WAIT and len(messages) == 0:
            messages = hosts['bob'].classical
            i += 1
            time.sleep(1)

        self.assertIsNotNone(messages)
        self.assertTrue(len(messages) > 0)
        self.assertEqual(messages[0]['sender'], hosts['alice'].host_id)
        self.assertEqual(messages[0]['message'], '01')
Ejemplo n.º 3
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    backend = CQCBackend()
    network.start(nodes, backend)
    network.delay = 0.7

    hosts = {'alice': Host('Alice', backend),
             'bob': Host('Bob', backend)}

    network.delay = 0
    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    q1 = Qubit(hosts['alice'])
    hosts['alice'].send_qubit('Bob', q1, await_ack=True)
    q1 = Qubit(hosts['alice'])
    hosts['alice'].send_qubit('Bob', q1, await_ack=True)
    q1 = Qubit(hosts['alice'])
    hosts['alice'].send_qubit('Bob', q1, await_ack=True)
    q1 = Qubit(hosts['bob'])
    hosts['bob'].send_qubit('Alice', q1, await_ack=True)
    network.stop(True)
    exit()
Ejemplo n.º 4
0
    def test_send_qubit_bob_to_alice(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        hosts['bob'].add_connection('00000000')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        q = Qubit(hosts['bob'])
        q.X()

        q_id = hosts['bob'].send_qubit(hosts['alice'].host_id, q)

        i = 0
        rec_q = hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_id)
        while i < TestOneHop.MAX_WAIT and rec_q is None:
            rec_q = hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(rec_q)
        self.assertEqual(rec_q.measure(), 1)
Ejemplo n.º 5
0
    def test_epr(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        q_id = hosts['alice'].send_epr(hosts['bob'].host_id)
        q1 = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
        i = 0
        while q1 is None and i < TestOneHop.MAX_WAIT:
            q1 = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(q1)
        i = 0
        q2 = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
        while q2 is None and i < TestOneHop.MAX_WAIT:
            q2 = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(q2)
        self.assertEqual(q1.measure(), q2.measure())
Ejemplo n.º 6
0
    def test_teleport(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        q = Qubit(hosts['alice'])
        q.X()

        hosts['alice'].send_teleport(hosts['bob'].host_id, q)

        q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
        i = 0
        while q2 is None and i < TestOneHop.MAX_WAIT:
            q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(q2)
        self.assertEqual(q2.measure(), 1)
Ejemplo n.º 7
0
def main():
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.0
    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    q = Qubit(hosts['alice'])
    q.X()

    hosts['alice'].send_teleport(hosts['bob'].host_id, q)

    q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
    i = 0
    while q2 is None and i < 5:
        q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
        i += 1
        time.sleep(1)

    assert q2 is not None
    assert q2.measure() == 1
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 8
0
def main():
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.7
    hosts = {'alice': Host('Alice', backend),
             'bob': Host('Bob', backend)}

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    hosts['alice'].send_superdense(hosts['bob'].host_id, '01')

    messages = hosts['bob'].classical
    i = 0
    while i < 5 and len(messages) == 0:
        messages = hosts['bob'].classical
        i += 1
        time.sleep(1)

    assert messages is not None
    assert len(messages) > 0
    assert (messages[0].sender == hosts['alice'].host_id)
    assert (messages[0].content == '01')
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 9
0
def main():
    backend = EQSNBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.0

    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    ack_received_1 = hosts['alice'].send_classical(hosts['bob'].host_id,
                                                   'hello bob one',
                                                   await_ack=True)
    hosts['alice'].max_ack_wait = 0.0
    ack_received_2 = hosts['alice'].send_classical(hosts['bob'].host_id,
                                                   'hello bob one',
                                                   await_ack=True)
    assert ack_received_1
    assert not ack_received_2
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 10
0
def test_adding_hosts_to_backend(backend_generator):
    print("Starrting adding a host test...")
    backend = backend_generator()
    network = Network.get_instance()
    network.start(["Alice"], backend)
    alice = Host('Alice', backend)
    alice.start()

    network.add_host(alice)
    network.stop(True)
    print("Test was successfull!")
Ejemplo n.º 11
0
def test_multiple_backends(backend_generator):
    print("Starting multiple backends test...")
    backend1 = backend_generator()
    backend2 = backend_generator()
    assert backend1._cqc_connections == backend2._cqc_connections
    network = Network.get_instance()
    network.start(["Alice", "Bob"], backend1)
    alice = Host('Alice', backend2)
    bob = Host('Bob', backend1)
    assert str(backend1._cqc_connections) == str(backend2._cqc_connections)
    assert str(backend1._hosts) == str(backend2._hosts)
    network.stop(True)
    print("Test was successfull!")
Ejemplo n.º 12
0
 def setUpClass(cls):
     global network
     global hosts
     nodes = ["Alice", "Bob"]
     backend = EQSNBackend()
     network.start(nodes=nodes, backend=backend)
     hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}
     hosts['alice'].add_connection('Bob')
     hosts['bob'].add_connection('Alice')
     hosts['alice'].start()
     hosts['bob'].start()
     for h in hosts.values():
         network.add_host(h)
Ejemplo n.º 13
0
def main():
    print("Skip test, this test has to be updated!")
    return
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.7

    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    network.delay = 0
    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    # print(f"ack test - SEND CLASSICAL - started at {time.strftime('%X')}")
    hosts['alice'].send_classical(hosts['bob'].host_id,
                                  'hello bob one',
                                  await_ack=True)
    hosts['alice'].send_classical(hosts['bob'].host_id,
                                  'hello bob two',
                                  await_ack=True)
    # print(f"ack test - SEND CLASSICAL - finished at {time.strftime('%X')}")

    saw_ack_1 = False
    saw_ack_2 = False
    messages = hosts['alice'].classical
    # print([m.seq_num for m in messages])
    for m in messages:
        if m.content == protocols.ACK and m.seq_num == 0:
            saw_ack_1 = True
        if m.content == protocols.ACK and m.seq_num == 1:
            saw_ack_2 = True
        if saw_ack_1 and saw_ack_2:
            break

    assert saw_ack_1
    assert saw_ack_2
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 14
0
def main():
    backend = EQSNBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.7

    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    network.delay = 0
    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    # send messages to Bob without waiting for ACKs
    hosts['alice'].send_classical(hosts['bob'].host_id,
                                  'hello bob one',
                                  await_ack=False)
    hosts['alice'].send_classical(hosts['bob'].host_id,
                                  'hello bob two',
                                  await_ack=False)
    hosts['alice'].send_classical(hosts['bob'].host_id,
                                  'hello bob three',
                                  await_ack=False)
    hosts['alice'].send_classical(hosts['bob'].host_id,
                                  'hello bob four',
                                  await_ack=False)

    # Wait for all Acks from Bob
    hosts['alice'].await_remaining_acks(hosts['bob'].host_id)

    saw_ack = [False, False, False, False]
    messages = hosts['alice'].classical
    for m in messages:
        if m.content == protocols.ACK:
            saw_ack[m.seq_num] = True

    for ack in saw_ack:
        assert ack
    print("All tests succesfull!")
    network.stop(True)
Ejemplo n.º 15
0
def main():
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.7
    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    network.delay = 0

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    hosts['alice'].send_classical(hosts['bob'].host_id, 'Hello Bob', False)
    hosts['bob'].send_classical(hosts['alice'].host_id, 'Hello Alice', False)

    i = 0
    bob_messages = hosts['bob'].classical
    while i < 5 and len(bob_messages) == 0:
        bob_messages = hosts['bob'].classical
        i += 1
        time.sleep(1)

    i = 0
    alice_messages = hosts['alice'].classical
    while i < 5 and len(alice_messages) == 0:
        alice_messages = hosts['alice'].classical
        i += 1
        time.sleep(1)

    assert len(alice_messages) > 0
    assert alice_messages[0].sender == hosts['bob'].host_id
    assert alice_messages[0].content == 'Hello Alice'

    assert (len(bob_messages) > 0)
    assert (bob_messages[0].sender == hosts['alice'].host_id)
    assert (bob_messages[0].content == 'Hello Bob')
    print("All tests succesfull!")
    network.stop(True)
    exit()
def main():
    backend = EQSNBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.0

    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    network.start(nodes, backend)
    network.packet_drop_rate = 0.5
    network.delay = 0

    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    # ACKs for 1 hop take at most 2 seconds
    hosts['alice'].max_ack_wait = 0.5
    num_acks = 0
    # don't make more then 10 attempts, since of receiver window.
    num_messages = 20
    for _ in range(num_messages):
        ack = hosts['alice'].send_classical(hosts['bob'].host_id,
                                            'Hello Bob',
                                            await_ack=True)
        if ack:
            num_acks += 1

    num_messages_bob_received = len(hosts['bob'].classical)
    assert num_acks != num_messages
    assert num_acks < num_messages
    assert num_messages_bob_received < num_messages

    # ACKs can also get dropped
    assert num_messages_bob_received > num_acks
    assert float(num_acks) / num_messages < 0.9
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 17
0
def main():
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.7
    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    q_id = hosts['alice'].send_epr(hosts['bob'].host_id)
    q1 = hosts['alice'].shares_epr(hosts['bob'].host_id)
    i = 0
    while not q1 and i < MAX_WAIT:
        q1 = hosts['alice'].shares_epr(hosts['bob'].host_id)
        i += 1
        time.sleep(1)

    i = 0
    q2 = hosts['bob'].shares_epr(hosts['alice'].host_id)
    while not q2 and i < 5:
        q2 = hosts['bob'].shares_epr(hosts['alice'].host_id)
        i += 1
        time.sleep(1)

    assert hosts['alice'].shares_epr(hosts['bob'].host_id)
    assert hosts['bob'].shares_epr(hosts['alice'].host_id)
    q_alice = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
    q_bob = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
    assert q_alice is not None
    assert q_bob is not None
    assert q_alice.measure() == q_bob.measure()
    assert not hosts['alice'].shares_epr(hosts['bob'].host_id)
    assert not hosts['bob'].shares_epr(hosts['alice'].host_id)
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 18
0
    def test_epr(self):
        with CQCConnection("Alice") as Alice, CQCConnection(
                "Bob") as Bob, CQCConnection("Eve") as Eve:
            hosts = {
                'alice': Host('00000000', Alice),
                'bob': Host('00000001', Bob),
                'eve': Host('00000011', Eve)
            }

            self.hosts = hosts

            hosts['alice'].add_connection('00000001')
            hosts['bob'].add_connection('00000000')

            hosts['bob'].add_connection('00000011')
            hosts['eve'].add_connection('00000001')

            hosts['alice'].start()
            hosts['bob'].start()
            hosts['eve'].start()

            for h in hosts.values():
                self.network.add_host(h)

            q_id = hosts['alice'].send_epr(hosts['eve'].host_id)

            i = 0
            q1 = None
            q2 = None
            while i < TestTwoHop.MAX_WAIT and q1 is None:
                q1 = hosts['alice'].get_epr(hosts['eve'].host_id, q_id)
                i += 1
                time.sleep(1)

            self.assertIsNotNone(q1)

            i = 0
            while i < TestTwoHop.MAX_WAIT and q2 is None:
                q2 = hosts['eve'].get_epr(hosts['alice'].host_id, q_id)
                i += 1
                time.sleep(1)

            self.assertIsNotNone(q2)
            self.assertEqual(q1.measure(), q2.measure())
Ejemplo n.º 19
0
def main():
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)

    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    network.delay = 0
    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].storage_epr_limit = 1
    hosts['bob'].storage_epr_limit = 1

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    hosts['alice'].max_ack_wait = 10

    hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True)
    hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True)

    assert hosts['alice'].shares_epr(hosts['bob'].host_id)
    print(hosts['alice'].get_epr_pairs(hosts['bob'].host_id))
    assert len(hosts['alice'].get_epr_pairs(hosts['bob'].host_id)) == 1
    assert hosts['bob'].shares_epr(hosts['alice'].host_id)
    assert len(hosts['bob'].get_epr_pairs(hosts['alice'].host_id)) == 1

    hosts['alice'].set_epr_memory_limit(2, hosts['bob'].host_id)
    hosts['bob'].set_epr_memory_limit(2)

    hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True)
    hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True)

    assert len(hosts['alice'].get_epr_pairs(hosts['bob'].host_id)) == 2
    assert len(hosts['bob'].get_epr_pairs(hosts['alice'].host_id)) == 2
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 20
0
    def test_teleport_superdense_combination(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}
        self.hosts = hosts

        # A <-> B
        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        hosts['alice'].send_superdense(hosts['bob'].host_id, '11')

        messages = hosts['bob'].classical
        i = 0
        while i < TestOneHop.MAX_WAIT and len(messages) == 0:
            messages = hosts['bob'].classical
            i += 1
            time.sleep(1)

        q = Qubit(hosts['alice'])
        q.X()

        hosts['alice'].send_teleport(hosts['bob'].host_id, q)
        q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
        i = 0
        while q2 is None and i < TestOneHop.MAX_WAIT:
            q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(messages)
        self.assertTrue(len(messages) > 0)
        self.assertEqual(messages[0]['sender'], hosts['alice'].host_id)
        self.assertEqual(messages[0]['message'], '11')

        self.assertIsNotNone(q2)
        self.assertEqual(q2.measure(), 1)
Ejemplo n.º 21
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    hosts = {'alice': Host('Alice'),
             'bob': Host('Bob'),
             'eve': Host('Eve')}

    network.delay = 0

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    # B <-> E
    hosts['bob'].add_connection('Eve')
    hosts['eve'].add_connection('Bob')

    hosts['alice'].start()
    hosts['bob'].start()
    hosts['eve'].start()

    for h in hosts.values():
        network.add_host(h)

    q = Qubit(hosts['alice'])
    q.X()
    q_id = hosts['alice'].send_qubit(hosts['eve'].host_id, q)

    i = 0
    q1 = None
    while i < MAX_WAIT and q1 is None:
        q1 = hosts['eve'].get_data_qubit(hosts['alice'].host_id, q_id)
        i += 1
        time.sleep(1)

    assert q1 != None
    assert q1.measure() == 1


    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 22
0
    def test_send_classical(self):
        global hosts
        global network

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        # A <-> B
        hosts['alice'].add_connection(hosts['bob'].host_id)
        hosts['bob'].add_connection(hosts['alice'].host_id)

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            network.add_host(h)

        hosts['alice'].send_classical(hosts['bob'].host_id, 'Hello Bob', await_ack=False)
        hosts['bob'].send_classical(hosts['alice'].host_id, 'Hello Alice', await_ack=False)

        i = 0
        bob_messages = hosts['bob'].get_classical(hosts['alice'].host_id)
        while i < TestOneHop.MAX_WAIT and len(bob_messages) == 0:
            bob_messages = hosts['bob'].get_classical(hosts['alice'].host_id)
            i += 1
            time.sleep(1)

        i = 0
        alice_messages = hosts['alice'].get_classical(hosts['bob'].host_id)
        while i < TestOneHop.MAX_WAIT and len(alice_messages) == 0:
            alice_messages = hosts['alice'].get_classical(hosts['bob'].host_id)
            print(alice_messages)
            i += 1
            time.sleep(1)

        self.assertTrue(len(alice_messages) > 0)
        self.assertEqual(alice_messages[0].sender, hosts['bob'].host_id)
        self.assertEqual(alice_messages[0].content, 'Hello Alice')

        self.assertTrue(len(bob_messages) > 0)
        self.assertEqual(bob_messages[0].sender, hosts['alice'].host_id)
        self.assertEqual(bob_messages[0].content, 'Hello Bob')
Ejemplo n.º 23
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    hosts = {'alice': Host('Alice'), 'bob': Host('Bob'), 'eve': Host('Eve')}

    network.delay = 0

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    # B <-> E
    hosts['bob'].add_connection('Eve')
    hosts['eve'].add_connection('Bob')

    hosts['alice'].start()
    hosts['bob'].start()
    hosts['eve'].start()

    for h in hosts.values():
        network.add_host(h)

    hosts['alice'].send_superdense(hosts['eve'].host_id, '11')
    hosts['alice'].send_classical(hosts['eve'].host_id, 'hello')

    messages = hosts['eve'].classical
    i = 0
    while i < MAX_WAIT and len(messages) < 3:
        messages = hosts['eve'].classical
        i += 1
        time.sleep(1)

    assert (len(messages) > 0)
    assert messages[0].sender == hosts['alice'].host_id
    assert (messages[0].content == 'hello')
    assert (messages[1].sender == hosts['alice'].host_id)
    assert (messages[1].content == '11')
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 24
0
    def test_shares_epr(self):
        global hosts
        global network

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}
        # A <-> B
        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            network.add_host(h)

        q_id = hosts['alice'].send_epr(hosts['bob'].host_id)
        q1 = hosts['alice'].shares_epr(hosts['bob'].host_id)
        i = 0
        while not q1 and i < TestOneHop.MAX_WAIT:
            q1 = hosts['alice'].shares_epr(hosts['bob'].host_id)
            i += 1
            time.sleep(1)

        i = 0
        q2 = hosts['bob'].shares_epr(hosts['alice'].host_id)
        while not q2 and i < TestOneHop.MAX_WAIT:
            q2 = hosts['bob'].shares_epr(hosts['alice'].host_id)
            i += 1
            time.sleep(1)

        self.assertTrue(hosts['alice'].shares_epr(hosts['bob'].host_id))
        self.assertTrue(hosts['bob'].shares_epr(hosts['alice'].host_id))
        q_alice = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
        q_bob = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
        self.assertIsNotNone(q_alice)
        self.assertIsNotNone(q_bob)
        self.assertEqual(q_alice.measure(), q_bob.measure())
        self.assertFalse(hosts['alice'].shares_epr(hosts['bob'].host_id))
        self.assertFalse(hosts['bob'].shares_epr(hosts['alice'].host_id))
Ejemplo n.º 25
0
    def test_classical_superdense_combination(self):
        with CQCConnection("Alice") as Alice, CQCConnection(
                "Bob") as Bob, CQCConnection("Eve") as Eve:
            hosts = {
                'alice': Host('00000000', Alice),
                'bob': Host('00000001', Bob),
                'eve': Host('00000011', Eve)
            }
            self.hosts = hosts

            # A <-> B <-> E
            hosts['alice'].add_connection('00000001')
            hosts['bob'].add_connection('00000000')

            hosts['bob'].add_connection('00000011')
            hosts['eve'].add_connection('00000001')

            hosts['alice'].start()
            hosts['bob'].start()
            hosts['eve'].start()

            for h in hosts.values():
                self.network.add_host(h)

            hosts['alice'].send_superdense(hosts['eve'].host_id, '11')
            hosts['alice'].send_classical(hosts['eve'].host_id, 'hello')

            messages = hosts['eve'].classical
            i = 0
            while i < TestTwoHop.MAX_WAIT and len(messages) < 3:
                messages = hosts['eve'].classical
                i += 1
                time.sleep(1)

            self.assertTrue(len(messages) > 0)
            self.assertEqual(messages[0]['sender'], hosts['alice'].host_id)
            self.assertEqual(messages[0]['message'], 'hello')
            self.assertEqual(messages[1]['sender'], hosts['alice'].host_id)
            self.assertEqual(messages[1]['message'], '11')
Ejemplo n.º 26
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    hosts = {'alice': Host('Alice'), 'bob': Host('Bob'), 'eve': Host('Eve')}

    network.delay = 0

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    # B <-> E
    hosts['bob'].add_connection('Eve')
    hosts['eve'].add_connection('Bob')

    hosts['alice'].start()
    hosts['bob'].start()
    hosts['eve'].start()

    for h in hosts.values():
        network.add_host(h)

    network.use_hop_by_hop = False
    hosts['alice'].send_classical(hosts['eve'].host_id, 'testing123')

    i = 0
    messages = hosts['eve'].classical
    while i < MAX_WAIT and len(messages) == 0:
        messages = hosts['eve'].classical
        i += 1
        time.sleep(1)

    assert len(messages) > 0
    assert messages[0].sender == hosts['alice'].host_id
    assert messages[0].content == 'testing123'
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 27
0
    def test_max_wait_for_ack(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        hosts['alice'].add_connection('Bob')
        hosts['bob'].add_connection('Alice')

        hosts['alice'].start()
        hosts['bob'].start()

        for h in hosts.values():
            self.network.add_host(h)

        ack_received_1 = hosts['alice'].send_classical(hosts['bob'].host_id, 'hello bob one', await_ack=True)
        hosts['alice'].max_ack_wait = 0
        ack_received_2 = hosts['alice'].send_classical(hosts['bob'].host_id, 'hello bob one', await_ack=True)
        self.assertTrue(ack_received_1)
        self.assertFalse(ack_received_2)
Ejemplo n.º 28
0
def main():
    backend = EQSNBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.7
    hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}

    # A <-> B
    hosts['alice'].add_connection('Bob')
    hosts['bob'].add_connection('Alice')

    hosts['alice'].start()
    hosts['bob'].start()

    for h in hosts.values():
        network.add_host(h)

    q_id = hosts['alice'].send_epr(hosts['bob'].host_id)
    q1 = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
    i = 0
    while q1 is None and i < 5:
        q1 = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
        i += 1
        time.sleep(1)

    assert q1 is not None
    i = 0
    q2 = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
    while q2 is None and i < 5:
        q2 = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
        i += 1
        time.sleep(1)

    assert q2 is not None
    assert (q1.measure() == q2.measure())
    print("All tests succesfull!")
    network.stop(True)
    exit()
Ejemplo n.º 29
0
    def test_teleport(self):
        with CQCConnection("Alice") as Alice, CQCConnection(
                "Bob") as Bob, CQCConnection("Eve") as Eve:
            hosts = {
                'alice': Host('00000000', Alice),
                'bob': Host('00000001', Bob),
                'eve': Host('00000011', Eve)
            }

            self.hosts = hosts

            # A <-> B <-> E
            hosts['alice'].add_connection('00000001')
            hosts['bob'].add_connection('00000000')

            hosts['bob'].add_connection('00000011')
            hosts['eve'].add_connection('00000001')

            hosts['alice'].start()
            hosts['bob'].start()
            hosts['eve'].start()

            for h in hosts.values():
                self.network.add_host(h)

            q = Qubit(hosts['alice'])
            q.X()

            hosts['alice'].send_teleport(hosts['eve'].host_id, q)
            q2 = None
            i = 0
            while i < TestTwoHop.MAX_WAIT and q2 is None:
                q2 = hosts['eve'].get_data_qubit(hosts['alice'].host_id)
                i += 1
                time.sleep(1)

            self.assertIsNotNone(q2)
            self.assertEqual(q2.measure(), 1)
Ejemplo n.º 30
0
    def test_full_network_routing(self):
        with CQCConnection("Alice") as Alice, CQCConnection(
                "Bob") as Bob, CQCConnection("Eve") as Eve:
            hosts = {
                'alice': Host('00000000', Alice),
                'bob': Host('00000001', Bob),
                'eve': Host('00000011', Eve)
            }

            self.hosts = hosts
            # A <-> B <-> E

            hosts['alice'].add_connection('00000001')
            hosts['bob'].add_connection('00000000')

            hosts['bob'].add_connection('00000011')
            hosts['eve'].add_connection('00000001')

            hosts['alice'].start()
            hosts['bob'].start()
            hosts['eve'].start()

            for h in hosts.values():
                self.network.add_host(h)

            self.network.use_hop_by_hop = False
            hosts['alice'].send_classical(hosts['eve'].host_id, 'testing123')

            i = 0
            messages = hosts['eve'].classical
            while i < TestTwoHop.MAX_WAIT and len(messages) == 0:
                messages = hosts['eve'].classical
                i += 1
                time.sleep(1)

            self.assertTrue(len(messages) > 0)
            self.assertEqual(messages[0]['sender'], hosts['alice'].host_id)
            self.assertEqual(messages[0]['message'], 'testing123')