Skip to content

Commit c43e990

Browse files
author
Brenden Blanco
committed
Reorganize examples into subdirectories
Examples directory has been growing, so add a bit of organization. Signed-off-by: Brenden Blanco <[email protected]>
1 parent 7a31b18 commit c43e990

Some content is hidden

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

47 files changed

+135
-52
lines changed

SPECS/bcc.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ Python bindings for BPF Compiler Collection (BCC)
7070
%exclude /usr/share/bcc/examples/*.pyo
7171
%exclude /usr/share/bcc/examples/*/*.pyc
7272
%exclude /usr/share/bcc/examples/*/*.pyo
73+
%exclude /usr/share/bcc/examples/*/*/*.pyc
74+
%exclude /usr/share/bcc/examples/*/*/*.pyo

examples/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
set(EXAMPLE_FILES hello_world.py task_switch.py task_switch.c simple_tc.py
2-
simulation.py vlan_learning.py vlan_learning.c)
3-
install(FILES ${EXAMPLE_FILES} DESTINATION share/bcc/examples)
1+
set(EXAMPLE_PROGRAMS hello_world.py)
2+
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples)
43

5-
add_subdirectory(distributed_bridge)
4+
add_subdirectory(networking)
5+
add_subdirectory(tracing)

examples/distributed_bridge/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/networking/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(EXAMPLE_FILES simulation.py)
2+
set(EXAMPLE_PROGRAMS simple_tc.py)
3+
install(FILES ${EXAMPLE_FILES} DESTINATION share/bcc/examples/networking)
4+
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples/networking)
5+
6+
add_subdirectory(distributed_bridge)
7+
add_subdirectory(neighbor_sharing)
8+
add_subdirectory(vlan_learning)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(EXAMPLE_FILES simulation.py tunnel.c tunnel_mesh.c)
2+
set(EXAMPLE_PROGRAMS main.py tunnel_mesh.py tunnel.py)
3+
install(FILES ${EXAMPLE_FILES} DESTINATION share/bcc/examples/networking/distributed_bridge)
4+
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples/networking/distributed_bridge)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(EXAMPLE_FILES README.txt simulation.py tc_neighbor_sharing.c)
2+
set(EXAMPLE_PROGRAMS tc_neighbor_sharing.py)
3+
install(FILES ${EXAMPLE_FILES} DESTINATION share/bcc/examples/networking/neighbor_sharing)
4+
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples/networking/neighbor_sharing)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
This example shows how a combination of BPF programs can be used to perform
2+
per-IP classification and rate limiting. The simulation in this example
3+
shows an example where N+M devices are combined and use 1 WAN. Traffic sent
4+
from/to the "neighbor" devices have their combined bandwidth capped at
5+
128kbit, and the rest of the traffic can use an additional 1Mbit.
6+
7+
This works by sharing a map between various tc ingress filters, each with
8+
a related set of bpf functions attached. The map stores a list of dynamically
9+
learned ip addresses that were seen on the neighbor devices and should be
10+
throttled.
11+
12+
/------------\ |
13+
neigh1 --|->->->->->->->-| | |
14+
neigh2 --|->->->->->->->-| <-128kb-| /------\ |
15+
neigh3 --|->->->->->->->-| | wan0 | wan | |
16+
| ^ | br100 |-<-<-<--| sim | |
17+
| clsfy_neigh() | | ^ \------/ |
18+
lan1 ----|->->->->->->->-| <--1Mb--| | |
19+
lan2 ----|->->->->->->->-| | classify_wan() |
20+
^ \------------/ |
21+
pass() |
22+
23+
To run the example:
24+
25+
$ sudo /path/to/neighbor_sharing/neighbor_sharing.py
26+
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
27+
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
28+
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
29+
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
30+
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
31+
Network ready. Create a shell in the wan0 namespace and test with netperf
32+
(Neighbors are 172.16.1.100-102, and LAN clients are 172.16.1.150-151)
33+
e.g.: ip netns exec wan0 netperf -H 172.16.1.100 -l 2
34+
Press enter when finished:
35+
36+
37+
In another shell:
38+
$ sudo ip netns exec wan0 netperf -H 172.16.1.100 -l 2
39+
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 172.16.1.100 () port 0 AF_INET : demo
40+
Recv Send Send
41+
Socket Socket Message Elapsed
42+
Size Size Size Time Throughput
43+
bytes bytes bytes secs. 10^6bits/sec
44+
45+
87380 16384 16384 4.30 0.18
46+
47+
$ sudo ip netns exec wan0 netperf -H 172.16.1.150 -l 2
48+
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 172.16.1.150 () port 0 AF_INET : demo
49+
Recv Send Send
50+
Socket Socket Message Elapsed
51+
Size Size Size Time Throughput
52+
bytes bytes bytes secs. 10^6bits/sec
53+
54+
87380 16384 16384 4.10 1.01
55+
56+
57+
The bandwidth is throttled according to the IP.

examples/tc_neighbor_sharing.py renamed to examples/networking/neighbor_sharing/tc_neighbor_sharing.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,6 @@
22
# Copyright (c) PLUMgrid, Inc.
33
# Licensed under the Apache License, Version 2.0 (the "License")
44

5-
# This example shows how a combination of BPF programs can be used to perform
6-
# per-IP classification and rate limiting. The simulation in this example
7-
# shows an example where N+M devices are combined and use 1 WAN. Traffic sent
8-
# from/to the "neighbor" devices have their combined bandwidth capped at
9-
# 128kbit, and the rest of the traffic can use an additional 1Mbit.
10-
11-
# This works by sharing a map between various tc ingress filters, each with
12-
# a related set of bpf functions attached. The map stores a list of dynamically
13-
# learned ip addresses that were seen on the neighbor devices and should be
14-
# throttled.
15-
16-
# /------------\ |
17-
# neigh1 --|->->->->->->->-| | |
18-
# neigh2 --|->->->->->->->-| <-128kb-| /------\ |
19-
# neigh3 --|->->->->->->->-| | wan0 | wan | |
20-
# | ^ | br100 |-<-<-<--| sim | |
21-
# | clsfy_neigh() | | ^ \------/ |
22-
# lan1 ----|->->->->->->->-| <--1Mb--| | |
23-
# lan2 ----|->->->->->->->-| | classify_wan() |
24-
# ^ \------------/ |
25-
# pass() |
26-
27-
285
from bcc import BPF
296
from pyroute2 import IPRoute, NetNS, IPDB, NSPopen
307
from simulation import Simulation

examples/simple_tc.py renamed to examples/networking/simple_tc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/python
22
# Copyright (c) PLUMgrid, Inc.
33
# Licensed under the Apache License, Version 2.0 (the "License")
44

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../simulation.py
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(EXAMPLE_FILES README.txt simulation.py vlan_learning.c)
2+
set(EXAMPLE_PROGRAMS vlan_learning.py)
3+
install(FILES ${EXAMPLE_FILES} DESTINATION share/bcc/examples/networking/vlan_learning)
4+
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples/networking/vlan_learning)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
This example shows a unique way to use a BPF program to demux any ethernet
2+
traffic into a pool of worker veth+namespaces (or any ifindex-based
3+
destination) depending on a configurable mapping of src-mac to ifindex. As
4+
part of the ingress processing, the program will dynamically learn the source
5+
ifindex of the matched source mac.
6+
7+
Simulate a physical network with a vlan aware switch and clients that may
8+
connect to any vlan. The program will detect the known clients and pass the
9+
traffic through to a dedicated namespace for processing. Clients may have
10+
overlapping IP spaces and the traffic will still work.
11+
12+
| bpf program |
13+
cli0 --| | /--|-- worker0 |
14+
cli1 --| trunk | +->--->-handle_p2v(pkt)-> /---|-- worker1 |
15+
cli2 --|=======|=+ /----|-- worker2 |
16+
... --| | +-<---<-handle_v2p(pkt)-<-----|-- ... |
17+
cliN --| | \----|-- workerM |
18+
| | ^ |
19+
phys | veth |
20+
switch | |
21+
22+
To run the example, simply:
23+
24+
sudo /path/to/vlan_learning/vlan_learning.py
25+
26+
Serving HTTP on 0.0.0.0 port 80 ...
27+
Serving HTTP on 0.0.0.0 port 80 ...
28+
Serving HTTP on 0.0.0.0 port 80 ...
29+
% Total % Received % Xferd Average Speed Time Time Time Current
30+
Dload Upload Total Spent Left Speed
31+
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0172.16.1.100 - - [04/Nov/2015 10:54:47] "GET / HTTP/1.1" 200 -
32+
100 574 100 574 0 0 45580 0 --:--:-- --:--:-- --:--:-- 47833
33+
34+
...
35+
36+
Press enter to exit:
37+
mac 020000000000 rx pkts = 95, rx bytes = 7022
38+
tx pkts = 0, tx bytes = 0
39+
mac 020000000001 rx pkts = 95, rx bytes = 7022
40+
tx pkts = 0, tx bytes = 0
41+
mac 020000000002 rx pkts = 97, rx bytes = 7154
42+
tx pkts = 0, tx bytes = 0
43+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../simulation.py

examples/vlan_learning.py renamed to examples/networking/vlan_learning/vlan_learning.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@
22
# Copyright (c) PLUMgrid, Inc.
33
# Licensed under the Apache License, Version 2.0 (the "License")
44

5-
# This example shows a unique way to use a BPF program to demux any ethernet
6-
# traffic into a pool of worker veth+namespaces (or any ifindex-based
7-
# destination) depending on a configurable mapping of src-mac to ifindex. As
8-
# part of the ingress processing, the program will dynamically learn the source
9-
# ifindex of the matched source mac.
10-
11-
# Simulate a physical network with a vlan aware switch and clients that may
12-
# connect to any vlan. The program will detect the known clients and pass the
13-
# traffic through to a dedicated namespace for processing. Clients may have
14-
# overlapping IP spaces and the traffic will still work.
15-
16-
# | bpf program |
17-
# cli0 --| | /--|-- worker0 |
18-
# cli1 --| trunk | +->--->-handle_p2v(pkt)-> /---|-- worker1 |
19-
# cli2 --|=======|=+ /----|-- worker2 |
20-
# ... --| | +-<---<-handle_v2p(pkt)-<-----|-- ... |
21-
# cliN --| | \----|-- workerM |
22-
# | | ^ |
23-
# phys | veth |
24-
# switch | |
25-
265
from bcc import BPF
276
from builtins import input
287
from pyroute2 import IPRoute, NetNS, IPDB, NSPopen

examples/tracing/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set(EXAMPLE_FILES bitehist.c bitehist_example.txt disksnoop.c
2+
disksnoop_example.txt task_switch.c tcpv4connect tcpv4connect_example.txt
3+
vfsreadlat.c vfsreadlat_example.txt)
4+
set(EXAMPLE_PROGRAMS bitehist.py disksnoop.py task_switch.py trace_fields.py vfsreadlat.py)
5+
install(FILES ${EXAMPLE_FILES} DESTINATION share/bcc/examples/tracing)
6+
install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples/tracing)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)