Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame^] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
| 3 | # Copyright (C) 2015-2019, 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 | from mininet.node import Node |
| 25 | |
| 26 | class AppManager(object): |
| 27 | def __init__(self, minindn, hosts, cls, **appParams): |
| 28 | self.cls = cls |
| 29 | self.apps = [] |
| 30 | for host in hosts: |
| 31 | # Don't run NDN apps on switches |
| 32 | if isinstance(host, Node): |
| 33 | self.startOnNode(host, **appParams) |
| 34 | |
| 35 | minindn.cleanups.append(self.cleanup) |
| 36 | |
| 37 | def startOnNode(self, host, **appParams): |
| 38 | app = self.cls(host, **appParams) |
| 39 | app.start() |
| 40 | self.apps.append(app) |
| 41 | |
| 42 | def cleanup(self): |
| 43 | for app in self.apps: |
| 44 | app.stop() |
| 45 | |
| 46 | def __getitem__(self, nodeName): |
| 47 | for app in self.apps: |
| 48 | if app.node.name == nodeName: |
| 49 | return app |
| 50 | return None |
| 51 | |
| 52 | def __iter__(self): |
| 53 | return self.apps.__iter__() |
| 54 | |
| 55 | def __next__(self): |
| 56 | return self.apps.__next__() |