Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions common/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "memory_address.h"
Expand Down Expand Up @@ -98,12 +99,15 @@ memory_brealloc(
void *new_data = memory_balloc(context, new_size);
if (new_data == NULL)
return NULL;
if (old_size < new_size)
memcpy(new_data, data, old_size);
else
memcpy(new_data, data, new_size);

if (old_size)
if (old_size) {
if (old_size < new_size)
memcpy(new_data, data, old_size);
else
memcpy(new_data, data, new_size);

memory_bfree(context, data, old_size);
}

return new_data;
}
6 changes: 4 additions & 2 deletions common/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "common/exp_array.h"
Expand Down Expand Up @@ -292,7 +291,10 @@ value_registry_join_range(
uint32_t v1 = ADDR_OF(&registry1->values)[idx1];
uint32_t v2 = ADDR_OF(&registry2->values)[idx2];

join_func(v1, v2, range_idx, join_func_data);
int ret = join_func(v1, v2, range_idx, join_func_data);
if (ret < 0) {
return ret;
}
}
}
return 0;
Expand Down
3 changes: 2 additions & 1 deletion common/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ value_table_init(
uint32_t *values = (uint32_t *)memory_balloc(
memory_context, h_dim * v_dim * sizeof(uint32_t)
);
memset(values, 0, h_dim * v_dim * sizeof(uint32_t));

if (values == NULL) {
remap_table_free(&value_table->remap_table);
return -1;
}

memset(values, 0, h_dim * v_dim * sizeof(uint32_t));

SET_OFFSET_OF(&value_table->values, values);

value_table->h_dim = h_dim;
Expand Down
11 changes: 7 additions & 4 deletions dataplane/unittest/config/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ check_instance(
}

int
main(int argc, char **argv) {
(void)argc;
(void)argv;

main() {
FILE *dataplane_config_file = fopen(CONFIG_PATH, "r");

struct dataplane_config *config = NULL;
Expand All @@ -33,4 +30,10 @@ main(int argc, char **argv) {
check_instance(config->instances, 0, 1024, 2048);
check_instance(config->instances + 1, 1, 512, 128);
check_instance(config->instances + 2, 0, 123, 124);

dataplane_config_free(config);

puts("OK");

return 0;
}
1 change: 0 additions & 1 deletion filter/attribute/net4.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "../helper.h"
#include "../rule.h"
#include "common/lpm.h"
#include "common/range_collector.h"
Expand Down
18 changes: 9 additions & 9 deletions filter/attribute/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ static inline uint32_t
lookup_port_src(struct packet *packet, void *data) {
(void)packet;
struct value_table *table = data;
return value_table_get(table, 0, packet_src_port(packet));
uint32_t res = value_table_get(table, 0, packet_src_port(packet));
return res;
}

typedef void (*action_get_port_range_func)(
Expand All @@ -71,7 +72,7 @@ typedef void (*action_get_port_range_func)(
static inline int
collect_port_values(
struct memory_context *memory_context,
const struct filter_rule *actions,
const struct filter_rule *rules,
uint32_t count,
action_get_port_range_func get_port_range,
struct value_table *table,
Expand All @@ -80,8 +81,7 @@ collect_port_values(
if (value_table_init(table, memory_context, 1, 65536))
return -1;

for (const struct filter_rule *action = actions;
action < actions + count;
for (const struct filter_rule *action = rules; action < rules + count;
++action) {

value_table_new_gen(table);
Expand All @@ -103,14 +103,13 @@ collect_port_values(

value_table_compact(table);

for (const struct filter_rule *action = actions;
action < actions + count;
++action) {
for (const struct filter_rule *rule = rules; rule < rules + count;
++rule) {
value_registry_start(registry);

struct filter_port_range *port_ranges;
uint32_t port_range_count;
get_port_range(action, &port_ranges, &port_range_count);
get_port_range(rule, &port_ranges, &port_range_count);
for (struct filter_port_range *ports = port_ranges;
ports < port_ranges + port_range_count;
++ports) {
Expand Down Expand Up @@ -150,7 +149,8 @@ get_port_range_dst(
static inline uint32_t
lookup_port_dst(struct packet *packet, void *data) {
struct value_table *table = data;
return value_table_get(table, 0, packet_dst_port(packet));
uint32_t res = value_table_get(table, 0, packet_dst_port(packet));
return res;
}

static inline int
Expand Down
8 changes: 5 additions & 3 deletions filter/attribute/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ lookup_proto(struct packet *packet, void *data) {
rte_pktmbuf_mtod(packet->mbuf, struct rte_ether_hdr *);
struct rte_ipv4_hdr *ip_hdr = (struct rte_ipv4_hdr *)(eth_hdr + 1);

uint32_t class;
if (ip_hdr->next_proto_id == IPPROTO_UDP) {
return c->max_tcp_class + 1;
class = c->max_tcp_class + 1;
} else if (ip_hdr->next_proto_id == IPPROTO_ICMP) {
return c->max_tcp_class + 2;
class = c->max_tcp_class + 2;
} else { // TCP
struct rte_tcp_hdr *tcp_hdr =
(struct rte_tcp_hdr *)(ip_hdr + 1);
return value_table_get(&c->tcp_flags, 0, tcp_hdr->tcp_flags);
class = value_table_get(&c->tcp_flags, 0, tcp_hdr->tcp_flags);
}
return class;
}

static inline void
Expand Down
100 changes: 100 additions & 0 deletions filter/bench/dpdk/def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#pragma once

#include <assert.h>
#include <stddef.h>
#include <stdint.h>

#include <rte_acl.h>
#include <rte_config.h>

#include <rte_ether.h>
#include <rte_ip.h>
#include <rte_mbuf.h>
#include <rte_tcp.h>
#include <rte_udp.h>

#include "common/network.h"
#include "filter/rule.h"

////////////////////////////////////////////////////////////////////////////////

#define MAX_RULE_NUM 10000

////////////////////////////////////////////////////////////////////////////////

#define IP_HDR_OFFSET \
(RTE_PKTMBUF_HEADROOM + sizeof(struct rte_mbuf) + \
sizeof(struct rte_ether_hdr))
#define TRANSPORT_HDR_OFFSET (IP_HDR_OFFSET + sizeof(struct rte_ipv4_hdr))

static_assert(
IP_HDR_OFFSET == 398, "offset of the IP header calculated incorrect"
);

////////////////////////////////////////////////////////////////////////////////

static const struct rte_acl_field_def dpdk_acl_field_defs[5] = {
{
.type = RTE_ACL_FIELD_TYPE_BITMASK,
.size = sizeof(uint8_t),
.field_index = 0,
.input_index = 0,
.offset = IP_HDR_OFFSET +
offsetof(struct rte_ipv4_hdr, next_proto_id),
},
{.type = RTE_ACL_FIELD_TYPE_MASK,
.size = sizeof(uint32_t),
.field_index = 1,
.input_index = 1,
.offset = IP_HDR_OFFSET + offsetof(struct rte_ipv4_hdr, src_addr)},
{.type = RTE_ACL_FIELD_TYPE_MASK,
.size = sizeof(uint32_t),
.field_index = 2,
.input_index = 2,
.offset = IP_HDR_OFFSET + offsetof(struct rte_ipv4_hdr, dst_addr)},
{.type = RTE_ACL_FIELD_TYPE_RANGE,
.size = sizeof(uint16_t),
.field_index = 3,
.input_index = 3,

// both udp and tcp headers start with src port following dst port
.offset = TRANSPORT_HDR_OFFSET},
{.type = RTE_ACL_FIELD_TYPE_RANGE,
.size = sizeof(uint16_t),
.field_index = 4,
.input_index = 4,
.offset = TRANSPORT_HDR_OFFSET + sizeof(uint16_t)}
};

////////////////////////////////////////////////////////////////////////////////

RTE_ACL_RULE_DEF(dpdk_acl_rule, RTE_DIM(dpdk_acl_field_defs));

////////////////////////////////////////////////////////////////////////////////

static const struct rte_acl_param dpdk_acl_params = {
.name = "DPDK_ACL",
.socket_id = SOCKET_ID_ANY,
.rule_size = RTE_ACL_RULE_SZ(RTE_DIM(dpdk_acl_field_defs)),

// maximum number of rules
.max_rule_num = MAX_RULE_NUM,
};

////////////////////////////////////////////////////////////////////////////////

struct dpdk_acl {
struct dpdk_acl_rule rules[MAX_RULE_NUM];
struct rte_acl_ctx *ctx;
struct rte_acl_config cfg;
};

////////////////////////////////////////////////////////////////////////////////

struct filter_rule_holder {
struct net4 nets_src[MAX_RULE_NUM];
struct net4 nets_dst[MAX_RULE_NUM];
struct filter_port_range ports_src[MAX_RULE_NUM];
struct filter_port_range ports_dst[MAX_RULE_NUM];
struct filter_rule rules[MAX_RULE_NUM];
};
39 changes: 39 additions & 0 deletions filter/bench/dpdk/gen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "gen.h"
#include "rule.h"
#include "utils.h"
#include <netinet/in.h>

////////////////////////////////////////////////////////////////////////////////

void
generate_rules(struct filter_rule_holder *holder, uint32_t count) {
for (uint32_t i = 0; i < count; ++i) {
struct filter_rule *rule = &holder->rules[i];

holder->nets_src[i].addr = ip(0xff, 0xff, i & 0xff, 0);
holder->nets_src[i].mask = ip(0xff, 0xff, 0xff, 0);

holder->nets_dst[i].addr = ip(0xff, 0xff, (i + 1) & 0xff, 0);
holder->nets_dst[i].mask = ip(0xff, 0xff, 0xff, 0);

rule->net4.dst_count = rule->net4.src_count = 1;
rule->net4.srcs = &holder->nets_src[i];
rule->net4.dsts = &holder->nets_dst[i];

holder->ports_src[i] = (struct filter_port_range
){.from = i & 127, .to = 500 + (i & 255)};
holder->ports_dst[i] = (struct filter_port_range
){.from = 100 + (i & 127), .to = 600 + (i & 255)};

rule->transport.src_count = rule->transport.dst_count = 1;
rule->transport.srcs = &holder->ports_src[i];
rule->transport.dsts = &holder->ports_dst[i];

rule->transport.proto = (struct filter_proto
){.proto = IPPROTO_UDP, .enable_bits = 0, .disable_bits = 0};

rule->action = i + 1;
}
}

////////////////////////////////////////////////////////////////////////////////
8 changes: 8 additions & 0 deletions filter/bench/dpdk/gen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "def.h"

////////////////////////////////////////////////////////////////////////////////

void
generate_rules(struct filter_rule_holder *holder, uint32_t count);

////////////////////////////////////////////////////////////////////////////////
Loading
Loading