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