Rich Lane | 0f4c77c | 2014-03-23 16:02:56 -0700 | [diff] [blame] | 1 | """ |
| 2 | Latency tests |
| 3 | |
| 4 | These tests are mostly helpful for finding an optimal value for the |
| 5 | --default-negative-timeout option. If this value is too large it will |
| 6 | unnecessarily some down testing, but if it is too small then tests |
| 7 | may pass when they should have failed. |
| 8 | |
| 9 | Most of this latency is caused by OFTest. Actual switch latency should be just |
| 10 | a few microseconds, but OFTest can add milliseconds on top of that. |
| 11 | """ |
| 12 | |
| 13 | import logging |
| 14 | import unittest |
| 15 | import time |
| 16 | |
| 17 | from oftest import config |
| 18 | import ofp |
| 19 | import oftest.base_tests as base_tests |
| 20 | |
| 21 | from oftest.testutils import * |
| 22 | |
| 23 | class DataplaneLatency(base_tests.SimpleDataPlane): |
| 24 | """ |
| 25 | Measure and assert dataplane latency |
| 26 | |
| 27 | All packets must arrive within the default timeout, and 90% must |
| 28 | arrive within the default negative timeout. |
| 29 | """ |
| 30 | def runTest(self): |
| 31 | in_port, out_port = openflow_ports(2) |
| 32 | |
| 33 | delete_all_flows(self.controller) |
| 34 | |
| 35 | pkt = str(simple_tcp_packet()) |
| 36 | |
| 37 | request = ofp.message.flow_add( |
| 38 | match=ofp.match(wildcards=ofp.OFPFW_ALL), |
| 39 | buffer_id=0xffffffff, |
| 40 | actions=[ofp.action.output(out_port)]) |
| 41 | |
| 42 | self.controller.message_send(request) |
| 43 | do_barrier(self.controller) |
| 44 | |
| 45 | latencies = [] |
| 46 | for i in xrange(0, 1000): |
| 47 | start_time = time.time() |
| 48 | self.dataplane.send(in_port, pkt) |
| 49 | verify_packet(self, pkt, out_port) |
| 50 | end_time = time.time() |
| 51 | latencies.append(end_time - start_time) |
| 52 | |
| 53 | latencies.sort() |
| 54 | |
| 55 | latency_min = latencies[0] |
| 56 | latency_90 = latencies[int(len(latencies)*0.9)] |
| 57 | latency_max = latencies[-1] |
| 58 | |
| 59 | logging.debug("Minimum latency: %f ms", latency_min * 1000.0) |
| 60 | logging.debug("90%% latency: %f ms", latency_90 * 1000.0) |
| 61 | logging.debug("Maximum latency: %f ms", latency_max * 1000.0) |
| 62 | |
| 63 | self.assertGreater(config["default_timeout"], latency_max) |
| 64 | self.assertGreater(config["default_negative_timeout"], latency_90) |
| 65 | |
| 66 | class PktinLatency(base_tests.SimpleDataPlane): |
| 67 | """ |
| 68 | Measure and assert packet-in latency |
| 69 | |
| 70 | All packet-ins must arrive within the default timeout, and 90% must |
| 71 | arrive within the default negative timeout. |
| 72 | """ |
| 73 | def runTest(self): |
| 74 | in_port, = openflow_ports(1) |
| 75 | |
| 76 | delete_all_flows(self.controller) |
| 77 | |
| 78 | pkt = str(simple_tcp_packet()) |
| 79 | |
| 80 | request = ofp.message.flow_add( |
| 81 | match=ofp.match(wildcards=ofp.OFPFW_ALL), |
| 82 | buffer_id=0xffffffff, |
| 83 | actions=[ofp.action.output(ofp.OFPP_CONTROLLER)]) |
| 84 | |
| 85 | self.controller.message_send(request) |
| 86 | do_barrier(self.controller) |
| 87 | |
| 88 | latencies = [] |
| 89 | for i in xrange(0, 1000): |
| 90 | start_time = time.time() |
| 91 | self.dataplane.send(in_port, pkt) |
| 92 | verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION) |
| 93 | end_time = time.time() |
| 94 | latencies.append(end_time - start_time) |
| 95 | |
| 96 | latencies.sort() |
| 97 | |
| 98 | latency_min = latencies[0] |
| 99 | latency_90 = latencies[int(len(latencies)*0.9)] |
| 100 | latency_max = latencies[-1] |
| 101 | |
| 102 | logging.debug("Minimum latency: %f ms", latency_min * 1000.0) |
| 103 | logging.debug("90%% latency: %f ms", latency_90 * 1000.0) |
| 104 | logging.debug("Maximum latency: %f ms", latency_max * 1000.0) |
| 105 | |
| 106 | self.assertGreater(config["default_timeout"], latency_max) |
| 107 | self.assertGreater(config["default_negative_timeout"], latency_90) |