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