Skip to content

HOWTO write a PTF Test

engdorm edited this page Oct 18, 2016 · 2 revisions

GitHub Repo for PTF

https://github.com/p4lang/ptf

Example packet construction, verification, sending code

ptf/src/ptf/testutils.py -Scapy- packet manipulation program is used to construct packets -Scapy supports many protocols, type ls() in scapy interactive shell to see a list of protocols

PTF Setup for SONiC

  1. Have a directory with PTF tests to run

  2. Have a run script outside the PTF test directory

  • ptf --test-dir --platform remote -t "parameter1='abc';parameter2=7"
  • --qlen allows users to specify number of packets that the ingress queue will hold (default is 100, will drop after max)
  • -t allows users to specify test input parameters (ip addresses, vlan ids, etc)
  • remote platform is used to provide support for testing ports on a different host
  • All the tests inside the directory will be run with run script above

Adding new protocol support

  • ensure /usr/lib/python2.7/dist-utils/ptf/packet.py imports and defines the protocol you want to use

  • if protocol is currently supported then add new import and define the protocol you want to add (maintain the structure of import and define)

verify_packet() function

  • will poll specific or all interfaces (depends on which function is called) until expected packet is matched or until polling timer expires

  • can use the filter feature to only look for specific types of protocols, for example IPv4 only

  • does a bit by bit comparison of the received packet with the expected packet

  • in some cases some fields of the packet may vary or not be known (eth_src, specific fields such as time elapsed inside packet header)

  • use the mask feature to mask out specific bits or headers inside the packet

  • some well-known header fields are supported by default such as eth_src, udp_chksum, ip_chksum

  • others such as "dhcp lease-time" may not be supported and will have to be masked out manually by using (Mask.set_do_not_care())

  • users must specify a bit offset and number of bits to mask out

Other verifiy functions

It is preferred to use verify_packets function as it check that no other unexpected packet has arrived unless --ralax flag is added to the running line. For other cases please see other verify functions in the test_utils.py that is the ptf git under src\ptf

Adding protocol construction support to testutils.py

To add a protocol to the testutils.py then make a generic function header which allows most if not all the fields in the packet to be passed in as parameters. For some complex protocols it may be okay to hardcode some values (ex: ptf/src/testutils.py --> dhcp discover/offer/request/ack functions).

Questions for PTF Setup

  • What does the network topology look like? One server with multiple docker PTF containers?
  • Is each PTF container connected to one switch?
  • Are there fan out switches between server and switches?
  • Will each docker PTF container be on a separate vlan?
  • Will docker PTF containers be deployed via ansible?
Clone this wiki locally