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