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