Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [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 |
Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [diff] [blame] | 10 | import oftest.base_tests as base_tests |
| 11 | |
| 12 | from oftest.testutils import * |
| 13 | |
Rich Lane | cb816fd | 2013-03-26 21:53:47 -0700 | [diff] [blame^] | 14 | NX_ROLE_OTHER = 0 |
| 15 | NX_ROLE_MASTER = 1 |
| 16 | NX_ROLE_SLAVE = 2 |
Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [diff] [blame] | 17 | |
Rich Lane | cb816fd | 2013-03-26 21:53:47 -0700 | [diff] [blame^] | 18 | class AnyReply(base_tests.SimpleDataPlane): |
Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [diff] [blame] | 19 | """ |
Rich Lane | cb816fd | 2013-03-26 21:53:47 -0700 | [diff] [blame^] | 20 | Verify that a role request gets either a role reply or an error. |
Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [diff] [blame] | 21 | |
Rich Lane | cb816fd | 2013-03-26 21:53:47 -0700 | [diff] [blame^] | 22 | This test should pass on any switch, no matter whether it implements |
| 23 | the extension. |
| 24 | """ |
Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [diff] [blame] | 25 | def runTest(self): |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 26 | request = ofp.message.nicira_controller_role_request(role=NX_ROLE_MASTER) |
Shudong Zhou | dc276ae | 2012-10-15 16:02:56 -0700 | [diff] [blame] | 27 | response, pkt = self.controller.transact(request) |
| 28 | self.assertTrue(response is not None, "No reply to Nicira role request") |
Rich Lane | cb816fd | 2013-03-26 21:53:47 -0700 | [diff] [blame^] | 29 | if isinstance(response, ofp.message.nicira_controller_role_reply): |
| 30 | logging.info("Role reply received") |
| 31 | logging.info(response.show()) |
| 32 | self.assertEquals(response.role, NX_ROLE_MASTER) |
| 33 | elif isinstance(response, ofp.message.error_msg): |
| 34 | logging.info("Error message received") |
| 35 | logging.info(response.show()) |
| 36 | self.assertEquals(response.err_type, ofp.OFPET_BAD_REQUEST) |
| 37 | self.assertEquals(response.code, ofp.OFPBRC_BAD_VENDOR) |
| 38 | else: |
| 39 | raise AssertionError("Unexpected reply type") |