Пример #1
0
    def general_status():
        def convert_time(timestamp):
            ret = datetime.fromtimestamp(float(timestamp) / 1000.0)
            return str(ret)

        interest = Interest("/localhost/nfd/status/general")
        interest.mustBeFresh = True
        interest.canBePrefix = True
        ret = run_until_complete(fetch_data_packet(server.face, interest))
        if isinstance(ret, Data):
            name = ret.name.toUri()
            msg = GeneralStatus()
            try:
                ProtobufTlv.decode(msg, ret.content)
            except RuntimeError as exc:
                logging.fatal("Decoding Error %s", exc)
                return "Decoding Error"
            status = decode_dict(msg)
            status['start_timestamp'] = convert_time(status['start_timestamp'])
            status['current_timestamp'] = convert_time(
                status['current_timestamp'])
            return render_template('general-status.html',
                                   refer_name='/general-status',
                                   name=name,
                                   status=status)
        else:
            logging.info("No response: general status")
            return redirect('/')
Пример #2
0
    def route_list():
        def decode_route_list(msg):
            ret = []
            for item in msg:
                name = decode_name(item.name)
                routes = decode_list(item.route)
                ret.append((name, routes))
            return ret

        interest = Interest("/localhost/nfd/rib/list")
        interest.mustBeFresh = True
        interest.canBePrefix = True
        ret = run_until_complete(fetch_data_packet(server.face, interest))
        if isinstance(ret, Data):
            name = ret.name.toUri()
            msg = RibStatusMessage()
            try:
                ProtobufTlv.decode(msg, ret.content)
            except RuntimeError as exc:
                logging.fatal("Decoding Error %s", exc)
                return "Decoding Error"
            rib_list = decode_route_list(msg.rib_entry)
            return render_template('route-list.html',
                                   refer_name='/route-list',
                                   rib_list=rib_list,
                                   **request.args.to_dict())
        else:
            logging.info("No response: route-list")
            return redirect('/')
Пример #3
0
    def strategy_list():
        def decode_strategy(msg):
            return [{
                "name": decode_name(item.name),
                "strategy": decode_name(item.strategy.name),
            } for item in msg]

        interest = Interest("/localhost/nfd/strategy-choice/list")
        interest.mustBeFresh = True
        interest.canBePrefix = True
        ret = run_until_complete(fetch_data_packet(server.face, interest))
        if isinstance(ret, Data):
            msg = StrategyChoiceMessage()
            try:
                ProtobufTlv.decode(msg, ret.content)
            except RuntimeError as exc:
                logging.info("Decoding Error %s", exc)
                return "Decoding Error"
            strategy_list = decode_strategy(msg.strategy_choice)
            return render_template('strategy-list.html',
                                   refer_name='/strategy-list',
                                   strategy_list=strategy_list,
                                   **request.args.to_dict())
        else:
            logging.info("No response: strategy-list")
            return redirect('/')
Пример #4
0
 def face_list():
     interest = Interest("/localhost/nfd/faces/list")
     interest.mustBeFresh = True
     interest.canBePrefix = True
     ret = run_until_complete(fetch_data_packet(server.face, interest))
     if isinstance(ret, Data):
         name = ret.name.toUri()
         msg = FaceStatusMessage()
         try:
             ProtobufTlv.decode(msg, ret.content)
         except RuntimeError as exc:
             logging.fatal("Decoding Error %s", exc)
             return "Decoding Error"
         face_list = decode_list(msg.face_status)
         fields = list(face_list[0].keys())
         fields_collapse = [
             field for field in set(fields) - {'face_id', 'uri'}
         ]
         return render_template('face-list.html',
                                refer_name='/face-list',
                                face_list=face_list,
                                fields_collapse=fields_collapse,
                                **request.args.to_dict())
     else:
         logging.info("No response: face-list")
         return redirect('/')
Пример #5
0
    def exec_ndn_ping():
        nonlocal last_ping_data
        name = request.form['name']
        can_be_prefix = request.form['can_be_prefix'] == 'true'
        must_be_fresh = request.form['must_be_fresh'] == 'true'
        try:
            interest_lifetime = float(
                request.form['interest_lifetime']) * 1000.0
        except ValueError:
            interest_lifetime = 4000.0

        interest = Interest(name)
        interest.canBePrefix = can_be_prefix
        interest.mustBeFresh = must_be_fresh
        interest.interestLifetimeMilliseconds = interest_lifetime
        st_time = time.time()
        ret = run_until_complete(fetch_data_packet(server.face, interest))
        ed_time = time.time()
        response_time = '{:.3f}s'.format(ed_time - st_time)
        if isinstance(ret, Data):
            response_type = 'Data'
            name = ret.name.toUri()
            if ret.metaInfo.type is not None:
                content_type = decode_content_type(ret.metaInfo.type)
            else:
                content_type = "None"
            if ret.metaInfo.freshnessPeriod is not None:
                freshness_period = "{:.3f}s".format(
                    ret.metaInfo.freshnessPeriod / 1000.0)
            else:
                freshness_period = "None"
            if ret.metaInfo.finalBlockId is not None:
                final_block_id = ret.metaInfo.finalBlockId.toEscapedString()
            else:
                final_block_id = "None"
            signature_type = type(ret.signature).__name__
            last_ping_data = ret.content.toBytes()
            return redirect(
                url_for('ndn_ping',
                        response_time=response_time,
                        response_type=response_type,
                        name=name,
                        content_type=content_type,
                        freshness_period=freshness_period,
                        final_block_id=final_block_id,
                        signature_type=signature_type,
                        download='/download/ping-data'))
        elif isinstance(ret, NetworkNack):
            response_type = 'NetworkNack'
            reason = decode_nack_reason(ret.getReason())
            return redirect(
                url_for('ndn_ping',
                        response_time=response_time,
                        response_type=response_type,
                        name=name,
                        reason=reason))
        elif ret is None:
            response_type = 'Timeout'
            return redirect(
                url_for('ndn_ping',
                        response_time=response_time,
                        response_type=response_type,
                        name=name))
        else:
            logging.info("No response: ndn-ping")
            return redirect('/')