blob: 4a9ebf2274a8cbc45bcfcab1b5b804761d0970d6 [file] [log] [blame]
Alexander Lane6f7a64f2018-05-17 15:01:14 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Ashlesh Gawande6651a742019-01-03 18:13:06 -06003# Copyright (C) 2015-2019, The University of Memphis,
Alexander Lane6f7a64f2018-05-17 15:01:14 -05004# 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
Saurab Dulal8ae870a2018-07-31 05:17:49 +000024from mininet.log import debug
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050025from minindn.minindn import Minindn
Saurab Dulal8ae870a2018-07-31 05:17:49 +000026
27SLEEP_TIME = 0.2
Alexander Lane6f7a64f2018-05-17 15:01:14 -050028
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050029class Nfdc(object):
30 STRATEGY_ASF = 'asf'
31 STRATEGY_BEST_ROUTE = 'best-route'
32 STRATEGY_MULTICAST = 'multicast'
33 STRATEGY_NCC = 'ncc'
34 PROTOCOL_UDP = 'udp'
35 PROTOCOL_TCP = 'tcp'
36 PROTOCOL_ETHER = 'ether'
Alexander Lane6f7a64f2018-05-17 15:01:14 -050037
38 @staticmethod
Ashlesh Gawande6651a742019-01-03 18:13:06 -060039 def registerRoute(node, namePrefix, remoteNodeAddress, protocol=PROTOCOL_UDP, origin=255,
40 cost=0, inheritFlag=True, captureFlag=False, expirationInMillis=None):
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050041 cmd = ('nfdc route add {} {}://{} origin {} cost {} {}{}').format(
Alexander Lane6f7a64f2018-05-17 15:01:14 -050042 namePrefix,
dulalsaurab2b899532018-10-25 18:02:15 +000043 protocol,
Ashlesh Gawande6651a742019-01-03 18:13:06 -060044 remoteNodeAddress,
Alexander Lane6f7a64f2018-05-17 15:01:14 -050045 origin,
46 cost,
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050047 'no-inherit ' if not inheritFlag else '',
48 'capture ' if captureFlag else '',
49 'expires {}'.format(expirationInMillis) if expirationInMillis else ''
Alexander Lane6f7a64f2018-05-17 15:01:14 -050050 )
dulalsaurab50778df2018-12-20 20:06:15 +000051
dulalsaurab2b899532018-10-25 18:02:15 +000052 debug(node.cmd(cmd))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050053 Minindn.sleep(SLEEP_TIME)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050054
55 @staticmethod
Ashlesh Gawande6651a742019-01-03 18:13:06 -060056 def unregisterRoute(node, namePrefix, remoteNodeAddress, origin=255):
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050057 cmd = 'nfdc route remove {} {} {}'.format(namePrefix, remoteNodeAddress, origin)
dulalsaurab0dcdb322018-08-15 20:39:07 +000058 debug(node.cmd(cmd))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050059 Minindn.sleep(SLEEP_TIME)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050060
61 @staticmethod
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050062 def createFace(node, remoteNodeAddress, protocol='udp', isPermanent=False):
63 cmd = ('nfdc face create {}://{} {}'.format(
Alexander Lane6f7a64f2018-05-17 15:01:14 -050064 protocol,
Ashlesh Gawande6651a742019-01-03 18:13:06 -060065 remoteNodeAddress,
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050066 'permanent' if isPermanent else 'persistent'
Alexander Lane6f7a64f2018-05-17 15:01:14 -050067 ))
dulalsaurab2b899532018-10-25 18:02:15 +000068 debug(node.cmd(cmd))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050069 Minindn.sleep(SLEEP_TIME)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050070
71 @staticmethod
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050072 def destroyFace(node, remoteNodeAddress, protocol='udp'):
73 debug(node.cmd('nfdc face destroy {}://{}'.format(protocol, remoteNodeAddress)))
74 Minindn.sleep(SLEEP_TIME)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050075
76 @staticmethod
77 def setStrategy(node, namePrefix, strategy):
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050078 cmd = 'nfdc strategy set {} ndn:/localhost/nfd/strategy/{}'.format(namePrefix, strategy)
dulalsaurab2b899532018-10-25 18:02:15 +000079 debug(node.cmd(cmd))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050080 Minindn.sleep(SLEEP_TIME)
Alexander Lane6f7a64f2018-05-17 15:01:14 -050081
82 @staticmethod
83 def unsetStrategy(node, namePrefix):
dulalsaurab2b899532018-10-25 18:02:15 +000084 debug(node.cmd("nfdc strategy unset {}".format(namePrefix)))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050085 Minindn.sleep(SLEEP_TIME)