summaryrefslogtreecommitdiff
path: root/tests/TestSuite_link_flowctrl.py
blob: 11c1795394f2d86a658267882cab7e969a82e1b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# BSD LICENSE
#
# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in
#     the documentation and/or other materials provided with the
#     distribution.
#   * Neither the name of Intel Corporation nor the names of its
#     contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
DPDK Test suite.
Test for Ethernet Link Flow Control Features by Poll Mode Drivers
"""

import dts
import re

from time import sleep
from test_case import TestCase
from pmd_output import PmdOutput
from settings import HEADER_SIZE


class TestLinkFlowctrl(TestCase):
    pause_frame_dst = "01:80:C2:00:00:01"
    pause_frame_type = "0x8808"
    pause_frame_opcode = "\\x00\\x01"
    pause_frame_control = "\\x00\\xFF"
    pause_frame_paddign = "\\x00" * 42

    pause_frame = '[Ether(src="%s",dst="%s",type=%s)/("%s%s%s")]'

    frames_to_sent = 10

    packet_size = 66    # 66 allows frame loss
    payload_size = packet_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] - HEADER_SIZE['udp']

    def set_up_all(self):
        """
        Run at the start of each test suite.

        Link flow control Prerequisites
        """

        self.dutPorts = self.dut.get_ports()
        self.verify(len(self.dutPorts) > 1, "Insuficient ports")

        self.rx_port = self.dutPorts[0]
        self.tester_tx_mac = self.tester.get_mac(self.tester.get_local_port(self.rx_port))

        self.tx_port = self.dutPorts[1]

        self.portMask = dts.create_mask([self.rx_port, self.tx_port])
        self.memChannels = self.dut.get_memory_channels()

        self.pmdout = PmdOutput(self.dut)
        self.pmdout.start_testpmd("all", "--portmask=%s" % self.portMask)

    def pause_frame_loss_test(self, rx_flow_control='off',
                              tx_flow_control='off',
                              pause_frame_fwd='off'):

        tester_tx_port = self.tester.get_local_port(self.rx_port)
        tester_rx_port = self.tester.get_local_port(self.tx_port)

        tgenInput = []
        tgenInput.append((tester_tx_port, tester_rx_port, "test.pcap"))

        self.dut.send_expect("set flow_ctrl rx %s tx %s 300 50 10 1 mac_ctrl_frame_fwd %s autoneg on %d " % (
                             rx_flow_control,
                             tx_flow_control,
                             pause_frame_fwd,
                             self.rx_port),
                             "testpmd> ")

        self.dut.send_expect("set fwd csum", "testpmd> ")
        self.dut.send_expect("start", "testpmd> ")

        self.tester.scapy_append('wrpcap("test.pcap",[Ether()/IP()/UDP()/("X"*%d)])' %
                                 TestLinkFlowctrl.payload_size)

        self.tester.scapy_execute()

        # Run traffic generator
        result = self.tester.traffic_generator_loss(tgenInput, 100)
        self.dut.send_expect("stop", "testpmd> ")

        return result

    def get_testpmd_port_stats(self, ports):
        """
            Returns the number of packets transmitted and received from testpmd.
            Uses testpmd show port stats.
        """

        rx_pattern = "RX-packets: (\d*)"
        tx_pattern = "TX-packets: (\d*)"
        rx = re.compile(rx_pattern)
        tx = re.compile(tx_pattern)

        port_stats = {}

        for port in ports:
            out = self.dut.send_expect("show port stats %d" % port,
                                       "testpmd> ")

            rx_packets = int(rx.search(out).group(1))
            tx_packets = int(tx.search(out).group(1))

            port_stats[port] = (rx_packets, tx_packets)

        return port_stats

    def pause_frame_test(self, frame, flow_control='off',
                         pause_frame_fwd='off'):
        """
            Sets testpmd flow control and mac ctrl frame fwd according to the
            parameters, starts forwarding and clears the stats, then sends the
            passed frame and stops forwarding.
            Returns the testpmd port stats.
        """

        tester_tx_port = self.tester.get_local_port(self.rx_port)
        tx_interface = self.tester.get_interface(tester_tx_port)
        tester_rx_port = self.tester.get_local_port(self.tx_port)

        tgenInput = []
        tgenInput.append((tester_tx_port, tester_rx_port, "test.pcap"))

        self.dut.send_expect("set flow_ctrl rx %s tx %s 300 50 10 1 mac_ctrl_frame_fwd %s autoneg %s %d " % (
                             flow_control,
                             flow_control,
                             pause_frame_fwd,
                             flow_control,
                             self.rx_port),
                             "testpmd> ")

        self.dut.send_expect("set fwd io", "testpmd> ")
        self.dut.send_expect("start", "testpmd> ")
        self.dut.send_expect("clear port stats all", "testpmd> ")

        self.tester.scapy_foreground()
        self.tester.scapy_append('sendp(%s, iface="%s", count=%d)' % (frame,
                                                                      tx_interface,
                                                                      TestLinkFlowctrl.frames_to_sent))

        self.tester.scapy_execute()

        # The following sleep is needed to allow all the packets to arrive.
        # 1s works for Crown Pass (FC18) DUT, Lizard Head Pass (FC14) tester
        # using Niantic. Increase it in case of packet loosing.
        sleep(1)

        self.dut.send_expect("stop", "testpmd> ")

        port_stats = self.get_testpmd_port_stats((self.rx_port, self.tx_port))

        return port_stats

    def check_pause_frame_test_result(self, result, expected_rx=False, expected_fwd=False):
        """
            Verifies the test results (use pause_frame_test before) against
            the expected behavior.
        """
        print "Result (port, rx, tx) %s,  expected rx %s, expected fwd %s" % (result,
                                                                              expected_rx,
                                                                              expected_fwd)

        if expected_rx:
            self.verify(result[self.rx_port][0] == TestLinkFlowctrl.frames_to_sent,
                        "Pause Frames are not being received by testpmd (%d received)" %
                        result[self.rx_port][0])
            if expected_fwd:
                self.verify(result[self.tx_port][1] == TestLinkFlowctrl.frames_to_sent,
                            "Pause Frames are not being forwarded by testpmd (%d sent)" % (
                                result[self.tx_port][1]))
            else:
                self.verify(result[self.tx_port][1] == 0,
                            "Pause Frames are being forwarded by testpmd (%d sent)" % (
                                result[self.tx_port][1]))
        else:
            self.verify(result[self.rx_port][0] == 0,
                        "Pause Frames are being received by testpmd (%d received)" %
                        result[self.rx_port][0])

    def build_pause_frame(self, option=0):
        """
        Build the PAUSE Frame for the tests. 3 available options:
        0: Correct frame (correct src and dst addresses and opcode)
        1: Wrong source frame (worng src, correct and dst address and opcode)
        2: Wrong opcode frame (correct src and dst address and wrong opcode)
        3: Wrong destination frame (correct src and opcode, wrong dst address)
        """

        if option == 1:
            return TestLinkFlowctrl.pause_frame % ("00:01:02:03:04:05",
                                                   TestLinkFlowctrl.pause_frame_dst,
                                                   TestLinkFlowctrl.pause_frame_type,
                                                   TestLinkFlowctrl.pause_frame_opcode,
                                                   TestLinkFlowctrl.pause_frame_control,
                                                   TestLinkFlowctrl.pause_frame_paddign)

        elif option == 2:
            return TestLinkFlowctrl.pause_frame % (self.tester_tx_mac,
                                                   TestLinkFlowctrl.pause_frame_dst,
                                                   TestLinkFlowctrl.pause_frame_type,
                                                   "\\x00\\x02",
                                                   TestLinkFlowctrl.pause_frame_control,
                                                   TestLinkFlowctrl.pause_frame_paddign)
        elif option == 3:
            return TestLinkFlowctrl.pause_frame % (self.tester_tx_mac,
                                                   "01:80:C2:00:AB:10",
                                                   TestLinkFlowctrl.pause_frame_type,
                                                   TestLinkFlowctrl.pause_frame_opcode,
                                                   TestLinkFlowctrl.pause_frame_control,
                                                   TestLinkFlowctrl.pause_frame_paddign)

        return TestLinkFlowctrl.pause_frame % (self.tester_tx_mac,
                                               TestLinkFlowctrl.pause_frame_dst,
                                               TestLinkFlowctrl.pause_frame_type,
                                               TestLinkFlowctrl.pause_frame_opcode,
                                               TestLinkFlowctrl.pause_frame_control,
                                               TestLinkFlowctrl.pause_frame_paddign)

    def test_flowctrl_off_pause_fwd_off(self):
        """
        Flow control disabled, MAC PAUSE frame forwarding disabled.
        PAUSE Frames must not be received by testpmd
        """

        pause_frames = [self.build_pause_frame(0),
                        self.build_pause_frame(1),
                        self.build_pause_frame(2),
                        self.build_pause_frame(3)]

        for frame in pause_frames:
            port_stats = self.pause_frame_test(frame)
            self.check_pause_frame_test_result(port_stats)

    def test_flowctrl_on_pause_fwd_off(self):
        """
        Flow control enabled, MAC PAUSE frame forwarding disabled.
        PAUSE Frames must not be received by testpmd
        """

        pause_frames = [self.build_pause_frame(0),
                        self.build_pause_frame(1),
                        self.build_pause_frame(2),
                        self.build_pause_frame(3)]

        for frame in pause_frames:
            port_stats = self.pause_frame_test(frame, flow_control='on')
            self.check_pause_frame_test_result(port_stats)

    def test_flowctrl_off_pause_fwd_on(self):
        """
        Flow control disabled, MAC PAUSE frame forwarding enabled.
        All PAUSE Frames must be forwarded by testpmd.
        """

        # Regular frames, check for no frames received
        pause_frame = self.build_pause_frame()
        port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats, True, True)

        # Wrong src MAC, check for no frames received
        pause_frame = self.build_pause_frame(1)
        port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats, True, True)

        # Unrecognized frames (wrong opcode), check for all frames received and fwd
        pause_frame = self.build_pause_frame(2)
        port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats, True, True)

        # Wrong dst MAC, check for all frames received
        pause_frame = self.build_pause_frame(3)
        port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats, True, True)

    def test_flowctrl_on_pause_fwd_on(self):
        """
        Flow control enabled, MAC PAUSE frame forwarding enabled.
        Only unrecognized PAUSE Frames must be forwarded by testpmd.
        """

        # Regular frames, check for no frames received
        pause_frame = self.build_pause_frame()
        port_stats = self.pause_frame_test(pause_frame, flow_control='on',
                                           pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats)

        # Wrong src MAC, check for no frames received
        pause_frame = self.build_pause_frame(1)
        port_stats = self.pause_frame_test(pause_frame, flow_control='on',
                                           pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats)

        # Unrecognized frames (wrong opcode), check for all frames received and fwd
        pause_frame = self.build_pause_frame(2)
        port_stats = self.pause_frame_test(pause_frame, flow_control='on',
                                           pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats, True, True)

        # Wrong dst MAC, check for all frames received
        pause_frame = self.build_pause_frame(3)
        port_stats = self.pause_frame_test(pause_frame, flow_control='on',
                                           pause_frame_fwd='on')
        self.check_pause_frame_test_result(port_stats, True, True)

    def test_perf_flowctrl_on_pause_fwd_on(self):
        """
        Disable link flow control and PAUSE frame forwarding
        """

        result = self.pause_frame_loss_test(rx_flow_control='on',
                                            tx_flow_control='on',
                                            pause_frame_fwd='on')

        print "Packet loss: %.3f%%" % result

        self.verify(result <= 0.01,
                    "Link flow control fail, the loss percent is more than 1%")

    def test_perf_flowctrl_on_pause_fwd_off(self):
        """
        Disable link flow control and enable PAUSE frame forwarding
        """

        result = self.pause_frame_loss_test(rx_flow_control='on',
                                            tx_flow_control='on',
                                            pause_frame_fwd='off')

        print "Packet loss: %.3f%%" % result

        self.verify(result <= 0.01,
                    "Link flow control fail, the loss percent is more than 1%")

    def test_perf_flowctrl_rx_on(self):
        """
        Enable only rx link flow control
        """

        result = self.pause_frame_loss_test(rx_flow_control='on',
                                            tx_flow_control='on',
                                            pause_frame_fwd='off')

        print "Packet loss: %.3f%%" % result

        self.verify(result <= 0.01,
                    "Link flow control fail, the loss percent is more than 1%")

    def test_perf_flowctrl_off_pause_fwd_on(self):
        """
        Enable link flow control and disable PAUSE frame forwarding
        """

        result = self.pause_frame_loss_test(rx_flow_control='off',
                                            tx_flow_control='off',
                                            pause_frame_fwd='on')

        print "Packet loss: %.3f%%" % result

        self.verify(result >= 0.5,
                    "Link flow control fail, the loss percent is less than 50%")

    def test_perf_flowctrl_off_pause_fwd_off(self):
        """
        Disable link flow control and PAUSE frame forwarding
        """

        result = self.pause_frame_loss_test(rx_flow_control='off',
                                            tx_flow_control='off',
                                            pause_frame_fwd='off')

        print "Packet loss: %.3f%%" % result

        self.verify(result >= 0.5,
                    "Link flow control fail, the loss percent is less than 50%")

    def test_perf_flowctrl_tx_on(self):
        """
        Disable link flow control and PAUSE frame forwarding
        """

        result = self.pause_frame_loss_test(rx_flow_control='off',
                                            tx_flow_control='on',
                                            pause_frame_fwd='off')

        print "Packet loss: %.3f%%" % result

        self.verify(result <= 0.01,
                    "Link flow control fail, the loss percent is more than 1%")

    def tear_down_all(self):
        """
        Run after each test case.
        """
        self.dut.send_expect("quit", "# ")