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