Update License text
[vnfsdk/compliance.git] / veslibrary / ves_clibrary / evel / evel-library / code / evel_unit / evel_unit.c
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
5  * Unless otherwise specified, all software contained herein is
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and 
15  * limitations under the License.
16  *
17  ****************************************************************************/
18 /**************************************************************************//**
19  * @file
20  * Unit tests for JSON encoding and throttling.
21  *
22  * This software is intended to show the essential elements of the library's
23  * use.
24  *
25  ****************************************************************************/
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <sys/time.h>
32
33 #include "evel.h"
34 #include "evel_internal.h"
35 #include "evel_throttle.h"
36 #include "metadata.h"
37
38 typedef enum {
39   SERVICE_NONE,
40   SERVICE_CODEC,
41   SERVICE_TRANSCODING,
42   SERVICE_RTCP,
43   SERVICE_EOC_VQM,
44   SERVICE_MARKER
45 } SERVICE_TEST;
46
47 /*****************************************************************************/
48 /* Local prototypes.                                                         */
49 /*****************************************************************************/
50 static void test_encode_heartbeat();
51 static void test_encode_header_overrides();
52 static void test_encode_fault();
53 static void test_encode_fault_with_escaping();
54 static void test_encode_measurement();
55 static void test_encode_mobile_mand();
56 static void test_encode_mobile_opts();
57 static void test_encode_other();
58 static void test_encode_report();
59 static void test_encode_service();
60 static void test_encode_service_subset(const SERVICE_TEST service_test);
61 static void test_encode_signaling();
62 static void test_encode_state_change();
63 static void test_encode_syslog();
64 static void test_json_response_junk();
65 static void test_json_provide_throttle_state();
66 static void test_json_measurement_interval();
67 static void test_json_throttle_spec_field();
68 static void test_json_throttle_spec_nv_pair();
69 static void test_json_throttle_spec_two_domains();
70 static void test_json_throttle_spec_bad_command_type();
71 static void test_encode_fault_throttled();
72 static void test_encode_measurement_throttled();
73 static void test_encode_mobile_throttled();
74 static void test_encode_other_throttled();
75 static void test_encode_report_throttled();
76 static void test_encode_service_throttled();
77 static void test_encode_signaling_throttled();
78 static void test_encode_state_change_throttled();
79 static void test_encode_syslog_throttled();
80 static void compare_strings(char * expected,
81                             char * actual,
82                             int max_size,
83                             char * description);
84
85 /**************************************************************************//**
86  * Main function.
87  *
88  * Runs all unit test cases, and fails hard on the first failure.
89  *
90  * @param[in] argc  Argument count.
91  * @param[in] argv  Argument vector - for usage see usage_text.
92  *****************************************************************************/
93 int main(int argc, char ** argv)
94 {
95   assert(argc >= 0);
96   assert(argv != NULL);
97
98   /***************************************************************************/
99   /* Fix our timezone to UTC.                                                */
100   /***************************************************************************/
101   putenv("TZ=UTC");
102
103   /***************************************************************************/
104   /* Initialize metadata.                                                    */
105   /***************************************************************************/
106   openstack_metadata_initialize();
107
108   /***************************************************************************/
109   /* Minimal initialisation to exercise the encoders.                        */
110   /***************************************************************************/
111   functional_role = "UNIT TEST";
112   log_initialize(EVEL_LOG_DEBUG, "EVEL");
113
114   /***************************************************************************/
115   /* Test each encoder.                                                      */
116   /***************************************************************************/
117   test_encode_heartbeat();
118   test_encode_header_overrides();
119   test_encode_fault();
120   test_encode_measurement();
121   test_encode_mobile_mand();
122   test_encode_mobile_opts();
123   test_encode_other();
124   test_encode_report();
125   test_encode_service();
126   test_encode_signaling();
127   test_encode_state_change();
128   test_encode_syslog();
129
130   /***************************************************************************/
131   /* Test JSON Throttle.                                                     */
132   /***************************************************************************/
133   test_json_response_junk();
134   test_json_provide_throttle_state();
135   test_json_measurement_interval();
136   test_json_throttle_spec_field();
137   test_json_throttle_spec_nv_pair();
138   test_json_throttle_spec_two_domains();
139   test_json_throttle_spec_bad_command_type();
140
141   /***************************************************************************/
142   /* Test each encoder with throttling applied.                              */
143   /***************************************************************************/
144   test_encode_fault_throttled();
145   test_encode_measurement_throttled();
146   test_encode_mobile_throttled();
147   test_encode_other_throttled();
148   test_encode_report_throttled();
149   test_encode_service_throttled();
150   test_encode_signaling_throttled();
151   test_encode_state_change_throttled();
152   test_encode_syslog_throttled();
153
154   /***************************************************************************/
155   /* Test character escaping.                                                */
156   /***************************************************************************/
157   test_encode_fault_with_escaping();
158
159   printf ("\nAll Tests Passed\n");
160
161   return 0;
162 }
163
164 /*****************************************************************************/
165 /* We link with this gettimeofday so that we get a fixed result              */
166 /*****************************************************************************/
167 int gettimeofday(struct timeval *tv,
168                  struct timezone *tz __attribute__((unused)))
169 {
170   tv->tv_sec = 1;
171   tv->tv_usec = 2;
172   return 0;
173 }
174
175 void test_encode_heartbeat()
176 {
177   char * expected =
178     "{\"event\": {"
179     "\"commonEventHeader\": {"
180     "\"domain\": \"heartbeat\", "
181     "\"eventId\": \"121\", "
182     "\"functionalRole\": \"UNIT TEST\", "
183     "\"lastEpochMicrosec\": 1000002, "
184     "\"priority\": \"Normal\", "
185     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
186     "\"sequence\": 121, "
187     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
188     "\"startEpochMicrosec\": 1000002, "
189     "\"version\": 1.2, "
190     "\"eventType\": \"Autonomous heartbeat\", "
191     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
192     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
193     "}}}";
194
195   size_t json_size = 0;
196   char json_body[EVEL_MAX_JSON_BODY];
197
198   /***************************************************************************/
199   /* Test the VM name/uuid once.                                             */
200   /***************************************************************************/
201   evel_set_next_event_sequence(121);
202
203   EVENT_HEADER * heartbeat = evel_new_heartbeat();
204   assert(heartbeat != NULL);
205
206   json_size = evel_json_encode_event(
207     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
208   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
209   assert((json_size == strlen(json_body)) && "Bad size returned");
210
211   evel_free_event(heartbeat);
212 }
213
214 void test_encode_header_overrides()
215 {
216   char * expected =
217     "{\"event\": {"
218     "\"commonEventHeader\": {"
219     "\"domain\": \"heartbeat\", "
220     "\"eventId\": \"121\", "
221     "\"functionalRole\": \"UNIT TEST\", "
222     "\"lastEpochMicrosec\": 1000, "
223     "\"priority\": \"Normal\", "
224     "\"reportingEntityName\": \"entity_name_override\", "
225     "\"sequence\": 121, "
226     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
227     "\"startEpochMicrosec\": 1001, "
228     "\"version\": 1.2, "
229     "\"eventType\": \"Autonomous heartbeat\", "
230     "\"reportingEntityId\": \"entity_id_override\", "
231     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
232     "}}}";
233
234   size_t json_size = 0;
235   char json_body[EVEL_MAX_JSON_BODY];
236
237   /***************************************************************************/
238   /* Test the VM name/uuid once.                                             */
239   /***************************************************************************/
240   evel_set_next_event_sequence(121);
241
242   EVENT_HEADER * heartbeat = evel_new_heartbeat();
243   assert(heartbeat != NULL);
244
245   evel_start_epoch_set(heartbeat, 1001);
246   evel_last_epoch_set(heartbeat, 1000);
247   evel_reporting_entity_name_set(heartbeat, "entity_name_override");
248   evel_reporting_entity_id_set(heartbeat, "entity_id_override");
249
250   json_size = evel_json_encode_event(
251     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
252   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
253   assert((json_size == strlen(json_body)) && "Bad size returned");
254
255   evel_free_event(heartbeat);
256 }
257
258 void test_encode_fault()
259 {
260   char * expected =
261     "{\"event\": {"
262     "\"commonEventHeader\": {"
263     "\"domain\": \"fault\", "
264     "\"eventId\": \"122\", "
265     "\"functionalRole\": \"UNIT TEST\", "
266     "\"lastEpochMicrosec\": 1000002, "
267     "\"priority\": \"Normal\", "
268     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
269     "\"sequence\": 122, "
270     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
271     "\"startEpochMicrosec\": 1000002, "
272     "\"version\": 1.2, "
273     "\"eventType\": \"Bad things happen...\", "
274     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
275     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
276     "}, "
277     "\"faultFields\": {"
278     "\"alarmCondition\": \"My alarm condition\", "
279     "\"eventSeverity\": \"MAJOR\", "
280     "\"eventSourceType\": \"other\", "
281     "\"specificProblem\": \"It broke very badly\", "
282     "\"eventCategory\": \"link\", "
283     "\"vfStatus\": \"Active\", "
284     "\"faultFieldsVersion\": 1.1, "
285     "\"alarmAdditionalInformation\": ["
286     "{\"name\": \"name1\", "
287     "\"value\": \"value1\"}, "
288     "{\"name\": \"name2\", "
289     "\"value\": \"value2\"}], "
290     "\"alarmInterfaceA\": \"My Interface Card\""
291     "}}}";
292
293   size_t json_size = 0;
294   char json_body[EVEL_MAX_JSON_BODY];
295   evel_set_next_event_sequence(122);
296   EVENT_FAULT * fault = evel_new_fault("My alarm condition",
297                                        "It broke very badly",
298                                        EVEL_PRIORITY_NORMAL,
299                                        EVEL_SEVERITY_MAJOR,
300                                         EVEL_SOURCE_HOST,
301                              EVEL_VF_STATUS_PREP_TERMINATE);
302   assert(fault != NULL);
303   evel_fault_type_set(fault, "Bad things happen...");
304   evel_fault_interface_set(fault, "My Interface Card");
305   evel_fault_addl_info_add(fault, "name1", "value1");
306   evel_fault_addl_info_add(fault, "name2", "value2");
307
308   json_size = evel_json_encode_event(
309     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
310   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
311   assert((json_size == strlen(json_body)) && "Bad size returned");
312
313   evel_free_event(fault);
314 }
315
316 void test_encode_measurement()
317 {
318   char * expected =
319     "{\"event\": "
320     "{\"commonEventHeader\": {"
321     "\"domain\": \"measurementsForVfScaling\", "
322     "\"eventId\": \"123\", "
323     "\"functionalRole\": \"UNIT TEST\", "
324     "\"lastEpochMicrosec\": 3000, "
325     "\"priority\": \"Normal\", "
326     "\"reportingEntityName\": \"entity_name\", "
327     "\"sequence\": 123, "
328     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
329     "\"startEpochMicrosec\": 2000, "
330     "\"version\": 1.2, "
331     "\"eventType\": \"Perf management...\", "
332     "\"reportingEntityId\": \"entity_id\", "
333     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
334     "}, "
335     "\"measurementsForVfScalingFields\": "
336     "{"
337     "\"measurementInterval\": 5.500000, "
338     "\"concurrentSessions\": 1, "
339     "\"configuredEntities\": 2, "
340     "\"cpuUsageArray\": ["
341     "{\"cpuIdentifier\": \"cpu1\", "
342     "\"percentUsage\": 11.110000}, "
343     "{\"cpuIdentifier\": \"cpu2\", "
344     "\"percentUsage\": 22.220000}], "
345     "\"filesystemUsageArray\": ["
346     "{\"blockConfigured\": 100.110000, "
347     "\"blockIops\": 33, "
348     "\"blockUsed\": 100.220000, "
349     "\"ephemeralConfigured\": 100.110000, "
350     "\"ephemeralIops\": 44, "
351     "\"ephemeralUsed\": 200.220000, "
352     "\"filesystemName\": \"00-11-22\"}, "
353     "{\"blockConfigured\": 300.110000, "
354     "\"blockIops\": 55, "
355     "\"blockUsed\": 300.220000, "
356     "\"ephemeralConfigured\": 300.110000, "
357     "\"ephemeralIops\": 66, "
358     "\"ephemeralUsed\": 400.220000, "
359     "\"filesystemName\": \"33-44-55\"}], "
360     "\"latencyDistribution\": ["
361     "{\"countsInTheBucket\": 20}, "
362     "{\"lowEndOfLatencyBucket\": 10.000000, "
363     "\"highEndOfLatencyBucket\": 20.000000, "
364     "\"countsInTheBucket\": 30}], "
365     "\"meanRequestLatency\": 4.400000, "
366     "\"memoryConfigured\": 6.600000, "
367     "\"memoryUsed\": 3.300000, "
368     "\"requestRate\": 7, "
369     "\"vNicUsageArray\": ["
370     "{"
371     "\"bytesIn\": 3, "
372     "\"bytesOut\": 4, "
373     "\"packetsIn\": 100, "
374     "\"packetsOut\": 200, "
375     "\"vNicIdentifier\": \"eth0\""
376     "}, "
377     "{"
378     "\"bytesIn\": 13, "
379     "\"bytesOut\": 14, "
380     "\"packetsIn\": 110, "
381     "\"packetsOut\": 240, "
382     "\"vNicIdentifier\": \"eth1\", "
383     "\"broadcastPacketsIn\": 11, "
384     "\"broadcastPacketsOut\": 12, "
385     "\"multicastPacketsIn\": 15, "
386     "\"multicastPacketsOut\": 16, "
387     "\"unicastPacketsIn\": 17, "
388     "\"unicastPacketsOut\": 18"
389     "}"
390     "], "
391     "\"aggregateCpuUsage\": 8.800000, "
392     "\"numberOfMediaPortsInUse\": 1234, "
393     "\"vnfcScalingMetric\": 1234.567800, "
394     "\"errors\": {"
395     "\"receiveDiscards\": 1, "
396     "\"receiveErrors\": 0, "
397     "\"transmitDiscards\": 2, "
398     "\"transmitErrors\": 1}, "
399     "\"featureUsageArray\": ["
400     "{\"featureIdentifier\": \"FeatureA\", "
401     "\"featureUtilization\": 123}, "
402     "{\"featureIdentifier\": \"FeatureB\", "
403     "\"featureUtilization\": 567}], "
404     "\"codecUsageArray\": ["
405     "{\"codecIdentifier\": \"G711a\", "
406     "\"numberInUse\": 91}, "
407     "{\"codecIdentifier\": \"G729ab\", "
408     "\"numberInUse\": 92}], "
409     "\"additionalMeasurements\": ["
410     "{\"name\": \"Group1\", "
411     "\"measurements\": ["
412     "{\"name\": \"Name1\", "
413     "\"value\": \"Value1\"}]}, "
414     "{\"name\": \"Group2\", "
415     "\"measurements\": ["
416     "{\"name\": \"Name1\", "
417     "\"value\": \"Value1\"}, "
418     "{\"name\": \"Name2\", "
419     "\"value\": \"Value2\"}]}], "
420     "\"measurementsForVfScalingVersion\": 1.1}}}";
421
422   size_t json_size = 0;
423   char json_body[EVEL_MAX_JSON_BODY];
424   EVENT_MEASUREMENT * measurement = NULL;
425   MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
426   MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
427   MEASUREMENT_CPU_USE *cpu_use;
428
429   /***************************************************************************/
430   /* Measurement.                                                            */
431   /***************************************************************************/
432   evel_set_next_event_sequence(123);
433   measurement = evel_new_measurement(5.5);
434   assert(measurement != NULL);
435   evel_measurement_type_set(measurement, "Perf management...");
436   evel_measurement_conc_sess_set(measurement, 1);
437   evel_measurement_cfg_ents_set(measurement, 2);
438   evel_measurement_mean_req_lat_set(measurement, 4.4);
439   evel_measurement_request_rate_set(measurement, 7);
440
441   cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
442   evel_measurement_cpu_use_idle_set(cpu_use,22.22);
443   evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
444   evel_measurement_cpu_use_nice_set(cpu_use,44.44);
445   evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
446   evel_measurement_cpu_use_steal_set(cpu_use,66.66);
447   evel_measurement_cpu_use_system_set(cpu_use,77.77);
448   evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
449   evel_measurement_cpu_use_wait_set(cpu_use,99.99);
450
451   cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
452   evel_measurement_cpu_use_idle_set(cpu_use,12.22);
453   evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
454   evel_measurement_cpu_use_nice_set(cpu_use,44.44);
455   evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
456   evel_measurement_cpu_use_steal_set(cpu_use,66.66);
457   evel_measurement_cpu_use_system_set(cpu_use,77.77);
458   evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
459   evel_measurement_cpu_use_wait_set(cpu_use,19.99);
460
461
462   evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33,
463                                 200.11, 200.22, 44);
464   evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55,
465                                 400.11, 400.22, 66);
466   evel_start_epoch_set(&measurement->header, 2000);
467   evel_last_epoch_set(&measurement->header, 3000);
468   evel_reporting_entity_name_set(&measurement->header, "entity_name");
469   evel_reporting_entity_id_set(&measurement->header, "entity_id");
470
471   /***************************************************************************/
472   /* Latency Bucket with no optional parameters.                             */
473   /***************************************************************************/
474   bucket = evel_new_meas_latency_bucket(20);
475   evel_meas_latency_bucket_add(measurement, bucket);
476
477   /***************************************************************************/
478   /* Latency Bucket with all optional parameters.                            */
479   /***************************************************************************/
480   bucket = evel_new_meas_latency_bucket(30);
481   evel_meas_latency_bucket_low_end_set(bucket, 10.0);
482   evel_meas_latency_bucket_high_end_set(bucket, 20.0);
483   evel_meas_latency_bucket_add(measurement, bucket);
484
485   /***************************************************************************/
486   /* vNIC Use with no optional parameters.                                   */
487   /***************************************************************************/
488   vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
489   evel_meas_vnic_use_add(measurement, vnic_use);
490
491   /***************************************************************************/
492   /* vNIC Use with all optional parameters.                                  */
493   /***************************************************************************/
494   vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
495   evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
496   evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
497   evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
498   evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
499   evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
500   evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
501   evel_meas_vnic_use_add(measurement, vnic_use);
502
503   evel_measurement_errors_set(measurement, 1, 0, 2, 1);
504
505   evel_measurement_feature_use_add(measurement, "FeatureA", 123);
506   evel_measurement_feature_use_add(measurement, "FeatureB", 567);
507
508   evel_measurement_codec_use_add(measurement, "G711a", 91);
509   evel_measurement_codec_use_add(measurement, "G729ab", 92);
510
511   evel_measurement_media_port_use_set(measurement, 1234);
512
513   evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
514
515   evel_measurement_custom_measurement_add(measurement,
516                                           "Group1", "Name1", "Value1");
517   evel_measurement_custom_measurement_add(measurement,
518                                           "Group2", "Name1", "Value1");
519   evel_measurement_custom_measurement_add(measurement,
520                                           "Group2", "Name2", "Value2");
521
522   json_size = evel_json_encode_event(
523     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
524   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
525   assert((json_size == strlen(json_body)) && "Bad size returned");
526
527   evel_free_event(measurement);
528 }
529
530 void test_encode_mobile_mand()
531 {
532   char * expected =
533     "{\"event\": "
534     "{\"commonEventHeader\": {"
535     "\"domain\": \"mobileFlow\", "
536     "\"eventId\": \"1241\", "
537     "\"functionalRole\": \"UNIT TEST\", "
538     "\"lastEpochMicrosec\": 1000002, "
539     "\"priority\": \"Normal\", "
540     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
541     "\"sequence\": 1241, "
542     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
543     "\"startEpochMicrosec\": 1000002, "
544     "\"version\": 1.2, "
545     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
546     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
547     "}, "
548     "\"mobileFlowFields\": {"
549     "\"flowDirection\": \"Outbound\", "
550     "\"gtpPerFlowMetrics\": {"
551     "\"avgBitErrorRate\": 12.300000, "
552     "\"avgPacketDelayVariation\": 3.120000, "
553     "\"avgPacketLatency\": 100, "
554     "\"avgReceiveThroughput\": 2100, "
555     "\"avgTransmitThroughput\": 500, "
556     "\"flowActivationEpoch\": 1470409421, "
557     "\"flowActivationMicrosec\": 987, "
558     "\"flowDeactivationEpoch\": 1470409431, "
559     "\"flowDeactivationMicrosec\": 11, "
560     "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:51 +0000\", "
561     "\"flowStatus\": \"Working\", "
562     "\"maxPacketDelayVariation\": 87, "
563     "\"numActivationFailures\": 3, "
564     "\"numBitErrors\": 17, "
565     "\"numBytesReceived\": 123654, "
566     "\"numBytesTransmitted\": 4561, "
567     "\"numDroppedPackets\": 0, "
568     "\"numL7BytesReceived\": 12, "
569     "\"numL7BytesTransmitted\": 10, "
570     "\"numLostPackets\": 1, "
571     "\"numOutOfOrderPackets\": 3, "
572     "\"numPacketErrors\": 7, "
573     "\"numPacketsReceivedExclRetrans\": 899, "
574     "\"numPacketsReceivedInclRetrans\": 901, "
575     "\"numPacketsTransmittedInclRetrans\": 302, "
576     "\"numRetries\": 6, "
577     "\"numTimeouts\": 2, "
578     "\"numTunneledL7BytesReceived\": 0, "
579     "\"roundTripTime\": 110, "
580     "\"timeToFirstByte\": 225"
581     "}, "
582     "\"ipProtocolType\": \"TCP\", "
583     "\"ipVersion\": \"IPv4\", "
584     "\"otherEndpointIpAddress\": \"2.3.4.1\", "
585     "\"otherEndpointPort\": 2341, "
586     "\"reportingEndpointIpAddr\": \"4.2.3.1\", "
587     "\"reportingEndpointPort\": 4321"
588     "}}}";
589
590   size_t json_size = 0;
591   char json_body[EVEL_MAX_JSON_BODY];
592   MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
593   EVENT_MOBILE_FLOW * mobile_flow = NULL;
594
595   /***************************************************************************/
596   /* Mobile.                                                                 */
597   /***************************************************************************/
598   evel_set_next_event_sequence(1241);
599
600   metrics = evel_new_mobile_gtp_flow_metrics(12.3,
601                                              3.12,
602                                              100,
603                                              2100,
604                                              500,
605                                              1470409421,
606                                              987,
607                                              1470409431,
608                                              11,
609                                              (time_t)1470409431,
610                                              "Working",
611                                              87,
612                                              3,
613                                              17,
614                                              123654,
615                                              4561,
616                                              0,
617                                              12,
618                                              10,
619                                              1,
620                                              3,
621                                              7,
622                                              899,
623                                              901,
624                                              302,
625                                              6,
626                                              2,
627                                              0,
628                                              110,
629                                              225);
630   assert(metrics != NULL);
631   mobile_flow = evel_new_mobile_flow("Outbound",
632                                      metrics,
633                                      "TCP",
634                                      "IPv4",
635                                      "2.3.4.1",
636                                      2341,
637                                      "4.2.3.1",
638                                      4321);
639   assert(mobile_flow != NULL);
640
641   json_size = evel_json_encode_event(
642     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
643   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
644   assert((json_size == strlen(json_body)) && "Bad size returned");
645
646   evel_free_event(mobile_flow);
647 }
648
649 void test_encode_mobile_opts()
650 {
651   char * expected =
652     "{\"event\": "
653     "{\"commonEventHeader\": {"
654     "\"domain\": \"mobileFlow\", "
655     "\"eventId\": \"1242\", "
656     "\"functionalRole\": \"UNIT TEST\", "
657     "\"lastEpochMicrosec\": 1000002, "
658     "\"priority\": \"Normal\", "
659     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
660     "\"sequence\": 1242, "
661     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
662     "\"startEpochMicrosec\": 1000002, "
663     "\"version\": 1.2, "
664     "\"eventType\": \"Mobile flow...\", "
665     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
666     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
667     "}, "
668     "\"mobileFlowFields\": {"
669     "\"flowDirection\": \"Inbound\", "
670     "\"gtpPerFlowMetrics\": {"
671     "\"avgBitErrorRate\": 132.000100, "
672     "\"avgPacketDelayVariation\": 31.200000, "
673     "\"avgPacketLatency\": 101, "
674     "\"avgReceiveThroughput\": 2101, "
675     "\"avgTransmitThroughput\": 501, "
676     "\"flowActivationEpoch\": 1470409422, "
677     "\"flowActivationMicrosec\": 988, "
678     "\"flowDeactivationEpoch\": 1470409432, "
679     "\"flowDeactivationMicrosec\": 12, "
680     "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
681     "\"flowStatus\": \"Inactive\", "
682     "\"maxPacketDelayVariation\": 88, "
683     "\"numActivationFailures\": 4, "
684     "\"numBitErrors\": 18, "
685     "\"numBytesReceived\": 123655, "
686     "\"numBytesTransmitted\": 4562, "
687     "\"numDroppedPackets\": 1, "
688     "\"numL7BytesReceived\": 13, "
689     "\"numL7BytesTransmitted\": 11, "
690     "\"numLostPackets\": 2, "
691     "\"numOutOfOrderPackets\": 4, "
692     "\"numPacketErrors\": 8, "
693     "\"numPacketsReceivedExclRetrans\": 900, "
694     "\"numPacketsReceivedInclRetrans\": 902, "
695     "\"numPacketsTransmittedInclRetrans\": 303, "
696     "\"numRetries\": 7, "
697     "\"numTimeouts\": 3, "
698     "\"numTunneledL7BytesReceived\": 1, "
699     "\"roundTripTime\": 111, "
700     "\"timeToFirstByte\": 226, "
701     "\"ipTosCountList\": ["
702     "[\"1\", 13], "
703     "[\"4\", 99], "
704     "[\"17\", 1]], "
705     "\"ipTosList\": [\"1\", \"4\", \"17\"], "
706     "\"tcpFlagList\": [\"CWR\", \"URG\"], "
707     "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
708     "\"mobileQciCosList\": [\"conversational\", \"65\"], "
709     "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
710     "\"durConnectionFailedStatus\": 12, "
711     "\"durTunnelFailedStatus\": 13, "
712     "\"flowActivatedBy\": \"Remote\", "
713     "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
714     "\"flowDeactivatedBy\": \"Remote\", "
715     "\"gtpConnectionStatus\": \"Connected\", "
716     "\"gtpTunnelStatus\": \"Not tunneling\", "
717     "\"largePacketRtt\": 80, "
718     "\"largePacketThreshold\": 600.000000, "
719     "\"maxReceiveBitRate\": 1357924680, "
720     "\"maxTransmitBitRate\": 235711, "
721     "\"numGtpEchoFailures\": 1, "
722     "\"numGtpTunnelErrors\": 4, "
723     "\"numHttpErrors\": 2"
724     "}, "
725     "\"ipProtocolType\": \"UDP\", "
726     "\"ipVersion\": \"IPv6\", "
727     "\"otherEndpointIpAddress\": \"2.3.4.2\", "
728     "\"otherEndpointPort\": 2342, "
729     "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
730     "\"reportingEndpointPort\": 4322, "
731     "\"applicationType\": \"Demo application\", "
732     "\"appProtocolType\": \"GSM\", "
733     "\"appProtocolVersion\": \"1\", "
734     "\"cid\": \"65535\", "
735     "\"connectionType\": \"S1-U\", "
736     "\"ecgi\": \"e65535\", "
737     "\"gtpProtocolType\": \"GTP-U\", "
738     "\"gtpVersion\": \"1\", "
739     "\"httpHeader\": \"http://www.something.com\", "
740     "\"imei\": \"209917614823\", "
741     "\"imsi\": \"355251/05/850925/8\", "
742     "\"lac\": \"1\", "
743     "\"mcc\": \"410\", "
744     "\"mnc\": \"04\", "
745     "\"msisdn\": \"6017123456789\", "
746     "\"otherFunctionalRole\": \"MME\", "
747     "\"rac\": \"514\", "
748     "\"radioAccessTechnology\": \"LTE\", "
749     "\"sac\": \"1\", "
750     "\"samplingAlgorithm\": 1, "
751     "\"tac\": \"2099\", "
752     "\"tunnelId\": \"Tunnel 1\", "
753     "\"vlanId\": \"15\""
754     "}}}";
755
756   size_t json_size = 0;
757   char json_body[EVEL_MAX_JSON_BODY];
758   MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
759   EVENT_MOBILE_FLOW * mobile_flow = NULL;
760
761   /***************************************************************************/
762   /* Mobile.                                                                 */
763   /***************************************************************************/
764   evel_set_next_event_sequence(1242);
765
766   metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
767                                              31.2,
768                                              101,
769                                              2101,
770                                              501,
771                                              1470409422,
772                                              988,
773                                              1470409432,
774                                              12,
775                                              (time_t)1470409432,
776                                              "Inactive",
777                                              88,
778                                              4,
779                                              18,
780                                              123655,
781                                              4562,
782                                              1,
783                                              13,
784                                              11,
785                                              2,
786                                              4,
787                                              8,
788                                              900,
789                                              902,
790                                              303,
791                                              7,
792                                              3,
793                                              1,
794                                              111,
795                                              226);
796   assert(metrics != NULL);
797
798   evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
799   evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
800   evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
801   evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
802   evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
803   evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
804   evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
805   evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
806   evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
807   evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
808   evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
809   evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
810   evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
811   evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
812   evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
813   evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
814   evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
815   evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
816   evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
817   evel_mobile_gtp_metrics_qci_cos_count_add(
818                                 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
819   evel_mobile_gtp_metrics_qci_cos_count_add(
820                                             metrics, EVEL_QCI_COS_LTE_65, 122);
821
822   mobile_flow = evel_new_mobile_flow("Inbound",
823                                      metrics,
824                                      "UDP",
825                                      "IPv6",
826                                      "2.3.4.2",
827                                      2342,
828                                      "4.2.3.2",
829                                      4322);
830   assert(mobile_flow != NULL);
831
832   evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
833   evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
834   evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
835   evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
836   evel_mobile_flow_cid_set(mobile_flow, "65535");
837   evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
838   evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
839   evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
840   evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
841   evel_mobile_flow_http_header_set(mobile_flow,
842                                    "http://www.something.com");
843   evel_mobile_flow_imei_set(mobile_flow, "209917614823");
844   evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
845   evel_mobile_flow_lac_set(mobile_flow, "1");
846   evel_mobile_flow_mcc_set(mobile_flow, "410");
847   evel_mobile_flow_mnc_set(mobile_flow, "04");
848   evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
849   evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
850   evel_mobile_flow_rac_set(mobile_flow, "514");
851   evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
852   evel_mobile_flow_sac_set(mobile_flow, "1");
853   evel_mobile_flow_samp_alg_set(mobile_flow, 1);
854   evel_mobile_flow_tac_set(mobile_flow, "2099");
855   evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
856   evel_mobile_flow_vlan_id_set(mobile_flow, "15");
857
858   json_size = evel_json_encode_event(
859     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
860   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
861   assert((json_size == strlen(json_body)) && "Bad size returned");
862
863   evel_free_event(mobile_flow);
864 }
865
866 void test_encode_report()
867 {
868   char * expected =
869     "{\"event\": "
870     "{\"commonEventHeader\": {"
871     "\"domain\": \"measurementsForVfReporting\", "
872     "\"eventId\": \"125\", "
873     "\"functionalRole\": \"UNIT TEST\", "
874     "\"lastEpochMicrosec\": 1000002, "
875     "\"priority\": \"Normal\", "
876     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
877     "\"sequence\": 125, "
878     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
879     "\"startEpochMicrosec\": 1000002, "
880     "\"version\": 1.2, "
881     "\"eventType\": \"Perf reporting...\", "
882     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
883     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
884     "}, "
885     "\"measurementsForVfReportingFields\": "
886     "{\"measurementInterval\": 1.100000, "
887     "\"featureUsageArray\": ["
888     "{\"featureIdentifier\": \"FeatureA\", "
889     "\"featureUtilization\": 123}, "
890     "{\"featureIdentifier\": \"FeatureB\", "
891     "\"featureUtilization\": 567}], "
892     "\"additionalMeasurements\": ["
893     "{\"name\": \"Group1\", "
894     "\"measurements\": ["
895     "{\"name\": \"Name1\", "
896     "\"value\": \"Value1\"}]}, "
897     "{\"name\": \"Group2\", "
898     "\"measurements\": ["
899     "{\"name\": \"Name1\", "
900     "\"value\": \"Value1\"}, "
901     "{\"name\": \"Name2\", "
902     "\"value\": \"Value2\"}]}], "
903     "\"measurementFieldsVersion\": 1.1}}}";
904
905   size_t json_size = 0;
906   char json_body[EVEL_MAX_JSON_BODY];
907   EVENT_REPORT * report = NULL;
908
909   /***************************************************************************/
910   /* Report.                                                                 */
911   /***************************************************************************/
912   evel_set_next_event_sequence(125);
913   report = evel_new_report(1.1);
914   assert(report != NULL);
915   evel_report_type_set(report, "Perf reporting...");
916   evel_report_feature_use_add(report, "FeatureA", 123);
917   evel_report_feature_use_add(report, "FeatureB", 567);
918   evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
919   evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
920   evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
921
922   json_size = evel_json_encode_event(
923     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
924   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
925   assert((json_size == strlen(json_body)) && "Bad size returned");
926
927   evel_free_event(report);
928 }
929
930 void test_encode_service()
931 {
932   test_encode_service_subset(SERVICE_NONE);
933   test_encode_service_subset(SERVICE_CODEC);
934   test_encode_service_subset(SERVICE_TRANSCODING);
935   test_encode_service_subset(SERVICE_RTCP);
936   test_encode_service_subset(SERVICE_EOC_VQM);
937   test_encode_service_subset(SERVICE_MARKER);
938 }
939
940 void test_encode_service_subset(const SERVICE_TEST service_test)
941 {
942   char * expected_start =
943     "{\"event\": "
944     "{\"commonEventHeader\": {"
945     "\"domain\": \"serviceEvents\", "
946     "\"eventId\": \"2000\", "
947     "\"functionalRole\": \"UNIT TEST\", "
948     "\"lastEpochMicrosec\": 1000002, "
949     "\"priority\": \"Normal\", "
950     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
951     "\"sequence\": 2000, "
952     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
953     "\"startEpochMicrosec\": 1000002, "
954     "\"version\": 1.2, "
955     "\"eventType\": \"Service Event\", "
956     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
957     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
958     "}, "
959     "\"serviceEventsFields\": {"
960     "\"eventInstanceIdentifier\": "
961     "{"
962     "\"vendorId\": \"vendor_x_id\", "
963     "\"eventId\": \"vendor_x_event_id\", "
964     "\"productId\": \"vendor_x_product_id\", "
965     "\"subsystemId\": \"vendor_x_subsystem_id\", "
966     "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
967     "}, "
968     "\"serviceEventsFieldsVersion\": 1.1, "
969     "\"correlator\": \"vendor_x_correlator\", "
970     "\"additionalFields\": ["
971     "{\"name\": \"Name1\", \"value\": \"Value1\"}, "
972     "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
973     "{\"name\": \"Name3\", \"value\": \"Value3\"}, "
974     "{\"name\": \"Name4\", \"value\": \"Value4\"}]";
975   char * expected_codec =
976     ", "
977     "\"codecSelected\": {"
978     "\"codec\": \"PCMA\""
979     "}";
980   char * expected_transcoding =
981     ", "
982     "\"codecSelectedTranscoding\": {"
983     "\"calleeSideCodec\": \"PCMA\", "
984     "\"callerSideCodec\": \"G729A\""
985     "}";
986   char * expected_rtcp =
987     ", "
988     "\"midCallRtcp\": {"
989     "\"rtcpData\": \"some_rtcp_data\""
990     "}";
991   char * expected_eoc_vqm =
992     ", "
993     "\"endOfCallVqmSummaries\": {"
994     "\"adjacencyName\": \"vendor_x_adjacency\", "
995     "\"endpointDescription\": \"Caller\", "
996     "\"endpointJitter\": 66, "
997     "\"endpointRtpOctetsDiscarded\": 100, "
998     "\"endpointRtpOctetsReceived\": 200, "
999     "\"endpointRtpOctetsSent\": 300, "
1000     "\"endpointRtpPacketsDiscarded\": 400, "
1001     "\"endpointRtpPacketsReceived\": 500, "
1002     "\"endpointRtpPacketsSent\": 600, "
1003     "\"localJitter\": 99, "
1004     "\"localRtpOctetsDiscarded\": 150, "
1005     "\"localRtpOctetsReceived\": 250, "
1006     "\"localRtpOctetsSent\": 350, "
1007     "\"localRtpPacketsDiscarded\": 450, "
1008     "\"localRtpPacketsReceived\": 550, "
1009     "\"localRtpPacketsSent\": 650, "
1010     "\"mosCqe\": 12.255000, "
1011     "\"packetsLost\": 157, "
1012     "\"packetLossPercent\": 0.232000, "
1013     "\"rFactor\": 11, "
1014     "\"roundTripDelay\": 15"
1015     "}";
1016   char * expected_marker =
1017     ", "
1018     "\"marker\": {"
1019     "\"phoneNumber\": \"0888888888\""
1020     "}";
1021   char * expected_end =
1022     "}}}";
1023
1024   char * expected_middle = NULL;
1025   switch (service_test)
1026   {
1027     case SERVICE_NONE:
1028       expected_middle = "";
1029       break;
1030     case SERVICE_CODEC:
1031       expected_middle = expected_codec;
1032       break;
1033     case SERVICE_TRANSCODING:
1034       expected_middle = expected_transcoding;
1035       break;
1036     case SERVICE_RTCP:
1037       expected_middle = expected_rtcp;
1038       break;
1039     case SERVICE_EOC_VQM:
1040       expected_middle = expected_eoc_vqm;
1041       break;
1042     case SERVICE_MARKER:
1043       expected_middle = expected_marker;
1044       break;
1045   }
1046   assert(expected_middle != NULL);
1047
1048   int offset = 0;
1049   char expected[EVEL_MAX_JSON_BODY];
1050   offset = snprintf(expected + offset,
1051                     EVEL_MAX_JSON_BODY - offset,
1052                     "%s%s%s",
1053                     expected_start,
1054                     expected_middle,
1055                     expected_end);
1056
1057   size_t json_size = 0;
1058   char json_body[EVEL_MAX_JSON_BODY];
1059   EVENT_SGNALING * event = NULL;
1060   evel_set_next_event_sequence(2000);
1061   event = evel_new_signaling("vendor_x_id",
1062            "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1063   assert(event != NULL);
1064   evel_signaling_type_set(event, "Signaling");
1065   evel_signaling_correlator_set(event, "vendor_x_correlator");
1066   evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1067   evel_signaling_vnfname_set(event, "vendor_x_vnf");
1068
1069   switch (service_test)
1070   {
1071     case SERVICE_NONE:
1072       break;
1073     case SERVICE_CODEC:
1074       evel_signaling_addl_info_add(event, "codec", "PCMA");
1075       break;
1076     case SERVICE_TRANSCODING:
1077       evel_signaling_addl_info_add(event, "calleecodec", "PCMA");
1078       evel_signaling_addl_info_add(event, "callercodec", "G729A");
1079       break;
1080     case SERVICE_RTCP:
1081       evel_signaling_addl_info_add(event, "rtcpdata", "abcdefgh");
1082       break;
1083     case SERVICE_EOC_VQM:
1084       evel_signaling_addl_info_add(event, "adjacency", "vendor_x");
1085       /*evel_service_adjacency_name_set(event, "vendor_x_adjacency");
1086       evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
1087       evel_service_endpoint_jitter_set(event, 66);
1088       evel_service_endpoint_rtp_oct_disc_set(event, 100);
1089       evel_service_endpoint_rtp_oct_recv_set(event, 200);
1090       evel_service_endpoint_rtp_oct_sent_set(event, 300);
1091       evel_service_endpoint_rtp_pkt_disc_set(event, 400);
1092       evel_service_endpoint_rtp_pkt_recv_set(event, 500);
1093       evel_service_endpoint_rtp_pkt_sent_set(event, 600);
1094       evel_service_local_jitter_set(event, 99);
1095       evel_service_local_rtp_oct_disc_set(event, 150);
1096       evel_service_local_rtp_oct_recv_set(event, 250);
1097       evel_service_local_rtp_oct_sent_set(event, 350);
1098       evel_service_local_rtp_pkt_disc_set(event, 450);
1099       evel_service_local_rtp_pkt_recv_set(event, 550);
1100       evel_service_local_rtp_pkt_sent_set(event, 650);
1101       evel_service_mos_cqe_set(event, 12.255);
1102       evel_service_packets_lost_set(event, 157);
1103       evel_service_packet_loss_percent_set(event, 0.232);
1104       evel_service_r_factor_set(event, 11);
1105       evel_service_round_trip_delay_set(event, 15);*/
1106       break;
1107     case SERVICE_MARKER:
1108       evel_signaling_addl_info_add(event, "service_phone", "0888888888");
1109       break;
1110   }
1111
1112   json_size = evel_json_encode_event(
1113     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1114   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
1115   assert((json_size == strlen(json_body)) && "Bad size returned");
1116
1117   evel_free_event(event);
1118 }
1119
1120 void test_encode_signaling()
1121 {
1122   char * expected =
1123     "{\"event\": "
1124     "{\"commonEventHeader\": {"
1125     "\"domain\": \"signaling\", "
1126     "\"eventId\": \"2001\", "
1127     "\"functionalRole\": \"UNIT TEST\", "
1128     "\"lastEpochMicrosec\": 1000002, "
1129     "\"priority\": \"Normal\", "
1130     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1131     "\"sequence\": 2001, "
1132     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1133     "\"startEpochMicrosec\": 1000002, "
1134     "\"version\": 1.2, "
1135     "\"eventType\": \"Signaling\", "
1136     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1137     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1138     "}, "
1139     "\"signalingFields\": {"
1140     "\"eventInstanceIdentifier\": "
1141     "{"
1142     "\"vendorId\": \"vendor_x_id\", "
1143     "\"eventId\": \"vendor_x_event_id\", "
1144     "\"productId\": \"vendor_x_product_id\", "
1145     "\"subsystemId\": \"vendor_x_subsystem_id\", "
1146     "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
1147     "}, "
1148     "\"signalingFieldsVersion\": 1.1, "
1149     "\"correlator\": \"vendor_x_correlator\", "
1150     "\"localIpAddress\": \"1.0.3.1\", "
1151     "\"localPort\": \"1031\", "
1152     "\"remoteIpAddress\": \"5.3.3.0\", "
1153     "\"remotePort\": \"5330\", "
1154     "\"compressedSip\": \"compressed_sip\", "
1155     "\"summarySip\": \"summary_sip\""
1156     "}}}";
1157
1158   size_t json_size = 0;
1159   char json_body[EVEL_MAX_JSON_BODY];
1160   EVENT_SIGNALING * event = NULL;
1161   evel_set_next_event_sequence(2001);
1162   event = evel_new_signaling("vendor_x_id",
1163            "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1164   assert(event != NULL);
1165   evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1166   evel_signaling_vnfname_set(event, "vendor_x_vnf");
1167   evel_signaling_type_set(event, "Signaling");
1168   evel_signaling_product_id_set(event, "vendor_x_product_id");
1169   evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
1170   evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
1171   evel_signaling_correlator_set(event, "vendor_x_correlator");
1172   evel_signaling_local_ip_address_set(event, "1.0.3.1");
1173   evel_signaling_local_port_set(event, "1031");
1174   evel_signaling_remote_ip_address_set(event, "5.3.3.0");
1175   evel_signaling_remote_port_set(event, "5330");
1176   evel_signaling_compressed_sip_set(event, "compressed_sip");
1177   evel_signaling_summary_sip_set(event, "summary_sip");
1178   json_size = evel_json_encode_event(
1179     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1180   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
1181   assert((json_size == strlen(json_body)) && "Bad size returned");
1182
1183   evel_free_event(event);
1184 }
1185
1186 void test_encode_state_change()
1187 {
1188   char * expected =
1189     "{\"event\": "
1190     "{\"commonEventHeader\": {"
1191     "\"domain\": \"stateChange\", "
1192     "\"eventId\": \"128\", "
1193     "\"functionalRole\": \"UNIT TEST\", "
1194     "\"lastEpochMicrosec\": 1000002, "
1195     "\"priority\": \"Normal\", "
1196     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1197     "\"sequence\": 128, "
1198     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1199     "\"startEpochMicrosec\": 1000002, "
1200     "\"version\": 1.2, "
1201     "\"eventType\": \"SC Type\", "
1202     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1203     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1204     "}, "
1205     "\"stateChangeFields\": {"
1206     "\"newState\": \"inService\", "
1207     "\"oldState\": \"outOfService\", "
1208     "\"stateInterface\": \"An Interface\", "
1209     "\"additionalFields\": ["
1210     "{\"name\": \"Name1\", "
1211     "\"value\": \"Value1\"}, "
1212     "{\"name\": \"Name2\", "
1213     "\"value\": \"Value2\"}"
1214     "], "
1215     "\"stateChangeFieldsVersion\": 1.1"
1216     "}}}";
1217
1218   size_t json_size = 0;
1219   char json_body[EVEL_MAX_JSON_BODY];
1220   EVENT_STATE_CHANGE * state_change = NULL;
1221   evel_set_next_event_sequence(128);
1222   state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
1223                                        EVEL_ENTITY_STATE_OUT_OF_SERVICE,
1224                                        "An Interface");
1225   assert(state_change != NULL);
1226   evel_state_change_type_set(state_change, "SC Type");
1227   evel_state_change_addl_field_add(state_change, "Name1", "Value1");
1228   evel_state_change_addl_field_add(state_change, "Name2", "Value2");
1229
1230   json_size = evel_json_encode_event(
1231     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
1232   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
1233   assert((json_size == strlen(json_body)) && "Bad size returned");
1234
1235   evel_free_event(state_change);
1236 }
1237
1238 void test_encode_syslog()
1239 {
1240   char * expected =
1241     "{\"event\": "
1242     "{\"commonEventHeader\": {"
1243     "\"domain\": \"syslog\", "
1244     "\"eventId\": \"126\", "
1245     "\"functionalRole\": \"UNIT TEST\", "
1246     "\"lastEpochMicrosec\": 1000002, "
1247     "\"priority\": \"Normal\", "
1248     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1249     "\"sequence\": 126, "
1250     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1251     "\"startEpochMicrosec\": 1000002, "
1252     "\"version\": 1.2, "
1253     "\"eventType\": \"SL Type\", "
1254     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1255     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1256     "}, "
1257     "\"syslogFields\": {"
1258     "\"eventSourceType\": \"virtualNetworkFunction\", "
1259     "\"syslogMsg\": \"SL Message\", "
1260     "\"syslogTag\": \"SL Tag\", "
1261     "\"syslogFieldsVersion\": 1.1, "
1262     "\"eventSourceHost\": \"SL Host\", "
1263     "\"syslogFacility\": 6, "
1264     "\"syslogProc\": \"SL Proc\", "
1265     "\"syslogProcId\": 2, "
1266     "\"syslogSData\": \"SL SDATA\", "
1267     "\"syslogVer\": 1"
1268     "}}}";
1269   size_t json_size = 0;
1270   char json_body[EVEL_MAX_JSON_BODY];
1271   EVENT_SYSLOG * syslog = NULL;
1272   evel_set_next_event_sequence(126);
1273   syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
1274                            "SL Message",
1275                            "SL Tag");
1276   assert(syslog != NULL);
1277   evel_syslog_type_set(syslog, "SL Type");
1278   evel_syslog_event_source_host_set(syslog, "SL Host");
1279   evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
1280   evel_syslog_proc_set(syslog, "SL Proc");
1281   evel_syslog_proc_id_set(syslog, 2);
1282   evel_syslog_version_set(syslog, 1);
1283   evel_syslog_s_data_set(syslog, "SL SDATA");
1284
1285   json_size = evel_json_encode_event(
1286     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
1287   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
1288   assert((json_size == strlen(json_body)) && "Bad size returned");
1289
1290   evel_free_event(syslog);
1291 }
1292
1293 void test_encode_other()
1294 {
1295   char * expected =
1296     "{\"event\": "
1297     "{\"commonEventHeader\": {"
1298     "\"domain\": \"other\", "
1299     "\"eventId\": \"129\", "
1300     "\"functionalRole\": \"UNIT TEST\", "
1301     "\"lastEpochMicrosec\": 1000002, "
1302     "\"priority\": \"Normal\", "
1303     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1304     "\"sequence\": 129, "
1305     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1306     "\"startEpochMicrosec\": 1000002, "
1307     "\"version\": 1.2, "
1308     "\"eventType\": \"Other Type\", "
1309     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1310     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1311     "}, "
1312     "\"otherFields\": ["
1313     "{\"name\": \"Other field 1\", "
1314     "\"value\": \"Other value 1\"}, "
1315     "{\"name\": \"Other field 2\", "
1316     "\"value\": \"Other value 2\"}"
1317     "]"
1318     "}}";
1319
1320   size_t json_size = 0;
1321   char json_body[EVEL_MAX_JSON_BODY];
1322   EVENT_OTHER * other = NULL;
1323   evel_set_next_event_sequence(129);
1324   other = evel_new_other();
1325   assert(other != NULL);
1326   evel_other_type_set(other, "Other Type");
1327   evel_other_field_add(other,
1328                        "Other field 1",
1329                        "Other value 1");
1330   evel_other_field_add(other,
1331                        "Other field 2",
1332                        "Other value 2");
1333
1334   json_size = evel_json_encode_event(
1335     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
1336   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
1337   assert((json_size == strlen(json_body)) && "Bad size returned");
1338
1339   evel_free_event(other);
1340 }
1341
1342 void compare_strings(char * expected,
1343                      char * actual,
1344                      int max_size,
1345                      char * description)
1346 {
1347   if (strncmp(expected, actual, max_size) != 0)
1348   {
1349     int diff = 0;
1350     while (diff < max_size)
1351     {
1352       if (expected[diff] != actual[diff])
1353       {
1354         break;
1355       }
1356       diff++;
1357     }
1358
1359     printf("Comparison Failure at Offset %d\n\n", diff);
1360     printf("Expected:\n%s\n", expected);
1361     printf("Actual:\n%s\n", actual);
1362     printf("Description: %s\n", description);
1363     assert(0);
1364   }
1365 }
1366
1367 /**************************************************************************//**
1368  * Copy a json string to a ::MEMORY_CHUNK for testing.
1369  *
1370  * @param chunk         The memory chunk.
1371  * @param string        The json string.
1372  *****************************************************************************/
1373 void copy_string_to_chunk(MEMORY_CHUNK * chunk, char * string)
1374 {
1375   int mem_size;
1376
1377   /***************************************************************************/
1378   /* Check preconditions.                                                    */
1379   /***************************************************************************/
1380   assert(chunk != NULL);
1381   assert(string != NULL);
1382
1383   mem_size = strlen(string) + 1;
1384   chunk->memory = malloc(mem_size);
1385   memcpy(chunk->memory, string, mem_size);
1386   chunk->size = mem_size;
1387 }
1388
1389 /**************************************************************************//**
1390  * Copy a json string to a ::MEMORY_CHUNK for testing.
1391  *
1392  * @param json          The JSON string.
1393  * @param post          Memory chunk to post a response.
1394  *****************************************************************************/
1395 void handle_json_response(char * json, MEMORY_CHUNK * post)
1396 {
1397   MEMORY_CHUNK chunk;
1398   post->memory = NULL;
1399   post->size = 0;
1400   copy_string_to_chunk(&chunk, json);
1401   evel_handle_event_response(&chunk, post);
1402   free(chunk.memory);
1403 }
1404
1405 /**************************************************************************//**
1406  * Test that a non-"commandList" JSON buffer leaves the throttle state off.
1407  *****************************************************************************/
1408 void test_json_response_junk()
1409 {
1410   MEMORY_CHUNK post;
1411   int domain;
1412   char * json_junk =
1413     "{"
1414     "\"junk1\": ["
1415     "\"1\", \"2\", \"3\"], "
1416     "\"junk2\": ["
1417     "\"1\", \"2\", \"3\"]"
1418     "}";
1419
1420   evel_throttle_initialize();
1421   handle_json_response(json_junk, &post);
1422
1423   /***************************************************************************/
1424   /* Check that all domains are not throttled.                               */
1425   /***************************************************************************/
1426   for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1427   {
1428     assert(evel_get_throttle_spec(domain) == NULL);
1429   }
1430
1431   /***************************************************************************/
1432   /* Check that we generated no post.                                        */
1433   /***************************************************************************/
1434   assert(post.memory == NULL);
1435
1436   evel_throttle_terminate();
1437 }
1438
1439 char * json_command_list_provide =
1440   "{"
1441   "\"commandList\": ["
1442   "{"
1443   "\"command\": {"
1444   "\"commandType\": \"provideThrottlingState\""
1445   "}"
1446   "}"
1447   "]"
1448   "}";
1449
1450 char * json_command_list_fault_clear =
1451   "{"
1452   "\"commandList\": ["
1453   "{"
1454   "\"command\": {"
1455   "\"commandType\": \"throttlingSpecification\", "
1456   "\"eventDomainThrottleSpecification\": {"
1457   "\"eventDomain\": \"fault\""
1458   "}"
1459   "}"
1460   "}"
1461   "]"
1462   "}";
1463
1464 char * json_command_list_syslog_clear =
1465   "{"
1466   "\"commandList\": ["
1467   "{"
1468   "\"command\": {"
1469   "\"commandType\": \"throttlingSpecification\", "
1470   "\"eventDomainThrottleSpecification\": {"
1471   "\"eventDomain\": \"syslog\""
1472   "}"
1473   "}"
1474   "}"
1475   "]"
1476   "}";
1477
1478 char * expected_throttle_state_normal =
1479   "{"
1480   "\"eventThrottlingState\": {"
1481   "\"eventThrottlingMode\": \"normal\"}"
1482   "}";
1483
1484 /**************************************************************************//**
1485  * Test that we can return the default throttling state.
1486  *****************************************************************************/
1487 void test_json_provide_throttle_state()
1488 {
1489   MEMORY_CHUNK post;
1490   int domain;
1491
1492   char * expected_post = expected_throttle_state_normal;
1493
1494   evel_throttle_initialize();
1495   handle_json_response(json_command_list_provide, &post);
1496
1497   /***************************************************************************/
1498   /* Check that all domains are not throttled.                               */
1499   /***************************************************************************/
1500   for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1501   {
1502     assert(evel_get_throttle_spec(domain) == NULL);
1503   }
1504
1505   /***************************************************************************/
1506   /* Check that we generated a throttling specification post.                */
1507   /***************************************************************************/
1508   assert(post.memory != NULL);
1509   compare_strings(expected_post, post.memory, strlen(expected_post),
1510                   "Throttle State Normal");
1511   free(post.memory);
1512
1513   evel_throttle_terminate();
1514 }
1515
1516 /**************************************************************************//**
1517  * Test the measurement interval handling and API.
1518  *****************************************************************************/
1519 void test_json_measurement_interval()
1520 {
1521   MEMORY_CHUNK post;
1522   char * json_command_list_interval_only =
1523     "{"
1524     "\"commandList\": ["
1525     "{"
1526     "\"command\": {"
1527     "\"measurementInterval\": 60"
1528     "}"
1529     "}"
1530     "]"
1531     "}";
1532
1533   char * json_command_list_interval_first =
1534     "{"
1535     "\"commandList\": ["
1536     "{"
1537     "\"command\": {"
1538     "\"measurementInterval\": 30, "
1539     "\"commandType\": \"measurementIntervalChange\""
1540     "}"
1541     "}"
1542     "]"
1543     "}";
1544
1545   char * json_command_list_command_first =
1546     "{"
1547     "\"commandList\": ["
1548     "{"
1549     "\"command\": {"
1550     "\"commandType\": \"measurementIntervalChange\", "
1551     "\"measurementInterval\": 60"
1552     "}"
1553     "}"
1554     "]"
1555     "}";
1556
1557   evel_throttle_initialize();
1558   assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1559
1560   /***************************************************************************/
1561   /* Check that we're not handling stuff when we shouldn't.                  */
1562   /***************************************************************************/
1563   handle_json_response(json_command_list_interval_only, &post);
1564   assert(post.memory == NULL);
1565   assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1566
1567   /***************************************************************************/
1568   /* Check that we're OK with the interval coming first.                     */
1569   /***************************************************************************/
1570   handle_json_response(json_command_list_interval_first, &post);
1571   assert(post.memory == NULL);
1572   assert(evel_get_measurement_interval() == 30);
1573
1574   /***************************************************************************/
1575   /* Check that we're OK with the command type coming first.                 */
1576   /***************************************************************************/
1577   handle_json_response(json_command_list_command_first, &post);
1578   assert(post.memory == NULL);
1579   assert(evel_get_measurement_interval() == 60);
1580
1581   evel_throttle_terminate();
1582 }
1583
1584 /**************************************************************************//**
1585  * Test a single domain, single field suppression.
1586  *****************************************************************************/
1587 void test_json_throttle_spec_field()
1588 {
1589   MEMORY_CHUNK post;
1590   int domain;
1591
1592   char * json_command_list_fault_single =
1593     "{"
1594     "\"commandList\": ["
1595     "{"
1596     "\"command\": {"
1597     "\"commandType\": \"throttlingSpecification\", "
1598     "\"eventDomainThrottleSpecification\": {"
1599     "\"eventDomain\": \"fault\", "
1600     "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1601     "}"
1602     "}"
1603     "}"
1604     "]"
1605     "}";
1606
1607   char * json_command_list_fault_double =
1608     "{"
1609     "\"commandList\": ["
1610     "{"
1611     "\"command\": {"
1612     "\"commandType\": \"throttlingSpecification\", "
1613     "\"eventDomainThrottleSpecification\": {"
1614     "\"eventDomain\": \"fault\", "
1615     "\"suppressedFieldNames\": ["
1616     "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1617     "}"
1618     "}"
1619     "}"
1620     "]"
1621     "}";
1622
1623   char * expected_post_fault_single =
1624     "{"
1625     "\"eventThrottlingState\": {"
1626     "\"eventThrottlingMode\": \"throttled\", "
1627     "\"eventDomainThrottleSpecificationList\": ["
1628     "{"
1629     "\"eventDomain\": \"fault\", "
1630     "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1631     "}"
1632     "]"
1633     "}"
1634     "}";
1635
1636   char * expected_post_fault_double =
1637     "{"
1638     "\"eventThrottlingState\": {"
1639     "\"eventThrottlingMode\": \"throttled\", "
1640     "\"eventDomainThrottleSpecificationList\": ["
1641     "{"
1642     "\"eventDomain\": \"fault\", "
1643     "\"suppressedFieldNames\": ["
1644     "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1645     "}"
1646     "]"
1647     "}"
1648     "}";
1649
1650   /***************************************************************************/
1651   /* Initialize and provide a specification with a single fault suppressed.  */
1652   /***************************************************************************/
1653   evel_throttle_initialize();
1654   handle_json_response(json_command_list_fault_single, &post);
1655
1656   /***************************************************************************/
1657   /* Check that the FAULT domain is throttled.                               */
1658   /***************************************************************************/
1659   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1660   for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1661   {
1662     if (domain != EVEL_DOMAIN_FAULT)
1663     {
1664       assert(evel_get_throttle_spec(domain) == NULL);
1665     }
1666   }
1667   assert(post.memory == NULL);
1668
1669   /***************************************************************************/
1670   /* Request and verify the throttling state.                                */
1671   /***************************************************************************/
1672   handle_json_response(json_command_list_provide, &post);
1673   assert(post.memory != NULL);
1674   compare_strings(expected_post_fault_single,
1675                   post.memory,
1676                   strlen(expected_post_fault_single),
1677                   "Fault - Single Field");
1678   free(post.memory);
1679   post.memory = NULL;
1680
1681   /***************************************************************************/
1682   /* Update a specification with two faults suppressed.                      */
1683   /***************************************************************************/
1684   handle_json_response(json_command_list_fault_double, &post);
1685
1686   /***************************************************************************/
1687   /* Check that the FAULT domain is throttled.                               */
1688   /***************************************************************************/
1689   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1690   for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1691   {
1692     if (domain != EVEL_DOMAIN_FAULT)
1693     {
1694       assert(evel_get_throttle_spec(domain) == NULL);
1695     }
1696   }
1697   assert(post.memory == NULL);
1698
1699   /***************************************************************************/
1700   /* Request and verify the throttling state.                                */
1701   /***************************************************************************/
1702   handle_json_response(json_command_list_provide, &post);
1703   assert(post.memory != NULL);
1704   compare_strings(expected_post_fault_double,
1705                   post.memory,
1706                   strlen(expected_post_fault_double),
1707                   "Fault - Double Field");
1708   free(post.memory);
1709   post.memory = NULL;
1710
1711   /***************************************************************************/
1712   /* Now clear the FAULT domain.                                             */
1713   /***************************************************************************/
1714   handle_json_response(json_command_list_fault_clear, &post);
1715   for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1716   {
1717     assert(evel_get_throttle_spec(domain) == NULL);
1718   }
1719
1720   evel_throttle_terminate();
1721 }
1722
1723 /**************************************************************************//**
1724  * Test a single domain, nv_pair suppression.
1725  *****************************************************************************/
1726 void test_json_throttle_spec_nv_pair()
1727 {
1728   MEMORY_CHUNK post;
1729   int domain;
1730
1731   char * json_command_list_fault_pair_single =
1732     "{"
1733     "\"commandList\": ["
1734     "{"
1735     "\"command\": {"
1736     "\"commandType\": \"throttlingSpecification\", "
1737     "\"eventDomainThrottleSpecification\": {"
1738     "\"eventDomain\": \"fault\", "
1739     "\"suppressedNvPairsList\": ["
1740     "{"
1741     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1742     "\"suppressedNvPairNames\": [\"name1\"]"
1743     "}"
1744     "]"
1745     "}"
1746     "}"
1747     "}"
1748     "]"
1749     "}";
1750
1751   char * json_command_list_fault_pair_double =
1752     "{"
1753     "\"commandList\": ["
1754     "{"
1755     "\"command\": {"
1756     "\"commandType\": \"throttlingSpecification\", "
1757     "\"eventDomainThrottleSpecification\": {"
1758     "\"eventDomain\": \"fault\", "
1759     "\"suppressedNvPairsList\": ["
1760     "{"
1761     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1762     "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1763     "}"
1764     "]"
1765     "}"
1766     "}"
1767     "}"
1768     "]"
1769     "}";
1770
1771   char * expected_post_fault_pair_single =
1772     "{"
1773     "\"eventThrottlingState\": {"
1774     "\"eventThrottlingMode\": \"throttled\", "
1775     "\"eventDomainThrottleSpecificationList\": ["
1776     "{"
1777     "\"eventDomain\": \"fault\", "
1778     "\"suppressedNvPairsList\": ["
1779     "{"
1780     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1781     "\"suppressedNvPairNames\": [\"name1\"]"
1782     "}"
1783     "]"
1784     "}"
1785     "]"
1786     "}"
1787     "}";
1788
1789   char * expected_post_fault_pair_double =
1790     "{"
1791     "\"eventThrottlingState\": {"
1792     "\"eventThrottlingMode\": \"throttled\", "
1793     "\"eventDomainThrottleSpecificationList\": ["
1794     "{"
1795     "\"eventDomain\": \"fault\", "
1796     "\"suppressedNvPairsList\": ["
1797     "{"
1798     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1799     "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1800     "}"
1801     "]"
1802     "}"
1803     "]"
1804     "}"
1805     "}";
1806
1807   /***************************************************************************/
1808   /* Initialize and provide a specification with a single nvpair with a      */
1809   /* single sub-field suppressed.                                            */
1810   /***************************************************************************/
1811   evel_throttle_initialize();
1812   handle_json_response(json_command_list_fault_pair_single, &post);
1813
1814   /***************************************************************************/
1815   /* Check that the FAULT domain is throttled.                               */
1816   /***************************************************************************/
1817   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1818   for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1819   {
1820     if (domain != EVEL_DOMAIN_FAULT)
1821     {
1822       assert(evel_get_throttle_spec(domain) == NULL);
1823     }
1824   }
1825   assert(post.memory == NULL);
1826
1827   /***************************************************************************/
1828   /* Request and verify the throttling state.                                */
1829   /***************************************************************************/
1830   handle_json_response(json_command_list_provide, &post);
1831   assert(post.memory != NULL);
1832   compare_strings(expected_post_fault_pair_single,
1833                   post.memory,
1834                   strlen(expected_post_fault_pair_single),
1835                   "Fault - Single Pair, Single Field");
1836   free(post.memory);
1837   post.memory = NULL;
1838
1839   /***************************************************************************/
1840   /* Update a specification with a single nvpair with two sub-fields         */
1841   /* suppressed.                                                             */
1842   /***************************************************************************/
1843   handle_json_response(json_command_list_fault_pair_double, &post);
1844
1845   /***************************************************************************/
1846   /* Check that the FAULT domain is throttled.                               */
1847   /***************************************************************************/
1848   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1849   for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1850   {
1851     if (domain != EVEL_DOMAIN_FAULT)
1852     {
1853       assert(evel_get_throttle_spec(domain) == NULL);
1854     }
1855   }
1856   assert(post.memory == NULL);
1857
1858   /***************************************************************************/
1859   /* Request and verify the throttling state.                                */
1860   /***************************************************************************/
1861   handle_json_response(json_command_list_provide, &post);
1862   assert(post.memory != NULL);
1863   compare_strings(expected_post_fault_pair_double,
1864                   post.memory,
1865                   strlen(expected_post_fault_pair_double),
1866                   "Fault - Double Field");
1867   free(post.memory);
1868   post.memory = NULL;
1869
1870   /***************************************************************************/
1871   /* Now clear the FAULT domain.                                             */
1872   /***************************************************************************/
1873   handle_json_response(json_command_list_fault_clear, &post);
1874   for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1875   {
1876     assert(evel_get_throttle_spec(domain) == NULL);
1877   }
1878
1879   evel_throttle_terminate();
1880 }
1881
1882 /**************************************************************************//**
1883  * Test two domains, nv_pair suppression.
1884  *****************************************************************************/
1885 void test_json_throttle_spec_two_domains()
1886 {
1887   MEMORY_CHUNK post;
1888   int domain;
1889
1890   char * json_command_list_two_domains =
1891     "{"
1892     "\"commandList\": ["
1893     "{"
1894     "\"command\": {"
1895     "\"commandType\": \"throttlingSpecification\", "
1896     "\"eventDomainThrottleSpecification\": {"
1897     "\"eventDomain\": \"fault\", "
1898     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1899     "\"suppressedNvPairsList\": ["
1900     "{"
1901     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1902     "\"suppressedNvPairNames\": [\"name1\"]"
1903     "}]}}}, "
1904     "{"
1905     "\"command\": {"
1906     "\"commandType\": \"throttlingSpecification\", "
1907     "\"eventDomainThrottleSpecification\": {"
1908     "\"eventDomain\": \"syslog\", "
1909     "\"suppressedFieldNames\": [\"syslogProcId\"], "
1910     "\"suppressedNvPairsList\": ["
1911     "{"
1912     "\"nvPairFieldName\": \"additionalFields\", "
1913     "\"suppressedNvPairNames\": [\"name1\"]"
1914     "}]}}}"
1915     "]"
1916     "}";
1917
1918   char * expected_post_two_domains =
1919     "{"
1920     "\"eventThrottlingState\": {"
1921     "\"eventThrottlingMode\": \"throttled\", "
1922     "\"eventDomainThrottleSpecificationList\": ["
1923     "{"
1924     "\"eventDomain\": \"fault\", "
1925     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1926     "\"suppressedNvPairsList\": ["
1927     "{"
1928     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1929     "\"suppressedNvPairNames\": [\"name1\"]"
1930     "}]}, "
1931     "{"
1932     "\"eventDomain\": \"syslog\", "
1933     "\"suppressedFieldNames\": [\"syslogProcId\"], "
1934     "\"suppressedNvPairsList\": ["
1935     "{"
1936     "\"nvPairFieldName\": \"additionalFields\", "
1937     "\"suppressedNvPairNames\": [\"name1\"]"
1938     "}]}"
1939     "]"
1940     "}"
1941     "}";
1942
1943   /***************************************************************************/
1944   /* Initialize and provide a specification with a single nvpair with a      */
1945   /* single sub-field suppressed.                                            */
1946   /***************************************************************************/
1947   evel_throttle_initialize();
1948   handle_json_response(json_command_list_two_domains, &post);
1949
1950   /***************************************************************************/
1951   /* Check that the FAULT and SYSLOG domains are throttled.                  */
1952   /***************************************************************************/
1953   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1954   assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1955   for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1956   {
1957     if ((domain != EVEL_DOMAIN_FAULT) && (domain != EVEL_DOMAIN_SYSLOG))
1958     {
1959       assert(evel_get_throttle_spec(domain) == NULL);
1960     }
1961   }
1962   assert(post.memory == NULL);
1963
1964   /***************************************************************************/
1965   /* Request and verify the throttling state.                                */
1966   /***************************************************************************/
1967   handle_json_response(json_command_list_provide, &post);
1968   assert(post.memory != NULL);
1969   compare_strings(expected_post_two_domains,
1970                   post.memory,
1971                   strlen(expected_post_two_domains),
1972                   "Fault - Two Domains");
1973   free(post.memory);
1974   post.memory = NULL;
1975
1976   /***************************************************************************/
1977   /* Now clear the FAULT and SYSLOG domains.                                 */
1978   /***************************************************************************/
1979   handle_json_response(json_command_list_fault_clear, &post);
1980   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
1981   assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1982   handle_json_response(json_command_list_syslog_clear, &post);
1983   for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1984   {
1985     assert(evel_get_throttle_spec(domain) == NULL);
1986   }
1987
1988   evel_throttle_terminate();
1989 }
1990
1991 /**************************************************************************//**
1992  * Test bad command type.
1993  *****************************************************************************/
1994 void test_json_throttle_spec_bad_command_type()
1995 {
1996   MEMORY_CHUNK post;
1997   int domain;
1998
1999   /***************************************************************************/
2000   /* Search for "dodgy" in the JSON, and you will see the dodgy bits we're   */
2001   /* handling in these tests.                                                */
2002   /***************************************************************************/
2003   #define NUM_BAD_COMMANDS 8
2004   char * json_command_list_dodgy_command =
2005     "{"
2006     "\"commandList\": ["
2007     "{"
2008     "\"command\": {"
2009     "\"commandType\": \"dodgyCommand\", "
2010     "\"eventDomainThrottleSpecification\": {"
2011     "\"eventDomain\": \"fault\", "
2012     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2013     "\"suppressedNvPairsList\": ["
2014     "{"
2015     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2016     "\"suppressedNvPairNames\": [\"name1\"]"
2017     "}]}}}"
2018     "]"
2019     "}";
2020
2021   char * json_command_list_dodgy_spec =
2022     "{"
2023     "\"commandList\": ["
2024     "{"
2025     "\"command\": {"
2026     "\"commandType\": \"throttlingSpecification\", "
2027     "\"dodgyEventDomainThrottleSpecification\": {"
2028     "\"eventDomain\": \"fault\", "
2029     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2030     "\"suppressedNvPairsList\": ["
2031     "{"
2032     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2033     "\"suppressedNvPairNames\": [\"name1\"]"
2034     "}]}}}"
2035     "]"
2036     "}";
2037
2038   char * json_command_list_dodgy_event_domain_key =
2039     "{"
2040     "\"commandList\": ["
2041     "{"
2042     "\"command\": {"
2043     "\"commandType\": \"throttlingSpecification\", "
2044     "\"eventDomainThrottleSpecification\": {"
2045     "\"dodgyEventDomainKey\": \"fault\", "
2046     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2047     "\"suppressedNvPairsList\": ["
2048     "{"
2049     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2050     "\"suppressedNvPairNames\": [\"name1\"]"
2051     "}]}}}"
2052     "]"
2053     "}";
2054
2055   char * json_command_list_dodgy_event_domain =
2056     "{"
2057     "\"commandList\": ["
2058     "{"
2059     "\"command\": {"
2060     "\"commandType\": \"throttlingSpecification\", "
2061     "\"eventDomainThrottleSpecification\": {"
2062     "\"eventDomain\": \"dodgyEventDomain\", "
2063     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2064     "\"suppressedNvPairsList\": ["
2065     "{"
2066     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2067     "\"suppressedNvPairNames\": [\"name1\"]"
2068     "}]}}}"
2069     "]"
2070     "}";
2071
2072   char * json_command_list_dodgy_field_names_key =
2073     "{"
2074     "\"commandList\": ["
2075     "{"
2076     "\"command\": {"
2077     "\"commandType\": \"throttlingSpecification\", "
2078     "\"eventDomainThrottleSpecification\": {"
2079     "\"eventDomain\": \"fault\", "
2080     "\"suppressedNvPairsList\": ["
2081     "{"
2082     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2083     "\"suppressedNvPairNames\": [\"name1\"]"
2084     "}]}}}"
2085     "]"
2086     "}";
2087
2088   char * json_command_list_dodgy_pair_names_list_key =
2089     "{"
2090     "\"commandList\": ["
2091     "{"
2092     "\"command\": {"
2093     "\"commandType\": \"throttlingSpecification\", "
2094     "\"eventDomainThrottleSpecification\": {"
2095     "\"eventDomain\": \"fault\", "
2096     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2097     "\"dodgySuppressedNvPairsListKey\": ["
2098     "{"
2099     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2100     "\"suppressedNvPairNames\": [\"name1\"]"
2101     "}]}}}"
2102     "]"
2103     "}";
2104
2105   char * json_command_list_dodgy_pair_field_name_key =
2106     "{"
2107     "\"commandList\": ["
2108     "{"
2109     "\"command\": {"
2110     "\"commandType\": \"throttlingSpecification\", "
2111     "\"eventDomainThrottleSpecification\": {"
2112     "\"eventDomain\": \"fault\", "
2113     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2114     "\"suppressedNvPairsList\": ["
2115     "{"
2116     "\"dodgyNvPairFieldNameKey\": \"alarmAdditionalInformation\", "
2117     "\"suppressedNvPairNames\": [\"name1\"]"
2118     "}]}}}"
2119     "]"
2120     "}";
2121
2122   char * json_command_list_dodgy_pair_names_key =
2123     "{"
2124     "\"commandList\": ["
2125     "{"
2126     "\"command\": {"
2127     "\"commandType\": \"throttlingSpecification\", "
2128     "\"eventDomainThrottleSpecification\": {"
2129     "\"eventDomain\": \"fault\", "
2130     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2131     "\"suppressedNvPairsList\": ["
2132     "{"
2133     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2134     "\"dodgySuppressedNvPairNamesKey\": [\"name1\"]"
2135     "}]}}}"
2136     "]"
2137     "}";
2138
2139   char * json_command_list_dodgy_depth =
2140     "{"
2141     "\"commandList\": ["
2142     "{"
2143     "\"command\": {"
2144     "\"commandType\": \"throttlingSpecification\", "
2145     "\"eventDomainThrottleSpecification\": {"
2146     "\"eventDomain\": \"fault\", "
2147     "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2148     "\"suppressedNvPairsList\": ["
2149     "{"
2150     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2151     "\"dodgySuppressedNvPairNamesKey\": "
2152     "[\"name1\", [[[[[[[[]]]]]]]]]"
2153     "}]}}}"
2154     "]"
2155     "}";
2156
2157   char * expected_throttle_state_dodgy_field_names_key =
2158     "{"
2159     "\"eventThrottlingState\": {"
2160     "\"eventThrottlingMode\": \"throttled\", "
2161     "\"eventDomainThrottleSpecificationList\": ["
2162     "{"
2163     "\"eventDomain\": \"fault\", "
2164     "\"suppressedNvPairsList\": ["
2165     "{"
2166     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2167     "\"suppressedNvPairNames\": [\"name1\"]"
2168     "}]}"
2169     "]"
2170     "}"
2171     "}";
2172
2173   char * expected_throttle_state_dodgy_pair_names_list_key =
2174     "{"
2175     "\"eventThrottlingState\": {"
2176     "\"eventThrottlingMode\": \"throttled\", "
2177     "\"eventDomainThrottleSpecificationList\": ["
2178     "{"
2179     "\"eventDomain\": \"fault\", "
2180     "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2181     "}"
2182     "]"
2183     "}"
2184     "}";
2185
2186   char * expected_throttle_state_dodgy_pair_field_name_key =
2187     "{"
2188     "\"eventThrottlingState\": {"
2189     "\"eventThrottlingMode\": \"throttled\", "
2190     "\"eventDomainThrottleSpecificationList\": ["
2191     "{"
2192     "\"eventDomain\": \"fault\", "
2193     "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2194     "}"
2195     "]"
2196     "}"
2197     "}";
2198
2199   char * expected_throttle_state_dodgy_pair_names_key =
2200     "{"
2201     "\"eventThrottlingState\": {"
2202     "\"eventThrottlingMode\": \"throttled\", "
2203     "\"eventDomainThrottleSpecificationList\": ["
2204     "{"
2205     "\"eventDomain\": \"fault\", "
2206     "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2207     "}"
2208     "]"
2209     "}"
2210     "}";
2211
2212   char * json_command_lists[] = {
2213     json_command_list_dodgy_command,
2214     json_command_list_dodgy_spec,
2215     json_command_list_dodgy_event_domain_key,
2216     json_command_list_dodgy_event_domain,
2217     json_command_list_dodgy_depth,
2218     json_command_list_dodgy_field_names_key,
2219     json_command_list_dodgy_pair_names_list_key,
2220     json_command_list_dodgy_pair_field_name_key,
2221     json_command_list_dodgy_pair_names_key
2222   };
2223
2224   char * expected_posts[] = {
2225     expected_throttle_state_normal,
2226     expected_throttle_state_normal,
2227     expected_throttle_state_normal,
2228     expected_throttle_state_normal,
2229     expected_throttle_state_normal,
2230     expected_throttle_state_dodgy_field_names_key,
2231     expected_throttle_state_dodgy_pair_names_list_key,
2232     expected_throttle_state_dodgy_pair_field_name_key,
2233     expected_throttle_state_dodgy_pair_names_key
2234    };
2235
2236   const int num_commands =
2237     sizeof(json_command_lists) / sizeof(json_command_lists[0]);
2238   const int num_posts =
2239     sizeof(expected_posts) / sizeof(expected_posts[0]);
2240   assert(num_commands == num_posts);
2241
2242   /***************************************************************************/
2243   /* Initialize and provide a specification with a single nvpair with a      */
2244   /* single sub-field suppressed.                                            */
2245   /***************************************************************************/
2246   evel_throttle_initialize();
2247
2248   int ii;
2249   for (ii = 0; ii < num_commands; ii++)
2250   {
2251     EVEL_DEBUG("Testing commandList[%d] = %s\n", ii, json_command_lists[ii]);
2252     handle_json_response(json_command_lists[ii], &post);
2253
2254     /*************************************************************************/
2255     /* Check that throttling is in a normal state - because we ignored the   */
2256     /* command / .....                                                       */
2257     /*************************************************************************/
2258     for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
2259     {
2260       assert(evel_get_throttle_spec(domain) == NULL);
2261     }
2262     if (expected_posts[ii] == expected_throttle_state_normal)
2263     {
2264       assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
2265     }
2266     else
2267     {
2268       assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2269     }
2270     assert(post.memory == NULL);
2271
2272     /*************************************************************************/
2273     /* Request and verify the throttling state.                              */
2274     /*************************************************************************/
2275     handle_json_response(json_command_list_provide, &post);
2276     assert(post.memory != NULL);
2277     compare_strings(expected_posts[ii],
2278                     post.memory,
2279                     strlen(expected_posts[ii]),
2280                     "Throttle State Normal");
2281     free(post.memory);
2282     post.memory = NULL;
2283   }
2284
2285   evel_throttle_terminate();
2286 }
2287
2288 void test_encode_fault_throttled()
2289 {
2290   MEMORY_CHUNK post;
2291
2292   /***************************************************************************/
2293   /* We also test suppression of the event header parameters here.           */
2294   /***************************************************************************/
2295   char * json_command_list =
2296     "{"
2297     "\"commandList\": ["
2298     "{"
2299     "\"command\": {"
2300     "\"commandType\": \"throttlingSpecification\", "
2301     "\"eventDomainThrottleSpecification\": {"
2302     "\"eventDomain\": \"fault\", "
2303     "\"suppressedFieldNames\": ["
2304     "\"alarmInterfaceA\", "
2305     "\"eventType\", "
2306     "\"reportingEntityId\", "
2307     "\"sourceId\"], "
2308     "\"suppressedNvPairsList\": ["
2309     "{"
2310     "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2311     "\"suppressedNvPairNames\": [\"name3\", \"name4\"]"
2312     "}]}}}"
2313     "]"
2314     "}";
2315
2316   char * expected =
2317     "{\"event\": {"
2318     "\"commonEventHeader\": {"
2319     "\"domain\": \"fault\", "
2320     "\"eventId\": \"122\", "
2321     "\"functionalRole\": \"UNIT TEST\", "
2322     "\"lastEpochMicrosec\": 1000002, "
2323     "\"priority\": \"Normal\", "
2324     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2325     "\"sequence\": 122, "
2326     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2327     "\"startEpochMicrosec\": 1000002, "
2328     "\"version\": 1.2"
2329     "}, "
2330     "\"faultFields\": {"
2331     "\"alarmCondition\": \"My alarm condition\", "
2332     "\"eventSeverity\": \"MAJOR\", "
2333     "\"eventSourceType\": \"other\", "
2334     "\"specificProblem\": \"It broke very badly\", "
2335     "\"vfStatus\": \"Active\", "
2336     "\"faultFieldsVersion\": 1.1, "
2337     "\"alarmAdditionalInformation\": ["
2338     "{\"name\": \"name1\", "
2339     "\"value\": \"value1\"}, "
2340     "{\"name\": \"name2\", "
2341     "\"value\": \"value2\"}]"
2342     "}}}";
2343
2344   /***************************************************************************/
2345   /* Initialize and provide a specification with a single fault suppressed.  */
2346   /***************************************************************************/
2347   evel_throttle_initialize();
2348   handle_json_response(json_command_list, &post);
2349
2350   /***************************************************************************/
2351   /* Check that the domain is throttled.                                     */
2352   /***************************************************************************/
2353   assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2354   assert(post.memory == NULL);
2355
2356   size_t json_size = 0;
2357   char json_body[EVEL_MAX_JSON_BODY];
2358   evel_set_next_event_sequence(122);
2359   EVENT_FAULT * fault = evel_new_fault("My alarm condition",
2360                                        "It broke very badly",
2361                                        EVEL_PRIORITY_NORMAL,
2362                                        EVEL_SEVERITY_MAJOR,
2363                                         EVEL_SOURCE_HOST,
2364                           EVEL_VF_STATUS_PREP_TERMINATE);
2365   assert(fault != NULL);
2366   evel_fault_type_set(fault, "Bad things happen...");
2367   evel_fault_addl_info_add(fault, "name1", "value1");
2368   evel_fault_addl_info_add(fault, "name2", "value2");
2369
2370   /***************************************************************************/
2371   /* Suppressed fields.                                                      */
2372   /***************************************************************************/
2373   evel_fault_interface_set(fault, "My Interface Card");
2374   evel_fault_addl_info_add(fault, "name3", "value3");
2375   evel_fault_addl_info_add(fault, "name4", "value4");
2376
2377   json_size = evel_json_encode_event(
2378     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
2379   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
2380   assert((json_size == strlen(json_body)) && "Bad size returned");
2381
2382   evel_free_event(fault);
2383   evel_throttle_terminate();
2384 }
2385
2386 void test_encode_measurement_throttled()
2387 {
2388   MEMORY_CHUNK post;
2389
2390   /***************************************************************************/
2391   /* We also test suppression of the event header parameters here.           */
2392   /***************************************************************************/
2393   char * json_command_list =
2394     "{"
2395     "\"commandList\": ["
2396     "{"
2397     "\"command\": {"
2398     "\"commandType\": \"throttlingSpecification\", "
2399     "\"eventDomainThrottleSpecification\": {"
2400     "\"eventDomain\": \"measurementsForVfScaling\", "
2401     "\"suppressedFieldNames\": ["
2402     "\"errors\", "
2403     "\"vnfcScalingMetric\", "
2404     "\"numberOfMediaPortsInUse\", "
2405     "\"aggregateCpuUsage\", "
2406     "\"requestRate\", "
2407     "\"memoryUsed\", "
2408     "\"memoryConfigured\", "
2409     "\"meanRequestLatency\", "
2410     "\"latencyDistribution\", "
2411     "\"concurrentSessions\", "
2412     "\"configuredEntities\", "
2413     "\"eventType\", "
2414     "\"reportingEntityId\", "
2415     "\"sourceId\"], "
2416     "\"suppressedNvPairsList\": ["
2417     "{"
2418     "\"nvPairFieldName\": \"cpuUsageArray\", "
2419     "\"suppressedNvPairNames\": [\"cpu3\", \"cpu4\"]"
2420     "}, "
2421     "{"
2422     "\"nvPairFieldName\": \"filesystemUsageArray\", "
2423     "\"suppressedNvPairNames\": [\"00-11-22\", \"33-44-55\"]"
2424     "}, "
2425     "{"
2426     "\"nvPairFieldName\": \"vNicUsageArray\", "
2427     "\"suppressedNvPairNames\": [\"eth1\", \"eth0\"]"
2428     "}, "
2429     "{"
2430     "\"nvPairFieldName\": \"featureUsageArray\", "
2431     "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2432     "},"
2433     "{"
2434     "\"nvPairFieldName\": \"codecUsageArray\", "
2435     "\"suppressedNvPairNames\": [\"G729ab\"]"
2436     "},"
2437     "{"
2438     "\"nvPairFieldName\": \"additionalMeasurements\", "
2439     "\"suppressedNvPairNames\": [\"Group2\"]"
2440     "}"
2441     "]}}}"
2442     "]"
2443     "}";
2444
2445   char * expected =
2446     "{\"event\": "
2447     "{\"commonEventHeader\": {"
2448     "\"domain\": \"measurementsForVfScaling\", "
2449     "\"eventId\": \"123\", "
2450     "\"functionalRole\": \"UNIT TEST\", "
2451     "\"lastEpochMicrosec\": 1000002, "
2452     "\"priority\": \"Normal\", "
2453     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2454     "\"sequence\": 123, "
2455     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2456     "\"startEpochMicrosec\": 1000002, "
2457     "\"version\": 1.2"
2458     "}, "
2459     "\"measurementsForVfScalingFields\": "
2460     "{"
2461     "\"measurementInterval\": 5.500000, "
2462     "\"cpuUsageArray\": ["
2463     "{\"cpuIdentifier\": \"cpu1\", "
2464     "\"percentUsage\": 11.110000}, "
2465     "{\"cpuIdentifier\": \"cpu2\", "
2466     "\"percentUsage\": 22.220000}], "
2467     "\"filesystemUsageArray\": ["
2468     "{\"blockConfigured\": 500.110000, "
2469     "\"blockIops\": 77, "
2470     "\"blockUsed\": 500.220000, "
2471     "\"ephemeralConfigured\": 500.110000, "
2472     "\"ephemeralIops\": 88, "
2473     "\"ephemeralUsed\": 600.220000, "
2474     "\"filesystemName\": \"66-77-88\"}], "
2475     "\"featureUsageArray\": ["
2476     "{\"featureIdentifier\": \"FeatureA\", "
2477     "\"featureUtilization\": 123}], "
2478     "\"codecUsageArray\": ["
2479     "{\"codecIdentifier\": \"G711a\", "
2480     "\"numberInUse\": 91}], "
2481     "\"additionalMeasurements\": ["
2482     "{\"name\": \"Group1\", "
2483     "\"measurements\": ["
2484     "{\"name\": \"Name1\", "
2485     "\"value\": \"Value1\"}]}], "
2486     "\"measurementsForVfScalingVersion\": 1.1}}}";
2487      MEASUREMENT_CPU_USE *cpu_use;
2488
2489   /***************************************************************************/
2490   /* Initialize and provide a specification with a single fault suppressed.  */
2491   /***************************************************************************/
2492   evel_throttle_initialize();
2493   handle_json_response(json_command_list, &post);
2494
2495   /***************************************************************************/
2496   /* Check that the domain is throttled.                                     */
2497   /***************************************************************************/
2498   assert(evel_get_throttle_spec(EVEL_DOMAIN_MEASUREMENT) != NULL);
2499   assert(post.memory == NULL);
2500
2501   size_t json_size = 0;
2502   char json_body[EVEL_MAX_JSON_BODY];
2503   evel_set_next_event_sequence(123);
2504   EVENT_MEASUREMENT * measurement = evel_new_measurement(5.5);
2505   MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
2506   MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
2507   assert(measurement != NULL);
2508
2509   evel_measurement_type_set(measurement, "Perf management...");
2510   evel_measurement_conc_sess_set(measurement, 1);
2511   evel_measurement_cfg_ents_set(measurement, 2);
2512   evel_measurement_mean_req_lat_set(measurement, 4.4);
2513   evel_measurement_mem_cfg_set(measurement, 6.6);
2514   evel_measurement_mem_used_set(measurement, 3.3);
2515   evel_measurement_request_rate_set(measurement, 7);
2516
2517   cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
2518   evel_measurement_cpu_use_idle_set(cpu_use,22.22);
2519   evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2520   evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2521   evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2522   evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2523   evel_measurement_cpu_use_system_set(cpu_use,77.77);
2524   evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2525   evel_measurement_cpu_use_wait_set(cpu_use,99.99);
2526
2527   cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
2528   evel_measurement_cpu_use_idle_set(cpu_use,12.22);
2529   evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2530   evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2531   evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2532   evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2533   evel_measurement_cpu_use_system_set(cpu_use,77.77);
2534   evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2535   evel_measurement_cpu_use_wait_set(cpu_use,19.99);
2536
2537   evel_measurement_fsys_use_add(measurement, "00-11-22",
2538                                 100.11, 100.22, 33,
2539                                 200.11, 200.22, 44);
2540   evel_measurement_fsys_use_add(measurement, "33-44-55",
2541                                 300.11, 300.22, 55,
2542                                 400.11, 400.22, 66);
2543   evel_measurement_fsys_use_add(measurement, "66-77-88",
2544                                 500.11, 500.22, 77,
2545                                 600.11, 600.22, 88);
2546
2547   bucket = evel_new_meas_latency_bucket(20);
2548   evel_meas_latency_bucket_add(measurement, bucket);
2549
2550   bucket = evel_new_meas_latency_bucket(30);
2551   evel_meas_latency_bucket_low_end_set(bucket, 10.0);
2552   evel_meas_latency_bucket_high_end_set(bucket, 20.0);
2553   evel_meas_latency_bucket_add(measurement, bucket);
2554
2555   vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
2556   evel_vnic_use_bcast_pkt_in_set(vnic_use, 1);
2557   evel_vnic_use_bcast_pkt_out_set(vnic_use, 2);
2558   evel_vnic_use_mcast_pkt_in_set(vnic_use, 5);
2559   evel_vnic_use_mcast_pkt_out_set(vnic_use, 6);
2560   evel_vnic_use_ucast_pkt_in_set(vnic_use, 7);
2561   evel_vnic_use_ucast_pkt_out_set(vnic_use, 8);
2562   evel_meas_vnic_use_add(measurement, vnic_use);
2563
2564   vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
2565   evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
2566   evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
2567   evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
2568   evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
2569   evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
2570   evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
2571   evel_meas_vnic_use_add(measurement, vnic_use);
2572
2573   evel_measurement_errors_set(measurement, 1, 0, 2, 1);
2574   evel_measurement_feature_use_add(measurement, "FeatureA", 123);
2575   evel_measurement_feature_use_add(measurement, "FeatureB", 567);
2576   evel_measurement_codec_use_add(measurement, "G711a", 91);
2577   evel_measurement_codec_use_add(measurement, "G729ab", 92);
2578   evel_measurement_media_port_use_set(measurement, 1234);
2579   evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
2580   evel_measurement_custom_measurement_add(measurement,
2581                                           "Group1", "Name1", "Value1");
2582   evel_measurement_custom_measurement_add(measurement,
2583                                           "Group2", "Name1", "Value1");
2584   evel_measurement_custom_measurement_add(measurement,
2585                                           "Group2", "Name2", "Value2");
2586
2587   json_size = evel_json_encode_event(
2588     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
2589   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
2590   assert((json_size == strlen(json_body)) && "Bad size returned");
2591
2592   evel_free_event(measurement);
2593   evel_throttle_terminate();
2594 }
2595
2596 void test_encode_mobile_throttled()
2597 {
2598   MEMORY_CHUNK post;
2599
2600   /***************************************************************************/
2601   /* We also test suppression of the event header parameters here.           */
2602   /***************************************************************************/
2603   char * json_command_list =
2604     "{"
2605     "\"commandList\": ["
2606     "{"
2607     "\"command\": {"
2608     "\"commandType\": \"throttlingSpecification\", "
2609     "\"eventDomainThrottleSpecification\": {"
2610     "\"eventDomain\": \"mobileFlow\", "
2611     "\"suppressedFieldNames\": ["
2612     "\"applicationType\", "
2613     "\"appProtocolType\", "
2614     "\"appProtocolVersion\", "
2615     "\"cid\", "
2616     "\"connectionType\", "
2617     "\"ecgi\", "
2618     "\"gtpProtocolType\", "
2619     "\"gtpVersion\", "
2620     "\"httpHeader\", "
2621     "\"imei\", "
2622     "\"imsi\", "
2623     "\"lac\", "
2624     "\"mcc\", "
2625     "\"mnc\", "
2626     "\"msisdn\", "
2627     "\"otherFunctionalRole\", "
2628     "\"rac\", "
2629     "\"radioAccessTechnology\", "
2630     "\"sac\", "
2631     "\"samplingAlgorithm\", "
2632     "\"tac\", "
2633     "\"tunnelId\", "
2634     "\"vlanId\", "
2635     "\"eventType\", "
2636     "\"reportingEntityId\", "
2637     "\"sourceId\"], "
2638     "\"suppressedNvPairsList\": ["
2639     "]}}}"
2640     "]"
2641     "}";
2642
2643   char * expected =
2644     "{\"event\": "
2645     "{\"commonEventHeader\": {"
2646     "\"domain\": \"mobileFlow\", "
2647     "\"eventId\": \"1242\", "
2648     "\"functionalRole\": \"UNIT TEST\", "
2649     "\"lastEpochMicrosec\": 1000002, "
2650     "\"priority\": \"Normal\", "
2651     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2652     "\"sequence\": 1242, "
2653     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2654     "\"startEpochMicrosec\": 1000002, "
2655     "\"version\": 1.2"
2656     "}, "
2657     "\"mobileFlowFields\": {"
2658     "\"flowDirection\": \"Inbound\", "
2659     "\"gtpPerFlowMetrics\": {"
2660     "\"avgBitErrorRate\": 132.000100, "
2661     "\"avgPacketDelayVariation\": 31.200000, "
2662     "\"avgPacketLatency\": 101, "
2663     "\"avgReceiveThroughput\": 2101, "
2664     "\"avgTransmitThroughput\": 501, "
2665     "\"flowActivationEpoch\": 1470409422, "
2666     "\"flowActivationMicrosec\": 988, "
2667     "\"flowDeactivationEpoch\": 1470409432, "
2668     "\"flowDeactivationMicrosec\": 12, "
2669     "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
2670     "\"flowStatus\": \"Inactive\", "
2671     "\"maxPacketDelayVariation\": 88, "
2672     "\"numActivationFailures\": 4, "
2673     "\"numBitErrors\": 18, "
2674     "\"numBytesReceived\": 123655, "
2675     "\"numBytesTransmitted\": 4562, "
2676     "\"numDroppedPackets\": 1, "
2677     "\"numL7BytesReceived\": 13, "
2678     "\"numL7BytesTransmitted\": 11, "
2679     "\"numLostPackets\": 2, "
2680     "\"numOutOfOrderPackets\": 4, "
2681     "\"numPacketErrors\": 8, "
2682     "\"numPacketsReceivedExclRetrans\": 900, "
2683     "\"numPacketsReceivedInclRetrans\": 902, "
2684     "\"numPacketsTransmittedInclRetrans\": 303, "
2685     "\"numRetries\": 7, "
2686     "\"numTimeouts\": 3, "
2687     "\"numTunneledL7BytesReceived\": 1, "
2688     "\"roundTripTime\": 111, "
2689     "\"timeToFirstByte\": 226, "
2690     "\"ipTosCountList\": ["
2691     "[\"1\", 13], "
2692     "[\"4\", 99], "
2693     "[\"17\", 1]], "
2694     "\"ipTosList\": [\"1\", \"4\", \"17\"], "
2695     "\"tcpFlagList\": [\"CWR\", \"URG\"], "
2696     "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
2697     "\"mobileQciCosList\": [\"conversational\", \"65\"], "
2698     "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
2699     "\"durConnectionFailedStatus\": 12, "
2700     "\"durTunnelFailedStatus\": 13, "
2701     "\"flowActivatedBy\": \"Remote\", "
2702     "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
2703     "\"flowDeactivatedBy\": \"Remote\", "
2704     "\"gtpConnectionStatus\": \"Connected\", "
2705     "\"gtpTunnelStatus\": \"Not tunneling\", "
2706     "\"largePacketRtt\": 80, "
2707     "\"largePacketThreshold\": 600.000000, "
2708     "\"maxReceiveBitRate\": 1357924680, "
2709     "\"maxTransmitBitRate\": 235711, "
2710     "\"numGtpEchoFailures\": 1, "
2711     "\"numGtpTunnelErrors\": 4, "
2712     "\"numHttpErrors\": 2"
2713     "}, "
2714     "\"ipProtocolType\": \"UDP\", "
2715     "\"ipVersion\": \"IPv6\", "
2716     "\"otherEndpointIpAddress\": \"2.3.4.2\", "
2717     "\"otherEndpointPort\": 2342, "
2718     "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
2719     "\"reportingEndpointPort\": 4322"
2720     "}}}";
2721
2722   /***************************************************************************/
2723   /* Initialize and provide a specification with a single fault suppressed.  */
2724   /***************************************************************************/
2725   evel_throttle_initialize();
2726   handle_json_response(json_command_list, &post);
2727
2728   /***************************************************************************/
2729   /* Check that the domain is throttled.                                     */
2730   /***************************************************************************/
2731   assert(evel_get_throttle_spec(EVEL_DOMAIN_MOBILE_FLOW) != NULL);
2732   assert(post.memory == NULL);
2733
2734   size_t json_size = 0;
2735   char json_body[EVEL_MAX_JSON_BODY];
2736   MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
2737   EVENT_MOBILE_FLOW * mobile_flow = NULL;
2738
2739   /***************************************************************************/
2740   /* Mobile.                                                                 */
2741   /***************************************************************************/
2742   evel_set_next_event_sequence(1242);
2743
2744   metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
2745                                              31.2,
2746                                              101,
2747                                              2101,
2748                                              501,
2749                                              1470409422,
2750                                              988,
2751                                              1470409432,
2752                                              12,
2753                                              (time_t)1470409432,
2754                                              "Inactive",
2755                                              88,
2756                                              4,
2757                                              18,
2758                                              123655,
2759                                              4562,
2760                                              1,
2761                                              13,
2762                                              11,
2763                                              2,
2764                                              4,
2765                                              8,
2766                                              900,
2767                                              902,
2768                                              303,
2769                                              7,
2770                                              3,
2771                                              1,
2772                                              111,
2773                                              226);
2774   assert(metrics != NULL);
2775
2776   evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
2777   evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
2778   evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
2779   evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
2780   evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
2781   evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
2782   evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
2783   evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
2784   evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
2785   evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
2786   evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
2787   evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
2788   evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
2789   evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
2790   evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
2791   evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
2792   evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
2793   evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
2794   evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
2795   evel_mobile_gtp_metrics_qci_cos_count_add(
2796                                 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
2797   evel_mobile_gtp_metrics_qci_cos_count_add(
2798                                             metrics, EVEL_QCI_COS_LTE_65, 122);
2799
2800   mobile_flow = evel_new_mobile_flow("Inbound",
2801                                      metrics,
2802                                      "UDP",
2803                                      "IPv6",
2804                                      "2.3.4.2",
2805                                      2342,
2806                                      "4.2.3.2",
2807                                      4322);
2808   assert(mobile_flow != NULL);
2809
2810   evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
2811   evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
2812   evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
2813   evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
2814   evel_mobile_flow_cid_set(mobile_flow, "65535");
2815   evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
2816   evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
2817   evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
2818   evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
2819   evel_mobile_flow_http_header_set(mobile_flow,
2820                                    "http://www.something.com");
2821   evel_mobile_flow_imei_set(mobile_flow, "209917614823");
2822   evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
2823   evel_mobile_flow_lac_set(mobile_flow, "1");
2824   evel_mobile_flow_mcc_set(mobile_flow, "410");
2825   evel_mobile_flow_mnc_set(mobile_flow, "04");
2826   evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
2827   evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
2828   evel_mobile_flow_rac_set(mobile_flow, "514");
2829   evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
2830   evel_mobile_flow_sac_set(mobile_flow, "1");
2831   evel_mobile_flow_samp_alg_set(mobile_flow, 1);
2832   evel_mobile_flow_tac_set(mobile_flow, "2099");
2833   evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
2834   evel_mobile_flow_vlan_id_set(mobile_flow, "15");
2835
2836   json_size = evel_json_encode_event(
2837     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
2838   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
2839   assert((json_size == strlen(json_body)) && "Bad size returned");
2840
2841   evel_free_event(mobile_flow);
2842   evel_throttle_terminate();
2843 }
2844
2845 void test_encode_other_throttled()
2846 {
2847   MEMORY_CHUNK post;
2848
2849   /***************************************************************************/
2850   /* We also test suppression of the event header parameters here.           */
2851   /***************************************************************************/
2852   char * json_command_list =
2853     "{"
2854     "\"commandList\": ["
2855     "{"
2856     "\"command\": {"
2857     "\"commandType\": \"throttlingSpecification\", "
2858     "\"eventDomainThrottleSpecification\": {"
2859     "\"eventDomain\": \"other\", "
2860     "\"suppressedFieldNames\": ["
2861     "\"eventType\", "
2862     "\"reportingEntityId\", "
2863     "\"sourceId\"], "
2864     "\"suppressedNvPairsList\": ["
2865     "]}}}"
2866     "]"
2867     "}";
2868
2869   char * expected =
2870     "{\"event\": "
2871     "{\"commonEventHeader\": {"
2872     "\"domain\": \"other\", "
2873     "\"eventId\": \"129\", "
2874     "\"functionalRole\": \"UNIT TEST\", "
2875     "\"lastEpochMicrosec\": 1000002, "
2876     "\"priority\": \"Normal\", "
2877     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2878     "\"sequence\": 129, "
2879     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2880     "\"startEpochMicrosec\": 1000002, "
2881     "\"version\": 1.2"
2882     "}, "
2883     "\"otherFields\": ["
2884     "{\"name\": \"Other field 1\", "
2885     "\"value\": \"Other value 1\"}, "
2886     "{\"name\": \"Other field 2\", "
2887     "\"value\": \"Other value 2\"}"
2888     "]"
2889     "}}";
2890
2891   /***************************************************************************/
2892   /* Initialize and provide a specification with a single fault suppressed.  */
2893   /***************************************************************************/
2894   evel_throttle_initialize();
2895   handle_json_response(json_command_list, &post);
2896
2897   /***************************************************************************/
2898   /* Check that the domain is throttled.                                     */
2899   /***************************************************************************/
2900   assert(evel_get_throttle_spec(EVEL_DOMAIN_OTHER) != NULL);
2901   assert(post.memory == NULL);
2902
2903   size_t json_size = 0;
2904   char json_body[EVEL_MAX_JSON_BODY];
2905   EVENT_OTHER * other = NULL;
2906   evel_set_next_event_sequence(129);
2907   other = evel_new_other();
2908   assert(other != NULL);
2909   evel_other_type_set(other, "Other Type");
2910   evel_other_field_add(other,
2911                        "Other field 1",
2912                        "Other value 1");
2913   evel_other_field_add(other,
2914                        "Other field 2",
2915                        "Other value 2");
2916
2917   json_size = evel_json_encode_event(
2918     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
2919   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
2920   assert((json_size == strlen(json_body)) && "Bad size returned");
2921
2922   evel_free_event(other);
2923   evel_throttle_terminate();
2924 }
2925
2926 void test_encode_report_throttled()
2927 {
2928   MEMORY_CHUNK post;
2929
2930   /***************************************************************************/
2931   /* We also test suppression of the event header parameters here.           */
2932   /***************************************************************************/
2933   char * json_command_list =
2934     "{"
2935     "\"commandList\": ["
2936     "{"
2937     "\"command\": {"
2938     "\"commandType\": \"throttlingSpecification\", "
2939     "\"eventDomainThrottleSpecification\": {"
2940     "\"eventDomain\": \"report\", "
2941     "\"suppressedFieldNames\": ["
2942     "\"eventType\", "
2943     "\"reportingEntityId\", "
2944     "\"sourceId\"], "
2945     "\"suppressedNvPairsList\": ["
2946     "{"
2947     "\"nvPairFieldName\": \"featureUsageArray\", "
2948     "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2949     "},"
2950     "{"
2951     "\"nvPairFieldName\": \"additionalMeasurements\", "
2952     "\"suppressedNvPairNames\": [\"Group2\"]"
2953     "}"
2954     "]}}}"
2955     "]"
2956     "}";
2957
2958   char * expected =
2959     "{\"event\": "
2960     "{\"commonEventHeader\": {"
2961     "\"domain\": \"measurementsForVfReporting\", "
2962     "\"eventId\": \"125\", "
2963     "\"functionalRole\": \"UNIT TEST\", "
2964     "\"lastEpochMicrosec\": 1000002, "
2965     "\"priority\": \"Normal\", "
2966     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2967     "\"sequence\": 125, "
2968     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2969     "\"startEpochMicrosec\": 1000002, "
2970     "\"version\": 1.2"
2971     "}, "
2972     "\"measurementsForVfReportingFields\": "
2973     "{\"measurementInterval\": 1.100000, "
2974     "\"featureUsageArray\": ["
2975     "{\"featureIdentifier\": \"FeatureA\", "
2976     "\"featureUtilization\": 123}], "
2977     "\"additionalMeasurements\": ["
2978     "{\"name\": \"Group1\", "
2979     "\"measurements\": ["
2980     "{\"name\": \"Name1\", "
2981     "\"value\": \"Value1\"}]}], "
2982     "\"measurementFieldsVersion\": 1.1}}}";
2983
2984   /***************************************************************************/
2985   /* Initialize and provide a specification with a single fault suppressed.  */
2986   /***************************************************************************/
2987   evel_throttle_initialize();
2988   handle_json_response(json_command_list, &post);
2989
2990   /***************************************************************************/
2991   /* Check that the domain is throttled.                                     */
2992   /***************************************************************************/
2993   assert(evel_get_throttle_spec(EVEL_DOMAIN_REPORT) != NULL);
2994   assert(post.memory == NULL);
2995
2996   size_t json_size = 0;
2997   char json_body[EVEL_MAX_JSON_BODY];
2998   EVENT_REPORT * report = NULL;
2999
3000   /***************************************************************************/
3001   /* Report.                                                                 */
3002   /***************************************************************************/
3003   evel_set_next_event_sequence(125);
3004   report = evel_new_report(1.1);
3005   assert(report != NULL);
3006   evel_report_type_set(report, "Perf reporting...");
3007   evel_report_feature_use_add(report, "FeatureA", 123);
3008   evel_report_feature_use_add(report, "FeatureB", 567);
3009   evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
3010   evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
3011   evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
3012
3013   json_size = evel_json_encode_event(
3014     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
3015   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
3016   assert((json_size == strlen(json_body)) && "Bad size returned");
3017
3018   evel_free_event(report);
3019   evel_throttle_terminate();
3020 }
3021
3022 void test_encode_service_throttled()
3023 {
3024   MEMORY_CHUNK post;
3025
3026   /***************************************************************************/
3027   /* We also test suppression of the event header parameters here.           */
3028   /***************************************************************************/
3029   char * json_command_list =
3030     "{"
3031     "\"commandList\": ["
3032     "{"
3033     "\"command\": {"
3034     "\"commandType\": \"throttlingSpecification\", "
3035     "\"eventDomainThrottleSpecification\": {"
3036     "\"eventDomain\": \"serviceEvents\", "
3037     "\"suppressedFieldNames\": ["
3038     "\"eventType\", "
3039     "\"correlator\", "
3040     "\"codecSelected\", "
3041     "\"codecSelectedTranscoding\", "
3042     "\"endOfCallVqmSummaries\", "
3043     "\"midCallRtcp\", "
3044     "\"marker\", "
3045     "\"reportingEntityId\", "
3046     "\"sourceId\"], "
3047     "\"suppressedNvPairsList\": ["
3048     "{"
3049     "\"nvPairFieldName\": \"additionalFields\", "
3050     "\"suppressedNvPairNames\": [\"Name1\", \"Name3\"]"
3051     "}"
3052     "]}}}"
3053     "]"
3054     "}";
3055
3056   char * expected =
3057     "{\"event\": "
3058     "{\"commonEventHeader\": {"
3059     "\"domain\": \"serviceEvents\", "
3060     "\"eventId\": \"2000\", "
3061     "\"functionalRole\": \"UNIT TEST\", "
3062     "\"lastEpochMicrosec\": 1000002, "
3063     "\"priority\": \"Normal\", "
3064     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3065     "\"sequence\": 2000, "
3066     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3067     "\"startEpochMicrosec\": 1000002, "
3068     "\"version\": 1.2"
3069     "}, "
3070     "\"serviceEventsFields\": {"
3071     "\"eventInstanceIdentifier\": "
3072     "{"
3073     "\"vendorId\": \"vendor_x_id\", "
3074     "\"eventId\": \"vendor_x_event_id\", "
3075     "\"productId\": \"vendor_x_product_id\", "
3076     "\"subsystemId\": \"vendor_x_subsystem_id\", "
3077     "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3078     "}, "
3079     "\"serviceEventsFieldsVersion\": 1.1, "
3080     "\"additionalFields\": ["
3081     "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
3082     "{\"name\": \"Name4\", \"value\": \"Value4\"}]"
3083     "}}}";
3084
3085   /***************************************************************************/
3086   /* Initialize and provide a specification with a single fault suppressed.  */
3087   /***************************************************************************/
3088   evel_throttle_initialize();
3089   handle_json_response(json_command_list, &post);
3090
3091   /***************************************************************************/
3092   /* Check that the domain is throttled.                                     */
3093   /***************************************************************************/
3094   assert(evel_get_throttle_spec(EVEL_DOMAIN_SERVICE) != NULL);
3095   assert(post.memory == NULL);
3096
3097   size_t json_size = 0;
3098   char json_body[EVEL_MAX_JSON_BODY];
3099   EVENT_SERVICE * event = NULL;
3100   evel_set_next_event_sequence(2000);
3101   event = evel_new_service("vendor_x_id", "vendor_x_event_id");
3102   assert(event != NULL);
3103   evel_service_type_set(event, "Service Event");
3104   evel_service_product_id_set(event, "vendor_x_product_id");
3105   evel_service_subsystem_id_set(event, "vendor_x_subsystem_id");
3106   evel_service_friendly_name_set(event, "vendor_x_frieldly_name");
3107   evel_service_correlator_set(event, "vendor_x_correlator");
3108   evel_service_codec_set(event, "PCMA");
3109   evel_service_codec_set(event, "PCMA");
3110   evel_service_callee_codec_set(event, "PCMA");
3111   evel_service_caller_codec_set(event, "G729A");
3112   evel_service_rtcp_data_set(event, "some_rtcp_data");
3113   evel_service_adjacency_name_set(event, "vendor_x_adjacency");
3114   evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
3115   evel_service_endpoint_jitter_set(event, 66);
3116   evel_service_endpoint_rtp_oct_disc_set(event, 100);
3117   evel_service_endpoint_rtp_oct_recv_set(event, 200);
3118   evel_service_endpoint_rtp_oct_sent_set(event, 300);
3119   evel_service_endpoint_rtp_pkt_disc_set(event, 400);
3120   evel_service_endpoint_rtp_pkt_recv_set(event, 500);
3121   evel_service_endpoint_rtp_pkt_sent_set(event, 600);
3122   evel_service_local_jitter_set(event, 99);
3123   evel_service_local_rtp_oct_disc_set(event, 150);
3124   evel_service_local_rtp_oct_recv_set(event, 250);
3125   evel_service_local_rtp_oct_sent_set(event, 350);
3126   evel_service_local_rtp_pkt_disc_set(event, 450);
3127   evel_service_local_rtp_pkt_recv_set(event, 550);
3128   evel_service_local_rtp_pkt_sent_set(event, 650);
3129   evel_service_mos_cqe_set(event, 12.255);
3130   evel_service_packets_lost_set(event, 157);
3131   evel_service_packet_loss_percent_set(event, 0.232);
3132   evel_service_r_factor_set(event, 11);
3133   evel_service_round_trip_delay_set(event, 15);
3134   evel_service_phone_number_set(event, "0888888888");
3135   evel_service_addl_field_add(event, "Name1", "Value1");
3136   evel_service_addl_field_add(event, "Name2", "Value2");
3137   evel_service_addl_field_add(event, "Name3", "Value3");
3138   evel_service_addl_field_add(event, "Name4", "Value4");
3139   json_size = evel_json_encode_event(
3140     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3141   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
3142   assert((json_size == strlen(json_body)) && "Bad size returned");
3143
3144   evel_free_event(event);
3145   evel_throttle_terminate();
3146 }
3147
3148 void test_encode_signaling_throttled()
3149 {
3150   MEMORY_CHUNK post;
3151
3152   /***************************************************************************/
3153   /* We also test suppression of the event header parameters here.           */
3154   /***************************************************************************/
3155   char * json_command_list =
3156     "{"
3157     "\"commandList\": ["
3158     "{"
3159     "\"command\": {"
3160     "\"commandType\": \"throttlingSpecification\", "
3161     "\"eventDomainThrottleSpecification\": {"
3162     "\"eventDomain\": \"signaling\", "
3163     "\"suppressedFieldNames\": ["
3164     "\"correlator\", "
3165     "\"eventType\", "
3166     "\"reportingEntityId\", "
3167     "\"sourceId\", "
3168     "\"localIpAddress\", "
3169     "\"localPort\", "
3170     "\"remoteIpAddress\", "
3171     "\"remotePort\", "
3172     "\"compressedSip\", "
3173     "\"summarySip\"], "
3174     "\"suppressedNvPairsList\": ["
3175     "]}}}"
3176     "]"
3177     "}";
3178
3179   char * expected =
3180     "{\"event\": "
3181     "{\"commonEventHeader\": {"
3182     "\"domain\": \"signaling\", "
3183     "\"eventId\": \"2001\", "
3184     "\"functionalRole\": \"UNIT TEST\", "
3185     "\"lastEpochMicrosec\": 1000002, "
3186     "\"priority\": \"Normal\", "
3187     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3188     "\"sequence\": 2001, "
3189     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3190     "\"startEpochMicrosec\": 1000002, "
3191     "\"version\": 1.2"
3192     "}, "
3193     "\"signalingFields\": {"
3194     "\"eventInstanceIdentifier\": "
3195     "{"
3196     "\"vendorId\": \"vendor_x_id\", "
3197     "\"eventId\": \"vendor_x_event_id\", "
3198     "\"productId\": \"vendor_x_product_id\", "
3199     "\"subsystemId\": \"vendor_x_subsystem_id\", "
3200     "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3201     "}, "
3202     "\"signalingFieldsVersion\": 1.1"
3203     "}}}";
3204
3205   /***************************************************************************/
3206   /* Initialize and provide a specification with a single fault suppressed.  */
3207   /***************************************************************************/
3208   evel_throttle_initialize();
3209   handle_json_response(json_command_list, &post);
3210
3211   /***************************************************************************/
3212   /* Check that the domain is throttled.                                     */
3213   /***************************************************************************/
3214   assert(evel_get_throttle_spec(EVEL_DOMAIN_SIGNALING) != NULL);
3215   assert(post.memory == NULL);
3216
3217   size_t json_size = 0;
3218   char json_body[EVEL_MAX_JSON_BODY];
3219   EVENT_SIGNALING * event = NULL;
3220   evel_set_next_event_sequence(2001);
3221   event = evel_new_signaling("vendor_x_id",
3222            "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
3223   assert(event != NULL);
3224   evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
3225   evel_signaling_vnfname_set(event, "vendor_x_vnf");
3226   evel_signaling_type_set(event, "Signaling");
3227   evel_signaling_product_id_set(event, "vendor_x_product_id");
3228   evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
3229   evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
3230   evel_signaling_correlator_set(event, "vendor_x_correlator");
3231   evel_signaling_local_ip_address_set(event, "1.0.3.1");
3232   evel_signaling_local_port_set(event, "1031");
3233   evel_signaling_remote_ip_address_set(event, "5.3.3.0");
3234   evel_signaling_remote_port_set(event, "5330");
3235   evel_signaling_compressed_sip_set(event, "compressed_sip");
3236   evel_signaling_summary_sip_set(event, "summary_sip");
3237   json_size = evel_json_encode_event(
3238     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3239   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
3240   assert((json_size == strlen(json_body)) && "Bad size returned");
3241
3242   evel_free_event(event);
3243   evel_throttle_terminate();
3244 }
3245
3246 void test_encode_state_change_throttled()
3247 {
3248   MEMORY_CHUNK post;
3249
3250   /***************************************************************************/
3251   /* We also test suppression of the event header parameters here.           */
3252   /***************************************************************************/
3253   char * json_command_list =
3254     "{"
3255     "\"commandList\": ["
3256     "{"
3257     "\"command\": {"
3258     "\"commandType\": \"throttlingSpecification\", "
3259     "\"eventDomainThrottleSpecification\": {"
3260     "\"eventDomain\": \"stateChange\", "
3261     "\"suppressedFieldNames\": ["
3262     "\"eventType\", "
3263     "\"reportingEntityId\", "
3264     "\"sourceId\"], "
3265     "\"suppressedNvPairsList\": ["
3266     "{"
3267     "\"nvPairFieldName\": \"additionalFields\", "
3268     "\"suppressedNvPairNames\": [\"Name1\"]"
3269     "},"
3270     "]}}}"
3271     "]"
3272     "}";
3273
3274   char * expected =
3275     "{\"event\": "
3276     "{\"commonEventHeader\": {"
3277     "\"domain\": \"stateChange\", "
3278     "\"eventId\": \"128\", "
3279     "\"functionalRole\": \"UNIT TEST\", "
3280     "\"lastEpochMicrosec\": 1000002, "
3281     "\"priority\": \"Normal\", "
3282     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3283     "\"sequence\": 128, "
3284     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3285     "\"startEpochMicrosec\": 1000002, "
3286     "\"version\": 1.2"
3287     "}, "
3288     "\"stateChangeFields\": {"
3289     "\"newState\": \"inService\", "
3290     "\"oldState\": \"outOfService\", "
3291     "\"stateInterface\": \"An Interface\", "
3292     "\"additionalFields\": ["
3293     "{\"name\": \"Name2\", "
3294     "\"value\": \"Value2\"}"
3295     "], "
3296     "\"stateChangeFieldsVersion\": 1.1"
3297     "}}}";
3298
3299   /***************************************************************************/
3300   /* Initialize and provide a specification with a single fault suppressed.  */
3301   /***************************************************************************/
3302   evel_throttle_initialize();
3303   handle_json_response(json_command_list, &post);
3304
3305   /***************************************************************************/
3306   /* Check that the domain is throttled.                                     */
3307   /***************************************************************************/
3308   assert(evel_get_throttle_spec(EVEL_DOMAIN_STATE_CHANGE) != NULL);
3309   assert(post.memory == NULL);
3310
3311   size_t json_size = 0;
3312   char json_body[EVEL_MAX_JSON_BODY];
3313   EVENT_STATE_CHANGE * state_change = NULL;
3314   evel_set_next_event_sequence(128);
3315   state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
3316                                        EVEL_ENTITY_STATE_OUT_OF_SERVICE,
3317                                        "An Interface");
3318   assert(state_change != NULL);
3319   evel_state_change_type_set(state_change, "SC Type");
3320   evel_state_change_addl_field_add(state_change, "Name1", "Value1");
3321   evel_state_change_addl_field_add(state_change, "Name2", "Value2");
3322
3323   json_size = evel_json_encode_event(
3324     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
3325   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
3326   assert((json_size == strlen(json_body)) && "Bad size returned");
3327
3328   evel_free_event(state_change);
3329   evel_throttle_terminate();
3330 }
3331
3332 void test_encode_syslog_throttled()
3333 {
3334   MEMORY_CHUNK post;
3335
3336   /***************************************************************************/
3337   /* We also test suppression of the event header parameters here.           */
3338   /***************************************************************************/
3339   char * json_command_list =
3340     "{"
3341     "\"commandList\": ["
3342     "{"
3343     "\"command\": {"
3344     "\"commandType\": \"throttlingSpecification\", "
3345     "\"eventDomainThrottleSpecification\": {"
3346     "\"eventDomain\": \"syslog\", "
3347     "\"suppressedFieldNames\": ["
3348     "\"eventSourceHost\", "
3349     "\"syslogFacility\", "
3350     "\"syslogProc\", "
3351     "\"syslogProcId\", "
3352     "\"syslogSData\", "
3353     "\"syslogVer\", "
3354     "\"eventType\", "
3355     "\"reportingEntityId\", "
3356     "\"sourceId\"], "
3357     "\"suppressedNvPairsList\": ["
3358     "{"
3359     "\"nvPairFieldName\": \"additionalFields\", "
3360     "\"suppressedNvPairNames\": [\"Name2\"]"
3361     "},"
3362     "]}}}"
3363     "]"
3364     "}";
3365
3366   char * expected =
3367     "{\"event\": "
3368     "{\"commonEventHeader\": {"
3369     "\"domain\": \"syslog\", "
3370     "\"eventId\": \"126\", "
3371     "\"functionalRole\": \"UNIT TEST\", "
3372     "\"lastEpochMicrosec\": 1000002, "
3373     "\"priority\": \"Normal\", "
3374     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3375     "\"sequence\": 126, "
3376     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3377     "\"startEpochMicrosec\": 1000002, "
3378     "\"version\": 1.2"
3379     "}, "
3380     "\"syslogFields\": {"
3381     "\"eventSourceType\": \"virtualNetworkFunction\", "
3382     "\"syslogMsg\": \"SL Message\", "
3383     "\"syslogTag\": \"SL Tag\", "
3384     "\"syslogFieldsVersion\": 1.1, "
3385     "\"additionalFields\": ["
3386     "{\"name\": \"Name1\", "
3387     "\"value\": \"Value1\"}"
3388     "]"
3389     "}}}";
3390
3391   /***************************************************************************/
3392   /* Initialize and provide a specification with a single fault suppressed.  */
3393   /***************************************************************************/
3394   evel_throttle_initialize();
3395   handle_json_response(json_command_list, &post);
3396
3397   /***************************************************************************/
3398   /* Check that the domain is throttled.                                     */
3399   /***************************************************************************/
3400   assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
3401   assert(post.memory == NULL);
3402
3403   size_t json_size = 0;
3404   char json_body[EVEL_MAX_JSON_BODY];
3405   EVENT_SYSLOG * syslog = NULL;
3406   evel_set_next_event_sequence(126);
3407   syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
3408                            "SL Message",
3409                            "SL Tag");
3410   assert(syslog != NULL);
3411   evel_syslog_type_set(syslog, "SL Type");
3412   evel_syslog_event_source_host_set(syslog, "SL Host");
3413   evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
3414   evel_syslog_proc_set(syslog, "SL Proc");
3415   evel_syslog_proc_id_set(syslog, 2);
3416   evel_syslog_version_set(syslog, 1);
3417   evel_syslog_s_data_set(syslog, "SL SDATA");
3418   evel_syslog_addl_field_add(syslog, "Name1", "Value1");
3419   evel_syslog_addl_field_add(syslog, "Name2", "Value2");
3420
3421   json_size = evel_json_encode_event(
3422     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
3423   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
3424   assert((json_size == strlen(json_body)) && "Bad size returned");
3425
3426   evel_free_event(syslog);
3427   evel_throttle_terminate();
3428 }
3429
3430 void test_encode_fault_with_escaping()
3431 {
3432   char * expected =
3433     "{\"event\": {"
3434     "\"commonEventHeader\": {"
3435     "\"domain\": \"fault\", "
3436     "\"eventId\": \"122\", "
3437     "\"functionalRole\": \"UNIT TEST\", "
3438     "\"lastEpochMicrosec\": 1000002, "
3439     "\"priority\": \"Normal\", "
3440     "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3441     "\"sequence\": 122, "
3442     "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3443     "\"startEpochMicrosec\": 1000002, "
3444     "\"version\": 1.2, "
3445     "\"eventType\": \"Bad things happen...\\\\\", "
3446     "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
3447     "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
3448     "}, "
3449     "\"faultFields\": {"
3450     "\"alarmCondition\": \"My alarm condition\", "
3451     "\"eventSeverity\": \"MAJOR\", "
3452     "\"eventSourceType\": \"other\", "
3453     "\"specificProblem\": \"It broke \\\"very\\\" badly\", "
3454     "\"vfStatus\": \"Active\", "
3455     "\"faultFieldsVersion\": 1.1, "
3456     "\"alarmAdditionalInformation\": ["
3457     "{\"name\": \"name1\", "
3458     "\"value\": \"value1\"}, "
3459     "{\"name\": \"name2\", "
3460     "\"value\": \"value2\"}], "
3461     "\"alarmInterfaceA\": \"My Interface Card\""
3462     "}}}";
3463
3464   size_t json_size = 0;
3465   char json_body[EVEL_MAX_JSON_BODY];
3466   evel_set_next_event_sequence(122);
3467   EVENT_FAULT * fault = evel_new_fault("My alarm condition",
3468                                        "It broke \"very\" badly",
3469                                        EVEL_PRIORITY_NORMAL,
3470                                        EVEL_SEVERITY_MAJOR,
3471                                         EVEL_SOURCE_HOST,
3472                           EVEL_VF_STATUS_PREP_TERMINATE);
3473   assert(fault != NULL);
3474   evel_fault_type_set(fault, "Bad things happen...\\");
3475   evel_fault_interface_set(fault, "My Interface Card");
3476   evel_fault_addl_info_add(fault, "name1", "value1");
3477   evel_fault_addl_info_add(fault, "name2", "value2");
3478
3479   json_size = evel_json_encode_event(
3480     json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
3481   compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
3482   assert((json_size == strlen(json_body)) && "Bad size returned");
3483
3484   evel_free_event(fault);
3485 }