Add support for comments in configuration variables
[samplevnf.git] / VNFs / DPPD-PROX / parse_utils.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 _PARSE_UTILS_H_
18 #define _PARSE_UTILS_H_
19
20 #include <inttypes.h>
21 #include "ip_subnet.h"
22
23 #define MAX_STR_LEN_PROC  (3 * 1518 + 20)
24
25 struct ipv6_addr;
26 struct ether_addr;
27
28 enum ctrl_type {CTRL_TYPE_DP, CTRL_TYPE_MSG, CTRL_TYPE_PKT};
29
30 struct core_task {
31         uint32_t core;
32         uint32_t task;
33         enum ctrl_type type;
34 };
35
36 struct core_task_set {
37         struct core_task core_task[64];
38         uint32_t n_elems;
39 };
40
41 int parse_vars(char *val, size_t len, const char *name);
42
43 int parse_int_mask(uint32_t* val, uint32_t* mask, const char *saddr);
44
45 int parse_range(uint32_t* lo, uint32_t* hi, const char *saddr);
46
47 /* parses CIDR notation. Note that bits within the address that are
48    outside the subnet (as specified by the prefix) are set to 0. */
49 int parse_ip4_cidr(struct ip4_subnet *val, const char *saddr);
50 int parse_ip6_cidr(struct ip6_subnet *val, const char *saddr);
51
52 int parse_ip(uint32_t *paddr, const char *saddr);
53
54 int parse_ip6(struct ipv6_addr *addr, const char *saddr);
55
56 int parse_mac(struct ether_addr *paddr, const char *saddr);
57
58 /* return error on overflow or invalid suffix*/
59 int parse_kmg(uint32_t* val, const char *str);
60
61 int parse_bool(uint32_t* val, const char *str);
62
63 int parse_flag(uint32_t* val, uint32_t flag, const char *str);
64
65 int parse_list_set(uint32_t *list, const char *str, uint32_t max_limit);
66
67 int parse_task_set(struct core_task_set *val, const char *str);
68
69 int parse_int(uint32_t* val, const char *str);
70 int parse_float(float* val, const char *str);
71
72 int parse_u64(uint64_t* val, const char *str);
73
74 int parse_str(char* dst, const char *str, size_t max_len);
75
76 int parse_path(char *dst, const char *str, size_t max_len);
77
78 int parse_port_name(uint32_t *val, const char *str);
79
80 /* The syntax for random fields is X0010101XXX... where X is a
81    randomized bit and 0, 1 are fixed bit. The resulting mask and fixed
82    arguments are in BE order. */
83 int parse_random_str(uint32_t *mask, uint32_t *fixed, uint32_t *len, const char *str);
84
85 int parse_port_name_list(uint32_t *val, uint32_t *tot, uint8_t max_vals, const char *str);
86
87 /* Parses a comma separated list containing a remapping of ports
88    specified by their name. Hence, all port names referenced from the
89    list have to be added using add_port_name() before this function
90    can be used. The first elements in the list are mapped to 0, the
91    second to 1, etc. Multiple elements can be mapped to the same
92    index. If multiple elements are used, they are separated by
93    pipes. An example would be p0|p1,p2|p3. In this example, p0 and p1
94    both map to 0 and p2 and p3 map both map to 1. The mapping should
95    contain at least enough entries as port ids. */
96 int parse_remap(uint8_t *mapping, const char *str);
97
98 /* Convert an lcore_id to socket notation */
99 int lcore_to_socket_core_ht(uint32_t lcore_id, char *dst, size_t len);
100
101 int add_port_name(uint32_t val, const char *str);
102
103 /* The $self variable is something that can change its value (i.e. its
104    value represents the core that is currently being parsed). */
105 int set_self_var(const char *str);
106
107 int add_var(const char* name, const char *val, uint8_t cli);
108
109 /* Parses str and returns pointer to the key value */
110 char *get_cfg_key(char *str);
111
112 /* Changes strings in place. */
113 void strip_spaces(char *strings[], const uint32_t count);
114
115 /* Contains error string if any of the above returned an error. */
116 const char* get_parse_err(void);
117
118 /* Returns true if running from  a virtual machine. */
119 int is_virtualized(void);
120
121 int parse_single_var(char *val, size_t len, const char *name);
122
123 #endif /* _PARSE_UTILS_H_ */