Fix extrapolation used in latency measurements
[samplevnf.git] / VNFs / DPPD-PROX / genl4_bundle.h
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef _GENL4_BUNDLE_H_
18 #define _GENL4_BUNDLE_H_
19
20 #include "heap.h"
21 #include "genl4_stream.h"
22 #include "lconf.h"
23
24 /* Configured once and used during packet generation. The structure
25    describes a single set of consecutive streams. When used at the
26    server side, it only contains a simple stream to represent a
27    service. */
28 struct bundle_cfg {
29         struct host_set   clients;
30         uint32_t          n_stream_cfgs;
31         struct stream_cfg **stream_cfgs;
32 };
33
34 /* A bundle_ctx represents a an active stream between a client and a
35    server of servers. */
36 struct bundle_ctx {
37         struct pkt_tuple        tuple;      /* Client IP/PORT generated once at bundle creation time, client PORT and server IP/PORT created when stream_idx++ */
38         struct heap_ref         heap_ref;   /* Back reference into heap */
39         struct heap             *heap;      /* timer management */
40
41         const struct bundle_cfg *cfg;       /* configuration time read only structure */
42
43         struct stream_ctx       ctx;        /* state management info for stream_cfg (reset when stream_idx++) */
44         uint32_t                stream_idx; /* iterate through cfg->straem_cfgs */
45 };
46
47 #define BUNDLE_CTX_UPCAST(r) ((struct bundle_ctx *)((uint8_t *)r - offsetof(struct bundle_ctx, heap_ref)))
48
49 struct bundle_ctx_pool {
50         struct rte_hash   *hash;
51         struct bundle_ctx **hash_entries;
52         struct bundle_ctx **free_bundles;
53         struct bundle_ctx *bundles; /* Memory containing all communications */
54         uint32_t          *occur;
55         struct bundle_cfg *bundle_cfg;
56         uint32_t          n_occur;
57         uint32_t          seed;
58         uint32_t          n_free_bundles;
59         uint32_t          tot_bundles;
60 };
61
62 struct l4_stats {
63         uint64_t bundles_created;
64         uint64_t tcp_finished_no_retransmit;
65         uint64_t tcp_finished_retransmit;
66         uint64_t udp_finished;
67         uint64_t tcp_created;
68         uint64_t udp_created;
69         uint64_t tcp_expired;
70         uint64_t tcp_retransmits;
71         uint64_t udp_expired;
72 };
73
74 struct cdf;
75 int bundle_ctx_pool_create(const char *name, uint32_t n_elems, struct bundle_ctx_pool *ret, uint32_t *occur, uint32_t n_occur, struct bundle_cfg *cfg, int socket_id);
76
77 struct bundle_ctx *bundle_ctx_pool_get(struct bundle_ctx_pool *p);
78 struct bundle_ctx *bundle_ctx_pool_get_w_cfg(struct bundle_ctx_pool *p);
79 void bundle_ctx_pool_put(struct bundle_ctx_pool *p, struct bundle_ctx *bundle);
80
81 void bundle_create_tuple(struct pkt_tuple *tp, const struct host_set *clients, const struct stream_cfg *stream_cfg, int rnd_ip, unsigned *seed);
82 void bundle_init(struct bundle_ctx *bundle, struct heap *heap, enum l4gen_peer peer, unsigned *seed);
83 void bundle_init_w_cfg(struct bundle_ctx *bundle, const struct bundle_cfg *cfg, struct heap *heap, enum l4gen_peer peer, unsigned *seed);
84 void bundle_expire(struct bundle_ctx *bundle, struct bundle_ctx_pool *pool, struct l4_stats *l4_stats);
85 int bundle_proc_data(struct bundle_ctx *bundle, struct rte_mbuf *mbuf, struct l4_meta *l4_meta, struct bundle_ctx_pool *pool, unsigned *seed, struct l4_stats *l4_stats);
86 uint32_t bundle_cfg_length(struct bundle_cfg *cfg);
87 uint32_t bundle_cfg_max_n_segments(struct bundle_cfg *cfg);
88
89 #endif /* _GENL4_BUNDLE_H_ */