Skip to content

Commit 2371c87

Browse files
committed
Add traffic class to packet metadata
1 parent 5afda68 commit 2371c87

File tree

10 files changed

+94
-9
lines changed

10 files changed

+94
-9
lines changed

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/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/polycubed/src/base_cube.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,10 @@ enum {
432432
};
433433
434434
struct pkt_metadata {
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
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
438439
439440
// used to send data to controller
440441
u16 reason;
@@ -467,11 +468,19 @@ void call_ingress_program(struct CTXTYPE *skb, int index) {
467468
ingress_programs.call(skb, index);
468469
}
469470
471+
static __always_inline
472+
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
473+
struct pkt_metadata *md, int index);
474+
470475
static __always_inline
471476
void call_egress_program(struct CTXTYPE *skb, int index) {
472477
egress_programs.call(skb, index);
473478
}
474479
480+
static __always_inline
481+
void call_egress_program_with_metadata(struct CTXTYPE *skb,
482+
struct pkt_metadata *md, int index);
483+
475484
/* checksum related */
476485
477486
// those functions have different implementations for XDP and TC

src/polycubed/src/controller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct metadata {
4040
u16 cube_id;
4141
u16 port_id;
4242
u32 packet_len;
43+
u32 traffic_class;
4344
u16 reason;
4445
u32 md[3]; // generic metadata
4546
} __attribute__((packed));
@@ -69,6 +70,7 @@ int controller_module_tx(struct __sk_buff *ctx) {
6970
md.cube_id = module_index;
7071
md.port_id = in_port;
7172
md.packet_len = ctx->len;
73+
md.traffic_class = ctx->mark;
7274
md.reason = reason;
7375
7476
x = ctx->cb[2];
@@ -173,6 +175,7 @@ struct pkt_metadata {
173175
u16 cube_id;
174176
u16 in_port;
175177
u32 packet_len;
178+
u32 traffic_class;
176179
177180
// used to send data to controller
178181
u16 reason;
@@ -199,6 +202,7 @@ int controller_module_tx(struct xdp_md *ctx) {
199202
md.cube_id = int_md->cube_id;
200203
md.in_port = int_md->in_port;
201204
md.packet_len = (u32)(data_end - data);
205+
md.traffic_class = int_md->traffic_class;
202206
md.reason = int_md->reason;
203207
204208
x = int_md->md[0];
@@ -239,6 +243,7 @@ struct pkt_metadata {
239243
u16 module_index;
240244
u16 in_port;
241245
u32 packet_len;
246+
u32 traffic_class;
242247
243248
// used to send data to controller
244249
u16 reason;

src/polycubed/src/cube_tc.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,26 @@ int pcn_pkt_controller_with_metadata(struct CTXTYPE *skb,
245245
skb->cb[4] = metadata[2];
246246
return pcn_pkt_controller(skb, md, reason);
247247
}
248+
249+
static __always_inline
250+
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
251+
struct pkt_metadata *md, int index) {
252+
// Save the traffic class for the next program in case it was changed
253+
// by the current one
254+
skb->mark = md->traffic_class;
255+
256+
call_ingress_program(skb, index);
257+
}
258+
259+
static __always_inline
260+
void call_egress_program_with_metadata(struct CTXTYPE *skb,
261+
struct pkt_metadata *md, int index) {
262+
// Save the traffic class for the next program in case it was changed
263+
// by the current one
264+
skb->mark = md->traffic_class;
265+
266+
call_egress_program(skb, index);
267+
}
248268
)";
249269

250270
const std::string CubeTC::CUBETC_HELPERS = R"(
@@ -327,6 +347,7 @@ int handle_rx_wrapper(struct CTXTYPE *skb) {
327347
md.in_port = x >> 16;
328348
md.cube_id = CUBE_ID;
329349
md.packet_len = skb->len;
350+
md.traffic_class = skb->mark;
330351
skb->cb[0] = md.in_port << 16 | CUBE_ID;
331352
332353
// Check if the cube is shadow and the in_port has odd index
@@ -343,6 +364,10 @@ int handle_rx_wrapper(struct CTXTYPE *skb) {
343364
344365
int rc = handle_rx(skb, &md);
345366
367+
// Save the traffic class for the next program in case it was changed
368+
// by the current one
369+
skb->mark = md.traffic_class;
370+
346371
switch (rc) {
347372
case RX_REDIRECT:
348373
// FIXME: reason is right, we are reusing the field

src/polycubed/src/cube_xdp.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ int pcn_pkt_controller_with_metadata(struct CTXTYPE *pkt, struct pkt_metadata *m
185185
186186
return pcn_pkt_controller(pkt, md, reason);
187187
}
188+
189+
static __always_inline
190+
void call_ingress_program_with_metadata(struct CTXTYPE *skb,
191+
struct pkt_metadata *md, int index) {
192+
u32 inport_key = 0;
193+
194+
// Save the metadata for the next program in case they were changed by the
195+
// current one
196+
port_md.update(&inport_key, md);;
197+
198+
call_ingress_program(skb, index);
199+
}
200+
201+
static __always_inline
202+
void call_egress_program_with_metadata(struct CTXTYPE *skb,
203+
struct pkt_metadata *md, int index) {
204+
u32 inport_key = 0;
205+
206+
// Save the metadata for the next program in case they were changed by the
207+
// current one
208+
port_md.update(&inport_key, md);;
209+
210+
call_egress_program(skb, index);
211+
}
188212
)";
189213

190214
const std::string CubeXDP::CUBEXDP_WRAPPER = R"(
@@ -198,9 +222,14 @@ int handle_rx_xdp_wrapper(struct CTXTYPE *ctx) {
198222
md.cube_id = CUBE_ID;
199223
md.in_port = int_md->in_port;
200224
md.packet_len = int_md->packet_len;
225+
md.traffic_class = int_md->traffic_class;
201226
202227
int rc = handle_rx(ctx, &md);
203228
229+
// Save the traffic class for the next program in case it was changed
230+
// by the current one
231+
int_md->traffic_class = md.traffic_class;
232+
204233
switch (rc) {
205234
case RX_DROP:
206235
return XDP_DROP;

src/polycubed/src/extiface_xdp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct pkt_metadata {
8080
u16 module_index;
8181
u16 in_port;
8282
u32 packet_len;
83+
u32 traffic_class;
8384
// used to send data to controller
8485
u16 reason;
8586
u32 md[3];

src/polycubed/src/transparent_cube_tc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ const std::string TransparentCubeTC::TRANSPARENTCUBETC_WRAPPER = R"(
9393
int handle_rx_wrapper(struct CTXTYPE *skb) {
9494
struct pkt_metadata md = {};
9595
md.packet_len = skb->len;
96+
md.traffic_class = skb->mark;
97+
9698
int rc = handle_rx(skb, &md);
9799
100+
// Save the traffic class for the next program in case it was changed
101+
// by the current one
102+
skb->mark = md.traffic_class;
103+
98104
switch (rc) {
99105
case RX_DROP:
100106
return TC_ACT_SHOT;

src/polycubed/src/transparent_cube_xdp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,14 @@ int handle_rx_xdp_wrapper(struct CTXTYPE *ctx) {
127127
if (int_md) {
128128
md.cube_id = CUBE_ID;
129129
md.packet_len = int_md->packet_len;
130+
md.traffic_class = int_md->traffic_class;
130131
131132
int rc = handle_rx(ctx, &md);
132133
134+
// Save the traffic class for the next program in case it was changed
135+
// by the current one
136+
int_md->traffic_class = md.traffic_class;
137+
133138
switch (rc) {
134139
case RX_DROP:
135140
return XDP_DROP;

0 commit comments

Comments
 (0)