1818import argparse
1919from ...app import NDNApp
2020from ...encoding import Name , Component
21- from ...types import InterestNack , InterestTimeout , InterestCanceled , ValidationFailure
22- from ... app_support . nfd_mgmt import FaceStatusMsg , FaceQueryFilter , FaceQueryFilterValue , parse_response , FaceFlags
21+ from ...app_support . nfd_mgmt import FaceStatusMsg , FaceQueryFilter , FaceQueryFilterValue , parse_response
22+ from .utils import express_interest
2323
2424
2525def add_parser (subparsers ):
@@ -33,68 +33,44 @@ def execute(args: argparse.Namespace):
3333 app = NDNApp ()
3434
3535 async def list_face ():
36- name = "/localhost/nfd/faces/list"
3736 try :
38- _ , _ , data = await app .express_interest (
39- name , lifetime = 1000 , can_be_prefix = True , must_be_fresh = True )
40-
37+ data = await express_interest (app , "/localhost/nfd/faces/list" )
4138 msg = FaceStatusMsg .parse (data )
4239 # TODO: Should calculate the length instead of using a fixed number
4340 print (f'{ "FaceID" :7} { "RemoteURI" :<30} \t { "LocalURI" :<30} ' )
4441 print (f'{ "------" :7} { "---------" :<30} \t { "--------" :<30} ' )
4542 for f in msg .face_status :
4643 print (f'{ f .face_id :<7} { f .uri :<30} \t { f .local_uri :<30} ' )
47-
48- except InterestNack as e :
49- print (f'Nacked with reason={ e .reason } ' )
50- except InterestTimeout :
51- print ('Timeout' )
52- except InterestCanceled :
53- print ('Local forwarder disconnected' )
54- except ValidationFailure :
55- print ('Data failed to validate' )
5644 finally :
5745 app .shutdown ()
5846
5947 async def inspect_face (face_id , face_uri ):
6048 async def exec_query ():
61- try :
62- _ , _ , data = await app .express_interest (
63- data_name , lifetime = 1000 , can_be_prefix = True , must_be_fresh = True )
64-
65- if not data :
66- return False
67- elif data [0 ] == 0x65 :
68- msg = parse_response (data )
69- print ('Query failed with response' , msg ['status_code' ], msg ['status_text' ])
70- else :
71- msg = FaceStatusMsg .parse (data )
72- for f in msg .face_status :
73- print ()
74- print (f'{ "Face ID" :>12} \t { f .face_id } ' )
75- print (f'{ "Remote URI" :>12} \t { f .uri } ' )
76- print (f'{ "Local URI" :>12} \t { f .local_uri } ' )
77- print (f'{ "Scope" :>12} \t { f .face_scope .name } ' )
78- print (f'{ "Persistency" :>12} \t { f .face_persistency .name } ' )
79- print (f'{ "Link Type" :>12} \t { f .link_type .name } ' )
80- if f .mtu :
81- print (f'{ "MTU" :>12} \t { f .mtu } ' )
82- else :
83- print (f'{ "MTU" :>12} \t -' )
84- print (f'{ "Counter IN" :>12} \t { f .n_in_interests } i { f .n_in_data } d '
85- f'{ f .n_in_nacks } n { f .n_in_bytes } B' )
86- print (f'{ "Counter OUT" :>12} \t { f .n_out_interests } i { f .n_out_data } d '
87- f'{ f .n_out_nacks } n { f .n_out_bytes } B' )
88- print (f'{ "Flags" :>12} \t { FaceFlags (f .flags )} ' )
89-
90- except InterestNack as e :
91- print (f'Nacked with reason={ e .reason } ' )
92- except InterestTimeout :
93- print ('Timeout' )
94- except InterestCanceled :
95- print ('Local forwarder disconnected' )
96- except ValidationFailure :
97- print ('Data failed to validate' )
49+ data = await express_interest (app , data_name )
50+ if not data :
51+ return False
52+ elif data [0 ] == 0x65 :
53+ msg = parse_response (data )
54+ print ('Query failed with response' , msg ['status_code' ], msg ['status_text' ])
55+ else :
56+ msg = FaceStatusMsg .parse (data )
57+ for f in msg .face_status :
58+ print ()
59+ print (f'{ "Face ID" :>12} \t { f .face_id } ' )
60+ print (f'{ "Remote URI" :>12} \t { f .uri } ' )
61+ print (f'{ "Local URI" :>12} \t { f .local_uri } ' )
62+ print (f'{ "Scope" :>12} \t { f .face_scope .name } ' )
63+ print (f'{ "Persistency" :>12} \t { f .face_persistency .name } ' )
64+ print (f'{ "Link Type" :>12} \t { f .link_type .name } ' )
65+ if f .mtu :
66+ print (f'{ "MTU" :>12} \t { f .mtu } ' )
67+ else :
68+ print (f'{ "MTU" :>12} \t -' )
69+ print (f'{ "Counter IN" :>12} \t { f .n_in_interests } i { f .n_in_data } d '
70+ f'{ f .n_in_nacks } n { f .n_in_bytes } B' )
71+ print (f'{ "Counter OUT" :>12} \t { f .n_out_interests } i { f .n_out_data } d '
72+ f'{ f .n_out_nacks } n { f .n_out_bytes } B' )
73+ print (f'{ "Flags" :>12} \t { f .flags } ' )
9874 return True
9975
10076 name = "/localhost/nfd/faces/query"
0 commit comments