blob: 2d38530a2f11933046fbe1a198fb8482fbed9ecb [file] [log] [blame]
Alexander Lane6f7a64f2018-05-17 15:01:14 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015-2018, The University of Memphis,
4# Arizona Board of Regents,
5# Regents of the University of California.
6#
7# This file is part of Mini-NDN.
8# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
9#
10# Mini-NDN is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# Mini-NDN is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with Mini-NDN, e.g., in COPYING.md file.
22# If not, see <http://www.gnu.org/licenses/>.
23
24import time
25
26class Nfdc:
27 STRATEGY_ASF = "asf"
28 STRATEGY_BEST_ROUTE = "best-route"
29 STRATEGY_MULTICAST = "multicast"
30 STRATEGY_NCC = "ncc"
31
32 @staticmethod
33 def registerRoute(node, namePrefix, remoteNode, origin=255, cost=0,
34 inheritFlag=True, captureFlag=False, expirationInMillis=0):
35 node.cmd("nfdc route add {} {} {} {} {}{}{}").format(
36 namePrefix,
37 remoteNode,
38 origin,
39 cost,
40 "no-inherit " if not inheritFlag else "",
41 "capture " if captureFlag else "",
42 "expires {}".format(expirationInMillis)
43 )
44 time.sleep(0.5)
45
46 @staticmethod
47 def unregisterRoute(node, namePrefix, remoteNode, origin=255):
48 node.cmd("nfdc route remove {} {} {}".format(namePrefix, remoteNode, origin))
49 time.sleep(0.5)
50
51 @staticmethod
52 def createFace(node, remoteNode, protocol="udp", isPermanent=False):
53 node.cmd("nfdc face create {}://{} {}".format(
54 protocol,
55 remoteNode,
56 "permanent" if isPermanent else "persistent"
57 ))
58 time.sleep(0.5)
59
60 @staticmethod
61 def destroyFace(node, remoteNode, protocol="udp"):
62 node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNode))
63 time.sleep(0.5)
64
65 @staticmethod
66 def setStrategy(node, namePrefix, strategy):
67 node.cmd("nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy))
68 time.sleep(0.5)
69
70 @staticmethod
71 def unsetStrategy(node, namePrefix):
72 node.cmd("nfdc strategy unset {}".format(namePrefix))
73 time.sleep(0.5)