def tcp_packet(self, setup, direction, ptfadapter, ip_version, src_ip=None, dst_ip=None, proto=None, sport=17185, dport=81, flags=None):
    'Generate a TCP packet for testing.'
    src_ip = (src_ip or DEFAULT_SRC_IP[ip_version])
    dst_ip = (dst_ip or self.get_dst_ip(direction, ip_version))
    if (ip_version == 'ipv4'):
        pkt = testutils.simple_tcp_packet(eth_dst=setup['destination_mac'][direction][self.src_port], eth_src=ptfadapter.dataplane.get_mac(0, 0), ip_dst=dst_ip, ip_src=src_ip, tcp_sport=sport, tcp_dport=dport, ip_ttl=64)
        if proto:
            pkt['IP'].proto = proto
    else:
        pkt = testutils.simple_tcpv6_packet(eth_dst=setup['destination_mac'][direction][self.src_port], eth_src=ptfadapter.dataplane.get_mac(0, 0), ipv6_dst=dst_ip, ipv6_src=src_ip, tcp_sport=sport, tcp_dport=dport, ipv6_hlim=64)
        if proto:
            pkt['IPv6'].nh = proto
    if flags:
        pkt['TCP'].flags = flags
    return pkt
Generate a TCP packet for testing.
def tcp_packet(self, setup, direction, ptfadapter, ip_version, src_ip=None, dst_ip=None, proto=None, sport=17185, dport=81, flags=None):
    
    src_ip = (src_ip or DEFAULT_SRC_IP[ip_version])
    dst_ip = (dst_ip or self.get_dst_ip(direction, ip_version))
    if (ip_version == 'ipv4'):
        pkt = testutils.simple_tcp_packet(eth_dst=setup['destination_mac'][direction][self.src_port], eth_src=ptfadapter.dataplane.get_mac(0, 0), ip_dst=dst_ip, ip_src=src_ip, tcp_sport=sport, tcp_dport=dport, ip_ttl=64)
        if proto:
            pkt['IP'].proto = proto
    else:
        pkt = testutils.simple_tcpv6_packet(eth_dst=setup['destination_mac'][direction][self.src_port], eth_src=ptfadapter.dataplane.get_mac(0, 0), ipv6_dst=dst_ip, ipv6_src=src_ip, tcp_sport=sport, tcp_dport=dport, ipv6_hlim=64)
        if proto:
            pkt['IPv6'].nh = proto
    if flags:
        pkt['TCP'].flags = flags
    return pkt