예제 #1
0
 def _send_to_master(self, pld):
     """
     Send the payload to the master PS.
     """
     master = self._master_id
     if self._is_master():
         return
     if not master:
         logging.warning("_send_to_master(): _master_id not set.")
         return
     pkt = self._build_packet(haddr_parse("IPV4", master),
                              payload=pld.copy())
     self.send(pkt, master)
예제 #2
0
    def test(self):
        """
        Bandwidth test method. Obtains a path to (2, 26) and sends PACKETS_NO
        packets (each with PAYLOAD_SIZE long payload) to a host in (2, 26).
        """
        addr = haddr_parse("IPV4", "127.1.19.254")
        conf_dir = "%s/ISD1/AD19/endhost" % GEN_PATH
        sender = SCIONDaemon.start(conf_dir, addr)

        paths = sender.get_paths(2, 26)
        self.assertTrue(paths)

        rcv_sock = UDPSocket(bind=("127.2.26.254", 0, "Bw test receiver"),
                             addr_type=AddrType.IPV4)

        logging.info("Starting the receiver.")
        recv_t = threading.Thread(
            target=thread_safety_net, args=(self.receiver, rcv_sock),
            name="BwT.receiver")
        recv_t.start()

        payload = PayloadRaw(b"A" * PAYLOAD_SIZE)
        spkt = sender._build_packet(
            haddr_parse("IPV4", "127.2.26.254"), dst_isd=2, dst_ad=26,
            dst_port=rcv_sock.port, payload=payload, path=paths[0])
        (next_hop, port) = sender.get_first_hop(spkt)
        assert next_hop is not None
        logging.info("Sending %d payload bytes (%d packets x %d bytes )" %
                     (PACKETS_NO * PAYLOAD_SIZE, PACKETS_NO, PAYLOAD_SIZE))
        for _ in range(PACKETS_NO):
            sender.send(spkt, next_hop, port)
            time.sleep(SLEEP)
        logging.info("Sending finished")

        recv_t.join()
        if self.rate < 10.0:
            sys.exit(0)
        else:
            sys.exit(int(self.rate))
예제 #3
0
def addr_c2py(caddr):
    """
    Helper function to convert C_SCIONAddr to SCIONAddr
    :param caddr: C_SCIONAddr to convert
    :type caddr: C_SCIONAddr
    :returns: Converted object
    :rtype: SCIONAddr
    """
    isd_as = ISD_AS(caddr.isd_as.to_bytes(4, 'big'))
    if caddr.host.addr_type == 0:
        return None
    htype = haddr_get_type(caddr.host.addr_type)
    haddr = haddr_parse(caddr.host.addr_type,
                        bytes(caddr.host.addr)[:htype.LEN])
    return SCIONAddr.from_values(isd_as, haddr)
예제 #4
0
# Stdlib
import random
import struct
import threading
import time

# SCION
from lib.packet.host_addr import haddr_parse
from lib.packet.scion_addr import ISD_AS, SCIONAddr
from lib.packet.svc import SVCType
from lib.tcp.socket import SCIONTCPSocket, SockOpt
from lib.util import recv_all
from integration.base_cli_srv import start_sciond

s_isd_as = ISD_AS("1-18")
s_ip = haddr_parse(1, "127.1.1.1")
c_isd_as = ISD_AS("2-26")
c_ip = haddr_parse(1, "127.2.2.2")
# TODO(PSz): test with 0
MAX_MSG_SIZE = 500000


def get_msg():
    size = random.randint(1, MAX_MSG_SIZE)
    return struct.pack("!I", size) + b"A"*size


def server(svc=False):
    print("server running")
    s = SCIONTCPSocket()
    print('setsockopt')
예제 #5
0
 def addr(self, idx):  # pragma: no cover
     return (haddr_parse(self.p.addrs[idx].type, self.p.addrs[idx].addr),
             self.p.addrs[idx].port)
예제 #6
0
파일: conf.py 프로젝트: netsec-ethz/pki
 def __init__(self, isd_as, ip, pubkey):
     self.addr = SCIONAddr.from_values(ISD_AS(isd_as), haddr_parse(1, ip))
     self.pubkey = pubkey
예제 #7
0
            cli.connect(monitor_id)
            print("Connection established")
            print("Confirmed", cli.confirm_root(root), end="\n\n")
            cli.close()


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("%s <srcISD-AS> <srcIP>" % sys.argv[0])
        # PYTHONPATH=..:../scion:../scion/python python3 log/client.py 2-25 127.2.2.2
        sys.exit(-1)

    import random
    from pki.test.basic_tests import load_mscs_scps
    addr = SCIONAddr.from_values(ISD_AS(sys.argv[1]),
                                 haddr_parse(1, sys.argv[2]))
    conf_file = OUTPUT_DIR + CONF_DIR + CONF_FILE
    # start client
    cli = LogClient(addr, conf_file)
    # take sample MSCs and SCPs and try to register them with random log
    mscs, scps = load_mscs_scps()
    mscs = list(mscs.values())
    scps = list(scps.values())
    rnd_log = random.choice(list(cli.conf.logs))
    print("Connecting to %s" % rnd_log)
    cli.connect(rnd_log)
    all_ = scps + mscs
    random.shuffle(all_)
    print("Submitting SCPs and MSCs to %s" % rnd_log)
    for obj in all_:
        print(cli.submit(obj))