trex-emu测试ping功能

  • trex配置文件

trex_cfg.yaml

- port_limit      : 2
  version         : 2
#List of interfaces. Change to suit your setup. Use ./dpdk_setup_ports.py -s to see available options
  interfaces    : ["00:09.0","00:0a.0"] 
  port_info       :  # Port IPs. Change to suit your needs. In case of loopback, you can leave as is.
          - ip         : 30.4.0.233
            default_gw : 30.4.0.254
          - ip         : 30.5.0.233
            default_gw : 30.5.0.254
  • 启动trex 服务
./t-rex-64 -i --software --emu
  • 启动trex-console
./trex-console 
trex>plugins load emu
trex>help
Console Commands:

capture -                      Manage PCAP captures          
debug -                        Internal debugger for development.
events -                       Shows events log              
help -                         Shows This Help Screen        
history -                      Manage the command history    
plugins -                      Show / load / use plugins     
quit -                         Exit the console              
tui -                          Shows a graphical console     
verbose -                      Shows or set verbose mode     

Common Commands:

acquire -                      Acquire ports                 
arp -                          Performs a port ARP resolution
clear -                        Clear cached local statistics 
connect -                      Connects to the TRex server and acquire ports
disconnect -                   Disconnect from the TRex server
global_cfg -                   Set global configuration parameters
ipv6 -                         Configures IPv6 of a port     
l2 -                           Configures a port in L2 mode  
l3 -                           Configures a port in L3 mode  
map -                          Maps ports topology           
ns -                           Network namespace             
ping -                         Pings the server / specific IP
pkt -                          Sends a Scapy format packet   
portattr -                     Sets port attributes          
release -                      Release ports                 
reset -                        Reset ports                   
scan6 -                        Search for IPv6 neighbors     
shutdown -                     Shutdown the server           
stats -                        Show various statistics       
vlan -                         Configures VLAN tagging for a port.

Stateless Commands:

pause -                        Pause active traffic on specified ports on TRex
profiles -                     Get loaded to server profiles information
push -                         Push a pcap file              
resume -                       Resume active traffic on specified ports on TRex
service -                      Configures port for service mode.
start -                        Start selected traffic on specified ports on TRex
stop -                         Stop active traffic on specified ports on TRex
streams -                      Get loaded to server streams information
update -                       Update port(s) speed currently active

Emulation Commands:

emu_appsim_show_counters -     Show appsim counters (per client).
emu_arp_cmd_query -            Arp cmd query command         
emu_arp_get_cfg -              Arp get configuration command 
emu_arp_set_cfg -              Arp set configuration command 
emu_arp_show_cache -           Arp show cache command        
emu_arp_show_counters -        Show arp counters data from arp table.
emu_cdp_show_counters -        Show cdp counters (per client).
emu_dhcp_show_counters -       Show dhcp counters (per client).
emu_dhcpsrv_show_counters -    Show DHCP Server counters.    
emu_dhcpv6_show_counters -     Show dhcpv6 counters (per client).
emu_dns_flush_cache -          Flush Dns Resolver cache.     
emu_dns_query -                Dns Query for Dns Resolver.   
emu_dns_show_c_counters -      Show DNS client counters.     
emu_dns_show_cache -           Show resolved domains for a Dns Resolver
emu_dns_show_domain_entries -  Show entries of Dns Domain in the Name Server.
emu_dns_show_domains -         Show domains a Name Server holds.
emu_dns_show_ns_counters -     Show DNS namespace counters.  
emu_dot1x_show_all -           Show dot1x client info (per 1 ns).
emu_dot1x_show_client_info -   Show dot1x client info (per 1 client).
emu_dot1x_show_counters -      Show dot1x counters (per client).
emu_icmp_ping -                ICMP ping utility (per client).
emu_icmp_show_counters -       Show Icmp counters (per client).
emu_igmp_add_mc -              IGMP add mc command           
emu_igmp_add_mc_sg -           IGMP add mc command           
emu_igmp_get_cfg -             IGMP get configuration command
emu_igmp_remove_all_mc -       IGMP remove all mc command    
emu_igmp_remove_mc -           IGMP remove mc command        
emu_igmp_remove_mc_sg -        IGMP remove mc command        
emu_igmp_set_cfg -             IGMP set configuration command
emu_igmp_show_counters -       Show IGMP counters data from igmp table.
emu_igmp_show_mc -             IGMP show mc command          
emu_ipfix_disable_gen -        Disable an IPFix generator.   
emu_ipfix_enable_gen -         Enable an IPFix generator.    
emu_ipfix_get_gen_info -       Get IPFix generators information.
emu_ipfix_set_data_rate -      Set IPFix generator data rate.
emu_ipfix_set_template_rate -  Set IPFix generator template rate.
emu_ipfix_show_counters -      Show IPFix data counters data.
emu_ipv6_add_mld -             IPV6 add mld command          
emu_ipv6_add_mld_sg -          MLD add mc command            
emu_ipv6_get_cfg -             IPV6 get configuration command
emu_ipv6_ping -                ICMPv6 ping utility (per client).
emu_ipv6_remove_all_mld -      IPV6 remove all mld command   
emu_ipv6_remove_mld -          IPV6 remove mld command       
emu_ipv6_remove_mld_sg -       MLD remove mc command         
emu_ipv6_set_cfg -             IPV6 set configuration command
emu_ipv6_show_cache -          IPV6 show cache command       
emu_ipv6_show_counters -       Show IPV6 counters data from ipv6 table.
emu_ipv6_show_mld -            IPV6 show mld command         
emu_lldp_show_counters -       Show lldp counters (per client).
emu_load_profile -             Load a given profile to emu server
emu_mdns_add_hosts -           Add hosts to mDNS client.     
emu_mdns_flush_cache -         Flush mDNS namespace cache.   
emu_mdns_query -               Query mDNS.                   
emu_mdns_remove_hosts -        Remove hosts from mDNS client.
emu_mdns_show_c_counters -     Show mDNS client counters.    
emu_mdns_show_cache -          Show resolved hostnames in mDNS namespace
emu_mdns_show_hosts -          Show hosts of mDNS client.    
emu_mdns_show_ns_counters -    Show mDNS namespace counters. 
emu_remove_profile -           Remove current profile from emu server
emu_show_all -                 Show all current namespaces & clients
emu_show_client_info -         Show client information       
emu_show_counters -            Show counters data from ctx according to given tables.
emu_show_mbuf -                Show mbuf usage in a table.   
emu_show_ns_info -             Show namespace information    
emu_shutdown -                 Shutdown the EMU server.      
emu_tdl_show_counters -        Show Tdl counters.            
emu_transe_show_counters -     Show transport example counters (per ns).
emu_transport_show_counters -  Show transport counters (per client).
  • 加载profile
trex>emu_load_profile -f emu/simple_icmp.py -t  --ns 1 --clients 3

Converting file to profile                                   [SUCCESS]

Converting profile took: 3.53 [ms]

Removing old emu profile                                     [SUCCESS]


Sending emu profile                                          
[SUCCESS]                               

Sending profile took: 20.41 [ms]
26.36 [ms]

simple_icmp.py文件如下:

from trex.emu.api import *
import argparse


class Prof1():
    def __init__(self):
        self.def_ns_plugs  = {'icmp': {},
                              'arp' : {'enable': True}}

        self.def_c_plugs  = {'arp':  {'enable': True},
                             'icmp': {},
                             }

    def create_profile(self, ns_size, clients_size):
        ns_list = []

        # create different namespace each time
        vport, tci, tpid = 0, [0, 0], [0x00, 0x00]
        for i in range(vport, ns_size + vport):
            ns_key = EMUNamespaceKey(vport  = i,
                                    tci     = tci,
                                    tpid    = tpid)
            ns = EMUNamespaceObj(ns_key = ns_key, def_c_plugs = self.def_c_plugs)

            mac = Mac('00:00:00:70:00:03')
            ipv4 = Ipv4('30.4.0.234')
            dg = Ipv4('30.4.0.254')

            # create a different client each time
            for j in range(clients_size):
                client = EMUClientObj(mac     = mac[j].V(),
                                      ipv4    = ipv4[j].V(),
                                      ipv4_dg = dg.V())
                ns.add_clients(client)
            ns_list.append(ns)

        return EMUProfile(ns = ns_list, def_ns_plugs = self.def_ns_plugs)

    def get_profile(self, tuneables):
        # Argparse for tunables
        parser = argparse.ArgumentParser(description='Argparser for simple emu profile.')
        parser.add_argument('--ns', type = int, default = 1,
                    help='Number of namespaces to create')
        parser.add_argument('--clients', type = int, default = 15,
                    help='Number of clients to create in each namespace')

        args = parser.parse_args(tuneables)

        assert args.ns > 0, 'namespaces must be positive!'
        assert args.clients > 0, 'clients must be positive!'

        return self.create_profile(args.ns, args.clients)


def register():
    return Prof1()
  • ping模拟的设备
trex>portattr -a
Port Status

     port       |          0           |          1           
----------------+----------------------+---------------------
driver          |     net_i40e_vf      |     net_i40e_vf      
description     |  Ethernet Virtual F  |  Ethernet Virtual F  
link status     |          UP          |          UP          
link speed      |       40 Gb/s        |       40 Gb/s        
port status     |         IDLE         |         IDLE         
promiscuous     |         off          |         off          
multicast       |         off          |         off          
flow ctrl       |         N/A          |         N/A          
vxlan fs        |          -           |          -           
--              |                      |                      
layer mode      |         IPv4         |         IPv4         
src IPv4        |      30.4.0.233      |      30.5.0.233      
IPv6            |         off          |         off          
src MAC         |  fa:16:3e:6f:51:ad   |  fa:16:3e:85:a3:4e   
---             |                      |                      
Destination     |      30.4.0.254      |      30.5.0.254      
ARP Resolution  |  c4:70:ab:ea:75:65   |  c4:79:ab:ea:9f:23   
----            |                      |                      
VLAN            |          -           |          -           
-----           |                      |                      
PCI Address     |     0000:00:09.0     |     0000:00:0a.0     
NUMA Node       |          0           |          0           
RX Filter Mode  |    hardware match    |    hardware match    
RX Queueing     |         off          |         off          
Grat ARP        |  every 120 seconds   |  every 120 seconds   
------          |                      |                      

trex>emu_show_all 
Namespace #1 Information

Port | Vlan tags | Tpids |  Plugins  | #Clients 
-----+-----------+-------+-----------+---------
 0   |     -     |   -   | arp, icmp |    3     

Clients Information

       MAC        |    IPv4    |  DG-IPv4   | MTU  |  Plugins  
------------------+------------+------------+------+----------
00:00:00:70:00:03 | 30.4.0.234 | 30.4.0.254 | 1500 | arp, icmp 
00:00:00:70:00:04 | 30.4.0.235 | 30.4.0.254 | 1500 | arp, icmp 
00:00:00:70:00:05 | 30.4.0.236 | 30.4.0.254 | 1500 | arp, icmp 

24.53 [ms]

trex>emu_icmp_ping -p 0 --mac 00:00:00:70:00:03

Starting to ping :                                           [SUCCESS]

Progress: 100.00%, Sent: 5/5, Rcv: 0/5, Err: 0/5, RTT min/avg/max = 0.00/0.00/0.00 ms                                   

Completed

trex>
posted @ 2022-01-13 11:10  staylight  阅读(374)  评论(0编辑  收藏  举报