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 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 17 | """ |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 18 | Basic protocol and dataplane test cases |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 19 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 20 | It is recommended that these definitions be kept in their own |
| 21 | namespace as different groups of tests will likely define |
| 22 | similar identifiers. |
| 23 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 24 | Current Assumptions: |
| 25 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 26 | The switch is actively attempting to contact the controller at the address |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 27 | indicated in oftest.config. |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 28 | |
| 29 | """ |
| 30 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 31 | import time |
| 32 | import sys |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 33 | import logging |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 34 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 35 | import unittest |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 36 | import random |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 37 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 38 | from oftest import config |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 39 | import oftest.controller as controller |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 40 | import oftest.dataplane as dataplane |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 41 | import oftest.base_tests as base_tests |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 42 | import ofp |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 43 | |
Dan Talayco | e605b1b | 2012-09-18 06:56:20 -0700 | [diff] [blame] | 44 | import oftest.illegal_message as illegal_message |
| 45 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 46 | from oftest.testutils import * |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 47 | |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 48 | TEST_VID_DEFAULT = 2 |
| 49 | |
Rich Lane | 97e9965 | 2013-01-02 17:23:20 -0800 | [diff] [blame] | 50 | @group('smoke') |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 51 | class Echo(base_tests.SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 52 | """ |
| 53 | Test echo response with no data |
| 54 | """ |
| 55 | def runTest(self): |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 56 | request = ofp.message.echo_request() |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 57 | response, pkt = self.controller.transact(request) |
Dan Talayco | 97d4f36 | 2012-09-18 03:22:09 -0700 | [diff] [blame] | 58 | self.assertTrue(response is not None, |
| 59 | "Did not get echo reply") |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 60 | self.assertEqual(response.type, ofp.OFPT_ECHO_REPLY, |
Dan Talayco | a92e75b | 2010-02-16 20:53:56 -0800 | [diff] [blame] | 61 | 'response is not echo_reply') |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 62 | self.assertEqual(request.xid, response.xid, |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 63 | 'response xid != request xid') |
| 64 | self.assertEqual(len(response.data), 0, 'response data non-empty') |
| 65 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 66 | class EchoWithData(base_tests.SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 67 | """ |
| 68 | Test echo response with short string data |
| 69 | """ |
| 70 | def runTest(self): |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 71 | request = ofp.message.echo_request(data='OpenFlow Will Rule The World') |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 72 | response, pkt = self.controller.transact(request) |
Dan Talayco | 97d4f36 | 2012-09-18 03:22:09 -0700 | [diff] [blame] | 73 | self.assertTrue(response is not None, |
| 74 | "Did not get echo reply (with data)") |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 75 | self.assertEqual(response.type, ofp.OFPT_ECHO_REPLY, |
Dan Talayco | a92e75b | 2010-02-16 20:53:56 -0800 | [diff] [blame] | 76 | 'response is not echo_reply') |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 77 | self.assertEqual(request.xid, response.xid, |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 78 | 'response xid != request xid') |
| 79 | self.assertEqual(request.data, response.data, |
| 80 | 'response data does not match request') |
| 81 | |
Rich Lane | 97e9965 | 2013-01-02 17:23:20 -0800 | [diff] [blame] | 82 | @group('smoke') |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 83 | class PacketIn(base_tests.SimpleDataPlane): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 84 | """ |
| 85 | Test packet in function |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 86 | |
| 87 | Send a packet to each dataplane port and verify that a packet |
| 88 | in message is received from the controller for each |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 89 | """ |
| 90 | def runTest(self): |
| 91 | # Construct packet to send to dataplane |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 92 | # Send packet to dataplane, once to each port |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 93 | # Poll controller with expect message type packet in |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 94 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 95 | delete_all_flows(self.controller) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 96 | do_barrier(self.controller) |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 97 | |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 98 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 99 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 100 | for of_port in config["port_map"].keys(): |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame] | 101 | for pkt, pt in [ |
| 102 | (simple_tcp_packet(), "simple TCP packet"), |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 103 | (simple_tcp_packet(dl_vlan_enable=True,vlan_vid=vid,pktlen=108), |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 104 | "simple tagged TCP packet"), |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame] | 105 | (simple_eth_packet(), "simple Ethernet packet"), |
| 106 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 107 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 108 | logging.info("PKT IN test with %s, port %s" % (pt, of_port)) |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame] | 109 | self.dataplane.send(of_port, str(pkt)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 110 | verify_packet_in(self, str(pkt), of_port, ofp.OFPR_NO_MATCH) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 111 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 112 | class PacketInBroadcastCheck(base_tests.SimpleDataPlane): |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 113 | """ |
| 114 | Check if bcast pkts leak when no flows are present |
| 115 | |
| 116 | Clear the flow table |
| 117 | Send in a broadcast pkt |
| 118 | Look for the packet on other dataplane ports. |
| 119 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 120 | |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 121 | def runTest(self): |
| 122 | # Need at least two ports |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 123 | self.assertTrue(len(config["port_map"]) > 1, "Too few ports for test") |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 124 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 125 | delete_all_flows(self.controller) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 126 | do_barrier(self.controller) |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 127 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 128 | of_ports = config["port_map"].keys() |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 129 | d_port = of_ports[0] |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 130 | pkt = simple_eth_packet(eth_dst='ff:ff:ff:ff:ff:ff') |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 131 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 132 | logging.info("BCast Leak Test, send to port %s" % d_port) |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 133 | self.dataplane.send(d_port, str(pkt)) |
| 134 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 135 | (of_port, pkt_in, pkt_time) = self.dataplane.poll(exp_pkt=pkt) |
Dan Talayco | 1f648cb | 2012-05-03 09:37:56 -0700 | [diff] [blame] | 136 | self.assertTrue(pkt_in is None, |
| 137 | 'BCast packet received on port ' + str(of_port)) |
| 138 | |
Rich Lane | 97e9965 | 2013-01-02 17:23:20 -0800 | [diff] [blame] | 139 | @group('smoke') |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 140 | class PacketOut(base_tests.SimpleDataPlane): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 141 | """ |
| 142 | Test packet out function |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 143 | |
| 144 | Send packet out message to controller for each dataplane port and |
| 145 | verify the packet appears on the appropriate dataplane port |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 146 | """ |
| 147 | def runTest(self): |
| 148 | # Construct packet to send to dataplane |
| 149 | # Send packet to dataplane |
| 150 | # Poll controller with expect message type packet in |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 151 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 152 | delete_all_flows(self.controller) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 153 | |
| 154 | # These will get put into function |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 155 | of_ports = config["port_map"].keys() |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 156 | of_ports.sort() |
| 157 | for dp_port in of_ports: |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame] | 158 | for outpkt, opt in [ |
| 159 | (simple_tcp_packet(), "simple TCP packet"), |
| 160 | (simple_eth_packet(), "simple Ethernet packet"), |
| 161 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 162 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 163 | logging.info("PKT OUT test with %s, port %s" % (opt, dp_port)) |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 164 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
Rich Lane | 0f0adc9 | 2013-01-04 15:13:02 -0800 | [diff] [blame] | 165 | data=str(outpkt), |
Rich Lane | ea8c472 | 2013-04-04 15:30:20 -0700 | [diff] [blame] | 166 | actions=[ofp.action.output(port=dp_port)], |
| 167 | buffer_id=0xffffffff) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 168 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 169 | logging.info("PacketOut to: " + str(dp_port)) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 170 | self.controller.message_send(msg) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 171 | |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 172 | verify_packets(self, outpkt, [dp_port]) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 173 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 174 | class PacketOutMC(base_tests.SimpleDataPlane): |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 175 | """ |
| 176 | Test packet out to multiple output ports |
| 177 | |
| 178 | Send packet out message to controller for 1 to N dataplane ports and |
| 179 | verify the packet appears on the appropriate ports |
| 180 | """ |
| 181 | def runTest(self): |
| 182 | # Construct packet to send to dataplane |
| 183 | # Send packet to dataplane |
| 184 | # Poll controller with expect message type packet in |
| 185 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 186 | delete_all_flows(self.controller) |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 187 | |
| 188 | # These will get put into function |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 189 | of_ports = config["port_map"].keys() |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 190 | random.shuffle(of_ports) |
| 191 | for num_ports in range(1,len(of_ports)+1): |
| 192 | for outpkt, opt in [ |
| 193 | (simple_tcp_packet(), "simple TCP packet"), |
| 194 | (simple_eth_packet(), "simple Ethernet packet"), |
| 195 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
| 196 | |
| 197 | dp_ports = of_ports[0:num_ports] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 198 | logging.info("PKT OUT test with " + opt + |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 199 | ", ports " + str(dp_ports)) |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 200 | actions = [ofp.action.output(port=port) for port in dp_ports] |
| 201 | msg = ofp.message.packet_out(in_port=ofp.OFPP_NONE, |
Rich Lane | 0f0adc9 | 2013-01-04 15:13:02 -0800 | [diff] [blame] | 202 | data=str(outpkt), |
Rich Lane | ea8c472 | 2013-04-04 15:30:20 -0700 | [diff] [blame] | 203 | actions=actions, |
| 204 | buffer_id=0xffffffff) |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 205 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 206 | logging.info("PacketOut to: " + str(dp_ports)) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 207 | self.controller.message_send(msg) |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 208 | |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 209 | verify_packets(self, outpkt, dp_ports) |
Ken Chiang | 1bf0160 | 2012-04-04 10:48:23 -0700 | [diff] [blame] | 210 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 211 | class FlowStatsGet(base_tests.SimpleProtocol): |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 212 | """ |
| 213 | Get stats |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 214 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 215 | Simply verify stats get transaction |
| 216 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 217 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 218 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 219 | logging.info("Running StatsGet") |
| 220 | logging.info("Inserting trial flow") |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 221 | request = flow_mod_gen(config["port_map"], True) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 222 | self.controller.message_send(request) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 223 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 224 | logging.info("Sending flow request") |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 225 | request = ofp.message.flow_stats_request(out_port=ofp.OFPP_NONE, |
Rich Lane | c3c2ae1 | 2013-01-04 10:13:17 -0800 | [diff] [blame] | 226 | table_id=0xff) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 227 | request.match.wildcards = 0 # ofp.OFPFW_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 228 | response, pkt = self.controller.transact(request) |
Dan Talayco | 97d4f36 | 2012-09-18 03:22:09 -0700 | [diff] [blame] | 229 | self.assertTrue(response is not None, |
| 230 | "Did not get response for flow stats") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 231 | logging.debug(response.show()) |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 232 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 233 | class TableStatsGet(base_tests.SimpleProtocol): |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 234 | """ |
| 235 | Get table stats |
| 236 | |
| 237 | Simply verify table stats get transaction |
| 238 | """ |
| 239 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 240 | logging.info("Running TableStatsGet") |
| 241 | logging.info("Inserting trial flow") |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 242 | request = flow_mod_gen(config["port_map"], True) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 243 | self.controller.message_send(request) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 244 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 245 | logging.info("Sending table stats request") |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 246 | request = ofp.message.table_stats_request() |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 247 | response, pkt = self.controller.transact(request) |
Dan Talayco | 97d4f36 | 2012-09-18 03:22:09 -0700 | [diff] [blame] | 248 | self.assertTrue(response is not None, |
| 249 | "Did not get reply for table stats") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 250 | logging.debug(response.show()) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 251 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 252 | class DescStatsGet(base_tests.SimpleProtocol): |
Ed Swierk | ae74c36 | 2012-04-02 08:21:41 -0700 | [diff] [blame] | 253 | """ |
| 254 | Get stats |
| 255 | |
| 256 | Simply verify stats get transaction |
| 257 | """ |
| 258 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 259 | logging.info("Running DescStatsGet") |
Ed Swierk | ae74c36 | 2012-04-02 08:21:41 -0700 | [diff] [blame] | 260 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 261 | logging.info("Sending stats request") |
Rich Lane | aecd716 | 2013-01-11 11:33:00 -0800 | [diff] [blame] | 262 | request = ofp.message.desc_stats_request() |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 263 | response, pkt = self.controller.transact(request) |
Dan Talayco | 97d4f36 | 2012-09-18 03:22:09 -0700 | [diff] [blame] | 264 | self.assertTrue(response is not None, |
| 265 | "Did not get reply for desc stats") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 266 | logging.debug(response.show()) |
Ed Swierk | ae74c36 | 2012-04-02 08:21:41 -0700 | [diff] [blame] | 267 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 268 | class FlowMod(base_tests.SimpleProtocol): |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 269 | """ |
| 270 | Insert a flow |
| 271 | |
| 272 | Simple verification of a flow mod transaction |
| 273 | """ |
| 274 | |
| 275 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 276 | logging.info("Running " + str(self)) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 277 | request = flow_mod_gen(config["port_map"], True) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 278 | self.controller.message_send(request) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 279 | |
Rich Lane | 97e9965 | 2013-01-02 17:23:20 -0800 | [diff] [blame] | 280 | @group('smoke') |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 281 | class PortConfigMod(base_tests.SimpleProtocol): |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 282 | """ |
| 283 | Modify a bit in port config and verify changed |
| 284 | |
| 285 | Get the switch configuration, modify the port configuration |
| 286 | and write it back; get the config again and verify changed. |
| 287 | Then set it back to the way it was. |
| 288 | """ |
| 289 | |
| 290 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 291 | logging.info("Running " + str(self)) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 292 | for of_port, ifname in config["port_map"].items(): # Grab first port |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 293 | break |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 294 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 295 | (hw_addr, port_config, advert) = \ |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 296 | port_config_get(self.controller, of_port) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 297 | self.assertTrue(port_config is not None, "Did not get port config") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 298 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 299 | logging.debug("No flood bit port " + str(of_port) + " is now " + |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 300 | str(port_config & ofp.OFPPC_NO_FLOOD)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 301 | |
| 302 | rv = port_config_set(self.controller, of_port, |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 303 | port_config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 304 | self.assertTrue(rv != -1, "Error sending port mod") |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 305 | do_barrier(self.controller) |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 306 | |
| 307 | # Verify change took place with same feature request |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 308 | (hw_addr, port_config2, advert) = \ |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 309 | port_config_get(self.controller, of_port) |
| 310 | logging.debug("No flood bit port " + str(of_port) + " is now " + |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 311 | str(port_config2 & ofp.OFPPC_NO_FLOOD)) |
| 312 | self.assertTrue(port_config2 is not None, "Did not get port config2") |
| 313 | self.assertTrue(port_config2 & ofp.OFPPC_NO_FLOOD != |
| 314 | port_config & ofp.OFPPC_NO_FLOOD, |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 315 | "Bit change did not take") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 316 | # Set it back |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 317 | rv = port_config_set(self.controller, of_port, port_config, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 318 | ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 319 | self.assertTrue(rv != -1, "Error sending port mod") |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 320 | do_barrier(self.controller) |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 321 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 322 | class PortConfigModErr(base_tests.SimpleProtocol): |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 323 | """ |
| 324 | Modify a bit in port config on an invalid port and verify |
| 325 | error message is received. |
| 326 | """ |
| 327 | |
| 328 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 329 | logging.info("Running " + str(self)) |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 330 | |
| 331 | # pick a random bad port number |
| 332 | bad_port = random.randint(1, ofp.OFPP_MAX) |
| 333 | count = 0 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 334 | while (count < 50) and (bad_port in config["port_map"].keys()): |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 335 | bad_port = random.randint(1, ofp.OFPP_MAX) |
| 336 | count = count + 1 |
| 337 | self.assertTrue(count < 50, "Error selecting bad port") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 338 | logging.info("Select " + str(bad_port) + " as invalid port") |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 339 | |
| 340 | rv = port_config_set(self.controller, bad_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 341 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 342 | self.assertTrue(rv != -1, "Error sending port mod") |
| 343 | |
| 344 | # poll for error message |
| 345 | while True: |
Dan Talayco | c689a79 | 2012-09-28 14:22:53 -0700 | [diff] [blame] | 346 | (response, raw) = self.controller.poll(ofp.OFPT_ERROR) |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 347 | if not response: # Timeout |
| 348 | break |
| 349 | if response.code == ofp.OFPPMFC_BAD_PORT: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 350 | logging.info("Received error message with OFPPMFC_BAD_PORT code") |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 351 | break |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 352 | if not config["relax"]: # Only one attempt to match |
Ken Chiang | aeb23d6 | 2012-08-23 21:20:07 -0700 | [diff] [blame] | 353 | break |
| 354 | count += 1 |
| 355 | if count > 10: # Too many tries |
| 356 | break |
| 357 | |
| 358 | self.assertTrue(response is not None, 'Did not receive error message') |
| 359 | |
Rich Lane | 97e9965 | 2013-01-02 17:23:20 -0800 | [diff] [blame] | 360 | @group('smoke') |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 361 | class BadMessage(base_tests.SimpleProtocol): |
Dan Talayco | e605b1b | 2012-09-18 06:56:20 -0700 | [diff] [blame] | 362 | """ |
| 363 | Send a message with a bad type and verify an error is returned |
| 364 | """ |
| 365 | |
| 366 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 367 | logging.info("Running " + str(self)) |
Dan Talayco | e605b1b | 2012-09-18 06:56:20 -0700 | [diff] [blame] | 368 | request = illegal_message.illegal_message_type() |
| 369 | |
Dan Talayco | c689a79 | 2012-09-28 14:22:53 -0700 | [diff] [blame] | 370 | reply, pkt = self.controller.transact(request) |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 371 | logging.info(repr(pkt)) |
Dan Talayco | e605b1b | 2012-09-18 06:56:20 -0700 | [diff] [blame] | 372 | self.assertTrue(reply is not None, "Did not get response to bad req") |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 373 | self.assertTrue(reply.type == ofp.OFPT_ERROR, |
Dan Talayco | e605b1b | 2012-09-18 06:56:20 -0700 | [diff] [blame] | 374 | "reply not an error message") |
Rich Lane | b73808c | 2013-03-11 15:22:23 -0700 | [diff] [blame] | 375 | logging.info(reply.err_type) |
Rich Lane | 4e361bb | 2013-03-11 13:57:31 -0700 | [diff] [blame] | 376 | self.assertTrue(reply.err_type == ofp.OFPET_BAD_REQUEST, |
Dan Talayco | e605b1b | 2012-09-18 06:56:20 -0700 | [diff] [blame] | 377 | "reply error type is not bad request") |
| 378 | self.assertTrue(reply.code == ofp.OFPBRC_BAD_TYPE, |
| 379 | "reply error code is not bad type") |
| 380 | |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 381 | @group('smoke') |
| 382 | @version('1.1+') |
| 383 | class TableModConfig(base_tests.SimpleProtocol): |
| 384 | """ |
| 385 | Simple table modification |
| 386 | |
| 387 | Mostly to make sure the switch correctly responds to these messages. |
| 388 | More complicated tests in the multi-tables.py tests |
| 389 | """ |
| 390 | def runTest(self): |
| 391 | # First table should always exist |
| 392 | table_id = 0 |
| 393 | |
| 394 | def get_table_config(): |
| 395 | request = ofp.message.table_stats_request() |
| 396 | response, _ = self.controller.transact(request) |
| 397 | try: |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 398 | table_stats = [x for x in response.entries if x.table_id == table_id][0] |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 399 | except IndexError: |
| 400 | raise AssertionError("table id %d not found" % table_id) |
| 401 | return table_stats.config |
| 402 | |
| 403 | # Get current configuration |
| 404 | orig_table_config = get_table_config() |
| 405 | |
| 406 | # Change the configuration |
| 407 | if orig_table_config == ofp.OFPTC_TABLE_MISS_CONTROLLER: |
| 408 | new_table_config = ofp.OFPTC_TABLE_MISS_DROP |
| 409 | else: |
| 410 | new_table_config = ofp.OFPTC_TABLE_MISS_CONTROLLER |
| 411 | request = ofp.message.table_mod(table_id=table_id, config=new_table_config) |
| 412 | self.controller.message_send(request) |
| 413 | self.controller.transact(ofp.message.barrier_request()) |
| 414 | |
| 415 | # Check the configuration took |
| 416 | self.assertEqual(get_table_config(), new_table_config) |
| 417 | |
| 418 | # Change the configuration back |
| 419 | request = ofp.message.table_mod(table_id=table_id, config=orig_table_config) |
| 420 | self.controller.message_send(request) |
| 421 | self.controller.transact(ofp.message.barrier_request()) |
| 422 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 423 | if __name__ == "__main__": |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 424 | print "Please run through oft script: ./oft --test_spec=basic" |