Skip to content

Commit 117e319

Browse files
committed
Merge remote-tracking branch 'upstream/master' into polycube_on_bcc_v0.12.0
2 parents dfbda16 + 5daab44 commit 117e319

File tree

20 files changed

+149
-16
lines changed

20 files changed

+149
-16
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.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Cube<PortType>::Cube(const nlohmann::json &conf,
7777

7878
auto &p = *ports_by_id_.at(md->port_id);
7979
PacketInMetadata md_;
80+
md_.traffic_class = md->traffic_class;
8081
md_.reason = md->reason;
8182
md_.metadata[0] = md->metadata[0];
8283
md_.metadata[1] = md->metadata[1];

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ class TransparentCubeIface;
3131
enum class CubeType;
3232

3333
struct PacketInMetadata {
34+
uint32_t traffic_class;
3435
uint32_t reason;
3536
uint32_t metadata[3];
3637
};
3738

3839
struct __attribute__((__packed__)) PacketIn {
39-
uint16_t cube_id; /**< Index of the Cube within the patchpanel */
40-
uint16_t port_id; /**< Port where the packet was received */
41-
uint32_t packet_len; /**< Total length of the packet */
42-
uint16_t reason; /**< Internal code between dataplane and control plane */
43-
uint32_t metadata[3]; /**< Buffer that can be used by the dataplane to send
44-
additional information to the control plane */
40+
uint16_t cube_id; /**< Index of the Cube within the patchpanel */
41+
uint16_t port_id; /**< Port where the packet was received */
42+
uint32_t packet_len; /**< Total length of the packet */
43+
uint32_t traffic_class; /**< Traffic class the packet belongs to */
44+
uint16_t reason; /**< Internal code between dataplane and control
45+
plane */
46+
uint32_t metadata[3]; /**< Buffer that can be used by the dataplane to send
47+
additional information to the control plane */
4548
};
4649

4750
typedef std::function<void(const PacketIn *md,

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/libs/polycube/src/transparent_cube.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ TransparentCube::TransparentCube(const nlohmann::json &conf,
3535

3636
Direction direction = static_cast<Direction>(md->port_id);
3737
PacketInMetadata md_;
38+
md_.traffic_class = md->traffic_class;
3839
md_.reason = md->reason;
3940
md_.metadata[0] = md->metadata[0];
4041
md_.metadata[1] = md->metadata[1];

src/polycubectl/prettyprint.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ func formatValue(data interface{}) string {
296296
buf := ""
297297
buf = fmt.Sprintf("%v", data)
298298

299+
if reflect.ValueOf(data).Kind() == reflect.String {
300+
return buf
301+
}
302+
299303
_, erri := strconv.ParseInt(buf, 10, 64)
300304
if erri != nil {
301305
f, errf := strconv.ParseFloat(buf, 64)

src/polycubed/src/base_cube.cpp

Lines changed: 22 additions & 3 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);
@@ -422,9 +432,10 @@ enum {
422432
};
423433
424434
struct pkt_metadata {
425-
u16 cube_id; //__attribute__((deprecated)) // use CUBE_ID instead
426-
u16 in_port; // The interface on which a packet was received.
427-
u32 packet_len; //__attribute__((deprecated)) // Use ctx->len
435+
u16 cube_id; //__attribute__((deprecated)) // use CUBE_ID instead
436+
u16 in_port; // The interface on which a packet was received.
437+
u32 packet_len; //__attribute__((deprecated)) // Use ctx->len
438+
u32 traffic_class; // The traffic class the packet belongs to
428439
429440
// used to send data to controller
430441
u16 reason;
@@ -457,11 +468,19 @@ void call_ingress_program(struct CTXTYPE *skb, int index) {
457468
ingress_programs.call(skb, index);
458469
}
459470
471+
static __always_inline
472+
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
473+
struct pkt_metadata *md, int index);
474+
460475
static __always_inline
461476
void call_egress_program(struct CTXTYPE *skb, int index) {
462477
egress_programs.call(skb, index);
463478
}
464479
480+
static __always_inline
481+
void call_egress_program_with_metadata(struct CTXTYPE *skb,
482+
struct pkt_metadata *md, int index);
483+
465484
/* checksum related */
466485
467486
// those functions have different implementations for XDP and TC

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)