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