1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5 * Unless otherwise specified, all software contained herein is
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ****************************************************************************/
18 /**************************************************************************//**
20 * Unit tests for JSON encoding and throttling.
22 * This software is intended to show the essential elements of the library's
25 ****************************************************************************/
34 #include "evel_internal.h"
35 #include "evel_throttle.h"
47 /*****************************************************************************/
48 /* Local prototypes. */
49 /*****************************************************************************/
50 static void test_encode_heartbeat();
51 static void test_encode_header_overrides();
52 static void test_encode_fault();
53 static void test_encode_fault_with_escaping();
54 static void test_encode_measurement();
55 static void test_encode_mobile_mand();
56 static void test_encode_mobile_opts();
57 static void test_encode_other();
58 static void test_encode_report();
59 static void test_encode_service();
60 static void test_encode_service_subset(const SERVICE_TEST service_test);
61 static void test_encode_signaling();
62 static void test_encode_state_change();
63 static void test_encode_syslog();
64 static void test_json_response_junk();
65 static void test_json_provide_throttle_state();
66 static void test_json_measurement_interval();
67 static void test_json_throttle_spec_field();
68 static void test_json_throttle_spec_nv_pair();
69 static void test_json_throttle_spec_two_domains();
70 static void test_json_throttle_spec_bad_command_type();
71 static void test_encode_fault_throttled();
72 static void test_encode_measurement_throttled();
73 static void test_encode_mobile_throttled();
74 static void test_encode_other_throttled();
75 static void test_encode_report_throttled();
76 static void test_encode_service_throttled();
77 static void test_encode_signaling_throttled();
78 static void test_encode_state_change_throttled();
79 static void test_encode_syslog_throttled();
80 static void compare_strings(char * expected,
85 /**************************************************************************//**
88 * Runs all unit test cases, and fails hard on the first failure.
90 * @param[in] argc Argument count.
91 * @param[in] argv Argument vector - for usage see usage_text.
92 *****************************************************************************/
93 int main(int argc, char ** argv)
98 /***************************************************************************/
99 /* Fix our timezone to UTC. */
100 /***************************************************************************/
103 /***************************************************************************/
104 /* Initialize metadata. */
105 /***************************************************************************/
106 openstack_metadata_initialize();
108 /***************************************************************************/
109 /* Minimal initialisation to exercise the encoders. */
110 /***************************************************************************/
111 functional_role = "UNIT TEST";
112 log_initialize(EVEL_LOG_DEBUG, "EVEL");
114 /***************************************************************************/
115 /* Test each encoder. */
116 /***************************************************************************/
117 test_encode_heartbeat();
118 test_encode_header_overrides();
120 test_encode_measurement();
121 test_encode_mobile_mand();
122 test_encode_mobile_opts();
124 test_encode_report();
125 test_encode_service();
126 test_encode_signaling();
127 test_encode_state_change();
128 test_encode_syslog();
130 /***************************************************************************/
131 /* Test JSON Throttle. */
132 /***************************************************************************/
133 test_json_response_junk();
134 test_json_provide_throttle_state();
135 test_json_measurement_interval();
136 test_json_throttle_spec_field();
137 test_json_throttle_spec_nv_pair();
138 test_json_throttle_spec_two_domains();
139 test_json_throttle_spec_bad_command_type();
141 /***************************************************************************/
142 /* Test each encoder with throttling applied. */
143 /***************************************************************************/
144 test_encode_fault_throttled();
145 test_encode_measurement_throttled();
146 test_encode_mobile_throttled();
147 test_encode_other_throttled();
148 test_encode_report_throttled();
149 test_encode_service_throttled();
150 test_encode_signaling_throttled();
151 test_encode_state_change_throttled();
152 test_encode_syslog_throttled();
154 /***************************************************************************/
155 /* Test character escaping. */
156 /***************************************************************************/
157 test_encode_fault_with_escaping();
159 printf ("\nAll Tests Passed\n");
164 /*****************************************************************************/
165 /* We link with this gettimeofday so that we get a fixed result */
166 /*****************************************************************************/
167 int gettimeofday(struct timeval *tv,
168 struct timezone *tz __attribute__((unused)))
175 void test_encode_heartbeat()
179 "\"commonEventHeader\": {"
180 "\"domain\": \"heartbeat\", "
181 "\"eventId\": \"121\", "
182 "\"functionalRole\": \"UNIT TEST\", "
183 "\"lastEpochMicrosec\": 1000002, "
184 "\"priority\": \"Normal\", "
185 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
186 "\"sequence\": 121, "
187 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
188 "\"startEpochMicrosec\": 1000002, "
190 "\"eventType\": \"Autonomous heartbeat\", "
191 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
192 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
195 size_t json_size = 0;
196 char json_body[EVEL_MAX_JSON_BODY];
198 /***************************************************************************/
199 /* Test the VM name/uuid once. */
200 /***************************************************************************/
201 evel_set_next_event_sequence(121);
203 EVENT_HEADER * heartbeat = evel_new_heartbeat();
204 assert(heartbeat != NULL);
206 json_size = evel_json_encode_event(
207 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
208 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
209 assert((json_size == strlen(json_body)) && "Bad size returned");
211 evel_free_event(heartbeat);
214 void test_encode_header_overrides()
218 "\"commonEventHeader\": {"
219 "\"domain\": \"heartbeat\", "
220 "\"eventId\": \"121\", "
221 "\"functionalRole\": \"UNIT TEST\", "
222 "\"lastEpochMicrosec\": 1000, "
223 "\"priority\": \"Normal\", "
224 "\"reportingEntityName\": \"entity_name_override\", "
225 "\"sequence\": 121, "
226 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
227 "\"startEpochMicrosec\": 1001, "
229 "\"eventType\": \"Autonomous heartbeat\", "
230 "\"reportingEntityId\": \"entity_id_override\", "
231 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
234 size_t json_size = 0;
235 char json_body[EVEL_MAX_JSON_BODY];
237 /***************************************************************************/
238 /* Test the VM name/uuid once. */
239 /***************************************************************************/
240 evel_set_next_event_sequence(121);
242 EVENT_HEADER * heartbeat = evel_new_heartbeat();
243 assert(heartbeat != NULL);
245 evel_start_epoch_set(heartbeat, 1001);
246 evel_last_epoch_set(heartbeat, 1000);
247 evel_reporting_entity_name_set(heartbeat, "entity_name_override");
248 evel_reporting_entity_id_set(heartbeat, "entity_id_override");
250 json_size = evel_json_encode_event(
251 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
252 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
253 assert((json_size == strlen(json_body)) && "Bad size returned");
255 evel_free_event(heartbeat);
258 void test_encode_fault()
262 "\"commonEventHeader\": {"
263 "\"domain\": \"fault\", "
264 "\"eventId\": \"122\", "
265 "\"functionalRole\": \"UNIT TEST\", "
266 "\"lastEpochMicrosec\": 1000002, "
267 "\"priority\": \"Normal\", "
268 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
269 "\"sequence\": 122, "
270 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
271 "\"startEpochMicrosec\": 1000002, "
273 "\"eventType\": \"Bad things happen...\", "
274 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
275 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
278 "\"alarmCondition\": \"My alarm condition\", "
279 "\"eventSeverity\": \"MAJOR\", "
280 "\"eventSourceType\": \"other\", "
281 "\"specificProblem\": \"It broke very badly\", "
282 "\"eventCategory\": \"link\", "
283 "\"vfStatus\": \"Active\", "
284 "\"faultFieldsVersion\": 1.1, "
285 "\"alarmAdditionalInformation\": ["
286 "{\"name\": \"name1\", "
287 "\"value\": \"value1\"}, "
288 "{\"name\": \"name2\", "
289 "\"value\": \"value2\"}], "
290 "\"alarmInterfaceA\": \"My Interface Card\""
293 size_t json_size = 0;
294 char json_body[EVEL_MAX_JSON_BODY];
295 evel_set_next_event_sequence(122);
296 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
297 "It broke very badly",
298 EVEL_PRIORITY_NORMAL,
301 EVEL_VF_STATUS_PREP_TERMINATE);
302 assert(fault != NULL);
303 evel_fault_type_set(fault, "Bad things happen...");
304 evel_fault_interface_set(fault, "My Interface Card");
305 evel_fault_addl_info_add(fault, "name1", "value1");
306 evel_fault_addl_info_add(fault, "name2", "value2");
308 json_size = evel_json_encode_event(
309 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
310 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
311 assert((json_size == strlen(json_body)) && "Bad size returned");
313 evel_free_event(fault);
316 void test_encode_measurement()
320 "{\"commonEventHeader\": {"
321 "\"domain\": \"measurementsForVfScaling\", "
322 "\"eventId\": \"123\", "
323 "\"functionalRole\": \"UNIT TEST\", "
324 "\"lastEpochMicrosec\": 3000, "
325 "\"priority\": \"Normal\", "
326 "\"reportingEntityName\": \"entity_name\", "
327 "\"sequence\": 123, "
328 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
329 "\"startEpochMicrosec\": 2000, "
331 "\"eventType\": \"Perf management...\", "
332 "\"reportingEntityId\": \"entity_id\", "
333 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
335 "\"measurementsForVfScalingFields\": "
337 "\"measurementInterval\": 5.500000, "
338 "\"concurrentSessions\": 1, "
339 "\"configuredEntities\": 2, "
340 "\"cpuUsageArray\": ["
341 "{\"cpuIdentifier\": \"cpu1\", "
342 "\"percentUsage\": 11.110000}, "
343 "{\"cpuIdentifier\": \"cpu2\", "
344 "\"percentUsage\": 22.220000}], "
345 "\"filesystemUsageArray\": ["
346 "{\"blockConfigured\": 100.110000, "
347 "\"blockIops\": 33, "
348 "\"blockUsed\": 100.220000, "
349 "\"ephemeralConfigured\": 100.110000, "
350 "\"ephemeralIops\": 44, "
351 "\"ephemeralUsed\": 200.220000, "
352 "\"filesystemName\": \"00-11-22\"}, "
353 "{\"blockConfigured\": 300.110000, "
354 "\"blockIops\": 55, "
355 "\"blockUsed\": 300.220000, "
356 "\"ephemeralConfigured\": 300.110000, "
357 "\"ephemeralIops\": 66, "
358 "\"ephemeralUsed\": 400.220000, "
359 "\"filesystemName\": \"33-44-55\"}], "
360 "\"latencyDistribution\": ["
361 "{\"countsInTheBucket\": 20}, "
362 "{\"lowEndOfLatencyBucket\": 10.000000, "
363 "\"highEndOfLatencyBucket\": 20.000000, "
364 "\"countsInTheBucket\": 30}], "
365 "\"meanRequestLatency\": 4.400000, "
366 "\"memoryConfigured\": 6.600000, "
367 "\"memoryUsed\": 3.300000, "
368 "\"requestRate\": 7, "
369 "\"vNicUsageArray\": ["
373 "\"packetsIn\": 100, "
374 "\"packetsOut\": 200, "
375 "\"vNicIdentifier\": \"eth0\""
380 "\"packetsIn\": 110, "
381 "\"packetsOut\": 240, "
382 "\"vNicIdentifier\": \"eth1\", "
383 "\"broadcastPacketsIn\": 11, "
384 "\"broadcastPacketsOut\": 12, "
385 "\"multicastPacketsIn\": 15, "
386 "\"multicastPacketsOut\": 16, "
387 "\"unicastPacketsIn\": 17, "
388 "\"unicastPacketsOut\": 18"
391 "\"aggregateCpuUsage\": 8.800000, "
392 "\"numberOfMediaPortsInUse\": 1234, "
393 "\"vnfcScalingMetric\": 1234.567800, "
395 "\"receiveDiscards\": 1, "
396 "\"receiveErrors\": 0, "
397 "\"transmitDiscards\": 2, "
398 "\"transmitErrors\": 1}, "
399 "\"featureUsageArray\": ["
400 "{\"featureIdentifier\": \"FeatureA\", "
401 "\"featureUtilization\": 123}, "
402 "{\"featureIdentifier\": \"FeatureB\", "
403 "\"featureUtilization\": 567}], "
404 "\"codecUsageArray\": ["
405 "{\"codecIdentifier\": \"G711a\", "
406 "\"numberInUse\": 91}, "
407 "{\"codecIdentifier\": \"G729ab\", "
408 "\"numberInUse\": 92}], "
409 "\"additionalMeasurements\": ["
410 "{\"name\": \"Group1\", "
411 "\"measurements\": ["
412 "{\"name\": \"Name1\", "
413 "\"value\": \"Value1\"}]}, "
414 "{\"name\": \"Group2\", "
415 "\"measurements\": ["
416 "{\"name\": \"Name1\", "
417 "\"value\": \"Value1\"}, "
418 "{\"name\": \"Name2\", "
419 "\"value\": \"Value2\"}]}], "
420 "\"measurementsForVfScalingVersion\": 1.1}}}";
422 size_t json_size = 0;
423 char json_body[EVEL_MAX_JSON_BODY];
424 EVENT_MEASUREMENT * measurement = NULL;
425 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
426 MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
427 MEASUREMENT_CPU_USE *cpu_use;
429 /***************************************************************************/
431 /***************************************************************************/
432 evel_set_next_event_sequence(123);
433 measurement = evel_new_measurement(5.5);
434 assert(measurement != NULL);
435 evel_measurement_type_set(measurement, "Perf management...");
436 evel_measurement_conc_sess_set(measurement, 1);
437 evel_measurement_cfg_ents_set(measurement, 2);
438 evel_measurement_mean_req_lat_set(measurement, 4.4);
439 evel_measurement_request_rate_set(measurement, 7);
441 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
442 evel_measurement_cpu_use_idle_set(cpu_use,22.22);
443 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
444 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
445 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
446 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
447 evel_measurement_cpu_use_system_set(cpu_use,77.77);
448 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
449 evel_measurement_cpu_use_wait_set(cpu_use,99.99);
451 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
452 evel_measurement_cpu_use_idle_set(cpu_use,12.22);
453 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
454 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
455 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
456 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
457 evel_measurement_cpu_use_system_set(cpu_use,77.77);
458 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
459 evel_measurement_cpu_use_wait_set(cpu_use,19.99);
462 evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33,
464 evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55,
466 evel_start_epoch_set(&measurement->header, 2000);
467 evel_last_epoch_set(&measurement->header, 3000);
468 evel_reporting_entity_name_set(&measurement->header, "entity_name");
469 evel_reporting_entity_id_set(&measurement->header, "entity_id");
471 /***************************************************************************/
472 /* Latency Bucket with no optional parameters. */
473 /***************************************************************************/
474 bucket = evel_new_meas_latency_bucket(20);
475 evel_meas_latency_bucket_add(measurement, bucket);
477 /***************************************************************************/
478 /* Latency Bucket with all optional parameters. */
479 /***************************************************************************/
480 bucket = evel_new_meas_latency_bucket(30);
481 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
482 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
483 evel_meas_latency_bucket_add(measurement, bucket);
485 /***************************************************************************/
486 /* vNIC Use with no optional parameters. */
487 /***************************************************************************/
488 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
489 evel_meas_vnic_use_add(measurement, vnic_use);
491 /***************************************************************************/
492 /* vNIC Use with all optional parameters. */
493 /***************************************************************************/
494 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
495 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
496 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
497 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
498 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
499 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
500 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
501 evel_meas_vnic_use_add(measurement, vnic_use);
503 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
505 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
506 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
508 evel_measurement_codec_use_add(measurement, "G711a", 91);
509 evel_measurement_codec_use_add(measurement, "G729ab", 92);
511 evel_measurement_media_port_use_set(measurement, 1234);
513 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
515 evel_measurement_custom_measurement_add(measurement,
516 "Group1", "Name1", "Value1");
517 evel_measurement_custom_measurement_add(measurement,
518 "Group2", "Name1", "Value1");
519 evel_measurement_custom_measurement_add(measurement,
520 "Group2", "Name2", "Value2");
522 json_size = evel_json_encode_event(
523 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
524 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
525 assert((json_size == strlen(json_body)) && "Bad size returned");
527 evel_free_event(measurement);
530 void test_encode_mobile_mand()
534 "{\"commonEventHeader\": {"
535 "\"domain\": \"mobileFlow\", "
536 "\"eventId\": \"1241\", "
537 "\"functionalRole\": \"UNIT TEST\", "
538 "\"lastEpochMicrosec\": 1000002, "
539 "\"priority\": \"Normal\", "
540 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
541 "\"sequence\": 1241, "
542 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
543 "\"startEpochMicrosec\": 1000002, "
545 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
546 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
548 "\"mobileFlowFields\": {"
549 "\"flowDirection\": \"Outbound\", "
550 "\"gtpPerFlowMetrics\": {"
551 "\"avgBitErrorRate\": 12.300000, "
552 "\"avgPacketDelayVariation\": 3.120000, "
553 "\"avgPacketLatency\": 100, "
554 "\"avgReceiveThroughput\": 2100, "
555 "\"avgTransmitThroughput\": 500, "
556 "\"flowActivationEpoch\": 1470409421, "
557 "\"flowActivationMicrosec\": 987, "
558 "\"flowDeactivationEpoch\": 1470409431, "
559 "\"flowDeactivationMicrosec\": 11, "
560 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:51 +0000\", "
561 "\"flowStatus\": \"Working\", "
562 "\"maxPacketDelayVariation\": 87, "
563 "\"numActivationFailures\": 3, "
564 "\"numBitErrors\": 17, "
565 "\"numBytesReceived\": 123654, "
566 "\"numBytesTransmitted\": 4561, "
567 "\"numDroppedPackets\": 0, "
568 "\"numL7BytesReceived\": 12, "
569 "\"numL7BytesTransmitted\": 10, "
570 "\"numLostPackets\": 1, "
571 "\"numOutOfOrderPackets\": 3, "
572 "\"numPacketErrors\": 7, "
573 "\"numPacketsReceivedExclRetrans\": 899, "
574 "\"numPacketsReceivedInclRetrans\": 901, "
575 "\"numPacketsTransmittedInclRetrans\": 302, "
576 "\"numRetries\": 6, "
577 "\"numTimeouts\": 2, "
578 "\"numTunneledL7BytesReceived\": 0, "
579 "\"roundTripTime\": 110, "
580 "\"timeToFirstByte\": 225"
582 "\"ipProtocolType\": \"TCP\", "
583 "\"ipVersion\": \"IPv4\", "
584 "\"otherEndpointIpAddress\": \"2.3.4.1\", "
585 "\"otherEndpointPort\": 2341, "
586 "\"reportingEndpointIpAddr\": \"4.2.3.1\", "
587 "\"reportingEndpointPort\": 4321"
590 size_t json_size = 0;
591 char json_body[EVEL_MAX_JSON_BODY];
592 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
593 EVENT_MOBILE_FLOW * mobile_flow = NULL;
595 /***************************************************************************/
597 /***************************************************************************/
598 evel_set_next_event_sequence(1241);
600 metrics = evel_new_mobile_gtp_flow_metrics(12.3,
630 assert(metrics != NULL);
631 mobile_flow = evel_new_mobile_flow("Outbound",
639 assert(mobile_flow != NULL);
641 json_size = evel_json_encode_event(
642 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
643 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
644 assert((json_size == strlen(json_body)) && "Bad size returned");
646 evel_free_event(mobile_flow);
649 void test_encode_mobile_opts()
653 "{\"commonEventHeader\": {"
654 "\"domain\": \"mobileFlow\", "
655 "\"eventId\": \"1242\", "
656 "\"functionalRole\": \"UNIT TEST\", "
657 "\"lastEpochMicrosec\": 1000002, "
658 "\"priority\": \"Normal\", "
659 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
660 "\"sequence\": 1242, "
661 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
662 "\"startEpochMicrosec\": 1000002, "
664 "\"eventType\": \"Mobile flow...\", "
665 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
666 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
668 "\"mobileFlowFields\": {"
669 "\"flowDirection\": \"Inbound\", "
670 "\"gtpPerFlowMetrics\": {"
671 "\"avgBitErrorRate\": 132.000100, "
672 "\"avgPacketDelayVariation\": 31.200000, "
673 "\"avgPacketLatency\": 101, "
674 "\"avgReceiveThroughput\": 2101, "
675 "\"avgTransmitThroughput\": 501, "
676 "\"flowActivationEpoch\": 1470409422, "
677 "\"flowActivationMicrosec\": 988, "
678 "\"flowDeactivationEpoch\": 1470409432, "
679 "\"flowDeactivationMicrosec\": 12, "
680 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
681 "\"flowStatus\": \"Inactive\", "
682 "\"maxPacketDelayVariation\": 88, "
683 "\"numActivationFailures\": 4, "
684 "\"numBitErrors\": 18, "
685 "\"numBytesReceived\": 123655, "
686 "\"numBytesTransmitted\": 4562, "
687 "\"numDroppedPackets\": 1, "
688 "\"numL7BytesReceived\": 13, "
689 "\"numL7BytesTransmitted\": 11, "
690 "\"numLostPackets\": 2, "
691 "\"numOutOfOrderPackets\": 4, "
692 "\"numPacketErrors\": 8, "
693 "\"numPacketsReceivedExclRetrans\": 900, "
694 "\"numPacketsReceivedInclRetrans\": 902, "
695 "\"numPacketsTransmittedInclRetrans\": 303, "
696 "\"numRetries\": 7, "
697 "\"numTimeouts\": 3, "
698 "\"numTunneledL7BytesReceived\": 1, "
699 "\"roundTripTime\": 111, "
700 "\"timeToFirstByte\": 226, "
701 "\"ipTosCountList\": ["
705 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
706 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
707 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
708 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
709 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
710 "\"durConnectionFailedStatus\": 12, "
711 "\"durTunnelFailedStatus\": 13, "
712 "\"flowActivatedBy\": \"Remote\", "
713 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
714 "\"flowDeactivatedBy\": \"Remote\", "
715 "\"gtpConnectionStatus\": \"Connected\", "
716 "\"gtpTunnelStatus\": \"Not tunneling\", "
717 "\"largePacketRtt\": 80, "
718 "\"largePacketThreshold\": 600.000000, "
719 "\"maxReceiveBitRate\": 1357924680, "
720 "\"maxTransmitBitRate\": 235711, "
721 "\"numGtpEchoFailures\": 1, "
722 "\"numGtpTunnelErrors\": 4, "
723 "\"numHttpErrors\": 2"
725 "\"ipProtocolType\": \"UDP\", "
726 "\"ipVersion\": \"IPv6\", "
727 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
728 "\"otherEndpointPort\": 2342, "
729 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
730 "\"reportingEndpointPort\": 4322, "
731 "\"applicationType\": \"Demo application\", "
732 "\"appProtocolType\": \"GSM\", "
733 "\"appProtocolVersion\": \"1\", "
734 "\"cid\": \"65535\", "
735 "\"connectionType\": \"S1-U\", "
736 "\"ecgi\": \"e65535\", "
737 "\"gtpProtocolType\": \"GTP-U\", "
738 "\"gtpVersion\": \"1\", "
739 "\"httpHeader\": \"http://www.something.com\", "
740 "\"imei\": \"209917614823\", "
741 "\"imsi\": \"355251/05/850925/8\", "
745 "\"msisdn\": \"6017123456789\", "
746 "\"otherFunctionalRole\": \"MME\", "
748 "\"radioAccessTechnology\": \"LTE\", "
750 "\"samplingAlgorithm\": 1, "
751 "\"tac\": \"2099\", "
752 "\"tunnelId\": \"Tunnel 1\", "
756 size_t json_size = 0;
757 char json_body[EVEL_MAX_JSON_BODY];
758 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
759 EVENT_MOBILE_FLOW * mobile_flow = NULL;
761 /***************************************************************************/
763 /***************************************************************************/
764 evel_set_next_event_sequence(1242);
766 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
796 assert(metrics != NULL);
798 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
799 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
800 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
801 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
802 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
803 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
804 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
805 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
806 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
807 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
808 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
809 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
810 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
811 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
812 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
813 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
814 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
815 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
816 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
817 evel_mobile_gtp_metrics_qci_cos_count_add(
818 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
819 evel_mobile_gtp_metrics_qci_cos_count_add(
820 metrics, EVEL_QCI_COS_LTE_65, 122);
822 mobile_flow = evel_new_mobile_flow("Inbound",
830 assert(mobile_flow != NULL);
832 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
833 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
834 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
835 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
836 evel_mobile_flow_cid_set(mobile_flow, "65535");
837 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
838 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
839 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
840 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
841 evel_mobile_flow_http_header_set(mobile_flow,
842 "http://www.something.com");
843 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
844 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
845 evel_mobile_flow_lac_set(mobile_flow, "1");
846 evel_mobile_flow_mcc_set(mobile_flow, "410");
847 evel_mobile_flow_mnc_set(mobile_flow, "04");
848 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
849 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
850 evel_mobile_flow_rac_set(mobile_flow, "514");
851 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
852 evel_mobile_flow_sac_set(mobile_flow, "1");
853 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
854 evel_mobile_flow_tac_set(mobile_flow, "2099");
855 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
856 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
858 json_size = evel_json_encode_event(
859 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
860 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
861 assert((json_size == strlen(json_body)) && "Bad size returned");
863 evel_free_event(mobile_flow);
866 void test_encode_report()
870 "{\"commonEventHeader\": {"
871 "\"domain\": \"measurementsForVfReporting\", "
872 "\"eventId\": \"125\", "
873 "\"functionalRole\": \"UNIT TEST\", "
874 "\"lastEpochMicrosec\": 1000002, "
875 "\"priority\": \"Normal\", "
876 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
877 "\"sequence\": 125, "
878 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
879 "\"startEpochMicrosec\": 1000002, "
881 "\"eventType\": \"Perf reporting...\", "
882 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
883 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
885 "\"measurementsForVfReportingFields\": "
886 "{\"measurementInterval\": 1.100000, "
887 "\"featureUsageArray\": ["
888 "{\"featureIdentifier\": \"FeatureA\", "
889 "\"featureUtilization\": 123}, "
890 "{\"featureIdentifier\": \"FeatureB\", "
891 "\"featureUtilization\": 567}], "
892 "\"additionalMeasurements\": ["
893 "{\"name\": \"Group1\", "
894 "\"measurements\": ["
895 "{\"name\": \"Name1\", "
896 "\"value\": \"Value1\"}]}, "
897 "{\"name\": \"Group2\", "
898 "\"measurements\": ["
899 "{\"name\": \"Name1\", "
900 "\"value\": \"Value1\"}, "
901 "{\"name\": \"Name2\", "
902 "\"value\": \"Value2\"}]}], "
903 "\"measurementFieldsVersion\": 1.1}}}";
905 size_t json_size = 0;
906 char json_body[EVEL_MAX_JSON_BODY];
907 EVENT_REPORT * report = NULL;
909 /***************************************************************************/
911 /***************************************************************************/
912 evel_set_next_event_sequence(125);
913 report = evel_new_report(1.1);
914 assert(report != NULL);
915 evel_report_type_set(report, "Perf reporting...");
916 evel_report_feature_use_add(report, "FeatureA", 123);
917 evel_report_feature_use_add(report, "FeatureB", 567);
918 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
919 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
920 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
922 json_size = evel_json_encode_event(
923 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
924 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
925 assert((json_size == strlen(json_body)) && "Bad size returned");
927 evel_free_event(report);
930 void test_encode_service()
932 test_encode_service_subset(SERVICE_NONE);
933 test_encode_service_subset(SERVICE_CODEC);
934 test_encode_service_subset(SERVICE_TRANSCODING);
935 test_encode_service_subset(SERVICE_RTCP);
936 test_encode_service_subset(SERVICE_EOC_VQM);
937 test_encode_service_subset(SERVICE_MARKER);
940 void test_encode_service_subset(const SERVICE_TEST service_test)
942 char * expected_start =
944 "{\"commonEventHeader\": {"
945 "\"domain\": \"serviceEvents\", "
946 "\"eventId\": \"2000\", "
947 "\"functionalRole\": \"UNIT TEST\", "
948 "\"lastEpochMicrosec\": 1000002, "
949 "\"priority\": \"Normal\", "
950 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
951 "\"sequence\": 2000, "
952 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
953 "\"startEpochMicrosec\": 1000002, "
955 "\"eventType\": \"Service Event\", "
956 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
957 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
959 "\"serviceEventsFields\": {"
960 "\"eventInstanceIdentifier\": "
962 "\"vendorId\": \"vendor_x_id\", "
963 "\"eventId\": \"vendor_x_event_id\", "
964 "\"productId\": \"vendor_x_product_id\", "
965 "\"subsystemId\": \"vendor_x_subsystem_id\", "
966 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
968 "\"serviceEventsFieldsVersion\": 1.1, "
969 "\"correlator\": \"vendor_x_correlator\", "
970 "\"additionalFields\": ["
971 "{\"name\": \"Name1\", \"value\": \"Value1\"}, "
972 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
973 "{\"name\": \"Name3\", \"value\": \"Value3\"}, "
974 "{\"name\": \"Name4\", \"value\": \"Value4\"}]";
975 char * expected_codec =
977 "\"codecSelected\": {"
978 "\"codec\": \"PCMA\""
980 char * expected_transcoding =
982 "\"codecSelectedTranscoding\": {"
983 "\"calleeSideCodec\": \"PCMA\", "
984 "\"callerSideCodec\": \"G729A\""
986 char * expected_rtcp =
989 "\"rtcpData\": \"some_rtcp_data\""
991 char * expected_eoc_vqm =
993 "\"endOfCallVqmSummaries\": {"
994 "\"adjacencyName\": \"vendor_x_adjacency\", "
995 "\"endpointDescription\": \"Caller\", "
996 "\"endpointJitter\": 66, "
997 "\"endpointRtpOctetsDiscarded\": 100, "
998 "\"endpointRtpOctetsReceived\": 200, "
999 "\"endpointRtpOctetsSent\": 300, "
1000 "\"endpointRtpPacketsDiscarded\": 400, "
1001 "\"endpointRtpPacketsReceived\": 500, "
1002 "\"endpointRtpPacketsSent\": 600, "
1003 "\"localJitter\": 99, "
1004 "\"localRtpOctetsDiscarded\": 150, "
1005 "\"localRtpOctetsReceived\": 250, "
1006 "\"localRtpOctetsSent\": 350, "
1007 "\"localRtpPacketsDiscarded\": 450, "
1008 "\"localRtpPacketsReceived\": 550, "
1009 "\"localRtpPacketsSent\": 650, "
1010 "\"mosCqe\": 12.255000, "
1011 "\"packetsLost\": 157, "
1012 "\"packetLossPercent\": 0.232000, "
1014 "\"roundTripDelay\": 15"
1016 char * expected_marker =
1019 "\"phoneNumber\": \"0888888888\""
1021 char * expected_end =
1024 char * expected_middle = NULL;
1025 switch (service_test)
1028 expected_middle = "";
1031 expected_middle = expected_codec;
1033 case SERVICE_TRANSCODING:
1034 expected_middle = expected_transcoding;
1037 expected_middle = expected_rtcp;
1039 case SERVICE_EOC_VQM:
1040 expected_middle = expected_eoc_vqm;
1042 case SERVICE_MARKER:
1043 expected_middle = expected_marker;
1046 assert(expected_middle != NULL);
1049 char expected[EVEL_MAX_JSON_BODY];
1050 offset = snprintf(expected + offset,
1051 EVEL_MAX_JSON_BODY - offset,
1057 size_t json_size = 0;
1058 char json_body[EVEL_MAX_JSON_BODY];
1059 EVENT_SGNALING * event = NULL;
1060 evel_set_next_event_sequence(2000);
1061 event = evel_new_signaling("vendor_x_id",
1062 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1063 assert(event != NULL);
1064 evel_signaling_type_set(event, "Signaling");
1065 evel_signaling_correlator_set(event, "vendor_x_correlator");
1066 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1067 evel_signaling_vnfname_set(event, "vendor_x_vnf");
1069 switch (service_test)
1074 evel_signaling_addl_info_add(event, "codec", "PCMA");
1076 case SERVICE_TRANSCODING:
1077 evel_signaling_addl_info_add(event, "calleecodec", "PCMA");
1078 evel_signaling_addl_info_add(event, "callercodec", "G729A");
1081 evel_signaling_addl_info_add(event, "rtcpdata", "abcdefgh");
1083 case SERVICE_EOC_VQM:
1084 evel_signaling_addl_info_add(event, "adjacency", "vendor_x");
1085 /*evel_service_adjacency_name_set(event, "vendor_x_adjacency");
1086 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
1087 evel_service_endpoint_jitter_set(event, 66);
1088 evel_service_endpoint_rtp_oct_disc_set(event, 100);
1089 evel_service_endpoint_rtp_oct_recv_set(event, 200);
1090 evel_service_endpoint_rtp_oct_sent_set(event, 300);
1091 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
1092 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
1093 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
1094 evel_service_local_jitter_set(event, 99);
1095 evel_service_local_rtp_oct_disc_set(event, 150);
1096 evel_service_local_rtp_oct_recv_set(event, 250);
1097 evel_service_local_rtp_oct_sent_set(event, 350);
1098 evel_service_local_rtp_pkt_disc_set(event, 450);
1099 evel_service_local_rtp_pkt_recv_set(event, 550);
1100 evel_service_local_rtp_pkt_sent_set(event, 650);
1101 evel_service_mos_cqe_set(event, 12.255);
1102 evel_service_packets_lost_set(event, 157);
1103 evel_service_packet_loss_percent_set(event, 0.232);
1104 evel_service_r_factor_set(event, 11);
1105 evel_service_round_trip_delay_set(event, 15);*/
1107 case SERVICE_MARKER:
1108 evel_signaling_addl_info_add(event, "service_phone", "0888888888");
1112 json_size = evel_json_encode_event(
1113 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1114 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
1115 assert((json_size == strlen(json_body)) && "Bad size returned");
1117 evel_free_event(event);
1120 void test_encode_signaling()
1124 "{\"commonEventHeader\": {"
1125 "\"domain\": \"signaling\", "
1126 "\"eventId\": \"2001\", "
1127 "\"functionalRole\": \"UNIT TEST\", "
1128 "\"lastEpochMicrosec\": 1000002, "
1129 "\"priority\": \"Normal\", "
1130 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1131 "\"sequence\": 2001, "
1132 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1133 "\"startEpochMicrosec\": 1000002, "
1134 "\"version\": 1.2, "
1135 "\"eventType\": \"Signaling\", "
1136 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1137 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1139 "\"signalingFields\": {"
1140 "\"eventInstanceIdentifier\": "
1142 "\"vendorId\": \"vendor_x_id\", "
1143 "\"eventId\": \"vendor_x_event_id\", "
1144 "\"productId\": \"vendor_x_product_id\", "
1145 "\"subsystemId\": \"vendor_x_subsystem_id\", "
1146 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
1148 "\"signalingFieldsVersion\": 1.1, "
1149 "\"correlator\": \"vendor_x_correlator\", "
1150 "\"localIpAddress\": \"1.0.3.1\", "
1151 "\"localPort\": \"1031\", "
1152 "\"remoteIpAddress\": \"5.3.3.0\", "
1153 "\"remotePort\": \"5330\", "
1154 "\"compressedSip\": \"compressed_sip\", "
1155 "\"summarySip\": \"summary_sip\""
1158 size_t json_size = 0;
1159 char json_body[EVEL_MAX_JSON_BODY];
1160 EVENT_SIGNALING * event = NULL;
1161 evel_set_next_event_sequence(2001);
1162 event = evel_new_signaling("vendor_x_id",
1163 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1164 assert(event != NULL);
1165 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1166 evel_signaling_vnfname_set(event, "vendor_x_vnf");
1167 evel_signaling_type_set(event, "Signaling");
1168 evel_signaling_product_id_set(event, "vendor_x_product_id");
1169 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
1170 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
1171 evel_signaling_correlator_set(event, "vendor_x_correlator");
1172 evel_signaling_local_ip_address_set(event, "1.0.3.1");
1173 evel_signaling_local_port_set(event, "1031");
1174 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
1175 evel_signaling_remote_port_set(event, "5330");
1176 evel_signaling_compressed_sip_set(event, "compressed_sip");
1177 evel_signaling_summary_sip_set(event, "summary_sip");
1178 json_size = evel_json_encode_event(
1179 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1180 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
1181 assert((json_size == strlen(json_body)) && "Bad size returned");
1183 evel_free_event(event);
1186 void test_encode_state_change()
1190 "{\"commonEventHeader\": {"
1191 "\"domain\": \"stateChange\", "
1192 "\"eventId\": \"128\", "
1193 "\"functionalRole\": \"UNIT TEST\", "
1194 "\"lastEpochMicrosec\": 1000002, "
1195 "\"priority\": \"Normal\", "
1196 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1197 "\"sequence\": 128, "
1198 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1199 "\"startEpochMicrosec\": 1000002, "
1200 "\"version\": 1.2, "
1201 "\"eventType\": \"SC Type\", "
1202 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1203 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1205 "\"stateChangeFields\": {"
1206 "\"newState\": \"inService\", "
1207 "\"oldState\": \"outOfService\", "
1208 "\"stateInterface\": \"An Interface\", "
1209 "\"additionalFields\": ["
1210 "{\"name\": \"Name1\", "
1211 "\"value\": \"Value1\"}, "
1212 "{\"name\": \"Name2\", "
1213 "\"value\": \"Value2\"}"
1215 "\"stateChangeFieldsVersion\": 1.1"
1218 size_t json_size = 0;
1219 char json_body[EVEL_MAX_JSON_BODY];
1220 EVENT_STATE_CHANGE * state_change = NULL;
1221 evel_set_next_event_sequence(128);
1222 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
1223 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
1225 assert(state_change != NULL);
1226 evel_state_change_type_set(state_change, "SC Type");
1227 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
1228 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
1230 json_size = evel_json_encode_event(
1231 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
1232 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
1233 assert((json_size == strlen(json_body)) && "Bad size returned");
1235 evel_free_event(state_change);
1238 void test_encode_syslog()
1242 "{\"commonEventHeader\": {"
1243 "\"domain\": \"syslog\", "
1244 "\"eventId\": \"126\", "
1245 "\"functionalRole\": \"UNIT TEST\", "
1246 "\"lastEpochMicrosec\": 1000002, "
1247 "\"priority\": \"Normal\", "
1248 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1249 "\"sequence\": 126, "
1250 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1251 "\"startEpochMicrosec\": 1000002, "
1252 "\"version\": 1.2, "
1253 "\"eventType\": \"SL Type\", "
1254 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1255 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1257 "\"syslogFields\": {"
1258 "\"eventSourceType\": \"virtualNetworkFunction\", "
1259 "\"syslogMsg\": \"SL Message\", "
1260 "\"syslogTag\": \"SL Tag\", "
1261 "\"syslogFieldsVersion\": 1.1, "
1262 "\"eventSourceHost\": \"SL Host\", "
1263 "\"syslogFacility\": 6, "
1264 "\"syslogProc\": \"SL Proc\", "
1265 "\"syslogProcId\": 2, "
1266 "\"syslogSData\": \"SL SDATA\", "
1269 size_t json_size = 0;
1270 char json_body[EVEL_MAX_JSON_BODY];
1271 EVENT_SYSLOG * syslog = NULL;
1272 evel_set_next_event_sequence(126);
1273 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
1276 assert(syslog != NULL);
1277 evel_syslog_type_set(syslog, "SL Type");
1278 evel_syslog_event_source_host_set(syslog, "SL Host");
1279 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
1280 evel_syslog_proc_set(syslog, "SL Proc");
1281 evel_syslog_proc_id_set(syslog, 2);
1282 evel_syslog_version_set(syslog, 1);
1283 evel_syslog_s_data_set(syslog, "SL SDATA");
1285 json_size = evel_json_encode_event(
1286 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
1287 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
1288 assert((json_size == strlen(json_body)) && "Bad size returned");
1290 evel_free_event(syslog);
1293 void test_encode_other()
1297 "{\"commonEventHeader\": {"
1298 "\"domain\": \"other\", "
1299 "\"eventId\": \"129\", "
1300 "\"functionalRole\": \"UNIT TEST\", "
1301 "\"lastEpochMicrosec\": 1000002, "
1302 "\"priority\": \"Normal\", "
1303 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1304 "\"sequence\": 129, "
1305 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1306 "\"startEpochMicrosec\": 1000002, "
1307 "\"version\": 1.2, "
1308 "\"eventType\": \"Other Type\", "
1309 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1310 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1312 "\"otherFields\": ["
1313 "{\"name\": \"Other field 1\", "
1314 "\"value\": \"Other value 1\"}, "
1315 "{\"name\": \"Other field 2\", "
1316 "\"value\": \"Other value 2\"}"
1320 size_t json_size = 0;
1321 char json_body[EVEL_MAX_JSON_BODY];
1322 EVENT_OTHER * other = NULL;
1323 evel_set_next_event_sequence(129);
1324 other = evel_new_other();
1325 assert(other != NULL);
1326 evel_other_type_set(other, "Other Type");
1327 evel_other_field_add(other,
1330 evel_other_field_add(other,
1334 json_size = evel_json_encode_event(
1335 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
1336 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
1337 assert((json_size == strlen(json_body)) && "Bad size returned");
1339 evel_free_event(other);
1342 void compare_strings(char * expected,
1347 if (strncmp(expected, actual, max_size) != 0)
1350 while (diff < max_size)
1352 if (expected[diff] != actual[diff])
1359 printf("Comparison Failure at Offset %d\n\n", diff);
1360 printf("Expected:\n%s\n", expected);
1361 printf("Actual:\n%s\n", actual);
1362 printf("Description: %s\n", description);
1367 /**************************************************************************//**
1368 * Copy a json string to a ::MEMORY_CHUNK for testing.
1370 * @param chunk The memory chunk.
1371 * @param string The json string.
1372 *****************************************************************************/
1373 void copy_string_to_chunk(MEMORY_CHUNK * chunk, char * string)
1377 /***************************************************************************/
1378 /* Check preconditions. */
1379 /***************************************************************************/
1380 assert(chunk != NULL);
1381 assert(string != NULL);
1383 mem_size = strlen(string) + 1;
1384 chunk->memory = malloc(mem_size);
1385 memcpy(chunk->memory, string, mem_size);
1386 chunk->size = mem_size;
1389 /**************************************************************************//**
1390 * Copy a json string to a ::MEMORY_CHUNK for testing.
1392 * @param json The JSON string.
1393 * @param post Memory chunk to post a response.
1394 *****************************************************************************/
1395 void handle_json_response(char * json, MEMORY_CHUNK * post)
1398 post->memory = NULL;
1400 copy_string_to_chunk(&chunk, json);
1401 evel_handle_event_response(&chunk, post);
1405 /**************************************************************************//**
1406 * Test that a non-"commandList" JSON buffer leaves the throttle state off.
1407 *****************************************************************************/
1408 void test_json_response_junk()
1415 "\"1\", \"2\", \"3\"], "
1417 "\"1\", \"2\", \"3\"]"
1420 evel_throttle_initialize();
1421 handle_json_response(json_junk, &post);
1423 /***************************************************************************/
1424 /* Check that all domains are not throttled. */
1425 /***************************************************************************/
1426 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1428 assert(evel_get_throttle_spec(domain) == NULL);
1431 /***************************************************************************/
1432 /* Check that we generated no post. */
1433 /***************************************************************************/
1434 assert(post.memory == NULL);
1436 evel_throttle_terminate();
1439 char * json_command_list_provide =
1441 "\"commandList\": ["
1444 "\"commandType\": \"provideThrottlingState\""
1450 char * json_command_list_fault_clear =
1452 "\"commandList\": ["
1455 "\"commandType\": \"throttlingSpecification\", "
1456 "\"eventDomainThrottleSpecification\": {"
1457 "\"eventDomain\": \"fault\""
1464 char * json_command_list_syslog_clear =
1466 "\"commandList\": ["
1469 "\"commandType\": \"throttlingSpecification\", "
1470 "\"eventDomainThrottleSpecification\": {"
1471 "\"eventDomain\": \"syslog\""
1478 char * expected_throttle_state_normal =
1480 "\"eventThrottlingState\": {"
1481 "\"eventThrottlingMode\": \"normal\"}"
1484 /**************************************************************************//**
1485 * Test that we can return the default throttling state.
1486 *****************************************************************************/
1487 void test_json_provide_throttle_state()
1492 char * expected_post = expected_throttle_state_normal;
1494 evel_throttle_initialize();
1495 handle_json_response(json_command_list_provide, &post);
1497 /***************************************************************************/
1498 /* Check that all domains are not throttled. */
1499 /***************************************************************************/
1500 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1502 assert(evel_get_throttle_spec(domain) == NULL);
1505 /***************************************************************************/
1506 /* Check that we generated a throttling specification post. */
1507 /***************************************************************************/
1508 assert(post.memory != NULL);
1509 compare_strings(expected_post, post.memory, strlen(expected_post),
1510 "Throttle State Normal");
1513 evel_throttle_terminate();
1516 /**************************************************************************//**
1517 * Test the measurement interval handling and API.
1518 *****************************************************************************/
1519 void test_json_measurement_interval()
1522 char * json_command_list_interval_only =
1524 "\"commandList\": ["
1527 "\"measurementInterval\": 60"
1533 char * json_command_list_interval_first =
1535 "\"commandList\": ["
1538 "\"measurementInterval\": 30, "
1539 "\"commandType\": \"measurementIntervalChange\""
1545 char * json_command_list_command_first =
1547 "\"commandList\": ["
1550 "\"commandType\": \"measurementIntervalChange\", "
1551 "\"measurementInterval\": 60"
1557 evel_throttle_initialize();
1558 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1560 /***************************************************************************/
1561 /* Check that we're not handling stuff when we shouldn't. */
1562 /***************************************************************************/
1563 handle_json_response(json_command_list_interval_only, &post);
1564 assert(post.memory == NULL);
1565 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1567 /***************************************************************************/
1568 /* Check that we're OK with the interval coming first. */
1569 /***************************************************************************/
1570 handle_json_response(json_command_list_interval_first, &post);
1571 assert(post.memory == NULL);
1572 assert(evel_get_measurement_interval() == 30);
1574 /***************************************************************************/
1575 /* Check that we're OK with the command type coming first. */
1576 /***************************************************************************/
1577 handle_json_response(json_command_list_command_first, &post);
1578 assert(post.memory == NULL);
1579 assert(evel_get_measurement_interval() == 60);
1581 evel_throttle_terminate();
1584 /**************************************************************************//**
1585 * Test a single domain, single field suppression.
1586 *****************************************************************************/
1587 void test_json_throttle_spec_field()
1592 char * json_command_list_fault_single =
1594 "\"commandList\": ["
1597 "\"commandType\": \"throttlingSpecification\", "
1598 "\"eventDomainThrottleSpecification\": {"
1599 "\"eventDomain\": \"fault\", "
1600 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1607 char * json_command_list_fault_double =
1609 "\"commandList\": ["
1612 "\"commandType\": \"throttlingSpecification\", "
1613 "\"eventDomainThrottleSpecification\": {"
1614 "\"eventDomain\": \"fault\", "
1615 "\"suppressedFieldNames\": ["
1616 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1623 char * expected_post_fault_single =
1625 "\"eventThrottlingState\": {"
1626 "\"eventThrottlingMode\": \"throttled\", "
1627 "\"eventDomainThrottleSpecificationList\": ["
1629 "\"eventDomain\": \"fault\", "
1630 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1636 char * expected_post_fault_double =
1638 "\"eventThrottlingState\": {"
1639 "\"eventThrottlingMode\": \"throttled\", "
1640 "\"eventDomainThrottleSpecificationList\": ["
1642 "\"eventDomain\": \"fault\", "
1643 "\"suppressedFieldNames\": ["
1644 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1650 /***************************************************************************/
1651 /* Initialize and provide a specification with a single fault suppressed. */
1652 /***************************************************************************/
1653 evel_throttle_initialize();
1654 handle_json_response(json_command_list_fault_single, &post);
1656 /***************************************************************************/
1657 /* Check that the FAULT domain is throttled. */
1658 /***************************************************************************/
1659 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1660 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1662 if (domain != EVEL_DOMAIN_FAULT)
1664 assert(evel_get_throttle_spec(domain) == NULL);
1667 assert(post.memory == NULL);
1669 /***************************************************************************/
1670 /* Request and verify the throttling state. */
1671 /***************************************************************************/
1672 handle_json_response(json_command_list_provide, &post);
1673 assert(post.memory != NULL);
1674 compare_strings(expected_post_fault_single,
1676 strlen(expected_post_fault_single),
1677 "Fault - Single Field");
1681 /***************************************************************************/
1682 /* Update a specification with two faults suppressed. */
1683 /***************************************************************************/
1684 handle_json_response(json_command_list_fault_double, &post);
1686 /***************************************************************************/
1687 /* Check that the FAULT domain is throttled. */
1688 /***************************************************************************/
1689 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1690 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1692 if (domain != EVEL_DOMAIN_FAULT)
1694 assert(evel_get_throttle_spec(domain) == NULL);
1697 assert(post.memory == NULL);
1699 /***************************************************************************/
1700 /* Request and verify the throttling state. */
1701 /***************************************************************************/
1702 handle_json_response(json_command_list_provide, &post);
1703 assert(post.memory != NULL);
1704 compare_strings(expected_post_fault_double,
1706 strlen(expected_post_fault_double),
1707 "Fault - Double Field");
1711 /***************************************************************************/
1712 /* Now clear the FAULT domain. */
1713 /***************************************************************************/
1714 handle_json_response(json_command_list_fault_clear, &post);
1715 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1717 assert(evel_get_throttle_spec(domain) == NULL);
1720 evel_throttle_terminate();
1723 /**************************************************************************//**
1724 * Test a single domain, nv_pair suppression.
1725 *****************************************************************************/
1726 void test_json_throttle_spec_nv_pair()
1731 char * json_command_list_fault_pair_single =
1733 "\"commandList\": ["
1736 "\"commandType\": \"throttlingSpecification\", "
1737 "\"eventDomainThrottleSpecification\": {"
1738 "\"eventDomain\": \"fault\", "
1739 "\"suppressedNvPairsList\": ["
1741 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1742 "\"suppressedNvPairNames\": [\"name1\"]"
1751 char * json_command_list_fault_pair_double =
1753 "\"commandList\": ["
1756 "\"commandType\": \"throttlingSpecification\", "
1757 "\"eventDomainThrottleSpecification\": {"
1758 "\"eventDomain\": \"fault\", "
1759 "\"suppressedNvPairsList\": ["
1761 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1762 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1771 char * expected_post_fault_pair_single =
1773 "\"eventThrottlingState\": {"
1774 "\"eventThrottlingMode\": \"throttled\", "
1775 "\"eventDomainThrottleSpecificationList\": ["
1777 "\"eventDomain\": \"fault\", "
1778 "\"suppressedNvPairsList\": ["
1780 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1781 "\"suppressedNvPairNames\": [\"name1\"]"
1789 char * expected_post_fault_pair_double =
1791 "\"eventThrottlingState\": {"
1792 "\"eventThrottlingMode\": \"throttled\", "
1793 "\"eventDomainThrottleSpecificationList\": ["
1795 "\"eventDomain\": \"fault\", "
1796 "\"suppressedNvPairsList\": ["
1798 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1799 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1807 /***************************************************************************/
1808 /* Initialize and provide a specification with a single nvpair with a */
1809 /* single sub-field suppressed. */
1810 /***************************************************************************/
1811 evel_throttle_initialize();
1812 handle_json_response(json_command_list_fault_pair_single, &post);
1814 /***************************************************************************/
1815 /* Check that the FAULT domain is throttled. */
1816 /***************************************************************************/
1817 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1818 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1820 if (domain != EVEL_DOMAIN_FAULT)
1822 assert(evel_get_throttle_spec(domain) == NULL);
1825 assert(post.memory == NULL);
1827 /***************************************************************************/
1828 /* Request and verify the throttling state. */
1829 /***************************************************************************/
1830 handle_json_response(json_command_list_provide, &post);
1831 assert(post.memory != NULL);
1832 compare_strings(expected_post_fault_pair_single,
1834 strlen(expected_post_fault_pair_single),
1835 "Fault - Single Pair, Single Field");
1839 /***************************************************************************/
1840 /* Update a specification with a single nvpair with two sub-fields */
1842 /***************************************************************************/
1843 handle_json_response(json_command_list_fault_pair_double, &post);
1845 /***************************************************************************/
1846 /* Check that the FAULT domain is throttled. */
1847 /***************************************************************************/
1848 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1849 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1851 if (domain != EVEL_DOMAIN_FAULT)
1853 assert(evel_get_throttle_spec(domain) == NULL);
1856 assert(post.memory == NULL);
1858 /***************************************************************************/
1859 /* Request and verify the throttling state. */
1860 /***************************************************************************/
1861 handle_json_response(json_command_list_provide, &post);
1862 assert(post.memory != NULL);
1863 compare_strings(expected_post_fault_pair_double,
1865 strlen(expected_post_fault_pair_double),
1866 "Fault - Double Field");
1870 /***************************************************************************/
1871 /* Now clear the FAULT domain. */
1872 /***************************************************************************/
1873 handle_json_response(json_command_list_fault_clear, &post);
1874 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1876 assert(evel_get_throttle_spec(domain) == NULL);
1879 evel_throttle_terminate();
1882 /**************************************************************************//**
1883 * Test two domains, nv_pair suppression.
1884 *****************************************************************************/
1885 void test_json_throttle_spec_two_domains()
1890 char * json_command_list_two_domains =
1892 "\"commandList\": ["
1895 "\"commandType\": \"throttlingSpecification\", "
1896 "\"eventDomainThrottleSpecification\": {"
1897 "\"eventDomain\": \"fault\", "
1898 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1899 "\"suppressedNvPairsList\": ["
1901 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1902 "\"suppressedNvPairNames\": [\"name1\"]"
1906 "\"commandType\": \"throttlingSpecification\", "
1907 "\"eventDomainThrottleSpecification\": {"
1908 "\"eventDomain\": \"syslog\", "
1909 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1910 "\"suppressedNvPairsList\": ["
1912 "\"nvPairFieldName\": \"additionalFields\", "
1913 "\"suppressedNvPairNames\": [\"name1\"]"
1918 char * expected_post_two_domains =
1920 "\"eventThrottlingState\": {"
1921 "\"eventThrottlingMode\": \"throttled\", "
1922 "\"eventDomainThrottleSpecificationList\": ["
1924 "\"eventDomain\": \"fault\", "
1925 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1926 "\"suppressedNvPairsList\": ["
1928 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1929 "\"suppressedNvPairNames\": [\"name1\"]"
1932 "\"eventDomain\": \"syslog\", "
1933 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1934 "\"suppressedNvPairsList\": ["
1936 "\"nvPairFieldName\": \"additionalFields\", "
1937 "\"suppressedNvPairNames\": [\"name1\"]"
1943 /***************************************************************************/
1944 /* Initialize and provide a specification with a single nvpair with a */
1945 /* single sub-field suppressed. */
1946 /***************************************************************************/
1947 evel_throttle_initialize();
1948 handle_json_response(json_command_list_two_domains, &post);
1950 /***************************************************************************/
1951 /* Check that the FAULT and SYSLOG domains are throttled. */
1952 /***************************************************************************/
1953 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1954 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1955 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1957 if ((domain != EVEL_DOMAIN_FAULT) && (domain != EVEL_DOMAIN_SYSLOG))
1959 assert(evel_get_throttle_spec(domain) == NULL);
1962 assert(post.memory == NULL);
1964 /***************************************************************************/
1965 /* Request and verify the throttling state. */
1966 /***************************************************************************/
1967 handle_json_response(json_command_list_provide, &post);
1968 assert(post.memory != NULL);
1969 compare_strings(expected_post_two_domains,
1971 strlen(expected_post_two_domains),
1972 "Fault - Two Domains");
1976 /***************************************************************************/
1977 /* Now clear the FAULT and SYSLOG domains. */
1978 /***************************************************************************/
1979 handle_json_response(json_command_list_fault_clear, &post);
1980 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
1981 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1982 handle_json_response(json_command_list_syslog_clear, &post);
1983 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1985 assert(evel_get_throttle_spec(domain) == NULL);
1988 evel_throttle_terminate();
1991 /**************************************************************************//**
1992 * Test bad command type.
1993 *****************************************************************************/
1994 void test_json_throttle_spec_bad_command_type()
1999 /***************************************************************************/
2000 /* Search for "dodgy" in the JSON, and you will see the dodgy bits we're */
2001 /* handling in these tests. */
2002 /***************************************************************************/
2003 #define NUM_BAD_COMMANDS 8
2004 char * json_command_list_dodgy_command =
2006 "\"commandList\": ["
2009 "\"commandType\": \"dodgyCommand\", "
2010 "\"eventDomainThrottleSpecification\": {"
2011 "\"eventDomain\": \"fault\", "
2012 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2013 "\"suppressedNvPairsList\": ["
2015 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2016 "\"suppressedNvPairNames\": [\"name1\"]"
2021 char * json_command_list_dodgy_spec =
2023 "\"commandList\": ["
2026 "\"commandType\": \"throttlingSpecification\", "
2027 "\"dodgyEventDomainThrottleSpecification\": {"
2028 "\"eventDomain\": \"fault\", "
2029 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2030 "\"suppressedNvPairsList\": ["
2032 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2033 "\"suppressedNvPairNames\": [\"name1\"]"
2038 char * json_command_list_dodgy_event_domain_key =
2040 "\"commandList\": ["
2043 "\"commandType\": \"throttlingSpecification\", "
2044 "\"eventDomainThrottleSpecification\": {"
2045 "\"dodgyEventDomainKey\": \"fault\", "
2046 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2047 "\"suppressedNvPairsList\": ["
2049 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2050 "\"suppressedNvPairNames\": [\"name1\"]"
2055 char * json_command_list_dodgy_event_domain =
2057 "\"commandList\": ["
2060 "\"commandType\": \"throttlingSpecification\", "
2061 "\"eventDomainThrottleSpecification\": {"
2062 "\"eventDomain\": \"dodgyEventDomain\", "
2063 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2064 "\"suppressedNvPairsList\": ["
2066 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2067 "\"suppressedNvPairNames\": [\"name1\"]"
2072 char * json_command_list_dodgy_field_names_key =
2074 "\"commandList\": ["
2077 "\"commandType\": \"throttlingSpecification\", "
2078 "\"eventDomainThrottleSpecification\": {"
2079 "\"eventDomain\": \"fault\", "
2080 "\"suppressedNvPairsList\": ["
2082 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2083 "\"suppressedNvPairNames\": [\"name1\"]"
2088 char * json_command_list_dodgy_pair_names_list_key =
2090 "\"commandList\": ["
2093 "\"commandType\": \"throttlingSpecification\", "
2094 "\"eventDomainThrottleSpecification\": {"
2095 "\"eventDomain\": \"fault\", "
2096 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2097 "\"dodgySuppressedNvPairsListKey\": ["
2099 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2100 "\"suppressedNvPairNames\": [\"name1\"]"
2105 char * json_command_list_dodgy_pair_field_name_key =
2107 "\"commandList\": ["
2110 "\"commandType\": \"throttlingSpecification\", "
2111 "\"eventDomainThrottleSpecification\": {"
2112 "\"eventDomain\": \"fault\", "
2113 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2114 "\"suppressedNvPairsList\": ["
2116 "\"dodgyNvPairFieldNameKey\": \"alarmAdditionalInformation\", "
2117 "\"suppressedNvPairNames\": [\"name1\"]"
2122 char * json_command_list_dodgy_pair_names_key =
2124 "\"commandList\": ["
2127 "\"commandType\": \"throttlingSpecification\", "
2128 "\"eventDomainThrottleSpecification\": {"
2129 "\"eventDomain\": \"fault\", "
2130 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2131 "\"suppressedNvPairsList\": ["
2133 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2134 "\"dodgySuppressedNvPairNamesKey\": [\"name1\"]"
2139 char * json_command_list_dodgy_depth =
2141 "\"commandList\": ["
2144 "\"commandType\": \"throttlingSpecification\", "
2145 "\"eventDomainThrottleSpecification\": {"
2146 "\"eventDomain\": \"fault\", "
2147 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2148 "\"suppressedNvPairsList\": ["
2150 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2151 "\"dodgySuppressedNvPairNamesKey\": "
2152 "[\"name1\", [[[[[[[[]]]]]]]]]"
2157 char * expected_throttle_state_dodgy_field_names_key =
2159 "\"eventThrottlingState\": {"
2160 "\"eventThrottlingMode\": \"throttled\", "
2161 "\"eventDomainThrottleSpecificationList\": ["
2163 "\"eventDomain\": \"fault\", "
2164 "\"suppressedNvPairsList\": ["
2166 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2167 "\"suppressedNvPairNames\": [\"name1\"]"
2173 char * expected_throttle_state_dodgy_pair_names_list_key =
2175 "\"eventThrottlingState\": {"
2176 "\"eventThrottlingMode\": \"throttled\", "
2177 "\"eventDomainThrottleSpecificationList\": ["
2179 "\"eventDomain\": \"fault\", "
2180 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2186 char * expected_throttle_state_dodgy_pair_field_name_key =
2188 "\"eventThrottlingState\": {"
2189 "\"eventThrottlingMode\": \"throttled\", "
2190 "\"eventDomainThrottleSpecificationList\": ["
2192 "\"eventDomain\": \"fault\", "
2193 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2199 char * expected_throttle_state_dodgy_pair_names_key =
2201 "\"eventThrottlingState\": {"
2202 "\"eventThrottlingMode\": \"throttled\", "
2203 "\"eventDomainThrottleSpecificationList\": ["
2205 "\"eventDomain\": \"fault\", "
2206 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2212 char * json_command_lists[] = {
2213 json_command_list_dodgy_command,
2214 json_command_list_dodgy_spec,
2215 json_command_list_dodgy_event_domain_key,
2216 json_command_list_dodgy_event_domain,
2217 json_command_list_dodgy_depth,
2218 json_command_list_dodgy_field_names_key,
2219 json_command_list_dodgy_pair_names_list_key,
2220 json_command_list_dodgy_pair_field_name_key,
2221 json_command_list_dodgy_pair_names_key
2224 char * expected_posts[] = {
2225 expected_throttle_state_normal,
2226 expected_throttle_state_normal,
2227 expected_throttle_state_normal,
2228 expected_throttle_state_normal,
2229 expected_throttle_state_normal,
2230 expected_throttle_state_dodgy_field_names_key,
2231 expected_throttle_state_dodgy_pair_names_list_key,
2232 expected_throttle_state_dodgy_pair_field_name_key,
2233 expected_throttle_state_dodgy_pair_names_key
2236 const int num_commands =
2237 sizeof(json_command_lists) / sizeof(json_command_lists[0]);
2238 const int num_posts =
2239 sizeof(expected_posts) / sizeof(expected_posts[0]);
2240 assert(num_commands == num_posts);
2242 /***************************************************************************/
2243 /* Initialize and provide a specification with a single nvpair with a */
2244 /* single sub-field suppressed. */
2245 /***************************************************************************/
2246 evel_throttle_initialize();
2249 for (ii = 0; ii < num_commands; ii++)
2251 EVEL_DEBUG("Testing commandList[%d] = %s\n", ii, json_command_lists[ii]);
2252 handle_json_response(json_command_lists[ii], &post);
2254 /*************************************************************************/
2255 /* Check that throttling is in a normal state - because we ignored the */
2256 /* command / ..... */
2257 /*************************************************************************/
2258 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
2260 assert(evel_get_throttle_spec(domain) == NULL);
2262 if (expected_posts[ii] == expected_throttle_state_normal)
2264 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
2268 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2270 assert(post.memory == NULL);
2272 /*************************************************************************/
2273 /* Request and verify the throttling state. */
2274 /*************************************************************************/
2275 handle_json_response(json_command_list_provide, &post);
2276 assert(post.memory != NULL);
2277 compare_strings(expected_posts[ii],
2279 strlen(expected_posts[ii]),
2280 "Throttle State Normal");
2285 evel_throttle_terminate();
2288 void test_encode_fault_throttled()
2292 /***************************************************************************/
2293 /* We also test suppression of the event header parameters here. */
2294 /***************************************************************************/
2295 char * json_command_list =
2297 "\"commandList\": ["
2300 "\"commandType\": \"throttlingSpecification\", "
2301 "\"eventDomainThrottleSpecification\": {"
2302 "\"eventDomain\": \"fault\", "
2303 "\"suppressedFieldNames\": ["
2304 "\"alarmInterfaceA\", "
2306 "\"reportingEntityId\", "
2308 "\"suppressedNvPairsList\": ["
2310 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2311 "\"suppressedNvPairNames\": [\"name3\", \"name4\"]"
2318 "\"commonEventHeader\": {"
2319 "\"domain\": \"fault\", "
2320 "\"eventId\": \"122\", "
2321 "\"functionalRole\": \"UNIT TEST\", "
2322 "\"lastEpochMicrosec\": 1000002, "
2323 "\"priority\": \"Normal\", "
2324 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2325 "\"sequence\": 122, "
2326 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2327 "\"startEpochMicrosec\": 1000002, "
2330 "\"faultFields\": {"
2331 "\"alarmCondition\": \"My alarm condition\", "
2332 "\"eventSeverity\": \"MAJOR\", "
2333 "\"eventSourceType\": \"other\", "
2334 "\"specificProblem\": \"It broke very badly\", "
2335 "\"vfStatus\": \"Active\", "
2336 "\"faultFieldsVersion\": 1.1, "
2337 "\"alarmAdditionalInformation\": ["
2338 "{\"name\": \"name1\", "
2339 "\"value\": \"value1\"}, "
2340 "{\"name\": \"name2\", "
2341 "\"value\": \"value2\"}]"
2344 /***************************************************************************/
2345 /* Initialize and provide a specification with a single fault suppressed. */
2346 /***************************************************************************/
2347 evel_throttle_initialize();
2348 handle_json_response(json_command_list, &post);
2350 /***************************************************************************/
2351 /* Check that the domain is throttled. */
2352 /***************************************************************************/
2353 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2354 assert(post.memory == NULL);
2356 size_t json_size = 0;
2357 char json_body[EVEL_MAX_JSON_BODY];
2358 evel_set_next_event_sequence(122);
2359 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
2360 "It broke very badly",
2361 EVEL_PRIORITY_NORMAL,
2362 EVEL_SEVERITY_MAJOR,
2364 EVEL_VF_STATUS_PREP_TERMINATE);
2365 assert(fault != NULL);
2366 evel_fault_type_set(fault, "Bad things happen...");
2367 evel_fault_addl_info_add(fault, "name1", "value1");
2368 evel_fault_addl_info_add(fault, "name2", "value2");
2370 /***************************************************************************/
2371 /* Suppressed fields. */
2372 /***************************************************************************/
2373 evel_fault_interface_set(fault, "My Interface Card");
2374 evel_fault_addl_info_add(fault, "name3", "value3");
2375 evel_fault_addl_info_add(fault, "name4", "value4");
2377 json_size = evel_json_encode_event(
2378 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
2379 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
2380 assert((json_size == strlen(json_body)) && "Bad size returned");
2382 evel_free_event(fault);
2383 evel_throttle_terminate();
2386 void test_encode_measurement_throttled()
2390 /***************************************************************************/
2391 /* We also test suppression of the event header parameters here. */
2392 /***************************************************************************/
2393 char * json_command_list =
2395 "\"commandList\": ["
2398 "\"commandType\": \"throttlingSpecification\", "
2399 "\"eventDomainThrottleSpecification\": {"
2400 "\"eventDomain\": \"measurementsForVfScaling\", "
2401 "\"suppressedFieldNames\": ["
2403 "\"vnfcScalingMetric\", "
2404 "\"numberOfMediaPortsInUse\", "
2405 "\"aggregateCpuUsage\", "
2408 "\"memoryConfigured\", "
2409 "\"meanRequestLatency\", "
2410 "\"latencyDistribution\", "
2411 "\"concurrentSessions\", "
2412 "\"configuredEntities\", "
2414 "\"reportingEntityId\", "
2416 "\"suppressedNvPairsList\": ["
2418 "\"nvPairFieldName\": \"cpuUsageArray\", "
2419 "\"suppressedNvPairNames\": [\"cpu3\", \"cpu4\"]"
2422 "\"nvPairFieldName\": \"filesystemUsageArray\", "
2423 "\"suppressedNvPairNames\": [\"00-11-22\", \"33-44-55\"]"
2426 "\"nvPairFieldName\": \"vNicUsageArray\", "
2427 "\"suppressedNvPairNames\": [\"eth1\", \"eth0\"]"
2430 "\"nvPairFieldName\": \"featureUsageArray\", "
2431 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2434 "\"nvPairFieldName\": \"codecUsageArray\", "
2435 "\"suppressedNvPairNames\": [\"G729ab\"]"
2438 "\"nvPairFieldName\": \"additionalMeasurements\", "
2439 "\"suppressedNvPairNames\": [\"Group2\"]"
2447 "{\"commonEventHeader\": {"
2448 "\"domain\": \"measurementsForVfScaling\", "
2449 "\"eventId\": \"123\", "
2450 "\"functionalRole\": \"UNIT TEST\", "
2451 "\"lastEpochMicrosec\": 1000002, "
2452 "\"priority\": \"Normal\", "
2453 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2454 "\"sequence\": 123, "
2455 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2456 "\"startEpochMicrosec\": 1000002, "
2459 "\"measurementsForVfScalingFields\": "
2461 "\"measurementInterval\": 5.500000, "
2462 "\"cpuUsageArray\": ["
2463 "{\"cpuIdentifier\": \"cpu1\", "
2464 "\"percentUsage\": 11.110000}, "
2465 "{\"cpuIdentifier\": \"cpu2\", "
2466 "\"percentUsage\": 22.220000}], "
2467 "\"filesystemUsageArray\": ["
2468 "{\"blockConfigured\": 500.110000, "
2469 "\"blockIops\": 77, "
2470 "\"blockUsed\": 500.220000, "
2471 "\"ephemeralConfigured\": 500.110000, "
2472 "\"ephemeralIops\": 88, "
2473 "\"ephemeralUsed\": 600.220000, "
2474 "\"filesystemName\": \"66-77-88\"}], "
2475 "\"featureUsageArray\": ["
2476 "{\"featureIdentifier\": \"FeatureA\", "
2477 "\"featureUtilization\": 123}], "
2478 "\"codecUsageArray\": ["
2479 "{\"codecIdentifier\": \"G711a\", "
2480 "\"numberInUse\": 91}], "
2481 "\"additionalMeasurements\": ["
2482 "{\"name\": \"Group1\", "
2483 "\"measurements\": ["
2484 "{\"name\": \"Name1\", "
2485 "\"value\": \"Value1\"}]}], "
2486 "\"measurementsForVfScalingVersion\": 1.1}}}";
2487 MEASUREMENT_CPU_USE *cpu_use;
2489 /***************************************************************************/
2490 /* Initialize and provide a specification with a single fault suppressed. */
2491 /***************************************************************************/
2492 evel_throttle_initialize();
2493 handle_json_response(json_command_list, &post);
2495 /***************************************************************************/
2496 /* Check that the domain is throttled. */
2497 /***************************************************************************/
2498 assert(evel_get_throttle_spec(EVEL_DOMAIN_MEASUREMENT) != NULL);
2499 assert(post.memory == NULL);
2501 size_t json_size = 0;
2502 char json_body[EVEL_MAX_JSON_BODY];
2503 evel_set_next_event_sequence(123);
2504 EVENT_MEASUREMENT * measurement = evel_new_measurement(5.5);
2505 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
2506 MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
2507 assert(measurement != NULL);
2509 evel_measurement_type_set(measurement, "Perf management...");
2510 evel_measurement_conc_sess_set(measurement, 1);
2511 evel_measurement_cfg_ents_set(measurement, 2);
2512 evel_measurement_mean_req_lat_set(measurement, 4.4);
2513 evel_measurement_mem_cfg_set(measurement, 6.6);
2514 evel_measurement_mem_used_set(measurement, 3.3);
2515 evel_measurement_request_rate_set(measurement, 7);
2517 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
2518 evel_measurement_cpu_use_idle_set(cpu_use,22.22);
2519 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2520 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2521 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2522 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2523 evel_measurement_cpu_use_system_set(cpu_use,77.77);
2524 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2525 evel_measurement_cpu_use_wait_set(cpu_use,99.99);
2527 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
2528 evel_measurement_cpu_use_idle_set(cpu_use,12.22);
2529 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2530 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2531 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2532 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2533 evel_measurement_cpu_use_system_set(cpu_use,77.77);
2534 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2535 evel_measurement_cpu_use_wait_set(cpu_use,19.99);
2537 evel_measurement_fsys_use_add(measurement, "00-11-22",
2539 200.11, 200.22, 44);
2540 evel_measurement_fsys_use_add(measurement, "33-44-55",
2542 400.11, 400.22, 66);
2543 evel_measurement_fsys_use_add(measurement, "66-77-88",
2545 600.11, 600.22, 88);
2547 bucket = evel_new_meas_latency_bucket(20);
2548 evel_meas_latency_bucket_add(measurement, bucket);
2550 bucket = evel_new_meas_latency_bucket(30);
2551 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
2552 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
2553 evel_meas_latency_bucket_add(measurement, bucket);
2555 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
2556 evel_vnic_use_bcast_pkt_in_set(vnic_use, 1);
2557 evel_vnic_use_bcast_pkt_out_set(vnic_use, 2);
2558 evel_vnic_use_mcast_pkt_in_set(vnic_use, 5);
2559 evel_vnic_use_mcast_pkt_out_set(vnic_use, 6);
2560 evel_vnic_use_ucast_pkt_in_set(vnic_use, 7);
2561 evel_vnic_use_ucast_pkt_out_set(vnic_use, 8);
2562 evel_meas_vnic_use_add(measurement, vnic_use);
2564 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
2565 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
2566 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
2567 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
2568 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
2569 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
2570 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
2571 evel_meas_vnic_use_add(measurement, vnic_use);
2573 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
2574 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
2575 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
2576 evel_measurement_codec_use_add(measurement, "G711a", 91);
2577 evel_measurement_codec_use_add(measurement, "G729ab", 92);
2578 evel_measurement_media_port_use_set(measurement, 1234);
2579 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
2580 evel_measurement_custom_measurement_add(measurement,
2581 "Group1", "Name1", "Value1");
2582 evel_measurement_custom_measurement_add(measurement,
2583 "Group2", "Name1", "Value1");
2584 evel_measurement_custom_measurement_add(measurement,
2585 "Group2", "Name2", "Value2");
2587 json_size = evel_json_encode_event(
2588 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
2589 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
2590 assert((json_size == strlen(json_body)) && "Bad size returned");
2592 evel_free_event(measurement);
2593 evel_throttle_terminate();
2596 void test_encode_mobile_throttled()
2600 /***************************************************************************/
2601 /* We also test suppression of the event header parameters here. */
2602 /***************************************************************************/
2603 char * json_command_list =
2605 "\"commandList\": ["
2608 "\"commandType\": \"throttlingSpecification\", "
2609 "\"eventDomainThrottleSpecification\": {"
2610 "\"eventDomain\": \"mobileFlow\", "
2611 "\"suppressedFieldNames\": ["
2612 "\"applicationType\", "
2613 "\"appProtocolType\", "
2614 "\"appProtocolVersion\", "
2616 "\"connectionType\", "
2618 "\"gtpProtocolType\", "
2627 "\"otherFunctionalRole\", "
2629 "\"radioAccessTechnology\", "
2631 "\"samplingAlgorithm\", "
2636 "\"reportingEntityId\", "
2638 "\"suppressedNvPairsList\": ["
2645 "{\"commonEventHeader\": {"
2646 "\"domain\": \"mobileFlow\", "
2647 "\"eventId\": \"1242\", "
2648 "\"functionalRole\": \"UNIT TEST\", "
2649 "\"lastEpochMicrosec\": 1000002, "
2650 "\"priority\": \"Normal\", "
2651 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2652 "\"sequence\": 1242, "
2653 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2654 "\"startEpochMicrosec\": 1000002, "
2657 "\"mobileFlowFields\": {"
2658 "\"flowDirection\": \"Inbound\", "
2659 "\"gtpPerFlowMetrics\": {"
2660 "\"avgBitErrorRate\": 132.000100, "
2661 "\"avgPacketDelayVariation\": 31.200000, "
2662 "\"avgPacketLatency\": 101, "
2663 "\"avgReceiveThroughput\": 2101, "
2664 "\"avgTransmitThroughput\": 501, "
2665 "\"flowActivationEpoch\": 1470409422, "
2666 "\"flowActivationMicrosec\": 988, "
2667 "\"flowDeactivationEpoch\": 1470409432, "
2668 "\"flowDeactivationMicrosec\": 12, "
2669 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
2670 "\"flowStatus\": \"Inactive\", "
2671 "\"maxPacketDelayVariation\": 88, "
2672 "\"numActivationFailures\": 4, "
2673 "\"numBitErrors\": 18, "
2674 "\"numBytesReceived\": 123655, "
2675 "\"numBytesTransmitted\": 4562, "
2676 "\"numDroppedPackets\": 1, "
2677 "\"numL7BytesReceived\": 13, "
2678 "\"numL7BytesTransmitted\": 11, "
2679 "\"numLostPackets\": 2, "
2680 "\"numOutOfOrderPackets\": 4, "
2681 "\"numPacketErrors\": 8, "
2682 "\"numPacketsReceivedExclRetrans\": 900, "
2683 "\"numPacketsReceivedInclRetrans\": 902, "
2684 "\"numPacketsTransmittedInclRetrans\": 303, "
2685 "\"numRetries\": 7, "
2686 "\"numTimeouts\": 3, "
2687 "\"numTunneledL7BytesReceived\": 1, "
2688 "\"roundTripTime\": 111, "
2689 "\"timeToFirstByte\": 226, "
2690 "\"ipTosCountList\": ["
2694 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
2695 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
2696 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
2697 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
2698 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
2699 "\"durConnectionFailedStatus\": 12, "
2700 "\"durTunnelFailedStatus\": 13, "
2701 "\"flowActivatedBy\": \"Remote\", "
2702 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
2703 "\"flowDeactivatedBy\": \"Remote\", "
2704 "\"gtpConnectionStatus\": \"Connected\", "
2705 "\"gtpTunnelStatus\": \"Not tunneling\", "
2706 "\"largePacketRtt\": 80, "
2707 "\"largePacketThreshold\": 600.000000, "
2708 "\"maxReceiveBitRate\": 1357924680, "
2709 "\"maxTransmitBitRate\": 235711, "
2710 "\"numGtpEchoFailures\": 1, "
2711 "\"numGtpTunnelErrors\": 4, "
2712 "\"numHttpErrors\": 2"
2714 "\"ipProtocolType\": \"UDP\", "
2715 "\"ipVersion\": \"IPv6\", "
2716 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
2717 "\"otherEndpointPort\": 2342, "
2718 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
2719 "\"reportingEndpointPort\": 4322"
2722 /***************************************************************************/
2723 /* Initialize and provide a specification with a single fault suppressed. */
2724 /***************************************************************************/
2725 evel_throttle_initialize();
2726 handle_json_response(json_command_list, &post);
2728 /***************************************************************************/
2729 /* Check that the domain is throttled. */
2730 /***************************************************************************/
2731 assert(evel_get_throttle_spec(EVEL_DOMAIN_MOBILE_FLOW) != NULL);
2732 assert(post.memory == NULL);
2734 size_t json_size = 0;
2735 char json_body[EVEL_MAX_JSON_BODY];
2736 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
2737 EVENT_MOBILE_FLOW * mobile_flow = NULL;
2739 /***************************************************************************/
2741 /***************************************************************************/
2742 evel_set_next_event_sequence(1242);
2744 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
2774 assert(metrics != NULL);
2776 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
2777 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
2778 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
2779 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
2780 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
2781 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
2782 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
2783 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
2784 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
2785 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
2786 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
2787 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
2788 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
2789 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
2790 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
2791 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
2792 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
2793 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
2794 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
2795 evel_mobile_gtp_metrics_qci_cos_count_add(
2796 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
2797 evel_mobile_gtp_metrics_qci_cos_count_add(
2798 metrics, EVEL_QCI_COS_LTE_65, 122);
2800 mobile_flow = evel_new_mobile_flow("Inbound",
2808 assert(mobile_flow != NULL);
2810 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
2811 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
2812 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
2813 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
2814 evel_mobile_flow_cid_set(mobile_flow, "65535");
2815 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
2816 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
2817 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
2818 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
2819 evel_mobile_flow_http_header_set(mobile_flow,
2820 "http://www.something.com");
2821 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
2822 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
2823 evel_mobile_flow_lac_set(mobile_flow, "1");
2824 evel_mobile_flow_mcc_set(mobile_flow, "410");
2825 evel_mobile_flow_mnc_set(mobile_flow, "04");
2826 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
2827 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
2828 evel_mobile_flow_rac_set(mobile_flow, "514");
2829 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
2830 evel_mobile_flow_sac_set(mobile_flow, "1");
2831 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
2832 evel_mobile_flow_tac_set(mobile_flow, "2099");
2833 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
2834 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
2836 json_size = evel_json_encode_event(
2837 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
2838 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
2839 assert((json_size == strlen(json_body)) && "Bad size returned");
2841 evel_free_event(mobile_flow);
2842 evel_throttle_terminate();
2845 void test_encode_other_throttled()
2849 /***************************************************************************/
2850 /* We also test suppression of the event header parameters here. */
2851 /***************************************************************************/
2852 char * json_command_list =
2854 "\"commandList\": ["
2857 "\"commandType\": \"throttlingSpecification\", "
2858 "\"eventDomainThrottleSpecification\": {"
2859 "\"eventDomain\": \"other\", "
2860 "\"suppressedFieldNames\": ["
2862 "\"reportingEntityId\", "
2864 "\"suppressedNvPairsList\": ["
2871 "{\"commonEventHeader\": {"
2872 "\"domain\": \"other\", "
2873 "\"eventId\": \"129\", "
2874 "\"functionalRole\": \"UNIT TEST\", "
2875 "\"lastEpochMicrosec\": 1000002, "
2876 "\"priority\": \"Normal\", "
2877 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2878 "\"sequence\": 129, "
2879 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2880 "\"startEpochMicrosec\": 1000002, "
2883 "\"otherFields\": ["
2884 "{\"name\": \"Other field 1\", "
2885 "\"value\": \"Other value 1\"}, "
2886 "{\"name\": \"Other field 2\", "
2887 "\"value\": \"Other value 2\"}"
2891 /***************************************************************************/
2892 /* Initialize and provide a specification with a single fault suppressed. */
2893 /***************************************************************************/
2894 evel_throttle_initialize();
2895 handle_json_response(json_command_list, &post);
2897 /***************************************************************************/
2898 /* Check that the domain is throttled. */
2899 /***************************************************************************/
2900 assert(evel_get_throttle_spec(EVEL_DOMAIN_OTHER) != NULL);
2901 assert(post.memory == NULL);
2903 size_t json_size = 0;
2904 char json_body[EVEL_MAX_JSON_BODY];
2905 EVENT_OTHER * other = NULL;
2906 evel_set_next_event_sequence(129);
2907 other = evel_new_other();
2908 assert(other != NULL);
2909 evel_other_type_set(other, "Other Type");
2910 evel_other_field_add(other,
2913 evel_other_field_add(other,
2917 json_size = evel_json_encode_event(
2918 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
2919 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
2920 assert((json_size == strlen(json_body)) && "Bad size returned");
2922 evel_free_event(other);
2923 evel_throttle_terminate();
2926 void test_encode_report_throttled()
2930 /***************************************************************************/
2931 /* We also test suppression of the event header parameters here. */
2932 /***************************************************************************/
2933 char * json_command_list =
2935 "\"commandList\": ["
2938 "\"commandType\": \"throttlingSpecification\", "
2939 "\"eventDomainThrottleSpecification\": {"
2940 "\"eventDomain\": \"report\", "
2941 "\"suppressedFieldNames\": ["
2943 "\"reportingEntityId\", "
2945 "\"suppressedNvPairsList\": ["
2947 "\"nvPairFieldName\": \"featureUsageArray\", "
2948 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2951 "\"nvPairFieldName\": \"additionalMeasurements\", "
2952 "\"suppressedNvPairNames\": [\"Group2\"]"
2960 "{\"commonEventHeader\": {"
2961 "\"domain\": \"measurementsForVfReporting\", "
2962 "\"eventId\": \"125\", "
2963 "\"functionalRole\": \"UNIT TEST\", "
2964 "\"lastEpochMicrosec\": 1000002, "
2965 "\"priority\": \"Normal\", "
2966 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2967 "\"sequence\": 125, "
2968 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2969 "\"startEpochMicrosec\": 1000002, "
2972 "\"measurementsForVfReportingFields\": "
2973 "{\"measurementInterval\": 1.100000, "
2974 "\"featureUsageArray\": ["
2975 "{\"featureIdentifier\": \"FeatureA\", "
2976 "\"featureUtilization\": 123}], "
2977 "\"additionalMeasurements\": ["
2978 "{\"name\": \"Group1\", "
2979 "\"measurements\": ["
2980 "{\"name\": \"Name1\", "
2981 "\"value\": \"Value1\"}]}], "
2982 "\"measurementFieldsVersion\": 1.1}}}";
2984 /***************************************************************************/
2985 /* Initialize and provide a specification with a single fault suppressed. */
2986 /***************************************************************************/
2987 evel_throttle_initialize();
2988 handle_json_response(json_command_list, &post);
2990 /***************************************************************************/
2991 /* Check that the domain is throttled. */
2992 /***************************************************************************/
2993 assert(evel_get_throttle_spec(EVEL_DOMAIN_REPORT) != NULL);
2994 assert(post.memory == NULL);
2996 size_t json_size = 0;
2997 char json_body[EVEL_MAX_JSON_BODY];
2998 EVENT_REPORT * report = NULL;
3000 /***************************************************************************/
3002 /***************************************************************************/
3003 evel_set_next_event_sequence(125);
3004 report = evel_new_report(1.1);
3005 assert(report != NULL);
3006 evel_report_type_set(report, "Perf reporting...");
3007 evel_report_feature_use_add(report, "FeatureA", 123);
3008 evel_report_feature_use_add(report, "FeatureB", 567);
3009 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
3010 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
3011 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
3013 json_size = evel_json_encode_event(
3014 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
3015 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
3016 assert((json_size == strlen(json_body)) && "Bad size returned");
3018 evel_free_event(report);
3019 evel_throttle_terminate();
3022 void test_encode_service_throttled()
3026 /***************************************************************************/
3027 /* We also test suppression of the event header parameters here. */
3028 /***************************************************************************/
3029 char * json_command_list =
3031 "\"commandList\": ["
3034 "\"commandType\": \"throttlingSpecification\", "
3035 "\"eventDomainThrottleSpecification\": {"
3036 "\"eventDomain\": \"serviceEvents\", "
3037 "\"suppressedFieldNames\": ["
3040 "\"codecSelected\", "
3041 "\"codecSelectedTranscoding\", "
3042 "\"endOfCallVqmSummaries\", "
3045 "\"reportingEntityId\", "
3047 "\"suppressedNvPairsList\": ["
3049 "\"nvPairFieldName\": \"additionalFields\", "
3050 "\"suppressedNvPairNames\": [\"Name1\", \"Name3\"]"
3058 "{\"commonEventHeader\": {"
3059 "\"domain\": \"serviceEvents\", "
3060 "\"eventId\": \"2000\", "
3061 "\"functionalRole\": \"UNIT TEST\", "
3062 "\"lastEpochMicrosec\": 1000002, "
3063 "\"priority\": \"Normal\", "
3064 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3065 "\"sequence\": 2000, "
3066 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3067 "\"startEpochMicrosec\": 1000002, "
3070 "\"serviceEventsFields\": {"
3071 "\"eventInstanceIdentifier\": "
3073 "\"vendorId\": \"vendor_x_id\", "
3074 "\"eventId\": \"vendor_x_event_id\", "
3075 "\"productId\": \"vendor_x_product_id\", "
3076 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3077 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3079 "\"serviceEventsFieldsVersion\": 1.1, "
3080 "\"additionalFields\": ["
3081 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
3082 "{\"name\": \"Name4\", \"value\": \"Value4\"}]"
3085 /***************************************************************************/
3086 /* Initialize and provide a specification with a single fault suppressed. */
3087 /***************************************************************************/
3088 evel_throttle_initialize();
3089 handle_json_response(json_command_list, &post);
3091 /***************************************************************************/
3092 /* Check that the domain is throttled. */
3093 /***************************************************************************/
3094 assert(evel_get_throttle_spec(EVEL_DOMAIN_SERVICE) != NULL);
3095 assert(post.memory == NULL);
3097 size_t json_size = 0;
3098 char json_body[EVEL_MAX_JSON_BODY];
3099 EVENT_SERVICE * event = NULL;
3100 evel_set_next_event_sequence(2000);
3101 event = evel_new_service("vendor_x_id", "vendor_x_event_id");
3102 assert(event != NULL);
3103 evel_service_type_set(event, "Service Event");
3104 evel_service_product_id_set(event, "vendor_x_product_id");
3105 evel_service_subsystem_id_set(event, "vendor_x_subsystem_id");
3106 evel_service_friendly_name_set(event, "vendor_x_frieldly_name");
3107 evel_service_correlator_set(event, "vendor_x_correlator");
3108 evel_service_codec_set(event, "PCMA");
3109 evel_service_codec_set(event, "PCMA");
3110 evel_service_callee_codec_set(event, "PCMA");
3111 evel_service_caller_codec_set(event, "G729A");
3112 evel_service_rtcp_data_set(event, "some_rtcp_data");
3113 evel_service_adjacency_name_set(event, "vendor_x_adjacency");
3114 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
3115 evel_service_endpoint_jitter_set(event, 66);
3116 evel_service_endpoint_rtp_oct_disc_set(event, 100);
3117 evel_service_endpoint_rtp_oct_recv_set(event, 200);
3118 evel_service_endpoint_rtp_oct_sent_set(event, 300);
3119 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
3120 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
3121 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
3122 evel_service_local_jitter_set(event, 99);
3123 evel_service_local_rtp_oct_disc_set(event, 150);
3124 evel_service_local_rtp_oct_recv_set(event, 250);
3125 evel_service_local_rtp_oct_sent_set(event, 350);
3126 evel_service_local_rtp_pkt_disc_set(event, 450);
3127 evel_service_local_rtp_pkt_recv_set(event, 550);
3128 evel_service_local_rtp_pkt_sent_set(event, 650);
3129 evel_service_mos_cqe_set(event, 12.255);
3130 evel_service_packets_lost_set(event, 157);
3131 evel_service_packet_loss_percent_set(event, 0.232);
3132 evel_service_r_factor_set(event, 11);
3133 evel_service_round_trip_delay_set(event, 15);
3134 evel_service_phone_number_set(event, "0888888888");
3135 evel_service_addl_field_add(event, "Name1", "Value1");
3136 evel_service_addl_field_add(event, "Name2", "Value2");
3137 evel_service_addl_field_add(event, "Name3", "Value3");
3138 evel_service_addl_field_add(event, "Name4", "Value4");
3139 json_size = evel_json_encode_event(
3140 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3141 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
3142 assert((json_size == strlen(json_body)) && "Bad size returned");
3144 evel_free_event(event);
3145 evel_throttle_terminate();
3148 void test_encode_signaling_throttled()
3152 /***************************************************************************/
3153 /* We also test suppression of the event header parameters here. */
3154 /***************************************************************************/
3155 char * json_command_list =
3157 "\"commandList\": ["
3160 "\"commandType\": \"throttlingSpecification\", "
3161 "\"eventDomainThrottleSpecification\": {"
3162 "\"eventDomain\": \"signaling\", "
3163 "\"suppressedFieldNames\": ["
3166 "\"reportingEntityId\", "
3168 "\"localIpAddress\", "
3170 "\"remoteIpAddress\", "
3172 "\"compressedSip\", "
3174 "\"suppressedNvPairsList\": ["
3181 "{\"commonEventHeader\": {"
3182 "\"domain\": \"signaling\", "
3183 "\"eventId\": \"2001\", "
3184 "\"functionalRole\": \"UNIT TEST\", "
3185 "\"lastEpochMicrosec\": 1000002, "
3186 "\"priority\": \"Normal\", "
3187 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3188 "\"sequence\": 2001, "
3189 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3190 "\"startEpochMicrosec\": 1000002, "
3193 "\"signalingFields\": {"
3194 "\"eventInstanceIdentifier\": "
3196 "\"vendorId\": \"vendor_x_id\", "
3197 "\"eventId\": \"vendor_x_event_id\", "
3198 "\"productId\": \"vendor_x_product_id\", "
3199 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3200 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3202 "\"signalingFieldsVersion\": 1.1"
3205 /***************************************************************************/
3206 /* Initialize and provide a specification with a single fault suppressed. */
3207 /***************************************************************************/
3208 evel_throttle_initialize();
3209 handle_json_response(json_command_list, &post);
3211 /***************************************************************************/
3212 /* Check that the domain is throttled. */
3213 /***************************************************************************/
3214 assert(evel_get_throttle_spec(EVEL_DOMAIN_SIGNALING) != NULL);
3215 assert(post.memory == NULL);
3217 size_t json_size = 0;
3218 char json_body[EVEL_MAX_JSON_BODY];
3219 EVENT_SIGNALING * event = NULL;
3220 evel_set_next_event_sequence(2001);
3221 event = evel_new_signaling("vendor_x_id",
3222 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
3223 assert(event != NULL);
3224 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
3225 evel_signaling_vnfname_set(event, "vendor_x_vnf");
3226 evel_signaling_type_set(event, "Signaling");
3227 evel_signaling_product_id_set(event, "vendor_x_product_id");
3228 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
3229 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
3230 evel_signaling_correlator_set(event, "vendor_x_correlator");
3231 evel_signaling_local_ip_address_set(event, "1.0.3.1");
3232 evel_signaling_local_port_set(event, "1031");
3233 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
3234 evel_signaling_remote_port_set(event, "5330");
3235 evel_signaling_compressed_sip_set(event, "compressed_sip");
3236 evel_signaling_summary_sip_set(event, "summary_sip");
3237 json_size = evel_json_encode_event(
3238 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3239 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
3240 assert((json_size == strlen(json_body)) && "Bad size returned");
3242 evel_free_event(event);
3243 evel_throttle_terminate();
3246 void test_encode_state_change_throttled()
3250 /***************************************************************************/
3251 /* We also test suppression of the event header parameters here. */
3252 /***************************************************************************/
3253 char * json_command_list =
3255 "\"commandList\": ["
3258 "\"commandType\": \"throttlingSpecification\", "
3259 "\"eventDomainThrottleSpecification\": {"
3260 "\"eventDomain\": \"stateChange\", "
3261 "\"suppressedFieldNames\": ["
3263 "\"reportingEntityId\", "
3265 "\"suppressedNvPairsList\": ["
3267 "\"nvPairFieldName\": \"additionalFields\", "
3268 "\"suppressedNvPairNames\": [\"Name1\"]"
3276 "{\"commonEventHeader\": {"
3277 "\"domain\": \"stateChange\", "
3278 "\"eventId\": \"128\", "
3279 "\"functionalRole\": \"UNIT TEST\", "
3280 "\"lastEpochMicrosec\": 1000002, "
3281 "\"priority\": \"Normal\", "
3282 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3283 "\"sequence\": 128, "
3284 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3285 "\"startEpochMicrosec\": 1000002, "
3288 "\"stateChangeFields\": {"
3289 "\"newState\": \"inService\", "
3290 "\"oldState\": \"outOfService\", "
3291 "\"stateInterface\": \"An Interface\", "
3292 "\"additionalFields\": ["
3293 "{\"name\": \"Name2\", "
3294 "\"value\": \"Value2\"}"
3296 "\"stateChangeFieldsVersion\": 1.1"
3299 /***************************************************************************/
3300 /* Initialize and provide a specification with a single fault suppressed. */
3301 /***************************************************************************/
3302 evel_throttle_initialize();
3303 handle_json_response(json_command_list, &post);
3305 /***************************************************************************/
3306 /* Check that the domain is throttled. */
3307 /***************************************************************************/
3308 assert(evel_get_throttle_spec(EVEL_DOMAIN_STATE_CHANGE) != NULL);
3309 assert(post.memory == NULL);
3311 size_t json_size = 0;
3312 char json_body[EVEL_MAX_JSON_BODY];
3313 EVENT_STATE_CHANGE * state_change = NULL;
3314 evel_set_next_event_sequence(128);
3315 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
3316 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
3318 assert(state_change != NULL);
3319 evel_state_change_type_set(state_change, "SC Type");
3320 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
3321 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
3323 json_size = evel_json_encode_event(
3324 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
3325 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
3326 assert((json_size == strlen(json_body)) && "Bad size returned");
3328 evel_free_event(state_change);
3329 evel_throttle_terminate();
3332 void test_encode_syslog_throttled()
3336 /***************************************************************************/
3337 /* We also test suppression of the event header parameters here. */
3338 /***************************************************************************/
3339 char * json_command_list =
3341 "\"commandList\": ["
3344 "\"commandType\": \"throttlingSpecification\", "
3345 "\"eventDomainThrottleSpecification\": {"
3346 "\"eventDomain\": \"syslog\", "
3347 "\"suppressedFieldNames\": ["
3348 "\"eventSourceHost\", "
3349 "\"syslogFacility\", "
3351 "\"syslogProcId\", "
3355 "\"reportingEntityId\", "
3357 "\"suppressedNvPairsList\": ["
3359 "\"nvPairFieldName\": \"additionalFields\", "
3360 "\"suppressedNvPairNames\": [\"Name2\"]"
3368 "{\"commonEventHeader\": {"
3369 "\"domain\": \"syslog\", "
3370 "\"eventId\": \"126\", "
3371 "\"functionalRole\": \"UNIT TEST\", "
3372 "\"lastEpochMicrosec\": 1000002, "
3373 "\"priority\": \"Normal\", "
3374 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3375 "\"sequence\": 126, "
3376 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3377 "\"startEpochMicrosec\": 1000002, "
3380 "\"syslogFields\": {"
3381 "\"eventSourceType\": \"virtualNetworkFunction\", "
3382 "\"syslogMsg\": \"SL Message\", "
3383 "\"syslogTag\": \"SL Tag\", "
3384 "\"syslogFieldsVersion\": 1.1, "
3385 "\"additionalFields\": ["
3386 "{\"name\": \"Name1\", "
3387 "\"value\": \"Value1\"}"
3391 /***************************************************************************/
3392 /* Initialize and provide a specification with a single fault suppressed. */
3393 /***************************************************************************/
3394 evel_throttle_initialize();
3395 handle_json_response(json_command_list, &post);
3397 /***************************************************************************/
3398 /* Check that the domain is throttled. */
3399 /***************************************************************************/
3400 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
3401 assert(post.memory == NULL);
3403 size_t json_size = 0;
3404 char json_body[EVEL_MAX_JSON_BODY];
3405 EVENT_SYSLOG * syslog = NULL;
3406 evel_set_next_event_sequence(126);
3407 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
3410 assert(syslog != NULL);
3411 evel_syslog_type_set(syslog, "SL Type");
3412 evel_syslog_event_source_host_set(syslog, "SL Host");
3413 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
3414 evel_syslog_proc_set(syslog, "SL Proc");
3415 evel_syslog_proc_id_set(syslog, 2);
3416 evel_syslog_version_set(syslog, 1);
3417 evel_syslog_s_data_set(syslog, "SL SDATA");
3418 evel_syslog_addl_field_add(syslog, "Name1", "Value1");
3419 evel_syslog_addl_field_add(syslog, "Name2", "Value2");
3421 json_size = evel_json_encode_event(
3422 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
3423 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
3424 assert((json_size == strlen(json_body)) && "Bad size returned");
3426 evel_free_event(syslog);
3427 evel_throttle_terminate();
3430 void test_encode_fault_with_escaping()
3434 "\"commonEventHeader\": {"
3435 "\"domain\": \"fault\", "
3436 "\"eventId\": \"122\", "
3437 "\"functionalRole\": \"UNIT TEST\", "
3438 "\"lastEpochMicrosec\": 1000002, "
3439 "\"priority\": \"Normal\", "
3440 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3441 "\"sequence\": 122, "
3442 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3443 "\"startEpochMicrosec\": 1000002, "
3444 "\"version\": 1.2, "
3445 "\"eventType\": \"Bad things happen...\\\\\", "
3446 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
3447 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
3449 "\"faultFields\": {"
3450 "\"alarmCondition\": \"My alarm condition\", "
3451 "\"eventSeverity\": \"MAJOR\", "
3452 "\"eventSourceType\": \"other\", "
3453 "\"specificProblem\": \"It broke \\\"very\\\" badly\", "
3454 "\"vfStatus\": \"Active\", "
3455 "\"faultFieldsVersion\": 1.1, "
3456 "\"alarmAdditionalInformation\": ["
3457 "{\"name\": \"name1\", "
3458 "\"value\": \"value1\"}, "
3459 "{\"name\": \"name2\", "
3460 "\"value\": \"value2\"}], "
3461 "\"alarmInterfaceA\": \"My Interface Card\""
3464 size_t json_size = 0;
3465 char json_body[EVEL_MAX_JSON_BODY];
3466 evel_set_next_event_sequence(122);
3467 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
3468 "It broke \"very\" badly",
3469 EVEL_PRIORITY_NORMAL,
3470 EVEL_SEVERITY_MAJOR,
3472 EVEL_VF_STATUS_PREP_TERMINATE);
3473 assert(fault != NULL);
3474 evel_fault_type_set(fault, "Bad things happen...\\");
3475 evel_fault_interface_set(fault, "My Interface Card");
3476 evel_fault_addl_info_add(fault, "name1", "value1");
3477 evel_fault_addl_info_add(fault, "name2", "value2");
3479 json_size = evel_json_encode_event(
3480 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
3481 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
3482 assert((json_size == strlen(json_body)) && "Bad size returned");
3484 evel_free_event(fault);