blob: 8886c8014e33f40aeded2f77d989294a09d9ddd4 [file] [log] [blame]
Ed Swierk277875a2013-01-08 15:13:46 -08001"""
2"""
3import struct
4
5import logging
6
7from oftest import config
8import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -08009import ofp
Ed Swierk277875a2013-01-08 15:13:46 -080010import oftest.base_tests as base_tests
11
12from oftest.testutils import *
13
14@nonstandard
15class BSNShellCommand(base_tests.SimpleDataPlane):
16 """
17 Exercise BSN vendor extension for running a shell command on the switch
18 """
19
20 def bsn_shell_command(self, cmd):
21 """
22 Use the BSN_SHELL_COMMAND vendor command to run the given command
23 and receive the output
24 """
Rich Lane28fa9272013-03-08 16:00:25 -080025 m = ofp.message.vendor()
Ed Swierk277875a2013-01-08 15:13:46 -080026 m.vendor = 0x005c16c7
27 m.data = struct.pack("!LL", 6, 0) + cmd
28 rc = self.controller.message_send(m)
29 self.assertNotEqual(rc, -1, "Error sending shell command")
30 out = ""
31 while True:
32 m, r = self.controller.poll(ofp.OFPT_VENDOR, 60)
33 self.assertEqual(m.vendor, 0x005c16c7, "Wrong vendor ID")
34 subtype = struct.unpack("!L", m.data[:4])[0]
35 if subtype == 7:
36 out += m.data[4:]
37 elif subtype == 8:
38 status = struct.unpack("!LL", m.data)[1]
39 return status, out
40 else:
41 assert False, "Wrong subtype"
42
43 def runTest(self):
44 status, out = self.bsn_shell_command("echo _one space_")
45 self.assertEqual(status, 0, "Shell command returned %s != 0" % status)
46 self.assertEqual(out, "_one space_\n", "Shell command output: '%r'" % out)