Skip to content

Commit 82d67ba

Browse files
committed
Migrate examples and CLIs into new model
1 parent 4df603d commit 82d67ba

25 files changed

Lines changed: 72 additions & 67 deletions

‎examples/appv2/basic_packets/consumer.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# limitations under the License.
1717
# -----------------------------------------------------------------------------
1818
import logging
19-
from ndn import utils, appv2, types
19+
from ndn import utils, appv2_2, types
2020
from ndn import encoding as enc
2121

2222

@@ -26,7 +26,7 @@
2626
style='{')
2727

2828

29-
app = appv2.NDNApp()
29+
app = appv2_2.NDNApp()
3030

3131

3232
async def main():
@@ -36,7 +36,7 @@ async def main():
3636
print(f'Sending Interest {enc.Name.to_str(name)}, {enc.InterestParam(must_be_fresh=True, lifetime=6000)}')
3737
# TODO: Write a better validator
3838
data_name, content, pkt_context = await app.express(
39-
name, validator=appv2.pass_all,
39+
name, validator=appv2_2.pass_all,
4040
must_be_fresh=True, can_be_prefix=False, lifetime=6000)
4141

4242
print(f'Received Data Name: {enc.Name.to_str(data_name)}')

‎examples/appv2/basic_packets/producer.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# limitations under the License.
1717
# -----------------------------------------------------------------------------
1818
import logging
19-
from ndn import appv2
19+
from ndn import appv2_2
2020
from ndn import encoding as enc
2121

2222

@@ -26,13 +26,13 @@
2626
style='{')
2727

2828

29-
app = appv2.NDNApp()
29+
app = appv2_2.NDNApp()
3030
keychain = app.default_keychain()
3131

3232

3333
@app.route('/example/testApp')
3434
def on_interest(name: enc.FormalName, _app_param: enc.BinaryStr | None,
35-
reply: appv2.ReplyFunc, context: appv2.PktContext):
35+
reply: appv2_2.ReplyFunc, context: appv2_2.PktContext):
3636
print(f'>> I: {enc.Name.to_str(name)}, {context["int_param"]}')
3737
content = b"Hello, world!"
3838
reply(app.make_data(name, content=content, signer=keychain.get_signer({}),

‎examples/appv2/forwarding_hint/consumer.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# limitations under the License.
1717
# -----------------------------------------------------------------------------
1818
import logging
19-
from ndn import utils, appv2, types
19+
from ndn import utils, appv2_2, types
2020
from ndn import encoding as enc
2121

2222

@@ -26,21 +26,21 @@
2626
style='{')
2727

2828

29-
app = appv2.NDNApp()
29+
app = appv2_2.NDNApp()
3030

3131

3232
async def express_int(name, fw_hint):
3333
try:
3434
if fw_hint is None:
3535
print(f'Sending Interest {enc.Name.to_str(name)}, {enc.InterestParam(must_be_fresh=True, lifetime=6000)}')
3636
data_name, content, pkt_context = await app.express(
37-
name, validator=appv2.pass_all,
37+
name, validator=appv2_2.pass_all,
3838
must_be_fresh=True, can_be_prefix=False, lifetime=6000)
3939
else:
4040
print(f'Sending Interest {enc.Name.to_str(name)}, '
4141
f'{enc.InterestParam(must_be_fresh=True, lifetime=6000, forwarding_hint=[fw_hint])}')
4242
data_name, content, pkt_context = await app.express(
43-
name, validator=appv2.pass_all,
43+
name, validator=appv2_2.pass_all,
4444
must_be_fresh=True, can_be_prefix=False, lifetime=6000, forwarding_hint=[fw_hint])
4545

4646
print(f'Received Data Name: {enc.Name.to_str(data_name)}')

‎examples/appv2/forwarding_hint/producer.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from ndn import appv2
2+
from ndn import appv2_2
33
from ndn import encoding as enc
44

55

@@ -9,13 +9,13 @@
99
style='{')
1010

1111

12-
app = appv2.NDNApp()
12+
app = appv2_2.NDNApp()
1313
keychain = app.default_keychain()
1414

1515

1616
@app.route('/repo/command')
1717
def on_cmd(name: enc.FormalName, _app_param: enc.BinaryStr | None,
18-
reply: appv2.ReplyFunc, context: appv2.PktContext):
18+
reply: appv2_2.ReplyFunc, context: appv2_2.PktContext):
1919
print(f'>> I: {enc.Name.to_str(name)}, {context["int_param"]}')
2020
content = b"Hello, world!"
2121
reply(app.make_data(name, content=content, signer=keychain.get_signer({}),
@@ -30,7 +30,7 @@ def on_cmd(name: enc.FormalName, _app_param: enc.BinaryStr | None,
3030
# So we can dispatch by forwarding hints.
3131
@app.route('/')
3232
def on_fwd_hint(name: enc.FormalName, app_param: enc.BinaryStr | None,
33-
reply: appv2.ReplyFunc, context: appv2.PktContext):
33+
reply: appv2_2.ReplyFunc, context: appv2_2.PktContext):
3434
fwd_hints = context["int_param"].forwarding_hint
3535
if fwd_hints:
3636
fh_name = fwd_hints[0]

‎examples/appv2/keychain_cert/fetch_certificate.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
# -----------------------------------------------------------------------------
1818
import sys
1919
import logging
20-
from ndn import appv2, types
20+
from ndn import appv2_2, types
2121
from ndn import encoding as enc
22-
from ndn.app_support import security_v2 as secv2
22+
from ndn.app_support import security_v2_2 as secv2
2323

2424

2525
logging.basicConfig(format='[{asctime}]{levelname}:{message}',
@@ -32,7 +32,7 @@
3232
logging.fatal('Please input a KEY or CERT name')
3333
exit(0)
3434

35-
app = appv2.NDNApp()
35+
app = appv2_2.NDNApp()
3636

3737

3838
async def main():
@@ -43,7 +43,7 @@ async def main():
4343
f'{enc.InterestParam(must_be_fresh=True, can_be_prefix=can_be_prefix, lifetime=6000)}')
4444
# TODO: Write a better validator
4545
data_name, content, pkt_context = await app.express(
46-
name, validator=appv2.pass_all,
46+
name, validator=appv2_2.pass_all,
4747
must_be_fresh=True, can_be_prefix=can_be_prefix, lifetime=6000)
4848

4949
print(f'Received Data Name: {enc.Name.to_str(data_name)}')

‎examples/appv2/keychain_cert/keychain_register.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# limitations under the License.
1717
# -----------------------------------------------------------------------------
1818
import logging
19-
from ndn import appv2
19+
from ndn import appv2_2
2020
from ndn.app_support.keychain_register import attach_keychain_register
2121

2222

@@ -26,7 +26,7 @@
2626
style='{')
2727

2828

29-
app = appv2.NDNApp()
29+
app = appv2_2.NDNApp()
3030
keychain = app.default_keychain()
3131
attach_keychain_register(keychain, app)
3232

‎examples/dpdk_experimental/udp_consumer.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# -----------------------------------------------------------------------------
1818
import logging
1919
import sys
20-
from ndn import utils, appv2, types
20+
from ndn import utils, appv2_2, types
2121
from ndn import encoding as enc
2222
from ndn.transport.ndn_dpdk import NdnDpdkUdpFace, DpdkRegisterer
2323

@@ -42,7 +42,7 @@
4242
face = NdnDpdkUdpFace(gql_url, self_addr, self_port, dpdk_addr, dpdk_port)
4343
registerer = DpdkRegisterer(face)
4444

45-
app = appv2.NDNApp(face=face, registerer=registerer)
45+
app = appv2_2.NDNApp(face=face, registerer=registerer)
4646
keychain = app.default_keychain()
4747

4848

@@ -53,7 +53,7 @@ async def main():
5353
print(f'Sending Interest {enc.Name.to_str(name)}, {enc.InterestParam(must_be_fresh=True, lifetime=6000)}')
5454
# TODO: Write a better validator
5555
data_name, content, pkt_context = await app.express(
56-
name, validator=appv2.pass_all,
56+
name, validator=appv2_2.pass_all,
5757
must_be_fresh=True, can_be_prefix=False, lifetime=6000)
5858

5959
print(f'Received Data Name: {enc.Name.to_str(data_name)}')

‎examples/dpdk_experimental/udp_producer.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# -----------------------------------------------------------------------------
1818
import logging
1919
import sys
20-
from ndn import appv2
20+
from ndn import appv2_2
2121
from ndn import encoding as enc
2222
from ndn.transport.ndn_dpdk import NdnDpdkUdpFace, DpdkRegisterer
2323

@@ -42,13 +42,13 @@
4242
face = NdnDpdkUdpFace(gql_url, self_addr, self_port, dpdk_addr, dpdk_port)
4343
registerer = DpdkRegisterer(face)
4444

45-
app = appv2.NDNApp(face=face, registerer=registerer)
45+
app = appv2_2.NDNApp(face=face, registerer=registerer)
4646
keychain = app.default_keychain()
4747

4848

4949
@app.route('/example/testApp')
5050
def on_interest(name: enc.FormalName, _app_param: enc.BinaryStr | None,
51-
reply: appv2.ReplyFunc, context: appv2.PktContext):
51+
reply: appv2_2.ReplyFunc, context: appv2_2.PktContext):
5252
print(f'>> I: {enc.Name.to_str(name)}, {context["int_param"]}')
5353
content = b"Hello, world!"
5454
reply(app.make_data(name, content=content, signer=keychain.get_signer({}),

‎src/ndn/bin/nfdc/cmd_get_face.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
# limitations under the License.
1717
# -----------------------------------------------------------------------------
1818
import argparse
19-
from ...appv2 import NDNApp
19+
from ...appv2_2 import NDNApp
2020
from ...encoding import Name, Component
21-
from ...app_support.nfd_mgmt import FaceStatusMsg, FaceQueryFilter, FaceQueryFilterValue, parse_response
21+
from ...encoding.tlv_model_v2 import tlv_encode, tlv_parse
22+
from ...app_support.nfd_mgmt_2 import FaceStatusMsg, FaceQueryFilter, FaceQueryFilterValue, parse_response
2223
from .utils import express_interest
2324

2425

@@ -35,7 +36,7 @@ def execute(args: argparse.Namespace):
3536
async def list_face():
3637
try:
3738
data = await express_interest(app, "/localhost/nfd/faces/list")
38-
msg = FaceStatusMsg.parse(data)
39+
msg = tlv_parse(FaceStatusMsg, data)
3940
# TODO: Should calculate the length instead of using a fixed number
4041
print(f'{"FaceID":7}{"RemoteURI":<30}\t{"LocalURI":<30}')
4142
print(f'{"------":7}{"---------":<30}\t{"--------":<30}')
@@ -53,7 +54,7 @@ async def exec_query():
5354
msg = parse_response(data)
5455
print('Query failed with response', msg['status_code'], msg['status_text'])
5556
else:
56-
msg = FaceStatusMsg.parse(data)
57+
msg = tlv_parse(FaceStatusMsg, data)
5758
for f in msg.face_status:
5859
print()
5960
print(f'{"Face ID":>12}\t{f.face_id}')
@@ -78,16 +79,16 @@ async def exec_query():
7879
filt.face_query_filter = FaceQueryFilterValue()
7980
if face_id is not None:
8081
filt.face_query_filter.face_id = face_id
81-
data_name = Name.from_str(name) + [Component.from_bytes(filt.encode())]
82+
data_name = Name.from_str(name) + [Component.from_bytes(tlv_encode(filt))]
8283
if not await exec_query():
8384
print('No face is found')
8485
else:
8586
filt.face_query_filter.uri = face_uri
86-
data_name = Name.from_str(name) + [Component.from_bytes(filt.encode())]
87+
data_name = Name.from_str(name) + [Component.from_bytes(tlv_encode(filt))]
8788
if not await exec_query():
8889
filt.face_query_filter.uri = None
8990
filt.face_query_filter.local_uri = face_uri
90-
data_name = Name.from_str(name) + [Component.from_bytes(filt.encode())]
91+
data_name = Name.from_str(name) + [Component.from_bytes(tlv_encode(filt))]
9192
if not await exec_query():
9293
print('No face is found')
9394
app.shutdown()

‎src/ndn/bin/nfdc/cmd_get_route.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
# limitations under the License.
1717
# -----------------------------------------------------------------------------
1818
import argparse
19-
from ...appv2 import NDNApp
19+
from ...appv2_2 import NDNApp
2020
from ...encoding import Name
21-
from ...app_support.nfd_mgmt import FibStatus, RibStatus
21+
from ...encoding.tlv_model_v2 import tlv_parse
22+
from ...app_support.nfd_mgmt_2 import FibStatus, RibStatus
2223
from .utils import express_interest
2324

2425

@@ -36,9 +37,9 @@ def execute(args: argparse.Namespace):
3637
async def list_route():
3738
try:
3839
fib_data = await express_interest(app, "/localhost/nfd/fib/list")
39-
fib_msg = FibStatus.parse(fib_data)
40+
fib_msg = tlv_parse(FibStatus, fib_data)
4041
rib_data = await express_interest(app, "/localhost/nfd/rib/list")
41-
rib_msg = RibStatus.parse(rib_data)
42+
rib_msg = tlv_parse(RibStatus, rib_data)
4243
# TODO: Should calculate the length instead of using a fixed number
4344
print('Forwarding Table (FIB)')
4445
for ent in fib_msg.entries:

0 commit comments

Comments
 (0)