Rich Lane | 51c924b | 2014-03-28 16:25:55 -0700 | [diff] [blame] | 1 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 2 | # Copyright (c) 2014 Big Switch Networks, Inc. |
| 3 | """ |
| 4 | Flow-mod test cases |
| 5 | """ |
| 6 | |
| 7 | import logging |
| 8 | |
| 9 | import oftest |
| 10 | from oftest import config |
| 11 | import oftest.base_tests as base_tests |
| 12 | import ofp |
| 13 | from loxi.pp import pp |
| 14 | |
| 15 | from oftest.testutils import * |
| 16 | from oftest.parse import parse_ipv6 |
| 17 | |
| 18 | class Overwrite(base_tests.SimpleDataPlane): |
| 19 | """ |
| 20 | Verify that overwriting a flow changes most fields but preserves stats |
| 21 | """ |
| 22 | def runTest(self): |
| 23 | in_port, out_port1, out_port2 = openflow_ports(3) |
| 24 | |
| 25 | delete_all_flows(self.controller) |
| 26 | |
| 27 | table_id = test_param_get("table", 0) |
| 28 | match = ofp.match([ |
| 29 | ofp.oxm.in_port(in_port), |
| 30 | ]) |
| 31 | priority = 1000 |
| 32 | |
| 33 | logging.info("Inserting flow") |
| 34 | request = ofp.message.flow_add( |
| 35 | table_id=table_id, |
| 36 | match=match, |
| 37 | instructions=[ |
| 38 | ofp.instruction.apply_actions([ofp.action.output(out_port1)]), |
| 39 | ], |
| 40 | buffer_id=ofp.OFP_NO_BUFFER, |
| 41 | priority=priority, |
| 42 | flags=ofp.OFPFF_SEND_FLOW_REM, |
| 43 | cookie=0x1234, |
| 44 | hard_timeout=1000, |
| 45 | idle_timeout=2000) |
| 46 | self.controller.message_send(request) |
| 47 | do_barrier(self.controller) |
| 48 | |
| 49 | # Send a packet through so that we can check stats were preserved |
| 50 | self.dataplane.send(in_port, str(simple_tcp_packet(pktlen=100))) |
| 51 | verify_flow_stats(self, ofp.match(), table_id=table_id, pkts=1) |
| 52 | |
| 53 | # Send a flow-add with the same table_id, match, and priority, causing |
| 54 | # an overwrite |
| 55 | logging.info("Overwriting flow") |
| 56 | request = ofp.message.flow_add( |
| 57 | table_id=table_id, |
| 58 | match=match, |
| 59 | instructions=[ |
| 60 | ofp.instruction.apply_actions([ofp.action.output(out_port2)]), |
| 61 | ], |
| 62 | buffer_id=ofp.OFP_NO_BUFFER, |
| 63 | priority=priority, |
| 64 | flags=0, |
| 65 | cookie=0xabcd, |
| 66 | hard_timeout=3000, |
| 67 | idle_timeout=4000) |
| 68 | self.controller.message_send(request) |
| 69 | do_barrier(self.controller) |
| 70 | |
| 71 | # Should not get a flow-removed message |
| 72 | msg, _ = self.controller.poll(exp_msg=ofp.message.flow_removed, |
| 73 | timeout=oftest.ofutils.default_negative_timeout) |
| 74 | self.assertEquals(msg, None) |
| 75 | |
| 76 | # Check that the fields in the flow stats entry match the second flow-add |
| 77 | stats = get_flow_stats(self, ofp.match()) |
| 78 | self.assertEquals(len(stats), 1) |
| 79 | entry = stats[0] |
| 80 | logging.debug(entry.show()) |
| 81 | self.assertEquals(entry.instructions, request.instructions) |
| 82 | self.assertEquals(entry.flags, request.flags) |
| 83 | self.assertEquals(entry.cookie, request.cookie) |
| 84 | self.assertEquals(entry.hard_timeout, request.hard_timeout) |
| 85 | self.assertEquals(entry.idle_timeout, request.idle_timeout) |
| 86 | |
| 87 | # Flow stats should have been preserved |
| 88 | verify_flow_stats(self, ofp.match(), table_id=table_id, pkts=1) |