ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 1 | from mininet.node import CPULimitedHost, Host, Node |
| 2 | from ndn.nfd import Nfd |
| 3 | |
| 4 | class NdnHostCommon(): |
| 5 | "Common methods of NdnHost and CpuLimitedNdnHost" |
| 6 | |
| 7 | def configNdn(self): |
| 8 | self.buildPeerIp() |
| 9 | |
| 10 | def buildPeerIp(self): |
| 11 | for iface in self.intfList(): |
| 12 | link = iface.link |
| 13 | if link: |
| 14 | node1, node2 = link.intf1.node, link.intf2.node |
| 15 | if node1 == self: |
| 16 | self.peerList[node2.name] = link.intf2.node.IP(link.intf2) |
| 17 | else: |
| 18 | self.peerList[node1.name] = link.intf1.node.IP(link.intf1) |
| 19 | |
| 20 | inited = False |
| 21 | |
| 22 | @classmethod |
| 23 | def init(cls): |
| 24 | "Initialization for NDNHost class" |
| 25 | cls.inited = True |
| 26 | |
| 27 | class NdnHost(Host, NdnHostCommon): |
| 28 | "NDNHost is a Host that always runs NFD" |
| 29 | |
| 30 | def __init__(self, name, **kwargs): |
| 31 | |
| 32 | Host.__init__(self, name, **kwargs) |
| 33 | if not NdnHost.inited: |
| 34 | NdnHostCommon.init() |
| 35 | |
| 36 | self.nfd = Nfd(self) |
| 37 | self.nfd.start() |
| 38 | |
| 39 | self.peerList = {} |
| 40 | |
| 41 | def config(self, fib=None, app=None, cache=None, **params): |
| 42 | |
| 43 | r = Node.config(self, **params) |
| 44 | |
| 45 | self.setParam(r, 'app', fib=fib) # why is this not app=app, to be investigated |
| 46 | self.setParam(r, 'fib', app=app) # and this fib=fib |
| 47 | self.setParam(r, 'cache', cache=cache) |
| 48 | |
| 49 | return r |
| 50 | |
| 51 | def terminate(self): |
| 52 | "Stop node." |
| 53 | self.nfd.stop() |
| 54 | Host.terminate(self) |
| 55 | |
| 56 | class CpuLimitedNdnHost(CPULimitedHost, NdnHostCommon): |
| 57 | '''CPULimitedNDNHost is a Host that always runs NFD and extends CPULimitedHost. |
| 58 | It should be used when one wants to limit the resources of NDN routers and hosts ''' |
| 59 | |
| 60 | def __init__(self, name, sched='cfs', **kwargs): |
| 61 | |
| 62 | CPULimitedHost.__init__(self, name, sched, **kwargs) |
| 63 | if not NdnHost.inited: |
| 64 | NdnHostCommon.init() |
| 65 | |
| 66 | self.nfd = Nfd(self) |
| 67 | self.nfd.start() |
| 68 | |
| 69 | self.peerList = {} |
| 70 | |
| 71 | def config(self, fib=None, app=None, cpu=None, cores=None, cache=None, **params): |
| 72 | |
| 73 | r = CPULimitedHost.config(self,cpu,cores, **params) |
| 74 | |
| 75 | self.setParam(r, 'app', fib=fib) #????? shoud it be app=app |
| 76 | self.setParam(r, 'fib', app=app) |
| 77 | self.setParam(r, 'cache', cache=cache) |
| 78 | |
| 79 | return r |
| 80 | |
| 81 | def terminate(self): |
| 82 | "Stop node." |
| 83 | self.nfd.stop() |
| 84 | Host.terminate(self) |