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