Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 3 | # Copyright (C) 2015-2019, The University of Memphis, |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 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 | |
| 24 | import time |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 25 | from mininet.log import debug |
| 26 | |
| 27 | SLEEP_TIME = 0.2 |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 28 | |
| 29 | class Nfdc: |
| 30 | STRATEGY_ASF = "asf" |
| 31 | STRATEGY_BEST_ROUTE = "best-route" |
| 32 | STRATEGY_MULTICAST = "multicast" |
| 33 | STRATEGY_NCC = "ncc" |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 34 | PROTOCOL_UDP = "udp" |
| 35 | PROTOCOL_TCP = "tcp" |
| 36 | PROTOCOL_ETHER = "ether" |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 37 | |
| 38 | @staticmethod |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 39 | def registerRoute(node, namePrefix, remoteNodeAddress, protocol=PROTOCOL_UDP, origin=255, |
| 40 | cost=0, inheritFlag=True, captureFlag=False, expirationInMillis=None): |
dulalsaurab | 50778df | 2018-12-20 20:06:15 +0000 | [diff] [blame] | 41 | cmd = ("nfdc route add {} {}://{} origin {} cost {} {}{}").format( |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 42 | namePrefix, |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 43 | protocol, |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 44 | remoteNodeAddress, |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 45 | origin, |
| 46 | cost, |
| 47 | "no-inherit " if not inheritFlag else "", |
| 48 | "capture " if captureFlag else "", |
dulalsaurab | 50778df | 2018-12-20 20:06:15 +0000 | [diff] [blame] | 49 | "expires {}".format(expirationInMillis) if expirationInMillis else "" |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 50 | ) |
dulalsaurab | 50778df | 2018-12-20 20:06:15 +0000 | [diff] [blame] | 51 | |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 52 | debug(node.cmd(cmd)) |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 53 | time.sleep(SLEEP_TIME) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 54 | |
| 55 | @staticmethod |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 56 | def unregisterRoute(node, namePrefix, remoteNodeAddress, origin=255): |
| 57 | cmd = "nfdc route remove {} {} {}".format(namePrefix, remoteNodeAddress, origin) |
dulalsaurab | 0dcdb32 | 2018-08-15 20:39:07 +0000 | [diff] [blame] | 58 | debug(node.cmd(cmd)) |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 59 | time.sleep(SLEEP_TIME) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 60 | |
| 61 | @staticmethod |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 62 | def createFace(node, remoteNodeAddress, protocol="udp", isPermanent=False): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 63 | cmd = ("nfdc face create {}://{} {}".format( |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 64 | protocol, |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 65 | remoteNodeAddress, |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 66 | "permanent" if isPermanent else "persistent" |
| 67 | )) |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 68 | debug(node.cmd(cmd)) |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 69 | time.sleep(SLEEP_TIME) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 70 | |
| 71 | @staticmethod |
Ashlesh Gawande | 6651a74 | 2019-01-03 18:13:06 -0600 | [diff] [blame] | 72 | def destroyFace(node, remoteNodeAddress, protocol="udp"): |
| 73 | debug(node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNodeAddress))) |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 74 | time.sleep(SLEEP_TIME) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 75 | |
| 76 | @staticmethod |
| 77 | def setStrategy(node, namePrefix, strategy): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 78 | cmd = "nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy) |
| 79 | debug(node.cmd(cmd)) |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 80 | time.sleep(SLEEP_TIME) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 81 | |
| 82 | @staticmethod |
| 83 | def unsetStrategy(node, namePrefix): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 84 | debug(node.cmd("nfdc strategy unset {}".format(namePrefix))) |
Saurab Dulal | 8ae870a | 2018-07-31 05:17:49 +0000 | [diff] [blame^] | 85 | time.sleep(SLEEP_TIME) |