blob: 41d479f491b5cfb0f7a0b3fb6e3a46ea73e629d2 [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
dulalsaurab2b899532018-10-25 18:02:15 +000025from mininet.log import setLogLevel, output, info, debug
Alexander Lane6f7a64f2018-05-17 15:01:14 -050026
27class Nfdc:
28 STRATEGY_ASF = "asf"
29 STRATEGY_BEST_ROUTE = "best-route"
30 STRATEGY_MULTICAST = "multicast"
31 STRATEGY_NCC = "ncc"
dulalsaurab2b899532018-10-25 18:02:15 +000032 PROTOCOL_UDP = "udp"
33 PROTOCOL_TCP = "tcp"
34 PROTOCOL_ETHER = "ether"
Alexander Lane6f7a64f2018-05-17 15:01:14 -050035
36 @staticmethod
dulalsaurab2b899532018-10-25 18:02:15 +000037 def registerRoute(node, namePrefix, remoteNode, protocol=PROTOCOL_UDP, origin=255, cost=0,
dulalsaurab50778df2018-12-20 20:06:15 +000038 inheritFlag=True, captureFlag=False, expirationInMillis=None):
39 cmd = ("nfdc route add {} {}://{} origin {} cost {} {}{}").format(
Alexander Lane6f7a64f2018-05-17 15:01:14 -050040 namePrefix,
dulalsaurab2b899532018-10-25 18:02:15 +000041 protocol,
Alexander Lane6f7a64f2018-05-17 15:01:14 -050042 remoteNode,
43 origin,
44 cost,
45 "no-inherit " if not inheritFlag else "",
46 "capture " if captureFlag else "",
dulalsaurab50778df2018-12-20 20:06:15 +000047 "expires {}".format(expirationInMillis) if expirationInMillis else ""
Alexander Lane6f7a64f2018-05-17 15:01:14 -050048 )
dulalsaurab50778df2018-12-20 20:06:15 +000049
dulalsaurab2b899532018-10-25 18:02:15 +000050 debug(node.cmd(cmd))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050051 time.sleep(0.5)
52
53 @staticmethod
54 def unregisterRoute(node, namePrefix, remoteNode, origin=255):
dulalsaurab2b899532018-10-25 18:02:15 +000055 cmd = "nfdc route remove {} {} {}".format(namePrefix, remoteNode, origin)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050056 time.sleep(0.5)
57
58 @staticmethod
59 def createFace(node, remoteNode, protocol="udp", isPermanent=False):
dulalsaurab2b899532018-10-25 18:02:15 +000060 cmd = ("nfdc face create {}://{} {}".format(
Alexander Lane6f7a64f2018-05-17 15:01:14 -050061 protocol,
62 remoteNode,
63 "permanent" if isPermanent else "persistent"
64 ))
dulalsaurab2b899532018-10-25 18:02:15 +000065 debug(node.cmd(cmd))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050066 time.sleep(0.5)
67
68 @staticmethod
69 def destroyFace(node, remoteNode, protocol="udp"):
dulalsaurab2b899532018-10-25 18:02:15 +000070 debug(node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNode)))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050071 time.sleep(0.5)
72
73 @staticmethod
74 def setStrategy(node, namePrefix, strategy):
dulalsaurab2b899532018-10-25 18:02:15 +000075 cmd = "nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy)
76 debug(node.cmd(cmd))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050077 time.sleep(0.5)
78
79 @staticmethod
80 def unsetStrategy(node, namePrefix):
dulalsaurab2b899532018-10-25 18:02:15 +000081 debug(node.cmd("nfdc strategy unset {}".format(namePrefix)))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050082 time.sleep(0.5)