Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 1 | """ |
| 2 | """ |
| 3 | import struct |
| 4 | |
| 5 | import logging |
| 6 | |
| 7 | from oftest import config |
| 8 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame^] | 9 | import ofp |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 10 | import oftest.message as message |
| 11 | import oftest.base_tests as base_tests |
| 12 | |
| 13 | from oftest.testutils import * |
| 14 | |
| 15 | @nonstandard |
| 16 | class 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) |