aboutsummaryrefslogtreecommitdiff
path: root/example/ipfragreass/odp_ipfragreass_reassemble.c
diff options
context:
space:
mode:
Diffstat (limited to 'example/ipfragreass/odp_ipfragreass_reassemble.c')
-rw-r--r--example/ipfragreass/odp_ipfragreass_reassemble.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/example/ipfragreass/odp_ipfragreass_reassemble.c b/example/ipfragreass/odp_ipfragreass_reassemble.c
index fd1618f54..89055e6e4 100644
--- a/example/ipfragreass/odp_ipfragreass_reassemble.c
+++ b/example/ipfragreass/odp_ipfragreass_reassemble.c
@@ -1,9 +1,11 @@
-/* Copyright (c) 2017, Linaro Limited
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2017-2018 Linaro Limited
*/
+/** @cond _ODP_HIDE_FROM_DOXYGEN_ */
+
+#include <odp_api.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -87,7 +89,7 @@ static inline uint32_t hash(odph_ipv4hdr_t *hdr)
{
uint32_t a = hdr->src_addr;
uint32_t b = hdr->dst_addr;
- uint32_t c = hdr->id << 16 | hdr->proto;
+ uint32_t c = (uint32_t)hdr->id << 16 | hdr->proto;
/* A degenerate 3x32-bit Jenkins hash */
c ^= b;
@@ -181,11 +183,9 @@ static struct packet *extract_complete_packet(struct packet *tail,
struct packet *current = tail;
odph_ipv4hdr_t tail_hdr;
uint16_t final_frag_offset;
- uint16_t expected_frag_offset;
tail_hdr = *(odph_ipv4hdr_t *)odp_packet_data(tail->handle);
final_frag_offset = ipv4hdr_fragment_offset_oct(tail_hdr);
- expected_frag_offset = final_frag_offset;
while (current) {
odph_ipv4hdr_t curr_hdr;
uint16_t curr_offset_oct;
@@ -256,7 +256,6 @@ static struct packet *extract_complete_packet(struct packet *tail,
break;
}
- expected_frag_offset -= prev_oct;
current = prev;
}
@@ -303,11 +302,17 @@ static int send_packet(struct packet *tail, odp_queue_t out)
*/
while (current && equal_flow(current, &result)) {
struct packet new_result = *current;
- int concat_success;
+ int concat_success, trunc_success;
current = prev_packet(new_result);
header = odp_packet_data(result.handle);
- odp_packet_pull_head(result.handle, ipv4hdr_ihl(*header));
+ trunc_success = odp_packet_trunc_head(&result.handle, ipv4hdr_ihl(*header),
+ NULL, NULL);
+ if (trunc_success < 0) {
+ fprintf(stderr, "ERROR: odp_packet_trunc_head\n");
+ return -1;
+ }
+
concat_success = odp_packet_concat(&new_result.handle,
result.handle);
if (concat_success < 0) {
@@ -376,7 +381,7 @@ static void sort_fraglist(union fraglist *fl, struct flts now)
*
* @return The number of packets reassembled and sent to the output queue
*/
-static int add_fraglist_to_fraglist(union fraglist *fl, union fraglist frags,
+static int add_fraglist_to_fraglist(odp_atomic_u128_t *fl, union fraglist frags,
struct packet *frags_head, struct flts now,
odp_queue_t out, odp_bool_t dont_assemble)
{
@@ -395,8 +400,7 @@ redo:;
struct flts oldfl_earliest;
struct flts frags_earliest;
- __atomic_load(&fl->half[0], &oldfl.half[0], __ATOMIC_RELAXED);
- __atomic_load(&fl->half[1], &oldfl.half[1], __ATOMIC_RELAXED);
+ oldfl.raw = odp_atomic_load_u128(fl);
/*
* If we're updating a non-empty fraglist, we should always attempt
@@ -429,9 +433,7 @@ redo:;
* yet. If not, just write out our changes and move on.
*/
if (newfl.part_len < newfl.whole_len || dont_assemble) {
- if (!atomic_strong_cas_dblptr(&fl->raw, &oldfl.raw, newfl.raw,
- __ATOMIC_RELEASE,
- __ATOMIC_RELAXED)) {
+ if (!odp_atomic_cas_rel_u128(fl, &oldfl.raw, newfl.raw)) {
/* Failed to add this fragment? Try again. */
set_prev_packet(frags_head, NULL);
goto redo;
@@ -450,8 +452,7 @@ redo:;
* otherwise we'll update the slot with our changes later.
*/
init_fraglist(&nullfl);
- if (!atomic_strong_cas_dblptr(&fl->raw, &oldfl.raw, nullfl.raw,
- __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
+ if (!odp_atomic_cas_acq_u128(fl, &oldfl.raw, nullfl.raw)) {
/* Failed to take this fraglist? Try again. */
set_prev_packet(frags_head, NULL);
goto redo;
@@ -554,7 +555,7 @@ redo:;
*
* @return The number of packets reassembled and sent to the output
*/
-static int add_frag_to_fraglist(union fraglist *fl, struct packet *frag,
+static int add_frag_to_fraglist(odp_atomic_u128_t *fl, struct packet *frag,
uint16_t frag_payload_len,
uint16_t frag_reass_payload_len,
odp_queue_t out)
@@ -580,7 +581,7 @@ static int add_frag_to_fraglist(union fraglist *fl, struct packet *frag,
* @param out The queue to which reassembled packets should be written
* @param force Whether all flows in the fraglist should be considered stale
*/
-static void remove_stale_flows(union fraglist *fl, union fraglist oldfl,
+static void remove_stale_flows(odp_atomic_u128_t *fl, union fraglist oldfl,
struct flts timestamp_now, odp_queue_t out,
odp_bool_t force)
{
@@ -679,7 +680,7 @@ static void remove_stale_flows(union fraglist *fl, union fraglist oldfl,
* @param out The queue to which reassembled packets should be written
* @param force Whether all flows in the fraglist should be considered stale
*/
-static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out,
+static void garbage_collect_fraglist(odp_atomic_u128_t *fl, odp_queue_t out,
odp_bool_t force)
{
uint64_t time_now;
@@ -692,8 +693,9 @@ static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out,
do {
time_now = odp_time_to_ns(odp_time_global());
timestamp_now.t = time_now / TS_RES_NS;
- __atomic_load(&fl->half[0], &oldfl.half[0], __ATOMIC_RELAXED);
- __atomic_load(&fl->half[1], &oldfl.half[1], __ATOMIC_RELAXED);
+
+ oldfl.raw = odp_atomic_load_u128(fl);
+
elapsed.t = timestamp_now.t - oldfl.earliest;
if (oldfl.tail == NULL ||
@@ -706,11 +708,8 @@ static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out,
union fraglist nullfl;
init_fraglist(&nullfl);
- success = atomic_strong_cas_dblptr(&fl->raw, &oldfl.raw,
- nullfl.raw,
- __ATOMIC_ACQUIRE,
- __ATOMIC_RELAXED);
-
+ success = odp_atomic_cas_acq_u128(fl, &oldfl.raw,
+ nullfl.raw);
if (success)
remove_stale_flows(fl, oldfl, timestamp_now,
out, force);
@@ -718,7 +717,7 @@ static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out,
} while (!success);
}
-int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists,
+int reassemble_ipv4_packets(odp_atomic_u128_t *fraglists, int num_fraglists,
struct packet *fragments, int num_fragments,
odp_queue_t out)
{
@@ -731,7 +730,7 @@ int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists,
uint16_t frag_payload_len;
uint16_t frag_reass_payload_len;
uint32_t key;
- union fraglist *fl;
+ odp_atomic_u128_t *fl;
int status;
frag = fragments[i];
@@ -761,7 +760,7 @@ int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists,
return packets_reassembled;
}
-void garbage_collect_fraglists(union fraglist *fraglists, int num_fraglists,
+void garbage_collect_fraglists(odp_atomic_u128_t *fraglists, int num_fraglists,
odp_queue_t out, odp_bool_t destroy_all)
{
int i;