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
fcd936c2
Commit
fcd936c2
authored
Feb 07, 2017
by
Huapeng Zhou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcc: add support for lpm trie map type
parent
f1692e0e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
107 additions
and
0 deletions
+107
-0
src/cc/compat/linux/bpf.h
src/cc/compat/linux/bpf.h
+7
-0
src/cc/compat/linux/virtual_bpf.h
src/cc/compat/linux/virtual_bpf.h
+7
-0
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+2
-0
src/lua/bcc/table.lua
src/lua/bcc/table.lua
+1
-0
src/lua/bpf/cdef.lua
src/lua/bpf/cdef.lua
+1
-0
src/python/bcc/table.py
src/python/bcc/table.py
+15
-0
tests/python/test_lpm_trie.py
tests/python/test_lpm_trie.py
+74
-0
No files found.
src/cc/compat/linux/bpf.h
View file @
fcd936c2
...
...
@@ -63,6 +63,12 @@ struct bpf_insn {
__s32
imm
;
/* signed immediate constant */
};
/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
struct
bpf_lpm_trie_key
{
__u32
prefixlen
;
/* up to 32 for AF_INET, 128 for AF_INET6 */
__u8
data
[
0
];
/* Arbitrary size */
};
/* BPF syscall commands, see bpf(2) man-page for details. */
enum
bpf_cmd
{
BPF_MAP_CREATE
,
...
...
@@ -89,6 +95,7 @@ enum bpf_map_type {
BPF_MAP_TYPE_CGROUP_ARRAY
,
BPF_MAP_TYPE_LRU_HASH
,
BPF_MAP_TYPE_LRU_PERCPU_HASH
,
BPF_MAP_TYPE_LPM_TRIE
,
};
enum
bpf_prog_type
{
...
...
src/cc/compat/linux/virtual_bpf.h
View file @
fcd936c2
...
...
@@ -64,6 +64,12 @@ struct bpf_insn {
__s32 imm; /* signed immediate constant */
};
/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
struct bpf_lpm_trie_key {
__u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
__u8 data[0]; /* Arbitrary size */
};
/* BPF syscall commands, see bpf(2) man-page for details. */
enum bpf_cmd {
BPF_MAP_CREATE,
...
...
@@ -90,6 +96,7 @@ enum bpf_map_type {
BPF_MAP_TYPE_CGROUP_ARRAY,
BPF_MAP_TYPE_LRU_HASH,
BPF_MAP_TYPE_LRU_PERCPU_HASH,
BPF_MAP_TYPE_LPM_TRIE,
};
enum bpf_prog_type {
...
...
src/cc/frontends/clang/b_frontend_action.cc
View file @
fcd936c2
...
...
@@ -645,6 +645,8 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
map_type
=
BPF_MAP_TYPE_LRU_HASH
;
}
else
if
(
A
->
getName
()
==
"maps/lru_percpu_hash"
)
{
map_type
=
BPF_MAP_TYPE_LRU_PERCPU_HASH
;
}
else
if
(
A
->
getName
()
==
"maps/lpm_trie"
)
{
map_type
=
BPF_MAP_TYPE_LPM_TRIE
;
}
else
if
(
A
->
getName
()
==
"maps/histogram"
)
{
if
(
table
.
key_desc
==
"
\"
int
\"
"
)
map_type
=
BPF_MAP_TYPE_ARRAY
;
...
...
src/lua/bcc/table.lua
View file @
fcd936c2
...
...
@@ -29,6 +29,7 @@ BaseTable.static.BPF_MAP_TYPE_STACK_TRACE = 7
BaseTable
.
static
.
BPF_MAP_TYPE_CGROUP_ARRAY
=
8
BaseTable
.
static
.
BPF_MAP_TYPE_LRU_HASH
=
9
BaseTable
.
static
.
BPF_MAP_TYPE_LRU_PERCPU_HASH
=
10
BaseTable
.
static
.
BPF_MAP_TYPE_LPM_TRIE
=
11
function
BaseTable
:
initialize
(
t_type
,
bpf
,
map_id
,
map_fd
,
key_type
,
leaf_type
)
assert
(
t_type
==
libbcc
.
bpf_table_type_id
(
bpf
.
module
,
map_id
))
...
...
src/lua/bpf/cdef.lua
View file @
fcd936c2
...
...
@@ -140,6 +140,7 @@ else
S
.
c
.
BPF_MAP
.
CGROUP_ARRAY
=
8
S
.
c
.
BPF_MAP
.
LRU_HASH
=
9
S
.
c
.
BPF_MAP
.
LRU_PERCPU_HASH
=
10
S
.
c
.
BPF_MAP
.
LPM_TRIE
=
11
end
if
not
S
.
c
.
BPF_PROG
.
TRACEPOINT
then
S
.
c
.
BPF_PROG
.
TRACEPOINT
=
5
...
...
src/python/bcc/table.py
View file @
fcd936c2
...
...
@@ -34,6 +34,7 @@ BPF_MAP_TYPE_STACK_TRACE = 7
BPF_MAP_TYPE_CGROUP_ARRAY
=
8
BPF_MAP_TYPE_LRU_HASH
=
9
BPF_MAP_TYPE_LRU_PERCPU_HASH
=
10
BPF_MAP_TYPE_LPM_TRIE
=
11
stars_max
=
40
log2_index_max
=
65
...
...
@@ -124,6 +125,8 @@ def Table(bpf, map_id, map_fd, keytype, leaftype, **kwargs):
t
=
PerCpuHash
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
,
**
kwargs
)
elif
ttype
==
BPF_MAP_TYPE_PERCPU_ARRAY
:
t
=
PerCpuArray
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
,
**
kwargs
)
elif
ttype
==
BPF_MAP_TYPE_LPM_TRIE
:
t
=
LpmTrie
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
)
elif
ttype
==
BPF_MAP_TYPE_STACK_TRACE
:
t
=
StackTrace
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
)
elif
ttype
==
BPF_MAP_TYPE_LRU_HASH
:
...
...
@@ -665,6 +668,18 @@ class PerCpuArray(ArrayBase):
result
=
self
.
sum
(
key
)
return
result
.
value
/
self
.
total_cpu
class
LpmTrie
(
TableBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
LpmTrie
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
__len__
(
self
):
raise
NotImplementedError
def
__delitem__
(
self
,
key
):
# Not implemented for lpm trie as of kernel commit
# b95a5c4db09bc7c253636cb84dc9b12c577fd5a0
raise
NotImplementedError
class
StackTrace
(
TableBase
):
MAX_DEPTH
=
127
...
...
tests/python/test_lpm_trie.py
0 → 100644
View file @
fcd936c2
#!/usr/bin/env python
# Copyright (c) 2017 Facebook, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
import
ctypes
as
ct
import
unittest
from
bcc
import
BPF
from
netaddr
import
IPAddress
class
KeyV4
(
ct
.
Structure
):
_fields_
=
[(
"prefixlen"
,
ct
.
c_uint
),
(
"data"
,
ct
.
c_ubyte
*
4
)]
class
KeyV6
(
ct
.
Structure
):
_fields_
=
[(
"prefixlen"
,
ct
.
c_uint
),
(
"data"
,
ct
.
c_ushort
*
8
)]
class
TestLpmTrie
(
unittest
.
TestCase
):
def
test_lpm_trie_v4
(
self
):
test_prog1
=
"""
BPF_F_TABLE("lpm_trie", u64, int, trie, 16, BPF_F_NO_PREALLOC);
"""
b
=
BPF
(
text
=
test_prog1
)
t
=
b
[
"trie"
]
k1
=
KeyV4
(
24
,
(
192
,
168
,
0
,
0
))
v1
=
ct
.
c_int
(
24
)
t
[
k1
]
=
v1
k2
=
KeyV4
(
28
,
(
192
,
168
,
0
,
0
))
v2
=
ct
.
c_int
(
28
)
t
[
k2
]
=
v2
k
=
KeyV4
(
32
,
(
192
,
168
,
0
,
15
))
self
.
assertEqual
(
t
[
k
].
value
,
28
)
k
=
KeyV4
(
32
,
(
192
,
168
,
0
,
127
))
self
.
assertEqual
(
t
[
k
].
value
,
24
)
with
self
.
assertRaises
(
KeyError
):
k
=
KeyV4
(
32
,
(
172
,
16
,
1
,
127
))
v
=
t
[
k
]
def
test_lpm_trie_v6
(
self
):
test_prog1
=
"""
struct key_v6 {
u32 prefixlen;
u32 data[4];
};
BPF_F_TABLE("lpm_trie", struct key_v6, int, trie, 16, BPF_F_NO_PREALLOC);
"""
b
=
BPF
(
text
=
test_prog1
)
t
=
b
[
"trie"
]
k1
=
KeyV6
(
64
,
IPAddress
(
'2a00:1450:4001:814:200e::'
).
words
)
v1
=
ct
.
c_int
(
64
)
t
[
k1
]
=
v1
k2
=
KeyV6
(
96
,
IPAddress
(
'2a00:1450:4001:814::200e'
).
words
)
v2
=
ct
.
c_int
(
96
)
t
[
k2
]
=
v2
k
=
KeyV6
(
128
,
IPAddress
(
'2a00:1450:4001:814::1024'
).
words
)
self
.
assertEqual
(
t
[
k
].
value
,
96
)
k
=
KeyV6
(
128
,
IPAddress
(
'2a00:1450:4001:814:2046::'
).
words
)
self
.
assertEqual
(
t
[
k
].
value
,
64
)
with
self
.
assertRaises
(
KeyError
):
k
=
KeyV6
(
128
,
IPAddress
(
'2a00:ffff::'
).
words
)
v
=
t
[
k
]
if
__name__
==
"__main__"
:
unittest
.
main
()
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