Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 1 | """ |
| 2 | Basic capabilities and capacities tests |
| 3 | |
| 4 | """ |
| 5 | |
| 6 | import logging |
Rich Lane | 4f50805 | 2013-01-28 10:49:46 -0800 | [diff] [blame] | 7 | import time |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 8 | import unittest |
| 9 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 10 | from oftest import config |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 11 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 12 | import ofp |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 13 | import oftest.dataplane as dataplane |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 14 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 15 | import oftest.base_tests as base_tests |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 16 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 17 | from oftest.testutils import * |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 18 | |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 19 | def flow_caps_common(obj, is_exact=True): |
| 20 | """ |
| 21 | The common function for |
| 22 | |
| 23 | @param obj The calling object |
| 24 | @param is_exact If True, checking exact match; else wildcard |
| 25 | """ |
| 26 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 27 | of_ports = config["port_map"].keys() |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 28 | of_ports.sort() |
| 29 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 30 | delete_all_flows(obj.controller) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 31 | |
| 32 | pkt = simple_tcp_packet() |
Ed Swierk | 6192e51 | 2012-08-22 11:41:40 -0700 | [diff] [blame] | 33 | match = packet_to_flow_match(obj, pkt) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 34 | obj.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 35 | for port in of_ports: |
| 36 | break; |
| 37 | match.in_port = port |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 38 | match.ipv4_src = 1 |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 39 | request = ofp.message.flow_mod() |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 40 | count_check = 101 # fixme: better way to determine this. |
| 41 | if is_exact: |
| 42 | match.wildcards = 0 |
| 43 | else: |
| 44 | match.wildcards |= ofp.OFPFW_DL_SRC |
| 45 | |
| 46 | request.match = match |
Rob Sherwood | 9130bcd | 2012-03-07 12:23:50 -0800 | [diff] [blame] | 47 | request.buffer_id = 0xffffffff # set to NONE |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 48 | logging.info(request.show()) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 49 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 50 | tstats = ofp.message.table_stats_request() |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 51 | try: # Determine the table index to check (or "all") |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 52 | table_idx = config["caps_table_idx"] |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 53 | except: |
| 54 | table_idx = -1 # Accumulate all table counts |
| 55 | |
| 56 | # Make sure we can install at least one flow |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 57 | logging.info("Inserting initial flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 58 | obj.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 59 | do_barrier(obj.controller, timeout=10) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 60 | flow_count = 1 |
| 61 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 62 | logging.info("Table idx: " + str(table_idx)) |
| 63 | logging.info("Check every " + str(count_check) + " inserts") |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 64 | |
| 65 | while True: |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 66 | request.match.ipv4_src += 1 |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 67 | obj.controller.message_send(request) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 68 | flow_count += 1 |
| 69 | if flow_count % count_check == 0: |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 70 | do_barrier(obj.controller, timeout=10) |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 71 | response, pkt = obj.controller.transact(tstats) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 72 | obj.assertTrue(response is not None, "Get tab stats failed") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 73 | logging.info(response.show()) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 74 | if table_idx == -1: # Accumulate for all tables |
| 75 | active_flows = 0 |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame^] | 76 | for stats in response.entries: |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 77 | active_flows += stats.active_count |
| 78 | else: # Table index to use specified in config |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame^] | 79 | active_flows = response.entries[table_idx].active_count |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 80 | if active_flows != flow_count: |
| 81 | break |
| 82 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 83 | logging.error("RESULT: " + str(flow_count) + " flows inserted") |
| 84 | logging.error("RESULT: " + str(active_flows) + " flows reported") |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 85 | |
Shudong Zhou | d71c4a7 | 2012-11-18 14:37:43 -0800 | [diff] [blame] | 86 | # clean up and wait a bit in case the table is really big |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 87 | delete_all_flows(obj.controller) |
Shudong Zhou | d71c4a7 | 2012-11-18 14:37:43 -0800 | [diff] [blame] | 88 | time.sleep(flow_count / 100) |
| 89 | |
| 90 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 91 | @disabled |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 92 | class FillTableExact(base_tests.SimpleProtocol): |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 93 | """ |
Dan Talayco | 8f91a5b | 2010-07-20 14:07:21 -0700 | [diff] [blame] | 94 | Fill the flow table with exact matches; can take a while |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 95 | |
| 96 | Fill table until no more flows can be added. Report result. |
| 97 | Increment the source IP address. Assume the flow table will |
| 98 | fill in less than 4 billion inserts |
| 99 | |
| 100 | To check the number of flows in the tables is expensive, so |
| 101 | it's only done periodically. This is controlled by the |
| 102 | count_check variable. |
| 103 | |
| 104 | A switch may have multiple tables. The default behaviour |
| 105 | is to count all the flows in all the tables. By setting |
| 106 | the parameter "caps_table_idx" in the configuration array, |
| 107 | you can control which table to check. |
| 108 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 109 | |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 110 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 111 | logging.info("Running " + str(self)) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 112 | flow_caps_common(self) |
| 113 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 114 | @disabled |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 115 | class FillTableWC(base_tests.SimpleProtocol): |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 116 | """ |
| 117 | Fill the flow table with wildcard matches |
| 118 | |
| 119 | Fill table using wildcard entries until no more flows can be |
| 120 | added. Report result. |
| 121 | Increment the source IP address. Assume the flow table will |
| 122 | fill in less than 4 billion inserts |
| 123 | |
| 124 | To check the number of flows in the tables is expensive, so |
| 125 | it's only done periodically. This is controlled by the |
| 126 | count_check variable. |
| 127 | |
| 128 | A switch may have multiple tables. The default behaviour |
| 129 | is to count all the flows in all the tables. By setting |
| 130 | the parameter "caps_table_idx" in the configuration array, |
| 131 | you can control which table to check. |
| 132 | |
| 133 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 134 | |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 135 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 136 | logging.info("Running " + str(self)) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 137 | flow_caps_common(self, is_exact=False) |