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, |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 38 | inheritFlag=True, captureFlag=False, expirationInMillis=0): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 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 "", |
| 47 | "expires {}".format(expirationInMillis) |
| 48 | ) |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 49 | debug(node.cmd(cmd)) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 50 | time.sleep(0.5) |
| 51 | |
| 52 | @staticmethod |
| 53 | def unregisterRoute(node, namePrefix, remoteNode, origin=255): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 54 | cmd = "nfdc route remove {} {} {}".format(namePrefix, remoteNode, origin) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 55 | time.sleep(0.5) |
| 56 | |
| 57 | @staticmethod |
| 58 | def createFace(node, remoteNode, protocol="udp", isPermanent=False): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 59 | cmd = ("nfdc face create {}://{} {}".format( |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 60 | protocol, |
| 61 | remoteNode, |
| 62 | "permanent" if isPermanent else "persistent" |
| 63 | )) |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 64 | debug(node.cmd(cmd)) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 65 | time.sleep(0.5) |
| 66 | |
| 67 | @staticmethod |
| 68 | def destroyFace(node, remoteNode, protocol="udp"): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 69 | debug(node.cmd("nfdc face destroy {}://{}".format(protocol, remoteNode))) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 70 | time.sleep(0.5) |
| 71 | |
| 72 | @staticmethod |
| 73 | def setStrategy(node, namePrefix, strategy): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 74 | cmd = "nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(namePrefix, strategy) |
| 75 | debug(node.cmd(cmd)) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 76 | time.sleep(0.5) |
| 77 | |
| 78 | @staticmethod |
| 79 | def unsetStrategy(node, namePrefix): |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 80 | debug(node.cmd("nfdc strategy unset {}".format(namePrefix))) |
Alexander Lane | 6f7a64f | 2018-05-17 15:01:14 -0500 | [diff] [blame] | 81 | time.sleep(0.5) |