blob: ab96f129b27c9e14d3c0433c80abf8cb73c45806 [file] [log] [blame]
Shudong Zhoudc276ae2012-10-15 16:02:56 -07001"""
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
Shudong Zhoudc276ae2012-10-15 16:02:56 -070010import oftest.base_tests as base_tests
11
12from oftest.testutils import *
13
Rich Lanecb816fd2013-03-26 21:53:47 -070014NX_ROLE_OTHER = 0
15NX_ROLE_MASTER = 1
16NX_ROLE_SLAVE = 2
Shudong Zhoudc276ae2012-10-15 16:02:56 -070017
Rich Lanecb816fd2013-03-26 21:53:47 -070018class AnyReply(base_tests.SimpleDataPlane):
Shudong Zhoudc276ae2012-10-15 16:02:56 -070019 """
Rich Lanecb816fd2013-03-26 21:53:47 -070020 Verify that a role request gets either a role reply or an error.
Shudong Zhoudc276ae2012-10-15 16:02:56 -070021
Rich Lanecb816fd2013-03-26 21:53:47 -070022 This test should pass on any switch, no matter whether it implements
23 the extension.
24 """
Shudong Zhoudc276ae2012-10-15 16:02:56 -070025 def runTest(self):
Rich Lane4b601452013-03-11 23:37:06 -070026 request = ofp.message.nicira_controller_role_request(role=NX_ROLE_MASTER)
Shudong Zhoudc276ae2012-10-15 16:02:56 -070027 response, pkt = self.controller.transact(request)
28 self.assertTrue(response is not None, "No reply to Nicira role request")
Rich Lanecb816fd2013-03-26 21:53:47 -070029 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")