blob: 0ed570d97038de4a3d848a3c9adbeac1d01b72de [file] [log] [blame]
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015-2017, 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
24from subprocess import call
Ashlesh Gawande95789cc2017-02-27 12:38:04 -060025from mininet.cli import CLI
26import sys
Alexander Lane4fa88812018-05-23 12:56:52 -050027from os.path import isfile
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050028
29sshbase = [ 'ssh', '-q', '-t', '-i/home/mininet/.ssh/id_rsa' ]
30scpbase = [ 'scp', '-i', '/home/mininet/.ssh/id_rsa' ]
31devnull = open('/dev/null', 'w')
32
33def ssh(login, cmd):
34 rcmd = sshbase + [login, cmd]
35 call(rcmd, stdout=devnull, stderr=devnull)
36
37def scp(*args):
38 tmp = []
39 for arg in args:
40 tmp.append(arg)
41 rcmd = scpbase + tmp
42 call(rcmd, stdout=devnull, stderr=devnull)
Ashlesh Gawande95789cc2017-02-27 12:38:04 -060043
Alexander Lane4fa88812018-05-23 12:56:52 -050044def copyExistentFile(node, fileList, destination):
45 for file in fileList:
46 if isfile(file):
47 node.cmd("cp {} {}".format(file, destination))
48 break
49 if not isfile(destination):
50 fileName = destination.split("/")[-1]
51 raise IOError("{} not found in expected directory.".format(fileName))
52
53
Ashlesh Gawande95789cc2017-02-27 12:38:04 -060054class MiniNDNCLI(CLI):
55 prompt = 'mini-ndn> '
56 def __init__(self, mininet, stdin=sys.stdin, script=None):
57 CLI.__init__(self, mininet, stdin=sys.stdin, script=None)