• dts--framework(二)


    Framwork下个文件中包含的函数

    packet.py

    LayersTypes = 
    {
        "L2": ['ether', 'vlan', 'etag', '1588', 'arp', 'lldp'],
        # ipv4_ext_unknown, ipv6_ext_unknown
        "L3": ['ipv4', 'ipv4ihl', 'ipv6', 'ipv4_ext', 'ipv6_ext', 'ipv6_ext2', 'ipv6_frag'],
        "L4": ['tcp', 'udp', 'frag', 'sctp', 'icmp', 'nofrag'],
        "TUNNEL": ['ip', 'gre', 'vxlan', 'nvgre', 'geneve', 'grenat'],
        "INNER L2": ['inner_mac', 'inner_vlan'],
        # inner_ipv4_unknown, inner_ipv6_unknown
        "INNER L3": ['inner_ipv4', 'inner_ipv4_ext', 'inner_ipv6', 'inner_ipv6_ext'],
        "INNER L4": ['inner_tcp', 'inner_udp', 'inner_frag', 'inner_sctp', 'inner_icmp', 'inner_nofrag'],
        "PAYLOAD": ['raw']
    }
    # Saved back groud sniff process id
    SNIFF_PIDS = {}
    # Saved packet generator process id
    # used in pktgen or tgen
    PKTGEN_PIDS = {}
    # default filter for LLDP packet
    LLDP_FILTER = {'layer': 'ether', 'config': {'type': 'not lldp'}}
    
    class scapy
        SCAPY_LAYERS =
            'ether': Ether(dst="ff:ff:ff:ff:ff:ff"),
            'vlan': Dot1Q(),
            'etag': Dot1BR(),
        00.__init__(self)
        01.assign_pkt(self, pkt)
        02.add_layers(self, layers)
        03.ether(self, pkt_layer, dst="ff:ff:ff:ff:ff:ff", src="00:00:20:00:00:00", type=None)
        04.vlan(self, pkt_layer, vlan, prio=0, type=None)
        05.strip_vlan(self, element)
        06.etag(self, pkt_layer, ECIDbase=0, prio=0, type=None)
        07.strip_etag(self, element)
        08.strip_layer2(self, element)
        09.strip_layer3(self, element)
        10.strip_layer4(self, element)
        11.ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0, dst="127.0.0.1", chksum=None, len=None, version=4, flags=None, ihl=None, ttl=64, id=1, options=None)
        12.ipv6(self, pkt_layer, version=6, tc=0, fl=0, plen=0, nh=0, hlim=64, src="::1", dst="::1")
        13.tcp(self, pkt_layer, src=53, dst=53, flags=None, len=None, chksum=None)
        14.udp(self, pkt_layer, src=53, dst=53, len=None, chksum=None)
        15.sctp(self, pkt_layer, src=53, dst=53, tag=None, len=None, chksum=None)
        16.raw(self, pkt_layer, payload=None)
        17.gre(self, pkt_layer, proto=None)
        18.vxlan(self, pkt_layer, vni=0)
        19.read_pcap(self, file)
        20.write_pcap(self, file)
        21.send_pcap_pkt(self, crb=None, file='', intf='', count=1)
        22.print_summary(self)
        23.send_pkt(self, intf='', count=1)
        
    class Packet
        def_packet = 
            'TIMESYNC': {'layers': ['ether', 'raw'], 'cfgload': False},
            'ARP': {'layers': ['ether', 'arp'], 'cfgload': False},
            'LLDP': {'layers': ['ether', 'lldp'], 'cfgload': False},
        00.__init__(self, **options)
        01._load_assign_layers(self)
        02.send_pkt(self, crb=None, tx_port='', auto_cfg=True, count=1)
        03.check_layer_config(self, layer, config)
        04.assign_layers(self, layers=None)
        05._load_pkt_layers(self)
        06.config_def_layers(self)
        07.config_layer(self, layer, config={})
        08.config_layers(self, layers=None)
        09._config_layer_ether(self, pkt_layer, config):
        10._config_layer_mac(self, pkt_layer, config):
        11._config_layer_vlan(self, pkt_layer, config):
        12._config_layer_etag(self, pkt_layer, config):
        13._config_layer_ipv4(self, pkt_layer, config):
        14._config_layer_ipv6(self, pkt_layer, config):
        15._config_layer_udp(self, pkt_layer, config):
        16._config_layer_tcp(self, pkt_layer, config):
        17._config_layer_sctp(self, pkt_layer, config):
        18._config_layer_gre(self, pkt_layer, config):
        19._config_layer_raw(self, pkt_layer, config):
        20._config_layer_vxlan(self, pkt_layer, config):
        21.strip_layer_element(self, layer, element)
        22.strip_element_layer2(self, element)
        23.strip_element_layer3(self, element)
        24.strip_element_vlan(self, element)
        25.strip_element_etag(self, element)
        26.strip_element_layer4(self, element)
    
    31.IncreaseIP(addr)
    32.IncreaseIPv6(addr)
    33.send_packets(intf, pkts=None, interval=0.01)
    34.save_packets(pkts=None, filename=None)
    35.get_ether_type(eth_type="")
    36.get_filter_cmd(filters=[])
    37.sniff_packets(intf, count=0, timeout=5, filters=[])
    38.load_sniff_pcap(index='')
    39.load_sniff_packets(index='')
    40.load_pcapfile(filename="")
    41.compare_pktload(pkt1=None, pkt2=None, layer="L2")
    42.strip_pktload(pkt=None, layer="L2")

    pmd_out.py

    """
        Module for get all statics value by port in testpmd
    """
    pmd_output
        01.__init__(self,dut)
        02.get_pmd_value(self, prefix, out)
        03.set_default_corelist(self)
        04.get_pmd_stats(self, portid)
        05.get_pmd_cmd(self)
        06.start_testpmd(self, cores, param='', eal_param='', socket=0)
        07.execute_cmd(self, pmd_cmd, expected='testpmd> ', timeout=TIMEOUT,
                            alt_session=False)
        08.get_output(self, timeout=1)
        09.get_value_from_string(self, key_str, regx_str, string)
        10.get_detail_from_port_info(self, key_str, regx_str, port)
        11.get_port_mac(self, port_id)
        12.get_port_connect_socket(self, port_id)
        13.get_port_memory_socket(self, port_id)
        14.get_port_link_status(self, port_id)
        15.get_port_link_speed(self, port_id)
        16.get_port_link_duplex(self, port_id)
        17.get_port_promiscuous_mode(self, port_id)
        18.get_port_allmulticast_mode(self, port_id)
        19.check_tx_bytes(self, tx_bytes, exp_bytes = 0)
        20.get_port_vlan_offload(self, port_id)
        21.quit(self)

    ssh.py

    '''
    Module for create session to host.
    Implement(执行) send_expect/copy function upper SSHPexpet module.
    '''
    class SSHConnection(object):
        01.init_log(self, logger):
        02.set_history(self, history):
        03.send_expect(self, cmds, expected, timeout=15, verify=False):
        04.send_command(self, cmds, timeout=1):
        05.get_session_before(self, timeout=15):
        06.close(self, force=False):
        07.isalive(self):
        08.check_available(self):
        09.copy_file_from(self, src, dst=".", password=''):
        10.copy_file_to(self, src, dst="~/", password=''):

    pexpect.py

    '''
    Module handle ssh sessions between tester and DUT.
    Implement send_expect function to send command and get output data.
    Aslo support transfer files to tester or DUT
    '''
    class SSHPexpect(object):
        @parallel_lock(num=8)
        01._connect_host(self, dut_id=0):
        02.init_log(self, logger, name):
        03.send_expect_base(self, command, expected, timeout):
        04.send_expect(self, command, expected, timeout=15, verify=False):
        05.send_command(self, command, timeout=1):
        06.clean_session(self):
        07.get_session_before(self, timeout=15):
        08.__flush(self):
        09.__prompt(self, command, timeout):
        10.__sendline(self, command):
        11.get_output_before(self):
        12.get_output_all(self):
        13.close(self, force=False):
        14.isalive(self):
        15.copy_file_from(self, src, dst=".", password=''):
        16.copy_file_to(self, src, dst="~/", password=''):
        17._spawn_scp(self, scp_cmd, password):
  • 相关阅读:
    Lyft Level 5 Challenge 2018
    Codeforces Round #514 (Div. 2)题解
    Bubble Cup 11
    不如来搞一下CDQ分治吧!
    Codeforces Round #331 (Div. 2)
    写一下中国剩余定理的证明
    codeforces Round#332Div2 题解
    GCPC2017 题解
    2017 USP Try-outs 题解
    CodeForce 387D. George and Interesting Graph
  • 原文地址:https://www.cnblogs.com/eilinge/p/9799285.html
Copyright © 2020-2023  润新知