blob: 39a6ec3cf3e82de515d072744840600f9ca0fbe2 [file] [log] [blame]
Rich Lane0bd61022015-03-04 10:57:11 -08001"""
2Test the role status message
3"""
4import struct
5import unittest
6import logging
7
8import oftest
9from oftest import config
10import oftest.controller as controller
11import ofp
12import oftest.base_tests as base_tests
13
14from oftest.testutils import *
15
16def simple_role_request(test, role, gen=None, con=None):
17 """
18 Send a role request we expect to succeed
19 """
20 if con == None:
21 con = test.controller
22 request = ofp.message.role_request(role=role, generation_id=gen)
23 response, _ = con.transact(request)
24 test.assertTrue(isinstance(response, ofp.message.role_reply), "Expected a role reply")
25 if role != ofp.OFPCR_ROLE_NOCHANGE:
26 test.assertEquals(response.role, role)
27 if gen != None:
28 test.assertEquals(response.generation_id, gen)
29 return response.role, response.generation_id
30
31@disabled
32class RoleStatus(unittest.TestCase):
33 """
34 Verify that when a connection becomes a master the existing master is
35 downgraded to slave and receives a role-status message.
36
37 Requires the switch to attempt to connect in parallel to ports 6653
38 and 6753 on the configured IP.
39 """
40
41 def setUp(self):
42 host = config["controller_host"]
43 self.controllers = [
44 controller.Controller(host=host,port=6653),
45 controller.Controller(host=host,port=6753)
46 ]
47
48 def runTest(self):
49 # Connect and handshake with both controllers
50 for con in self.controllers:
51 con.start()
52 if not con.connect():
53 raise AssertionError("failed to connect controller %s" % str(con))
54 reply, _ = con.transact(ofp.message.features_request())
55 self.assertTrue(isinstance(reply, ofp.message.features_reply))
56
57 # Assert initial role and get generation IDs
58 role, gen0 = simple_role_request(self, ofp.OFPCR_ROLE_NOCHANGE, con=self.controllers[0])
59 self.assertEqual(role, ofp.OFPCR_ROLE_EQUAL)
60 role, gen1 = simple_role_request(self, ofp.OFPCR_ROLE_NOCHANGE, con=self.controllers[1])
61 self.assertEqual(role, ofp.OFPCR_ROLE_EQUAL)
62
63 # Initial role assignment: controller 0 is master, controller 1 is slave
64 simple_role_request(self, ofp.OFPCR_ROLE_MASTER, gen0, con=self.controllers[0])
65 simple_role_request(self, ofp.OFPCR_ROLE_SLAVE, gen1, con=self.controllers[1])
66 self.verify_role(self.controllers[0], ofp.OFPCR_ROLE_MASTER)
67 self.verify_role(self.controllers[1], ofp.OFPCR_ROLE_SLAVE)
68
69 # Controller 1 requests master
70 # Controller 0 becomes slave
71 simple_role_request(self, ofp.OFPCR_ROLE_MASTER, gen1, con=self.controllers[1])
72 self.verify_role(self.controllers[0], ofp.OFPCR_ROLE_SLAVE)
73 self.verify_role(self.controllers[1], ofp.OFPCR_ROLE_MASTER)
74
75 # Controller 0 should receive a role_status message
76 msg, _ = self.controllers[0].poll(ofp.message.role_status)
77 self.assertIsInstance(msg, ofp.message.role_status)
78 self.assertEqual(msg.role, ofp.OFPCR_ROLE_SLAVE)
79 self.assertEqual(msg.reason, ofp.OFPCRR_MASTER_REQUEST)
80 self.assertEqual(msg.generation_id, gen1)
81
82 def verify_role(self, con, role):
83 rcv_role, _ = simple_role_request(self, ofp.OFPCR_ROLE_NOCHANGE, con=con)
84 self.assertEqual(rcv_role, role)
85
86 def tearDown(self):
87 for con in self.controllers:
88 con.shutdown()
89