Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 1 | # -*- 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 | |
| 24 | import time |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 25 | from mininet.log import setLogLevel, output, info, debug |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 26 | |
| 27 | class Nfdc: |
| 28 | STRATEGY_ASF = "asf" |
| 29 | STRATEGY_BEST_ROUTE = "best-route" |
| 30 | STRATEGY_MULTICAST = "multicast" |
| 31 | STRATEGY_NCC = "ncc" |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 32 | PROTOCOL_UDP = "udp" |
| 33 | PROTOCOL_TCP = "tcp" |
| 34 | PROTOCOL_ETHER = "ether" |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 35 | |
| 36 | @staticmethod |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 37 | def registerRoute(node, namePrefix, remoteNode, protocol=PROTOCOL_UDP, origin=255, cost=0, |
dulalsaurab | 50778df | 2018-12-20 20:06:15 +0000 | [diff] [blame^] | 38 | inheritFlag=True, captureFlag=False, expirationInMillis=None): |
| 39 | cmd = ("nfdc route add {} {}://{} origin {} cost {} {}{}").format( |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 40 | namePrefix, |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 41 | protocol, |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 42 | remoteNode, |
| 43 | origin, |
| 44 | cost, |
| 45 | "no-inherit " if not inheritFlag else "", |
| 46 | "capture " if captureFlag else "", |
dulalsaurab | 50778df | 2018-12-20 20:06:15 +0000 | [diff] [blame^] | 47 | "expires {}".format(expirationInMillis) if expirationInMillis else "" |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 48 | ) |
dulalsaurab | 50778df | 2018-12-20 20:06:15 +0000 | [diff] [blame^] | 49 | |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 50 | debug(node.cmd(cmd)) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 51 | time.sleep(0.5) |
| 52 | |
| 53 | @staticmethod |
| 54 | def unregisterRoute(node, namePrefix, remoteNode, origin=255): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 55 | cmd = "nfdc route remove {} {} {}".format(namePrefix, remoteNode, origin) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 56 | time.sleep(0.5) |
| 57 | |
| 58 | @staticmethod |
| 59 | def createFace(node, remoteNode, protocol="udp", isPermanent=False): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 60 | cmd = ("nfdc face create {}://{} {}".format( |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 61 | protocol, |
| 62 | remoteNode, |
| 63 | "permanent" if isPermanent else "persistent" |
| 64 | )) |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 65 | debug(node.cmd(cmd)) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 66 | time.sleep(0.5) |
| 67 | |
| 68 | @staticmethod |
| 69 | def destroyFace(node, remoteNode, protocol="udp"): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 70 | debug(node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNode))) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 71 | time.sleep(0.5) |
| 72 | |
| 73 | @staticmethod |
| 74 | def setStrategy(node, namePrefix, strategy): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 75 | cmd = "nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy) |
| 76 | debug(node.cmd(cmd)) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 77 | time.sleep(0.5) |
| 78 | |
| 79 | @staticmethod |
| 80 | def unsetStrategy(node, namePrefix): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 81 | debug(node.cmd("nfdc strategy unset {}".format(namePrefix))) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 82 | time.sleep(0.5) |