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