Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
4d15420a
Commit
4d15420a
authored
Jun 19, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71 from iovisor/bblanco_dev
Rework vlan example to be 1:1, no mac learning
parents
439e53ca
6bf723dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
20 deletions
+16
-20
examples/hello_world.py
examples/hello_world.py
+2
-2
examples/vlan_learning.c
examples/vlan_learning.c
+5
-4
examples/vlan_learning.py
examples/vlan_learning.py
+9
-14
No files found.
examples/hello_world.py
View file @
4d15420a
...
...
@@ -2,8 +2,8 @@
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
# run in project directory with:
# sudo
bash -c "PYTHONPATH=$PWD/src LD_LIBRARY_PATH=$PWD/build/src/cc examples
/hello_world.py"
# run in project
examples
directory with:
# sudo
.
/hello_world.py"
from
bpf
import
BPF
from
subprocess
import
call
...
...
examples/vlan_learning.c
View file @
4d15420a
...
...
@@ -10,7 +10,7 @@ struct ifindex_leaf_t {
};
// redirect based on mac -> out_ifindex (auto-learning)
BPF_TABLE
(
"hash"
,
u64
,
struct
ifindex_leaf_t
,
egress
,
4096
);
BPF_TABLE
(
"hash"
,
int
,
struct
ifindex_leaf_t
,
egress
,
4096
);
// redirect based on mac -> out_ifindex (config-driven)
BPF_TABLE
(
"hash"
,
u64
,
struct
ifindex_leaf_t
,
ingress
,
4096
);
...
...
@@ -24,8 +24,9 @@ int handle_phys2virt(struct __sk_buff *skb) {
lock_xadd
(
&
leaf
->
tx_pkts
,
1
);
lock_xadd
(
&
leaf
->
tx_bytes
,
skb
->
len
);
// auto-program reverse direction table
int
out_ifindex
=
leaf
->
out_ifindex
;
struct
ifindex_leaf_t
zleaf
=
{
0
};
struct
ifindex_leaf_t
*
out_leaf
=
egress
.
lookup_or_init
(
&
src_mac
,
&
zleaf
);
struct
ifindex_leaf_t
*
out_leaf
=
egress
.
lookup_or_init
(
&
out_ifindex
,
&
zleaf
);
// relearn when mac moves ifindex
if
(
out_leaf
->
out_ifindex
!=
skb
->
ifindex
)
out_leaf
->
out_ifindex
=
skb
->
ifindex
;
...
...
@@ -39,8 +40,8 @@ EOP:
int
handle_virt2phys
(
struct
__sk_buff
*
skb
)
{
BEGIN
(
ethernet
);
PROTO
(
ethernet
)
{
u64
dst_mac
=
ethernet
->
dst
;
struct
ifindex_leaf_t
*
leaf
=
egress
.
lookup
(
&
dst_mac
);
int
src_ifindex
=
skb
->
ifindex
;
struct
ifindex_leaf_t
*
leaf
=
egress
.
lookup
(
&
src_ifindex
);
if
(
leaf
)
{
lock_xadd
(
&
leaf
->
tx_pkts
,
1
);
lock_xadd
(
&
leaf
->
tx_bytes
,
skb
->
len
);
...
...
examples/vlan_learning.py
View file @
4d15420a
...
...
@@ -24,6 +24,7 @@
# switch | subinterface |
from
bpf
import
BPF
from
builtins
import
input
from
ctypes
import
c_uint
,
c_int
,
c_ulonglong
,
Structure
from
pyroute2
import
IPRoute
,
NetNS
,
IPDB
,
NSPopen
from
random
import
shuffle
...
...
@@ -34,8 +35,7 @@ import sys
ipr
=
IPRoute
()
ipdb
=
IPDB
(
nl
=
ipr
)
num_workers
=
3
num_clients
=
9
num_clients
=
3
num_vlans
=
16
# load the bpf program
...
...
@@ -52,7 +52,7 @@ class VlanSimulation(Simulation):
def
start
(
self
):
# start identical workers each in a namespace
for
i
in
range
(
0
,
num_
worker
s
):
for
i
in
range
(
0
,
num_
client
s
):
httpmod
=
(
"SimpleHTTPServer"
if
sys
.
version_info
[
0
]
<
3
else
"http.server"
)
cmd
=
[
"python"
,
"-m"
,
httpmod
,
"80"
]
...
...
@@ -84,32 +84,27 @@ class VlanSimulation(Simulation):
# allocate vlans randomly
available_vlans
=
[
i
for
i
in
range
(
2
,
2
+
num_vlans
)]
shuffle
(
available_vlans
)
available_ips
=
[[
i
for
i
in
range
(
100
,
105
)]
for
i
in
range
(
0
,
num_
worker
s
)]
available_ips
=
[[
i
for
i
in
range
(
100
,
105
)]
for
i
in
range
(
0
,
num_
client
s
)]
# these are simulations of physical clients
for
i
in
range
(
0
,
num_clients
):
worker_i
=
i
%
num_workers
ipaddr
=
"172.16.1.%d"
%
available_ips
[
worker_i
].
pop
(
0
)
macaddr
=
(
"02:00:00:%.2x:%.2x:%.2x"
%
((
i
>>
16
)
&
0xff
,
(
i
>>
8
)
&
0xff
,
i
&
0xff
))
# program arp manually
p
=
NSPopen
(
"worker%d"
%
worker_i
,
[
"arp"
,
"-s"
,
ipaddr
,
macaddr
])
p
.
communicate
();
p
.
wait
();
p
.
release
()
# assign this client to the given worker
idx
=
self
.
ipdb
.
interfaces
[
"worker%da"
%
worker_
i
][
"index"
]
idx
=
self
.
ipdb
.
interfaces
[
"worker%da"
%
i
][
"index"
]
mac
=
int
(
macaddr
.
replace
(
":"
,
""
),
16
)
ingress
[
ingress
.
Key
(
mac
)]
=
ingress
.
Leaf
(
idx
,
0
,
0
)
# test traffic with curl loop
cmd
=
[
"bash"
,
"-c"
,
"for i in {1..8}; do curl 172.16.1.5 -o /dev/null; sleep 1; done"
]
br_ifc
=
self
.
ipdb
.
create
(
ifname
=
"br100.%d"
%
i
,
kind
=
"vlan"
,
link
=
br100
,
br_ifc
=
self
.
ipdb
.
create
(
ifname
=
"br100.%d"
%
i
,
kind
=
"vlan"
,
link
=
br100
,
vlan_id
=
available_vlans
.
pop
(
0
)).
commit
()
(
out_ifc
,
in_ifc
)
=
self
.
_create_ns
(
"client%d"
%
i
,
in_ifc
=
br_ifc
,
ipaddr
=
ipaddr
+
"/24"
,
macaddr
=
macaddr
,
cmd
=
cmd
)[
1
:
3
]
ipaddr
=
"172.16.1.100/24"
,
macaddr
=
macaddr
,
cmd
=
cmd
)[
1
:
3
]
try
:
sim
=
VlanSimulation
(
ipdb
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment