Adding PROX(Packet pROcessing eXecution engine) VNF to sampleVNF
[samplevnf.git] / VNFs / DPPD-PROX / dpi / dpi.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 _DPI_H_
18 #define _DPI_H_
19
20 #include <sys/time.h>
21 #include <inttypes.h>
22 #include <stddef.h>
23
24 struct flow_info {
25         uint32_t ip_src;
26         uint32_t ip_dst;
27         uint8_t ip_proto;
28         uint16_t port_src;
29         uint16_t port_dst;
30         uint8_t reservered[3];
31 } __attribute__((packed));
32
33 struct dpi_payload {
34         uint8_t  *payload;
35         uint16_t len;
36         uint16_t client_to_server;
37         struct timeval tv;
38 };
39
40 struct dpi_engine {
41         /* Returns 0 on success, This function is called from an
42            arbitrary thread before any other function in this struct
43            is called. */
44         int (*dpi_init)(uint32_t thread_count, int argc, const char *argv[]);
45         /* Return the size that should be allocated in the flow
46            table. It is the sizeof(*flow_data) passed to
47            dpi_process(). */
48         size_t (*dpi_get_flow_entry_size)(void);
49         /* Called before the flow entry is expired. */
50         void (*dpi_flow_expire)(void *flow_data);
51         /* start function called from a DPI thread itself. The opaque
52            pointer returned here will be passed to dpi_thread_stop and
53            dpi_process. */
54         void *(*dpi_thread_start)(void);
55         /* Stop function called from a DPI thread itself. */
56         void (*dpi_thread_stop)(void *opaque);
57         /* Processing function to perform actual DPI work. struct
58            flow_info contains the 5 tuple, flow_data is the entry in
59            the flow table which has a size specified by
60            dpi_get_flow_entry_size(). The payload (together with the
61            time and the direction) is passed through the payload
62            parameter. DPI results are returned by the results
63            array. The function returns 0 on success. */
64         int (*dpi_process)(void *opaque, struct flow_info *fi, void *flow_data,
65                            struct dpi_payload *payload, uint32_t results[],
66                            size_t *result_len);
67         /* Called once at cleanup. */
68         void (*dpi_finish)(void);
69         /* Function used for printing. */
70         int (*dpi_print)(const char *fmt, ...);
71 };
72
73 /* Returns the implementation of a dpi_engine. */
74 struct dpi_engine *get_dpi_engine(void);
75
76 #endif /* _DPI_H_ */