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