Пример #1
0
def main(args):
    # Log Level
    if args.logging == 'error':
        log_level = logging.ERROR
    elif args.logging == 'warning':
        log_level = logging.WARNING
    elif args.logging == 'info':
        log_level = logging.INFO
    elif args.logging == 'debug':
        log_level = logging.DEBUG
    else:
        log_level = 255
    logger = Logger("Repo", log_level)

    # Info
    logger.info("Starting a BeeSens Repo...")
    logger.info("UDP Port:       " + str(args.port))
    logger.info("Web Port:       " + str(args.web_port))
    logger.info("Database Path:  " + str(args.database_path))
    logger.info("Empty Database: " + str(args.flush_database))
    logger.info("PEM Path:       " + str(args.pem_path))
    logger.info("Log Level:      " + args.logging)
    logger.info("Packet Format:  " + args.format)

    # Packet encoder
    encoder = NdnTlvEncoder(log_level) if args.format == 'ndntlv' else SimpleStringEncoder

    # Start
    forwarder = PiCN.Playground.BeeSensRepo.RepoStack(args.port, http_port=args.web_port, log_level=log_level,
                                                      encoder=encoder, database_path=args.database_path,
                                                      flush_database=args.flush_database, pem_path=args.pem_path)
    forwarder.start_forwarder()
    forwarder.link_layer.process.join()
Пример #2
0
def main(args):
    # Log Level
    if args.logging == 'error':
        log_level = logging.ERROR
    elif args.logging == 'warning':
        log_level = logging.WARNING
    elif args.logging == 'info':
        log_level = logging.INFO
    elif args.logging == 'debug':
        log_level = logging.DEBUG
    else:
        log_level = 255
    logger = Logger("Repo", log_level)

    # Info
    logger.info("Starting a PinnedNFN Server...")
    logger.info("Replica ID:     " + str(args.id))
    logger.info("UDP Port:       " + str(args.port))
    logger.info("Log Level:      " + args.logging)
    logger.info("Packet Format:  " + args.format)

    # Packet encoder
    encoder = NdnTlvEncoder(
        log_level) if args.format == 'ndntlv' else SimpleStringEncoder

    # Start
    server = PiCN.Playground.PinnedNFN.PinnedNFNStack(replica_id=args.id,
                                                      port=args.port,
                                                      log_level=log_level,
                                                      encoder=encoder)
    server.start_forwarder()
    server.link_layer.process.join()
Пример #3
0
def main(args):
    # Log Level
    if args.logging == 'error':
        log_level = logging.ERROR
    elif args.logging == 'warning':
        log_level = logging.WARNING
    elif args.logging == 'info':
        log_level = logging.INFO
    elif args.logging == 'debug':
        log_level = logging.DEBUG
    else:
        log_level = 255
    logger = Logger("Repo", log_level)

    # Info
    logger.info("Starting a Repo...")
    logger.info("UDP Port:       " + str(args.port))
    logger.info("Log Level:      " + args.logging)
    logger.info("Packet Format:  " + args.format)

    # Packet encoder
    encoder = NdnTlvEncoder(
        log_level) if args.format == 'ndntlv' else SimpleStringEncoder

    # Start
    forwarder = PiCN.Playground.AssistedSharing.RepoStack(
        args.port, log_level, encoder)
    forwarder.start_forwarder()
    forwarder.link_layer.process.join()
Пример #4
0
def run_singel_interest(format, ip, port, plain, interestName, logger, sock):
    # Packet encoder
    # print("\n Sending Interest "+ str(interestName)+"\n")
    t1=time.time()
    encoder = NdnTlvEncoder() if format == 'ndntlv' else SimpleStringEncoder
    # Generate interest packet
    interest: Interest = Interest(interestName)
    encoded_interest = encoder.encode(interest)

    # Send interest packet
    try:
        resolved_hostname = socket.gethostbyname(ip)
    except:
        print("Resolution of hostname failed.")
        sys.exit(-2)
    sock.sendto(encoded_interest, (resolved_hostname, port))

    # Receive content object
    try:
        wire_packet, addr = sock.recvfrom(8192)
    except:
        print("Timeout.")
        sys.exit(-1)

    # Print
    # if plain is False:
    #     printer = NdnTlvPrinter(wire_packet)
    #     printer.formatted_print()
    # else:
    #     encoder = NdnTlvEncoder()
    #     if encoder.is_content(wire_packet):
    #         sys.stdout.buffer.write(encoder.decode_data(wire_packet)[1])
    #     else:
    #         sys.exit(-2)

    # logger.info("Content Received "+ str(interestName))
    #print("\n Content Received "+ str(interestName)+"\n")
    t2 = time.time()
    print("The response time for"+str(interestName)+","+ str(t1) + "," + str(t2) + "," +str(t2-t1))
Пример #5
0
Файл: flic.py Проект: s3lph/PiCN
 def _indexTable2data(self, pfx: Name, decoder, end: int):
     # traverse the manifest tree
     # input: decoder with index table
     # output: reassembled data
     data = b''
     while decoder._offset < end:
         if decoder.peekType(NDN_TYPE_MANIFEST_DATAPTR, end):
             ptr = decoder.readBlobTlv(NDN_TYPE_MANIFEST_DATAPTR)
             # print("data ptr %s" % binascii.hexlify(ptr))
             name = copy.copy(pfx).setDigest(ptr)
             # print(name.to_json())
             chunk = self.icn.readChunk(name)
             data += NdnTlvEncoder().decode(chunk).get_bytes()
         elif decoder.peekType(NDN_TYPE_MANIFEST_MANIFESTPTR, end):
             ptr = decoder.readBlobTlv(NDN_TYPE_MANIFEST_MANIFESTPTR)
             # print("manifest ptr %s" % binascii.hexlify(ptr))
             name = copy.copy(pfx).setDigest(ptr)
             chunk = self.icn.readChunk(name)
             content = NdnTlvEncoder().decode(chunk)
             data += self._manifestToBytes(content.get_bytes())
         else:
             print("invalid index table entry")
             return data
     return data
Пример #6
0
def main(args):

    prefix = Name(args.icnprefix)

    log_level = logging.DEBUG

    if args.format == "ndntlv":
        encoder = NdnTlvEncoder()
    else:
        encoder = SimpleStringEncoder(log_level=log_level)

    repo = ICNDataRepository(args.datapath,
                             prefix,
                             args.port,
                             log_level,
                             encoder=encoder,
                             autoconfig=args.autoconfig)
    repo.start_repo()

    repo.linklayer.process.join()
Пример #7
0
 def setUp(self):
     self.f9000 = ICNForwarder(9000, encoder=NdnTlvEncoder(), routing=True,
                               peers=[('127.0.0.1', 9001), ('127.0.0.1', 9002), ('127.0.0.1', 9090)])
     self.f9001 = ICNForwarder(9001, encoder=NdnTlvEncoder(), routing=True,
                               peers=[('127.0.0.1', 9000), ('127.0.0.1', 9002), ('127.0.0.1', 9003),
                                      ('127.0.0.1', 9004)])
     self.f9002 = ICNForwarder(9002, encoder=NdnTlvEncoder(), routing=True,
                               peers=[('127.0.0.1', 9000), ('127.0.0.1', 9001), ('127.0.0.1', 9004)])
     self.f9003 = ICNForwarder(9003, encoder=NdnTlvEncoder(), routing=True,
                               peers=[('127.0.0.1', 9001), ('127.0.0.1', 9004)])
     self.f9004 = ICNForwarder(9004, encoder=NdnTlvEncoder(), routing=True,
                               peers=[('127.0.0.1', 9001), ('127.0.0.1', 9002), ('127.0.0.1', 9003)])
     os.makedirs('/tmp/test_repo', exist_ok=True)
     f = open('/tmp/test_repo/helloworld', 'w')
     f.write('Hello, World!\n')
     f.close()
     self.repo = ICNDataRepository('/tmp/test_repo', Name('/testrepo'), port=9090, encoder=NdnTlvEncoder())
     self.fetch = Fetch('127.0.0.1', 9004, encoder=NdnTlvEncoder())
     # Create RIB entry for the repository (with Python weirdness)
     repo_fid: int = self.f9000.linklayer.faceidtable.get_or_create_faceid(AddressInfo(('127.0.0.1', 9090), 0))
     rib: BaseRoutingInformationBase = self.f9000.routinglayer.rib
     rib.insert(Name('/testrepo'), repo_fid, distance=1, timeout=None)
Пример #8
0
Файл: flic.py Проект: s3lph/PiCN
 def _mkContentChunk(self, name: Name, data: bytes):
     # input: name, payload bytes
     # output: chunk bytes
     c = Content(name, data)
     return NdnTlvEncoder().encode(c)  # and sign
Пример #9
0
Файл: flic.py Проект: s3lph/PiCN
 def bytesFromManifestName(self, name: Name):
     chunk = self.icn.readChunk(name)
     content = NdnTlvEncoder().decode(chunk)
     name._components.pop()  # drop the last component (e.g. '_')
     return self._manifestToBytes(name, content.get_bytes())
Пример #10
0
def main(args):
    logger = Logger(
        "ICNPushRepo",
        logging.DEBUG)  # note: set later according to cli/config arguments
    logger.info("Starting a Push Repository...")

    # Parse Configuration file
    conf = None
    if args.config != "none":
        try:
            conf = ConfigParser(args.config)
            logger.info("Successfully parsed configuration file.")
        except CouldNotOpenConfigError:
            conf = None
            logger.warning(
                "Could not open configuration file. Proceed with command line arguments or default values."
            )
        except CouldNotParseError:
            logger.warning(
                "Could not parse configuration file. Proceed with command line arguments or default values."
            )
        except MalformedConfigurationError as e:
            logger.warning(
                "Invalid configuration file. Proceed with command line arguments or default values. Hint: "
                + str(e))

    # Choose command line arguments before config file arguments before default values
    if not args.port:
        if conf and conf.udp_port:
            args.port = conf.udp_port
        else:
            args.port = default_port

    if not args.format:
        if conf and conf.format:
            args.format = conf.format
        else:
            args.format = default_format

    if not args.logging:
        if conf and conf.logging:
            args.logging = conf.logging
        else:
            args.logging = default_logging

    # Log Level
    if args.logging == 'error':
        log_level = logging.ERROR
    elif args.logging == 'warning':
        log_level = logging.WARNING
    elif args.logging == 'info':
        log_level = logging.INFO
    elif args.logging == 'debug':
        log_level = logging.DEBUG
    else:
        log_level = 255
    logger.setLevel(log_level)

    # Info
    logger.info("UDP Port:       " + str(args.port))
    logger.info("Log Level:      " + args.logging)
    logger.info("Packet Format:  " + args.format)
    logger.info("Database:       " + args.database_path)
    logger.info("Flush DB:       " + str(args.flush_database))

    # Packet encoder
    encoder = NdnTlvEncoder(
        log_level) if args.format == 'ndntlv' else SimpleStringEncoder(
            log_level)

    # Start
    forwarder = PiCN.ProgramLibs.ICNPushRepository.ICNPushRepository(
        args.database_path, args.port, log_level, encoder, args.flush_database)
    forwarder.start_forwarder()
    forwarder.linklayer.process.join()
Пример #11
0
 def __init__(self, log_level=255):
     NdnTlvEncoder.__init__(self, log_level=log_level)
     self.heartbeatTV = 0x02  # deliberately picked for this prototype :)
Пример #12
0
from PiCN.ProgramLibs.Fetch import Fetch
from PiCN.ProgramLibs.NFNForwarder import NFNForwarder
from PiCN.Layers.LinkLayer.Interfaces import SimulationBus
from PiCN.Layers.LinkLayer.Interfaces import AddressInfo
from PiCN.Layers.PacketEncodingLayer.Encoder import BasicEncoder, SimpleStringEncoder, NdnTlvEncoder
from PiCN.Mgmt import MgmtClient
from PiCN.Packets import Content, Interest, Name

simulation_bus = SimulationBus(packetencoder=NdnTlvEncoder())
nfn_fwd0 = NFNForwarder(port=0,
                        encoder=NdnTlvEncoder(),
                        interfaces=[simulation_bus.add_interface("nfn0")],
                        log_level=255,
                        ageing_interval=1)

nfn_fwd1 = NFNForwarder(port=0,
                        encoder=NdnTlvEncoder(),
                        interfaces=[simulation_bus.add_interface("nfn1")],
                        log_level=255,
                        ageing_interval=1)

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

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

nfn_fwd0.start_forwarder()