Skip to content

Commit e29ef7e

Browse files
authored
Add bf pktpy source (#221)
Signed-off-by: Andy Fingerhut <andy_fingerhut@alum.wustl.edu>
1 parent 0fbd248 commit e29ef7e

File tree

146 files changed

+10067
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+10067
-38
lines changed

README.md

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ More information about Black, you find at
4242
The following software is required to run PTF:
4343

4444
* Python 3.x
45-
* Scapy 2.5.0 (unless you provide another packet manipulation module)
46-
* pypcap (optional - VLAN tests will fail without this)
47-
* tcpdump (optional - Scapy will complain if it's missing)
45+
46+
The following packages are optional for running PTF:
47+
48+
* Scapy 2.5.0 (you may also use the included `bf_pktpy` module instead)
49+
* pypcap (VLAN tests will fail without this)
50+
* tcpdump (Scapy will complain if it's missing)
4851

4952
Root/sudo privilege is required on the host, in order to run `ptf`.
5053

@@ -74,11 +77,7 @@ apt-get install tcpdump
7477

7578
### Using `bf_pktpy` as an alternate packet manipulation module
7679

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-
80+
The Python module `bf_pktpy` is included as part of the ptf package.
8281
It was developed as an alternative to `scapy`. The tradeoffs of using
8382
`bf_pktpy` vs. `scapy` are:
8483

@@ -89,34 +88,7 @@ It was developed as an alternative to `scapy`. The tradeoffs of using
8988
under a different license.
9089
+ `bf_pktpy` implements only a small subset of the functionality of
9190
`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-
```
91+
headers. It is released under an Apache 2.0 license.
12092

12193
If you want to use `bf_pktpy` when running the command `ptf` from the
12294
command line, provide the `-pmm` option as shown below.
@@ -274,9 +246,9 @@ timeout takes precedence over the global timeout passed on the command line.
274246
## Pluggable packet manipulation module
275247

276248
By default, `ptf` uses `Scapy` as the packet manipulation module, but it can
277-
also operate on a different one.
249+
also operate on a different one, e.g. the included `bf_pktpy` module.
278250

279-
Such module **must define/implement the same symbols**, as defined in `Scapy`
251+
Such a module **must define/implement the same symbols**, as defined in `Scapy`
280252
implementation of packet. Most of them are just names of most common frame
281253
headers (Ether, IP, TCP, UDP, ...).
282254

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ platforms = any
2222
python_requires = >=3.4
2323
setup_requires =
2424
setuptools_scm
25+
install_requires =
26+
six
27+
getmac
28+
scapy_helper
29+
netifaces
30+
psutil
2531

2632
[options.packages.find]
2733
where = src

src/bf_pktpy/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021 Intel Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from bf_pktpy.library.specs import Ether, IP, IPv6, ARP, TCP, UDP, ICMP, MPLS
14+
from bf_pktpy.library.specs import GRE, Dot1Q, BOOTP, DHCP, BFD
15+
16+
# from bf_pktpy.library.specs import Arp
17+
from bf_pktpy.library.utils import Interface, Stream, Listener, Decoder
18+
from bf_pktpy.commands import send, sendp, sr, sr1, srp, srp1
19+
from bf_pktpy.commands import srloop, srploop, sniff, bridge_and_sniff

src/bf_pktpy/__main__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2021 Intel Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
14+
from main import run_interactive
15+
16+
if __name__ == "__main__":
17+
run_interactive()

src/bf_pktpy/all/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021 Intel Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
14+
# Import all from packets & utils
15+
from bf_pktpy.packets import *
16+
from bf_pktpy.library.helpers.bytes2hex import bytes2hex
17+
from bf_pktpy.library.helpers.get_if_list import get_if_list
18+
from bf_pktpy.library.utils.hexdump import hexdump
19+
from bf_pktpy.library.utils.ls import ls

src/bf_pktpy/build_information.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2021 Intel Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from bf_pktpy.library.helpers import constants
14+
15+
16+
class BuildInformation:
17+
def __init__(self):
18+
self._version = "0.2"
19+
20+
def show_details(self, logo=False):
21+
if logo:
22+
print(constants.logo)
23+
print("\tBarefoot PKTPY (Packet Generator)\n\tVersion: %s" % self._version)

0 commit comments

Comments
 (0)