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