@@ -48,7 +48,7 @@ The following software is required to run PTF:
4848
4949Root/sudo privilege is required on the host, in order to run ` ptf ` .
5050
51- The default packet manipulator tool for ` ptf ` is ` Scapy ` . To install it use:
51+ The default packet manipulation module for ` ptf ` is ` Scapy ` . To install it use:
5252``` text
5353pip install scapy==2.5.0
5454```
@@ -72,6 +72,94 @@ yum install tcpdump
7272apt-get install tcpdump
7373```
7474
75+ ### Using ` bf_pktpy ` as an alternate packet manipulation module
76+
77+ The Python module ` bf_pktpy ` is included as part of the
78+ ` open-p4studio ` repository:
79+
80+ + https://github.com/p4lang/open-p4studio/tree/main/pkgsrc/ptf-modules/bf-pktpy
81+
82+ It was developed as an alternative to ` scapy ` . The tradeoffs of using
83+ ` bf_pktpy ` vs. ` scapy ` are:
84+
85+ + ` scapy ` implements more functionality, but is licensed under the
86+ copyleft GNU General Public License v2.0 (see
87+ https://github.com/secdev/scapy/blob/master/LICENSE ), so may be
88+ undesirable in use cases where you wish your tests to be released
89+ under a different license.
90+ + ` bf_pktpy ` implements only a small subset of the functionality of
91+ ` scapy ` , but it does include support for very commonly-used packet
92+ headers. It is released under an Apache 2.0 license (see
93+ https://github.com/p4lang/open-p4studio/blob/main/pkgsrc/ptf-modules/bf-pktpy/LICENSE ).
94+
95+ The package ` bf_pktpy ` is not currently available from PyPI. To
96+ install ` bf_pktpy ` from source code, choose one of these methods:
97+
98+ ``` bash
99+ pip install " bf-pktpy@git+https://github.com/p4lang/open-p4studio#subdirectory=pkgsrc/ptf-utils/bf-pktpy"
100+ ```
101+
102+ ``` bash
103+ git clone https://github.com/p4lang/open-p4studio
104+ cd open-p4studio/pkgsrc/ptf-utils/bf-pktpy
105+ pip install .
106+ ```
107+
108+ To make effective use of ` bf_pktpy ` you must also install these
109+ additional Python packages. All are released under an MIT or
110+ BSD-3-Clause license, which are compatible for releasing with
111+ ` bf_pktpy ` , or for importing in a project with most licenses,
112+ including ` Apache-2.0 ` , ` BSD-3-Clause ` , ` GPL-2.0-only ` , or many
113+ others.
114+
115+ ``` bash
116+ pip install six getmac scapy_helper psutil
117+ sudo apt-get install python3-dev
118+ pip install netifaces
119+ ```
120+
121+ If you want to use ` bf_pktpy ` when running the command ` ptf ` from the
122+ command line, provide the ` -pmm ` option as shown below.
123+
124+ ``` bash
125+ ptf -pmm bf_pktpy.ptf.packet_pktpy < other command line arguments>
126+ ```
127+
128+ If you want to write a Python program that imports ` ptf ` and causes it
129+ to use ` bf_pktpy ` instead of the default ` scapy ` , you can do so as
130+ follows in your Python code:
131+
132+ ``` python
133+ import ptf
134+ ptf.config[" packet_manipulation_module" ] = " bf_pktpy.ptf.packet_pktpy"
135+ import ptf.packet
136+ ```
137+
138+ The above methods are the highest precedence way of choosing the
139+ packet manipulation module used by ` ptf ` . If you do not use those
140+ methods, another way is to assign the packet manipulation module name
141+ to the environment variable ` PTF_PACKET_MANIPULATION_MODULE ` , e.g. in
142+ Bash:
143+
144+ ``` bash
145+ export PTF_PACKET_MANIPULATION_MODULE=" bf_pktpy.ptf.packet_pktpy"
146+ ```
147+
148+ When running such a program, you should see the following line printed
149+ to standard output confirming that it is using ` bf_pktpy ` instead of
150+ ` scapy ` :
151+
152+ ``` text
153+ Using packet manipulation module: bf_pktpy.ptf.packet_pktpy
154+ ```
155+
156+ If instead you see this line of output, ` ptf ` is using ` scapy ` :
157+
158+ ``` text
159+ Using packet manipulation module: ptf.packet_scapy
160+ ```
161+
162+
75163## Run PTF
76164
77165Once you have written tests and your switch is running, you can run 'ptf'. Use
0 commit comments