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