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