Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1 | """ |
| 2 | Flow query test case. |
| 3 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 4 | Attempts to fill switch to capacity with randomized flows, and ensure that |
| 5 | they all are read back correctly. |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 6 | """ |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 7 | |
| 8 | # COMMON TEST PARAMETERS |
| 9 | # |
| 10 | # Name: wildcards |
| 11 | # Type: number |
| 12 | # Description: |
| 13 | # Overrides bitmap of supported wildcards reported by switch |
| 14 | # Default: none |
| 15 | # |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 16 | # Name: wildcards_force |
| 17 | # Type: number |
| 18 | # Description: |
| 19 | # Bitmap of wildcards to always be set |
| 20 | # Default: none |
| 21 | # |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 22 | # Name: actions |
| 23 | # Type: number |
| 24 | # Description: |
| 25 | # Overrides bitmap of supported actions reported by switch |
| 26 | # Default: none |
| 27 | # |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 28 | # Name: actions_force |
| 29 | # Type: number |
| 30 | # Description: |
| 31 | # Bitmap of actions to always be used |
| 32 | # Default: none |
| 33 | # |
| 34 | # Name: ports |
| 35 | # Type: list of OF port numbers |
| 36 | # Description: |
| 37 | # Override list of OF port numbers reported by switch |
| 38 | # Default: none |
| 39 | # |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 40 | # Name: queues |
| 41 | # Type: list of OF (port-number, queue-id) pairs |
| 42 | # Description: |
| 43 | # Override list of OF (port-number, queue-id) pairs returned by switch |
| 44 | # Default: none |
| 45 | # |
Howard Persh | b10a47a | 2012-08-21 13:54:47 -0700 | [diff] [blame] | 46 | # Name: vlans |
| 47 | # Type: list of VLAN ids |
| 48 | # Description: |
| 49 | # Override VLAN ids used in tests to given list |
| 50 | # Default: [] |
| 51 | # |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 52 | # Name: conservative_ordered_actions |
| 53 | # Type: boolean (True or False) |
| 54 | # Description: |
| 55 | # Compare flow actions lists as unordered |
| 56 | # Default: True |
| 57 | |
| 58 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 59 | import math |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 60 | |
| 61 | import logging |
| 62 | |
| 63 | import unittest |
| 64 | import random |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 65 | import time |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 66 | |
| 67 | import oftest.controller as controller |
| 68 | import oftest.cstruct as ofp |
| 69 | import oftest.message as message |
| 70 | import oftest.dataplane as dataplane |
| 71 | import oftest.action as action |
| 72 | import oftest.action_list as action_list |
| 73 | import oftest.parse as parse |
| 74 | import pktact |
| 75 | import basic |
| 76 | |
| 77 | from testutils import * |
| 78 | from time import sleep |
| 79 | |
| 80 | #@var port_map Local copy of the configuration map from OF port |
| 81 | # numbers to OS interfaces |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 82 | fq_port_map = None |
| 83 | #@var fq_logger Local logger object |
| 84 | fq_logger = None |
| 85 | #@var fq_config Local copy of global configuration data |
| 86 | fq_config = None |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 87 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 88 | # For test priority |
| 89 | test_prio = {} |
| 90 | |
| 91 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 92 | def test_set_init(config): |
| 93 | """ |
| 94 | Set up function for packet action test classes |
| 95 | |
| 96 | @param config The configuration dictionary; see oft |
| 97 | """ |
| 98 | |
| 99 | basic.test_set_init(config) |
| 100 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 101 | global fq_port_map |
| 102 | global fq_logger |
| 103 | global fq_config |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 104 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 105 | fq_logger = logging.getLogger("flowq") |
| 106 | fq_logger.info("Initializing test set") |
| 107 | fq_port_map = config["port_map"] |
| 108 | fq_config = config |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 109 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 110 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 111 | def flip_coin(): |
| 112 | return random.randint(1, 100) <= 50 |
| 113 | |
| 114 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 115 | def shuffle(list): |
| 116 | n = len(list) |
| 117 | lim = n * n |
| 118 | i = 0 |
| 119 | while i < lim: |
| 120 | a = random.randint(0, n - 1) |
| 121 | b = random.randint(0, n - 1) |
| 122 | temp = list[a] |
| 123 | list[a] = list[b] |
| 124 | list[b] = temp |
| 125 | i = i + 1 |
| 126 | return list |
| 127 | |
| 128 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 129 | def rand_pick(list): |
| 130 | return list[random.randint(0, len(list) - 1)] |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 131 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 132 | def rand_dl_addr(): |
| 133 | return [random.randint(0, 255) & ~1, |
| 134 | random.randint(0, 255), |
| 135 | random.randint(0, 255), |
| 136 | random.randint(0, 255), |
| 137 | random.randint(0, 255), |
| 138 | random.randint(0, 255) |
| 139 | ] |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 140 | |
| 141 | def rand_nw_addr(): |
| 142 | return random.randint(0, (1 << 32) - 1) |
| 143 | |
| 144 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 145 | class Flow_Info: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 146 | # Members: |
| 147 | # priorities - list of flow priorities |
| 148 | # dl_addrs - list of MAC addresses |
| 149 | # vlans - list of VLAN ids |
| 150 | # ethertypes - list of Ethertypes |
| 151 | # ip_addrs - list of IP addresses |
| 152 | # ip_tos - list of IP TOS values |
| 153 | # ip_protos - list of IP protocols |
| 154 | # l4_ports - list of L4 ports |
| 155 | |
| 156 | def __init__(self): |
| 157 | priorities = [] |
| 158 | dl_addrs = [] |
| 159 | vlans = [] |
| 160 | ethertypes = [] |
| 161 | ip_addrs = [] |
| 162 | ip_tos = [] |
| 163 | ip_protos = [] |
| 164 | l4_ports = [] |
| 165 | |
| 166 | def rand(self, n): |
| 167 | self.priorities = [] |
| 168 | i = 0 |
| 169 | while i < n: |
| 170 | self.priorities.append(random.randint(1, 65534)) |
| 171 | i = i + 1 |
| 172 | |
| 173 | self.dl_addrs = [] |
| 174 | i = 0 |
| 175 | while i < n: |
| 176 | self.dl_addrs.append(rand_dl_addr()) |
| 177 | i = i + 1 |
| 178 | |
Howard Persh | b10a47a | 2012-08-21 13:54:47 -0700 | [diff] [blame] | 179 | if test_param_get(fq_config, "vlans", []) != []: |
| 180 | self.vlans = test_param_get(fq_config, "vlans", []) |
| 181 | |
| 182 | fq_logger.info("Overriding VLAN ids to:") |
| 183 | fq_logger.info(self.vlans) |
| 184 | else: |
| 185 | self.vlans = [] |
| 186 | i = 0 |
| 187 | while i < n: |
| 188 | self.vlans.append(random.randint(1, 4094)) |
| 189 | i = i + 1 |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 190 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 191 | self.ethertypes = [0x0800, 0x0806] |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 192 | i = 0 |
| 193 | while i < n: |
| 194 | self.ethertypes.append(random.randint(0, (1 << 16) - 1)) |
| 195 | i = i + 1 |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 196 | self.ethertypes = shuffle(self.ethertypes)[0 : n] |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 197 | |
| 198 | self.ip_addrs = [] |
| 199 | i = 0 |
| 200 | while i < n: |
| 201 | self.ip_addrs.append(rand_nw_addr()) |
| 202 | i = i + 1 |
| 203 | |
| 204 | self.ip_tos = [] |
| 205 | i = 0 |
| 206 | while i < n: |
| 207 | self.ip_tos.append(random.randint(0, (1 << 8) - 1) & ~3) |
| 208 | i = i + 1 |
| 209 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 210 | self.ip_protos = [1, 6, 17] |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 211 | i = 0 |
| 212 | while i < n: |
| 213 | self.ip_protos.append(random.randint(0, (1 << 8) - 1)) |
| 214 | i = i + 1 |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 215 | self.ip_protos = shuffle(self.ip_protos)[0 : n] |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 216 | |
| 217 | self.l4_ports = [] |
| 218 | i = 0 |
| 219 | while i < n: |
| 220 | self.l4_ports.append(random.randint(0, (1 << 16) - 1)) |
| 221 | i = i + 1 |
| 222 | |
| 223 | def rand_priority(self): |
| 224 | return rand_pick(self.priorities) |
| 225 | |
| 226 | def rand_dl_addr(self): |
| 227 | return rand_pick(self.dl_addrs) |
| 228 | |
| 229 | def rand_vlan(self): |
| 230 | return rand_pick(self.vlans) |
| 231 | |
| 232 | def rand_ethertype(self): |
| 233 | return rand_pick(self.ethertypes) |
| 234 | |
| 235 | def rand_ip_addr(self): |
| 236 | return rand_pick(self.ip_addrs) |
| 237 | |
| 238 | def rand_ip_tos(self): |
| 239 | return rand_pick(self.ip_tos) |
| 240 | |
| 241 | def rand_ip_proto(self): |
| 242 | return rand_pick(self.ip_protos) |
| 243 | |
| 244 | def rand_l4_port(self): |
| 245 | return rand_pick(self.l4_ports) |
| 246 | |
| 247 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 248 | # TBD - These don't belong here |
| 249 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 250 | all_wildcards_list = [ofp.OFPFW_IN_PORT, |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 251 | ofp.OFPFW_DL_DST, |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 252 | ofp.OFPFW_DL_SRC, |
| 253 | ofp.OFPFW_DL_VLAN, |
| 254 | ofp.OFPFW_DL_VLAN_PCP, |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 255 | ofp.OFPFW_DL_TYPE, |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 256 | ofp.OFPFW_NW_TOS, |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 257 | ofp.OFPFW_NW_PROTO, |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 258 | ofp.OFPFW_NW_SRC_MASK, |
| 259 | ofp.OFPFW_NW_DST_MASK, |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 260 | ofp.OFPFW_TP_SRC, |
| 261 | ofp.OFPFW_TP_DST |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 262 | ] |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 263 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 264 | # TBD - Need this because there are duplicates in ofp.ofp_flow_wildcards_map |
| 265 | # -- FIX |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 266 | all_wildcard_names = { |
| 267 | 1 : 'OFPFW_IN_PORT', |
| 268 | 2 : 'OFPFW_DL_VLAN', |
| 269 | 4 : 'OFPFW_DL_SRC', |
| 270 | 8 : 'OFPFW_DL_DST', |
| 271 | 16 : 'OFPFW_DL_TYPE', |
| 272 | 32 : 'OFPFW_NW_PROTO', |
| 273 | 64 : 'OFPFW_TP_SRC', |
| 274 | 128 : 'OFPFW_TP_DST', |
| 275 | 1048576 : 'OFPFW_DL_VLAN_PCP', |
| 276 | 2097152 : 'OFPFW_NW_TOS' |
| 277 | } |
| 278 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 279 | def wildcard_set(x, w, val): |
| 280 | result = x |
| 281 | if w == ofp.OFPFW_NW_SRC_MASK: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 282 | result = (result & ~ofp.OFPFW_NW_SRC_MASK) \ |
| 283 | | (val << ofp.OFPFW_NW_SRC_SHIFT) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 284 | elif w == ofp.OFPFW_NW_DST_MASK: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 285 | result = (result & ~ofp.OFPFW_NW_DST_MASK) \ |
| 286 | | (val << ofp.OFPFW_NW_DST_SHIFT) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 287 | elif val == 0: |
| 288 | result = result & ~w |
| 289 | else: |
| 290 | result = result | w |
| 291 | return result |
| 292 | |
| 293 | def wildcard_get(x, w): |
| 294 | if w == ofp.OFPFW_NW_SRC_MASK: |
| 295 | return (x & ofp.OFPFW_NW_SRC_MASK) >> ofp.OFPFW_NW_SRC_SHIFT |
| 296 | if w == ofp.OFPFW_NW_DST_MASK: |
| 297 | return (x & ofp.OFPFW_NW_DST_MASK) >> ofp.OFPFW_NW_DST_SHIFT |
| 298 | return 1 if (x & w) != 0 else 0 |
| 299 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 300 | def wildcards_to_str(wildcards): |
| 301 | result = "{" |
| 302 | sep = "" |
| 303 | for w in all_wildcards_list: |
| 304 | if (wildcards & w) == 0: |
| 305 | continue |
| 306 | if w == ofp.OFPFW_NW_SRC_MASK: |
| 307 | n = wildcard_get(wildcards, w) |
| 308 | if n > 0: |
| 309 | result = result + sep + ("OFPFW_NW_SRC(%d)" % (n)) |
| 310 | elif w == ofp.OFPFW_NW_DST_MASK: |
| 311 | n = wildcard_get(wildcards, w) |
| 312 | if n > 0: |
| 313 | result = result + sep + ("OFPFW_NW_DST(%d)" % (n)) |
| 314 | else: |
| 315 | result = result + sep + all_wildcard_names[w] |
| 316 | sep = ", " |
| 317 | result = result +"}" |
| 318 | return result |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 319 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 320 | all_actions_list = [ofp.OFPAT_OUTPUT, |
| 321 | ofp.OFPAT_SET_VLAN_VID, |
| 322 | ofp.OFPAT_SET_VLAN_PCP, |
| 323 | ofp.OFPAT_STRIP_VLAN, |
| 324 | ofp.OFPAT_SET_DL_SRC, |
| 325 | ofp.OFPAT_SET_DL_DST, |
| 326 | ofp.OFPAT_SET_NW_SRC, |
| 327 | ofp.OFPAT_SET_NW_DST, |
| 328 | ofp.OFPAT_SET_NW_TOS, |
| 329 | ofp.OFPAT_SET_TP_SRC, |
| 330 | ofp.OFPAT_SET_TP_DST, |
| 331 | ofp.OFPAT_ENQUEUE |
| 332 | ] |
| 333 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 334 | def actions_bmap_to_str(bm): |
| 335 | result = "{" |
| 336 | sep = "" |
| 337 | for a in all_actions_list: |
| 338 | if ((1 << a) & bm) != 0: |
| 339 | result = result + sep + ofp.ofp_action_type_map[a] |
| 340 | sep = ", " |
| 341 | result = result + "}" |
| 342 | return result |
| 343 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 344 | def dl_addr_to_str(a): |
| 345 | return "%x:%x:%x:%x:%x:%x" % tuple(a) |
| 346 | |
| 347 | def ip_addr_to_str(a, n): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 348 | if n is not None: |
| 349 | a = a & ~((1 << (32 - n)) - 1) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 350 | result = "%d.%d.%d.%d" % (a >> 24, \ |
| 351 | (a >> 16) & 0xff, \ |
| 352 | (a >> 8) & 0xff, \ |
| 353 | a & 0xff \ |
| 354 | ) |
| 355 | if n is not None: |
| 356 | result = result + ("/%d" % (n)) |
| 357 | return result |
| 358 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 359 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 360 | class Flow_Cfg: |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 361 | # Members: |
| 362 | # - match |
| 363 | # - idle_timeout |
| 364 | # - hard_timeout |
| 365 | # - priority |
| 366 | # - action_list |
| 367 | |
| 368 | def __init__(self): |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 369 | self.priority = 0 |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 370 | self.match = parse.ofp_match() |
| 371 | self.match.wildcards = ofp.OFPFW_ALL |
| 372 | self.idle_timeout = 0 |
| 373 | self.hard_timeout = 0 |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 374 | self.actions = action_list.action_list() |
| 375 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 376 | # {pri, match} is considered a flow key |
| 377 | def key_equal(self, x): |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 378 | if self.priority != x.priority: |
| 379 | return False |
| 380 | # TBD - Should this logic be moved to ofp_match.__eq__()? |
| 381 | if self.match.wildcards != x.match.wildcards: |
| 382 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 383 | if wildcard_get(self.match.wildcards, ofp.OFPFW_IN_PORT) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 384 | and self.match.in_port != x.match.in_port: |
| 385 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 386 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_DST) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 387 | and self.match.dl_dst != x.match.dl_dst: |
| 388 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 389 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_SRC) == 0 \ |
| 390 | and self.match.dl_src != x.match.dl_src: |
| 391 | return False |
| 392 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_VLAN) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 393 | and self.match.dl_vlan != x.match.dl_vlan: |
| 394 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 395 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_VLAN_PCP) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 396 | and self.match.dl_vlan_pcp != x.match.dl_vlan_pcp: |
| 397 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 398 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_TYPE) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 399 | and self.match.dl_type != x.match.dl_type: |
| 400 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 401 | if wildcard_get(self.match.wildcards, ofp.OFPFW_NW_TOS) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 402 | and self.match.nw_tos != x.match.nw_tos: |
| 403 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 404 | if wildcard_get(self.match.wildcards, ofp.OFPFW_NW_PROTO) == 0 \ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 405 | and self.match.nw_proto != x.match.nw_proto: |
| 406 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 407 | n = wildcard_get(self.match.wildcards, ofp.OFPFW_NW_SRC_MASK) |
| 408 | if n < 32: |
| 409 | m = ~((1 << n) - 1) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 410 | if (self.match.nw_src & m) != (x.match.nw_src & m): |
| 411 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 412 | n = wildcard_get(self.match.wildcards, ofp.OFPFW_NW_DST_MASK) |
| 413 | if n < 32: |
| 414 | m = ~((1 << n) - 1) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 415 | if (self.match.nw_dst & m) != (x.match.nw_dst & m): |
| 416 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 417 | if wildcard_get(self.match.wildcards, ofp.OFPFW_TP_SRC) == 0 \ |
| 418 | and self.match.tp_src != x.match.tp_src: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 419 | return False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 420 | if wildcard_get(self.match.wildcards, ofp.OFPFW_TP_DST) == 0 \ |
| 421 | and self.match.tp_dst != x.match.tp_dst: |
| 422 | return False |
| 423 | return True |
| 424 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 425 | def actions_equal(self, x): |
| 426 | if test_param_get(fq_config, "conservative_ordered_actions", True): |
| 427 | # Compare actions lists as unordered |
| 428 | |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 429 | aa = copy.deepcopy(x.actions.actions) |
| 430 | for a in self.actions.actions: |
| 431 | i = 0 |
| 432 | while i < len(aa): |
| 433 | if a == aa[i]: |
| 434 | break |
| 435 | i = i + 1 |
| 436 | if i < len(aa): |
| 437 | aa.pop(i) |
| 438 | else: |
| 439 | return False |
| 440 | return aa == [] |
| 441 | else: |
| 442 | return self.actions == x.actions |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 443 | |
| 444 | def non_key_equal(self, x): |
| 445 | if self.cookie != x.cookie: |
| 446 | return False |
| 447 | if self.idle_timeout != x.idle_timeout: |
| 448 | return False |
| 449 | if self.hard_timeout != x.hard_timeout: |
| 450 | return False |
| 451 | return self.actions_equal(x) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 452 | |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 453 | def key_str(self): |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 454 | result = "priority=%d" % self.priority |
| 455 | # TBD - Would be nice if ofp_match.show() was better behaved |
| 456 | # (no newlines), and more intuitive (things in hex where approprate), etc. |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 457 | result = result + (", wildcards=0x%x=%s" \ |
| 458 | % (self.match.wildcards, \ |
| 459 | wildcards_to_str(self.match.wildcards) \ |
| 460 | ) |
| 461 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 462 | if wildcard_get(self.match.wildcards, ofp.OFPFW_IN_PORT) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 463 | result = result + (", in_port=%d" % (self.match.in_port)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 464 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_DST) == 0: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 465 | result = result + (", dl_dst=%s" \ |
| 466 | % (dl_addr_to_str(self.match.dl_dst)) \ |
| 467 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 468 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_SRC) == 0: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 469 | result = result + (", dl_src=%s" \ |
| 470 | % (dl_addr_to_str(self.match.dl_src)) \ |
| 471 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 472 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_VLAN) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 473 | result = result + (", dl_vlan=%d" % (self.match.dl_vlan)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 474 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_VLAN_PCP) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 475 | result = result + (", dl_vlan_pcp=%d" % (self.match.dl_vlan_pcp)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 476 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_TYPE) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 477 | result = result + (", dl_type=0x%x" % (self.match.dl_type)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 478 | if wildcard_get(self.match.wildcards, ofp.OFPFW_NW_TOS) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 479 | result = result + (", nw_tos=0x%x" % (self.match.nw_tos)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 480 | if wildcard_get(self.match.wildcards, ofp.OFPFW_NW_PROTO) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 481 | result = result + (", nw_proto=%d" % (self.match.nw_proto)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 482 | n = wildcard_get(self.match.wildcards, ofp.OFPFW_NW_SRC_MASK) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 483 | if n < 32: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 484 | result = result + (", nw_src=%s" % \ |
| 485 | (ip_addr_to_str(self.match.nw_src, 32 - n)) \ |
| 486 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 487 | n = wildcard_get(self.match.wildcards, ofp.OFPFW_NW_DST_MASK) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 488 | if n < 32: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 489 | result = result + (", nw_dst=%s" % \ |
| 490 | (ip_addr_to_str(self.match.nw_dst, 32 - n)) \ |
| 491 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 492 | if wildcard_get(self.match.wildcards, ofp.OFPFW_TP_SRC) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 493 | result = result + (", tp_src=%d" % self.match.tp_src) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 494 | if wildcard_get(self.match.wildcards, ofp.OFPFW_TP_DST) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 495 | result = result + (", tp_dst=%d" % self.match.tp_dst) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 496 | return result |
| 497 | |
| 498 | def __eq__(self, x): |
| 499 | return (self.key_equal(x) and self.non_key_equal(x)) |
| 500 | |
| 501 | def __str__(self): |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 502 | result = self.key_str() |
| 503 | result = result + (", cookie=%d" % self.cookie) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 504 | result = result + (", idle_timeout=%d" % self.idle_timeout) |
| 505 | result = result + (", hard_timeout=%d" % self.hard_timeout) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 506 | for a in self.actions.actions: |
| 507 | result = result + (", action=%s" % ofp.ofp_action_type_map[a.type]) |
| 508 | if a.type == ofp.OFPAT_OUTPUT: |
| 509 | result = result + ("(%d)" % (a.port)) |
| 510 | elif a.type == ofp.OFPAT_SET_VLAN_VID: |
| 511 | result = result + ("(%d)" % (a.vlan_vid)) |
| 512 | elif a.type == ofp.OFPAT_SET_VLAN_PCP: |
| 513 | result = result + ("(%d)" % (a.vlan_pcp)) |
| 514 | elif a.type == ofp.OFPAT_SET_DL_SRC or a.type == ofp.OFPAT_SET_DL_DST: |
| 515 | result = result + ("(%s)" % (dl_addr_to_str(a.dl_addr))) |
| 516 | elif a.type == ofp.OFPAT_SET_NW_SRC or a.type == ofp.OFPAT_SET_NW_DST: |
| 517 | result = result + ("(%s)" % (ip_addr_to_str(a.nw_addr, None))) |
| 518 | elif a.type == ofp.OFPAT_SET_NW_TOS: |
| 519 | result = result + ("(0x%x)" % (a.nw_tos)) |
| 520 | elif a.type == ofp.OFPAT_SET_TP_SRC or a.type == ofp.OFPAT_SET_TP_DST: |
| 521 | result = result + ("(%d)" % (a.tp_port)) |
| 522 | elif a.type == ofp.OFPAT_ENQUEUE: |
| 523 | result = result + ("(port=%d,queue=%d)" % (a.port, a.queue_id)) |
| 524 | return result |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 525 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 526 | def rand_actions_ordered(self, fi, valid_actions, valid_ports, valid_queues): |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 527 | # Action lists are ordered, so pick an ordered random subset of |
| 528 | # supported actions |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 529 | |
| 530 | actions_force = test_param_get(fq_config, "actions_force", 0) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 531 | if actions_force != 0: |
| 532 | fq_logger.info("Forced actions:") |
| 533 | fq_logger.info(actions_bmap_to_str(actions_force)) |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 534 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 535 | ACTION_MAX_LEN = 65535 # @fixme Should be test param? |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 536 | supported_actions = [] |
| 537 | for a in all_actions_list: |
| 538 | if ((1 << a) & valid_actions) != 0: |
| 539 | supported_actions.append(a) |
| 540 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 541 | actions \ |
| 542 | = shuffle(supported_actions)[0 : random.randint(1, len(supported_actions))] |
| 543 | |
| 544 | for a in all_actions_list: |
| 545 | if ((1 << a) & actions_force) != 0: |
| 546 | actions.append(a) |
| 547 | |
| 548 | actions = shuffle(actions) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 549 | |
Howard Persh | 6a3698d | 2012-08-21 14:26:39 -0700 | [diff] [blame] | 550 | set_vlanf = False |
| 551 | strip_vlanf = False |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 552 | self.actions = action_list.action_list() |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 553 | for a in actions: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 554 | act = None |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 555 | if a == ofp.OFPAT_OUTPUT: |
| 556 | pass # OUTPUT actions must come last |
| 557 | elif a == ofp.OFPAT_SET_VLAN_VID: |
Howard Persh | 6a3698d | 2012-08-21 14:26:39 -0700 | [diff] [blame] | 558 | if not strip_vlanf: |
| 559 | act = action.action_set_vlan_vid() |
| 560 | act.vlan_vid = fi.rand_vlan() |
| 561 | set_vlanf = True |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 562 | elif a == ofp.OFPAT_SET_VLAN_PCP: |
Howard Persh | 6a3698d | 2012-08-21 14:26:39 -0700 | [diff] [blame] | 563 | if not strip_vlanf: |
| 564 | act = action.action_set_vlan_pcp() |
| 565 | act.vlan_pcp = random.randint(0, (1 << 3) - 1) |
| 566 | set_vlanf = True |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 567 | elif a == ofp.OFPAT_STRIP_VLAN: |
Howard Persh | 6a3698d | 2012-08-21 14:26:39 -0700 | [diff] [blame] | 568 | if not set_vlanf: |
| 569 | act = action.action_strip_vlan() |
| 570 | strip_vlanf = True |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 571 | elif a == ofp.OFPAT_SET_DL_SRC: |
| 572 | act = action.action_set_dl_src() |
| 573 | act.dl_addr = fi.rand_dl_addr() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 574 | elif a == ofp.OFPAT_SET_DL_DST: |
| 575 | act = action.action_set_dl_dst() |
| 576 | act.dl_addr = fi.rand_dl_addr() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 577 | elif a == ofp.OFPAT_SET_NW_SRC: |
| 578 | act = action.action_set_nw_src() |
| 579 | act.nw_addr = fi.rand_ip_addr() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 580 | elif a == ofp.OFPAT_SET_NW_DST: |
| 581 | act = action.action_set_nw_dst() |
| 582 | act.nw_addr = fi.rand_ip_addr() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 583 | elif a == ofp.OFPAT_SET_NW_TOS: |
| 584 | act = action.action_set_nw_tos() |
| 585 | act.nw_tos = fi.rand_ip_tos() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 586 | elif a == ofp.OFPAT_SET_TP_SRC: |
| 587 | act = action.action_set_tp_src() |
| 588 | act.tp_port = fi.rand_l4_port() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 589 | elif a == ofp.OFPAT_SET_TP_DST: |
| 590 | act = action.action_set_tp_dst() |
| 591 | act.tp_port = fi.rand_l4_port() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 592 | elif a == ofp.OFPAT_ENQUEUE: |
| 593 | pass # Enqueue actions must come last |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 594 | if act: |
| 595 | act.max_len = ACTION_MAX_LEN |
| 596 | self.actions.add(act) |
| 597 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 598 | p = random.randint(1, 100) |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 599 | if (((1 << ofp.OFPAT_ENQUEUE) & actions_force) != 0 or p <= 33) \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 600 | and len(valid_queues) > 0 \ |
| 601 | and ofp.OFPAT_ENQUEUE in actions: |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 602 | # In not forecd, one third of the time, include ENQUEUE actions |
| 603 | # at end of list |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 604 | # At most 1 ENQUEUE action |
| 605 | act = action.action_enqueue() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 606 | (act.port, act.queue_id) = rand_pick(valid_queues) |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 607 | act.max_len = ACTION_MAX_LEN |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 608 | self.actions.add(act) |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 609 | if (((1 << ofp.OFPAT_OUTPUT) & actions_force) != 0 \ |
| 610 | or (p > 33 and p <= 66) \ |
| 611 | ) \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 612 | and len(valid_ports) > 0 \ |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 613 | and ofp.OFPAT_OUTPUT in actions: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 614 | # One third of the time, include OUTPUT actions at end of list |
| 615 | port_idxs = shuffle(range(len(valid_ports))) |
| 616 | # Only 1 output action allowed if IN_PORT wildcarded |
| 617 | n = 1 if wildcard_get(self.match.wildcards, ofp.OFPFW_IN_PORT) != 0 \ |
| 618 | else random.randint(1, len(valid_ports)) |
| 619 | port_idxs = port_idxs[0 : n] |
| 620 | for pi in port_idxs: |
| 621 | act = action.action_output() |
| 622 | act.port = valid_ports[pi] |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 623 | act.max_len = ACTION_MAX_LEN |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 624 | if act.port != ofp.OFPP_IN_PORT \ |
| 625 | or wildcard_get(self.match.wildcards, ofp.OFPFW_IN_PORT) == 0: |
| 626 | # OUTPUT(IN_PORT) only valid if OFPFW_IN_PORT not wildcarded |
| 627 | self.actions.add(act) |
| 628 | else: |
| 629 | # One third of the time, include neither |
| 630 | pass |
| 631 | |
| 632 | |
| 633 | # Randomize flow data for flow modifies (i.e. cookie and actions) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 634 | def rand_mod(self, fi, valid_actions, valid_ports, valid_queues): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 635 | self.cookie = random.randint(0, (1 << 53) - 1) |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 636 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 637 | # By default, test with conservative ordering conventions |
| 638 | # This should probably be indicated in a profile |
| 639 | if test_param_get(fq_config, "conservative_ordered_actions", True): |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 640 | self.rand_actions_ordered(fi, valid_actions, valid_ports, valid_queues) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 641 | return self |
| 642 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 643 | actions_force = test_param_get(fq_config, "actions_force", 0) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 644 | if actions_force != 0: |
| 645 | fq_logger.info("Forced actions:") |
| 646 | fq_logger.info(actions_bmap_to_str(actions_force)) |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 647 | |
| 648 | ACTION_MAX_LEN = 65535 # @fixme Should be test param? |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 649 | supported_actions = [] |
| 650 | for a in all_actions_list: |
| 651 | if ((1 << a) & valid_actions) != 0: |
| 652 | supported_actions.append(a) |
| 653 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 654 | actions \ |
| 655 | = shuffle(supported_actions)[0 : random.randint(1, len(supported_actions))] |
| 656 | |
| 657 | for a in all_actions_list: |
| 658 | if ((1 << a) & actions_force) != 0: |
| 659 | actions.append(a) |
| 660 | |
| 661 | actions = shuffle(actions) |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 662 | |
| 663 | self.actions = action_list.action_list() |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 664 | for a in actions: |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 665 | if a == ofp.OFPAT_OUTPUT: |
| 666 | # TBD - Output actions are clustered in list, spread them out? |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 667 | if len(valid_ports) == 0: |
| 668 | continue |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 669 | port_idxs = shuffle(range(len(valid_ports))) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 670 | port_idxs = port_idxs[0 : random.randint(1, len(valid_ports))] |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 671 | for pi in port_idxs: |
| 672 | act = action.action_output() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 673 | act.port = valid_ports[pi] |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 674 | self.actions.add(act) |
| 675 | elif a == ofp.OFPAT_SET_VLAN_VID: |
| 676 | act = action.action_set_vlan_vid() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 677 | act.vlan_vid = fi.rand_vlan() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 678 | self.actions.add(act) |
| 679 | elif a == ofp.OFPAT_SET_VLAN_PCP: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 680 | act = action.action_set_vlan_pcp() |
| 681 | act.vlan_pcp = random.randint(0, (1 << 3) - 1) |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 682 | elif a == ofp.OFPAT_STRIP_VLAN: |
| 683 | act = action.action_strip_vlan() |
| 684 | self.actions.add(act) |
| 685 | elif a == ofp.OFPAT_SET_DL_SRC: |
| 686 | act = action.action_set_dl_src() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 687 | act.dl_addr = fi.rand_dl_addr() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 688 | self.actions.add(act) |
| 689 | elif a == ofp.OFPAT_SET_DL_DST: |
| 690 | act = action.action_set_dl_dst() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 691 | act.dl_addr = fi.rand_dl_addr() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 692 | self.actions.add(act) |
| 693 | elif a == ofp.OFPAT_SET_NW_SRC: |
| 694 | act = action.action_set_nw_src() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 695 | act.nw_addr = fi.rand_ip_addr() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 696 | self.actions.add(act) |
| 697 | elif a == ofp.OFPAT_SET_NW_DST: |
| 698 | act = action.action_set_nw_dst() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 699 | act.nw_addr = fi.rand_ip_addr() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 700 | self.actions.add(act) |
| 701 | elif a == ofp.OFPAT_SET_NW_TOS: |
| 702 | act = action.action_set_nw_tos() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 703 | act.nw_tos = fi.rand_ip_tos() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 704 | self.actions.add(act) |
| 705 | elif a == ofp.OFPAT_SET_TP_SRC: |
| 706 | act = action.action_set_tp_src() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 707 | act.tp_port = fi.rand_l4_port() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 708 | self.actions.add(act) |
| 709 | elif a == ofp.OFPAT_SET_TP_DST: |
| 710 | act = action.action_set_tp_dst() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 711 | act.tp_port = fi.rand_l4_port() |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 712 | self.actions.add(act) |
| 713 | elif a == ofp.OFPAT_ENQUEUE: |
| 714 | # TBD - Enqueue actions are clustered in list, spread them out? |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 715 | if len(valid_queues) == 0: |
| 716 | continue |
| 717 | qidxs = shuffle(range(len(valid_queues))) |
| 718 | qidxs = qidxs[0 : random.randint(1, len(valid_queues))] |
| 719 | for qi in qidxs: |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 720 | act = action.action_enqueue() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 721 | (act.port, act.queue_id) = valid_queues[qi] |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 722 | self.actions.add(act) |
| 723 | |
| 724 | return self |
| 725 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 726 | # Randomize flow cfg |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 727 | def rand(self, fi, wildcards_force, valid_wildcards, valid_actions, valid_ports, |
| 728 | valid_queues): |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 729 | if wildcards_force != 0: |
| 730 | fq_logger.info("Wildcards forced:") |
| 731 | fq_logger.info(wildcards_to_str(wildcards_force)) |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 732 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 733 | # Start with no wildcards, i.e. everything specified |
| 734 | self.match.wildcards = 0 |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 735 | |
| 736 | if wildcards_force != 0: |
| 737 | exact = False |
| 738 | else: |
| 739 | # Make approx. 5% of flows exact |
| 740 | exact = (random.randint(1, 100) <= 5) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 741 | |
| 742 | # For each qualifier Q, |
| 743 | # if (wildcarding is not supported for Q, |
| 744 | # or an exact flow is specified |
| 745 | # or a coin toss comes up heads), |
| 746 | # specify Q |
| 747 | # else |
| 748 | # wildcard Q |
| 749 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 750 | if wildcard_get(wildcards_force, ofp.OFPFW_IN_PORT) == 0 \ |
| 751 | and (wildcard_get(valid_wildcards, ofp.OFPFW_IN_PORT) == 0 \ |
| 752 | or exact \ |
| 753 | or flip_coin() \ |
| 754 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 755 | self.match.in_port = rand_pick(valid_ports) |
| 756 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 757 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 758 | ofp.OFPFW_IN_PORT, \ |
| 759 | 1 \ |
| 760 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 761 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 762 | if wildcard_get(wildcards_force, ofp.OFPFW_DL_DST) == 0 \ |
| 763 | and (wildcard_get(valid_wildcards, ofp.OFPFW_DL_DST) == 0 \ |
| 764 | or exact \ |
| 765 | or flip_coin() \ |
| 766 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 767 | self.match.dl_dst = fi.rand_dl_addr() |
| 768 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 769 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 770 | ofp.OFPFW_DL_DST, \ |
| 771 | 1 \ |
| 772 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 773 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 774 | if wildcard_get(wildcards_force, ofp.OFPFW_DL_SRC) == 0 \ |
| 775 | and (wildcard_get(valid_wildcards, ofp.OFPFW_DL_SRC) == 0 \ |
| 776 | or exact \ |
| 777 | or flip_coin() \ |
| 778 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 779 | self.match.dl_src = fi.rand_dl_addr() |
| 780 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 781 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 782 | ofp.OFPFW_DL_SRC, \ |
| 783 | 1 \ |
| 784 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 785 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 786 | if wildcard_get(wildcards_force, ofp.OFPFW_DL_VLAN) == 0 \ |
| 787 | and (wildcard_get(valid_wildcards, ofp.OFPFW_DL_VLAN) == 0 \ |
| 788 | or exact \ |
| 789 | or flip_coin() \ |
| 790 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 791 | self.match.dl_vlan = fi.rand_vlan() |
| 792 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 793 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 794 | ofp.OFPFW_DL_VLAN, \ |
| 795 | 1 \ |
| 796 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 797 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 798 | if wildcard_get(wildcards_force, ofp.OFPFW_DL_VLAN_PCP) == 0 \ |
| 799 | and (wildcard_get(valid_wildcards, ofp.OFPFW_DL_VLAN_PCP) == 0 \ |
| 800 | or exact \ |
| 801 | or flip_coin() \ |
| 802 | ): |
| 803 | self.match.dl_vlan_pcp = random.randint(0, (1 << 3) - 1) |
| 804 | else: |
| 805 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 806 | ofp.OFPFW_DL_VLAN_PCP, \ |
| 807 | 1 \ |
| 808 | ) |
| 809 | |
| 810 | if wildcard_get(wildcards_force, ofp.OFPFW_DL_TYPE) == 0 \ |
| 811 | and (wildcard_get(valid_wildcards, ofp.OFPFW_DL_TYPE) == 0 \ |
| 812 | or exact \ |
| 813 | or flip_coin() \ |
| 814 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 815 | self.match.dl_type = fi.rand_ethertype() |
| 816 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 817 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 818 | ofp.OFPFW_DL_TYPE, \ |
| 819 | 1 \ |
| 820 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 821 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 822 | n = wildcard_get(wildcards_force, ofp.OFPFW_NW_SRC_MASK) |
| 823 | if n == 0: |
| 824 | if exact or flip_coin(): |
| 825 | n = 0 |
| 826 | else: |
| 827 | n = wildcard_get(valid_wildcards, ofp.OFPFW_NW_SRC_MASK) |
| 828 | if n > 32: |
| 829 | n = 32 |
| 830 | n = random.randint(0, n) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 831 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 832 | ofp.OFPFW_NW_SRC_MASK, \ |
| 833 | n \ |
| 834 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 835 | if n < 32: |
| 836 | self.match.nw_src = fi.rand_ip_addr() & ~((1 << n) - 1) |
| 837 | # Specifying any IP address match other than all bits |
| 838 | # don't care requires that Ethertype is one of {IP, ARP} |
| 839 | if flip_coin(): |
| 840 | self.match.dl_type = rand_pick([0x0800, 0x0806]) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 841 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 842 | ofp.OFPFW_DL_TYPE, \ |
| 843 | 0 \ |
| 844 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 845 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 846 | n = wildcard_get(wildcards_force, ofp.OFPFW_NW_DST_MASK) |
| 847 | if n == 0: |
| 848 | if exact or flip_coin(): |
| 849 | n = 0 |
| 850 | else: |
| 851 | n = wildcard_get(valid_wildcards, ofp.OFPFW_NW_DST_MASK) |
| 852 | if n > 32: |
| 853 | n = 32 |
| 854 | n = random.randint(0, n) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 855 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 856 | ofp.OFPFW_NW_DST_MASK, \ |
| 857 | n \ |
| 858 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 859 | if n < 32: |
| 860 | self.match.nw_dst = fi.rand_ip_addr() & ~((1 << n) - 1) |
| 861 | # Specifying any IP address match other than all bits |
| 862 | # don't care requires that Ethertype is one of {IP, ARP} |
| 863 | if flip_coin(): |
| 864 | self.match.dl_type = rand_pick([0x0800, 0x0806]) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 865 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 866 | ofp.OFPFW_DL_TYPE, \ |
| 867 | 0 \ |
| 868 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 869 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 870 | if wildcard_get(wildcards_force, ofp.OFPFW_NW_TOS) == 0 \ |
| 871 | and (wildcard_get(valid_wildcards, ofp.OFPFW_NW_TOS) == 0 \ |
| 872 | or exact \ |
| 873 | or flip_coin() \ |
| 874 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 875 | self.match.nw_tos = fi.rand_ip_tos() |
| 876 | # Specifying a TOS value requires that Ethertype is IP |
| 877 | if flip_coin(): |
| 878 | self.match.dl_type = 0x0800 |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 879 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 880 | ofp.OFPFW_DL_TYPE, \ |
| 881 | 0 \ |
| 882 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 883 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 884 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 885 | ofp.OFPFW_NW_TOS, \ |
| 886 | 1 \ |
| 887 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 888 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 889 | # Known issue on OVS with specifying nw_proto w/o dl_type as IP |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 890 | if wildcard_get(wildcards_force, ofp.OFPFW_NW_PROTO) == 0 \ |
| 891 | and (wildcard_get(valid_wildcards, ofp.OFPFW_NW_PROTO) == 0 \ |
| 892 | or exact \ |
| 893 | or flip_coin() \ |
| 894 | ): |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 895 | self.match.nw_proto = fi.rand_ip_proto() |
| 896 | # Specifying an IP protocol requires that Ethertype is IP |
| 897 | if flip_coin(): |
| 898 | self.match.dl_type = 0x0800 |
| 899 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 900 | ofp.OFPFW_DL_TYPE, \ |
| 901 | 0 \ |
| 902 | ) |
| 903 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 904 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 905 | ofp.OFPFW_NW_PROTO, \ |
| 906 | 1 \ |
| 907 | ) |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 908 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 909 | if wildcard_get(wildcards_force, ofp.OFPFW_TP_SRC) == 0 \ |
| 910 | and (wildcard_get(valid_wildcards, ofp.OFPFW_TP_SRC) == 0 \ |
| 911 | or exact\ |
| 912 | or flip_coin() \ |
| 913 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 914 | self.match.tp_src = fi.rand_l4_port() |
| 915 | # Specifying a L4 port requires that IP protcol is |
| 916 | # one of {ICMP, TCP, UDP} |
| 917 | if flip_coin(): |
| 918 | self.match.nw_proto = rand_pick([1, 6, 17]) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 919 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 920 | ofp.OFPFW_NW_PROTO, \ |
| 921 | 0 \ |
| 922 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 923 | # Specifying a L4 port requirues that Ethertype is IP |
| 924 | self.match.dl_type = 0x0800 |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 925 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 926 | ofp.OFPFW_DL_TYPE, \ |
| 927 | 0 \ |
| 928 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 929 | if self.match.nw_proto == 1: |
| 930 | self.match.tp_src = self.match.tp_src & 0xff |
| 931 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 932 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 933 | ofp.OFPFW_TP_SRC, \ |
| 934 | 1 \ |
| 935 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 936 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 937 | if wildcard_get(wildcards_force, ofp.OFPFW_TP_DST) == 0 \ |
| 938 | and (wildcard_get(valid_wildcards, ofp.OFPFW_TP_DST) == 0 \ |
| 939 | or exact \ |
| 940 | or flip_coin() \ |
| 941 | ): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 942 | self.match.tp_dst = fi.rand_l4_port() |
| 943 | # Specifying a L4 port requires that IP protcol is |
| 944 | # one of {ICMP, TCP, UDP} |
| 945 | if flip_coin(): |
| 946 | self.match.nw_proto = rand_pick([1, 6, 17]) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 947 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 948 | ofp.OFPFW_NW_PROTO, \ |
| 949 | 0 \ |
| 950 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 951 | # Specifying a L4 port requirues that Ethertype is IP |
| 952 | self.match.dl_type = 0x0800 |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 953 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 954 | ofp.OFPFW_DL_TYPE, \ |
| 955 | 0 \ |
| 956 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 957 | if self.match.nw_proto == 1: |
| 958 | self.match.tp_dst = self.match.tp_dst & 0xff |
| 959 | else: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 960 | self.match.wildcards = wildcard_set(self.match.wildcards, \ |
| 961 | ofp.OFPFW_TP_DST, \ |
| 962 | 1 \ |
| 963 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 964 | |
| 965 | # If nothing is wildcarded, it is an exact flow spec -- some switches |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 966 | # (Open vSwitch, for one) *require* that exact flow specs |
| 967 | # have priority 65535. |
| 968 | self.priority = 65535 if self.match.wildcards == 0 \ |
| 969 | else fi.rand_priority() |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 970 | |
| 971 | # N.B. Don't make the timeout too short, else the flow might |
| 972 | # disappear before we get a chance to check for it. |
| 973 | t = random.randint(0, 65535) |
| 974 | self.idle_timeout = 0 if t < 60 else t |
| 975 | t = random.randint(0, 65535) |
| 976 | self.hard_timeout = 0 if t < 60 else t |
| 977 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 978 | self.rand_mod(fi, valid_actions, valid_ports, valid_queues) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 979 | |
| 980 | return self |
| 981 | |
| 982 | # Return flow cfg in canonical form |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 983 | # - There are dependencies between flow qualifiers, e.g. it only makes |
| 984 | # sense to qualify nw_proto if dl_type is qualified to be 0x0800 (IP). |
| 985 | # The canonical form of flow match criteria will "wildcard out" |
| 986 | # all such cases. |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 987 | def canonical(self): |
| 988 | result = copy.deepcopy(self) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 989 | |
| 990 | if wildcard_get(result.match.wildcards, ofp.OFPFW_DL_VLAN) != 0: |
| 991 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 992 | ofp.OFPFW_DL_VLAN_PCP, \ |
| 993 | 1 \ |
| 994 | ) |
| 995 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 996 | if wildcard_get(result.match.wildcards, ofp.OFPFW_DL_TYPE) != 0 \ |
| 997 | or result.match.dl_type not in [0x0800, 0x0806]: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 998 | # dl_tyoe is wildcarded, or specified as something other |
| 999 | # than IP or ARP |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1000 | # => nw_src, nw_dst, nw_proto cannot be specified, |
| 1001 | # must be wildcarded |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1002 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1003 | ofp.OFPFW_NW_SRC_MASK, \ |
| 1004 | 32 \ |
| 1005 | ) |
| 1006 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1007 | ofp.OFPFW_NW_DST_MASK, \ |
| 1008 | 32 \ |
| 1009 | ) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1010 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1011 | ofp.OFPFW_NW_PROTO, \ |
| 1012 | 1 \ |
| 1013 | ) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1014 | |
| 1015 | if wildcard_get(result.match.wildcards, ofp.OFPFW_DL_TYPE) != 0 \ |
| 1016 | or result.match.dl_type != 0x0800: |
| 1017 | # dl_type is wildcarded, or specified as something other than IP |
| 1018 | # => nw_tos, tp_src and tp_dst cannot be specified, |
| 1019 | # must be wildcarded |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1020 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1021 | ofp.OFPFW_NW_TOS, \ |
| 1022 | 1 \ |
| 1023 | ) |
| 1024 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1025 | ofp.OFPFW_TP_SRC, \ |
| 1026 | 1 \ |
| 1027 | ) |
| 1028 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1029 | ofp.OFPFW_TP_DST, \ |
| 1030 | 1 \ |
| 1031 | ) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1032 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1033 | ofp.OFPFW_NW_SRC_MASK, \ |
| 1034 | 32 \ |
| 1035 | ) |
| 1036 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1037 | ofp.OFPFW_NW_DST_MASK, \ |
| 1038 | 32 \ |
| 1039 | ) |
| 1040 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1041 | ofp.OFPFW_NW_PROTO, \ |
| 1042 | 1 \ |
| 1043 | ) |
| 1044 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1045 | if wildcard_get(result.match.wildcards, ofp.OFPFW_NW_PROTO) != 0 \ |
| 1046 | or result.match.nw_proto not in [1, 6, 17]: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1047 | # nw_proto is wildcarded, or specified as something other than ICMP, |
| 1048 | # TCP or UDP |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1049 | # => tp_src and tp_dst cannot be specified, must be wildcarded |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1050 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1051 | ofp.OFPFW_TP_SRC, \ |
| 1052 | 1 \ |
| 1053 | ) |
| 1054 | result.match.wildcards = wildcard_set(result.match.wildcards, \ |
| 1055 | ofp.OFPFW_TP_DST, \ |
| 1056 | 1 \ |
| 1057 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1058 | return result |
| 1059 | |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1060 | # Overlap check |
| 1061 | # delf == True <=> Check for delete overlap, else add overlap |
| 1062 | # "Add overlap" is defined as there exists a packet that could match both the |
| 1063 | # receiver and argument flowspecs |
| 1064 | # "Delete overlap" is defined as the specificity of the argument flowspec |
| 1065 | # is greater than or equal to the specificity of the receiver flowspec |
| 1066 | def overlaps(self, x, delf): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1067 | if wildcard_get(self.match.wildcards, ofp.OFPFW_IN_PORT) == 0: |
| 1068 | if wildcard_get(x.match.wildcards, ofp.OFPFW_IN_PORT) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1069 | if self.match.in_port != x.match.in_port: |
| 1070 | return False # Both specified, and not equal |
| 1071 | elif delf: |
| 1072 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1073 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_VLAN) == 0: |
| 1074 | if wildcard_get(x.match.wildcards, ofp.OFPFW_DL_VLAN) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1075 | if self.match.dl_vlan != x.match.dl_vlan: |
| 1076 | return False # Both specified, and not equal |
| 1077 | elif delf: |
| 1078 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1079 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_SRC) == 0: |
| 1080 | if wildcard_get(x.match.wildcards, ofp.OFPFW_DL_SRC) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1081 | if self.match.dl_src != x.match.dl_src: |
| 1082 | return False # Both specified, and not equal |
| 1083 | elif delf: |
| 1084 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1085 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_DST) == 0: |
| 1086 | if wildcard_get(x.match.wildcards, ofp.OFPFW_DL_DST) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1087 | if self.match.dl_dst != x.match.dl_dst: |
| 1088 | return False # Both specified, and not equal |
| 1089 | elif delf: |
| 1090 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1091 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_TYPE) == 0: |
| 1092 | if wildcard_get(x.match.wildcards, ofp.OFPFW_DL_TYPE) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1093 | if self.match.dl_type != x.match.dl_type: |
| 1094 | return False # Both specified, and not equal |
| 1095 | elif delf: |
| 1096 | return False # Recevier more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1097 | if wildcard_get(self.match.wildcards, ofp.OFPFW_NW_PROTO) == 0: |
| 1098 | if wildcard_get(x.match.wildcards, ofp.OFPFW_NW_PROTO) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1099 | if self.match.nw_proto != x.match.nw_proto: |
| 1100 | return False # Both specified, and not equal |
| 1101 | elif delf: |
| 1102 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1103 | if wildcard_get(self.match.wildcards, ofp.OFPFW_TP_SRC) == 0: |
| 1104 | if wildcard_get(x.match.wildcards, ofp.OFPFW_TP_SRC) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1105 | if self.match.tp_src != x.match.tp_src: |
| 1106 | return False # Both specified, and not equal |
| 1107 | elif delf: |
| 1108 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1109 | if wildcard_get(self.match.wildcards, ofp.OFPFW_TP_DST) == 0: |
| 1110 | if wildcard_get(x.match.wildcards, ofp.OFPFW_TP_DST) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1111 | if self.match.tp_dst != x.match.tp_dst: |
| 1112 | return False # Both specified, and not equal |
| 1113 | elif delf: |
| 1114 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1115 | na = wildcard_get(self.match.wildcards, ofp.OFPFW_NW_SRC_MASK) |
| 1116 | nb = wildcard_get(x.match.wildcards, ofp.OFPFW_NW_SRC_MASK) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1117 | if delf and na < nb: |
| 1118 | return False # Receiver more specific |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1119 | if (na < 32 and nb < 32): |
| 1120 | m = ~((1 << na) - 1) & ~((1 << nb) - 1) |
| 1121 | if (self.match.nw_src & m) != (x.match.nw_src & m): |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1122 | return False # Overlapping bits not equal |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1123 | na = wildcard_get(self.match.wildcards, ofp.OFPFW_NW_DST_MASK) |
| 1124 | nb = wildcard_get(x.match.wildcards, ofp.OFPFW_NW_DST_MASK) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1125 | if delf and na < nb: |
| 1126 | return False # Receiver more specific |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1127 | if (na < 32 and nb < 32): |
| 1128 | m = ~((1 << na) - 1) & ~((1 << nb) - 1) |
| 1129 | if (self.match.nw_dst & m) != (x.match.nw_dst & m): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1130 | return False # Overlapping bits not equal |
| 1131 | if wildcard_get(self.match.wildcards, ofp.OFPFW_DL_VLAN_PCP) == 0: |
| 1132 | if wildcard_get(x.match.wildcards, ofp.OFPFW_DL_VLAN_PCP) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1133 | if self.match.dl_vlan_pcp != x.match.dl_vlan_pcp: |
| 1134 | return False # Both specified, and not equal |
| 1135 | elif delf: |
| 1136 | return False # Receiver more specific |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1137 | if wildcard_get(self.match.wildcards, ofp.OFPFW_NW_TOS) == 0: |
| 1138 | if wildcard_get(x.match.wildcards, ofp.OFPFW_NW_TOS) == 0: |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1139 | if self.match.nw_tos != x.match.nw_tos: |
| 1140 | return False # Both specified, and not equal |
| 1141 | elif delf: |
| 1142 | return False # Receiver more specific |
| 1143 | return True # Flows overlap |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1144 | |
| 1145 | def to_flow_mod_msg(self, msg): |
| 1146 | msg.match = self.match |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1147 | msg.cookie = self.cookie |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1148 | msg.idle_timeout = self.idle_timeout |
| 1149 | msg.hard_timeout = self.hard_timeout |
| 1150 | msg.priority = self.priority |
| 1151 | msg.actions = self.actions |
| 1152 | return msg |
| 1153 | |
| 1154 | def from_flow_stat(self, msg): |
| 1155 | self.match = msg.match |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1156 | self.cookie = msg.cookie |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1157 | self.idle_timeout = msg.idle_timeout |
| 1158 | self.hard_timeout = msg.hard_timeout |
| 1159 | self.priority = msg.priority |
| 1160 | self.actions = msg.actions |
| 1161 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1162 | def from_flow_rem(self, msg): |
| 1163 | self.match = msg.match |
| 1164 | self.idle_timeout = msg.idle_timeout |
| 1165 | self.priority = msg.priority |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1166 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1167 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1168 | class Flow_Tbl: |
| 1169 | def clear(self): |
| 1170 | self.dict = {} |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1171 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1172 | def __init__(self): |
| 1173 | self.clear() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1174 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1175 | def find(self, f): |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 1176 | return self.dict.get(f.key_str(), None) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1177 | |
| 1178 | def insert(self, f): |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 1179 | self.dict[f.key_str()] = f |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1180 | |
| 1181 | def delete(self, f): |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 1182 | del self.dict[f.key_str()] |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1183 | |
| 1184 | def values(self): |
| 1185 | return self.dict.values() |
| 1186 | |
| 1187 | def count(self): |
| 1188 | return len(self.dict) |
| 1189 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1190 | def rand(self, wildcards_force, sw, fi, num_flows): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1191 | self.clear() |
| 1192 | i = 0 |
| 1193 | tbl = 0 |
| 1194 | j = 0 |
| 1195 | while i < num_flows: |
| 1196 | fc = Flow_Cfg() |
| 1197 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1198 | wildcards_force, \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1199 | sw.tbl_stats.stats[tbl].wildcards, \ |
| 1200 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1201 | sw.valid_ports, \ |
| 1202 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1203 | ) |
| 1204 | fc = fc.canonical() |
| 1205 | if self.find(fc): |
| 1206 | continue |
| 1207 | fc.send_rem = False |
| 1208 | self.insert(fc) |
| 1209 | i = i + 1 |
| 1210 | j = j + 1 |
| 1211 | if j >= sw.tbl_stats.stats[tbl].max_entries: |
| 1212 | tbl = tbl + 1 |
| 1213 | j = 0 |
| 1214 | |
| 1215 | |
| 1216 | class Switch: |
| 1217 | # Members: |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1218 | # controller - switch's test controller |
| 1219 | # sw_features - switch's OFPT_FEATURES_REPLY message |
| 1220 | # valid_ports - list of valid port numbers |
| 1221 | # valid_queues - list of valid [port, queue] pairs |
| 1222 | # tbl_stats - switch's OFPT_STATS_REPLY message, for table stats request |
| 1223 | # queue_stats - switch's OFPT_STATS_REPLY message, for queue stats request |
| 1224 | # flow_stats - switch's OFPT_STATS_REPLY message, for flow stats request |
| 1225 | # flow_tbl - (test's idea of) switch's flow table |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1226 | |
| 1227 | def __init__(self): |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1228 | self.controller = None |
| 1229 | self.sw_features = None |
| 1230 | self.valid_ports = [] |
| 1231 | self.valid_queues = [] |
| 1232 | self.tbl_stats = None |
| 1233 | self.flow_stats = None |
| 1234 | self.flow_tbl = Flow_Tbl() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1235 | self.error_msgs = [] |
| 1236 | self.removed_msgs = [] |
| 1237 | |
| 1238 | def error_handler(self, controller, msg, rawmsg): |
| 1239 | fq_logger.info("Got an ERROR message, type=%d, code=%d" \ |
| 1240 | % (msg.type, msg.code) \ |
| 1241 | ) |
| 1242 | fq_logger.info("Message header:") |
| 1243 | fq_logger.info(msg.header.show()) |
| 1244 | self.error_msgs.append(msg) |
| 1245 | |
| 1246 | def removed_handler(self, controller, msg, rawmsg): |
| 1247 | fq_logger.info("Got a REMOVED message") |
| 1248 | fq_logger.info("Message header:") |
| 1249 | fq_logger.info(msg.header.show()) |
| 1250 | self.removed_msgs.append(msg) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1251 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1252 | def controller_set(self, controller): |
| 1253 | self.controller = controller |
| 1254 | # Register error message handler |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1255 | self.error_msgs = [] |
| 1256 | self.removed_msgs = [] |
| 1257 | controller.register(ofp.OFPT_ERROR, self.error_handler) |
| 1258 | controller.register(ofp.OFPT_FLOW_REMOVED, self.removed_handler) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1259 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1260 | def features_get(self): |
| 1261 | # Get switch features |
| 1262 | request = message.features_request() |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 1263 | (self.sw_features, pkt) = self.controller.transact(request) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1264 | if self.sw_features is None: |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1265 | fq_logger.error("Get switch features failed") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1266 | return False |
| 1267 | self.valid_ports = map(lambda x: x.port_no, self.sw_features.ports) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1268 | fq_logger.info("Ports reported by switch:") |
| 1269 | fq_logger.info(self.valid_ports) |
| 1270 | ports_override = test_param_get(fq_config, "ports", []) |
| 1271 | if ports_override != []: |
| 1272 | fq_logger.info("Overriding ports to:") |
| 1273 | fq_logger.info(ports_override) |
| 1274 | self.valid_ports = ports_override |
| 1275 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1276 | # TBD - OFPP_LOCAL is returned by OVS is switch features -- |
| 1277 | # is that universal? |
| 1278 | |
| 1279 | # TBD - There seems to be variability in which switches support which |
| 1280 | # ports; need to sort that out |
| 1281 | # TBD - Is it legal to enqueue to a special port? Depends on switch? |
| 1282 | # self.valid_ports.extend([ofp.OFPP_IN_PORT, \ |
| 1283 | # ofp.OFPP_NORMAL, \ |
| 1284 | # ofp.OFPP_FLOOD, \ |
| 1285 | # ofp.OFPP_ALL, \ |
| 1286 | # ofp.OFPP_CONTROLLER \ |
| 1287 | # ] \ |
| 1288 | # ) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1289 | fq_logger.info("Supported actions reported by switch:") |
| 1290 | fq_logger.info("0x%x=%s" \ |
| 1291 | % (self.sw_features.actions, \ |
| 1292 | actions_bmap_to_str(self.sw_features.actions) \ |
| 1293 | ) \ |
| 1294 | ) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1295 | actions_override = test_param_get(fq_config, "actions", -1) |
| 1296 | if actions_override != -1: |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1297 | fq_logger.info("Overriding supported actions to:") |
| 1298 | fq_logger.info(actions_bmap_to_str(actions_override)) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1299 | self.sw_features.actions = actions_override |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1300 | return True |
| 1301 | |
| 1302 | def tbl_stats_get(self): |
| 1303 | # Get table stats |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1304 | request = message.table_stats_request() |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 1305 | (self.tbl_stats, pkt) = self.controller.transact(request) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1306 | if self.tbl_stats is None: |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1307 | fq_logger.error("Get table stats failed") |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1308 | return False |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1309 | i = 0 |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1310 | for ts in self.tbl_stats.stats: |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1311 | fq_logger.info("Supported wildcards for table %d reported by switch:" |
| 1312 | % (i) |
| 1313 | ) |
| 1314 | fq_logger.info("0x%x=%s" \ |
| 1315 | % (ts.wildcards, \ |
| 1316 | wildcards_to_str(ts.wildcards) \ |
| 1317 | ) \ |
| 1318 | ) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1319 | wildcards_override = test_param_get(fq_config, "wildcards", -1) |
| 1320 | if wildcards_override != -1: |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1321 | fq_logger.info("Overriding supported wildcards for table %d to:" |
| 1322 | % (i) |
| 1323 | ) |
| 1324 | fq_logger.info(wildcards_to_str(wildcards_override)) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1325 | ts.wildcards = wildcards_override |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1326 | i = i + 1 |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1327 | return True |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1328 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1329 | def queue_stats_get(self): |
| 1330 | # Get queue stats |
| 1331 | request = message.queue_stats_request() |
| 1332 | request.port_no = ofp.OFPP_ALL |
| 1333 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 1334 | (self.queue_stats, pkt) = self.controller.transact(request) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1335 | if self.queue_stats is None: |
| 1336 | fq_logger.error("Get queue stats failed") |
| 1337 | return False |
| 1338 | self.valid_queues = map(lambda x: (x.port_no, x.queue_id), \ |
| 1339 | self.queue_stats.stats \ |
| 1340 | ) |
| 1341 | fq_logger.info("(Port, queue) pairs reported by switch:") |
| 1342 | fq_logger.info(self.valid_queues) |
| 1343 | queues_override = test_param_get(fq_config, "queues", []) |
| 1344 | if queues_override != []: |
| 1345 | fq_logger.info("Overriding (port, queue) pairs to:") |
| 1346 | fq_logger.info(queues_override) |
| 1347 | self.valid_queues = queues_override |
| 1348 | return True |
| 1349 | |
| 1350 | def connect(self, controller): |
| 1351 | # Connect to controller, and get all switch capabilities |
| 1352 | self.controller_set(controller) |
| 1353 | return (self.features_get() \ |
| 1354 | and self.tbl_stats_get() \ |
| 1355 | and self.queue_stats_get() \ |
| 1356 | ) |
| 1357 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1358 | def flow_stats_get(self, limit = 10000): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1359 | request = message.flow_stats_request() |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1360 | query_match = ofp.ofp_match() |
| 1361 | query_match.wildcards = ofp.OFPFW_ALL |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1362 | request.match = query_match |
| 1363 | request.table_id = 0xff |
| 1364 | request.out_port = ofp.OFPP_NONE; |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1365 | if self.controller.message_send(request) == -1: |
| 1366 | return False |
| 1367 | # <TBD> |
| 1368 | # Glue together successive reponse messages for stats reply. |
| 1369 | # Looking at the "more" flag and performing re-assembly |
| 1370 | # should be a part of the infrastructure. |
| 1371 | # </TBD> |
| 1372 | n = 0 |
| 1373 | while True: |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1374 | (resp, pkt) = self.controller.poll(ofp.OFPT_STATS_REPLY, 4) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1375 | if resp is None: |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1376 | return False # Did not get expected response |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1377 | if n == 0: |
| 1378 | self.flow_stats = resp |
| 1379 | else: |
| 1380 | self.flow_stats.stats.extend(resp.stats) |
| 1381 | n = n + 1 |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1382 | if len(self.flow_stats.stats) > limit: |
| 1383 | fq_logger.error("Too many flows returned") |
| 1384 | return False |
| 1385 | if (resp.flags & 1) == 0: |
| 1386 | break # No more responses expected |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1387 | return (n > 0) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1388 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1389 | def flow_add(self, flow_cfg, overlapf = False): |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1390 | flow_mod_msg = message.flow_mod() |
| 1391 | flow_mod_msg.command = ofp.OFPFC_ADD |
| 1392 | flow_mod_msg.buffer_id = 0xffffffff |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1393 | flow_cfg.to_flow_mod_msg(flow_mod_msg) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1394 | if overlapf: |
| 1395 | flow_mod_msg.flags = flow_mod_msg.flags | ofp.OFPFF_CHECK_OVERLAP |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1396 | if flow_cfg.send_rem: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1397 | flow_mod_msg.flags = flow_mod_msg.flags | ofp.OFPFF_SEND_FLOW_REM |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1398 | flow_mod_msg.header.xid = random.randrange(1,0xffffffff) |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1399 | fq_logger.info("Sending flow_mod(add), xid=%d" |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1400 | % (flow_mod_msg.header.xid) |
| 1401 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1402 | return (self.controller.message_send(flow_mod_msg) != -1) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1403 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1404 | def flow_mod(self, flow_cfg, strictf): |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1405 | flow_mod_msg = message.flow_mod() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1406 | flow_mod_msg.command = ofp.OFPFC_MODIFY_STRICT if strictf \ |
| 1407 | else ofp.OFPFC_MODIFY |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1408 | flow_mod_msg.buffer_id = 0xffffffff |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1409 | flow_cfg.to_flow_mod_msg(flow_mod_msg) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1410 | flow_mod_msg.header.xid = random.randrange(1,0xffffffff) |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1411 | fq_logger.info("Sending flow_mod(mod), xid=%d" |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1412 | % (flow_mod_msg.header.xid) |
| 1413 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1414 | return (self.controller.message_send(flow_mod_msg) != -1) |
| 1415 | |
| 1416 | def flow_del(self, flow_cfg, strictf): |
| 1417 | flow_mod_msg = message.flow_mod() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1418 | flow_mod_msg.command = ofp.OFPFC_DELETE_STRICT if strictf \ |
| 1419 | else ofp.OFPFC_DELETE |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1420 | flow_mod_msg.buffer_id = 0xffffffff |
| 1421 | # TBD - "out_port" filtering of deletes needs to be tested |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1422 | flow_mod_msg.out_port = ofp.OFPP_NONE |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1423 | flow_cfg.to_flow_mod_msg(flow_mod_msg) |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1424 | flow_mod_msg.header.xid = random.randrange(1,0xffffffff) |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1425 | fq_logger.info("Sending flow_mod(del), xid=%d" |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1426 | % (flow_mod_msg.header.xid) |
| 1427 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1428 | return (self.controller.message_send(flow_mod_msg) != -1) |
| 1429 | |
| 1430 | def barrier(self): |
| 1431 | barrier = message.barrier_request() |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1432 | (resp, pkt) = self.controller.transact(barrier, 20) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1433 | return (resp is not None) |
| 1434 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1435 | def errors_verify(self, num_exp, type = 0, code = 0): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1436 | result = True |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1437 | fq_logger.info("Expecting %d error messages" % (num_exp)) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1438 | num_got = len(self.error_msgs) |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1439 | fq_logger.info("Got %d error messages" % (num_got)) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1440 | if num_got != num_exp: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1441 | fq_logger.error("Incorrect number of error messages received") |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1442 | result = False |
| 1443 | if num_exp == 0: |
| 1444 | return result |
| 1445 | elif num_exp == 1: |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1446 | fq_logger.info("Expecting error message, type=%d, code=%d" \ |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1447 | % (type, code) \ |
| 1448 | ) |
| 1449 | f = False |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1450 | for e in self.error_msgs: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1451 | if e.type == type and e.code == code: |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1452 | fq_logger.info("Got it") |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1453 | f = True |
| 1454 | if not f: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1455 | fq_logger.error("Did not get it") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1456 | result = False |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1457 | else: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1458 | fq_logger.error("Can't expect more than 1 error message type") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1459 | result = False |
| 1460 | return result |
| 1461 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1462 | def removed_verify(self, num_exp): |
| 1463 | result = True |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1464 | fq_logger.info("Expecting %d removed messages" % (num_exp)) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1465 | num_got = len(self.removed_msgs) |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1466 | fq_logger.info("Got %d removed messages" % (num_got)) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1467 | if num_got != num_exp: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1468 | fq_logger.error("Incorrect number of removed messages received") |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1469 | result = False |
| 1470 | if num_exp < 2: |
| 1471 | return result |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1472 | fq_logger.error("Can't expect more than 1 error message type") |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1473 | return False |
| 1474 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1475 | # modf == True <=> Verify for flow modify, else for add/delete |
| 1476 | def flow_tbl_verify(self, modf = False): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1477 | result = True |
| 1478 | |
| 1479 | # Verify flow count in switch |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1480 | fq_logger.info("Reading table stats") |
| 1481 | fq_logger.info("Expecting %d flows" % (self.flow_tbl.count())) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1482 | if not self.tbl_stats_get(): |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1483 | fq_logger.error("Get table stats failed") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1484 | return False |
| 1485 | n = 0 |
| 1486 | for ts in self.tbl_stats.stats: |
| 1487 | n = n + ts.active_count |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1488 | fq_logger.info("Table stats reported %d active flows" \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1489 | % (n) \ |
| 1490 | ) |
| 1491 | if n != self.flow_tbl.count(): |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1492 | fq_logger.error("Incorrect number of active flows reported") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1493 | result = False |
| 1494 | |
| 1495 | # Read flows from switch |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1496 | fq_logger.info("Retrieving flows from switch") |
| 1497 | fq_logger.info("Expecting %d flows" % (self.flow_tbl.count())) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1498 | if not self.flow_stats_get(): |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1499 | fq_logger.error("Get flow stats failed") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1500 | return False |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1501 | fq_logger.info("Retrieved %d flows" % (len(self.flow_stats.stats))) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1502 | |
| 1503 | # Verify flows returned by switch |
| 1504 | |
| 1505 | if len(self.flow_stats.stats) != self.flow_tbl.count(): |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1506 | fq_logger.error("Switch reported incorrect number of flows") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1507 | result = False |
| 1508 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1509 | fq_logger.info("Verifying received flows") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1510 | for fc in self.flow_tbl.values(): |
| 1511 | fc.matched = False |
| 1512 | for fs in self.flow_stats.stats: |
| 1513 | flow_in = Flow_Cfg() |
| 1514 | flow_in.from_flow_stat(fs) |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1515 | fq_logger.info("Received flow:") |
| 1516 | fq_logger.info(str(flow_in)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1517 | fc = self.flow_tbl.find(flow_in) |
| 1518 | if fc is None: |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1519 | fq_logger.error("Received flow:") |
| 1520 | fq_logger.error(str(flow_in)) |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1521 | fq_logger.error("does not match any defined flow") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1522 | result = False |
| 1523 | elif fc.matched: |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1524 | fq_logger.error("Received flow:") |
| 1525 | fq_logger.error(str(flow_in)) |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1526 | fq_logger.error("re-matches defined flow:") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1527 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1528 | result = False |
| 1529 | else: |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1530 | fq_logger.info("matched") |
| 1531 | if modf: |
| 1532 | # Check for modify |
| 1533 | |
| 1534 | if flow_in.cookie != fc.cookie: |
| 1535 | fq_logger.warning("Defined flow:") |
| 1536 | fq_logger.warning(str(fc)) |
| 1537 | fq_logger.warning("Received flow:") |
| 1538 | fq_logger.warning(str(flow_in)) |
| 1539 | fq_logger.warning("cookies do not match") |
| 1540 | if not flow_in.actions_equal(fc): |
| 1541 | fq_logger.error("Defined flow:") |
| 1542 | fq_logger.error(str(fc)) |
| 1543 | fq_logger.error("Received flow:") |
| 1544 | fq_logger.error(str(flow_in)) |
| 1545 | fq_logger.error("actions do not match") |
| 1546 | else: |
| 1547 | # Check for add/delete |
| 1548 | |
| 1549 | if not flow_in == fc: |
| 1550 | fq_logger.error("Defined flow:") |
| 1551 | fq_logger.error(str(fc)) |
| 1552 | fq_logger.error("Received flow:") |
| 1553 | fq_logger.error(str(flow_in)) |
| 1554 | fq_logger.error("non-key portions of flow do not match") |
| 1555 | result = False |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1556 | fc.matched = True |
| 1557 | for fc in self.flow_tbl.values(): |
| 1558 | if not fc.matched: |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1559 | fq_logger.error("Defined flow:") |
| 1560 | fq_logger.error(str(fc)) |
| 1561 | fq_logger.error("was not returned by switch") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1562 | result = False |
| 1563 | |
| 1564 | return result |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1565 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 1566 | def settle(self): |
| 1567 | time.sleep(2) |
| 1568 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1569 | # FLOW ADD 5 |
| 1570 | # |
| 1571 | # OVERVIEW |
| 1572 | # Add flows to switch, read back and verify flow configurations |
| 1573 | # |
| 1574 | # PURPOSE |
| 1575 | # - Test acceptance of flow adds |
| 1576 | # - Test ability of switch to process additions to flow table in random |
| 1577 | # priority order |
| 1578 | # - Test correctness of flow configuration responses |
| 1579 | # |
| 1580 | # PARAMETERS |
| 1581 | # |
| 1582 | # Name: num_flows |
| 1583 | # Type: number |
| 1584 | # Description: |
| 1585 | # Number of flows to define; 0 => maximum number of flows, as determined |
| 1586 | # from switch capabilities |
| 1587 | # Default: 100 |
| 1588 | # |
| 1589 | # PROCESS |
| 1590 | # 1. Delete all flows from switch |
| 1591 | # 2. Generate <num_flows> distinct flow configurations |
| 1592 | # 3. Send <num_flows> flow adds to switch, for flows generated in step 2 above |
| 1593 | # 4. Verify that no OFPT_ERROR responses were generated by switch |
| 1594 | # 5. Retrieve flow stats from switch |
| 1595 | # 6. Compare flow configurations returned by switch |
| 1596 | # 7. Test PASSED iff all flows sent to switch in step 3 above are returned |
| 1597 | # in step 5 above; else test FAILED |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1598 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1599 | class Flow_Add_5(basic.SimpleProtocol): |
| 1600 | """ |
| 1601 | Test FLOW_ADD_5 from draft top-half test plan |
| 1602 | |
| 1603 | INPUTS |
| 1604 | num_flows - Number of flows to generate |
| 1605 | """ |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1606 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1607 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1608 | fq_logger.info("Flow_Add_5 TEST BEGIN") |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1609 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1610 | num_flows = test_param_get(fq_config, "num_flows", 100) |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1611 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1612 | # Clear all flows from switch |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1613 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1614 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1615 | rc = delete_all_flows(self.controller, fq_logger) |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1616 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 1617 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1618 | # Get switch capabilites |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1619 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1620 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1621 | self.assertTrue(sw.connect(self.controller), \ |
| 1622 | "Failed to connect to switch" \ |
| 1623 | ) |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1624 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1625 | if num_flows == 0: |
| 1626 | # Number of flows requested was 0 |
| 1627 | # => Generate max number of flows |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1628 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1629 | for ts in sw.tbl_stats.stats: |
| 1630 | num_flows = num_flows + ts.max_entries |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1631 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1632 | fq_logger.info("Generating %d flows" % (num_flows)) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1633 | |
| 1634 | # Dream up some flow information, i.e. space to chose from for |
| 1635 | # random flow parameter generation |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1636 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1637 | fi = Flow_Info() |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1638 | fi.rand(max(2 * int(math.log(num_flows)), 1)) |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1639 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1640 | # Create a flow table |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1641 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1642 | ft = Flow_Tbl() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1643 | ft.rand(required_wildcards(self), sw, fi, num_flows) |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1644 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1645 | # Send flow table to switch |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1646 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1647 | fq_logger.info("Sending flow adds to switch") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1648 | for fc in ft.values(): # Randomizes order of sending |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1649 | fq_logger.info("Adding flow:") |
| 1650 | fq_logger.info(str(fc)); |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1651 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1652 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1653 | # Do barrier, to make sure all flows are in |
Howard Persh | 680b92a | 2012-03-31 13:34:35 -0700 | [diff] [blame] | 1654 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1655 | self.assertTrue(sw.barrier(), "Barrier failed") |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1656 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1657 | result = True |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1658 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 1659 | sw.settle() # Allow switch to settle and generate any notifications |
| 1660 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1661 | # Check for any error messages |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1662 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1663 | if not sw.errors_verify(0): |
| 1664 | result = False |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1665 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1666 | # Verify flow table |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1667 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1668 | sw.flow_tbl = ft |
| 1669 | if not sw.flow_tbl_verify(): |
| 1670 | result = False |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1671 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1672 | self.assertTrue(result, "Flow_Add_5 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1673 | fq_logger.info("Flow_Add_5 TEST PASSED") |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1674 | |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1675 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1676 | # FLOW ADD 5_1 |
| 1677 | # |
| 1678 | # OVERVIEW |
| 1679 | # Verify handling of non-canonical flows |
| 1680 | # |
| 1681 | # PURPOSE |
| 1682 | # - Test that switch detects and correctly responds to a non-canonical flow |
| 1683 | # definition. A canonical flow is one that satisfies all match qualifier |
| 1684 | # dependencies; a non-canonical flow is one that does not. |
| 1685 | # |
| 1686 | # PARAMETERS |
| 1687 | # - None |
| 1688 | # |
| 1689 | # PROCESS |
| 1690 | # 1. Delete all flows from switch |
| 1691 | # 2. Generate 1 flow definition, which is different from its canonicalization |
| 1692 | # 3. Send flow to switch |
| 1693 | # 4. Retrieve flow from switch |
| 1694 | # 5. Compare returned flow to canonical form of defined flow |
| 1695 | # 7. Test PASSED iff flow received in step 4 above is identical to canonical form of flow defined in step 3 above |
| 1696 | |
| 1697 | # Disabled. |
| 1698 | # Should be DUT dependent. |
| 1699 | test_prio["Flow_Add_5_1"] = -1 |
| 1700 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1701 | class Flow_Add_5_1(basic.SimpleProtocol): |
| 1702 | """ |
| 1703 | Test FLOW_ADD_5.1 from draft top-half test plan |
| 1704 | |
| 1705 | INPUTS |
| 1706 | None |
| 1707 | """ |
| 1708 | |
| 1709 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1710 | fq_logger.info("Flow_Add_5_1 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1711 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1712 | num_flows = test_param_get(fq_config, "num_flows", 100) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1713 | |
| 1714 | # Clear all flows from switch |
| 1715 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1716 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1717 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1718 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 1719 | |
| 1720 | # Get switch capabilites |
| 1721 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1722 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1723 | self.assertTrue(sw.connect(self.controller), \ |
| 1724 | "Failed to connect to switch" \ |
| 1725 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1726 | |
| 1727 | # Dream up some flow information, i.e. space to chose from for |
| 1728 | # random flow parameter generation |
| 1729 | |
| 1730 | fi = Flow_Info() |
| 1731 | fi.rand(10) |
| 1732 | |
| 1733 | # Dream up a flow config that will be canonicalized by the switch |
| 1734 | |
| 1735 | while True: |
| 1736 | fc = Flow_Cfg() |
| 1737 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1738 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1739 | sw.tbl_stats.stats[0].wildcards, \ |
| 1740 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1741 | sw.valid_ports, \ |
| 1742 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1743 | ) |
| 1744 | fcc = fc.canonical() |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1745 | if fcc.match != fc.match: |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1746 | break |
| 1747 | |
| 1748 | ft = Flow_Tbl() |
| 1749 | ft.insert(fcc) |
| 1750 | |
| 1751 | # Send it to the switch |
| 1752 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1753 | fq_logger.info("Sending flow add to switch:") |
| 1754 | fq_logger.info(str(fc)) |
| 1755 | fq_logger.info("should be canonicalized as:") |
| 1756 | fq_logger.info(str(fcc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1757 | fc.send_rem = False |
| 1758 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 1759 | |
| 1760 | # Do barrier, to make sure all flows are in |
| 1761 | |
| 1762 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 1763 | |
| 1764 | result = True |
| 1765 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 1766 | sw.settle() # Allow switch to settle and generate any notifications |
| 1767 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1768 | # Check for any error messages |
| 1769 | |
| 1770 | if not sw.errors_verify(0): |
| 1771 | result = False |
| 1772 | |
| 1773 | # Verify flow table |
| 1774 | |
| 1775 | sw.flow_tbl = ft |
| 1776 | if not sw.flow_tbl_verify(): |
| 1777 | result = False |
| 1778 | |
| 1779 | self.assertTrue(result, "Flow_Add_5_1 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1780 | fq_logger.info("Flow_Add_5_1 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1781 | |
| 1782 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1783 | # FLOW ADD 6 |
| 1784 | # |
| 1785 | # OVERVIEW |
| 1786 | # Test flow table capacity |
| 1787 | # |
| 1788 | # PURPOSE |
| 1789 | # - Test switch can accept as many flow definitions as it claims |
| 1790 | # - Test generation of OFPET_FLOW_MOD_FAILED/OFPFMFC_ALL_TABLES_FULL |
| 1791 | # - Test that attempting to create flows beyond capacity does not corrupt |
| 1792 | # flow table |
| 1793 | # |
| 1794 | # PARAMETERS |
| 1795 | # None |
| 1796 | # |
| 1797 | # PROCESS |
| 1798 | # 1. Delete all flows from switch |
| 1799 | # 2. Send OFPT_FEATURES_REQUEST and OFPT_STATS_REQUEST/OFPST_TABLE enquiries |
| 1800 | # to determine flow table size, N |
| 1801 | # 3. Generate (N + 1) distinct flow configurations |
| 1802 | # 4. Send N flow adds to switch, for flows generated in step 3 above |
| 1803 | # 5. Verify flow table in switch |
| 1804 | # 6. Send one more flow add to switch |
| 1805 | # 7. Verify that OFPET_FLOW_MOD_FAILED/OFPFMFC_ALL_TABLES_FULL error |
| 1806 | # response was generated by switch, for last flow mod sent |
| 1807 | # 7. Retrieve flow stats from switch |
| 1808 | # 8. Verify flow table in switch |
| 1809 | # 9. Test PASSED iff: |
| 1810 | # - error message received, for correct flow |
| 1811 | # - last flow definition sent to switch is not in flow table |
| 1812 | # else test FAILED |
| 1813 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 1814 | # Disabled because of bogus capacity reported by OVS. |
| 1815 | # Should be DUT dependent. |
| 1816 | test_prio["Flow_Add_6"] = -1 |
| 1817 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1818 | class Flow_Add_6(basic.SimpleProtocol): |
| 1819 | """ |
| 1820 | Test FLOW_ADD_6 from draft top-half test plan |
| 1821 | |
| 1822 | INPUTS |
| 1823 | num_flows - Number of flows to generate |
| 1824 | """ |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1825 | |
| 1826 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1827 | fq_logger.info("Flow_Add_6 TEST BEGIN") |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1828 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1829 | # Clear all flows from switch |
Howard Persh | c796358 | 2012-03-29 10:02:59 -0700 | [diff] [blame] | 1830 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1831 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1832 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1833 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 1834 | |
| 1835 | # Get switch capabilites |
| 1836 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1837 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1838 | self.assertTrue(sw.connect(self.controller), \ |
| 1839 | "Failed to connect to switch" \ |
| 1840 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1841 | |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 1842 | num_flows = 0 |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1843 | for ts in sw.tbl_stats.stats: |
| 1844 | num_flows = num_flows + ts.max_entries |
| 1845 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1846 | fq_logger.info("Switch capacity is %d flows" % (num_flows)) |
| 1847 | fq_logger.info("Generating %d flows" % (num_flows)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1848 | |
| 1849 | # Dream up some flow information, i.e. space to chose from for |
| 1850 | # random flow parameter generation |
| 1851 | |
| 1852 | fi = Flow_Info() |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1853 | fi.rand(max(2 * int(math.log(num_flows)), 1)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1854 | |
| 1855 | # Create a flow table, to switch's capacity |
| 1856 | |
| 1857 | ft = Flow_Tbl() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1858 | ft.rand(required_wildcards(self), sw, fi, num_flows) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1859 | |
| 1860 | # Send flow table to switch |
| 1861 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1862 | fq_logger.info("Sending flow adds to switch") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1863 | for fc in ft.values(): # Randomizes order of sending |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1864 | fq_logger.info("Adding flow:") |
| 1865 | fq_logger.info(str(fc)); |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1866 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 1867 | |
| 1868 | # Do barrier, to make sure all flows are in |
| 1869 | |
| 1870 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 1871 | |
| 1872 | result = True |
| 1873 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 1874 | sw.settle() # Allow switch to settle and generate any notifications |
| 1875 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1876 | # Check for any error messages |
| 1877 | |
| 1878 | if not sw.errors_verify(0): |
| 1879 | result = False |
| 1880 | |
| 1881 | # Dream up one more flow |
| 1882 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1883 | fq_logger.info("Creating one more flow") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1884 | while True: |
| 1885 | fc = Flow_Cfg() |
| 1886 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1887 | required_wildcards(self), \ |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1888 | sw.tbl_stats.stats[0].wildcards, \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1889 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1890 | sw.valid_ports, \ |
| 1891 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1892 | ) |
| 1893 | fc = fc.canonical() |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1894 | if not ft.find(fc): |
| 1895 | break |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1896 | |
| 1897 | # Send one-more flow |
| 1898 | |
| 1899 | fc.send_rem = False |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1900 | fq_logger.info("Sending flow add switch") |
| 1901 | fq_logger.info(str(fc)); |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1902 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 1903 | |
| 1904 | # Do barrier, to make sure all flows are in |
| 1905 | |
| 1906 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 1907 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 1908 | sw.settle() # Allow switch to settle and generate any notifications |
| 1909 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1910 | # Check for expected error message |
| 1911 | |
| 1912 | if not sw.errors_verify(1, \ |
| 1913 | ofp.OFPET_FLOW_MOD_FAILED, \ |
| 1914 | ofp.OFPFMFC_ALL_TABLES_FULL \ |
| 1915 | ): |
| 1916 | result = False |
| 1917 | |
| 1918 | # Verify flow table |
| 1919 | |
| 1920 | sw.flow_tbl = ft |
| 1921 | if not sw.flow_tbl_verify(): |
| 1922 | result = False |
| 1923 | |
| 1924 | self.assertTrue(result, "Flow_add_6 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1925 | fq_logger.info("Flow_add_6 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1926 | |
| 1927 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 1928 | # FLOW ADD 7 |
| 1929 | # |
| 1930 | # OVERVIEW |
| 1931 | # Test flow redefinition |
| 1932 | # |
| 1933 | # PURPOSE |
| 1934 | # Verify that successive flow adds with same priority and match criteria |
| 1935 | # overwrite in flow table |
| 1936 | # |
| 1937 | # PARAMETERS |
| 1938 | # None |
| 1939 | # |
| 1940 | # PROCESS |
| 1941 | # 1. Delete all flows from switch |
| 1942 | # 2. Generate flow definition F1 |
| 1943 | # 3. Generate flow definition F2, with same key (priority and match) as F1, |
| 1944 | # but with different actions |
| 1945 | # 4. Send flow adds for F1 and F2 to switch |
| 1946 | # 5. Verify flow definitions in switch |
| 1947 | # 6. Test PASSED iff 1 flow returned by switch, matching configuration of F2; |
| 1948 | # else test FAILED |
| 1949 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1950 | class Flow_Add_7(basic.SimpleProtocol): |
| 1951 | """ |
| 1952 | Test FLOW_ADD_7 from draft top-half test plan |
| 1953 | |
| 1954 | INPUTS |
| 1955 | None |
| 1956 | """ |
| 1957 | |
| 1958 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1959 | fq_logger.info("Flow_Add_7 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1960 | |
| 1961 | # Clear all flows from switch |
| 1962 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1963 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 1964 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1965 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 1966 | |
| 1967 | # Get switch capabilites |
| 1968 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1969 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1970 | self.assertTrue(sw.connect(self.controller), \ |
| 1971 | "Failed to connect to switch" \ |
| 1972 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1973 | |
| 1974 | # Dream up some flow information, i.e. space to chose from for |
| 1975 | # random flow parameter generation |
| 1976 | |
| 1977 | fi = Flow_Info() |
| 1978 | fi.rand(10) |
| 1979 | |
| 1980 | # Dream up a flow config |
| 1981 | |
| 1982 | fc = Flow_Cfg() |
| 1983 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1984 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1985 | sw.tbl_stats.stats[0].wildcards, \ |
| 1986 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 1987 | sw.valid_ports, \ |
| 1988 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1989 | ) |
| 1990 | fc = fc.canonical() |
| 1991 | |
| 1992 | # Send it to the switch |
| 1993 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 1994 | fq_logger.info("Sending flow add to switch:") |
| 1995 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 1996 | ft = Flow_Tbl() |
| 1997 | fc.send_rem = False |
| 1998 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 1999 | ft.insert(fc) |
| 2000 | |
| 2001 | # Dream up some different actions, with the same flow key |
| 2002 | |
| 2003 | fc2 = copy.deepcopy(fc) |
| 2004 | while True: |
| 2005 | fc2.rand_mod(fi, \ |
| 2006 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2007 | sw.valid_ports, \ |
| 2008 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2009 | ) |
| 2010 | if fc2 != fc: |
| 2011 | break |
| 2012 | |
| 2013 | # Send that to the switch |
| 2014 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2015 | fq_logger.info("Sending flow add to switch:") |
| 2016 | fq_logger.info(str(fc2)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2017 | fc2.send_rem = False |
| 2018 | self.assertTrue(sw.flow_add(fc2), "Failed to add flow") |
| 2019 | ft.insert(fc2) |
| 2020 | |
| 2021 | # Do barrier, to make sure all flows are in |
| 2022 | |
| 2023 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2024 | |
| 2025 | result = True |
| 2026 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2027 | sw.settle() # Allow switch to settle and generate any notifications |
| 2028 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2029 | # Check for any error messages |
| 2030 | |
| 2031 | if not sw.errors_verify(0): |
| 2032 | result = False |
| 2033 | |
| 2034 | # Verify flow table |
| 2035 | |
| 2036 | sw.flow_tbl = ft |
| 2037 | if not sw.flow_tbl_verify(): |
| 2038 | result = False |
| 2039 | |
| 2040 | self.assertTrue(result, "Flow_Add_7 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2041 | fq_logger.info("Flow_Add_7 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2042 | |
| 2043 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2044 | # FLOW ADD 8 |
| 2045 | # |
| 2046 | # OVERVIEW |
| 2047 | # Add overlapping flows to switch, verify that overlapping flows are rejected |
| 2048 | # |
| 2049 | # PURPOSE |
| 2050 | # - Test detection of overlapping flows by switch |
| 2051 | # - Test generation of OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP messages |
| 2052 | # - Test rejection of overlapping flows |
| 2053 | # - Test defining overlapping flows does not corrupt flow table |
| 2054 | # |
| 2055 | # PARAMETERS |
| 2056 | # None |
| 2057 | # |
| 2058 | # PROCESS |
| 2059 | # 1. Delete all flows from switch |
| 2060 | # 2. Generate flow definition F1 |
| 2061 | # 3. Generate flow definition F2, with key overlapping F1 |
| 2062 | # 4. Send flow add to switch, for F1 |
| 2063 | # 5. Send flow add to switch, for F2, with OFPFF_CHECK_OVERLAP set |
| 2064 | # 6. Verify that OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error response |
| 2065 | # was generated by switch |
| 2066 | # 7. Verifiy flows configured in swtich |
| 2067 | # 8. Test PASSED iff: |
| 2068 | # - error message received, for overlapping flow |
| 2069 | # - overlapping flow is not in flow table |
| 2070 | # else test FAILED |
| 2071 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2072 | class Flow_Add_8(basic.SimpleProtocol): |
| 2073 | """ |
| 2074 | Test FLOW_ADD_8 from draft top-half test plan |
| 2075 | |
| 2076 | INPUTS |
| 2077 | None |
| 2078 | """ |
| 2079 | |
| 2080 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2081 | fq_logger.info("Flow_Add_8 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2082 | |
| 2083 | # Clear all flows from switch |
| 2084 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2085 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2086 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2087 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2088 | |
| 2089 | # Get switch capabilites |
| 2090 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2091 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2092 | self.assertTrue(sw.connect(self.controller), \ |
| 2093 | "Failed to connect to switch" \ |
| 2094 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2095 | |
| 2096 | # Dream up some flow information, i.e. space to chose from for |
| 2097 | # random flow parameter generation |
| 2098 | |
| 2099 | fi = Flow_Info() |
| 2100 | fi.rand(10) |
| 2101 | |
| 2102 | # Dream up a flow config, with at least 1 qualifier specified |
| 2103 | |
| 2104 | fc = Flow_Cfg() |
| 2105 | while True: |
| 2106 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2107 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2108 | sw.tbl_stats.stats[0].wildcards, \ |
| 2109 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2110 | sw.valid_ports, \ |
| 2111 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2112 | ) |
| 2113 | fc = fc.canonical() |
| 2114 | if fc.match.wildcards != ofp.OFPFW_ALL: |
| 2115 | break |
| 2116 | |
| 2117 | # Send it to the switch |
| 2118 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2119 | fq_logger.info("Sending flow add to switch:") |
| 2120 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2121 | ft = Flow_Tbl() |
| 2122 | fc.send_rem = False |
| 2123 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 2124 | ft.insert(fc) |
| 2125 | |
| 2126 | # Wildcard out one qualifier that was specified, to create an |
| 2127 | # overlapping flow |
| 2128 | |
| 2129 | fc2 = copy.deepcopy(fc) |
| 2130 | for wi in shuffle(range(len(all_wildcards_list))): |
| 2131 | w = all_wildcards_list[wi] |
| 2132 | if (fc2.match.wildcards & w) == 0: |
| 2133 | break |
| 2134 | if w == ofp.OFPFW_NW_SRC_MASK: |
| 2135 | w = ofp.OFPFW_NW_SRC_ALL |
| 2136 | wn = "OFPFW_NW_SRC" |
| 2137 | elif w == ofp.OFPFW_NW_DST_MASK: |
| 2138 | w = ofp.OFPFW_NW_DST_ALL |
| 2139 | wn = "OFPFW_NW_DST" |
| 2140 | else: |
| 2141 | wn = all_wildcard_names[w] |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2142 | fq_logger.info("Wildcarding out %s" % (wn)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2143 | fc2.match.wildcards = fc2.match.wildcards | w |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2144 | fc2 = fc2.canonical() |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2145 | |
| 2146 | # Send that to the switch, with overlap checking |
| 2147 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2148 | fq_logger.info("Sending flow add to switch:") |
| 2149 | fq_logger.info(str(fc2)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2150 | fc2.send_rem = False |
| 2151 | self.assertTrue(sw.flow_add(fc2, True), "Failed to add flow") |
| 2152 | |
| 2153 | # Do barrier, to make sure all flows are in |
| 2154 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2155 | |
| 2156 | result = True |
| 2157 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2158 | sw.settle() # Allow switch to settle and generate any notifications |
| 2159 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2160 | # Check for expected error message |
| 2161 | |
| 2162 | if not sw.errors_verify(1, \ |
| 2163 | ofp.OFPET_FLOW_MOD_FAILED, \ |
| 2164 | ofp.OFPFMFC_OVERLAP \ |
| 2165 | ): |
| 2166 | result = False |
| 2167 | |
| 2168 | # Verify flow table |
| 2169 | |
| 2170 | sw.flow_tbl = ft |
| 2171 | if not sw.flow_tbl_verify(): |
| 2172 | result = False |
| 2173 | |
| 2174 | self.assertTrue(result, "Flow_Add_8 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2175 | fq_logger.info("Flow_Add_8 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2176 | |
| 2177 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2178 | # FLOW MODIFY 1 |
| 2179 | # |
| 2180 | # OVERVIEW |
| 2181 | # Strict modify of single existing flow |
| 2182 | # |
| 2183 | # PURPOSE |
| 2184 | # - Verify that strict flow modify operates only on specified flow |
| 2185 | # - Verify that flow is correctly modified |
| 2186 | # |
| 2187 | # PARAMETERS |
| 2188 | # None |
| 2189 | # |
| 2190 | # PROCESS |
| 2191 | # 1. Delete all flows from switch |
| 2192 | # 2. Generate 1 flow F |
| 2193 | # 3. Send flow add to switch, for flow F |
| 2194 | # 4. Generate new action list for flow F, yielding F' |
| 2195 | # 5. Send strict flow modify to switch, for flow F' |
| 2196 | # 6. Verify flow table in switch |
| 2197 | # 7. Test PASSED iff flow returned by switch is F'; else FAILED |
| 2198 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2199 | class Flow_Mod_1(basic.SimpleProtocol): |
| 2200 | """ |
| 2201 | Test FLOW_MOD_1 from draft top-half test plan |
| 2202 | |
| 2203 | INPUTS |
| 2204 | None |
| 2205 | """ |
| 2206 | |
| 2207 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2208 | fq_logger.info("Flow_Mod_1 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2209 | |
| 2210 | # Clear all flows from switch |
| 2211 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2212 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2213 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2214 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2215 | |
| 2216 | # Get switch capabilites |
| 2217 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2218 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2219 | self.assertTrue(sw.connect(self.controller), \ |
| 2220 | "Failed to connect to switch" \ |
| 2221 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2222 | |
| 2223 | # Dream up some flow information, i.e. space to chose from for |
| 2224 | # random flow parameter generation |
| 2225 | |
| 2226 | fi = Flow_Info() |
| 2227 | fi.rand(10) |
| 2228 | |
| 2229 | # Dream up a flow config |
| 2230 | |
| 2231 | fc = Flow_Cfg() |
| 2232 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2233 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2234 | sw.tbl_stats.stats[0].wildcards, \ |
| 2235 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2236 | sw.valid_ports, \ |
| 2237 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2238 | ) |
| 2239 | fc = fc.canonical() |
| 2240 | |
| 2241 | # Send it to the switch |
| 2242 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2243 | fq_logger.info("Sending flow add to switch:") |
| 2244 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2245 | ft = Flow_Tbl() |
| 2246 | fc.send_rem = False |
| 2247 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 2248 | ft.insert(fc) |
| 2249 | |
| 2250 | # Dream up some different actions, with the same flow key |
| 2251 | |
| 2252 | fc2 = copy.deepcopy(fc) |
| 2253 | while True: |
| 2254 | fc2.rand_mod(fi, \ |
| 2255 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2256 | sw.valid_ports, \ |
| 2257 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2258 | ) |
| 2259 | if fc2 != fc: |
| 2260 | break |
| 2261 | |
| 2262 | # Send that to the switch |
| 2263 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2264 | fq_logger.info("Sending strict flow mod to switch:") |
| 2265 | fq_logger.info(str(fc2)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2266 | fc2.send_rem = False |
| 2267 | self.assertTrue(sw.flow_mod(fc2, True), "Failed to modify flow") |
| 2268 | ft.insert(fc2) |
| 2269 | |
| 2270 | # Do barrier, to make sure all flows are in |
| 2271 | |
| 2272 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2273 | |
| 2274 | result = True |
| 2275 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2276 | sw.settle() # Allow switch to settle and generate any notifications |
| 2277 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2278 | # Check for any error messages |
| 2279 | |
| 2280 | if not sw.errors_verify(0): |
| 2281 | result = False |
| 2282 | |
| 2283 | # Verify flow table |
| 2284 | |
| 2285 | sw.flow_tbl = ft |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2286 | if not sw.flow_tbl_verify(True): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2287 | result = False |
| 2288 | |
| 2289 | self.assertTrue(result, "Flow_Mod_1 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2290 | fq_logger.info("Flow_Mod_1 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2291 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2292 | |
| 2293 | # FLOW MODIFY 2 |
| 2294 | # |
| 2295 | # OVERVIEW |
| 2296 | # Loose modify of mutiple flows |
| 2297 | # |
| 2298 | # PURPOSE |
| 2299 | # - Verify that loose flow modify operates only on matching flows |
| 2300 | # - Verify that matching flows are correctly modified |
| 2301 | # |
| 2302 | # PARAMETERS |
| 2303 | # Name: num_flows |
| 2304 | # Type: number |
| 2305 | # Description: |
| 2306 | # Number of flows to define |
| 2307 | # Default: 100 |
| 2308 | # |
| 2309 | # PROCESS |
| 2310 | # 1. Delete all flows from switch |
| 2311 | # 2. Generate <num_flows> distinct flow configurations |
| 2312 | # 3. Send <num_flows> flow adds to switch |
| 2313 | # 4. Pick 1 defined flow F at random |
| 2314 | # 5. Create overlapping loose flow mod match criteria by repeatedly |
| 2315 | # wildcarding out qualifiers in match of F => F', |
| 2316 | # and create new actions list A' for F' |
| 2317 | # 6. Send loose flow modify for F' to switch |
| 2318 | # 7. Verify flow table in swtich |
| 2319 | # 8. Test PASSED iff all flows sent to switch in steps 3 and 6 above, |
| 2320 | # are returned in step 7 above, each with correct (original or modified) |
| 2321 | # action list; |
| 2322 | # else test FAILED |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2323 | |
| 2324 | class Flow_Mod_2(basic.SimpleProtocol): |
| 2325 | """ |
| 2326 | Test FLOW_MOD_2 from draft top-half test plan |
| 2327 | |
| 2328 | INPUTS |
| 2329 | None |
| 2330 | """ |
| 2331 | |
| 2332 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2333 | fq_logger.info("Flow_Mod_2 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2334 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2335 | num_flows = test_param_get(fq_config, "num_flows", 100) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2336 | |
| 2337 | # Clear all flows from switch |
| 2338 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2339 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2340 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2341 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2342 | |
| 2343 | # Get switch capabilites |
| 2344 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2345 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2346 | self.assertTrue(sw.connect(self.controller), \ |
| 2347 | "Failed to connect to switch" \ |
| 2348 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2349 | |
| 2350 | # Dream up some flow information, i.e. space to chose from for |
| 2351 | # random flow parameter generation |
| 2352 | |
| 2353 | fi = Flow_Info() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 2354 | # Shrunk, to increase chance of meta-matches |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2355 | fi.rand(max(int(math.log(num_flows)) / 2, 1)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2356 | |
| 2357 | # Dream up some flows |
| 2358 | |
| 2359 | ft = Flow_Tbl() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2360 | ft.rand(required_wildcards(self), sw, fi, num_flows) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2361 | |
| 2362 | # Send flow table to switch |
| 2363 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2364 | fq_logger.info("Sending flow adds to switch") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2365 | for fc in ft.values(): # Randomizes order of sending |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2366 | fq_logger.info("Adding flow:") |
| 2367 | fq_logger.info(str(fc)); |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2368 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 2369 | |
| 2370 | # Do barrier, to make sure all flows are in |
| 2371 | |
| 2372 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2373 | |
| 2374 | result = True |
| 2375 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2376 | sw.settle() # Allow switch to settle and generate any notifications |
| 2377 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2378 | # Check for any error messages |
| 2379 | |
| 2380 | if not sw.errors_verify(0): |
| 2381 | result = False |
| 2382 | |
| 2383 | # Verify flow table |
| 2384 | |
| 2385 | sw.flow_tbl = ft |
| 2386 | if not sw.flow_tbl_verify(): |
| 2387 | result = False |
| 2388 | |
| 2389 | # Pick a random flow as a basis |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2390 | |
| 2391 | mfc = copy.deepcopy((ft.values())[0]) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2392 | mfc.rand_mod(fi, \ |
| 2393 | sw.sw_features.actions, \ |
| 2394 | sw.valid_ports, \ |
| 2395 | sw.valid_queues \ |
| 2396 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2397 | |
| 2398 | # Repeatedly wildcard qualifiers |
| 2399 | |
| 2400 | for wi in shuffle(range(len(all_wildcards_list))): |
| 2401 | w = all_wildcards_list[wi] |
| 2402 | if w == ofp.OFPFW_NW_SRC_MASK or w == ofp.OFPFW_NW_DST_MASK: |
| 2403 | n = wildcard_get(mfc.match.wildcards, w) |
| 2404 | if n < 32: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 2405 | mfc.match.wildcards = wildcard_set(mfc.match.wildcards, \ |
| 2406 | w, \ |
| 2407 | random.randint(n + 1, 32) \ |
| 2408 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2409 | else: |
| 2410 | continue |
| 2411 | else: |
| 2412 | if wildcard_get(mfc.match.wildcards, w) == 0: |
| 2413 | mfc.match.wildcards = wildcard_set(mfc.match.wildcards, w, 1) |
| 2414 | else: |
| 2415 | continue |
| 2416 | mfc = mfc.canonical() |
| 2417 | |
| 2418 | # Count the number of flows that would be modified |
| 2419 | |
| 2420 | n = 0 |
| 2421 | for fc in ft.values(): |
| 2422 | if mfc.overlaps(fc, True) and not mfc.non_key_equal(fc): |
| 2423 | n = n + 1 |
| 2424 | |
| 2425 | # If more than 1, we found our loose delete flow spec |
| 2426 | if n > 1: |
| 2427 | break |
| 2428 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2429 | fq_logger.info("Modifying %d flows" % (n)) |
| 2430 | fq_logger.info("Sending flow mod to switch:") |
| 2431 | fq_logger.info(str(mfc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2432 | self.assertTrue(sw.flow_mod(mfc, False), "Failed to modify flow") |
| 2433 | |
| 2434 | # Do barrier, to make sure all flows are in |
| 2435 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2436 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2437 | sw.settle() # Allow switch to settle and generate any notifications |
| 2438 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2439 | # Check for error message |
| 2440 | |
| 2441 | if not sw.errors_verify(0): |
| 2442 | result = False |
| 2443 | |
| 2444 | # Apply flow mod to local flow table |
| 2445 | |
| 2446 | for fc in ft.values(): |
| 2447 | if mfc.overlaps(fc, True): |
root | 2843d2b | 2012-04-06 10:27:46 -0700 | [diff] [blame] | 2448 | fc.actions = mfc.actions |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2449 | |
| 2450 | # Verify flow table |
| 2451 | |
| 2452 | sw.flow_tbl = ft |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2453 | if not sw.flow_tbl_verify(True): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2454 | result = False |
| 2455 | |
| 2456 | self.assertTrue(result, "Flow_Mod_2 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2457 | fq_logger.info("Flow_Mod_2 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2458 | |
| 2459 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2460 | # FLOW MODIFY 3 |
| 2461 | |
| 2462 | # OVERVIEW |
| 2463 | # Strict modify of non-existent flow |
| 2464 | # |
| 2465 | # PURPOSE |
| 2466 | # Verify that strict modify of a non-existent flow is equivalent to a flow add |
| 2467 | # |
| 2468 | # PARAMETERS |
| 2469 | # None |
| 2470 | # |
| 2471 | # PROCESS |
| 2472 | # 1. Delete all flows from switch |
| 2473 | # 2. Send single flow mod, as strict modify, to switch |
| 2474 | # 3. Verify flow table in switch |
| 2475 | # 4. Test PASSED iff flow defined in step 2 above verified; else FAILED |
| 2476 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2477 | class Flow_Mod_3(basic.SimpleProtocol): |
| 2478 | """ |
| 2479 | Test FLOW_MOD_3 from draft top-half test plan |
| 2480 | |
| 2481 | INPUTS |
| 2482 | None |
| 2483 | """ |
| 2484 | |
| 2485 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2486 | fq_logger.info("Flow_Mod_3 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2487 | |
| 2488 | # Clear all flows from switch |
| 2489 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2490 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2491 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2492 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2493 | |
| 2494 | # Get switch capabilites |
| 2495 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2496 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2497 | self.assertTrue(sw.connect(self.controller), \ |
| 2498 | "Failed to connect to switch" \ |
| 2499 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2500 | |
| 2501 | # Dream up some flow information, i.e. space to chose from for |
| 2502 | # random flow parameter generation |
| 2503 | |
| 2504 | fi = Flow_Info() |
| 2505 | fi.rand(10) |
| 2506 | |
| 2507 | # Dream up a flow config |
| 2508 | |
| 2509 | fc = Flow_Cfg() |
| 2510 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2511 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2512 | sw.tbl_stats.stats[0].wildcards, \ |
| 2513 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2514 | sw.valid_ports, \ |
| 2515 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2516 | ) |
| 2517 | fc = fc.canonical() |
| 2518 | |
| 2519 | # Send it to the switch |
| 2520 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2521 | fq_logger.info("Sending flow mod to switch:") |
| 2522 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2523 | ft = Flow_Tbl() |
| 2524 | fc.send_rem = False |
| 2525 | self.assertTrue(sw.flow_mod(fc, True), "Failed to modify flows") |
| 2526 | ft.insert(fc) |
| 2527 | |
| 2528 | # Do barrier, to make sure all flows are in |
| 2529 | |
| 2530 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2531 | |
| 2532 | result = True |
| 2533 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2534 | sw.settle() # Allow switch to settle and generate any notifications |
| 2535 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2536 | # Check for any error messages |
| 2537 | |
| 2538 | if not sw.errors_verify(0): |
| 2539 | result = False |
| 2540 | |
| 2541 | # Verify flow table |
| 2542 | |
| 2543 | sw.flow_tbl = ft |
| 2544 | if not sw.flow_tbl_verify(): |
| 2545 | result = False |
| 2546 | |
| 2547 | self.assertTrue(result, "Flow_Mod_3 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2548 | fq_logger.info("Flow_Mod_3 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2549 | |
| 2550 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2551 | # FLOW MODIFY 3_1 |
| 2552 | |
| 2553 | # OVERVIEW |
| 2554 | # No-op modify |
| 2555 | # |
| 2556 | # PURPOSE |
| 2557 | # Verify that modify of a flow with new actions same as old ones operates correctly |
| 2558 | # |
| 2559 | # PARAMETERS |
| 2560 | # None |
| 2561 | # |
| 2562 | # PROCESS |
| 2563 | # 1. Delete all flows from switch |
| 2564 | # 2. Send single flow mod, as strict modify, to switch |
| 2565 | # 3. Verify flow table in switch |
| 2566 | # 4. Send same flow mod, as strict modify, to switch |
| 2567 | # 5. Verify flow table in switch |
| 2568 | # 6. Test PASSED iff flow defined in step 2 and 4 above verified; else FAILED |
| 2569 | |
| 2570 | class Flow_Mod_3_1(basic.SimpleProtocol): |
| 2571 | """ |
| 2572 | Test FLOW_MOD_3_1 from draft top-half test plan |
| 2573 | |
| 2574 | INPUTS |
| 2575 | None |
| 2576 | """ |
| 2577 | |
| 2578 | def runTest(self): |
| 2579 | fq_logger.info("Flow_Mod_3_1 TEST BEGIN") |
| 2580 | |
| 2581 | # Clear all flows from switch |
| 2582 | |
| 2583 | fq_logger.info("Deleting all flows from switch") |
| 2584 | rc = delete_all_flows(self.controller, fq_logger) |
| 2585 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2586 | |
| 2587 | # Get switch capabilites |
| 2588 | |
| 2589 | sw = Switch() |
| 2590 | self.assertTrue(sw.connect(self.controller), \ |
| 2591 | "Failed to connect to switch" \ |
| 2592 | ) |
| 2593 | |
| 2594 | # Dream up some flow information, i.e. space to chose from for |
| 2595 | # random flow parameter generation |
| 2596 | |
| 2597 | fi = Flow_Info() |
| 2598 | fi.rand(10) |
| 2599 | |
| 2600 | # Dream up a flow config |
| 2601 | |
| 2602 | fc = Flow_Cfg() |
| 2603 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2604 | required_wildcards(self), \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2605 | sw.tbl_stats.stats[0].wildcards, \ |
| 2606 | sw.sw_features.actions, \ |
| 2607 | sw.valid_ports, \ |
| 2608 | sw.valid_queues \ |
| 2609 | ) |
| 2610 | fc = fc.canonical() |
| 2611 | |
| 2612 | # Send it to the switch |
| 2613 | |
| 2614 | fq_logger.info("Sending flow mod to switch:") |
| 2615 | fq_logger.info(str(fc)) |
| 2616 | ft = Flow_Tbl() |
| 2617 | fc.send_rem = False |
| 2618 | self.assertTrue(sw.flow_mod(fc, True), "Failed to modify flows") |
| 2619 | ft.insert(fc) |
| 2620 | |
| 2621 | # Do barrier, to make sure all flows are in |
| 2622 | |
| 2623 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2624 | |
| 2625 | result = True |
| 2626 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2627 | sw.settle() # Allow switch to settle and generate any notifications |
| 2628 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2629 | # Check for any error messages |
| 2630 | |
| 2631 | if not sw.errors_verify(0): |
| 2632 | result = False |
| 2633 | |
| 2634 | # Verify flow table |
| 2635 | |
| 2636 | sw.flow_tbl = ft |
| 2637 | if not sw.flow_tbl_verify(): |
| 2638 | result = False |
| 2639 | |
| 2640 | # Send same flow to the switch again |
| 2641 | |
| 2642 | fq_logger.info("Sending flow mod to switch:") |
| 2643 | fq_logger.info(str(fc)) |
| 2644 | self.assertTrue(sw.flow_mod(fc, True), "Failed to modify flows") |
| 2645 | |
| 2646 | # Do barrier, to make sure all flows are in |
| 2647 | |
| 2648 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2649 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2650 | sw.settle() # Allow switch to settle and generate any notifications |
| 2651 | |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2652 | # Check for any error messages |
| 2653 | |
| 2654 | if not sw.errors_verify(0): |
| 2655 | result = False |
| 2656 | |
| 2657 | # Verify flow table |
| 2658 | |
| 2659 | if not sw.flow_tbl_verify(): |
| 2660 | result = False |
| 2661 | |
| 2662 | self.assertTrue(result, "Flow_Mod_3_1 TEST FAILED") |
| 2663 | fq_logger.info("Flow_Mod_3_1 TEST PASSED") |
| 2664 | |
| 2665 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2666 | # FLOW DELETE 1 |
| 2667 | # |
| 2668 | # OVERVIEW |
| 2669 | # Strict delete of single flow |
| 2670 | # |
| 2671 | # PURPOSE |
| 2672 | # Verify correct operation of strict delete of single defined flow |
| 2673 | # |
| 2674 | # PARAMETERS |
| 2675 | # None |
| 2676 | # |
| 2677 | # PROCESS |
| 2678 | # 1. Delete all flows from switch |
| 2679 | # 2. Send flow F to switch |
| 2680 | # 3. Send strict flow delete for F to switch |
| 2681 | # 4. Verify flow table in swtich |
| 2682 | # 6. Test PASSED iff all flows sent to switch in step 2 above, |
| 2683 | # less flow removed in step 3 above, are returned in step 4 above; |
| 2684 | # else test FAILED |
| 2685 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2686 | class Flow_Del_1(basic.SimpleProtocol): |
| 2687 | """ |
| 2688 | Test FLOW_DEL_1 from draft top-half test plan |
| 2689 | |
| 2690 | INPUTS |
| 2691 | None |
| 2692 | """ |
| 2693 | |
| 2694 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2695 | fq_logger.info("Flow_Del_1 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2696 | |
| 2697 | # Clear all flows from switch |
| 2698 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2699 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2700 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2701 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2702 | |
| 2703 | # Get switch capabilites |
| 2704 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2705 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2706 | self.assertTrue(sw.connect(self.controller), \ |
| 2707 | "Failed to connect to switch" \ |
| 2708 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2709 | |
| 2710 | # Dream up some flow information, i.e. space to chose from for |
| 2711 | # random flow parameter generation |
| 2712 | |
| 2713 | fi = Flow_Info() |
| 2714 | fi.rand(10) |
| 2715 | |
| 2716 | # Dream up a flow config |
| 2717 | |
| 2718 | fc = Flow_Cfg() |
| 2719 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2720 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2721 | sw.tbl_stats.stats[0].wildcards, \ |
| 2722 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2723 | sw.valid_ports, \ |
| 2724 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2725 | ) |
| 2726 | fc = fc.canonical() |
| 2727 | |
| 2728 | # Send it to the switch |
| 2729 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2730 | fq_logger.info("Sending flow add to switch:") |
| 2731 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2732 | ft = Flow_Tbl() |
| 2733 | fc.send_rem = False |
| 2734 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 2735 | ft.insert(fc) |
| 2736 | |
| 2737 | # Dream up some different actions, with the same flow key |
| 2738 | |
| 2739 | fc2 = copy.deepcopy(fc) |
| 2740 | while True: |
| 2741 | fc2.rand_mod(fi, \ |
| 2742 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2743 | sw.valid_ports, \ |
| 2744 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2745 | ) |
| 2746 | if fc2 != fc: |
| 2747 | break |
| 2748 | |
| 2749 | # Delete strictly |
| 2750 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2751 | fq_logger.info("Sending strict flow del to switch:") |
| 2752 | fq_logger.info(str(fc2)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2753 | self.assertTrue(sw.flow_del(fc2, True), "Failed to delete flow") |
| 2754 | ft.delete(fc) |
| 2755 | |
| 2756 | # Do barrier, to make sure all flows are in |
| 2757 | |
| 2758 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2759 | |
| 2760 | result = True |
| 2761 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2762 | sw.settle() # Allow switch to settle and generate any notifications |
| 2763 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2764 | # Check for any error messages |
| 2765 | |
| 2766 | if not sw.errors_verify(0): |
| 2767 | result = False |
| 2768 | |
| 2769 | # Verify flow table |
| 2770 | |
| 2771 | sw.flow_tbl = ft |
| 2772 | if not sw.flow_tbl_verify(): |
| 2773 | result = False |
| 2774 | |
| 2775 | self.assertTrue(result, "Flow_Del_1 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2776 | fq_logger.info("Flow_Del_1 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2777 | |
| 2778 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2779 | # FLOW DELETE 2 |
| 2780 | # |
| 2781 | # OVERVIEW |
| 2782 | # Loose delete of multiple flows |
| 2783 | # |
| 2784 | # PURPOSE |
| 2785 | # - Verify correct operation of loose delete of multiple flows |
| 2786 | # |
| 2787 | # PARAMETERS |
| 2788 | # Name: num_flows |
| 2789 | # Type: number |
| 2790 | # Description: |
| 2791 | # Number of flows to define |
| 2792 | # Default: 100 |
| 2793 | # |
| 2794 | # PROCESS |
| 2795 | # 1. Delete all flows from switch |
| 2796 | # 2. Generate <num_flows> distinct flow configurations |
| 2797 | # 3. Send <num_flows> flow adds to switch, for flows generated in step 2 above |
| 2798 | # 4. Pick 1 defined flow F at random |
| 2799 | # 5. Repeatedly wildcard out qualifiers in match of F, creating F', such that |
| 2800 | # F' will match more than 1 existing flow key |
| 2801 | # 6. Send loose flow delete for F' to switch |
| 2802 | # 7. Verify flow table in switch |
| 2803 | # 8. Test PASSED iff all flows sent to switch in step 3 above, less flows |
| 2804 | # removed in step 6 above (i.e. those that match F'), are returned |
| 2805 | # in step 7 above; |
| 2806 | # else test FAILED |
| 2807 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2808 | class Flow_Del_2(basic.SimpleProtocol): |
| 2809 | """ |
| 2810 | Test FLOW_DEL_2 from draft top-half test plan |
| 2811 | |
| 2812 | INPUTS |
| 2813 | None |
| 2814 | """ |
| 2815 | |
| 2816 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2817 | fq_logger.info("Flow_Del_2 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2818 | |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2819 | num_flows = test_param_get(fq_config, "num_flows", 100) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2820 | |
| 2821 | # Clear all flows from switch |
| 2822 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2823 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2824 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2825 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2826 | |
| 2827 | # Get switch capabilites |
| 2828 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2829 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2830 | self.assertTrue(sw.connect(self.controller), \ |
| 2831 | "Failed to connect to switch" \ |
| 2832 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2833 | |
| 2834 | # Dream up some flow information, i.e. space to chose from for |
| 2835 | # random flow parameter generation |
| 2836 | |
| 2837 | fi = Flow_Info() |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 2838 | # Shrunk, to increase chance of meta-matches |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2839 | fi.rand(max(int(math.log(num_flows)) / 2, 1)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2840 | |
| 2841 | # Dream up some flows |
| 2842 | |
| 2843 | ft = Flow_Tbl() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 2844 | ft.rand(required_wildcards(self), sw, fi, num_flows) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2845 | |
| 2846 | # Send flow table to switch |
| 2847 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2848 | fq_logger.info("Sending flow adds to switch") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2849 | for fc in ft.values(): # Randomizes order of sending |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2850 | fq_logger.info("Adding flow:") |
| 2851 | fq_logger.info(str(fc)); |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2852 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 2853 | |
| 2854 | # Do barrier, to make sure all flows are in |
| 2855 | |
| 2856 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2857 | |
| 2858 | result = True |
| 2859 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2860 | sw.settle() # Allow switch to settle and generate any notifications |
| 2861 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2862 | # Check for any error messages |
| 2863 | |
| 2864 | if not sw.errors_verify(0): |
| 2865 | result = False |
| 2866 | |
| 2867 | # Verify flow table |
| 2868 | |
| 2869 | sw.flow_tbl = ft |
| 2870 | if not sw.flow_tbl_verify(): |
| 2871 | result = False |
| 2872 | |
| 2873 | # Pick a random flow as a basis |
| 2874 | |
| 2875 | dfc = copy.deepcopy(ft.values()[0]) |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2876 | dfc.rand_mod(fi, \ |
| 2877 | sw.sw_features.actions, \ |
| 2878 | sw.valid_ports, \ |
| 2879 | sw.valid_queues \ |
| 2880 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2881 | |
| 2882 | # Repeatedly wildcard qualifiers |
| 2883 | |
| 2884 | for wi in shuffle(range(len(all_wildcards_list))): |
| 2885 | w = all_wildcards_list[wi] |
| 2886 | if w == ofp.OFPFW_NW_SRC_MASK or w == ofp.OFPFW_NW_DST_MASK: |
| 2887 | n = wildcard_get(dfc.match.wildcards, w) |
| 2888 | if n < 32: |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 2889 | dfc.match.wildcards = wildcard_set(dfc.match.wildcards, \ |
| 2890 | w, \ |
| 2891 | random.randint(n + 1, 32) \ |
| 2892 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2893 | else: |
| 2894 | continue |
| 2895 | else: |
| 2896 | if wildcard_get(dfc.match.wildcards, w) == 0: |
| 2897 | dfc.match.wildcards = wildcard_set(dfc.match.wildcards, w, 1) |
| 2898 | else: |
| 2899 | continue |
| 2900 | dfc = dfc.canonical() |
| 2901 | |
| 2902 | # Count the number of flows that would be deleted |
| 2903 | |
| 2904 | n = 0 |
| 2905 | for fc in ft.values(): |
| 2906 | if dfc.overlaps(fc, True): |
| 2907 | n = n + 1 |
| 2908 | |
| 2909 | # If more than 1, we found our loose delete flow spec |
| 2910 | if n > 1: |
| 2911 | break |
| 2912 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2913 | fq_logger.info("Deleting %d flows" % (n)) |
| 2914 | fq_logger.info("Sending flow del to switch:") |
| 2915 | fq_logger.info(str(dfc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2916 | self.assertTrue(sw.flow_del(dfc, False), "Failed to delete flows") |
| 2917 | |
| 2918 | # Do barrier, to make sure all flows are in |
| 2919 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 2920 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 2921 | sw.settle() # Allow switch to settle and generate any notifications |
| 2922 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2923 | # Check for error message |
| 2924 | |
| 2925 | if not sw.errors_verify(0): |
| 2926 | result = False |
| 2927 | |
| 2928 | # Apply flow mod to local flow table |
| 2929 | |
| 2930 | for fc in ft.values(): |
| 2931 | if dfc.overlaps(fc, True): |
| 2932 | ft.delete(fc) |
| 2933 | |
| 2934 | # Verify flow table |
| 2935 | |
| 2936 | sw.flow_tbl = ft |
| 2937 | if not sw.flow_tbl_verify(): |
| 2938 | result = False |
| 2939 | |
| 2940 | self.assertTrue(result, "Flow_Del_2 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2941 | fq_logger.info("Flow_Del_2 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2942 | |
| 2943 | |
Howard Persh | 07d99e6 | 2012-04-09 15:26:57 -0700 | [diff] [blame] | 2944 | # FLOW DELETE 4 |
| 2945 | # |
| 2946 | # OVERVIEW |
| 2947 | # Flow removed messages |
| 2948 | # |
| 2949 | # PURPOSE |
| 2950 | # Verify that switch generates OFPT_FLOW_REMOVED/OFPRR_DELETE response |
| 2951 | # messages when deleting flows that were added with OFPFF_SEND_FLOW_REM flag |
| 2952 | # |
| 2953 | # PARAMETERS |
| 2954 | # None |
| 2955 | # |
| 2956 | # PROCESS |
| 2957 | # 1. Delete all flows from switch |
| 2958 | # 2. Send flow add to switch, with OFPFF_SEND_FLOW_REM set |
| 2959 | # 3. Send strict flow delete of flow to switch |
| 2960 | # 4. Verify that OFPT_FLOW_REMOVED/OFPRR_DELETE message is received from switch |
| 2961 | # 5. Verify flow table in switch |
| 2962 | # 6. Test PASSED iff all flows sent to switch in step 2 above, less flow |
| 2963 | # removed in step 3 above, are returned in step 5 above, and that |
| 2964 | # asynch message was received; else test FAILED |
| 2965 | |
| 2966 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2967 | class Flow_Del_4(basic.SimpleProtocol): |
| 2968 | """ |
| 2969 | Test FLOW_DEL_4 from draft top-half test plan |
| 2970 | |
| 2971 | INPUTS |
| 2972 | None |
| 2973 | """ |
| 2974 | |
| 2975 | def runTest(self): |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2976 | fq_logger.info("Flow_Del_4 TEST BEGIN") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2977 | |
| 2978 | # Clear all flows from switch |
| 2979 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 2980 | fq_logger.info("Deleting all flows from switch") |
Dan Talayco | 910a828 | 2012-04-07 00:05:20 -0700 | [diff] [blame] | 2981 | rc = delete_all_flows(self.controller, fq_logger) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2982 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 2983 | |
| 2984 | # Get switch capabilites |
| 2985 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2986 | sw = Switch() |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 2987 | self.assertTrue(sw.connect(self.controller), \ |
| 2988 | "Failed to connect to switch" \ |
| 2989 | ) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 2990 | |
| 2991 | # Dream up some flow information, i.e. space to chose from for |
| 2992 | # random flow parameter generation |
| 2993 | |
| 2994 | fi = Flow_Info() |
| 2995 | fi.rand(10) |
| 2996 | |
| 2997 | # Dream up a flow config |
| 2998 | |
| 2999 | fc = Flow_Cfg() |
| 3000 | fc.rand(fi, \ |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 3001 | required_wildcards(self), \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3002 | sw.tbl_stats.stats[0].wildcards, \ |
| 3003 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 3004 | sw.valid_ports, \ |
| 3005 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3006 | ) |
| 3007 | fc = fc.canonical() |
| 3008 | |
| 3009 | # Send it to the switch. with "notify on removed" |
| 3010 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 3011 | fq_logger.info("Sending flow add to switch:") |
| 3012 | fq_logger.info(str(fc)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3013 | ft = Flow_Tbl() |
| 3014 | fc.send_rem = True |
| 3015 | self.assertTrue(sw.flow_add(fc), "Failed to add flow") |
| 3016 | ft.insert(fc) |
| 3017 | |
| 3018 | # Dream up some different actions, with the same flow key |
| 3019 | |
| 3020 | fc2 = copy.deepcopy(fc) |
| 3021 | while True: |
| 3022 | fc2.rand_mod(fi, \ |
| 3023 | sw.sw_features.actions, \ |
Howard Persh | 8d21c1f | 2012-04-20 15:57:29 -0700 | [diff] [blame] | 3024 | sw.valid_ports, \ |
| 3025 | sw.valid_queues \ |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3026 | ) |
| 3027 | if fc2 != fc: |
| 3028 | break |
| 3029 | |
| 3030 | # Delete strictly |
| 3031 | |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 3032 | fq_logger.info("Sending strict flow del to switch:") |
| 3033 | fq_logger.info(str(fc2)) |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3034 | self.assertTrue(sw.flow_del(fc2, True), "Failed to delete flow") |
| 3035 | ft.delete(fc) |
| 3036 | |
| 3037 | # Do barrier, to make sure all flows are in |
| 3038 | |
| 3039 | self.assertTrue(sw.barrier(), "Barrier failed") |
| 3040 | |
| 3041 | result = True |
| 3042 | |
Howard Persh | 9cab482 | 2012-09-11 17:08:40 -0700 | [diff] [blame] | 3043 | sw.settle() # Allow switch to settle and generate any notifications |
| 3044 | |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3045 | # Check for expected "removed" message |
| 3046 | |
Howard Persh | 3340d45 | 2012-04-06 16:45:21 -0700 | [diff] [blame] | 3047 | if not sw.errors_verify(0): |
| 3048 | result = False |
| 3049 | |
| 3050 | if not sw.removed_verify(1): |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3051 | result = False |
| 3052 | |
| 3053 | # Verify flow table |
| 3054 | |
| 3055 | sw.flow_tbl = ft |
| 3056 | if not sw.flow_tbl_verify(): |
| 3057 | result = False |
| 3058 | |
| 3059 | self.assertTrue(result, "Flow_Del_4 TEST FAILED") |
Howard Persh | 5f3c83f | 2012-04-13 09:57:10 -0700 | [diff] [blame] | 3060 | fq_logger.info("Flow_Del_4 TEST PASSED") |
root | f6af167 | 2012-04-06 09:46:29 -0700 | [diff] [blame] | 3061 | |