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