summaryrefslogtreecommitdiff
path: root/tests/TestSuite_userspace_ethtool.py
blob: 937a9e502309ef84d265cbf6f8eb89d0ad1a6011 (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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
# 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 support of userspace ethtool feature
"""

import os
import utils
import time
import re
from test_case import TestCase
from packet import Packet, sniff_packets, load_sniff_packets
import random
from etgen import IxiaPacketGenerator
from settings import HEADER_SIZE
from settings import SCAPY2IXIA
from utils import RED


class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):

    def set_up_all(self):
        """
        Run at the start of each test suite.
        """
        self.ports = self.dut.get_ports()
        self.verify(len(self.ports) >= 2, "No ports found for " + self.nic)

        # build sample app
        out = self.dut.send_expect("make -C examples/ethtool", "# ")
        self.verify("Error" not in out, "compilation error 1")
        self.verify("No such file" not in out, "compilation error 2")

        path = "./examples/ethtool/ethtool-app/ethtool-app/%s/ethtool" % self.target
        self.cmd = "%s -c f -n %d" % (path, self.dut.get_memory_channels())

        # pause frame basic configuration
        self.pause_time = 65535
        self.frame_size = 64
        self.pause_rate = 0.50

        # update IxiaPacketGenerator function from local
        self.tester.extend_external_packet_generator(TestUserspaceEthtool, self)

    def set_up(self):
        """
        Run before each test case.
        """
        pass

    def build_ethtool(self):
        out = self.dut.send_expect("make -C examples/ethtool", "# ")
        self.verify("Error" not in out, "compilation error 1")
        self.verify("No such file" not in out, "compilation error 2")

    def strip_portstats(self, portid):
        out = self.dut.send_expect("portstats %d " % portid, "EthApp>")
        stats_pattern = r"portstats (\d)(\s+)Port (\d+) stats(\s+)In: (\d+)" \
            " \((\d+) bytes\)(\s+)Out: (\d+) \((\d+) bytes\)" \
            "(\s+)Err: (\d+)"

        m = re.match(stats_pattern, out)
        if m:
            return (int(m.group(5)), int(m.group(8)))
        else:
            return (0, 0)

    def strip_ringparam(self, portid):
        out = self.dut.send_expect("ringparam %d" % portid, "EthApp>")
        ring_pattern = r"ringparam (\d)(\s+)Port (\d+) ring parameters(\s+)" \
            "Rx Pending: (\d+) \((\d+) max\)(\s+)Tx Pending: " \
            "(\d+) \((\d+) max\)"
        m = re.match(ring_pattern, out)
        if m:
            return (int(m.group(5)), int(m.group(6)), int(m.group(8)),
                    int(m.group(9)))
        else:
            return (0, 0, 0, 0)

    def strip_mac(self, portid):
        out = self.dut.send_expect("macaddr %d" % portid, "EthApp>")
        mac_pattern = r"macaddr (\d+)(\s+)Port (\d+) MAC Address: (.*)"
        m = re.match(mac_pattern, out)
        if m:
            return m.group(4)
        else:
            return "00:00:00:00:00:00"

    def strip_mtu(self, intf):
        """
        Strip tester port mtu
        """
        link_info = self.tester.send_expect("ip link show %s" % intf, "# ")
        mtu_pattern = r".* mtu (\d+) .*"
        m = re.match(mtu_pattern, link_info)
        if m:
            return int(m.group(1))
        else:
            return 1518

    def strip_md5(self, filename):
        md5_info = self.dut.send_expect("md5sum %s" % filename, "# ")
        md5_pattern = r"(\w+)  (\w+)"
        m = re.match(md5_pattern, md5_info)
        if m:
            return m.group(1)
        else:
            return ""

    def dpdk_get_nic_info(self, dpdk_driver_msg):
        # get nic driver information using dpdk's ethtool
        info_lines = dpdk_driver_msg.strip().splitlines()
        driver_pattern = r"Port (\d+) driver: (.*) \(ver: (.*)\)"
        pattern = "(.*): (.*)"
        firmwarePat = "0x([0-9a-f]+)"
        check_content = ['firmware-version', 'driver']
        nic_infos = {}
        port = None
        cnt = 0
        while cnt < len(info_lines):
            if not info_lines[cnt]:
                pass
            else:
                m = re.match(driver_pattern, info_lines[cnt])
                if m:
                    port = m.group(1)
                    nic_infos[port] = {}
                    nic_infos[port]['driver'] = m.group(2).split('_').pop()
                    dpdk_version = m.group(3)
                else:
                    if port:
                        out = re.findall(pattern, info_lines[cnt], re.M)[0]
                        if len(out) == 2:
                            if out[0] == 'firmware-version':
                                nic_infos[port][out[0]] = "0x" + re.findall(firmwarePat, out[1], re.M)[0]
                            else:
                                nic_infos[port][out[0]] = out[1]
            cnt += 1
        # check driver content
        status = []
        for port_no in nic_infos:
            nic_info = nic_infos[port_no]
            for item in check_content:
                if item not in nic_info.keys():
                    status.append("port {0} get {1} failed".format(port_no, item))
                    break
        # if there is error in status, clear nic_infos 
        if status:
            msg = os.linesep.join(status)
            nic_infos = None
        else:
            msg = ''
        
        return nic_infos, msg

    def linux_get_nic_info(self, port_name):
        # get nic driver information using linux's ethtool
        pattern = "(.*): (.*)"
        firmwarePat = "0x([0-9a-f]+)"
        infos = self.dut.send_expect("ethtool -i %s"%port_name, "# ").splitlines()
        sys_nic_info = {}
        for info in infos:
            if not info:
                continue
            result = re.findall(pattern, info, re.M)
            if not result:
                continue
            out = result[0]
            if len(out) == 2:
                if out[0] == 'firmware-version':
                    sys_nic_info[out[0]] = "0x" + re.findall(firmwarePat, out[1], re.M)[0]
                else:
                    sys_nic_info[out[0]] = out[1]
        return sys_nic_info

    def check_driver_info(self, port_name, sys_nic_info, dpdk_drv_info):
        # compare dpdk query nic information with linux query nic information 
        for item, value in dpdk_drv_info.items():
            if item not in sys_nic_info.keys():
                msg = "linux ethtool failed to dump driver info"
                status = False
                break
            if value != sys_nic_info[item]:
                msg = "Userspace ethtool failed to dump driver info"
                status = False
                break
        else:
            msg = "{0}: dpdk ethtool dump nic information done".format(port_name)
            status = True

        return status, msg

    def test_dump_driver_info(self):
        """
        Test ethtool can dump basic information
        """
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        dpdk_driver_msg = self.dut.send_expect("drvinfo", "EthApp>")
        self.dut.send_expect("quit", "# ")
        dpdk_nic_infos, msg = self.dpdk_get_nic_info(dpdk_driver_msg)
        self.verify(dpdk_nic_infos, msg)
        
        portsinfo = {}
        for index in range(len(self.ports)):
            portsinfo[index] = {}
            portinfo = portsinfo[index]
            port = self.ports[index]
            netdev = self.dut.ports_info[port]['port']
            # strip orignal driver
            portinfo['ori_driver'] = netdev.get_nic_driver()
            portinfo['net_dev'] = netdev
            # bind to default driver
            netdev.bind_driver()
            # get linux interface
            intf_name = netdev.get_interface_name()
            sys_nic_info = self.linux_get_nic_info(intf_name)
            status, msg = self.check_driver_info(intf_name, sys_nic_info, dpdk_nic_infos[str(index)])
            self.logger.info(msg)
            self.verify(status, msg)

        for index in range(len(self.ports)):
            # bind to original driver
            portinfo = portsinfo[index]
            portinfo['net_dev'].bind_driver(portinfo['ori_driver'])

        self.dut.send_expect(self.cmd, "EthApp>", 60)
        # ethtool doesn't support port disconnect by tools of linux 
        # only detect physical link disconnect status
        if self.nic.startswith("fortville") == False:  
            # check link status dump function
            for port in self.ports:
                tester_port = self.tester.get_local_port(port)
                intf = self.tester.get_interface(tester_port)
                self.tester.send_expect("ip link set dev %s down" % intf, "# ")
            # wait for link stable
            time.sleep(5)
    
            out = self.dut.send_expect("link", "EthApp>", 60)
            link_pattern = r"Port (\d+): (.*)"
            link_infos = out.split("\r\n")
            for link_info in link_infos:
                m = re.match(link_pattern, link_info)
                if m:
                    port = m.group(1)
                    status = m.group(2)
                    self.verify(status == "Down", "Userspace tool failed to detect link down")
    
            for port in self.ports:
                tester_port = self.tester.get_local_port(port)
                intf = self.tester.get_interface(tester_port)
                self.tester.send_expect("ip link set dev %s up" % intf, "# ")
            # wait for link stable
            time.sleep(5)

        # check port stats function
        pkt = Packet(pkt_type='UDP')
        for port in self.ports:
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            ori_rx_pkts, ori_tx_pkts = self.strip_portstats(port)
            pkt.send_pkt(tx_port=intf)
            time.sleep(1)
            rx_pkts, tx_pkts = self.strip_portstats(port)
            self.verify((rx_pkts == (ori_rx_pkts + 1)), "Failed to record Rx/Tx packets")

        self.dut.send_expect("quit", "# ")

    def test_retrieve_reg(self):
        """
        Test ethtool app can retrieve port register
        """
        self.dut.send_expect(self.cmd, "EthApp>", 60)

        portsinfo = []
        ori_drivers = []
        
        if self.nic.startswith("fortville"):
            return
        
        for portid in range(len(self.ports)):
            self.dut.send_expect("regs %d regs_%d.bin" % (portid, portid), "EthApp>")
            portinfo = {'portid': portid, 'reg_file': 'regs_%d.bin' % portid}
            portsinfo.append(portinfo)

        self.dut.send_expect("quit", "# ")

        for index in range(len(self.ports)):
            port = self.ports[index]
            netdev = self.dut.ports_info[port]['port']
            portinfo = portsinfo[index]
            # strip orignal driver
            portinfo['ori_driver'] = netdev.get_nic_driver()
            portinfo['net_dev'] = netdev
            # bind to default driver
            netdev.bind_driver()
            # get linux interface
            intf = netdev.get_interface_name()
            out = self.dut.send_expect("ethtool -d %s raw off file %s" % (intf, portinfo['reg_file']), "# ")
            self.verify(("LINKS" in out and "FCTRL" in out), "Failed to dump %s registers" % intf)

        for index in range(len(self.ports)):
            # bind to original driver
            portinfo = portsinfo[index]
            portinfo['net_dev'].bind_driver(portinfo['ori_driver'])

    def test_retrieve_eeprom(self):
        """
        Test ethtool app dump eeprom function
        """
        # require md5sum to check file
        out = self.dut.send_expect("whereis md5sum", "# ")
        self.verify("/usr/bin/md5sum" in out, "This case required md5sum installed on DUT")

        self.dut.send_expect(self.cmd, "EthApp>", 60)

        portsinfo = []
        ori_drivers = []

        for portid in range(len(self.ports)):
            # dump eemprom by userspace ethtool
            self.dut.send_expect("eeprom %d eeprom_%d.bin" % (portid, portid), "EthApp>")
            portinfo = {'portid': portid, 'eeprom_file': 'eeprom_%d.bin' % portid}
            portsinfo.append(portinfo)

        self.dut.send_expect("quit", "# ")

        for index in range(len(self.ports)):
            port = self.ports[index]
            netdev = self.dut.ports_info[port]['port']
            portinfo = portsinfo[index]
            # strip orignal driver
            portinfo['ori_driver'] = netdev.get_nic_driver()
            portinfo['net_dev'] = netdev
            # bind to default driver
            netdev.bind_driver()
            # get linux interface
            intf = netdev.get_interface_name()
            ethtool_eeprom = "ethtool_eeprom_%d.bin" % index
            # dump eemprom by linux ethtool
            self.dut.send_expect("ethtool --eeprom-dump %s raw on > %s" % (intf, ethtool_eeprom), "# ")
            # wait for file ready
            time.sleep(2)
            portinfo['ethtool_eeprom'] = ethtool_eeprom
            # bind to original driver
            portinfo['net_dev'].bind_driver(portinfo['ori_driver'])

        for index in range(len(self.ports)):
            md5 = self.strip_md5(portsinfo[index]['eeprom_file'])
            md5_ref = self.strip_md5(portsinfo[index]['ethtool_eeprom'])
            print utils.GREEN("Reference eeprom md5 %s" % md5)
            print utils.GREEN("Reference eeprom md5_ref %s" % md5_ref)
            self.verify(md5 == md5_ref, "Dumped eeprom not same as linux dumped")

    def test_ring_parameter(self):
        """
        Test ethtool app ring parameter getting and setting
        """
        for index in range(len(self.ports)):
            self.dut.send_expect(self.cmd, "EthApp>", 60)
            port = self.ports[index]
            ori_rx_pkts, ori_tx_pkts = self.strip_portstats(port)
            _, rx_max, _, tx_max = self.strip_ringparam(index)
            self.dut.send_expect("ringparam %d %d %d" % (index, rx_max, tx_max), "EthApp>")
            rx_ring, _, tx_ring, _ = self.strip_ringparam(index)
            self.verify(rx_ring == rx_max, "Userspace tool failed to set Rx ring parameter")
            self.verify(tx_ring == tx_max, "Userspace tool failed to set Tx ring parameter")
            pkt = Packet()
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            pkt.send_pkt(tx_port=intf)
            rx_pkts, tx_pkts = self.strip_portstats(index)
            self.verify(rx_pkts == ori_rx_pkts + 1, "Failed to forward after ring parameter changed")
            self.dut.send_expect("quit", "# ")

    def test_ethtool_vlan(self):
        """
        Test ethtool app vlan add and delete
        """
        main_file = "examples/ethtool/ethtool-app/main.c"
        # enable vlan filter
        self.dut.send_expect("sed -i -e '/cfg_port.txmode.mq_mode = ETH_MQ_TX_NONE;$/a\\cfg_port.rxmode.hw_vlan_filter=1;' %s" % main_file, "# ")

        # build sample app
        self.build_ethtool()

        self.dut.send_expect(self.cmd, "EthApp>", 60)
        for index in range(len(self.ports)):
            port = self.ports[index]
            # generate random vlan
            vlan = random.randrange(0, 4095)
            # add vlan on port, record original statistic
            self.dut.send_expect("vlan %d add %d" % (index, vlan), "EthApp>")
            ori_rx_pkts, ori_tx_pkts = self.strip_portstats(port)

            # send correct vlan packet to port
            pkt = Packet(pkt_type='VLAN_UDP')
            pkt.config_layer('vlan', {'vlan': vlan})
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            pkt.send_pkt(tx_port=intf)
            rx_pkts, tx_pkts = self.strip_portstats(port)
            self.verify(rx_pkts == ori_rx_pkts + 1, "Failed to Rx vlan packet")
            self.verify(tx_pkts == ori_tx_pkts + 1, "Failed to Tx vlan packet")

            # send incorrect vlan packet to port
            wrong_vlan = (vlan + 1) % 4096
            pkt.config_layer('vlan', {'vlan': wrong_vlan})
            pkt.send_pkt(tx_port=intf)
            time.sleep(2)
            rx_pkts_wrong, _ = self.strip_portstats(port)
            self.verify(rx_pkts_wrong == rx_pkts, "Failed to filter Rx vlan packet")

            # remove vlan
            self.dut.send_expect("vlan %d del %d" % (index, vlan), "EthApp>")
            # send same packet and make sure not received
            pkt.config_layer('vlan', {'vlan': vlan})
            pkt.send_pkt(tx_port=intf)
            time.sleep(2)
            rx_pkts_del, _ = self.strip_portstats(port)
            self.verify(rx_pkts_del == rx_pkts, "Failed to remove Rx vlan filter")

        self.dut.send_expect("quit", "# ")
        self.dut.send_expect("sed -i -e '/hw_vlan_filter=1;$/d' %s" % main_file, "# ")
        # build sample app
        self.build_ethtool()

    def test_mac_address(self):
        """
        Test ethtool app mac function
        """
        valid_mac = "00:10:00:00:00:00"
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        for index in range(len(self.ports)):
            port = self.ports[index]
            mac = self.dut.ports_info[port]['mac']
            dump_mac = self.strip_mac(index)
            self.verify(mac == dump_mac, "Userspace tool failed to dump mac")
            self.dut.send_expect("macaddr %d %s" % (port, valid_mac), "EthApp>")
            dump_mac = self.strip_mac(index)
            self.verify(dump_mac == valid_mac, "Userspace tool failed to set mac")
            # check forwarded mac has been changed
            pkt = Packet()
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            # send and sniff packet
            inst = sniff_packets(intf, timeout=5)
            pkt.send_pkt(tx_port=intf)
            pkts = load_sniff_packets(inst)
            self.verify(len(pkts) == 1, "Packet not forwarded as expected")
            src_mac = pkts[0].strip_layer_element("layer2", "src")
            self.verify(src_mac == valid_mac, "Forwarded packet not match default mac")

        # check multicase will not be valid mac
        invalid_mac = "01:00:00:00:00:00"
        out = self.dut.send_expect("validate %s" % invalid_mac, "EthApp>")
        self.verify("not unicast" in out, "Failed to detect incorrect unicast mac")
        invalid_mac = "00:00:00:00:00:00"
        out = self.dut.send_expect("validate %s" % invalid_mac, "EthApp>")
        self.verify("not unicast" in out, "Failed to detect incorrect unicast mac")
        out = self.dut.send_expect("validate %s" % valid_mac, "EthApp>")
        self.verify("is unicast" in out, "Failed to detect correct unicast mac")
        self.dut.send_expect("quit", "# ")

    def test_port_config(self):
        """
        Test ethtool app port configure
        """
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        for index in range(len(self.ports)):
            port = self.ports[index]
            ori_rx_pkts, _ = self.strip_portstats(index)
            # stop port
            self.dut.send_expect("stop %d" % index, "EthApp>")
            # check packet not forwarded when port is stop
            pkt = Packet()
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            pkt.send_pkt(tx_port=intf)
            rx_pkts, tx_pkts = self.strip_portstats(index)
            self.verify(rx_pkts == ori_rx_pkts, "Failed to stop port")
            # restart port and check packet can normally forwarded
            time.sleep(2)
            self.dut.send_expect("open %d" % index, "EthApp>")
            # wait few time for port ready
            rx_pkts, tx_pkts = self.strip_portstats(index)
            time.sleep(2)
            pkt.send_pkt(tx_port=intf)
            rx_pkts_open, tx_pkts_open = self.strip_portstats(index)
            self.verify(rx_pkts_open == rx_pkts + 1, "Failed to reopen port rx")
            self.verify(tx_pkts_open == tx_pkts + 1, "Failed to reopen port tx")

        self.dut.send_expect("quit", "# ")

    def test_port_mtu(self):
        """
        Test ethtool app port mtu configure
        """
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        mtus = [1519, 2048]
        for index in range(len(self.ports)):
            port = self.ports[index]
            # change mtu
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            ori_mtu = self.strip_mtu(intf)
            self.tester.send_expect("ifconfig %s mtu 9000" % (intf), "# ")
            for mtu in mtus:
                self.dut.send_expect("mtu %d %d" % (index, mtu), "EthApp>")
                ori_rx_pkts, _ = self.strip_portstats(index)
                pkt_size = mtu + HEADER_SIZE['eth']
                pkt = Packet(pkt_len=pkt_size)
                pkt.send_pkt(tx_port=intf)
                rx_pkts, _ = self.strip_portstats(index)
                self.verify(rx_pkts == ori_rx_pkts, "Packet match mtu not forwarded as expected")
                pkt = Packet(pkt_len=mtu + 1)
                pkt.send_pkt(tx_port=intf)
                rx_pkts_over, _ = self.strip_portstats(index)
                self.verify(rx_pkts == rx_pkts_over, "Packet over mtu should not be forwarded")

            self.tester.send_expect("ifconfig %s mtu %d" % (intf, ori_mtu), "# ")

        self.dut.send_expect("quit", "# ")

    def test_perf_port_rx_pause(self):
        """
        Test ethtool app flow control configure
        """
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        # enable pause rx
        self.dut.send_expect("pause 0 rx", "EthApp")

        # calculate number of packets
        pps = self.wirespeed(self.nic, self.frame_size, 1) * 1000000.0
        # get line rate
        linerate = pps * (self.frame_size + 20) * 8
        # calculate default sleep time for one pause frame
        sleep = (1 / linerate) * self.pause_time * 512
        # calculate packets dropped in sleep time
        self.n_pkts = int((sleep / (1 / pps)) * (1 / self.pause_rate))

        tgen_input = []
        headers_size = HEADER_SIZE['eth'] + HEADER_SIZE['ip'] + \
            HEADER_SIZE['udp']
        payload_size = self.frame_size - headers_size
        self.tester.scapy_append('wrpcap("pause_rx.pcap", [Ether()/IP()/UDP()/("X"*%d)])' % payload_size)
        self.tester.scapy_execute()
        # rx and tx is the same port
        tester_port = self.tester.get_local_port(self.ports[0])
        tgen_input.append((tester_port, tester_port, "pause_rx.pcap"))

        ori_func = self.config_stream
        self.config_stream = self.config_stream_pause_rx
        _, rx_pps = self.tester.traffic_generator_throughput(tgen_input)
        self.config_stream = ori_func

        rate = rx_pps / pps
        # rate should same as expected rate
        self.verify(rate > (self.pause_rate - 0.01) and
                    rate < (self.pause_rate + 0.01), "Failed to handle Rx pause frame")

        self.dut.send_expect("quit", "# ")

    def test_perf_port_tx_pause(self):
        """
        Test ethtool app flow control configure
        """
        # sleep a while when receive packets
        main_file = "examples/ethtool/ethtool-app/main.c"
        self.dut.send_expect("sed -i -e '/if (cnt_recv_frames > 0) {$/i\usleep(10);' %s" % main_file, "# ")
        # build sample app
        self.build_ethtool()
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        # enable pause tx
        self.dut.send_expect("pause 0 tx", "EthApp")

        tgen_input = []
        headers_size = HEADER_SIZE['eth'] + HEADER_SIZE['ip'] + \
            HEADER_SIZE['udp']
        payload_size = self.frame_size - headers_size
        self.tester.scapy_append('wrpcap("pause_tx.pcap", [Ether()/IP()/UDP()/("X"*%d)])' % payload_size)
        self.tester.scapy_execute()
        # rx and tx is the same port
        tester_port = self.tester.get_local_port(self.ports[0])
        tgen_input.append((tester_port, tester_port, "pause_tx.pcap"))

        self.wirespeed(self.nic, self.frame_size, 1) * 1000000.0
        _, tx_pps = self.tester.traffic_generator_throughput(tgen_input)

        # verify ixia transmit line rate dropped
        pps = self.wirespeed(self.nic, self.frame_size, 1) * 1000000.0
        rate = tx_pps / pps
        self.verify(rate < 0.1, "Failed to slow down transmit speed")

        # verify received packets more than sent
        self.stat_get_stat_all_stats(tester_port)
        sent_pkts = self.get_frames_sent()
        recv_pkts = self.get_frames_received()
        self.verify((float(recv_pkts) / float(sent_pkts)) > 1.05, "Failed to transmit pause frame")

        self.dut.send_expect("quit", "# ")
        self.dut.send_expect("sed -i -e '/usleep(10);$/d' %s" % main_file, "# ")
        # rebuild sample app
        self.build_ethtool()

    def config_stream_pause_rx(self, fpcap, txport, rate_percent, stream_id=1, latency=False):
        """
        Configure IXIA stream with pause frame and normal packet
        """
        # enable flow control on port
        self.add_tcl_cmd("port config -flowControl true")
        self.add_tcl_cmd("port config -flowControlType ieee8023x")
        self.add_tcl_cmd("port set %d %d %d" % (self.chasId, txport['card'], txport['port']))

        flows = self.parse_pcap(fpcap)

        self.add_tcl_cmd("ixGlobalSetDefault")
        self.add_tcl_cmd("stream config -rateMode usePercentRate")
        self.add_tcl_cmd("stream config -percentPacketRate 100")
        self.add_tcl_cmd("stream config -numBursts 1")
        self.add_tcl_cmd("stream config -numFrames %d" % self.n_pkts)
        self.add_tcl_cmd("stream config -dma advance")

        pat = re.compile(r"(\w+)\((.*)\)")
        for header in flows[0].split('/'):
            match = pat.match(header)
            params = eval('dict(%s)' % match.group(2))
            method_name = match.group(1)
            if method_name in SCAPY2IXIA:
                method = getattr(self, method_name.lower())
                method(txport, **params)

        # stream id start from 1
        self.add_tcl_cmd("stream set %d %d %d %d" % (self.chasId, txport['card'], txport['port'], 1))

        # pause frame stream
        self.add_tcl_cmd("stream config -rateMode usePercentRate")
        self.add_tcl_cmd("stream config -percentPacketRate 100")
        self.add_tcl_cmd("stream config -numBursts 1")
        self.add_tcl_cmd("stream config -numFrames 1")
        self.add_tcl_cmd("stream config -dma gotoFirst")

        self.add_tcl_cmd("protocol setDefault")
        self.add_tcl_cmd("protocol config -name pauseControl")
        self.add_tcl_cmd("pauseControl setDefault")
        self.add_tcl_cmd("pauseControl config -da \"01 80 C2 00 00 01\"")
        self.add_tcl_cmd("pauseControl config -pauseTime %d" % self.pause_time)
        self.add_tcl_cmd("pauseControl config -pauseControlType ieee8023x")
        self.add_tcl_cmd("pauseControl set %d %d %d" % (self.chasId, txport['card'], txport['port']))
        self.add_tcl_cmd("stream set %d %d %d %d" %
                         (self.chasId, txport['card'], txport['port'], 2))

    def tear_down(self):
        """
        Run after each test case.
        """
        self.dut.kill_all()
        pass

    def tear_down_all(self):
        """
        Run after each test suite.
        """
        self.dut.kill_all()