Skip to content

Commit 407cc7e

Browse files
Exporting the Table Description of the ebpf maps
Adding public TableDesc get_table_desc(...) method to BaseCube class Copying BCC's table_desc.h file_desc.h bcc_exception.h headers to /usr/include/polycube/services
1 parent 6b1e5fe commit 407cc7e

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

src/libs/polycube/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ add_subdirectory(src)
22

33
configure_file(libpolycube.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpolycube.pc @ONLY)
44

5+
# In order to use the TableDesc class inside the BaseCube and let Polycube services
6+
# to be compiled outside of the base polycube services location,
7+
# we need these BCC header files to be present on the host filesystem.
8+
# By copying these source files from the BCC submodule to /usr/include/polycube,
9+
# we ensure to have them updated to the last BCC submodule version used in polycube.
10+
file(COPY
11+
../bcc/src/cc/table_desc.h
12+
../bcc/src/cc/file_desc.h
13+
../bcc/src/cc/bcc_exception.h
14+
DESTINATION
15+
${CMAKE_CURRENT_SOURCE_DIR}/include/polycube/services)
16+
517
install(DIRECTORY include/ DESTINATION /usr/include)
618

719
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpolycube.pc

src/libs/polycube/include/polycube/services/base_cube.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "polycube/services/cube_iface.h"
3030
#include "polycube/services/table.h"
3131
#include "polycube/services/utils.h"
32+
#include "polycube/services/table_desc.h"
3233

3334
namespace polycube {
3435
namespace service {
@@ -71,6 +72,9 @@ class BaseCube {
7172
const std::string &table_name, int index = 0,
7273
ProgramType type = ProgramType::INGRESS);
7374

75+
const ebpf::TableDesc &get_table_desc(const std::string &table_name, int index,
76+
ProgramType type);
77+
7478
virtual void datapath_log_msg(const LogMsg *msg);
7579

7680
void set_log_level(LogLevel level);

src/libs/polycube/include/polycube/services/cube_iface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "polycube/services/port_iface.h"
2222
#include "polycube/services/table.h"
2323
#include "polycube/services/types.h"
24+
#include "polycube/services/table_desc.h"
2425

2526
#include <map>
2627
#include <string>
@@ -63,7 +64,9 @@ class BaseCubeIface {
6364
virtual uint16_t get_index(ProgramType type) const = 0;
6465
virtual int get_table_fd(const std::string &table_name, int index,
6566
ProgramType type) = 0;
66-
67+
virtual const ebpf::TableDesc &get_table_desc(const std::string &table_name, int index,
68+
ProgramType type) = 0;
69+
6770
virtual void set_log_level(LogLevel level) = 0;
6871
virtual LogLevel get_log_level() const = 0;
6972

src/libs/polycube/src/base_cube.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ int BaseCube::get_table_fd(const std::string &table_name, int index,
4343
return cube_->get_table_fd(table_name, index, type);
4444
}
4545

46+
const ebpf::TableDesc &BaseCube::get_table_desc(const std::string &table_name, int index,
47+
ProgramType type) {
48+
return cube_->get_table_desc(table_name, index, type);
49+
}
50+
4651
void BaseCube::reload(const std::string &code, int index, ProgramType type) {
4752
cube_->reload(code, index, type);
4853
}

src/polycubed/src/base_cube.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ int BaseCube::get_table_fd(const std::string &table_name, int index,
140140
}
141141
}
142142

143+
const ebpf::TableDesc &BaseCube::get_table_desc(const std::string &table_name,
144+
int index, ProgramType type) {
145+
switch (type) {
146+
case ProgramType::INGRESS:
147+
return ingress_programs_[index]->get_table(table_name).getTableDescription();
148+
case ProgramType::EGRESS:
149+
return egress_programs_[index]->get_table(table_name).getTableDescription();
150+
}
151+
}
152+
143153
void BaseCube::reload(const std::string &code, int index, ProgramType type) {
144154
std::lock_guard<std::mutex> cube_guard(cube_mutex_);
145155
return do_reload(code, index, type);

src/polycubed/src/base_cube.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class BaseCube : virtual public BaseCubeIface {
7676
const Guid &uuid() const;
7777

7878
int get_table_fd(const std::string &table_name, int index, ProgramType type);
79+
const ebpf::TableDesc &get_table_desc(const std::string &table_name, int index,
80+
ProgramType type);
7981

8082
void set_log_level(LogLevel level);
8183
LogLevel get_log_level() const;

0 commit comments

Comments
 (0)