Add new Nfdc batch helper to speed up running multiple commands
and refactoring to minimize code duplication.
Also added two demos/tests under examples to validate behavior.
Change-Id: I0700b7e204793d2a6bbf75f7c920a3e3951005be
diff --git a/examples/tests/faces_test.py b/examples/demos_and_tests/faces_test.py
similarity index 78%
rename from examples/tests/faces_test.py
rename to examples/demos_and_tests/faces_test.py
index 0589441..c1b7a3f 100644
--- a/examples/tests/faces_test.py
+++ b/examples/demos_and_tests/faces_test.py
@@ -1,6 +1,6 @@
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
#
-# Copyright (C) 2015-2021, The University of Memphis,
+# Copyright (C) 2015-2024, The University of Memphis,
# Arizona Board of Regents,
# Regents of the University of California.
#
@@ -73,8 +73,9 @@
It can also be set manually as follows. The important bit to note here
is the use of the Nfdc command
"""
- links = {"a":["b", "c"], "b":["c"]}
+ links = {"a": ["b", "c"], "b": ["c"]}
nfdc_batches = dict()
+ info("Setting up routes and strategies...\n")
for first in links:
for second in links[first]:
host1 = ndn.net[first]
@@ -84,23 +85,24 @@
Nfdc.createFace(host1, interface_ip)
Nfdc.registerRoute(host1, PREFIX, interface_ip, cost=0)
Nfdc.setStrategy(host1, PREFIX, Nfdc.STRATEGY_ASF)
- sleep(1)
- debug(ndn.net["a"].cmd("nfdc face list"))
- debug(ndn.net["a"].cmd("nfdc fib list"))
- debug(ndn.net["a"].cmd("nfdc strategy show /example"))
+ sleep(1)
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
# Start ping server
info("Starting pings...\n")
- pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
- getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
+ pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w")
+ getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log,\
stderr=pingserver_log)
# start ping client
- ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
ping1.wait()
printOutput(ping1.stdout.read())
- links = {"a":["b", "c"], "b":["c"]}
+ info("Bringing down routes and strategies...\n")
+ links = {"a": ["b", "c"], "b": ["c"]}
for first in links:
for second in links[first]:
host1 = ndn.net[first]
@@ -111,11 +113,11 @@
Nfdc.destroyFace(host1, interface_ip)
Nfdc.unsetStrategy(host1, PREFIX)
sleep(1)
- debug(ndn.net["a"].cmd("nfdc face list"))
- debug(ndn.net["a"].cmd("nfdc fib list"))
- debug(ndn.net["a"].cmd("nfdc strategy show /example"))
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
- ping2 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping2 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
ping2.wait()
printOutput(ping2.stdout.read())
@@ -153,7 +155,8 @@
It can also be set manually as follows. The important bit to note here
is the use of the Nfdc command
"""
- links = {"a":["b", "c"], "b":["c"]}
+ info("Setting up routes and strategies...\n")
+ links = {"a": ["b", "c"], "b": ["c"]}
nfdc_batches = dict()
for first in links:
for second in links[first]:
@@ -165,22 +168,24 @@
Nfdc.createFace(host1, interface_addr, protocol=Nfdc.PROTOCOL_ETHER, localInterface=sender_interface)
Nfdc.registerRoute(host1, PREFIX, interface_addr, cost=0, protocol=Nfdc.PROTOCOL_ETHER)
Nfdc.setStrategy(host1, PREFIX, Nfdc.STRATEGY_ASF)
- sleep(1)
- debug(ndn.net["a"].cmd("nfdc face list"))
- debug(ndn.net["a"].cmd("nfdc fib list"))
- debug(ndn.net["a"].cmd("nfdc strategy show /example"))
+ sleep(1)
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
# Start ping server
info("Starting pings...\n")
- pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
- getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
+ pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w")
+ getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log,\
stderr=pingserver_log)
# start ping client
- ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
ping1.wait()
printOutput(ping1.stdout.read())
+ info("Bringing down routes and strategies...\n")
+
links = {"a":["b", "c"], "b":["c"]}
for first in links:
for second in links[first]:
@@ -192,11 +197,11 @@
Nfdc.destroyFace(host1, interface_addr, protocol=Nfdc.PROTOCOL_ETHER)
Nfdc.unsetStrategy(host1, PREFIX)
sleep(1)
- debug(ndn.net["a"].cmd("nfdc face list"))
- debug(ndn.net["a"].cmd("nfdc fib list"))
- debug(ndn.net["a"].cmd("nfdc strategy show /example"))
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
- ping2 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping2 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
ping2.wait()
printOutput(ping2.stdout.read())
@@ -234,6 +239,10 @@
Experiment.startPctPings(ndn.net, 60)
sleep(70)
+
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
ndn.stop()
@@ -267,6 +276,10 @@
Experiment.startPctPings(ndn.net, 60)
sleep(70)
+
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
ndn.stop()
@@ -311,18 +324,18 @@
info('Route addition to NFD completed succesfully\n')
- debug(ndn.net["a"].cmd("nfdc face list"))
- debug(ndn.net["a"].cmd("nfdc fib list"))
- debug(ndn.net["a"].cmd("nfdc strategy show /example"))
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
# Start ping server
info("Starting pings...\n")
- pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
- getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
+ pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w")
+ getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log,\
stderr=pingserver_log)
# start ping client
- ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
ping1.wait()
printOutput(ping1.stdout.read())
@@ -369,28 +382,34 @@
info('Route addition to NFD completed succesfully\n')
- debug(ndn.net["a"].cmd("nfdc face list"))
- debug(ndn.net["a"].cmd("nfdc fib list"))
- debug(ndn.net["a"].cmd("nfdc strategy show /example"))
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
# Start ping server
info("Starting pings...\n")
- pingserver_log = open("{}/c/ndnpingserver.log".format(ndn.workDir), "w")
- getPopen(ndn.net["c"], "ndnpingserver {}".format(PREFIX), stdout=pingserver_log,\
+ pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w")
+ getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log,\
stderr=pingserver_log)
# start ping client
- ping1 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
ping1.wait()
printOutput(ping1.stdout.read())
ndn.stop()
if __name__ == '__main__':
- setLogLevel("debug")
+ setLogLevel("info")
+ info("\n\nUDP FACES\n")
udp_run()
+ info("\n\nETHERNET FACES\n")
eth_run()
+ info("\n\nNLSR WITH UDP FACES\n")
udp_nlsr_run()
+ info("\n\nNLSR WITH ETHERNET FACES\n")
eth_nlsr_run()
+ info("\n\nSTATIC ROUTING HELPER WITH UDP FACES\n")
udp_static_run()
+ info("\n\nSTATIC ROUTING HELPER WITH ETHERNET FACES\n")
eth_static_run()
\ No newline at end of file
diff --git a/examples/demos_and_tests/nfdc_batch_example.py b/examples/demos_and_tests/nfdc_batch_example.py
new file mode 100644
index 0000000..ea002cb
--- /dev/null
+++ b/examples/demos_and_tests/nfdc_batch_example.py
@@ -0,0 +1,131 @@
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2015-2024, The University of Memphis,
+# Arizona Board of Regents,
+# Regents of the University of California.
+#
+# This file is part of Mini-NDN.
+# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
+#
+# Mini-NDN is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Mini-NDN is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Mini-NDN, e.g., in COPYING.md file.
+# If not, see <http://www.gnu.org/licenses/>.
+
+from subprocess import PIPE
+from time import sleep
+
+from mininet.log import setLogLevel, info, debug
+from mininet.topo import Topo
+
+from minindn.minindn import Minindn
+from minindn.apps.app_manager import AppManager
+from minindn.util import MiniNDNCLI, getPopen
+from minindn.apps.nfd import Nfd
+from minindn.helpers.nfdc import Nfdc, NfdcBatch
+
+PREFIX = "/example"
+
+def printOutput(output):
+ _out = output.decode("utf-8").split("\n")
+ for _line in _out:
+ info(_line + "\n")
+
+def run():
+ Minindn.cleanUp()
+ Minindn.verifyDependencies()
+
+ # Topology can be created/modified using Mininet topo object
+ topo = Topo()
+ info("Setup\n")
+ # add hosts
+ a = topo.addHost('a')
+ b = topo.addHost('b')
+ c = topo.addHost('c')
+
+ # add links
+ topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
+ topo.addLink(b, c, delay='10ms', bw=10)
+ topo.addLink(a, c, delay='10ms', bw=10)
+
+ ndn = Minindn(topo=topo)
+ ndn.start()
+
+ # configure and start nfd on each node
+ info("Configuring NFD\n")
+ AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG")
+
+ info("Setting up routes and strategies...\n")
+ links = {"a": ["b", "c"], "b": ["c"]}
+ nfdc_batches = dict()
+ for first in links:
+ nfdc_batches[first] = NfdcBatch()
+ batch = nfdc_batches[first]
+ for second in links[first]:
+ host1 = ndn.net[first]
+ host2 = ndn.net[second]
+ interface = host2.connectionsTo(host1)[0][0]
+ interface_ip = interface.IP()
+ # Nfdc.createFace(host1, interface_ip)
+ batch.createFace(interface_ip)
+ batch.registerRoute(PREFIX, interface_ip, cost=0)
+ batch.setStrategy(PREFIX, Nfdc.STRATEGY_ASF)
+ for node in nfdc_batches:
+ nfdc_batches[node].executeBatch(ndn.net[node])
+ sleep(1)
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
+
+ # Start ping server
+ info("Starting pings...\n")
+ pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w")
+ getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log,
+ stderr=pingserver_log)
+
+ # start ping client
+ ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
+ ping1.wait()
+ printOutput(ping1.stdout.read())
+
+ info("Bringing down routes and strategies...\n")
+ links = {"a": ["b", "c"], "b": ["c"]}
+ nfdc_batches = dict()
+ for first in links:
+ nfdc_batches[first] = NfdcBatch()
+ batch = nfdc_batches[first]
+ for second in links[first]:
+ host1 = ndn.net[first]
+ host2 = ndn.net[second]
+ interface = host2.connectionsTo(host1)[0][0]
+ interface_ip = interface.IP()
+ batch.unregisterRoute(PREFIX, interface_ip)
+ batch.destroyFace(interface_ip)
+ batch.unsetStrategy(PREFIX)
+ for node in nfdc_batches:
+ nfdc_batches[node].executeBatch(ndn.net[node])
+ sleep(1)
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
+
+ ping2 = getPopen(ndn.net["a"], "ndnping {} -c 5".format(PREFIX), stdout=PIPE, stderr=PIPE)
+ ping2.wait()
+ printOutput(ping2.stdout.read())
+
+ info("\nExperiment Completed!\n")
+ # MiniNDNCLI(ndn.net)
+ ndn.stop()
+
+if __name__ == '__main__':
+ setLogLevel("info")
+ run()
\ No newline at end of file
diff --git a/examples/demos_and_tests/nfdc_example.py b/examples/demos_and_tests/nfdc_example.py
new file mode 100644
index 0000000..baf1a45
--- /dev/null
+++ b/examples/demos_and_tests/nfdc_example.py
@@ -0,0 +1,119 @@
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2015-2024, The University of Memphis,
+# Arizona Board of Regents,
+# Regents of the University of California.
+#
+# This file is part of Mini-NDN.
+# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
+#
+# Mini-NDN is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Mini-NDN is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Mini-NDN, e.g., in COPYING.md file.
+# If not, see <http://www.gnu.org/licenses/>.
+
+from subprocess import PIPE
+from time import sleep
+
+from mininet.log import setLogLevel, info, debug
+from mininet.topo import Topo
+
+from minindn.minindn import Minindn
+from minindn.apps.app_manager import AppManager
+from minindn.util import MiniNDNCLI, getPopen
+from minindn.apps.nfd import Nfd
+from minindn.helpers.nfdc import Nfdc, NfdcBatch
+
+PREFIX = "/example"
+
+def printOutput(output):
+ _out = output.decode("utf-8").split("\n")
+ for _line in _out:
+ info(_line + "\n")
+
+def run():
+ Minindn.cleanUp()
+ Minindn.verifyDependencies()
+
+ # Topology can be created/modified using Mininet topo object
+ topo = Topo()
+ info("Setup\n")
+ # add hosts
+ a = topo.addHost('a')
+ b = topo.addHost('b')
+ c = topo.addHost('c')
+
+ # add links
+ topo.addLink(a, b, delay='10ms', bw=10) # bw = bandwidth
+ topo.addLink(b, c, delay='10ms', bw=10)
+ topo.addLink(a, c, delay='10ms', bw=10)
+
+ ndn = Minindn(topo=topo)
+ ndn.start()
+
+ # configure and start nfd on each node
+ info("Configuring NFD\n")
+ AppManager(ndn, ndn.net.hosts, Nfd, logLevel="DEBUG")
+
+ info("Setting up routes and strategies...\n")
+ links = {"a": ["b", "c"], "b": ["c"]}
+ for first in links:
+ for second in links[first]:
+ host1 = ndn.net[first]
+ host2 = ndn.net[second]
+ interface = host2.connectionsTo(host1)[0][0]
+ interface_ip = interface.IP()
+ # Nfdc.createFace(host1, interface_ip)
+ Nfdc.createFace(host1, interface_ip)
+ Nfdc.registerRoute(host1, PREFIX, interface_ip, cost=0)
+ Nfdc.setStrategy(host1, PREFIX, Nfdc.STRATEGY_ASF)
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
+
+ # Start ping server
+ info("Starting pings...\n")
+ pingserver_log = open(f"{ndn.workDir}/c/ndnpingserver.log", "w")
+ getPopen(ndn.net["c"], f"ndnpingserver {PREFIX}", stdout=pingserver_log,
+ stderr=pingserver_log)
+
+ # start ping client
+ ping1 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
+ ping1.wait()
+ printOutput(ping1.stdout.read())
+
+ info("Bringing down routes and strategies...\n")
+ links = {"a": ["b", "c"], "b": ["c"]}
+ for first in links:
+ for second in links[first]:
+ host1 = ndn.net[first]
+ host2 = ndn.net[second]
+ interface = host2.connectionsTo(host1)[0][0]
+ interface_ip = interface.IP()
+ Nfdc.unregisterRoute(host1, PREFIX, interface_ip)
+ Nfdc.destroyFace(host1, interface_ip)
+ Nfdc.unsetStrategy(host1, PREFIX)
+ info(ndn.net["a"].cmd("nfdc face list"))
+ info(ndn.net["a"].cmd("nfdc fib list"))
+ info(ndn.net["a"].cmd("nfdc strategy show /example"))
+
+ ping2 = getPopen(ndn.net["a"], f"ndnping {PREFIX} -c 5", stdout=PIPE, stderr=PIPE)
+ ping2.wait()
+ printOutput(ping2.stdout.read())
+
+ info("\nExperiment Completed!\n")
+ # MiniNDNCLI(ndn.net)
+ ndn.stop()
+
+if __name__ == '__main__':
+ setLogLevel("info")
+ run()
\ No newline at end of file