1 /**************************************************************************//**
3 * Unit tests for JSON encoding and throttling.
5 * This software is intended to show the essential elements of the library's
11 * Copyright(c) <2016>, AT&T Intellectual Property. All other rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement: This product includes software
23 * developed by the AT&T.
24 * 4. Neither the name of AT&T nor the names of its contributors may be used to
25 * endorse or promote products derived from this software without specific
26 * prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
29 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *****************************************************************************/
47 #include "evel_internal.h"
48 #include "evel_throttle.h"
60 /*****************************************************************************/
61 /* Local prototypes. */
62 /*****************************************************************************/
63 static void test_encode_heartbeat();
64 static void test_encode_header_overrides();
65 static void test_encode_fault();
66 static void test_encode_fault_with_escaping();
67 static void test_encode_measurement();
68 static void test_encode_mobile_mand();
69 static void test_encode_mobile_opts();
70 static void test_encode_other();
71 static void test_encode_report();
72 static void test_encode_service();
73 static void test_encode_service_subset(const SERVICE_TEST service_test);
74 static void test_encode_signaling();
75 static void test_encode_state_change();
76 static void test_encode_syslog();
77 static void test_json_response_junk();
78 static void test_json_provide_throttle_state();
79 static void test_json_measurement_interval();
80 static void test_json_throttle_spec_field();
81 static void test_json_throttle_spec_nv_pair();
82 static void test_json_throttle_spec_two_domains();
83 static void test_json_throttle_spec_bad_command_type();
84 static void test_encode_fault_throttled();
85 static void test_encode_measurement_throttled();
86 static void test_encode_mobile_throttled();
87 static void test_encode_other_throttled();
88 static void test_encode_report_throttled();
89 static void test_encode_service_throttled();
90 static void test_encode_signaling_throttled();
91 static void test_encode_state_change_throttled();
92 static void test_encode_syslog_throttled();
93 static void compare_strings(char * expected,
98 /**************************************************************************//**
101 * Runs all unit test cases, and fails hard on the first failure.
103 * @param[in] argc Argument count.
104 * @param[in] argv Argument vector - for usage see usage_text.
105 *****************************************************************************/
106 int main(int argc, char ** argv)
109 assert(argv != NULL);
111 /***************************************************************************/
112 /* Fix our timezone to UTC. */
113 /***************************************************************************/
116 /***************************************************************************/
117 /* Initialize metadata. */
118 /***************************************************************************/
119 openstack_metadata_initialize();
121 /***************************************************************************/
122 /* Minimal initialisation to exercise the encoders. */
123 /***************************************************************************/
124 functional_role = "UNIT TEST";
125 log_initialize(EVEL_LOG_DEBUG, "EVEL");
127 /***************************************************************************/
128 /* Test each encoder. */
129 /***************************************************************************/
130 test_encode_heartbeat();
131 test_encode_header_overrides();
133 test_encode_measurement();
134 test_encode_mobile_mand();
135 test_encode_mobile_opts();
137 test_encode_report();
138 test_encode_service();
139 test_encode_signaling();
140 test_encode_state_change();
141 test_encode_syslog();
143 /***************************************************************************/
144 /* Test JSON Throttle. */
145 /***************************************************************************/
146 test_json_response_junk();
147 test_json_provide_throttle_state();
148 test_json_measurement_interval();
149 test_json_throttle_spec_field();
150 test_json_throttle_spec_nv_pair();
151 test_json_throttle_spec_two_domains();
152 test_json_throttle_spec_bad_command_type();
154 /***************************************************************************/
155 /* Test each encoder with throttling applied. */
156 /***************************************************************************/
157 test_encode_fault_throttled();
158 test_encode_measurement_throttled();
159 test_encode_mobile_throttled();
160 test_encode_other_throttled();
161 test_encode_report_throttled();
162 test_encode_service_throttled();
163 test_encode_signaling_throttled();
164 test_encode_state_change_throttled();
165 test_encode_syslog_throttled();
167 /***************************************************************************/
168 /* Test character escaping. */
169 /***************************************************************************/
170 test_encode_fault_with_escaping();
172 printf ("\nAll Tests Passed\n");
177 /*****************************************************************************/
178 /* We link with this gettimeofday so that we get a fixed result */
179 /*****************************************************************************/
180 int gettimeofday(struct timeval *tv,
181 struct timezone *tz __attribute__((unused)))
188 void test_encode_heartbeat()
192 "\"commonEventHeader\": {"
193 "\"domain\": \"heartbeat\", "
194 "\"eventId\": \"121\", "
195 "\"functionalRole\": \"UNIT TEST\", "
196 "\"lastEpochMicrosec\": 1000002, "
197 "\"priority\": \"Normal\", "
198 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
199 "\"sequence\": 121, "
200 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
201 "\"startEpochMicrosec\": 1000002, "
203 "\"eventType\": \"Autonomous heartbeat\", "
204 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
205 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
208 size_t json_size = 0;
209 char json_body[EVEL_MAX_JSON_BODY];
211 /***************************************************************************/
212 /* Test the VM name/uuid once. */
213 /***************************************************************************/
214 evel_set_next_event_sequence(121);
216 EVENT_HEADER * heartbeat = evel_new_heartbeat();
217 assert(heartbeat != NULL);
219 json_size = evel_json_encode_event(
220 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
221 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
222 assert((json_size == strlen(json_body)) && "Bad size returned");
224 evel_free_event(heartbeat);
227 void test_encode_header_overrides()
231 "\"commonEventHeader\": {"
232 "\"domain\": \"heartbeat\", "
233 "\"eventId\": \"121\", "
234 "\"functionalRole\": \"UNIT TEST\", "
235 "\"lastEpochMicrosec\": 1000, "
236 "\"priority\": \"Normal\", "
237 "\"reportingEntityName\": \"entity_name_override\", "
238 "\"sequence\": 121, "
239 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
240 "\"startEpochMicrosec\": 1001, "
242 "\"eventType\": \"Autonomous heartbeat\", "
243 "\"reportingEntityId\": \"entity_id_override\", "
244 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
247 size_t json_size = 0;
248 char json_body[EVEL_MAX_JSON_BODY];
250 /***************************************************************************/
251 /* Test the VM name/uuid once. */
252 /***************************************************************************/
253 evel_set_next_event_sequence(121);
255 EVENT_HEADER * heartbeat = evel_new_heartbeat();
256 assert(heartbeat != NULL);
258 evel_start_epoch_set(heartbeat, 1001);
259 evel_last_epoch_set(heartbeat, 1000);
260 evel_reporting_entity_name_set(heartbeat, "entity_name_override");
261 evel_reporting_entity_id_set(heartbeat, "entity_id_override");
263 json_size = evel_json_encode_event(
264 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
265 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
266 assert((json_size == strlen(json_body)) && "Bad size returned");
268 evel_free_event(heartbeat);
271 void test_encode_fault()
275 "\"commonEventHeader\": {"
276 "\"domain\": \"fault\", "
277 "\"eventId\": \"122\", "
278 "\"functionalRole\": \"UNIT TEST\", "
279 "\"lastEpochMicrosec\": 1000002, "
280 "\"priority\": \"Normal\", "
281 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
282 "\"sequence\": 122, "
283 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
284 "\"startEpochMicrosec\": 1000002, "
286 "\"eventType\": \"Bad things happen...\", "
287 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
288 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
291 "\"alarmCondition\": \"My alarm condition\", "
292 "\"eventSeverity\": \"MAJOR\", "
293 "\"eventSourceType\": \"other\", "
294 "\"specificProblem\": \"It broke very badly\", "
295 "\"vfStatus\": \"Active\", "
296 "\"faultFieldsVersion\": 1.1, "
297 "\"alarmAdditionalInformation\": ["
298 "{\"name\": \"name1\", "
299 "\"value\": \"value1\"}, "
300 "{\"name\": \"name2\", "
301 "\"value\": \"value2\"}], "
302 "\"alarmInterfaceA\": \"My Interface Card\""
305 size_t json_size = 0;
306 char json_body[EVEL_MAX_JSON_BODY];
307 evel_set_next_event_sequence(122);
308 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
309 "It broke very badly",
310 EVEL_PRIORITY_NORMAL,
311 EVEL_SEVERITY_MAJOR);
312 assert(fault != NULL);
313 evel_fault_type_set(fault, "Bad things happen...");
314 evel_fault_interface_set(fault, "My Interface Card");
315 evel_fault_addl_info_add(fault, "name1", "value1");
316 evel_fault_addl_info_add(fault, "name2", "value2");
318 json_size = evel_json_encode_event(
319 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
320 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
321 assert((json_size == strlen(json_body)) && "Bad size returned");
323 evel_free_event(fault);
326 void test_encode_measurement()
330 "{\"commonEventHeader\": {"
331 "\"domain\": \"measurementsForVfScaling\", "
332 "\"eventId\": \"123\", "
333 "\"functionalRole\": \"UNIT TEST\", "
334 "\"lastEpochMicrosec\": 3000, "
335 "\"priority\": \"Normal\", "
336 "\"reportingEntityName\": \"entity_name\", "
337 "\"sequence\": 123, "
338 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
339 "\"startEpochMicrosec\": 2000, "
341 "\"eventType\": \"Perf management...\", "
342 "\"reportingEntityId\": \"entity_id\", "
343 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
345 "\"measurementsForVfScalingFields\": "
347 "\"measurementInterval\": 5.500000, "
348 "\"concurrentSessions\": 1, "
349 "\"configuredEntities\": 2, "
350 "\"cpuUsageArray\": ["
351 "{\"cpuIdentifier\": \"cpu1\", "
352 "\"percentUsage\": 11.110000}, "
353 "{\"cpuIdentifier\": \"cpu2\", "
354 "\"percentUsage\": 22.220000}], "
355 "\"filesystemUsageArray\": ["
356 "{\"blockConfigured\": 100.110000, "
357 "\"blockIops\": 33, "
358 "\"blockUsed\": 100.220000, "
359 "\"ephemeralConfigured\": 100.110000, "
360 "\"ephemeralIops\": 44, "
361 "\"ephemeralUsed\": 200.220000, "
362 "\"filesystemName\": \"00-11-22\"}, "
363 "{\"blockConfigured\": 300.110000, "
364 "\"blockIops\": 55, "
365 "\"blockUsed\": 300.220000, "
366 "\"ephemeralConfigured\": 300.110000, "
367 "\"ephemeralIops\": 66, "
368 "\"ephemeralUsed\": 400.220000, "
369 "\"filesystemName\": \"33-44-55\"}], "
370 "\"latencyDistribution\": ["
371 "{\"countsInTheBucket\": 20}, "
372 "{\"lowEndOfLatencyBucket\": 10.000000, "
373 "\"highEndOfLatencyBucket\": 20.000000, "
374 "\"countsInTheBucket\": 30}], "
375 "\"meanRequestLatency\": 4.400000, "
376 "\"memoryConfigured\": 6.600000, "
377 "\"memoryUsed\": 3.300000, "
378 "\"requestRate\": 7, "
379 "\"vNicUsageArray\": ["
383 "\"packetsIn\": 100, "
384 "\"packetsOut\": 200, "
385 "\"vNicIdentifier\": \"eth0\""
390 "\"packetsIn\": 110, "
391 "\"packetsOut\": 240, "
392 "\"vNicIdentifier\": \"eth1\", "
393 "\"broadcastPacketsIn\": 11, "
394 "\"broadcastPacketsOut\": 12, "
395 "\"multicastPacketsIn\": 15, "
396 "\"multicastPacketsOut\": 16, "
397 "\"unicastPacketsIn\": 17, "
398 "\"unicastPacketsOut\": 18"
401 "\"aggregateCpuUsage\": 8.800000, "
402 "\"numberOfMediaPortsInUse\": 1234, "
403 "\"vnfcScalingMetric\": 1234.567800, "
405 "\"receiveDiscards\": 1, "
406 "\"receiveErrors\": 0, "
407 "\"transmitDiscards\": 2, "
408 "\"transmitErrors\": 1}, "
409 "\"featureUsageArray\": ["
410 "{\"featureIdentifier\": \"FeatureA\", "
411 "\"featureUtilization\": 123}, "
412 "{\"featureIdentifier\": \"FeatureB\", "
413 "\"featureUtilization\": 567}], "
414 "\"codecUsageArray\": ["
415 "{\"codecIdentifier\": \"G711a\", "
416 "\"numberInUse\": 91}, "
417 "{\"codecIdentifier\": \"G729ab\", "
418 "\"numberInUse\": 92}], "
419 "\"additionalMeasurements\": ["
420 "{\"name\": \"Group1\", "
421 "\"measurements\": ["
422 "{\"name\": \"Name1\", "
423 "\"value\": \"Value1\"}]}, "
424 "{\"name\": \"Group2\", "
425 "\"measurements\": ["
426 "{\"name\": \"Name1\", "
427 "\"value\": \"Value1\"}, "
428 "{\"name\": \"Name2\", "
429 "\"value\": \"Value2\"}]}], "
430 "\"measurementsForVfScalingVersion\": 1.1}}}";
432 size_t json_size = 0;
433 char json_body[EVEL_MAX_JSON_BODY];
434 EVENT_MEASUREMENT * measurement = NULL;
435 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
436 MEASUREMENT_VNIC_USE * vnic_use = NULL;
438 /***************************************************************************/
440 /***************************************************************************/
441 evel_set_next_event_sequence(123);
442 measurement = evel_new_measurement(5.5);
443 assert(measurement != NULL);
444 evel_measurement_type_set(measurement, "Perf management...");
445 evel_measurement_conc_sess_set(measurement, 1);
446 evel_measurement_cfg_ents_set(measurement, 2);
447 evel_measurement_mean_req_lat_set(measurement, 4.4);
448 evel_measurement_mem_cfg_set(measurement, 6.6);
449 evel_measurement_mem_used_set(measurement, 3.3);
450 evel_measurement_request_rate_set(measurement, 7);
451 evel_measurement_agg_cpu_use_set(measurement, 8.8);
452 evel_measurement_cpu_use_add(measurement, "cpu1", 11.11);
453 evel_measurement_cpu_use_add(measurement, "cpu2", 22.22);
454 evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33,
456 evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55,
458 evel_start_epoch_set(&measurement->header, 2000);
459 evel_last_epoch_set(&measurement->header, 3000);
460 evel_reporting_entity_name_set(&measurement->header, "entity_name");
461 evel_reporting_entity_id_set(&measurement->header, "entity_id");
463 /***************************************************************************/
464 /* Latency Bucket with no optional parameters. */
465 /***************************************************************************/
466 bucket = evel_new_meas_latency_bucket(20);
467 evel_meas_latency_bucket_add(measurement, bucket);
469 /***************************************************************************/
470 /* Latency Bucket with all optional parameters. */
471 /***************************************************************************/
472 bucket = evel_new_meas_latency_bucket(30);
473 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
474 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
475 evel_meas_latency_bucket_add(measurement, bucket);
477 /***************************************************************************/
478 /* vNIC Use with no optional parameters. */
479 /***************************************************************************/
480 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
481 evel_meas_vnic_use_add(measurement, vnic_use);
483 /***************************************************************************/
484 /* vNIC Use with all optional parameters. */
485 /***************************************************************************/
486 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
487 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
488 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
489 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
490 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
491 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
492 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
493 evel_meas_vnic_use_add(measurement, vnic_use);
495 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
497 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
498 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
500 evel_measurement_codec_use_add(measurement, "G711a", 91);
501 evel_measurement_codec_use_add(measurement, "G729ab", 92);
503 evel_measurement_media_port_use_set(measurement, 1234);
505 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
507 evel_measurement_custom_measurement_add(measurement,
508 "Group1", "Name1", "Value1");
509 evel_measurement_custom_measurement_add(measurement,
510 "Group2", "Name1", "Value1");
511 evel_measurement_custom_measurement_add(measurement,
512 "Group2", "Name2", "Value2");
514 json_size = evel_json_encode_event(
515 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
516 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
517 assert((json_size == strlen(json_body)) && "Bad size returned");
519 evel_free_event(measurement);
522 void test_encode_mobile_mand()
526 "{\"commonEventHeader\": {"
527 "\"domain\": \"mobileFlow\", "
528 "\"eventId\": \"1241\", "
529 "\"functionalRole\": \"UNIT TEST\", "
530 "\"lastEpochMicrosec\": 1000002, "
531 "\"priority\": \"Normal\", "
532 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
533 "\"sequence\": 1241, "
534 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
535 "\"startEpochMicrosec\": 1000002, "
537 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
538 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
540 "\"mobileFlowFields\": {"
541 "\"flowDirection\": \"Outbound\", "
542 "\"gtpPerFlowMetrics\": {"
543 "\"avgBitErrorRate\": 12.300000, "
544 "\"avgPacketDelayVariation\": 3.120000, "
545 "\"avgPacketLatency\": 100, "
546 "\"avgReceiveThroughput\": 2100, "
547 "\"avgTransmitThroughput\": 500, "
548 "\"flowActivationEpoch\": 1470409421, "
549 "\"flowActivationMicrosec\": 987, "
550 "\"flowDeactivationEpoch\": 1470409431, "
551 "\"flowDeactivationMicrosec\": 11, "
552 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:51 +0000\", "
553 "\"flowStatus\": \"Working\", "
554 "\"maxPacketDelayVariation\": 87, "
555 "\"numActivationFailures\": 3, "
556 "\"numBitErrors\": 17, "
557 "\"numBytesReceived\": 123654, "
558 "\"numBytesTransmitted\": 4561, "
559 "\"numDroppedPackets\": 0, "
560 "\"numL7BytesReceived\": 12, "
561 "\"numL7BytesTransmitted\": 10, "
562 "\"numLostPackets\": 1, "
563 "\"numOutOfOrderPackets\": 3, "
564 "\"numPacketErrors\": 7, "
565 "\"numPacketsReceivedExclRetrans\": 899, "
566 "\"numPacketsReceivedInclRetrans\": 901, "
567 "\"numPacketsTransmittedInclRetrans\": 302, "
568 "\"numRetries\": 6, "
569 "\"numTimeouts\": 2, "
570 "\"numTunneledL7BytesReceived\": 0, "
571 "\"roundTripTime\": 110, "
572 "\"timeToFirstByte\": 225"
574 "\"ipProtocolType\": \"TCP\", "
575 "\"ipVersion\": \"IPv4\", "
576 "\"otherEndpointIpAddress\": \"2.3.4.1\", "
577 "\"otherEndpointPort\": 2341, "
578 "\"reportingEndpointIpAddr\": \"4.2.3.1\", "
579 "\"reportingEndpointPort\": 4321"
582 size_t json_size = 0;
583 char json_body[EVEL_MAX_JSON_BODY];
584 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
585 EVENT_MOBILE_FLOW * mobile_flow = NULL;
587 /***************************************************************************/
589 /***************************************************************************/
590 evel_set_next_event_sequence(1241);
592 metrics = evel_new_mobile_gtp_flow_metrics(12.3,
622 assert(metrics != NULL);
623 mobile_flow = evel_new_mobile_flow("Outbound",
631 assert(mobile_flow != NULL);
633 json_size = evel_json_encode_event(
634 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
635 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
636 assert((json_size == strlen(json_body)) && "Bad size returned");
638 evel_free_event(mobile_flow);
641 void test_encode_mobile_opts()
645 "{\"commonEventHeader\": {"
646 "\"domain\": \"mobileFlow\", "
647 "\"eventId\": \"1242\", "
648 "\"functionalRole\": \"UNIT TEST\", "
649 "\"lastEpochMicrosec\": 1000002, "
650 "\"priority\": \"Normal\", "
651 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
652 "\"sequence\": 1242, "
653 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
654 "\"startEpochMicrosec\": 1000002, "
656 "\"eventType\": \"Mobile flow...\", "
657 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
658 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
660 "\"mobileFlowFields\": {"
661 "\"flowDirection\": \"Inbound\", "
662 "\"gtpPerFlowMetrics\": {"
663 "\"avgBitErrorRate\": 132.000100, "
664 "\"avgPacketDelayVariation\": 31.200000, "
665 "\"avgPacketLatency\": 101, "
666 "\"avgReceiveThroughput\": 2101, "
667 "\"avgTransmitThroughput\": 501, "
668 "\"flowActivationEpoch\": 1470409422, "
669 "\"flowActivationMicrosec\": 988, "
670 "\"flowDeactivationEpoch\": 1470409432, "
671 "\"flowDeactivationMicrosec\": 12, "
672 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
673 "\"flowStatus\": \"Inactive\", "
674 "\"maxPacketDelayVariation\": 88, "
675 "\"numActivationFailures\": 4, "
676 "\"numBitErrors\": 18, "
677 "\"numBytesReceived\": 123655, "
678 "\"numBytesTransmitted\": 4562, "
679 "\"numDroppedPackets\": 1, "
680 "\"numL7BytesReceived\": 13, "
681 "\"numL7BytesTransmitted\": 11, "
682 "\"numLostPackets\": 2, "
683 "\"numOutOfOrderPackets\": 4, "
684 "\"numPacketErrors\": 8, "
685 "\"numPacketsReceivedExclRetrans\": 900, "
686 "\"numPacketsReceivedInclRetrans\": 902, "
687 "\"numPacketsTransmittedInclRetrans\": 303, "
688 "\"numRetries\": 7, "
689 "\"numTimeouts\": 3, "
690 "\"numTunneledL7BytesReceived\": 1, "
691 "\"roundTripTime\": 111, "
692 "\"timeToFirstByte\": 226, "
693 "\"ipTosCountList\": ["
697 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
698 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
699 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
700 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
701 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
702 "\"durConnectionFailedStatus\": 12, "
703 "\"durTunnelFailedStatus\": 13, "
704 "\"flowActivatedBy\": \"Remote\", "
705 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
706 "\"flowDeactivatedBy\": \"Remote\", "
707 "\"gtpConnectionStatus\": \"Connected\", "
708 "\"gtpTunnelStatus\": \"Not tunneling\", "
709 "\"largePacketRtt\": 80, "
710 "\"largePacketThreshold\": 600.000000, "
711 "\"maxReceiveBitRate\": 1357924680, "
712 "\"maxTransmitBitRate\": 235711, "
713 "\"numGtpEchoFailures\": 1, "
714 "\"numGtpTunnelErrors\": 4, "
715 "\"numHttpErrors\": 2"
717 "\"ipProtocolType\": \"UDP\", "
718 "\"ipVersion\": \"IPv6\", "
719 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
720 "\"otherEndpointPort\": 2342, "
721 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
722 "\"reportingEndpointPort\": 4322, "
723 "\"applicationType\": \"Demo application\", "
724 "\"appProtocolType\": \"GSM\", "
725 "\"appProtocolVersion\": \"1\", "
726 "\"cid\": \"65535\", "
727 "\"connectionType\": \"S1-U\", "
728 "\"ecgi\": \"e65535\", "
729 "\"gtpProtocolType\": \"GTP-U\", "
730 "\"gtpVersion\": \"1\", "
731 "\"httpHeader\": \"http://www.something.com\", "
732 "\"imei\": \"209917614823\", "
733 "\"imsi\": \"355251/05/850925/8\", "
737 "\"msisdn\": \"6017123456789\", "
738 "\"otherFunctionalRole\": \"MME\", "
740 "\"radioAccessTechnology\": \"LTE\", "
742 "\"samplingAlgorithm\": 1, "
743 "\"tac\": \"2099\", "
744 "\"tunnelId\": \"Tunnel 1\", "
748 size_t json_size = 0;
749 char json_body[EVEL_MAX_JSON_BODY];
750 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
751 EVENT_MOBILE_FLOW * mobile_flow = NULL;
753 /***************************************************************************/
755 /***************************************************************************/
756 evel_set_next_event_sequence(1242);
758 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
788 assert(metrics != NULL);
790 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
791 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
792 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
793 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
794 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
795 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
796 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
797 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
798 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
799 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
800 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
801 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
802 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
803 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
804 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
805 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
806 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
807 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
808 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
809 evel_mobile_gtp_metrics_qci_cos_count_add(
810 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
811 evel_mobile_gtp_metrics_qci_cos_count_add(
812 metrics, EVEL_QCI_COS_LTE_65, 122);
814 mobile_flow = evel_new_mobile_flow("Inbound",
822 assert(mobile_flow != NULL);
824 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
825 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
826 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
827 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
828 evel_mobile_flow_cid_set(mobile_flow, "65535");
829 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
830 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
831 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
832 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
833 evel_mobile_flow_http_header_set(mobile_flow,
834 "http://www.something.com");
835 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
836 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
837 evel_mobile_flow_lac_set(mobile_flow, "1");
838 evel_mobile_flow_mcc_set(mobile_flow, "410");
839 evel_mobile_flow_mnc_set(mobile_flow, "04");
840 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
841 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
842 evel_mobile_flow_rac_set(mobile_flow, "514");
843 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
844 evel_mobile_flow_sac_set(mobile_flow, "1");
845 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
846 evel_mobile_flow_tac_set(mobile_flow, "2099");
847 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
848 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
850 json_size = evel_json_encode_event(
851 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
852 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
853 assert((json_size == strlen(json_body)) && "Bad size returned");
855 evel_free_event(mobile_flow);
858 void test_encode_report()
862 "{\"commonEventHeader\": {"
863 "\"domain\": \"measurementsForVfReporting\", "
864 "\"eventId\": \"125\", "
865 "\"functionalRole\": \"UNIT TEST\", "
866 "\"lastEpochMicrosec\": 1000002, "
867 "\"priority\": \"Normal\", "
868 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
869 "\"sequence\": 125, "
870 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
871 "\"startEpochMicrosec\": 1000002, "
873 "\"eventType\": \"Perf reporting...\", "
874 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
875 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
877 "\"measurementsForVfReportingFields\": "
878 "{\"measurementInterval\": 1.100000, "
879 "\"featureUsageArray\": ["
880 "{\"featureIdentifier\": \"FeatureA\", "
881 "\"featureUtilization\": 123}, "
882 "{\"featureIdentifier\": \"FeatureB\", "
883 "\"featureUtilization\": 567}], "
884 "\"additionalMeasurements\": ["
885 "{\"name\": \"Group1\", "
886 "\"measurements\": ["
887 "{\"name\": \"Name1\", "
888 "\"value\": \"Value1\"}]}, "
889 "{\"name\": \"Group2\", "
890 "\"measurements\": ["
891 "{\"name\": \"Name1\", "
892 "\"value\": \"Value1\"}, "
893 "{\"name\": \"Name2\", "
894 "\"value\": \"Value2\"}]}], "
895 "\"measurementFieldsVersion\": 1.1}}}";
897 size_t json_size = 0;
898 char json_body[EVEL_MAX_JSON_BODY];
899 EVENT_REPORT * report = NULL;
901 /***************************************************************************/
903 /***************************************************************************/
904 evel_set_next_event_sequence(125);
905 report = evel_new_report(1.1);
906 assert(report != NULL);
907 evel_report_type_set(report, "Perf reporting...");
908 evel_report_feature_use_add(report, "FeatureA", 123);
909 evel_report_feature_use_add(report, "FeatureB", 567);
910 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
911 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
912 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
914 json_size = evel_json_encode_event(
915 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
916 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
917 assert((json_size == strlen(json_body)) && "Bad size returned");
919 evel_free_event(report);
922 void test_encode_service()
924 test_encode_service_subset(SERVICE_NONE);
925 test_encode_service_subset(SERVICE_CODEC);
926 test_encode_service_subset(SERVICE_TRANSCODING);
927 test_encode_service_subset(SERVICE_RTCP);
928 test_encode_service_subset(SERVICE_EOC_VQM);
929 test_encode_service_subset(SERVICE_MARKER);
932 void test_encode_service_subset(const SERVICE_TEST service_test)
934 char * expected_start =
936 "{\"commonEventHeader\": {"
937 "\"domain\": \"serviceEvents\", "
938 "\"eventId\": \"2000\", "
939 "\"functionalRole\": \"UNIT TEST\", "
940 "\"lastEpochMicrosec\": 1000002, "
941 "\"priority\": \"Normal\", "
942 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
943 "\"sequence\": 2000, "
944 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
945 "\"startEpochMicrosec\": 1000002, "
947 "\"eventType\": \"Service Event\", "
948 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
949 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
951 "\"serviceEventsFields\": {"
952 "\"eventInstanceIdentifier\": "
954 "\"vendorId\": \"vendor_x_id\", "
955 "\"eventId\": \"vendor_x_event_id\", "
956 "\"productId\": \"vendor_x_product_id\", "
957 "\"subsystemId\": \"vendor_x_subsystem_id\", "
958 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
960 "\"serviceEventsFieldsVersion\": 1.1, "
961 "\"correlator\": \"vendor_x_correlator\", "
962 "\"additionalFields\": ["
963 "{\"name\": \"Name1\", \"value\": \"Value1\"}, "
964 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
965 "{\"name\": \"Name3\", \"value\": \"Value3\"}, "
966 "{\"name\": \"Name4\", \"value\": \"Value4\"}]";
967 char * expected_codec =
969 "\"codecSelected\": {"
970 "\"codec\": \"PCMA\""
972 char * expected_transcoding =
974 "\"codecSelectedTranscoding\": {"
975 "\"calleeSideCodec\": \"PCMA\", "
976 "\"callerSideCodec\": \"G729A\""
978 char * expected_rtcp =
981 "\"rtcpData\": \"some_rtcp_data\""
983 char * expected_eoc_vqm =
985 "\"endOfCallVqmSummaries\": {"
986 "\"adjacencyName\": \"vendor_x_adjacency\", "
987 "\"endpointDescription\": \"Caller\", "
988 "\"endpointJitter\": 66, "
989 "\"endpointRtpOctetsDiscarded\": 100, "
990 "\"endpointRtpOctetsReceived\": 200, "
991 "\"endpointRtpOctetsSent\": 300, "
992 "\"endpointRtpPacketsDiscarded\": 400, "
993 "\"endpointRtpPacketsReceived\": 500, "
994 "\"endpointRtpPacketsSent\": 600, "
995 "\"localJitter\": 99, "
996 "\"localRtpOctetsDiscarded\": 150, "
997 "\"localRtpOctetsReceived\": 250, "
998 "\"localRtpOctetsSent\": 350, "
999 "\"localRtpPacketsDiscarded\": 450, "
1000 "\"localRtpPacketsReceived\": 550, "
1001 "\"localRtpPacketsSent\": 650, "
1002 "\"mosCqe\": 12.255000, "
1003 "\"packetsLost\": 157, "
1004 "\"packetLossPercent\": 0.232000, "
1006 "\"roundTripDelay\": 15"
1008 char * expected_marker =
1011 "\"phoneNumber\": \"0888888888\""
1013 char * expected_end =
1016 char * expected_middle = NULL;
1017 switch (service_test)
1020 expected_middle = "";
1023 expected_middle = expected_codec;
1025 case SERVICE_TRANSCODING:
1026 expected_middle = expected_transcoding;
1029 expected_middle = expected_rtcp;
1031 case SERVICE_EOC_VQM:
1032 expected_middle = expected_eoc_vqm;
1034 case SERVICE_MARKER:
1035 expected_middle = expected_marker;
1038 assert(expected_middle != NULL);
1041 char expected[EVEL_MAX_JSON_BODY];
1042 offset = snprintf(expected + offset,
1043 EVEL_MAX_JSON_BODY - offset,
1049 size_t json_size = 0;
1050 char json_body[EVEL_MAX_JSON_BODY];
1051 EVENT_SERVICE * event = NULL;
1052 evel_set_next_event_sequence(2000);
1053 event = evel_new_service("vendor_x_id", "vendor_x_event_id");
1054 assert(event != NULL);
1055 evel_service_type_set(event, "Service Event");
1056 evel_service_product_id_set(event, "vendor_x_product_id");
1057 evel_service_subsystem_id_set(event, "vendor_x_subsystem_id");
1058 evel_service_friendly_name_set(event, "vendor_x_frieldly_name");
1059 evel_service_correlator_set(event, "vendor_x_correlator");
1061 switch (service_test)
1066 evel_service_codec_set(event, "PCMA");
1068 case SERVICE_TRANSCODING:
1069 evel_service_callee_codec_set(event, "PCMA");
1070 evel_service_caller_codec_set(event, "G729A");
1073 evel_service_rtcp_data_set(event, "some_rtcp_data");
1075 case SERVICE_EOC_VQM:
1076 evel_service_adjacency_name_set(event, "vendor_x_adjacency");
1077 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
1078 evel_service_endpoint_jitter_set(event, 66);
1079 evel_service_endpoint_rtp_oct_disc_set(event, 100);
1080 evel_service_endpoint_rtp_oct_recv_set(event, 200);
1081 evel_service_endpoint_rtp_oct_sent_set(event, 300);
1082 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
1083 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
1084 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
1085 evel_service_local_jitter_set(event, 99);
1086 evel_service_local_rtp_oct_disc_set(event, 150);
1087 evel_service_local_rtp_oct_recv_set(event, 250);
1088 evel_service_local_rtp_oct_sent_set(event, 350);
1089 evel_service_local_rtp_pkt_disc_set(event, 450);
1090 evel_service_local_rtp_pkt_recv_set(event, 550);
1091 evel_service_local_rtp_pkt_sent_set(event, 650);
1092 evel_service_mos_cqe_set(event, 12.255);
1093 evel_service_packets_lost_set(event, 157);
1094 evel_service_packet_loss_percent_set(event, 0.232);
1095 evel_service_r_factor_set(event, 11);
1096 evel_service_round_trip_delay_set(event, 15);
1098 case SERVICE_MARKER:
1099 evel_service_phone_number_set(event, "0888888888");
1103 evel_service_addl_field_add(event, "Name1", "Value1");
1104 evel_service_addl_field_add(event, "Name2", "Value2");
1105 evel_service_addl_field_add(event, "Name3", "Value3");
1106 evel_service_addl_field_add(event, "Name4", "Value4");
1107 json_size = evel_json_encode_event(
1108 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1109 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
1110 assert((json_size == strlen(json_body)) && "Bad size returned");
1112 evel_free_event(event);
1115 void test_encode_signaling()
1119 "{\"commonEventHeader\": {"
1120 "\"domain\": \"signaling\", "
1121 "\"eventId\": \"2001\", "
1122 "\"functionalRole\": \"UNIT TEST\", "
1123 "\"lastEpochMicrosec\": 1000002, "
1124 "\"priority\": \"Normal\", "
1125 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1126 "\"sequence\": 2001, "
1127 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1128 "\"startEpochMicrosec\": 1000002, "
1129 "\"version\": 1.2, "
1130 "\"eventType\": \"Signaling\", "
1131 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1132 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1134 "\"signalingFields\": {"
1135 "\"eventInstanceIdentifier\": "
1137 "\"vendorId\": \"vendor_x_id\", "
1138 "\"eventId\": \"vendor_x_event_id\", "
1139 "\"productId\": \"vendor_x_product_id\", "
1140 "\"subsystemId\": \"vendor_x_subsystem_id\", "
1141 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
1143 "\"signalingFieldsVersion\": 1.1, "
1144 "\"correlator\": \"vendor_x_correlator\", "
1145 "\"localIpAddress\": \"1.0.3.1\", "
1146 "\"localPort\": \"1031\", "
1147 "\"remoteIpAddress\": \"5.3.3.0\", "
1148 "\"remotePort\": \"5330\", "
1149 "\"compressedSip\": \"compressed_sip\", "
1150 "\"summarySip\": \"summary_sip\""
1153 size_t json_size = 0;
1154 char json_body[EVEL_MAX_JSON_BODY];
1155 EVENT_SIGNALING * event = NULL;
1156 evel_set_next_event_sequence(2001);
1157 event = evel_new_signaling("vendor_x_id", "vendor_x_event_id");
1158 assert(event != NULL);
1159 evel_signaling_type_set(event, "Signaling");
1160 evel_signaling_product_id_set(event, "vendor_x_product_id");
1161 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
1162 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
1163 evel_signaling_correlator_set(event, "vendor_x_correlator");
1164 evel_signaling_local_ip_address_set(event, "1.0.3.1");
1165 evel_signaling_local_port_set(event, "1031");
1166 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
1167 evel_signaling_remote_port_set(event, "5330");
1168 evel_signaling_compressed_sip_set(event, "compressed_sip");
1169 evel_signaling_summary_sip_set(event, "summary_sip");
1170 json_size = evel_json_encode_event(
1171 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1172 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
1173 assert((json_size == strlen(json_body)) && "Bad size returned");
1175 evel_free_event(event);
1178 void test_encode_state_change()
1182 "{\"commonEventHeader\": {"
1183 "\"domain\": \"stateChange\", "
1184 "\"eventId\": \"128\", "
1185 "\"functionalRole\": \"UNIT TEST\", "
1186 "\"lastEpochMicrosec\": 1000002, "
1187 "\"priority\": \"Normal\", "
1188 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1189 "\"sequence\": 128, "
1190 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1191 "\"startEpochMicrosec\": 1000002, "
1192 "\"version\": 1.2, "
1193 "\"eventType\": \"SC Type\", "
1194 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1195 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1197 "\"stateChangeFields\": {"
1198 "\"newState\": \"inService\", "
1199 "\"oldState\": \"outOfService\", "
1200 "\"stateInterface\": \"An Interface\", "
1201 "\"additionalFields\": ["
1202 "{\"name\": \"Name1\", "
1203 "\"value\": \"Value1\"}, "
1204 "{\"name\": \"Name2\", "
1205 "\"value\": \"Value2\"}"
1207 "\"stateChangeFieldsVersion\": 1.1"
1210 size_t json_size = 0;
1211 char json_body[EVEL_MAX_JSON_BODY];
1212 EVENT_STATE_CHANGE * state_change = NULL;
1213 evel_set_next_event_sequence(128);
1214 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
1215 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
1217 assert(state_change != NULL);
1218 evel_state_change_type_set(state_change, "SC Type");
1219 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
1220 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
1222 json_size = evel_json_encode_event(
1223 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
1224 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
1225 assert((json_size == strlen(json_body)) && "Bad size returned");
1227 evel_free_event(state_change);
1230 void test_encode_syslog()
1234 "{\"commonEventHeader\": {"
1235 "\"domain\": \"syslog\", "
1236 "\"eventId\": \"126\", "
1237 "\"functionalRole\": \"UNIT TEST\", "
1238 "\"lastEpochMicrosec\": 1000002, "
1239 "\"priority\": \"Normal\", "
1240 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1241 "\"sequence\": 126, "
1242 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1243 "\"startEpochMicrosec\": 1000002, "
1244 "\"version\": 1.2, "
1245 "\"eventType\": \"SL Type\", "
1246 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1247 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1249 "\"syslogFields\": {"
1250 "\"eventSourceType\": \"virtualNetworkFunction\", "
1251 "\"syslogMsg\": \"SL Message\", "
1252 "\"syslogTag\": \"SL Tag\", "
1253 "\"syslogFieldsVersion\": 1.1, "
1254 "\"eventSourceHost\": \"SL Host\", "
1255 "\"syslogFacility\": 6, "
1256 "\"syslogProc\": \"SL Proc\", "
1257 "\"syslogProcId\": 2, "
1258 "\"syslogSData\": \"SL SDATA\", "
1261 size_t json_size = 0;
1262 char json_body[EVEL_MAX_JSON_BODY];
1263 EVENT_SYSLOG * syslog = NULL;
1264 evel_set_next_event_sequence(126);
1265 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
1268 assert(syslog != NULL);
1269 evel_syslog_type_set(syslog, "SL Type");
1270 evel_syslog_event_source_host_set(syslog, "SL Host");
1271 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
1272 evel_syslog_proc_set(syslog, "SL Proc");
1273 evel_syslog_proc_id_set(syslog, 2);
1274 evel_syslog_version_set(syslog, 1);
1275 evel_syslog_s_data_set(syslog, "SL SDATA");
1277 json_size = evel_json_encode_event(
1278 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
1279 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
1280 assert((json_size == strlen(json_body)) && "Bad size returned");
1282 evel_free_event(syslog);
1285 void test_encode_other()
1289 "{\"commonEventHeader\": {"
1290 "\"domain\": \"other\", "
1291 "\"eventId\": \"129\", "
1292 "\"functionalRole\": \"UNIT TEST\", "
1293 "\"lastEpochMicrosec\": 1000002, "
1294 "\"priority\": \"Normal\", "
1295 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1296 "\"sequence\": 129, "
1297 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1298 "\"startEpochMicrosec\": 1000002, "
1299 "\"version\": 1.2, "
1300 "\"eventType\": \"Other Type\", "
1301 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1302 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1304 "\"otherFields\": ["
1305 "{\"name\": \"Other field 1\", "
1306 "\"value\": \"Other value 1\"}, "
1307 "{\"name\": \"Other field 2\", "
1308 "\"value\": \"Other value 2\"}"
1312 size_t json_size = 0;
1313 char json_body[EVEL_MAX_JSON_BODY];
1314 EVENT_OTHER * other = NULL;
1315 evel_set_next_event_sequence(129);
1316 other = evel_new_other();
1317 assert(other != NULL);
1318 evel_other_type_set(other, "Other Type");
1319 evel_other_field_add(other,
1322 evel_other_field_add(other,
1326 json_size = evel_json_encode_event(
1327 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
1328 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
1329 assert((json_size == strlen(json_body)) && "Bad size returned");
1331 evel_free_event(other);
1334 void compare_strings(char * expected,
1339 if (strncmp(expected, actual, max_size) != 0)
1342 while (diff < max_size)
1344 if (expected[diff] != actual[diff])
1351 printf("Comparison Failure at Offset %d\n\n", diff);
1352 printf("Expected:\n%s\n", expected);
1353 printf("Actual:\n%s\n", actual);
1354 printf("Description: %s\n", description);
1359 /**************************************************************************//**
1360 * Copy a json string to a ::MEMORY_CHUNK for testing.
1362 * @param chunk The memory chunk.
1363 * @param string The json string.
1364 *****************************************************************************/
1365 void copy_string_to_chunk(MEMORY_CHUNK * chunk, char * string)
1369 /***************************************************************************/
1370 /* Check preconditions. */
1371 /***************************************************************************/
1372 assert(chunk != NULL);
1373 assert(string != NULL);
1375 mem_size = strlen(string) + 1;
1376 chunk->memory = malloc(mem_size);
1377 memcpy(chunk->memory, string, mem_size);
1378 chunk->size = mem_size;
1381 /**************************************************************************//**
1382 * Copy a json string to a ::MEMORY_CHUNK for testing.
1384 * @param json The JSON string.
1385 * @param post Memory chunk to post a response.
1386 *****************************************************************************/
1387 void handle_json_response(char * json, MEMORY_CHUNK * post)
1390 post->memory = NULL;
1392 copy_string_to_chunk(&chunk, json);
1393 evel_handle_event_response(&chunk, post);
1397 /**************************************************************************//**
1398 * Test that a non-"commandList" JSON buffer leaves the throttle state off.
1399 *****************************************************************************/
1400 void test_json_response_junk()
1407 "\"1\", \"2\", \"3\"], "
1409 "\"1\", \"2\", \"3\"]"
1412 evel_throttle_initialize();
1413 handle_json_response(json_junk, &post);
1415 /***************************************************************************/
1416 /* Check that all domains are not throttled. */
1417 /***************************************************************************/
1418 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1420 assert(evel_get_throttle_spec(domain) == NULL);
1423 /***************************************************************************/
1424 /* Check that we generated no post. */
1425 /***************************************************************************/
1426 assert(post.memory == NULL);
1428 evel_throttle_terminate();
1431 char * json_command_list_provide =
1433 "\"commandList\": ["
1436 "\"commandType\": \"provideThrottlingState\""
1442 char * json_command_list_fault_clear =
1444 "\"commandList\": ["
1447 "\"commandType\": \"throttlingSpecification\", "
1448 "\"eventDomainThrottleSpecification\": {"
1449 "\"eventDomain\": \"fault\""
1456 char * json_command_list_syslog_clear =
1458 "\"commandList\": ["
1461 "\"commandType\": \"throttlingSpecification\", "
1462 "\"eventDomainThrottleSpecification\": {"
1463 "\"eventDomain\": \"syslog\""
1470 char * expected_throttle_state_normal =
1472 "\"eventThrottlingState\": {"
1473 "\"eventThrottlingMode\": \"normal\"}"
1476 /**************************************************************************//**
1477 * Test that we can return the default throttling state.
1478 *****************************************************************************/
1479 void test_json_provide_throttle_state()
1484 char * expected_post = expected_throttle_state_normal;
1486 evel_throttle_initialize();
1487 handle_json_response(json_command_list_provide, &post);
1489 /***************************************************************************/
1490 /* Check that all domains are not throttled. */
1491 /***************************************************************************/
1492 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1494 assert(evel_get_throttle_spec(domain) == NULL);
1497 /***************************************************************************/
1498 /* Check that we generated a throttling specification post. */
1499 /***************************************************************************/
1500 assert(post.memory != NULL);
1501 compare_strings(expected_post, post.memory, strlen(expected_post),
1502 "Throttle State Normal");
1505 evel_throttle_terminate();
1508 /**************************************************************************//**
1509 * Test the measurement interval handling and API.
1510 *****************************************************************************/
1511 void test_json_measurement_interval()
1514 char * json_command_list_interval_only =
1516 "\"commandList\": ["
1519 "\"measurementInterval\": 60"
1525 char * json_command_list_interval_first =
1527 "\"commandList\": ["
1530 "\"measurementInterval\": 30, "
1531 "\"commandType\": \"measurementIntervalChange\""
1537 char * json_command_list_command_first =
1539 "\"commandList\": ["
1542 "\"commandType\": \"measurementIntervalChange\", "
1543 "\"measurementInterval\": 60"
1549 evel_throttle_initialize();
1550 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1552 /***************************************************************************/
1553 /* Check that we're not handling stuff when we shouldn't. */
1554 /***************************************************************************/
1555 handle_json_response(json_command_list_interval_only, &post);
1556 assert(post.memory == NULL);
1557 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1559 /***************************************************************************/
1560 /* Check that we're OK with the interval coming first. */
1561 /***************************************************************************/
1562 handle_json_response(json_command_list_interval_first, &post);
1563 assert(post.memory == NULL);
1564 assert(evel_get_measurement_interval() == 30);
1566 /***************************************************************************/
1567 /* Check that we're OK with the command type coming first. */
1568 /***************************************************************************/
1569 handle_json_response(json_command_list_command_first, &post);
1570 assert(post.memory == NULL);
1571 assert(evel_get_measurement_interval() == 60);
1573 evel_throttle_terminate();
1576 /**************************************************************************//**
1577 * Test a single domain, single field suppression.
1578 *****************************************************************************/
1579 void test_json_throttle_spec_field()
1584 char * json_command_list_fault_single =
1586 "\"commandList\": ["
1589 "\"commandType\": \"throttlingSpecification\", "
1590 "\"eventDomainThrottleSpecification\": {"
1591 "\"eventDomain\": \"fault\", "
1592 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1599 char * json_command_list_fault_double =
1601 "\"commandList\": ["
1604 "\"commandType\": \"throttlingSpecification\", "
1605 "\"eventDomainThrottleSpecification\": {"
1606 "\"eventDomain\": \"fault\", "
1607 "\"suppressedFieldNames\": ["
1608 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1615 char * expected_post_fault_single =
1617 "\"eventThrottlingState\": {"
1618 "\"eventThrottlingMode\": \"throttled\", "
1619 "\"eventDomainThrottleSpecificationList\": ["
1621 "\"eventDomain\": \"fault\", "
1622 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1628 char * expected_post_fault_double =
1630 "\"eventThrottlingState\": {"
1631 "\"eventThrottlingMode\": \"throttled\", "
1632 "\"eventDomainThrottleSpecificationList\": ["
1634 "\"eventDomain\": \"fault\", "
1635 "\"suppressedFieldNames\": ["
1636 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1642 /***************************************************************************/
1643 /* Initialize and provide a specification with a single fault suppressed. */
1644 /***************************************************************************/
1645 evel_throttle_initialize();
1646 handle_json_response(json_command_list_fault_single, &post);
1648 /***************************************************************************/
1649 /* Check that the FAULT domain is throttled. */
1650 /***************************************************************************/
1651 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1652 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1654 if (domain != EVEL_DOMAIN_FAULT)
1656 assert(evel_get_throttle_spec(domain) == NULL);
1659 assert(post.memory == NULL);
1661 /***************************************************************************/
1662 /* Request and verify the throttling state. */
1663 /***************************************************************************/
1664 handle_json_response(json_command_list_provide, &post);
1665 assert(post.memory != NULL);
1666 compare_strings(expected_post_fault_single,
1668 strlen(expected_post_fault_single),
1669 "Fault - Single Field");
1673 /***************************************************************************/
1674 /* Update a specification with two faults suppressed. */
1675 /***************************************************************************/
1676 handle_json_response(json_command_list_fault_double, &post);
1678 /***************************************************************************/
1679 /* Check that the FAULT domain is throttled. */
1680 /***************************************************************************/
1681 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1682 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1684 if (domain != EVEL_DOMAIN_FAULT)
1686 assert(evel_get_throttle_spec(domain) == NULL);
1689 assert(post.memory == NULL);
1691 /***************************************************************************/
1692 /* Request and verify the throttling state. */
1693 /***************************************************************************/
1694 handle_json_response(json_command_list_provide, &post);
1695 assert(post.memory != NULL);
1696 compare_strings(expected_post_fault_double,
1698 strlen(expected_post_fault_double),
1699 "Fault - Double Field");
1703 /***************************************************************************/
1704 /* Now clear the FAULT domain. */
1705 /***************************************************************************/
1706 handle_json_response(json_command_list_fault_clear, &post);
1707 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1709 assert(evel_get_throttle_spec(domain) == NULL);
1712 evel_throttle_terminate();
1715 /**************************************************************************//**
1716 * Test a single domain, nv_pair suppression.
1717 *****************************************************************************/
1718 void test_json_throttle_spec_nv_pair()
1723 char * json_command_list_fault_pair_single =
1725 "\"commandList\": ["
1728 "\"commandType\": \"throttlingSpecification\", "
1729 "\"eventDomainThrottleSpecification\": {"
1730 "\"eventDomain\": \"fault\", "
1731 "\"suppressedNvPairsList\": ["
1733 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1734 "\"suppressedNvPairNames\": [\"name1\"]"
1743 char * json_command_list_fault_pair_double =
1745 "\"commandList\": ["
1748 "\"commandType\": \"throttlingSpecification\", "
1749 "\"eventDomainThrottleSpecification\": {"
1750 "\"eventDomain\": \"fault\", "
1751 "\"suppressedNvPairsList\": ["
1753 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1754 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1763 char * expected_post_fault_pair_single =
1765 "\"eventThrottlingState\": {"
1766 "\"eventThrottlingMode\": \"throttled\", "
1767 "\"eventDomainThrottleSpecificationList\": ["
1769 "\"eventDomain\": \"fault\", "
1770 "\"suppressedNvPairsList\": ["
1772 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1773 "\"suppressedNvPairNames\": [\"name1\"]"
1781 char * expected_post_fault_pair_double =
1783 "\"eventThrottlingState\": {"
1784 "\"eventThrottlingMode\": \"throttled\", "
1785 "\"eventDomainThrottleSpecificationList\": ["
1787 "\"eventDomain\": \"fault\", "
1788 "\"suppressedNvPairsList\": ["
1790 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1791 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1799 /***************************************************************************/
1800 /* Initialize and provide a specification with a single nvpair with a */
1801 /* single sub-field suppressed. */
1802 /***************************************************************************/
1803 evel_throttle_initialize();
1804 handle_json_response(json_command_list_fault_pair_single, &post);
1806 /***************************************************************************/
1807 /* Check that the FAULT domain is throttled. */
1808 /***************************************************************************/
1809 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1810 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1812 if (domain != EVEL_DOMAIN_FAULT)
1814 assert(evel_get_throttle_spec(domain) == NULL);
1817 assert(post.memory == NULL);
1819 /***************************************************************************/
1820 /* Request and verify the throttling state. */
1821 /***************************************************************************/
1822 handle_json_response(json_command_list_provide, &post);
1823 assert(post.memory != NULL);
1824 compare_strings(expected_post_fault_pair_single,
1826 strlen(expected_post_fault_pair_single),
1827 "Fault - Single Pair, Single Field");
1831 /***************************************************************************/
1832 /* Update a specification with a single nvpair with two sub-fields */
1834 /***************************************************************************/
1835 handle_json_response(json_command_list_fault_pair_double, &post);
1837 /***************************************************************************/
1838 /* Check that the FAULT domain is throttled. */
1839 /***************************************************************************/
1840 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1841 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1843 if (domain != EVEL_DOMAIN_FAULT)
1845 assert(evel_get_throttle_spec(domain) == NULL);
1848 assert(post.memory == NULL);
1850 /***************************************************************************/
1851 /* Request and verify the throttling state. */
1852 /***************************************************************************/
1853 handle_json_response(json_command_list_provide, &post);
1854 assert(post.memory != NULL);
1855 compare_strings(expected_post_fault_pair_double,
1857 strlen(expected_post_fault_pair_double),
1858 "Fault - Double Field");
1862 /***************************************************************************/
1863 /* Now clear the FAULT domain. */
1864 /***************************************************************************/
1865 handle_json_response(json_command_list_fault_clear, &post);
1866 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1868 assert(evel_get_throttle_spec(domain) == NULL);
1871 evel_throttle_terminate();
1874 /**************************************************************************//**
1875 * Test two domains, nv_pair suppression.
1876 *****************************************************************************/
1877 void test_json_throttle_spec_two_domains()
1882 char * json_command_list_two_domains =
1884 "\"commandList\": ["
1887 "\"commandType\": \"throttlingSpecification\", "
1888 "\"eventDomainThrottleSpecification\": {"
1889 "\"eventDomain\": \"fault\", "
1890 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1891 "\"suppressedNvPairsList\": ["
1893 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1894 "\"suppressedNvPairNames\": [\"name1\"]"
1898 "\"commandType\": \"throttlingSpecification\", "
1899 "\"eventDomainThrottleSpecification\": {"
1900 "\"eventDomain\": \"syslog\", "
1901 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1902 "\"suppressedNvPairsList\": ["
1904 "\"nvPairFieldName\": \"additionalFields\", "
1905 "\"suppressedNvPairNames\": [\"name1\"]"
1910 char * expected_post_two_domains =
1912 "\"eventThrottlingState\": {"
1913 "\"eventThrottlingMode\": \"throttled\", "
1914 "\"eventDomainThrottleSpecificationList\": ["
1916 "\"eventDomain\": \"fault\", "
1917 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1918 "\"suppressedNvPairsList\": ["
1920 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1921 "\"suppressedNvPairNames\": [\"name1\"]"
1924 "\"eventDomain\": \"syslog\", "
1925 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1926 "\"suppressedNvPairsList\": ["
1928 "\"nvPairFieldName\": \"additionalFields\", "
1929 "\"suppressedNvPairNames\": [\"name1\"]"
1935 /***************************************************************************/
1936 /* Initialize and provide a specification with a single nvpair with a */
1937 /* single sub-field suppressed. */
1938 /***************************************************************************/
1939 evel_throttle_initialize();
1940 handle_json_response(json_command_list_two_domains, &post);
1942 /***************************************************************************/
1943 /* Check that the FAULT and SYSLOG domains are throttled. */
1944 /***************************************************************************/
1945 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1946 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1947 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1949 if ((domain != EVEL_DOMAIN_FAULT) && (domain != EVEL_DOMAIN_SYSLOG))
1951 assert(evel_get_throttle_spec(domain) == NULL);
1954 assert(post.memory == NULL);
1956 /***************************************************************************/
1957 /* Request and verify the throttling state. */
1958 /***************************************************************************/
1959 handle_json_response(json_command_list_provide, &post);
1960 assert(post.memory != NULL);
1961 compare_strings(expected_post_two_domains,
1963 strlen(expected_post_two_domains),
1964 "Fault - Two Domains");
1968 /***************************************************************************/
1969 /* Now clear the FAULT and SYSLOG domains. */
1970 /***************************************************************************/
1971 handle_json_response(json_command_list_fault_clear, &post);
1972 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
1973 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1974 handle_json_response(json_command_list_syslog_clear, &post);
1975 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1977 assert(evel_get_throttle_spec(domain) == NULL);
1980 evel_throttle_terminate();
1983 /**************************************************************************//**
1984 * Test bad command type.
1985 *****************************************************************************/
1986 void test_json_throttle_spec_bad_command_type()
1991 /***************************************************************************/
1992 /* Search for "dodgy" in the JSON, and you will see the dodgy bits we're */
1993 /* handling in these tests. */
1994 /***************************************************************************/
1995 #define NUM_BAD_COMMANDS 8
1996 char * json_command_list_dodgy_command =
1998 "\"commandList\": ["
2001 "\"commandType\": \"dodgyCommand\", "
2002 "\"eventDomainThrottleSpecification\": {"
2003 "\"eventDomain\": \"fault\", "
2004 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2005 "\"suppressedNvPairsList\": ["
2007 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2008 "\"suppressedNvPairNames\": [\"name1\"]"
2013 char * json_command_list_dodgy_spec =
2015 "\"commandList\": ["
2018 "\"commandType\": \"throttlingSpecification\", "
2019 "\"dodgyEventDomainThrottleSpecification\": {"
2020 "\"eventDomain\": \"fault\", "
2021 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2022 "\"suppressedNvPairsList\": ["
2024 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2025 "\"suppressedNvPairNames\": [\"name1\"]"
2030 char * json_command_list_dodgy_event_domain_key =
2032 "\"commandList\": ["
2035 "\"commandType\": \"throttlingSpecification\", "
2036 "\"eventDomainThrottleSpecification\": {"
2037 "\"dodgyEventDomainKey\": \"fault\", "
2038 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2039 "\"suppressedNvPairsList\": ["
2041 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2042 "\"suppressedNvPairNames\": [\"name1\"]"
2047 char * json_command_list_dodgy_event_domain =
2049 "\"commandList\": ["
2052 "\"commandType\": \"throttlingSpecification\", "
2053 "\"eventDomainThrottleSpecification\": {"
2054 "\"eventDomain\": \"dodgyEventDomain\", "
2055 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2056 "\"suppressedNvPairsList\": ["
2058 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2059 "\"suppressedNvPairNames\": [\"name1\"]"
2064 char * json_command_list_dodgy_field_names_key =
2066 "\"commandList\": ["
2069 "\"commandType\": \"throttlingSpecification\", "
2070 "\"eventDomainThrottleSpecification\": {"
2071 "\"eventDomain\": \"fault\", "
2072 "\"suppressedNvPairsList\": ["
2074 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2075 "\"suppressedNvPairNames\": [\"name1\"]"
2080 char * json_command_list_dodgy_pair_names_list_key =
2082 "\"commandList\": ["
2085 "\"commandType\": \"throttlingSpecification\", "
2086 "\"eventDomainThrottleSpecification\": {"
2087 "\"eventDomain\": \"fault\", "
2088 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2089 "\"dodgySuppressedNvPairsListKey\": ["
2091 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2092 "\"suppressedNvPairNames\": [\"name1\"]"
2097 char * json_command_list_dodgy_pair_field_name_key =
2099 "\"commandList\": ["
2102 "\"commandType\": \"throttlingSpecification\", "
2103 "\"eventDomainThrottleSpecification\": {"
2104 "\"eventDomain\": \"fault\", "
2105 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2106 "\"suppressedNvPairsList\": ["
2108 "\"dodgyNvPairFieldNameKey\": \"alarmAdditionalInformation\", "
2109 "\"suppressedNvPairNames\": [\"name1\"]"
2114 char * json_command_list_dodgy_pair_names_key =
2116 "\"commandList\": ["
2119 "\"commandType\": \"throttlingSpecification\", "
2120 "\"eventDomainThrottleSpecification\": {"
2121 "\"eventDomain\": \"fault\", "
2122 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2123 "\"suppressedNvPairsList\": ["
2125 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2126 "\"dodgySuppressedNvPairNamesKey\": [\"name1\"]"
2131 char * json_command_list_dodgy_depth =
2133 "\"commandList\": ["
2136 "\"commandType\": \"throttlingSpecification\", "
2137 "\"eventDomainThrottleSpecification\": {"
2138 "\"eventDomain\": \"fault\", "
2139 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2140 "\"suppressedNvPairsList\": ["
2142 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2143 "\"dodgySuppressedNvPairNamesKey\": "
2144 "[\"name1\", [[[[[[[[]]]]]]]]]"
2149 char * expected_throttle_state_dodgy_field_names_key =
2151 "\"eventThrottlingState\": {"
2152 "\"eventThrottlingMode\": \"throttled\", "
2153 "\"eventDomainThrottleSpecificationList\": ["
2155 "\"eventDomain\": \"fault\", "
2156 "\"suppressedNvPairsList\": ["
2158 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2159 "\"suppressedNvPairNames\": [\"name1\"]"
2165 char * expected_throttle_state_dodgy_pair_names_list_key =
2167 "\"eventThrottlingState\": {"
2168 "\"eventThrottlingMode\": \"throttled\", "
2169 "\"eventDomainThrottleSpecificationList\": ["
2171 "\"eventDomain\": \"fault\", "
2172 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2178 char * expected_throttle_state_dodgy_pair_field_name_key =
2180 "\"eventThrottlingState\": {"
2181 "\"eventThrottlingMode\": \"throttled\", "
2182 "\"eventDomainThrottleSpecificationList\": ["
2184 "\"eventDomain\": \"fault\", "
2185 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2191 char * expected_throttle_state_dodgy_pair_names_key =
2193 "\"eventThrottlingState\": {"
2194 "\"eventThrottlingMode\": \"throttled\", "
2195 "\"eventDomainThrottleSpecificationList\": ["
2197 "\"eventDomain\": \"fault\", "
2198 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2204 char * json_command_lists[] = {
2205 json_command_list_dodgy_command,
2206 json_command_list_dodgy_spec,
2207 json_command_list_dodgy_event_domain_key,
2208 json_command_list_dodgy_event_domain,
2209 json_command_list_dodgy_depth,
2210 json_command_list_dodgy_field_names_key,
2211 json_command_list_dodgy_pair_names_list_key,
2212 json_command_list_dodgy_pair_field_name_key,
2213 json_command_list_dodgy_pair_names_key
2216 char * expected_posts[] = {
2217 expected_throttle_state_normal,
2218 expected_throttle_state_normal,
2219 expected_throttle_state_normal,
2220 expected_throttle_state_normal,
2221 expected_throttle_state_normal,
2222 expected_throttle_state_dodgy_field_names_key,
2223 expected_throttle_state_dodgy_pair_names_list_key,
2224 expected_throttle_state_dodgy_pair_field_name_key,
2225 expected_throttle_state_dodgy_pair_names_key
2228 const int num_commands =
2229 sizeof(json_command_lists) / sizeof(json_command_lists[0]);
2230 const int num_posts =
2231 sizeof(expected_posts) / sizeof(expected_posts[0]);
2232 assert(num_commands == num_posts);
2234 /***************************************************************************/
2235 /* Initialize and provide a specification with a single nvpair with a */
2236 /* single sub-field suppressed. */
2237 /***************************************************************************/
2238 evel_throttle_initialize();
2241 for (ii = 0; ii < num_commands; ii++)
2243 EVEL_DEBUG("Testing commandList[%d] = %s\n", ii, json_command_lists[ii]);
2244 handle_json_response(json_command_lists[ii], &post);
2246 /*************************************************************************/
2247 /* Check that throttling is in a normal state - because we ignored the */
2248 /* command / ..... */
2249 /*************************************************************************/
2250 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
2252 assert(evel_get_throttle_spec(domain) == NULL);
2254 if (expected_posts[ii] == expected_throttle_state_normal)
2256 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
2260 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2262 assert(post.memory == NULL);
2264 /*************************************************************************/
2265 /* Request and verify the throttling state. */
2266 /*************************************************************************/
2267 handle_json_response(json_command_list_provide, &post);
2268 assert(post.memory != NULL);
2269 compare_strings(expected_posts[ii],
2271 strlen(expected_posts[ii]),
2272 "Throttle State Normal");
2277 evel_throttle_terminate();
2280 void test_encode_fault_throttled()
2284 /***************************************************************************/
2285 /* We also test suppression of the event header parameters here. */
2286 /***************************************************************************/
2287 char * json_command_list =
2289 "\"commandList\": ["
2292 "\"commandType\": \"throttlingSpecification\", "
2293 "\"eventDomainThrottleSpecification\": {"
2294 "\"eventDomain\": \"fault\", "
2295 "\"suppressedFieldNames\": ["
2296 "\"alarmInterfaceA\", "
2298 "\"reportingEntityId\", "
2300 "\"suppressedNvPairsList\": ["
2302 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2303 "\"suppressedNvPairNames\": [\"name3\", \"name4\"]"
2310 "\"commonEventHeader\": {"
2311 "\"domain\": \"fault\", "
2312 "\"eventId\": \"122\", "
2313 "\"functionalRole\": \"UNIT TEST\", "
2314 "\"lastEpochMicrosec\": 1000002, "
2315 "\"priority\": \"Normal\", "
2316 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2317 "\"sequence\": 122, "
2318 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2319 "\"startEpochMicrosec\": 1000002, "
2322 "\"faultFields\": {"
2323 "\"alarmCondition\": \"My alarm condition\", "
2324 "\"eventSeverity\": \"MAJOR\", "
2325 "\"eventSourceType\": \"other\", "
2326 "\"specificProblem\": \"It broke very badly\", "
2327 "\"vfStatus\": \"Active\", "
2328 "\"faultFieldsVersion\": 1.1, "
2329 "\"alarmAdditionalInformation\": ["
2330 "{\"name\": \"name1\", "
2331 "\"value\": \"value1\"}, "
2332 "{\"name\": \"name2\", "
2333 "\"value\": \"value2\"}]"
2336 /***************************************************************************/
2337 /* Initialize and provide a specification with a single fault suppressed. */
2338 /***************************************************************************/
2339 evel_throttle_initialize();
2340 handle_json_response(json_command_list, &post);
2342 /***************************************************************************/
2343 /* Check that the domain is throttled. */
2344 /***************************************************************************/
2345 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2346 assert(post.memory == NULL);
2348 size_t json_size = 0;
2349 char json_body[EVEL_MAX_JSON_BODY];
2350 evel_set_next_event_sequence(122);
2351 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
2352 "It broke very badly",
2353 EVEL_PRIORITY_NORMAL,
2354 EVEL_SEVERITY_MAJOR);
2355 assert(fault != NULL);
2356 evel_fault_type_set(fault, "Bad things happen...");
2357 evel_fault_addl_info_add(fault, "name1", "value1");
2358 evel_fault_addl_info_add(fault, "name2", "value2");
2360 /***************************************************************************/
2361 /* Suppressed fields. */
2362 /***************************************************************************/
2363 evel_fault_interface_set(fault, "My Interface Card");
2364 evel_fault_addl_info_add(fault, "name3", "value3");
2365 evel_fault_addl_info_add(fault, "name4", "value4");
2367 json_size = evel_json_encode_event(
2368 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
2369 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
2370 assert((json_size == strlen(json_body)) && "Bad size returned");
2372 evel_free_event(fault);
2373 evel_throttle_terminate();
2376 void test_encode_measurement_throttled()
2380 /***************************************************************************/
2381 /* We also test suppression of the event header parameters here. */
2382 /***************************************************************************/
2383 char * json_command_list =
2385 "\"commandList\": ["
2388 "\"commandType\": \"throttlingSpecification\", "
2389 "\"eventDomainThrottleSpecification\": {"
2390 "\"eventDomain\": \"measurementsForVfScaling\", "
2391 "\"suppressedFieldNames\": ["
2393 "\"vnfcScalingMetric\", "
2394 "\"numberOfMediaPortsInUse\", "
2395 "\"aggregateCpuUsage\", "
2398 "\"memoryConfigured\", "
2399 "\"meanRequestLatency\", "
2400 "\"latencyDistribution\", "
2401 "\"concurrentSessions\", "
2402 "\"configuredEntities\", "
2404 "\"reportingEntityId\", "
2406 "\"suppressedNvPairsList\": ["
2408 "\"nvPairFieldName\": \"cpuUsageArray\", "
2409 "\"suppressedNvPairNames\": [\"cpu3\", \"cpu4\"]"
2412 "\"nvPairFieldName\": \"filesystemUsageArray\", "
2413 "\"suppressedNvPairNames\": [\"00-11-22\", \"33-44-55\"]"
2416 "\"nvPairFieldName\": \"vNicUsageArray\", "
2417 "\"suppressedNvPairNames\": [\"eth1\", \"eth0\"]"
2420 "\"nvPairFieldName\": \"featureUsageArray\", "
2421 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2424 "\"nvPairFieldName\": \"codecUsageArray\", "
2425 "\"suppressedNvPairNames\": [\"G729ab\"]"
2428 "\"nvPairFieldName\": \"additionalMeasurements\", "
2429 "\"suppressedNvPairNames\": [\"Group2\"]"
2437 "{\"commonEventHeader\": {"
2438 "\"domain\": \"measurementsForVfScaling\", "
2439 "\"eventId\": \"123\", "
2440 "\"functionalRole\": \"UNIT TEST\", "
2441 "\"lastEpochMicrosec\": 1000002, "
2442 "\"priority\": \"Normal\", "
2443 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2444 "\"sequence\": 123, "
2445 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2446 "\"startEpochMicrosec\": 1000002, "
2449 "\"measurementsForVfScalingFields\": "
2451 "\"measurementInterval\": 5.500000, "
2452 "\"cpuUsageArray\": ["
2453 "{\"cpuIdentifier\": \"cpu1\", "
2454 "\"percentUsage\": 11.110000}, "
2455 "{\"cpuIdentifier\": \"cpu2\", "
2456 "\"percentUsage\": 22.220000}], "
2457 "\"filesystemUsageArray\": ["
2458 "{\"blockConfigured\": 500.110000, "
2459 "\"blockIops\": 77, "
2460 "\"blockUsed\": 500.220000, "
2461 "\"ephemeralConfigured\": 500.110000, "
2462 "\"ephemeralIops\": 88, "
2463 "\"ephemeralUsed\": 600.220000, "
2464 "\"filesystemName\": \"66-77-88\"}], "
2465 "\"featureUsageArray\": ["
2466 "{\"featureIdentifier\": \"FeatureA\", "
2467 "\"featureUtilization\": 123}], "
2468 "\"codecUsageArray\": ["
2469 "{\"codecIdentifier\": \"G711a\", "
2470 "\"numberInUse\": 91}], "
2471 "\"additionalMeasurements\": ["
2472 "{\"name\": \"Group1\", "
2473 "\"measurements\": ["
2474 "{\"name\": \"Name1\", "
2475 "\"value\": \"Value1\"}]}], "
2476 "\"measurementsForVfScalingVersion\": 1.1}}}";
2478 /***************************************************************************/
2479 /* Initialize and provide a specification with a single fault suppressed. */
2480 /***************************************************************************/
2481 evel_throttle_initialize();
2482 handle_json_response(json_command_list, &post);
2484 /***************************************************************************/
2485 /* Check that the domain is throttled. */
2486 /***************************************************************************/
2487 assert(evel_get_throttle_spec(EVEL_DOMAIN_MEASUREMENT) != NULL);
2488 assert(post.memory == NULL);
2490 size_t json_size = 0;
2491 char json_body[EVEL_MAX_JSON_BODY];
2492 evel_set_next_event_sequence(123);
2493 EVENT_MEASUREMENT * measurement = evel_new_measurement(5.5);
2494 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
2495 MEASUREMENT_VNIC_USE * vnic_use = NULL;
2496 assert(measurement != NULL);
2498 evel_measurement_type_set(measurement, "Perf management...");
2499 evel_measurement_conc_sess_set(measurement, 1);
2500 evel_measurement_cfg_ents_set(measurement, 2);
2501 evel_measurement_mean_req_lat_set(measurement, 4.4);
2502 evel_measurement_mem_cfg_set(measurement, 6.6);
2503 evel_measurement_mem_used_set(measurement, 3.3);
2504 evel_measurement_request_rate_set(measurement, 7);
2505 evel_measurement_agg_cpu_use_set(measurement, 8.8);
2506 evel_measurement_cpu_use_add(measurement, "cpu1", 11.11);
2507 evel_measurement_cpu_use_add(measurement, "cpu2", 22.22);
2508 evel_measurement_cpu_use_add(measurement, "cpu3", 33.33);
2509 evel_measurement_cpu_use_add(measurement, "cpu4", 44.44);
2510 evel_measurement_fsys_use_add(measurement, "00-11-22",
2512 200.11, 200.22, 44);
2513 evel_measurement_fsys_use_add(measurement, "33-44-55",
2515 400.11, 400.22, 66);
2516 evel_measurement_fsys_use_add(measurement, "66-77-88",
2518 600.11, 600.22, 88);
2520 bucket = evel_new_meas_latency_bucket(20);
2521 evel_meas_latency_bucket_add(measurement, bucket);
2523 bucket = evel_new_meas_latency_bucket(30);
2524 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
2525 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
2526 evel_meas_latency_bucket_add(measurement, bucket);
2528 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
2529 evel_vnic_use_bcast_pkt_in_set(vnic_use, 1);
2530 evel_vnic_use_bcast_pkt_out_set(vnic_use, 2);
2531 evel_vnic_use_mcast_pkt_in_set(vnic_use, 5);
2532 evel_vnic_use_mcast_pkt_out_set(vnic_use, 6);
2533 evel_vnic_use_ucast_pkt_in_set(vnic_use, 7);
2534 evel_vnic_use_ucast_pkt_out_set(vnic_use, 8);
2535 evel_meas_vnic_use_add(measurement, vnic_use);
2537 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
2538 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
2539 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
2540 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
2541 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
2542 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
2543 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
2544 evel_meas_vnic_use_add(measurement, vnic_use);
2546 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
2547 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
2548 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
2549 evel_measurement_codec_use_add(measurement, "G711a", 91);
2550 evel_measurement_codec_use_add(measurement, "G729ab", 92);
2551 evel_measurement_media_port_use_set(measurement, 1234);
2552 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
2553 evel_measurement_custom_measurement_add(measurement,
2554 "Group1", "Name1", "Value1");
2555 evel_measurement_custom_measurement_add(measurement,
2556 "Group2", "Name1", "Value1");
2557 evel_measurement_custom_measurement_add(measurement,
2558 "Group2", "Name2", "Value2");
2560 json_size = evel_json_encode_event(
2561 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
2562 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
2563 assert((json_size == strlen(json_body)) && "Bad size returned");
2565 evel_free_event(measurement);
2566 evel_throttle_terminate();
2569 void test_encode_mobile_throttled()
2573 /***************************************************************************/
2574 /* We also test suppression of the event header parameters here. */
2575 /***************************************************************************/
2576 char * json_command_list =
2578 "\"commandList\": ["
2581 "\"commandType\": \"throttlingSpecification\", "
2582 "\"eventDomainThrottleSpecification\": {"
2583 "\"eventDomain\": \"mobileFlow\", "
2584 "\"suppressedFieldNames\": ["
2585 "\"applicationType\", "
2586 "\"appProtocolType\", "
2587 "\"appProtocolVersion\", "
2589 "\"connectionType\", "
2591 "\"gtpProtocolType\", "
2600 "\"otherFunctionalRole\", "
2602 "\"radioAccessTechnology\", "
2604 "\"samplingAlgorithm\", "
2609 "\"reportingEntityId\", "
2611 "\"suppressedNvPairsList\": ["
2618 "{\"commonEventHeader\": {"
2619 "\"domain\": \"mobileFlow\", "
2620 "\"eventId\": \"1242\", "
2621 "\"functionalRole\": \"UNIT TEST\", "
2622 "\"lastEpochMicrosec\": 1000002, "
2623 "\"priority\": \"Normal\", "
2624 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2625 "\"sequence\": 1242, "
2626 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2627 "\"startEpochMicrosec\": 1000002, "
2630 "\"mobileFlowFields\": {"
2631 "\"flowDirection\": \"Inbound\", "
2632 "\"gtpPerFlowMetrics\": {"
2633 "\"avgBitErrorRate\": 132.000100, "
2634 "\"avgPacketDelayVariation\": 31.200000, "
2635 "\"avgPacketLatency\": 101, "
2636 "\"avgReceiveThroughput\": 2101, "
2637 "\"avgTransmitThroughput\": 501, "
2638 "\"flowActivationEpoch\": 1470409422, "
2639 "\"flowActivationMicrosec\": 988, "
2640 "\"flowDeactivationEpoch\": 1470409432, "
2641 "\"flowDeactivationMicrosec\": 12, "
2642 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
2643 "\"flowStatus\": \"Inactive\", "
2644 "\"maxPacketDelayVariation\": 88, "
2645 "\"numActivationFailures\": 4, "
2646 "\"numBitErrors\": 18, "
2647 "\"numBytesReceived\": 123655, "
2648 "\"numBytesTransmitted\": 4562, "
2649 "\"numDroppedPackets\": 1, "
2650 "\"numL7BytesReceived\": 13, "
2651 "\"numL7BytesTransmitted\": 11, "
2652 "\"numLostPackets\": 2, "
2653 "\"numOutOfOrderPackets\": 4, "
2654 "\"numPacketErrors\": 8, "
2655 "\"numPacketsReceivedExclRetrans\": 900, "
2656 "\"numPacketsReceivedInclRetrans\": 902, "
2657 "\"numPacketsTransmittedInclRetrans\": 303, "
2658 "\"numRetries\": 7, "
2659 "\"numTimeouts\": 3, "
2660 "\"numTunneledL7BytesReceived\": 1, "
2661 "\"roundTripTime\": 111, "
2662 "\"timeToFirstByte\": 226, "
2663 "\"ipTosCountList\": ["
2667 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
2668 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
2669 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
2670 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
2671 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
2672 "\"durConnectionFailedStatus\": 12, "
2673 "\"durTunnelFailedStatus\": 13, "
2674 "\"flowActivatedBy\": \"Remote\", "
2675 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
2676 "\"flowDeactivatedBy\": \"Remote\", "
2677 "\"gtpConnectionStatus\": \"Connected\", "
2678 "\"gtpTunnelStatus\": \"Not tunneling\", "
2679 "\"largePacketRtt\": 80, "
2680 "\"largePacketThreshold\": 600.000000, "
2681 "\"maxReceiveBitRate\": 1357924680, "
2682 "\"maxTransmitBitRate\": 235711, "
2683 "\"numGtpEchoFailures\": 1, "
2684 "\"numGtpTunnelErrors\": 4, "
2685 "\"numHttpErrors\": 2"
2687 "\"ipProtocolType\": \"UDP\", "
2688 "\"ipVersion\": \"IPv6\", "
2689 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
2690 "\"otherEndpointPort\": 2342, "
2691 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
2692 "\"reportingEndpointPort\": 4322"
2695 /***************************************************************************/
2696 /* Initialize and provide a specification with a single fault suppressed. */
2697 /***************************************************************************/
2698 evel_throttle_initialize();
2699 handle_json_response(json_command_list, &post);
2701 /***************************************************************************/
2702 /* Check that the domain is throttled. */
2703 /***************************************************************************/
2704 assert(evel_get_throttle_spec(EVEL_DOMAIN_MOBILE_FLOW) != NULL);
2705 assert(post.memory == NULL);
2707 size_t json_size = 0;
2708 char json_body[EVEL_MAX_JSON_BODY];
2709 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
2710 EVENT_MOBILE_FLOW * mobile_flow = NULL;
2712 /***************************************************************************/
2714 /***************************************************************************/
2715 evel_set_next_event_sequence(1242);
2717 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
2747 assert(metrics != NULL);
2749 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
2750 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
2751 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
2752 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
2753 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
2754 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
2755 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
2756 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
2757 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
2758 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
2759 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
2760 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
2761 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
2762 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
2763 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
2764 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
2765 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
2766 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
2767 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
2768 evel_mobile_gtp_metrics_qci_cos_count_add(
2769 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
2770 evel_mobile_gtp_metrics_qci_cos_count_add(
2771 metrics, EVEL_QCI_COS_LTE_65, 122);
2773 mobile_flow = evel_new_mobile_flow("Inbound",
2781 assert(mobile_flow != NULL);
2783 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
2784 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
2785 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
2786 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
2787 evel_mobile_flow_cid_set(mobile_flow, "65535");
2788 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
2789 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
2790 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
2791 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
2792 evel_mobile_flow_http_header_set(mobile_flow,
2793 "http://www.something.com");
2794 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
2795 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
2796 evel_mobile_flow_lac_set(mobile_flow, "1");
2797 evel_mobile_flow_mcc_set(mobile_flow, "410");
2798 evel_mobile_flow_mnc_set(mobile_flow, "04");
2799 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
2800 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
2801 evel_mobile_flow_rac_set(mobile_flow, "514");
2802 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
2803 evel_mobile_flow_sac_set(mobile_flow, "1");
2804 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
2805 evel_mobile_flow_tac_set(mobile_flow, "2099");
2806 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
2807 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
2809 json_size = evel_json_encode_event(
2810 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
2811 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
2812 assert((json_size == strlen(json_body)) && "Bad size returned");
2814 evel_free_event(mobile_flow);
2815 evel_throttle_terminate();
2818 void test_encode_other_throttled()
2822 /***************************************************************************/
2823 /* We also test suppression of the event header parameters here. */
2824 /***************************************************************************/
2825 char * json_command_list =
2827 "\"commandList\": ["
2830 "\"commandType\": \"throttlingSpecification\", "
2831 "\"eventDomainThrottleSpecification\": {"
2832 "\"eventDomain\": \"other\", "
2833 "\"suppressedFieldNames\": ["
2835 "\"reportingEntityId\", "
2837 "\"suppressedNvPairsList\": ["
2844 "{\"commonEventHeader\": {"
2845 "\"domain\": \"other\", "
2846 "\"eventId\": \"129\", "
2847 "\"functionalRole\": \"UNIT TEST\", "
2848 "\"lastEpochMicrosec\": 1000002, "
2849 "\"priority\": \"Normal\", "
2850 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2851 "\"sequence\": 129, "
2852 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2853 "\"startEpochMicrosec\": 1000002, "
2856 "\"otherFields\": ["
2857 "{\"name\": \"Other field 1\", "
2858 "\"value\": \"Other value 1\"}, "
2859 "{\"name\": \"Other field 2\", "
2860 "\"value\": \"Other value 2\"}"
2864 /***************************************************************************/
2865 /* Initialize and provide a specification with a single fault suppressed. */
2866 /***************************************************************************/
2867 evel_throttle_initialize();
2868 handle_json_response(json_command_list, &post);
2870 /***************************************************************************/
2871 /* Check that the domain is throttled. */
2872 /***************************************************************************/
2873 assert(evel_get_throttle_spec(EVEL_DOMAIN_OTHER) != NULL);
2874 assert(post.memory == NULL);
2876 size_t json_size = 0;
2877 char json_body[EVEL_MAX_JSON_BODY];
2878 EVENT_OTHER * other = NULL;
2879 evel_set_next_event_sequence(129);
2880 other = evel_new_other();
2881 assert(other != NULL);
2882 evel_other_type_set(other, "Other Type");
2883 evel_other_field_add(other,
2886 evel_other_field_add(other,
2890 json_size = evel_json_encode_event(
2891 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
2892 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
2893 assert((json_size == strlen(json_body)) && "Bad size returned");
2895 evel_free_event(other);
2896 evel_throttle_terminate();
2899 void test_encode_report_throttled()
2903 /***************************************************************************/
2904 /* We also test suppression of the event header parameters here. */
2905 /***************************************************************************/
2906 char * json_command_list =
2908 "\"commandList\": ["
2911 "\"commandType\": \"throttlingSpecification\", "
2912 "\"eventDomainThrottleSpecification\": {"
2913 "\"eventDomain\": \"report\", "
2914 "\"suppressedFieldNames\": ["
2916 "\"reportingEntityId\", "
2918 "\"suppressedNvPairsList\": ["
2920 "\"nvPairFieldName\": \"featureUsageArray\", "
2921 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2924 "\"nvPairFieldName\": \"additionalMeasurements\", "
2925 "\"suppressedNvPairNames\": [\"Group2\"]"
2933 "{\"commonEventHeader\": {"
2934 "\"domain\": \"measurementsForVfReporting\", "
2935 "\"eventId\": \"125\", "
2936 "\"functionalRole\": \"UNIT TEST\", "
2937 "\"lastEpochMicrosec\": 1000002, "
2938 "\"priority\": \"Normal\", "
2939 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2940 "\"sequence\": 125, "
2941 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2942 "\"startEpochMicrosec\": 1000002, "
2945 "\"measurementsForVfReportingFields\": "
2946 "{\"measurementInterval\": 1.100000, "
2947 "\"featureUsageArray\": ["
2948 "{\"featureIdentifier\": \"FeatureA\", "
2949 "\"featureUtilization\": 123}], "
2950 "\"additionalMeasurements\": ["
2951 "{\"name\": \"Group1\", "
2952 "\"measurements\": ["
2953 "{\"name\": \"Name1\", "
2954 "\"value\": \"Value1\"}]}], "
2955 "\"measurementFieldsVersion\": 1.1}}}";
2957 /***************************************************************************/
2958 /* Initialize and provide a specification with a single fault suppressed. */
2959 /***************************************************************************/
2960 evel_throttle_initialize();
2961 handle_json_response(json_command_list, &post);
2963 /***************************************************************************/
2964 /* Check that the domain is throttled. */
2965 /***************************************************************************/
2966 assert(evel_get_throttle_spec(EVEL_DOMAIN_REPORT) != NULL);
2967 assert(post.memory == NULL);
2969 size_t json_size = 0;
2970 char json_body[EVEL_MAX_JSON_BODY];
2971 EVENT_REPORT * report = NULL;
2973 /***************************************************************************/
2975 /***************************************************************************/
2976 evel_set_next_event_sequence(125);
2977 report = evel_new_report(1.1);
2978 assert(report != NULL);
2979 evel_report_type_set(report, "Perf reporting...");
2980 evel_report_feature_use_add(report, "FeatureA", 123);
2981 evel_report_feature_use_add(report, "FeatureB", 567);
2982 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
2983 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
2984 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
2986 json_size = evel_json_encode_event(
2987 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
2988 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
2989 assert((json_size == strlen(json_body)) && "Bad size returned");
2991 evel_free_event(report);
2992 evel_throttle_terminate();
2995 void test_encode_service_throttled()
2999 /***************************************************************************/
3000 /* We also test suppression of the event header parameters here. */
3001 /***************************************************************************/
3002 char * json_command_list =
3004 "\"commandList\": ["
3007 "\"commandType\": \"throttlingSpecification\", "
3008 "\"eventDomainThrottleSpecification\": {"
3009 "\"eventDomain\": \"serviceEvents\", "
3010 "\"suppressedFieldNames\": ["
3013 "\"codecSelected\", "
3014 "\"codecSelectedTranscoding\", "
3015 "\"endOfCallVqmSummaries\", "
3018 "\"reportingEntityId\", "
3020 "\"suppressedNvPairsList\": ["
3022 "\"nvPairFieldName\": \"additionalFields\", "
3023 "\"suppressedNvPairNames\": [\"Name1\", \"Name3\"]"
3031 "{\"commonEventHeader\": {"
3032 "\"domain\": \"serviceEvents\", "
3033 "\"eventId\": \"2000\", "
3034 "\"functionalRole\": \"UNIT TEST\", "
3035 "\"lastEpochMicrosec\": 1000002, "
3036 "\"priority\": \"Normal\", "
3037 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3038 "\"sequence\": 2000, "
3039 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3040 "\"startEpochMicrosec\": 1000002, "
3043 "\"serviceEventsFields\": {"
3044 "\"eventInstanceIdentifier\": "
3046 "\"vendorId\": \"vendor_x_id\", "
3047 "\"eventId\": \"vendor_x_event_id\", "
3048 "\"productId\": \"vendor_x_product_id\", "
3049 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3050 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3052 "\"serviceEventsFieldsVersion\": 1.1, "
3053 "\"additionalFields\": ["
3054 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
3055 "{\"name\": \"Name4\", \"value\": \"Value4\"}]"
3058 /***************************************************************************/
3059 /* Initialize and provide a specification with a single fault suppressed. */
3060 /***************************************************************************/
3061 evel_throttle_initialize();
3062 handle_json_response(json_command_list, &post);
3064 /***************************************************************************/
3065 /* Check that the domain is throttled. */
3066 /***************************************************************************/
3067 assert(evel_get_throttle_spec(EVEL_DOMAIN_SERVICE) != NULL);
3068 assert(post.memory == NULL);
3070 size_t json_size = 0;
3071 char json_body[EVEL_MAX_JSON_BODY];
3072 EVENT_SERVICE * event = NULL;
3073 evel_set_next_event_sequence(2000);
3074 event = evel_new_service("vendor_x_id", "vendor_x_event_id");
3075 assert(event != NULL);
3076 evel_service_type_set(event, "Service Event");
3077 evel_service_product_id_set(event, "vendor_x_product_id");
3078 evel_service_subsystem_id_set(event, "vendor_x_subsystem_id");
3079 evel_service_friendly_name_set(event, "vendor_x_frieldly_name");
3080 evel_service_correlator_set(event, "vendor_x_correlator");
3081 evel_service_codec_set(event, "PCMA");
3082 evel_service_codec_set(event, "PCMA");
3083 evel_service_callee_codec_set(event, "PCMA");
3084 evel_service_caller_codec_set(event, "G729A");
3085 evel_service_rtcp_data_set(event, "some_rtcp_data");
3086 evel_service_adjacency_name_set(event, "vendor_x_adjacency");
3087 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
3088 evel_service_endpoint_jitter_set(event, 66);
3089 evel_service_endpoint_rtp_oct_disc_set(event, 100);
3090 evel_service_endpoint_rtp_oct_recv_set(event, 200);
3091 evel_service_endpoint_rtp_oct_sent_set(event, 300);
3092 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
3093 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
3094 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
3095 evel_service_local_jitter_set(event, 99);
3096 evel_service_local_rtp_oct_disc_set(event, 150);
3097 evel_service_local_rtp_oct_recv_set(event, 250);
3098 evel_service_local_rtp_oct_sent_set(event, 350);
3099 evel_service_local_rtp_pkt_disc_set(event, 450);
3100 evel_service_local_rtp_pkt_recv_set(event, 550);
3101 evel_service_local_rtp_pkt_sent_set(event, 650);
3102 evel_service_mos_cqe_set(event, 12.255);
3103 evel_service_packets_lost_set(event, 157);
3104 evel_service_packet_loss_percent_set(event, 0.232);
3105 evel_service_r_factor_set(event, 11);
3106 evel_service_round_trip_delay_set(event, 15);
3107 evel_service_phone_number_set(event, "0888888888");
3108 evel_service_addl_field_add(event, "Name1", "Value1");
3109 evel_service_addl_field_add(event, "Name2", "Value2");
3110 evel_service_addl_field_add(event, "Name3", "Value3");
3111 evel_service_addl_field_add(event, "Name4", "Value4");
3112 json_size = evel_json_encode_event(
3113 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3114 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
3115 assert((json_size == strlen(json_body)) && "Bad size returned");
3117 evel_free_event(event);
3118 evel_throttle_terminate();
3121 void test_encode_signaling_throttled()
3125 /***************************************************************************/
3126 /* We also test suppression of the event header parameters here. */
3127 /***************************************************************************/
3128 char * json_command_list =
3130 "\"commandList\": ["
3133 "\"commandType\": \"throttlingSpecification\", "
3134 "\"eventDomainThrottleSpecification\": {"
3135 "\"eventDomain\": \"signaling\", "
3136 "\"suppressedFieldNames\": ["
3139 "\"reportingEntityId\", "
3141 "\"localIpAddress\", "
3143 "\"remoteIpAddress\", "
3145 "\"compressedSip\", "
3147 "\"suppressedNvPairsList\": ["
3154 "{\"commonEventHeader\": {"
3155 "\"domain\": \"signaling\", "
3156 "\"eventId\": \"2001\", "
3157 "\"functionalRole\": \"UNIT TEST\", "
3158 "\"lastEpochMicrosec\": 1000002, "
3159 "\"priority\": \"Normal\", "
3160 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3161 "\"sequence\": 2001, "
3162 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3163 "\"startEpochMicrosec\": 1000002, "
3166 "\"signalingFields\": {"
3167 "\"eventInstanceIdentifier\": "
3169 "\"vendorId\": \"vendor_x_id\", "
3170 "\"eventId\": \"vendor_x_event_id\", "
3171 "\"productId\": \"vendor_x_product_id\", "
3172 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3173 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3175 "\"signalingFieldsVersion\": 1.1"
3178 /***************************************************************************/
3179 /* Initialize and provide a specification with a single fault suppressed. */
3180 /***************************************************************************/
3181 evel_throttle_initialize();
3182 handle_json_response(json_command_list, &post);
3184 /***************************************************************************/
3185 /* Check that the domain is throttled. */
3186 /***************************************************************************/
3187 assert(evel_get_throttle_spec(EVEL_DOMAIN_SIGNALING) != NULL);
3188 assert(post.memory == NULL);
3190 size_t json_size = 0;
3191 char json_body[EVEL_MAX_JSON_BODY];
3192 EVENT_SIGNALING * event = NULL;
3193 evel_set_next_event_sequence(2001);
3194 event = evel_new_signaling("vendor_x_id", "vendor_x_event_id");
3195 assert(event != NULL);
3196 evel_signaling_type_set(event, "Signaling");
3197 evel_signaling_product_id_set(event, "vendor_x_product_id");
3198 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
3199 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
3200 evel_signaling_correlator_set(event, "vendor_x_correlator");
3201 evel_signaling_local_ip_address_set(event, "1.0.3.1");
3202 evel_signaling_local_port_set(event, "1031");
3203 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
3204 evel_signaling_remote_port_set(event, "5330");
3205 evel_signaling_compressed_sip_set(event, "compressed_sip");
3206 evel_signaling_summary_sip_set(event, "summary_sip");
3207 json_size = evel_json_encode_event(
3208 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3209 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
3210 assert((json_size == strlen(json_body)) && "Bad size returned");
3212 evel_free_event(event);
3213 evel_throttle_terminate();
3216 void test_encode_state_change_throttled()
3220 /***************************************************************************/
3221 /* We also test suppression of the event header parameters here. */
3222 /***************************************************************************/
3223 char * json_command_list =
3225 "\"commandList\": ["
3228 "\"commandType\": \"throttlingSpecification\", "
3229 "\"eventDomainThrottleSpecification\": {"
3230 "\"eventDomain\": \"stateChange\", "
3231 "\"suppressedFieldNames\": ["
3233 "\"reportingEntityId\", "
3235 "\"suppressedNvPairsList\": ["
3237 "\"nvPairFieldName\": \"additionalFields\", "
3238 "\"suppressedNvPairNames\": [\"Name1\"]"
3246 "{\"commonEventHeader\": {"
3247 "\"domain\": \"stateChange\", "
3248 "\"eventId\": \"128\", "
3249 "\"functionalRole\": \"UNIT TEST\", "
3250 "\"lastEpochMicrosec\": 1000002, "
3251 "\"priority\": \"Normal\", "
3252 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3253 "\"sequence\": 128, "
3254 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3255 "\"startEpochMicrosec\": 1000002, "
3258 "\"stateChangeFields\": {"
3259 "\"newState\": \"inService\", "
3260 "\"oldState\": \"outOfService\", "
3261 "\"stateInterface\": \"An Interface\", "
3262 "\"additionalFields\": ["
3263 "{\"name\": \"Name2\", "
3264 "\"value\": \"Value2\"}"
3266 "\"stateChangeFieldsVersion\": 1.1"
3269 /***************************************************************************/
3270 /* Initialize and provide a specification with a single fault suppressed. */
3271 /***************************************************************************/
3272 evel_throttle_initialize();
3273 handle_json_response(json_command_list, &post);
3275 /***************************************************************************/
3276 /* Check that the domain is throttled. */
3277 /***************************************************************************/
3278 assert(evel_get_throttle_spec(EVEL_DOMAIN_STATE_CHANGE) != NULL);
3279 assert(post.memory == NULL);
3281 size_t json_size = 0;
3282 char json_body[EVEL_MAX_JSON_BODY];
3283 EVENT_STATE_CHANGE * state_change = NULL;
3284 evel_set_next_event_sequence(128);
3285 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
3286 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
3288 assert(state_change != NULL);
3289 evel_state_change_type_set(state_change, "SC Type");
3290 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
3291 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
3293 json_size = evel_json_encode_event(
3294 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
3295 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
3296 assert((json_size == strlen(json_body)) && "Bad size returned");
3298 evel_free_event(state_change);
3299 evel_throttle_terminate();
3302 void test_encode_syslog_throttled()
3306 /***************************************************************************/
3307 /* We also test suppression of the event header parameters here. */
3308 /***************************************************************************/
3309 char * json_command_list =
3311 "\"commandList\": ["
3314 "\"commandType\": \"throttlingSpecification\", "
3315 "\"eventDomainThrottleSpecification\": {"
3316 "\"eventDomain\": \"syslog\", "
3317 "\"suppressedFieldNames\": ["
3318 "\"eventSourceHost\", "
3319 "\"syslogFacility\", "
3321 "\"syslogProcId\", "
3325 "\"reportingEntityId\", "
3327 "\"suppressedNvPairsList\": ["
3329 "\"nvPairFieldName\": \"additionalFields\", "
3330 "\"suppressedNvPairNames\": [\"Name2\"]"
3338 "{\"commonEventHeader\": {"
3339 "\"domain\": \"syslog\", "
3340 "\"eventId\": \"126\", "
3341 "\"functionalRole\": \"UNIT TEST\", "
3342 "\"lastEpochMicrosec\": 1000002, "
3343 "\"priority\": \"Normal\", "
3344 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3345 "\"sequence\": 126, "
3346 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3347 "\"startEpochMicrosec\": 1000002, "
3350 "\"syslogFields\": {"
3351 "\"eventSourceType\": \"virtualNetworkFunction\", "
3352 "\"syslogMsg\": \"SL Message\", "
3353 "\"syslogTag\": \"SL Tag\", "
3354 "\"syslogFieldsVersion\": 1.1, "
3355 "\"additionalFields\": ["
3356 "{\"name\": \"Name1\", "
3357 "\"value\": \"Value1\"}"
3361 /***************************************************************************/
3362 /* Initialize and provide a specification with a single fault suppressed. */
3363 /***************************************************************************/
3364 evel_throttle_initialize();
3365 handle_json_response(json_command_list, &post);
3367 /***************************************************************************/
3368 /* Check that the domain is throttled. */
3369 /***************************************************************************/
3370 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
3371 assert(post.memory == NULL);
3373 size_t json_size = 0;
3374 char json_body[EVEL_MAX_JSON_BODY];
3375 EVENT_SYSLOG * syslog = NULL;
3376 evel_set_next_event_sequence(126);
3377 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
3380 assert(syslog != NULL);
3381 evel_syslog_type_set(syslog, "SL Type");
3382 evel_syslog_event_source_host_set(syslog, "SL Host");
3383 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
3384 evel_syslog_proc_set(syslog, "SL Proc");
3385 evel_syslog_proc_id_set(syslog, 2);
3386 evel_syslog_version_set(syslog, 1);
3387 evel_syslog_s_data_set(syslog, "SL SDATA");
3388 evel_syslog_addl_field_add(syslog, "Name1", "Value1");
3389 evel_syslog_addl_field_add(syslog, "Name2", "Value2");
3391 json_size = evel_json_encode_event(
3392 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
3393 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
3394 assert((json_size == strlen(json_body)) && "Bad size returned");
3396 evel_free_event(syslog);
3397 evel_throttle_terminate();
3400 void test_encode_fault_with_escaping()
3404 "\"commonEventHeader\": {"
3405 "\"domain\": \"fault\", "
3406 "\"eventId\": \"122\", "
3407 "\"functionalRole\": \"UNIT TEST\", "
3408 "\"lastEpochMicrosec\": 1000002, "
3409 "\"priority\": \"Normal\", "
3410 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3411 "\"sequence\": 122, "
3412 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3413 "\"startEpochMicrosec\": 1000002, "
3414 "\"version\": 1.2, "
3415 "\"eventType\": \"Bad things happen...\\\\\", "
3416 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
3417 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
3419 "\"faultFields\": {"
3420 "\"alarmCondition\": \"My alarm condition\", "
3421 "\"eventSeverity\": \"MAJOR\", "
3422 "\"eventSourceType\": \"other\", "
3423 "\"specificProblem\": \"It broke \\\"very\\\" badly\", "
3424 "\"vfStatus\": \"Active\", "
3425 "\"faultFieldsVersion\": 1.1, "
3426 "\"alarmAdditionalInformation\": ["
3427 "{\"name\": \"name1\", "
3428 "\"value\": \"value1\"}, "
3429 "{\"name\": \"name2\", "
3430 "\"value\": \"value2\"}], "
3431 "\"alarmInterfaceA\": \"My Interface Card\""
3434 size_t json_size = 0;
3435 char json_body[EVEL_MAX_JSON_BODY];
3436 evel_set_next_event_sequence(122);
3437 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
3438 "It broke \"very\" badly",
3439 EVEL_PRIORITY_NORMAL,
3440 EVEL_SEVERITY_MAJOR);
3441 assert(fault != NULL);
3442 evel_fault_type_set(fault, "Bad things happen...\\");
3443 evel_fault_interface_set(fault, "My Interface Card");
3444 evel_fault_addl_info_add(fault, "name1", "value1");
3445 evel_fault_addl_info_add(fault, "name2", "value2");
3447 json_size = evel_json_encode_event(
3448 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
3449 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
3450 assert((json_size == strlen(json_body)) && "Bad size returned");
3452 evel_free_event(fault);