Home | History | Annotate | only in /external/bcc/examples/networking/neighbor_sharing
Up to higher level directory
NameDateSize
CMakeLists.txt22-Oct-2020299
README.txt22-Oct-20202.6K
simulation.py22-Oct-20204.4K
tc_neighbor_sharing.c22-Oct-20201.6K
tc_neighbor_sharing.py22-Oct-20202.9K

README.txt

      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.
     58