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