Skip to content

Commit

Permalink
Merge pull request #272 from FedeParola/traffic-class-support
Browse files Browse the repository at this point in the history
Add traffic class to packet metadata
  • Loading branch information
frisso committed Feb 18, 2020
2 parents 5afda68 + 2371c87 commit 7855b8e
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/libs/polycube/include/polycube/services/cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Cube<PortType>::Cube(const nlohmann::json &conf,

auto &p = *ports_by_id_.at(md->port_id);
PacketInMetadata md_;
md_.traffic_class = md->traffic_class;
md_.reason = md->reason;
md_.metadata[0] = md->metadata[0];
md_.metadata[1] = md->metadata[1];
Expand Down
15 changes: 9 additions & 6 deletions src/libs/polycube/include/polycube/services/cube_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ class TransparentCubeIface;
enum class CubeType;

struct PacketInMetadata {
uint32_t traffic_class;
uint32_t reason;
uint32_t metadata[3];
};

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

typedef std::function<void(const PacketIn *md,
Expand Down
1 change: 1 addition & 0 deletions src/libs/polycube/src/transparent_cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TransparentCube::TransparentCube(const nlohmann::json &conf,

Direction direction = static_cast<Direction>(md->port_id);
PacketInMetadata md_;
md_.traffic_class = md->traffic_class;
md_.reason = md->reason;
md_.metadata[0] = md->metadata[0];
md_.metadata[1] = md->metadata[1];
Expand Down
15 changes: 12 additions & 3 deletions src/polycubed/src/base_cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,10 @@ enum {
};
struct pkt_metadata {
u16 cube_id; //__attribute__((deprecated)) // use CUBE_ID instead
u16 in_port; // The interface on which a packet was received.
u32 packet_len; //__attribute__((deprecated)) // Use ctx->len
u16 cube_id; //__attribute__((deprecated)) // use CUBE_ID instead
u16 in_port; // The interface on which a packet was received.
u32 packet_len; //__attribute__((deprecated)) // Use ctx->len
u32 traffic_class; // The traffic class the packet belongs to
// used to send data to controller
u16 reason;
Expand Down Expand Up @@ -467,11 +468,19 @@ void call_ingress_program(struct CTXTYPE *skb, int index) {
ingress_programs.call(skb, index);
}
static __always_inline
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
struct pkt_metadata *md, int index);
static __always_inline
void call_egress_program(struct CTXTYPE *skb, int index) {
egress_programs.call(skb, index);
}
static __always_inline
void call_egress_program_with_metadata(struct CTXTYPE *skb,
struct pkt_metadata *md, int index);
/* checksum related */
// those functions have different implementations for XDP and TC
Expand Down
5 changes: 5 additions & 0 deletions src/polycubed/src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct metadata {
u16 cube_id;
u16 port_id;
u32 packet_len;
u32 traffic_class;
u16 reason;
u32 md[3]; // generic metadata
} __attribute__((packed));
Expand Down Expand Up @@ -69,6 +70,7 @@ int controller_module_tx(struct __sk_buff *ctx) {
md.cube_id = module_index;
md.port_id = in_port;
md.packet_len = ctx->len;
md.traffic_class = ctx->mark;
md.reason = reason;
x = ctx->cb[2];
Expand Down Expand Up @@ -173,6 +175,7 @@ struct pkt_metadata {
u16 cube_id;
u16 in_port;
u32 packet_len;
u32 traffic_class;
// used to send data to controller
u16 reason;
Expand All @@ -199,6 +202,7 @@ int controller_module_tx(struct xdp_md *ctx) {
md.cube_id = int_md->cube_id;
md.in_port = int_md->in_port;
md.packet_len = (u32)(data_end - data);
md.traffic_class = int_md->traffic_class;
md.reason = int_md->reason;
x = int_md->md[0];
Expand Down Expand Up @@ -239,6 +243,7 @@ struct pkt_metadata {
u16 module_index;
u16 in_port;
u32 packet_len;
u32 traffic_class;
// used to send data to controller
u16 reason;
Expand Down
25 changes: 25 additions & 0 deletions src/polycubed/src/cube_tc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ int pcn_pkt_controller_with_metadata(struct CTXTYPE *skb,
skb->cb[4] = metadata[2];
return pcn_pkt_controller(skb, md, reason);
}
static __always_inline
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
struct pkt_metadata *md, int index) {
// Save the traffic class for the next program in case it was changed
// by the current one
skb->mark = md->traffic_class;
call_ingress_program(skb, index);
}
static __always_inline
void call_egress_program_with_metadata(struct CTXTYPE *skb,
struct pkt_metadata *md, int index) {
// Save the traffic class for the next program in case it was changed
// by the current one
skb->mark = md->traffic_class;
call_egress_program(skb, index);
}
)";

const std::string CubeTC::CUBETC_HELPERS = R"(
Expand Down Expand Up @@ -327,6 +347,7 @@ int handle_rx_wrapper(struct CTXTYPE *skb) {
md.in_port = x >> 16;
md.cube_id = CUBE_ID;
md.packet_len = skb->len;
md.traffic_class = skb->mark;
skb->cb[0] = md.in_port << 16 | CUBE_ID;
// Check if the cube is shadow and the in_port has odd index
Expand All @@ -343,6 +364,10 @@ int handle_rx_wrapper(struct CTXTYPE *skb) {
int rc = handle_rx(skb, &md);
// Save the traffic class for the next program in case it was changed
// by the current one
skb->mark = md.traffic_class;
switch (rc) {
case RX_REDIRECT:
// FIXME: reason is right, we are reusing the field
Expand Down
29 changes: 29 additions & 0 deletions src/polycubed/src/cube_xdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ int pcn_pkt_controller_with_metadata(struct CTXTYPE *pkt, struct pkt_metadata *m
return pcn_pkt_controller(pkt, md, reason);
}
static __always_inline
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
struct pkt_metadata *md, int index) {
u32 inport_key = 0;
// Save the metadata for the next program in case they were changed by the
// current one
port_md.update(&inport_key, md);;
call_ingress_program(skb, index);
}
static __always_inline
void call_egress_program_with_metadata(struct CTXTYPE *skb,
struct pkt_metadata *md, int index) {
u32 inport_key = 0;
// Save the metadata for the next program in case they were changed by the
// current one
port_md.update(&inport_key, md);;
call_egress_program(skb, index);
}
)";

const std::string CubeXDP::CUBEXDP_WRAPPER = R"(
Expand All @@ -198,9 +222,14 @@ int handle_rx_xdp_wrapper(struct CTXTYPE *ctx) {
md.cube_id = CUBE_ID;
md.in_port = int_md->in_port;
md.packet_len = int_md->packet_len;
md.traffic_class = int_md->traffic_class;
int rc = handle_rx(ctx, &md);
// Save the traffic class for the next program in case it was changed
// by the current one
int_md->traffic_class = md.traffic_class;
switch (rc) {
case RX_DROP:
return XDP_DROP;
Expand Down
1 change: 1 addition & 0 deletions src/polycubed/src/extiface_xdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct pkt_metadata {
u16 module_index;
u16 in_port;
u32 packet_len;
u32 traffic_class;
// used to send data to controller
u16 reason;
u32 md[3];
Expand Down
6 changes: 6 additions & 0 deletions src/polycubed/src/transparent_cube_tc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ const std::string TransparentCubeTC::TRANSPARENTCUBETC_WRAPPER = R"(
int handle_rx_wrapper(struct CTXTYPE *skb) {
struct pkt_metadata md = {};
md.packet_len = skb->len;
md.traffic_class = skb->mark;
int rc = handle_rx(skb, &md);
// Save the traffic class for the next program in case it was changed
// by the current one
skb->mark = md.traffic_class;
switch (rc) {
case RX_DROP:
return TC_ACT_SHOT;
Expand Down
5 changes: 5 additions & 0 deletions src/polycubed/src/transparent_cube_xdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ int handle_rx_xdp_wrapper(struct CTXTYPE *ctx) {
if (int_md) {
md.cube_id = CUBE_ID;
md.packet_len = int_md->packet_len;
md.traffic_class = int_md->traffic_class;
int rc = handle_rx(ctx, &md);
// Save the traffic class for the next program in case it was changed
// by the current one
int_md->traffic_class = md.traffic_class;
switch (rc) {
case RX_DROP:
return XDP_DROP;
Expand Down

0 comments on commit 7855b8e

Please sign in to comment.