Skip to content

Commit c6a6d56

Browse files
author
Kirc
committed
Add get_len_from_type, remove elements_lengths
1 parent 60e1dd9 commit c6a6d56

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

plugins/storage/fastbit/config_struct.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ struct fastbit_config {
5858
std::map<uint32_t, /* ODID */
5959
struct od_info>*> *od_infos;
6060

61-
/* Element lengths from ipfix-elements.xml is loaded into elements_lengths
62-
* (Enterprise ID -> element ID -> element storage type)
63-
*/
64-
std::map<uint32_t, std::map<uint16_t, int>> *elements_lengths;
65-
6661
/* Stores elements that should be indexed */
6762
std::vector<std::string> *index_en_id;
6863

plugins/storage/fastbit/fastbit.cpp

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,56 @@ void ipv6_addr_non_canonical(char *str, const struct in6_addr *addr)
8080
addr->s6_addr[14], addr->s6_addr[15]);
8181
}
8282

83+
/**
84+
* \brief Returns the length of an element, based on its type
85+
*
86+
* @param type Element type
87+
*
88+
*/
89+
int get_len_from_type(ELEMENT_TYPE type)
90+
{
91+
int len;
92+
93+
switch (type) {
94+
case ET_DATE_TIME_MILLISECONDS:
95+
case ET_DATE_TIME_MICROSECONDS:
96+
case ET_DATE_TIME_NANOSECONDS:
97+
case ET_MAC_ADDRESS:
98+
case ET_FLOAT_64:
99+
case ET_SIGNED_64:
100+
case ET_UNSIGNED_64:
101+
len = 8;
102+
break;
103+
case ET_BOOLEAN:
104+
case ET_DATE_TIME_SECONDS:
105+
case ET_FLOAT_32:
106+
case ET_IPV4_ADDRESS:
107+
case ET_SIGNED_32:
108+
case ET_UNSIGNED_32:
109+
len = 4;
110+
break;
111+
case ET_SIGNED_16:
112+
case ET_UNSIGNED_16:
113+
len = 2;
114+
break;
115+
case ET_SIGNED_8:
116+
case ET_UNSIGNED_8:
117+
len = 1;
118+
break;
119+
case ET_IPV6_ADDRESS:
120+
case ET_STRING:
121+
case ET_OCTET_ARRAY:
122+
case ET_BASIC_LIST:
123+
case ET_SUB_TEMPLATE_LIST:
124+
case ET_SUB_TEMPLATE_MULTILIST:
125+
default:
126+
len = -1;
127+
break;
128+
}
129+
130+
return len;
131+
}
132+
83133
/**
84134
* \brief Load elements types from xml to configure structure
85135
*
@@ -148,7 +198,7 @@ int load_types_from_xml(struct fastbit_config *conf)
148198
len = -1;
149199
}
150200

151-
(*conf->elements_lengths)[en][id] = len;
201+
// (*conf->elements_lengths)[en][id] = len;
152202
}
153203

154204
return 0;
@@ -490,12 +540,6 @@ int storage_init(char *params, void **config)
490540
return 1;
491541
}
492542

493-
c->elements_lengths = new std::map<uint32_t, std::map<uint16_t, int>>;
494-
if (c->elements_lengths == NULL) {
495-
MSG_ERROR(msg_module, "Memory allocation failed (%s:%d)", __FILE__, __LINE__);
496-
return 1;
497-
}
498-
499543
c->index_en_id = new std::vector<std::string>;
500544
if (c->index_en_id == NULL) {
501545
MSG_ERROR(msg_module, "Memory allocation failed (%s:%d)", __FILE__, __LINE__);
@@ -729,7 +773,6 @@ int storage_close(void **config)
729773
delete od_infos;
730774
delete conf->index_en_id;
731775
delete conf->dirs;
732-
delete conf->elements_lengths;
733776
delete conf;
734777
return 0;
735778
}

plugins/storage/fastbit/fastbit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ struct od_info {
9090
FlowWatch flow_watch;
9191
};
9292

93+
/**
94+
* \brief Returns the length of an element, based on its type
95+
*
96+
* @param type Element type
97+
*
98+
*/
99+
int get_len_from_type(ELEMENT_TYPE type);
100+
93101
/**
94102
* \brief Load elements types from xml to configure structure
95103
*

plugins/storage/fastbit/fastbit_element.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,14 @@ uint16_t el_uint::fill(uint8_t *data) {
598598

599599
int el_uint::set_type()
600600
{
601-
int target_size = (_config->use_template_field_lengths) ?
602-
_real_size : (*_config->elements_lengths)[_en][_id];
601+
int target_size;
602+
const ipfix_element_t *ipfix_elem = get_element_by_id(_id, _en);
603+
604+
if (_config->use_template_field_lengths || !ipfix_elem) {
605+
target_size = _real_size;
606+
} else {
607+
target_size = get_len_from_type(ipfix_elem->type);
608+
}
603609

604610
switch (target_size) {
605611
case 1:

0 commit comments

Comments
 (0)