@@ -102,6 +102,92 @@ struct translator_table_rec
102102 translator_func func ;
103103};
104104
105+ //***************************** COPIED FROM OLD PLUGIN *****************************
106+ // Path to unirec elements config file
107+ const char * UNIREC_ELEMENTS_FILE = "unirec-elements.txt" ; //TODO is this where it should be located
108+
109+ // Possible UniRec data types
110+ const char * unirec_data_types_str [] = {
111+ "string" , /*UR_TYPE_STRING*/
112+ "bytes" , /*UR_TYPE_BYTES*/
113+ "char" , /*UR_TYPE_CHAR*/
114+ "uint8" , /*UR_TYPE_UINT8*/
115+ "int8" , /*UR_TYPE_INT8*/
116+ "uint16" , /*UR_TYPE_UINT16*/
117+ "int16" , /*UR_TYPE_INT16*/
118+ "uint32" , /*UR_TYPE_UINT32*/
119+ "int32" , /*UR_TYPE_INT32*/
120+ "uint64" , /*UR_TYPE_UINT64*/
121+ "int64" , /*UR_TYPE_INT64*/
122+ "float" , /*UR_TYPE_FLOAT*/
123+ "double" , /*UR_TYPE_DOUBLE*/
124+ "ipaddr" , /*UR_TYPE_IP*/
125+ "time" , /*UR_TYPE_TIME*/
126+ };
127+
128+ /**
129+ * \brief Creates IPFIX id from string
130+ *
131+ * @param ipfixToken String in eXXidYY format, where XX is enterprise number and YY is element ID
132+ * @return Returns id that is used to compare field against IPFIX template
133+ */
134+ static ipfixElement ipfix_from_string (char * ipfixToken )
135+ {
136+ ipfixElement element ;
137+ char * endptr ;
138+
139+ element .en = strtol (ipfixToken + 1 , & endptr , 10 );
140+ element .id = strtol (endptr + 2 , (char * * ) NULL , 10 );
141+
142+ return element ;
143+ }
144+
145+ static int8_t checkUnirecType (const char * type )
146+ {
147+ int i ;
148+ for (i = 0 ; i < UNIREC_DATA_TYPES_COUNT ; i ++ ) {
149+ if (strcmp (type , unirec_data_types_str [i ]) == 0 ) {
150+ return i ;
151+ }
152+ }
153+ return -1 ;
154+ }
155+
156+ /**
157+ * \brief Convert ipfix element id to unirec type for faster processing ipfix messages
158+ * \param ipfix_el Ipfix element structure.
159+ * \return One value from enum `unirecFieldEnum`.
160+ */
161+ static int8_t getUnirecFieldTypeFromIpfixId (ipfixElement ipfix_el )
162+ {
163+ uint16_t id = ipfix_el .id ;
164+ uint32_t en = ipfix_el .en ;
165+
166+ if ((en == 0 && (id == 8 || id == 12 )) ||
167+ (en == 39499 && id == 40 ) ||
168+ (en == 0 && (id == 27 || id == 28 )) ||
169+ (en == 39499 && id == 41 )) {
170+ // IP or INVEA_SIP_RTP_IP
171+ return UNIREC_FIELD_IP ;
172+ } else if (en == 0 && id == 2 ) {
173+ // Packets
174+ return UNIREC_FIELD_PACKET ;
175+ } else if (en == 0 && (id == 152 || id == 153 )) {
176+ // Timestamps
177+ return UNIREC_FIELD_TS ;
178+ } else if (en == 0 && id == 10 ) {
179+ // DIR_BIT_FIELD
180+ return UNIREC_FIELD_DBF ;
181+ } else if (en == 0 && id == 405 ) {
182+ // LINK_BIT_FIELD
183+ return UNIREC_FIELD_LBF ;
184+ } else {
185+ // Other
186+ return UNIREC_FIELD_OTHER ;
187+ }
188+ }
189+
190+
105191/**
106192 * \brief Loads all available elements from configuration file
107193 * @return List of UniRec elements on success, NULL otherwise
@@ -118,14 +204,14 @@ static unirecField *load_elements()
118204 /* Open the file */
119205 uef = fopen (UNIREC_ELEMENTS_FILE , "r" );
120206 if (uef == NULL ) {
121- IPX_CTX_ERROR ( ctx , "Unable to open: %s" , UNIREC_ELEMENTS_FILE );
207+ //TODO unable to open message
122208 return NULL ;
123209 }
124210
125211 /* Init buffer */
126212 line = malloc (lineSize );
127213 if (line == NULL ){
128- IPX_CTX_ERROR ( ctx , "Unable to allocate memory for buffer." );
214+ //TODO memory allocation message
129215 fclose (uef );
130216 return NULL ;
131217 }
@@ -144,7 +230,7 @@ static unirecField *load_elements()
144230 /* Create new element structure, make space for ipfixElCount ipfix elements and NULL */
145231 currentField = malloc (sizeof (unirecField ));
146232 if (currentField == NULL ){
147- IPX_CTX_ERROR ( ctx , "Unable to allocate memory for field." );
233+ //TODO memory allocation message
148234 fclose (uef );
149235 free (line );
150236 return NULL ;
@@ -165,7 +251,7 @@ static unirecField *load_elements()
165251 case 1 :
166252 currentField -> unirec_type = checkUnirecType (token );
167253 if (currentField -> unirec_type < 0 ) {
168- MSG_ERROR (msg_module , "Unknown UniRec data type \"%s\" of field \"%s\"" , token , currentField -> name );
254+ // MSG_ERROR(msg_module, "Unknown UniRec data type \"%s\" of field \"%s\"", token, currentField->name);
169255 fclose (uef );
170256 free (line );
171257 return NULL ;
@@ -215,6 +301,7 @@ static unirecField *load_elements()
215301
216302 return fields ;
217303}
304+ //********************** END OF COPIED FROM OLD PLUGIN *****************************
218305
219306/**
220307 * \brief Global translator table
0 commit comments