blob: cc06ebe4634324770ae53d6b825fe2994b2fdebf [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.message as message
11import oftest.base_tests as base_tests
12
13from oftest.testutils import *
14
15@nonstandard
16class BSNShellCommand(base_tests.SimpleDataPlane):
17 """
18 Exercise BSN vendor extension for running a shell command on the switch
19 """
20
21 def bsn_shell_command(self, cmd):
22 """
23 Use the BSN_SHELL_COMMAND vendor command to run the given command
24 and receive the output
25 """
26 m = message.vendor()
27 m.vendor = 0x005c16c7
28 m.data = struct.pack("!LL", 6, 0) + cmd
29 rc = self.controller.message_send(m)
30 self.assertNotEqual(rc, -1, "Error sending shell command")
31 out = ""
32 while True:
33 m, r = self.controller.poll(ofp.OFPT_VENDOR, 60)
34 self.assertEqual(m.vendor, 0x005c16c7, "Wrong vendor ID")
35 subtype = struct.unpack("!L", m.data[:4])[0]
36 if subtype == 7:
37 out += m.data[4:]
38 elif subtype == 8:
39 status = struct.unpack("!LL", m.data)[1]
40 return status, out
41 else:
42 assert False, "Wrong subtype"
43
44 def runTest(self):
45 status, out = self.bsn_shell_command("echo _one space_")
46 self.assertEqual(status, 0, "Shell command returned %s != 0" % status)
47 self.assertEqual(out, "_one space_\n", "Shell command output: '%r'" % out)