From 5915d243e1b33593cb12488c65ce833479292a92 Mon Sep 17 00:00:00 2001 From: Salvatore Date: Tue, 20 Apr 2021 15:31:23 +0200 Subject: [PATCH] fixing examples --- examples/empty/driver/driver.c | 39 +++++++++++++++ examples/filtering/driver/driver.c | 79 ++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 examples/empty/driver/driver.c create mode 100644 examples/filtering/driver/driver.c diff --git a/examples/empty/driver/driver.c b/examples/empty/driver/driver.c new file mode 100644 index 0000000..151b9bd --- /dev/null +++ b/examples/empty/driver/driver.c @@ -0,0 +1,39 @@ +// Copyright 2020 ETH Zurich +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "gdriver.h" + +uint32_t fill_packet(uint32_t msg_idx, uint32_t pkt_idx, uint8_t *pkt_buff, uint32_t max_pkt_size, uint32_t* l1_pkt_size) +{ + // nothing to do here + + return max_pkt_size; +} + +int main(int argc, char**argv) +{ + const char *handlers_file="build/empty"; + const char *hh="empty_hh"; + const char *ph="empty_ph"; + const char *th="empty_th"; + + gdriver_init(argc, argv, handlers_file, hh, ph, th); + gdriver_set_packet_fill_callback(fill_packet); + + gdriver_run(); + + gdriver_fini(); + return 0; +} diff --git a/examples/filtering/driver/driver.c b/examples/filtering/driver/driver.c new file mode 100644 index 0000000..11154b9 --- /dev/null +++ b/examples/filtering/driver/driver.c @@ -0,0 +1,79 @@ +// Copyright 2020 ETH Zurich +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "gdriver.h" + +#include "../handlers/filtering.h" + +#define SEED 6598736 + +uint16_t hashmult(const uint16_t key) +{ + uint16_t hash = 0; + uint8_t *key_byte = (uint8_t *)&key; + for (uint16_t i = 0; i < sizeof(uint16_t); i++) + { + //printf("i %u k %u",i,key_byte[i] ); + hash = hash * 31 + (key_byte[i]); + } + return hash; +} + +void fill_htable(uint32_t *vec, uint32_t length) +{ + for (uint32_t i = 0; i < length; i++) + { + vec[hashmult((uint16_t)i)] = i; + } +} + +uint32_t fill_packet(uint32_t msg_idx, uint32_t pkt_idx, uint8_t *pkt_buff, uint32_t max_pkt_size, uint32_t *l1_pkt_size) +{ + assert(max_pkt_size >= KEY_SIZE); + + for (int i = 0; i < KEY_SIZE / sizeof(uint32_t); i++) + { + ((uint32_t *)pkt_buff)[i] = rand(); + } + + return max_pkt_size; +} + +int main(int argc, char **argv) +{ + const char *handlers_file = "build/filtering"; + const char *hh = NULL; + const char *ph = "filtering_ph"; + const char *th = NULL; + + srand(SEED); + + gdriver_init(argc, argv, handlers_file, hh, ph, th); + gdriver_set_packet_fill_callback(fill_packet); + + uint32_t *vec = (uint32_t *)malloc(sizeof(uint32_t) * (TOT_WORDS)); + fill_htable(vec, TOT_WORDS); + + gdriver_set_l2_img((void *)vec, sizeof(uint32_t) * (TOT_WORDS)); + + gdriver_run(); + + gdriver_fini(); + + free(vec); + return 0; +}