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