blob: 4b28a64c4d90738fc8431cd7f671b0f688307ff4 [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,
Alexander Lane6f7a64f2018-05-17 15:01:14 -050038 inheritFlag=True, captureFlag=False, expirationInMillis=0):
dulalsaurab2b899532018-10-25 18:02:15 +000039 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 "",
47 "expires {}".format(expirationInMillis)
48 )
dulalsaurab2b899532018-10-25 18:02:15 +000049 debug(node.cmd(cmd))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050050 time.sleep(0.5)
51
52 @staticmethod
53 def unregisterRoute(node, namePrefix, remoteNode, origin=255):
dulalsaurab2b899532018-10-25 18:02:15 +000054 cmd = "nfdc route remove {} {} {}".format(namePrefix, remoteNode, origin)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050055 time.sleep(0.5)
56
57 @staticmethod
58 def createFace(node, remoteNode, protocol="udp", isPermanent=False):
dulalsaurab2b899532018-10-25 18:02:15 +000059 cmd = ("nfdc face create {}://{} {}".format(
Alexander Lane6f7a64f2018-05-17 15:01:14 -050060 protocol,
61 remoteNode,
62 "permanent" if isPermanent else "persistent"
63 ))
dulalsaurab2b899532018-10-25 18:02:15 +000064 debug(node.cmd(cmd))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050065 time.sleep(0.5)
66
67 @staticmethod
68 def destroyFace(node, remoteNode, protocol="udp"):
dulalsaurab2b899532018-10-25 18:02:15 +000069 debug(node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNode)))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050070 time.sleep(0.5)
71
72 @staticmethod
73 def setStrategy(node, namePrefix, strategy):
dulalsaurab2b899532018-10-25 18:02:15 +000074 cmd = "nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy)
75 debug(node.cmd(cmd))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050076 time.sleep(0.5)
77
78 @staticmethod
79 def unsetStrategy(node, namePrefix):
dulalsaurab2b899532018-10-25 18:02:15 +000080 debug(node.cmd("nfdc strategy unset {}".format(namePrefix)))
Alexander Lane6f7a64f2018-05-17 15:01:14 -050081 time.sleep(0.5)