Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 3 | # Copyright (C) 2015-2017, The University of Memphis, |
Ashlesh Gawande | 0cccdb8 | 2016-08-15 12:58:06 -0500 | [diff] [blame] | 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 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 | # This file incorporates work covered by the following copyright and |
| 25 | # permission notice: |
| 26 | # |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 27 | # Mininet 2.3.0d1 License |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 28 | # |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 29 | # Copyright (c) 2013-2016 Open Networking Laboratory |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 30 | # Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of |
| 31 | # The Leland Stanford Junior University |
| 32 | # |
| 33 | # Original authors: Bob Lantz and Brandon Heller |
| 34 | # |
| 35 | # We are making Mininet available for public use and benefit with the |
| 36 | # expectation that others will use, modify and enhance the Software and |
| 37 | # contribute those enhancements back to the community. However, since we |
| 38 | # would like to make the Software available for broadest use, with as few |
| 39 | # restrictions as possible permission is hereby granted, free of charge, to |
| 40 | # any person obtaining a copy of this Software to deal in the Software |
| 41 | # under the copyrights without restriction, including without limitation |
| 42 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 43 | # and/or sell copies of the Software, and to permit persons to whom the |
| 44 | # Software is furnished to do so, subject to the following conditions: |
| 45 | # |
| 46 | # The above copyright notice and this permission notice shall be included |
| 47 | # in all copies or substantial portions of the Software. |
| 48 | # |
| 49 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 50 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 51 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 52 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 53 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 54 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 55 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 56 | # |
| 57 | # The name and trademarks of copyright holder(s) may NOT be used in |
| 58 | # advertising or publicity pertaining to the Software or any derivatives |
| 59 | # without specific, written prior permission. |
| 60 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 61 | from mininet.node import CPULimitedHost, Host, Node |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 62 | from mininet.examples.cluster import RemoteMixin |
| 63 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 64 | from ndn.nfd import Nfd |
| 65 | |
| 66 | class NdnHostCommon(): |
| 67 | "Common methods of NdnHost and CpuLimitedNdnHost" |
| 68 | |
| 69 | def configNdn(self): |
| 70 | self.buildPeerIp() |
| 71 | |
| 72 | def buildPeerIp(self): |
| 73 | for iface in self.intfList(): |
| 74 | link = iface.link |
| 75 | if link: |
| 76 | node1, node2 = link.intf1.node, link.intf2.node |
| 77 | if node1 == self: |
| 78 | self.peerList[node2.name] = link.intf2.node.IP(link.intf2) |
| 79 | else: |
| 80 | self.peerList[node1.name] = link.intf1.node.IP(link.intf1) |
| 81 | |
| 82 | inited = False |
| 83 | |
| 84 | @classmethod |
| 85 | def init(cls): |
| 86 | "Initialization for NDNHost class" |
| 87 | cls.inited = True |
| 88 | |
| 89 | class NdnHost(Host, NdnHostCommon): |
| 90 | "NDNHost is a Host that always runs NFD" |
| 91 | |
| 92 | def __init__(self, name, **kwargs): |
| 93 | |
| 94 | Host.__init__(self, name, **kwargs) |
| 95 | if not NdnHost.inited: |
| 96 | NdnHostCommon.init() |
| 97 | |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 98 | # Create home directory for a node |
| 99 | self.homeFolder = "%s/%s" % (self.params['workdir'], self.name) |
| 100 | self.cmd("mkdir -p %s" % self.homeFolder) |
| 101 | self.cmd("cd %s" % self.homeFolder) |
| 102 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 103 | self.nfd = None |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 104 | |
| 105 | self.peerList = {} |
| 106 | |
Vince Lehman | c64dcb8 | 2015-10-21 16:04:09 -0500 | [diff] [blame] | 107 | def config(self, app=None, cache=None, **params): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 108 | |
| 109 | r = Node.config(self, **params) |
| 110 | |
Vince Lehman | c64dcb8 | 2015-10-21 16:04:09 -0500 | [diff] [blame] | 111 | self.setParam(r, 'app', app=app) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 112 | self.setParam(r, 'cache', cache=cache) |
| 113 | |
| 114 | return r |
| 115 | |
| 116 | def terminate(self): |
| 117 | "Stop node." |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 118 | if self.nfd is not None: |
| 119 | self.nfd.stop() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 120 | Host.terminate(self) |
| 121 | |
| 122 | class CpuLimitedNdnHost(CPULimitedHost, NdnHostCommon): |
| 123 | '''CPULimitedNDNHost is a Host that always runs NFD and extends CPULimitedHost. |
| 124 | It should be used when one wants to limit the resources of NDN routers and hosts ''' |
| 125 | |
| 126 | def __init__(self, name, sched='cfs', **kwargs): |
| 127 | |
| 128 | CPULimitedHost.__init__(self, name, sched, **kwargs) |
| 129 | if not NdnHost.inited: |
| 130 | NdnHostCommon.init() |
| 131 | |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 132 | # Create home directory for a node |
| 133 | self.homeFolder = "%s/%s" % (self.params['workdir'], self.name) |
| 134 | self.cmd("mkdir -p %s" % self.homeFolder) |
| 135 | self.cmd("cd %s" % self.homeFolder) |
| 136 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 137 | self.nfd = None |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 138 | |
| 139 | self.peerList = {} |
| 140 | |
Vince Lehman | c64dcb8 | 2015-10-21 16:04:09 -0500 | [diff] [blame] | 141 | def config(self, app=None, cpu=None, cores=None, cache=None, **params): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 142 | |
| 143 | r = CPULimitedHost.config(self,cpu,cores, **params) |
| 144 | |
Vince Lehman | c64dcb8 | 2015-10-21 16:04:09 -0500 | [diff] [blame] | 145 | self.setParam(r, 'app', app=app) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 146 | self.setParam(r, 'cache', cache=cache) |
| 147 | |
| 148 | return r |
| 149 | |
| 150 | def terminate(self): |
| 151 | "Stop node." |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 152 | if self.nfd is not None: |
| 153 | self.nfd.stop() |
| 154 | CPULimitedHost.terminate(self) |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 155 | |
| 156 | class RemoteNdnHost(RemoteMixin, NdnHost): |
| 157 | "A node on a remote server" |
| 158 | pass |