-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
524 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2019-2021 The python-ndn authors | ||
# | ||
# This file is part of python-ndn. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
import argparse | ||
from ...app import NDNApp | ||
from ...encoding import Name | ||
from ...app_support.nfd_mgmt import FibStatus, RibStatus | ||
from .utils import express_interest | ||
|
||
|
||
def add_parser(subparsers): | ||
parser = subparsers.add_parser('Get-Route', aliases=['route', 'gr']) | ||
parser.add_argument('route', metavar='ROUTE', nargs='?', default='', | ||
help='The prefix of the specified route to query') | ||
parser.set_defaults(executor=execute) | ||
|
||
|
||
def execute(args: argparse.Namespace): | ||
app = NDNApp() | ||
route = args.route | ||
|
||
async def list_route(): | ||
try: | ||
fib_data = await express_interest(app, "/localhost/nfd/fib/list") | ||
fib_msg = FibStatus.parse(fib_data) | ||
rib_data = await express_interest(app, "/localhost/nfd/rib/list") | ||
rib_msg = RibStatus.parse(rib_data) | ||
# TODO: Should calculate the length instead of using a fixed number | ||
print('Forwarding Table (FIB)') | ||
for ent in fib_msg.entries: | ||
prefix = Name.to_str(ent.name) | ||
if route and prefix != route: | ||
continue | ||
print(prefix) | ||
for nh in ent.next_hop_records: | ||
print(f'\tFaceID={nh.face_id:<5} Cost={nh.cost:<5}') | ||
print() | ||
print('Routing Table (RIB)') | ||
for ent in rib_msg.entries: | ||
prefix = Name.to_str(ent.name) | ||
if route and prefix != route: | ||
continue | ||
print(prefix) | ||
for nh in ent.routes: | ||
print(f'\tFaceID={nh.face_id:<5} Cost={nh.cost:<5} Origin={nh.origin:<3} Flags={nh.flags}') | ||
finally: | ||
app.shutdown() | ||
|
||
app.run_forever(list_route()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2019-2021 The python-ndn authors | ||
# | ||
# This file is part of python-ndn. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
import argparse | ||
from ...app import NDNApp | ||
from ...encoding import Name | ||
from ...app_support.nfd_mgmt import StrategyChoiceMsg | ||
from .utils import express_interest | ||
|
||
|
||
def add_parser(subparsers): | ||
parser = subparsers.add_parser('Get-Strategy', aliases=['strategy', 'gs']) | ||
parser.add_argument('prefix', metavar='PREFIX', nargs='?', default='', | ||
help='The specified route prefix') | ||
parser.set_defaults(executor=execute) | ||
|
||
|
||
def execute(args: argparse.Namespace): | ||
app = NDNApp() | ||
prefix = args.prefix | ||
|
||
async def list_strategy(): | ||
try: | ||
data = await express_interest(app, "/localhost/nfd/strategy-choice/list") | ||
msg = StrategyChoiceMsg.parse(data) | ||
for s in msg.strategy_choices: | ||
s_prefix = Name.to_str(s.name) | ||
if prefix and s_prefix != prefix: | ||
continue | ||
print(f'{s_prefix}\n\t{Name.to_str(s.strategy.name)}') | ||
finally: | ||
app.shutdown() | ||
|
||
app.run_forever(list_strategy()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2019-2021 The python-ndn authors | ||
# | ||
# This file is part of python-ndn. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
import argparse | ||
from ...app import NDNApp | ||
from ...app_support.nfd_mgmt import parse_response, make_command | ||
from .utils import express_interest | ||
|
||
|
||
def add_parser(subparsers): | ||
parser = subparsers.add_parser('New-Face', aliases=['nf']) | ||
parser.add_argument('uri', metavar='URI', | ||
help='The URI or IP address of the face to create. ' | ||
'Note: current version does not support DNS resolve.') | ||
parser.set_defaults(executor=execute) | ||
|
||
|
||
def execute(args: argparse.Namespace): | ||
app = NDNApp() | ||
uri = str(args.uri) | ||
if uri.find('://') < 0: | ||
uri = 'udp4://' + uri | ||
if len(uri.split(":")) < 3: | ||
uri = uri + ":6363" | ||
|
||
async def create_face(): | ||
cmd = make_command('faces', 'create', uri=uri.encode()) | ||
res = await express_interest(app, cmd) | ||
msg = parse_response(res) | ||
print(f'{msg["status_code"]} {msg["status_text"]}') | ||
app.shutdown() | ||
|
||
app.run_forever(after_start=create_face()) |
Oops, something went wrong.