ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 1 | """These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases). |
| 2 | Refer Documentation -- Detailed testing methodology |
| 3 | <Some of test-cases are directly taken from oftest> """ |
| 4 | |
| 5 | "Test Suite 2 --> Openflow Protocol messages" |
| 6 | |
| 7 | |
| 8 | import logging |
| 9 | |
| 10 | import unittest |
| 11 | import random |
| 12 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 13 | from oftest import config |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 14 | import oftest.controller as controller |
| 15 | import oftest.cstruct as ofp |
| 16 | import oftest.message as message |
| 17 | import oftest.dataplane as dataplane |
| 18 | import oftest.action as action |
| 19 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 20 | import oftest.base_tests as base_tests |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 21 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 22 | from oftest.testutils import * |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 23 | from time import sleep |
| 24 | from FuncUtils import * |
| 25 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 26 | class FeaturesRequest(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 27 | |
| 28 | """Verify Features_Request-Reply is implemented |
| 29 | a) Send OFPT_FEATURES_REQUEST |
| 30 | b) Verify OFPT_FEATURES_REPLY is received without errors""" |
| 31 | |
| 32 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 33 | logging.info("Running Features_Request test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 34 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 35 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 36 | of_ports.sort() |
| 37 | |
| 38 | #Clear switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 39 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 40 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 41 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 42 | logging.info("Sending Features_Request") |
| 43 | logging.info("Expecting Features_Reply") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 44 | |
| 45 | request = message.features_request() |
| 46 | rv = self.controller.message_send(request) |
| 47 | self.assertTrue(rv != -1, "Not able to send features request.") |
| 48 | |
| 49 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FEATURES_REPLY, |
| 50 | timeout=2) |
| 51 | self.assertTrue(response is not None, |
| 52 | 'Did not receive Features Reply') |
| 53 | |
| 54 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 55 | class ConfigurationRequest(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 56 | |
| 57 | """Check basic Get Config request is implemented |
| 58 | a) Send OFPT_GET_CONFIG_REQUEST |
| 59 | b) Verify OFPT_GET_CONFIG_REPLY is received without errors""" |
| 60 | |
| 61 | def runTest(self): |
| 62 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 63 | logging.info("Running Configuration_Request test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 64 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 65 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 66 | of_ports.sort() |
| 67 | |
| 68 | #Clear switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 69 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 70 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 71 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 72 | logging.info("Sending OFPT_GET_CONFIG_REQUEST ") |
| 73 | logging.info("Expecting OFPT_GET_CONFIG_REPLY ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 74 | |
| 75 | request = message.get_config_request() |
| 76 | rv = self.controller.message_send(request) |
| 77 | self.assertTrue(rv != -1, " Not able to send get_config request.") |
| 78 | |
| 79 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_GET_CONFIG_REPLY, |
| 80 | timeout=2) |
| 81 | self.assertTrue(response is not None, |
| 82 | 'Did not receive OFPT_GET_CONFIG_REPLY') |
| 83 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 84 | class ModifyStateAdd(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 85 | |
| 86 | """Check basic Flow Add request is implemented |
| 87 | a) Send OFPT_FLOW_MOD , command = OFPFC_ADD |
| 88 | c) Send ofp_table_stats request , verify active_count=1 in reply""" |
| 89 | |
| 90 | def runTest(self): |
| 91 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 92 | logging.info("Running Modify_State_Add test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 93 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 94 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 95 | of_ports.sort() |
| 96 | |
| 97 | #Clear switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 98 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 99 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 100 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 101 | logging.info("Inserting a flow entry") |
| 102 | logging.info("Expecting active_count=1 in table_stats_reply") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 103 | |
| 104 | #Insert a flow entry matching on ingress_port |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 105 | (pkt,match) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 106 | |
| 107 | # Send Table_Stats_Request and verify flow gets inserted. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 108 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 109 | |
| 110 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 111 | class ModifyStateDelete(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 112 | |
| 113 | """Check Basic Flow Delete request is implemented |
| 114 | a) Send OFPT_FLOW_MOD, command = OFPFC_ADD |
| 115 | b) Send ofp_table_stats request , verify active_count=1 in reply |
| 116 | c) Send OFPT_FLOW_MOD, command = OFPFC_DELETE |
| 117 | c) Send ofp_table_stats request , verify active_count=0 in reply""" |
| 118 | |
| 119 | def runTest(self): |
| 120 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 121 | logging.info("Running Modify_State_Delete test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 122 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 123 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 124 | of_ports.sort() |
| 125 | |
| 126 | #Clear switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 127 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 128 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 129 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 130 | logging.info("Inserting a flow entry and then deleting it") |
| 131 | logging.info("Expecting the active_count=0 in table_stats_reply") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 132 | |
| 133 | #Insert a flow matching on ingress_port |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 134 | (pkt,match) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 135 | |
| 136 | #Verify Flow inserted. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 137 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 138 | |
| 139 | #Delete the flow |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 140 | nonstrict_delete(self,match) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 141 | |
| 142 | # Send Table_Stats_Request and verify flow deleted. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 143 | verify_tablestats(self,expect_active=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 144 | |
| 145 | |
| 146 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 147 | class ModifyStateModify(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 148 | |
| 149 | """Verify basic Flow Modify request is implemented |
| 150 | a) Send OFPT_FLOW_MOD, command = OFPFC_ADD, Action A |
| 151 | b) Send OFPT_FLOW_MOD, command = OFPFC_MODIFY , with output action A' |
| 152 | c) Send a packet matching the flow, verify packet implements action A' """ |
| 153 | |
| 154 | def runTest(self): |
| 155 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 156 | logging.info("Running Modify_State_Modify test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 157 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 158 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 159 | of_ports.sort() |
| 160 | |
| 161 | #Clear switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 162 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 163 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 164 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 165 | logging.info("Inserting a flow entry and then modifying it") |
| 166 | logging.info("Expecting the Test Packet to implement the modified action") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 167 | |
| 168 | # Insert a flow matching on ingress_port with action A (output to of_port[1]) |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 169 | (pkt,match) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 170 | |
| 171 | # Modify the flow action (output to of_port[2]) |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 172 | modify_flow_action(self,of_ports,match) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 173 | |
| 174 | # Send the Test Packet and verify action implemented is A' (output to of_port[2]) |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 175 | send_packet(self,pkt,of_ports[0],of_ports[2]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 176 | |
| 177 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 178 | class ReadState(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 179 | |
| 180 | """Test that a basic Read state request (like flow_stats_get request) does not generate an error |
| 181 | a) Send OFPT_FLOW_MOD, command = OFPFC_ADD |
| 182 | b) Send ofp_flow_stats request |
| 183 | b) Verify switch replies without errors""" |
| 184 | |
| 185 | def runTest(self): |
| 186 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 187 | logging.info("Running Read_State test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 188 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 189 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 190 | of_ports.sort() |
| 191 | |
| 192 | #Clear switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 193 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 194 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 195 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 196 | logging.info("Inserting a flow entry and then sending flow_stats request") |
| 197 | logging.info("Expecting the a flow_stats_reply without errors") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 198 | |
| 199 | # Insert a flow with match on ingress_port |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 200 | (pkt,match ) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 201 | |
| 202 | #Verify Flow_Stats request does not generate errors |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 203 | get_flowstats(self,match) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 204 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 205 | class PacketOut(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 206 | |
| 207 | """Test packet out function |
| 208 | a) Send packet out message for each dataplane port. |
| 209 | b) Verify the packet appears on the appropriate dataplane port""" |
| 210 | |
| 211 | def runTest(self): |
| 212 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 213 | logging.info("Running Packet_Out test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 214 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 215 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 216 | of_ports.sort() |
| 217 | |
| 218 | #Clear Switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 219 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 220 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 221 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 222 | logging.info("Sending a packet-out for each dataplane port") |
| 223 | logging.info("Expecting the packet on appropriate dataplane port") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 224 | |
| 225 | for dp_port in of_ports: |
| 226 | for outpkt, opt in [ |
| 227 | (simple_tcp_packet(), "simple TCP packet"), |
| 228 | (simple_eth_packet(), "simple Ethernet packet"), |
| 229 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
| 230 | |
| 231 | msg = message.packet_out() |
| 232 | msg.data = str(outpkt) |
| 233 | act = action.action_output() |
| 234 | act.port = dp_port |
| 235 | self.assertTrue(msg.actions.add(act), 'Could not add action to msg') |
| 236 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 237 | logging.info("PacketOut to: " + str(dp_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 238 | rv = self.controller.message_send(msg) |
| 239 | self.assertTrue(rv == 0, "Error sending out message") |
| 240 | |
| 241 | exp_pkt_arg = None |
| 242 | exp_port = None |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 243 | if config["relax"]: |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 244 | exp_pkt_arg = outpkt |
| 245 | exp_port = dp_port |
| 246 | (of_port, pkt, pkt_time) = self.dataplane.poll(timeout=2, |
| 247 | port_number=exp_port, |
| 248 | exp_pkt=exp_pkt_arg) |
| 249 | |
| 250 | self.assertTrue(pkt is not None, 'Packet not received') |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 251 | logging.info("PacketOut: got pkt from " + str(of_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 252 | if of_port is not None: |
| 253 | self.assertEqual(of_port, dp_port, "Unexpected receive port") |
| 254 | if not dataplane.match_exp_pkt(outpkt, pkt): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 255 | logging.debug("Sent %s" % format_packet(outpkt)) |
| 256 | logging.debug("Resp %s" % format_packet( |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 257 | str(pkt)[:len(str(outpkt))])) |
| 258 | self.assertEqual(str(outpkt), str(pkt)[:len(str(outpkt))], |
| 259 | 'Response packet does not match send packet') |
| 260 | |
| 261 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 262 | class PacketIn(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 263 | |
| 264 | """Test basic packet_in function |
| 265 | a) Send a simple tcp packet to a dataplane port, without any flow-entry |
| 266 | b) Verify that a packet_in event is sent to the controller""" |
| 267 | |
| 268 | def runTest(self): |
| 269 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 270 | logging.info("Running Packet_In test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 271 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 272 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 273 | of_ports.sort() |
| 274 | ingress_port = of_ports[0] |
| 275 | |
| 276 | #Clear Switch state |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 277 | rc = delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 278 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 279 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 280 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 281 | logging.info("Sending a Simple tcp packet a dataplane port") |
| 282 | logging.info("Expecting a packet_in event on the control plane") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 283 | |
| 284 | # Send packet on dataplane port and verify packet_in event gets generated. |
| 285 | pkt = simple_tcp_packet() |
| 286 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 287 | logging.info("Sending packet to dp port " + str(ingress_port) + |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 288 | ", expecting packet_in on control plane" ) |
| 289 | |
| 290 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_PACKET_IN, |
| 291 | timeout=2) |
| 292 | self.assertTrue(response is not None, |
| 293 | 'Packet in event is not sent to the controller') |
| 294 | |
| 295 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 296 | class Hello(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 297 | |
| 298 | """Test Hello messages are implemented |
| 299 | a) Create Hello messages from controller |
| 300 | b) Verify switch also exchanges hello message -- (Poll the control plane) |
| 301 | d) Verify the version field in the hello messages is openflow 1.0.0 """ |
| 302 | |
| 303 | def runTest(self): |
| 304 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 305 | logging.info("Running Hello test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 306 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 307 | logging.info("Sending Hello") |
| 308 | logging.info("Expecting a Hello on the control plane with version--1.0.0") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 309 | |
| 310 | #Send Hello message |
| 311 | request = message.hello() |
| 312 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO, |
| 313 | timeout=1) |
| 314 | self.assertTrue(response is not None, |
| 315 | 'Switch did not exchange hello message in return') |
| 316 | self.assertTrue(response.header.version == 0x01, 'switch openflow-version field is not 1.0.0') |
| 317 | |
| 318 | |
| 319 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 320 | class EchoWithoutBody(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 321 | |
| 322 | """Test basic echo-reply is implemented |
| 323 | a) Send echo-request from the controller side, note echo body is empty here. |
| 324 | b) Verify switch responds back with echo-reply with same xid """ |
| 325 | |
| 326 | def runTest(self): |
| 327 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 328 | logging.info("Running Echo_Without_Body test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 329 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 330 | logging.info("Sending Echo Request") |
| 331 | logging.info("Expecting a Echo Reply with version--1.0.0 and same xid") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 332 | |
| 333 | # Send echo_request |
| 334 | request = message.echo_request() |
| 335 | (response, pkt) = self.controller.transact(request) |
| 336 | self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,'response is not echo_reply') |
| 337 | self.assertEqual(request.header.xid, response.header.xid, |
| 338 | 'response xid != request xid') |
| 339 | self.assertTrue(response.header.version == 0x01, 'switch openflow-version field is not 1.0.1') |
| 340 | self.assertEqual(len(response.data), 0, 'response data non-empty') |
| 341 | |
| 342 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 343 | class BarrierRequestReply(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 344 | |
| 345 | """ Check basic Barrier request is implemented |
| 346 | a) Send OFPT_BARRIER_REQUEST |
| 347 | c) Verify OFPT_BARRIER_REPLY is recieved""" |
| 348 | |
| 349 | def runTest(self): |
| 350 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 351 | logging.info("Running Barrier_Request_Reply test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 352 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 353 | logging.info("Sending Barrier Request") |
| 354 | logging.info("Expecting a Barrier Reply with same xid") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 355 | |
| 356 | #Send Barrier Request |
| 357 | request = message.barrier_request() |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 358 | (response,pkt) = self.controller.transact(request) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 359 | self.assertEqual(response.header.type, ofp.OFPT_BARRIER_REPLY,'response is not barrier_reply') |
| 360 | self.assertEqual(request.header.xid, response.header.xid, |
| 361 | 'response xid != request xid') |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |