1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 ****************************************************************************/
17 /**************************************************************************//**
19 * Unit tests for JSON encoding and throttling.
21 * This software is intended to show the essential elements of the library's
24 ****************************************************************************/
33 #include "evel_internal.h"
34 #include "evel_throttle.h"
46 /*****************************************************************************/
47 /* Local prototypes. */
48 /*****************************************************************************/
49 static void test_encode_heartbeat();
50 static void test_encode_header_overrides();
51 static void test_encode_fault();
52 static void test_encode_fault_with_escaping();
53 static void test_encode_measurement();
54 static void test_encode_mobile_mand();
55 static void test_encode_mobile_opts();
56 static void test_encode_other();
57 static void test_encode_report();
58 static void test_encode_service();
59 static void test_encode_service_subset(const SERVICE_TEST service_test);
60 static void test_encode_signaling();
61 static void test_encode_state_change();
62 static void test_encode_syslog();
63 static void test_json_response_junk();
64 static void test_json_provide_throttle_state();
65 static void test_json_measurement_interval();
66 static void test_json_throttle_spec_field();
67 static void test_json_throttle_spec_nv_pair();
68 static void test_json_throttle_spec_two_domains();
69 static void test_json_throttle_spec_bad_command_type();
70 static void test_encode_fault_throttled();
71 static void test_encode_measurement_throttled();
72 static void test_encode_mobile_throttled();
73 static void test_encode_other_throttled();
74 static void test_encode_report_throttled();
75 static void test_encode_service_throttled();
76 static void test_encode_signaling_throttled();
77 static void test_encode_state_change_throttled();
78 static void test_encode_syslog_throttled();
79 static void compare_strings(char * expected,
84 /**************************************************************************//**
87 * Runs all unit test cases, and fails hard on the first failure.
89 * @param[in] argc Argument count.
90 * @param[in] argv Argument vector - for usage see usage_text.
91 *****************************************************************************/
92 int main(int argc, char ** argv)
97 /***************************************************************************/
98 /* Fix our timezone to UTC. */
99 /***************************************************************************/
102 /***************************************************************************/
103 /* Initialize metadata. */
104 /***************************************************************************/
105 openstack_metadata_initialize();
107 /***************************************************************************/
108 /* Minimal initialisation to exercise the encoders. */
109 /***************************************************************************/
110 functional_role = "UNIT TEST";
111 log_initialize(EVEL_LOG_DEBUG, "EVEL");
113 /***************************************************************************/
114 /* Test each encoder. */
115 /***************************************************************************/
116 test_encode_heartbeat();
117 test_encode_header_overrides();
119 test_encode_measurement();
120 test_encode_mobile_mand();
121 test_encode_mobile_opts();
123 test_encode_report();
124 test_encode_service();
125 test_encode_signaling();
126 test_encode_state_change();
127 test_encode_syslog();
129 /***************************************************************************/
130 /* Test JSON Throttle. */
131 /***************************************************************************/
132 test_json_response_junk();
133 test_json_provide_throttle_state();
134 test_json_measurement_interval();
135 test_json_throttle_spec_field();
136 test_json_throttle_spec_nv_pair();
137 test_json_throttle_spec_two_domains();
138 test_json_throttle_spec_bad_command_type();
140 /***************************************************************************/
141 /* Test each encoder with throttling applied. */
142 /***************************************************************************/
143 test_encode_fault_throttled();
144 test_encode_measurement_throttled();
145 test_encode_mobile_throttled();
146 test_encode_other_throttled();
147 test_encode_report_throttled();
148 test_encode_service_throttled();
149 test_encode_signaling_throttled();
150 test_encode_state_change_throttled();
151 test_encode_syslog_throttled();
153 /***************************************************************************/
154 /* Test character escaping. */
155 /***************************************************************************/
156 test_encode_fault_with_escaping();
158 printf ("\nAll Tests Passed\n");
163 /*****************************************************************************/
164 /* We link with this gettimeofday so that we get a fixed result */
165 /*****************************************************************************/
166 int gettimeofday(struct timeval *tv,
167 struct timezone *tz __attribute__((unused)))
174 void test_encode_heartbeat()
178 "\"commonEventHeader\": {"
179 "\"domain\": \"heartbeat\", "
180 "\"eventId\": \"121\", "
181 "\"functionalRole\": \"UNIT TEST\", "
182 "\"lastEpochMicrosec\": 1000002, "
183 "\"priority\": \"Normal\", "
184 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
185 "\"sequence\": 121, "
186 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
187 "\"startEpochMicrosec\": 1000002, "
189 "\"eventType\": \"Autonomous heartbeat\", "
190 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
191 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
194 size_t json_size = 0;
195 char json_body[EVEL_MAX_JSON_BODY];
197 /***************************************************************************/
198 /* Test the VM name/uuid once. */
199 /***************************************************************************/
200 evel_set_next_event_sequence(121);
202 EVENT_HEADER * heartbeat = evel_new_heartbeat();
203 assert(heartbeat != NULL);
205 json_size = evel_json_encode_event(
206 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
207 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
208 assert((json_size == strlen(json_body)) && "Bad size returned");
210 evel_free_event(heartbeat);
213 void test_encode_header_overrides()
217 "\"commonEventHeader\": {"
218 "\"domain\": \"heartbeat\", "
219 "\"eventId\": \"121\", "
220 "\"functionalRole\": \"UNIT TEST\", "
221 "\"lastEpochMicrosec\": 1000, "
222 "\"priority\": \"Normal\", "
223 "\"reportingEntityName\": \"entity_name_override\", "
224 "\"sequence\": 121, "
225 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
226 "\"startEpochMicrosec\": 1001, "
228 "\"eventType\": \"Autonomous heartbeat\", "
229 "\"reportingEntityId\": \"entity_id_override\", "
230 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
233 size_t json_size = 0;
234 char json_body[EVEL_MAX_JSON_BODY];
236 /***************************************************************************/
237 /* Test the VM name/uuid once. */
238 /***************************************************************************/
239 evel_set_next_event_sequence(121);
241 EVENT_HEADER * heartbeat = evel_new_heartbeat();
242 assert(heartbeat != NULL);
244 evel_start_epoch_set(heartbeat, 1001);
245 evel_last_epoch_set(heartbeat, 1000);
246 evel_reporting_entity_name_set(heartbeat, "entity_name_override");
247 evel_reporting_entity_id_set(heartbeat, "entity_id_override");
249 json_size = evel_json_encode_event(
250 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
251 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
252 assert((json_size == strlen(json_body)) && "Bad size returned");
254 evel_free_event(heartbeat);
257 void test_encode_fault()
261 "\"commonEventHeader\": {"
262 "\"domain\": \"fault\", "
263 "\"eventId\": \"122\", "
264 "\"functionalRole\": \"UNIT TEST\", "
265 "\"lastEpochMicrosec\": 1000002, "
266 "\"priority\": \"Normal\", "
267 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
268 "\"sequence\": 122, "
269 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
270 "\"startEpochMicrosec\": 1000002, "
272 "\"eventType\": \"Bad things happen...\", "
273 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
274 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
277 "\"alarmCondition\": \"My alarm condition\", "
278 "\"eventSeverity\": \"MAJOR\", "
279 "\"eventSourceType\": \"other\", "
280 "\"specificProblem\": \"It broke very badly\", "
281 "\"eventCategory\": \"link\", "
282 "\"vfStatus\": \"Active\", "
283 "\"faultFieldsVersion\": 1.1, "
284 "\"alarmAdditionalInformation\": ["
285 "{\"name\": \"name1\", "
286 "\"value\": \"value1\"}, "
287 "{\"name\": \"name2\", "
288 "\"value\": \"value2\"}], "
289 "\"alarmInterfaceA\": \"My Interface Card\""
292 size_t json_size = 0;
293 char json_body[EVEL_MAX_JSON_BODY];
294 evel_set_next_event_sequence(122);
295 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
296 "It broke very badly",
297 EVEL_PRIORITY_NORMAL,
300 EVEL_VF_STATUS_PREP_TERMINATE);
301 assert(fault != NULL);
302 evel_fault_type_set(fault, "Bad things happen...");
303 evel_fault_interface_set(fault, "My Interface Card");
304 evel_fault_addl_info_add(fault, "name1", "value1");
305 evel_fault_addl_info_add(fault, "name2", "value2");
307 json_size = evel_json_encode_event(
308 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
309 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
310 assert((json_size == strlen(json_body)) && "Bad size returned");
312 evel_free_event(fault);
315 void test_encode_measurement()
319 "{\"commonEventHeader\": {"
320 "\"domain\": \"measurementsForVfScaling\", "
321 "\"eventId\": \"123\", "
322 "\"functionalRole\": \"UNIT TEST\", "
323 "\"lastEpochMicrosec\": 3000, "
324 "\"priority\": \"Normal\", "
325 "\"reportingEntityName\": \"entity_name\", "
326 "\"sequence\": 123, "
327 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
328 "\"startEpochMicrosec\": 2000, "
330 "\"eventType\": \"Perf management...\", "
331 "\"reportingEntityId\": \"entity_id\", "
332 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
334 "\"measurementsForVfScalingFields\": "
336 "\"measurementInterval\": 5.500000, "
337 "\"concurrentSessions\": 1, "
338 "\"configuredEntities\": 2, "
339 "\"cpuUsageArray\": ["
340 "{\"cpuIdentifier\": \"cpu1\", "
341 "\"percentUsage\": 11.110000}, "
342 "{\"cpuIdentifier\": \"cpu2\", "
343 "\"percentUsage\": 22.220000}], "
344 "\"filesystemUsageArray\": ["
345 "{\"blockConfigured\": 100.110000, "
346 "\"blockIops\": 33, "
347 "\"blockUsed\": 100.220000, "
348 "\"ephemeralConfigured\": 100.110000, "
349 "\"ephemeralIops\": 44, "
350 "\"ephemeralUsed\": 200.220000, "
351 "\"filesystemName\": \"00-11-22\"}, "
352 "{\"blockConfigured\": 300.110000, "
353 "\"blockIops\": 55, "
354 "\"blockUsed\": 300.220000, "
355 "\"ephemeralConfigured\": 300.110000, "
356 "\"ephemeralIops\": 66, "
357 "\"ephemeralUsed\": 400.220000, "
358 "\"filesystemName\": \"33-44-55\"}], "
359 "\"latencyDistribution\": ["
360 "{\"countsInTheBucket\": 20}, "
361 "{\"lowEndOfLatencyBucket\": 10.000000, "
362 "\"highEndOfLatencyBucket\": 20.000000, "
363 "\"countsInTheBucket\": 30}], "
364 "\"meanRequestLatency\": 4.400000, "
365 "\"memoryConfigured\": 6.600000, "
366 "\"memoryUsed\": 3.300000, "
367 "\"requestRate\": 7, "
368 "\"vNicUsageArray\": ["
372 "\"packetsIn\": 100, "
373 "\"packetsOut\": 200, "
374 "\"vNicIdentifier\": \"eth0\""
379 "\"packetsIn\": 110, "
380 "\"packetsOut\": 240, "
381 "\"vNicIdentifier\": \"eth1\", "
382 "\"broadcastPacketsIn\": 11, "
383 "\"broadcastPacketsOut\": 12, "
384 "\"multicastPacketsIn\": 15, "
385 "\"multicastPacketsOut\": 16, "
386 "\"unicastPacketsIn\": 17, "
387 "\"unicastPacketsOut\": 18"
390 "\"aggregateCpuUsage\": 8.800000, "
391 "\"numberOfMediaPortsInUse\": 1234, "
392 "\"vnfcScalingMetric\": 1234.567800, "
394 "\"receiveDiscards\": 1, "
395 "\"receiveErrors\": 0, "
396 "\"transmitDiscards\": 2, "
397 "\"transmitErrors\": 1}, "
398 "\"featureUsageArray\": ["
399 "{\"featureIdentifier\": \"FeatureA\", "
400 "\"featureUtilization\": 123}, "
401 "{\"featureIdentifier\": \"FeatureB\", "
402 "\"featureUtilization\": 567}], "
403 "\"codecUsageArray\": ["
404 "{\"codecIdentifier\": \"G711a\", "
405 "\"numberInUse\": 91}, "
406 "{\"codecIdentifier\": \"G729ab\", "
407 "\"numberInUse\": 92}], "
408 "\"additionalMeasurements\": ["
409 "{\"name\": \"Group1\", "
410 "\"measurements\": ["
411 "{\"name\": \"Name1\", "
412 "\"value\": \"Value1\"}]}, "
413 "{\"name\": \"Group2\", "
414 "\"measurements\": ["
415 "{\"name\": \"Name1\", "
416 "\"value\": \"Value1\"}, "
417 "{\"name\": \"Name2\", "
418 "\"value\": \"Value2\"}]}], "
419 "\"measurementsForVfScalingVersion\": 1.1}}}";
421 size_t json_size = 0;
422 char json_body[EVEL_MAX_JSON_BODY];
423 EVENT_MEASUREMENT * measurement = NULL;
424 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
425 MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
426 MEASUREMENT_CPU_USE *cpu_use;
428 /***************************************************************************/
430 /***************************************************************************/
431 evel_set_next_event_sequence(123);
432 measurement = evel_new_measurement(5.5);
433 assert(measurement != NULL);
434 evel_measurement_type_set(measurement, "Perf management...");
435 evel_measurement_conc_sess_set(measurement, 1);
436 evel_measurement_cfg_ents_set(measurement, 2);
437 evel_measurement_mean_req_lat_set(measurement, 4.4);
438 evel_measurement_request_rate_set(measurement, 7);
440 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
441 evel_measurement_cpu_use_idle_set(cpu_use,22.22);
442 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
443 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
444 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
445 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
446 evel_measurement_cpu_use_system_set(cpu_use,77.77);
447 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
448 evel_measurement_cpu_use_wait_set(cpu_use,99.99);
450 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
451 evel_measurement_cpu_use_idle_set(cpu_use,12.22);
452 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
453 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
454 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
455 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
456 evel_measurement_cpu_use_system_set(cpu_use,77.77);
457 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
458 evel_measurement_cpu_use_wait_set(cpu_use,19.99);
461 evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33,
463 evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55,
465 evel_start_epoch_set(&measurement->header, 2000);
466 evel_last_epoch_set(&measurement->header, 3000);
467 evel_reporting_entity_name_set(&measurement->header, "entity_name");
468 evel_reporting_entity_id_set(&measurement->header, "entity_id");
470 /***************************************************************************/
471 /* Latency Bucket with no optional parameters. */
472 /***************************************************************************/
473 bucket = evel_new_meas_latency_bucket(20);
474 evel_meas_latency_bucket_add(measurement, bucket);
476 /***************************************************************************/
477 /* Latency Bucket with all optional parameters. */
478 /***************************************************************************/
479 bucket = evel_new_meas_latency_bucket(30);
480 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
481 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
482 evel_meas_latency_bucket_add(measurement, bucket);
484 /***************************************************************************/
485 /* vNIC Use with no optional parameters. */
486 /***************************************************************************/
487 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
488 evel_meas_vnic_use_add(measurement, vnic_use);
490 /***************************************************************************/
491 /* vNIC Use with all optional parameters. */
492 /***************************************************************************/
493 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
494 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
495 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
496 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
497 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
498 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
499 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
500 evel_meas_vnic_use_add(measurement, vnic_use);
502 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
504 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
505 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
507 evel_measurement_codec_use_add(measurement, "G711a", 91);
508 evel_measurement_codec_use_add(measurement, "G729ab", 92);
510 evel_measurement_media_port_use_set(measurement, 1234);
512 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
514 evel_measurement_custom_measurement_add(measurement,
515 "Group1", "Name1", "Value1");
516 evel_measurement_custom_measurement_add(measurement,
517 "Group2", "Name1", "Value1");
518 evel_measurement_custom_measurement_add(measurement,
519 "Group2", "Name2", "Value2");
521 json_size = evel_json_encode_event(
522 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
523 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
524 assert((json_size == strlen(json_body)) && "Bad size returned");
526 evel_free_event(measurement);
529 void test_encode_mobile_mand()
533 "{\"commonEventHeader\": {"
534 "\"domain\": \"mobileFlow\", "
535 "\"eventId\": \"1241\", "
536 "\"functionalRole\": \"UNIT TEST\", "
537 "\"lastEpochMicrosec\": 1000002, "
538 "\"priority\": \"Normal\", "
539 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
540 "\"sequence\": 1241, "
541 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
542 "\"startEpochMicrosec\": 1000002, "
544 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
545 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
547 "\"mobileFlowFields\": {"
548 "\"flowDirection\": \"Outbound\", "
549 "\"gtpPerFlowMetrics\": {"
550 "\"avgBitErrorRate\": 12.300000, "
551 "\"avgPacketDelayVariation\": 3.120000, "
552 "\"avgPacketLatency\": 100, "
553 "\"avgReceiveThroughput\": 2100, "
554 "\"avgTransmitThroughput\": 500, "
555 "\"flowActivationEpoch\": 1470409421, "
556 "\"flowActivationMicrosec\": 987, "
557 "\"flowDeactivationEpoch\": 1470409431, "
558 "\"flowDeactivationMicrosec\": 11, "
559 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:51 +0000\", "
560 "\"flowStatus\": \"Working\", "
561 "\"maxPacketDelayVariation\": 87, "
562 "\"numActivationFailures\": 3, "
563 "\"numBitErrors\": 17, "
564 "\"numBytesReceived\": 123654, "
565 "\"numBytesTransmitted\": 4561, "
566 "\"numDroppedPackets\": 0, "
567 "\"numL7BytesReceived\": 12, "
568 "\"numL7BytesTransmitted\": 10, "
569 "\"numLostPackets\": 1, "
570 "\"numOutOfOrderPackets\": 3, "
571 "\"numPacketErrors\": 7, "
572 "\"numPacketsReceivedExclRetrans\": 899, "
573 "\"numPacketsReceivedInclRetrans\": 901, "
574 "\"numPacketsTransmittedInclRetrans\": 302, "
575 "\"numRetries\": 6, "
576 "\"numTimeouts\": 2, "
577 "\"numTunneledL7BytesReceived\": 0, "
578 "\"roundTripTime\": 110, "
579 "\"timeToFirstByte\": 225"
581 "\"ipProtocolType\": \"TCP\", "
582 "\"ipVersion\": \"IPv4\", "
583 "\"otherEndpointIpAddress\": \"2.3.4.1\", "
584 "\"otherEndpointPort\": 2341, "
585 "\"reportingEndpointIpAddr\": \"4.2.3.1\", "
586 "\"reportingEndpointPort\": 4321"
589 size_t json_size = 0;
590 char json_body[EVEL_MAX_JSON_BODY];
591 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
592 EVENT_MOBILE_FLOW * mobile_flow = NULL;
594 /***************************************************************************/
596 /***************************************************************************/
597 evel_set_next_event_sequence(1241);
599 metrics = evel_new_mobile_gtp_flow_metrics(12.3,
629 assert(metrics != NULL);
630 mobile_flow = evel_new_mobile_flow("Outbound",
638 assert(mobile_flow != NULL);
640 json_size = evel_json_encode_event(
641 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
642 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
643 assert((json_size == strlen(json_body)) && "Bad size returned");
645 evel_free_event(mobile_flow);
648 void test_encode_mobile_opts()
652 "{\"commonEventHeader\": {"
653 "\"domain\": \"mobileFlow\", "
654 "\"eventId\": \"1242\", "
655 "\"functionalRole\": \"UNIT TEST\", "
656 "\"lastEpochMicrosec\": 1000002, "
657 "\"priority\": \"Normal\", "
658 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
659 "\"sequence\": 1242, "
660 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
661 "\"startEpochMicrosec\": 1000002, "
663 "\"eventType\": \"Mobile flow...\", "
664 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
665 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
667 "\"mobileFlowFields\": {"
668 "\"flowDirection\": \"Inbound\", "
669 "\"gtpPerFlowMetrics\": {"
670 "\"avgBitErrorRate\": 132.000100, "
671 "\"avgPacketDelayVariation\": 31.200000, "
672 "\"avgPacketLatency\": 101, "
673 "\"avgReceiveThroughput\": 2101, "
674 "\"avgTransmitThroughput\": 501, "
675 "\"flowActivationEpoch\": 1470409422, "
676 "\"flowActivationMicrosec\": 988, "
677 "\"flowDeactivationEpoch\": 1470409432, "
678 "\"flowDeactivationMicrosec\": 12, "
679 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
680 "\"flowStatus\": \"Inactive\", "
681 "\"maxPacketDelayVariation\": 88, "
682 "\"numActivationFailures\": 4, "
683 "\"numBitErrors\": 18, "
684 "\"numBytesReceived\": 123655, "
685 "\"numBytesTransmitted\": 4562, "
686 "\"numDroppedPackets\": 1, "
687 "\"numL7BytesReceived\": 13, "
688 "\"numL7BytesTransmitted\": 11, "
689 "\"numLostPackets\": 2, "
690 "\"numOutOfOrderPackets\": 4, "
691 "\"numPacketErrors\": 8, "
692 "\"numPacketsReceivedExclRetrans\": 900, "
693 "\"numPacketsReceivedInclRetrans\": 902, "
694 "\"numPacketsTransmittedInclRetrans\": 303, "
695 "\"numRetries\": 7, "
696 "\"numTimeouts\": 3, "
697 "\"numTunneledL7BytesReceived\": 1, "
698 "\"roundTripTime\": 111, "
699 "\"timeToFirstByte\": 226, "
700 "\"ipTosCountList\": ["
704 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
705 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
706 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
707 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
708 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
709 "\"durConnectionFailedStatus\": 12, "
710 "\"durTunnelFailedStatus\": 13, "
711 "\"flowActivatedBy\": \"Remote\", "
712 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
713 "\"flowDeactivatedBy\": \"Remote\", "
714 "\"gtpConnectionStatus\": \"Connected\", "
715 "\"gtpTunnelStatus\": \"Not tunneling\", "
716 "\"largePacketRtt\": 80, "
717 "\"largePacketThreshold\": 600.000000, "
718 "\"maxReceiveBitRate\": 1357924680, "
719 "\"maxTransmitBitRate\": 235711, "
720 "\"numGtpEchoFailures\": 1, "
721 "\"numGtpTunnelErrors\": 4, "
722 "\"numHttpErrors\": 2"
724 "\"ipProtocolType\": \"UDP\", "
725 "\"ipVersion\": \"IPv6\", "
726 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
727 "\"otherEndpointPort\": 2342, "
728 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
729 "\"reportingEndpointPort\": 4322, "
730 "\"applicationType\": \"Demo application\", "
731 "\"appProtocolType\": \"GSM\", "
732 "\"appProtocolVersion\": \"1\", "
733 "\"cid\": \"65535\", "
734 "\"connectionType\": \"S1-U\", "
735 "\"ecgi\": \"e65535\", "
736 "\"gtpProtocolType\": \"GTP-U\", "
737 "\"gtpVersion\": \"1\", "
738 "\"httpHeader\": \"http://www.something.com\", "
739 "\"imei\": \"209917614823\", "
740 "\"imsi\": \"355251/05/850925/8\", "
744 "\"msisdn\": \"6017123456789\", "
745 "\"otherFunctionalRole\": \"MME\", "
747 "\"radioAccessTechnology\": \"LTE\", "
749 "\"samplingAlgorithm\": 1, "
750 "\"tac\": \"2099\", "
751 "\"tunnelId\": \"Tunnel 1\", "
755 size_t json_size = 0;
756 char json_body[EVEL_MAX_JSON_BODY];
757 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
758 EVENT_MOBILE_FLOW * mobile_flow = NULL;
760 /***************************************************************************/
762 /***************************************************************************/
763 evel_set_next_event_sequence(1242);
765 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
795 assert(metrics != NULL);
797 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
798 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
799 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
800 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
801 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
802 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
803 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
804 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
805 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
806 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
807 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
808 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
809 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
810 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
811 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
812 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
813 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
814 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
815 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
816 evel_mobile_gtp_metrics_qci_cos_count_add(
817 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
818 evel_mobile_gtp_metrics_qci_cos_count_add(
819 metrics, EVEL_QCI_COS_LTE_65, 122);
821 mobile_flow = evel_new_mobile_flow("Inbound",
829 assert(mobile_flow != NULL);
831 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
832 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
833 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
834 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
835 evel_mobile_flow_cid_set(mobile_flow, "65535");
836 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
837 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
838 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
839 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
840 evel_mobile_flow_http_header_set(mobile_flow,
841 "http://www.something.com");
842 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
843 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
844 evel_mobile_flow_lac_set(mobile_flow, "1");
845 evel_mobile_flow_mcc_set(mobile_flow, "410");
846 evel_mobile_flow_mnc_set(mobile_flow, "04");
847 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
848 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
849 evel_mobile_flow_rac_set(mobile_flow, "514");
850 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
851 evel_mobile_flow_sac_set(mobile_flow, "1");
852 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
853 evel_mobile_flow_tac_set(mobile_flow, "2099");
854 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
855 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
857 json_size = evel_json_encode_event(
858 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
859 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
860 assert((json_size == strlen(json_body)) && "Bad size returned");
862 evel_free_event(mobile_flow);
865 void test_encode_report()
869 "{\"commonEventHeader\": {"
870 "\"domain\": \"measurementsForVfReporting\", "
871 "\"eventId\": \"125\", "
872 "\"functionalRole\": \"UNIT TEST\", "
873 "\"lastEpochMicrosec\": 1000002, "
874 "\"priority\": \"Normal\", "
875 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
876 "\"sequence\": 125, "
877 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
878 "\"startEpochMicrosec\": 1000002, "
880 "\"eventType\": \"Perf reporting...\", "
881 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
882 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
884 "\"measurementsForVfReportingFields\": "
885 "{\"measurementInterval\": 1.100000, "
886 "\"featureUsageArray\": ["
887 "{\"featureIdentifier\": \"FeatureA\", "
888 "\"featureUtilization\": 123}, "
889 "{\"featureIdentifier\": \"FeatureB\", "
890 "\"featureUtilization\": 567}], "
891 "\"additionalMeasurements\": ["
892 "{\"name\": \"Group1\", "
893 "\"measurements\": ["
894 "{\"name\": \"Name1\", "
895 "\"value\": \"Value1\"}]}, "
896 "{\"name\": \"Group2\", "
897 "\"measurements\": ["
898 "{\"name\": \"Name1\", "
899 "\"value\": \"Value1\"}, "
900 "{\"name\": \"Name2\", "
901 "\"value\": \"Value2\"}]}], "
902 "\"measurementFieldsVersion\": 1.1}}}";
904 size_t json_size = 0;
905 char json_body[EVEL_MAX_JSON_BODY];
906 EVENT_REPORT * report = NULL;
908 /***************************************************************************/
910 /***************************************************************************/
911 evel_set_next_event_sequence(125);
912 report = evel_new_report(1.1);
913 assert(report != NULL);
914 evel_report_type_set(report, "Perf reporting...");
915 evel_report_feature_use_add(report, "FeatureA", 123);
916 evel_report_feature_use_add(report, "FeatureB", 567);
917 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
918 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
919 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
921 json_size = evel_json_encode_event(
922 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
923 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
924 assert((json_size == strlen(json_body)) && "Bad size returned");
926 evel_free_event(report);
929 void test_encode_service()
931 test_encode_service_subset(SERVICE_NONE);
932 test_encode_service_subset(SERVICE_CODEC);
933 test_encode_service_subset(SERVICE_TRANSCODING);
934 test_encode_service_subset(SERVICE_RTCP);
935 test_encode_service_subset(SERVICE_EOC_VQM);
936 test_encode_service_subset(SERVICE_MARKER);
939 void test_encode_service_subset(const SERVICE_TEST service_test)
941 char * expected_start =
943 "{\"commonEventHeader\": {"
944 "\"domain\": \"serviceEvents\", "
945 "\"eventId\": \"2000\", "
946 "\"functionalRole\": \"UNIT TEST\", "
947 "\"lastEpochMicrosec\": 1000002, "
948 "\"priority\": \"Normal\", "
949 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
950 "\"sequence\": 2000, "
951 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
952 "\"startEpochMicrosec\": 1000002, "
954 "\"eventType\": \"Service Event\", "
955 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
956 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
958 "\"serviceEventsFields\": {"
959 "\"eventInstanceIdentifier\": "
961 "\"vendorId\": \"vendor_x_id\", "
962 "\"eventId\": \"vendor_x_event_id\", "
963 "\"productId\": \"vendor_x_product_id\", "
964 "\"subsystemId\": \"vendor_x_subsystem_id\", "
965 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
967 "\"serviceEventsFieldsVersion\": 1.1, "
968 "\"correlator\": \"vendor_x_correlator\", "
969 "\"additionalFields\": ["
970 "{\"name\": \"Name1\", \"value\": \"Value1\"}, "
971 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
972 "{\"name\": \"Name3\", \"value\": \"Value3\"}, "
973 "{\"name\": \"Name4\", \"value\": \"Value4\"}]";
974 char * expected_codec =
976 "\"codecSelected\": {"
977 "\"codec\": \"PCMA\""
979 char * expected_transcoding =
981 "\"codecSelectedTranscoding\": {"
982 "\"calleeSideCodec\": \"PCMA\", "
983 "\"callerSideCodec\": \"G729A\""
985 char * expected_rtcp =
988 "\"rtcpData\": \"some_rtcp_data\""
990 char * expected_eoc_vqm =
992 "\"endOfCallVqmSummaries\": {"
993 "\"adjacencyName\": \"vendor_x_adjacency\", "
994 "\"endpointDescription\": \"Caller\", "
995 "\"endpointJitter\": 66, "
996 "\"endpointRtpOctetsDiscarded\": 100, "
997 "\"endpointRtpOctetsReceived\": 200, "
998 "\"endpointRtpOctetsSent\": 300, "
999 "\"endpointRtpPacketsDiscarded\": 400, "
1000 "\"endpointRtpPacketsReceived\": 500, "
1001 "\"endpointRtpPacketsSent\": 600, "
1002 "\"localJitter\": 99, "
1003 "\"localRtpOctetsDiscarded\": 150, "
1004 "\"localRtpOctetsReceived\": 250, "
1005 "\"localRtpOctetsSent\": 350, "
1006 "\"localRtpPacketsDiscarded\": 450, "
1007 "\"localRtpPacketsReceived\": 550, "
1008 "\"localRtpPacketsSent\": 650, "
1009 "\"mosCqe\": 12.255000, "
1010 "\"packetsLost\": 157, "
1011 "\"packetLossPercent\": 0.232000, "
1013 "\"roundTripDelay\": 15"
1015 char * expected_marker =
1018 "\"phoneNumber\": \"0888888888\""
1020 char * expected_end =
1023 char * expected_middle = NULL;
1024 switch (service_test)
1027 expected_middle = "";
1030 expected_middle = expected_codec;
1032 case SERVICE_TRANSCODING:
1033 expected_middle = expected_transcoding;
1036 expected_middle = expected_rtcp;
1038 case SERVICE_EOC_VQM:
1039 expected_middle = expected_eoc_vqm;
1041 case SERVICE_MARKER:
1042 expected_middle = expected_marker;
1045 assert(expected_middle != NULL);
1048 char expected[EVEL_MAX_JSON_BODY];
1049 offset = snprintf(expected + offset,
1050 EVEL_MAX_JSON_BODY - offset,
1056 size_t json_size = 0;
1057 char json_body[EVEL_MAX_JSON_BODY];
1058 EVENT_SGNALING * event = NULL;
1059 evel_set_next_event_sequence(2000);
1060 event = evel_new_signaling("vendor_x_id",
1061 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1062 assert(event != NULL);
1063 evel_signaling_type_set(event, "Signaling");
1064 evel_signaling_correlator_set(event, "vendor_x_correlator");
1065 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1066 evel_signaling_vnfname_set(event, "vendor_x_vnf");
1068 switch (service_test)
1073 evel_signaling_addl_info_add(event, "codec", "PCMA");
1075 case SERVICE_TRANSCODING:
1076 evel_signaling_addl_info_add(event, "calleecodec", "PCMA");
1077 evel_signaling_addl_info_add(event, "callercodec", "G729A");
1080 evel_signaling_addl_info_add(event, "rtcpdata", "abcdefgh");
1082 case SERVICE_EOC_VQM:
1083 evel_signaling_addl_info_add(event, "adjacency", "vendor_x");
1084 /*evel_service_adjacency_name_set(event, "vendor_x_adjacency");
1085 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
1086 evel_service_endpoint_jitter_set(event, 66);
1087 evel_service_endpoint_rtp_oct_disc_set(event, 100);
1088 evel_service_endpoint_rtp_oct_recv_set(event, 200);
1089 evel_service_endpoint_rtp_oct_sent_set(event, 300);
1090 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
1091 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
1092 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
1093 evel_service_local_jitter_set(event, 99);
1094 evel_service_local_rtp_oct_disc_set(event, 150);
1095 evel_service_local_rtp_oct_recv_set(event, 250);
1096 evel_service_local_rtp_oct_sent_set(event, 350);
1097 evel_service_local_rtp_pkt_disc_set(event, 450);
1098 evel_service_local_rtp_pkt_recv_set(event, 550);
1099 evel_service_local_rtp_pkt_sent_set(event, 650);
1100 evel_service_mos_cqe_set(event, 12.255);
1101 evel_service_packets_lost_set(event, 157);
1102 evel_service_packet_loss_percent_set(event, 0.232);
1103 evel_service_r_factor_set(event, 11);
1104 evel_service_round_trip_delay_set(event, 15);*/
1106 case SERVICE_MARKER:
1107 evel_signaling_addl_info_add(event, "service_phone", "0888888888");
1111 json_size = evel_json_encode_event(
1112 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1113 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
1114 assert((json_size == strlen(json_body)) && "Bad size returned");
1116 evel_free_event(event);
1119 void test_encode_signaling()
1123 "{\"commonEventHeader\": {"
1124 "\"domain\": \"signaling\", "
1125 "\"eventId\": \"2001\", "
1126 "\"functionalRole\": \"UNIT TEST\", "
1127 "\"lastEpochMicrosec\": 1000002, "
1128 "\"priority\": \"Normal\", "
1129 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1130 "\"sequence\": 2001, "
1131 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1132 "\"startEpochMicrosec\": 1000002, "
1133 "\"version\": 1.2, "
1134 "\"eventType\": \"Signaling\", "
1135 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1136 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1138 "\"signalingFields\": {"
1139 "\"eventInstanceIdentifier\": "
1141 "\"vendorId\": \"vendor_x_id\", "
1142 "\"eventId\": \"vendor_x_event_id\", "
1143 "\"productId\": \"vendor_x_product_id\", "
1144 "\"subsystemId\": \"vendor_x_subsystem_id\", "
1145 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
1147 "\"signalingFieldsVersion\": 1.1, "
1148 "\"correlator\": \"vendor_x_correlator\", "
1149 "\"localIpAddress\": \"1.0.3.1\", "
1150 "\"localPort\": \"1031\", "
1151 "\"remoteIpAddress\": \"5.3.3.0\", "
1152 "\"remotePort\": \"5330\", "
1153 "\"compressedSip\": \"compressed_sip\", "
1154 "\"summarySip\": \"summary_sip\""
1157 size_t json_size = 0;
1158 char json_body[EVEL_MAX_JSON_BODY];
1159 EVENT_SIGNALING * event = NULL;
1160 evel_set_next_event_sequence(2001);
1161 event = evel_new_signaling("vendor_x_id",
1162 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1163 assert(event != NULL);
1164 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1165 evel_signaling_vnfname_set(event, "vendor_x_vnf");
1166 evel_signaling_type_set(event, "Signaling");
1167 evel_signaling_product_id_set(event, "vendor_x_product_id");
1168 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
1169 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
1170 evel_signaling_correlator_set(event, "vendor_x_correlator");
1171 evel_signaling_local_ip_address_set(event, "1.0.3.1");
1172 evel_signaling_local_port_set(event, "1031");
1173 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
1174 evel_signaling_remote_port_set(event, "5330");
1175 evel_signaling_compressed_sip_set(event, "compressed_sip");
1176 evel_signaling_summary_sip_set(event, "summary_sip");
1177 json_size = evel_json_encode_event(
1178 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1179 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
1180 assert((json_size == strlen(json_body)) && "Bad size returned");
1182 evel_free_event(event);
1185 void test_encode_state_change()
1189 "{\"commonEventHeader\": {"
1190 "\"domain\": \"stateChange\", "
1191 "\"eventId\": \"128\", "
1192 "\"functionalRole\": \"UNIT TEST\", "
1193 "\"lastEpochMicrosec\": 1000002, "
1194 "\"priority\": \"Normal\", "
1195 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1196 "\"sequence\": 128, "
1197 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1198 "\"startEpochMicrosec\": 1000002, "
1199 "\"version\": 1.2, "
1200 "\"eventType\": \"SC Type\", "
1201 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1202 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1204 "\"stateChangeFields\": {"
1205 "\"newState\": \"inService\", "
1206 "\"oldState\": \"outOfService\", "
1207 "\"stateInterface\": \"An Interface\", "
1208 "\"additionalFields\": ["
1209 "{\"name\": \"Name1\", "
1210 "\"value\": \"Value1\"}, "
1211 "{\"name\": \"Name2\", "
1212 "\"value\": \"Value2\"}"
1214 "\"stateChangeFieldsVersion\": 1.1"
1217 size_t json_size = 0;
1218 char json_body[EVEL_MAX_JSON_BODY];
1219 EVENT_STATE_CHANGE * state_change = NULL;
1220 evel_set_next_event_sequence(128);
1221 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
1222 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
1224 assert(state_change != NULL);
1225 evel_state_change_type_set(state_change, "SC Type");
1226 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
1227 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
1229 json_size = evel_json_encode_event(
1230 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
1231 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
1232 assert((json_size == strlen(json_body)) && "Bad size returned");
1234 evel_free_event(state_change);
1237 void test_encode_syslog()
1241 "{\"commonEventHeader\": {"
1242 "\"domain\": \"syslog\", "
1243 "\"eventId\": \"126\", "
1244 "\"functionalRole\": \"UNIT TEST\", "
1245 "\"lastEpochMicrosec\": 1000002, "
1246 "\"priority\": \"Normal\", "
1247 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1248 "\"sequence\": 126, "
1249 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1250 "\"startEpochMicrosec\": 1000002, "
1251 "\"version\": 1.2, "
1252 "\"eventType\": \"SL Type\", "
1253 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1254 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1256 "\"syslogFields\": {"
1257 "\"eventSourceType\": \"virtualNetworkFunction\", "
1258 "\"syslogMsg\": \"SL Message\", "
1259 "\"syslogTag\": \"SL Tag\", "
1260 "\"syslogFieldsVersion\": 1.1, "
1261 "\"eventSourceHost\": \"SL Host\", "
1262 "\"syslogFacility\": 6, "
1263 "\"syslogProc\": \"SL Proc\", "
1264 "\"syslogProcId\": 2, "
1265 "\"syslogSData\": \"SL SDATA\", "
1268 size_t json_size = 0;
1269 char json_body[EVEL_MAX_JSON_BODY];
1270 EVENT_SYSLOG * syslog = NULL;
1271 evel_set_next_event_sequence(126);
1272 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
1275 assert(syslog != NULL);
1276 evel_syslog_type_set(syslog, "SL Type");
1277 evel_syslog_event_source_host_set(syslog, "SL Host");
1278 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
1279 evel_syslog_proc_set(syslog, "SL Proc");
1280 evel_syslog_proc_id_set(syslog, 2);
1281 evel_syslog_version_set(syslog, 1);
1282 evel_syslog_s_data_set(syslog, "SL SDATA");
1284 json_size = evel_json_encode_event(
1285 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
1286 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
1287 assert((json_size == strlen(json_body)) && "Bad size returned");
1289 evel_free_event(syslog);
1292 void test_encode_other()
1296 "{\"commonEventHeader\": {"
1297 "\"domain\": \"other\", "
1298 "\"eventId\": \"129\", "
1299 "\"functionalRole\": \"UNIT TEST\", "
1300 "\"lastEpochMicrosec\": 1000002, "
1301 "\"priority\": \"Normal\", "
1302 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1303 "\"sequence\": 129, "
1304 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1305 "\"startEpochMicrosec\": 1000002, "
1306 "\"version\": 1.2, "
1307 "\"eventType\": \"Other Type\", "
1308 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1309 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1311 "\"otherFields\": ["
1312 "{\"name\": \"Other field 1\", "
1313 "\"value\": \"Other value 1\"}, "
1314 "{\"name\": \"Other field 2\", "
1315 "\"value\": \"Other value 2\"}"
1319 size_t json_size = 0;
1320 char json_body[EVEL_MAX_JSON_BODY];
1321 EVENT_OTHER * other = NULL;
1322 evel_set_next_event_sequence(129);
1323 other = evel_new_other();
1324 assert(other != NULL);
1325 evel_other_type_set(other, "Other Type");
1326 evel_other_field_add(other,
1329 evel_other_field_add(other,
1333 json_size = evel_json_encode_event(
1334 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
1335 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
1336 assert((json_size == strlen(json_body)) && "Bad size returned");
1338 evel_free_event(other);
1341 void compare_strings(char * expected,
1346 if (strncmp(expected, actual, max_size) != 0)
1349 while (diff < max_size)
1351 if (expected[diff] != actual[diff])
1358 printf("Comparison Failure at Offset %d\n\n", diff);
1359 printf("Expected:\n%s\n", expected);
1360 printf("Actual:\n%s\n", actual);
1361 printf("Description: %s\n", description);
1366 /**************************************************************************//**
1367 * Copy a json string to a ::MEMORY_CHUNK for testing.
1369 * @param chunk The memory chunk.
1370 * @param string The json string.
1371 *****************************************************************************/
1372 void copy_string_to_chunk(MEMORY_CHUNK * chunk, char * string)
1376 /***************************************************************************/
1377 /* Check preconditions. */
1378 /***************************************************************************/
1379 assert(chunk != NULL);
1380 assert(string != NULL);
1382 mem_size = strlen(string) + 1;
1383 chunk->memory = malloc(mem_size);
1384 memcpy(chunk->memory, string, mem_size);
1385 chunk->size = mem_size;
1388 /**************************************************************************//**
1389 * Copy a json string to a ::MEMORY_CHUNK for testing.
1391 * @param json The JSON string.
1392 * @param post Memory chunk to post a response.
1393 *****************************************************************************/
1394 void handle_json_response(char * json, MEMORY_CHUNK * post)
1397 post->memory = NULL;
1399 copy_string_to_chunk(&chunk, json);
1400 evel_handle_event_response(&chunk, post);
1404 /**************************************************************************//**
1405 * Test that a non-"commandList" JSON buffer leaves the throttle state off.
1406 *****************************************************************************/
1407 void test_json_response_junk()
1414 "\"1\", \"2\", \"3\"], "
1416 "\"1\", \"2\", \"3\"]"
1419 evel_throttle_initialize();
1420 handle_json_response(json_junk, &post);
1422 /***************************************************************************/
1423 /* Check that all domains are not throttled. */
1424 /***************************************************************************/
1425 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1427 assert(evel_get_throttle_spec(domain) == NULL);
1430 /***************************************************************************/
1431 /* Check that we generated no post. */
1432 /***************************************************************************/
1433 assert(post.memory == NULL);
1435 evel_throttle_terminate();
1438 char * json_command_list_provide =
1440 "\"commandList\": ["
1443 "\"commandType\": \"provideThrottlingState\""
1449 char * json_command_list_fault_clear =
1451 "\"commandList\": ["
1454 "\"commandType\": \"throttlingSpecification\", "
1455 "\"eventDomainThrottleSpecification\": {"
1456 "\"eventDomain\": \"fault\""
1463 char * json_command_list_syslog_clear =
1465 "\"commandList\": ["
1468 "\"commandType\": \"throttlingSpecification\", "
1469 "\"eventDomainThrottleSpecification\": {"
1470 "\"eventDomain\": \"syslog\""
1477 char * expected_throttle_state_normal =
1479 "\"eventThrottlingState\": {"
1480 "\"eventThrottlingMode\": \"normal\"}"
1483 /**************************************************************************//**
1484 * Test that we can return the default throttling state.
1485 *****************************************************************************/
1486 void test_json_provide_throttle_state()
1491 char * expected_post = expected_throttle_state_normal;
1493 evel_throttle_initialize();
1494 handle_json_response(json_command_list_provide, &post);
1496 /***************************************************************************/
1497 /* Check that all domains are not throttled. */
1498 /***************************************************************************/
1499 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1501 assert(evel_get_throttle_spec(domain) == NULL);
1504 /***************************************************************************/
1505 /* Check that we generated a throttling specification post. */
1506 /***************************************************************************/
1507 assert(post.memory != NULL);
1508 compare_strings(expected_post, post.memory, strlen(expected_post),
1509 "Throttle State Normal");
1512 evel_throttle_terminate();
1515 /**************************************************************************//**
1516 * Test the measurement interval handling and API.
1517 *****************************************************************************/
1518 void test_json_measurement_interval()
1521 char * json_command_list_interval_only =
1523 "\"commandList\": ["
1526 "\"measurementInterval\": 60"
1532 char * json_command_list_interval_first =
1534 "\"commandList\": ["
1537 "\"measurementInterval\": 30, "
1538 "\"commandType\": \"measurementIntervalChange\""
1544 char * json_command_list_command_first =
1546 "\"commandList\": ["
1549 "\"commandType\": \"measurementIntervalChange\", "
1550 "\"measurementInterval\": 60"
1556 evel_throttle_initialize();
1557 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1559 /***************************************************************************/
1560 /* Check that we're not handling stuff when we shouldn't. */
1561 /***************************************************************************/
1562 handle_json_response(json_command_list_interval_only, &post);
1563 assert(post.memory == NULL);
1564 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1566 /***************************************************************************/
1567 /* Check that we're OK with the interval coming first. */
1568 /***************************************************************************/
1569 handle_json_response(json_command_list_interval_first, &post);
1570 assert(post.memory == NULL);
1571 assert(evel_get_measurement_interval() == 30);
1573 /***************************************************************************/
1574 /* Check that we're OK with the command type coming first. */
1575 /***************************************************************************/
1576 handle_json_response(json_command_list_command_first, &post);
1577 assert(post.memory == NULL);
1578 assert(evel_get_measurement_interval() == 60);
1580 evel_throttle_terminate();
1583 /**************************************************************************//**
1584 * Test a single domain, single field suppression.
1585 *****************************************************************************/
1586 void test_json_throttle_spec_field()
1591 char * json_command_list_fault_single =
1593 "\"commandList\": ["
1596 "\"commandType\": \"throttlingSpecification\", "
1597 "\"eventDomainThrottleSpecification\": {"
1598 "\"eventDomain\": \"fault\", "
1599 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1606 char * json_command_list_fault_double =
1608 "\"commandList\": ["
1611 "\"commandType\": \"throttlingSpecification\", "
1612 "\"eventDomainThrottleSpecification\": {"
1613 "\"eventDomain\": \"fault\", "
1614 "\"suppressedFieldNames\": ["
1615 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1622 char * expected_post_fault_single =
1624 "\"eventThrottlingState\": {"
1625 "\"eventThrottlingMode\": \"throttled\", "
1626 "\"eventDomainThrottleSpecificationList\": ["
1628 "\"eventDomain\": \"fault\", "
1629 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1635 char * expected_post_fault_double =
1637 "\"eventThrottlingState\": {"
1638 "\"eventThrottlingMode\": \"throttled\", "
1639 "\"eventDomainThrottleSpecificationList\": ["
1641 "\"eventDomain\": \"fault\", "
1642 "\"suppressedFieldNames\": ["
1643 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1649 /***************************************************************************/
1650 /* Initialize and provide a specification with a single fault suppressed. */
1651 /***************************************************************************/
1652 evel_throttle_initialize();
1653 handle_json_response(json_command_list_fault_single, &post);
1655 /***************************************************************************/
1656 /* Check that the FAULT domain is throttled. */
1657 /***************************************************************************/
1658 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1659 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1661 if (domain != EVEL_DOMAIN_FAULT)
1663 assert(evel_get_throttle_spec(domain) == NULL);
1666 assert(post.memory == NULL);
1668 /***************************************************************************/
1669 /* Request and verify the throttling state. */
1670 /***************************************************************************/
1671 handle_json_response(json_command_list_provide, &post);
1672 assert(post.memory != NULL);
1673 compare_strings(expected_post_fault_single,
1675 strlen(expected_post_fault_single),
1676 "Fault - Single Field");
1680 /***************************************************************************/
1681 /* Update a specification with two faults suppressed. */
1682 /***************************************************************************/
1683 handle_json_response(json_command_list_fault_double, &post);
1685 /***************************************************************************/
1686 /* Check that the FAULT domain is throttled. */
1687 /***************************************************************************/
1688 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1689 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1691 if (domain != EVEL_DOMAIN_FAULT)
1693 assert(evel_get_throttle_spec(domain) == NULL);
1696 assert(post.memory == NULL);
1698 /***************************************************************************/
1699 /* Request and verify the throttling state. */
1700 /***************************************************************************/
1701 handle_json_response(json_command_list_provide, &post);
1702 assert(post.memory != NULL);
1703 compare_strings(expected_post_fault_double,
1705 strlen(expected_post_fault_double),
1706 "Fault - Double Field");
1710 /***************************************************************************/
1711 /* Now clear the FAULT domain. */
1712 /***************************************************************************/
1713 handle_json_response(json_command_list_fault_clear, &post);
1714 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1716 assert(evel_get_throttle_spec(domain) == NULL);
1719 evel_throttle_terminate();
1722 /**************************************************************************//**
1723 * Test a single domain, nv_pair suppression.
1724 *****************************************************************************/
1725 void test_json_throttle_spec_nv_pair()
1730 char * json_command_list_fault_pair_single =
1732 "\"commandList\": ["
1735 "\"commandType\": \"throttlingSpecification\", "
1736 "\"eventDomainThrottleSpecification\": {"
1737 "\"eventDomain\": \"fault\", "
1738 "\"suppressedNvPairsList\": ["
1740 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1741 "\"suppressedNvPairNames\": [\"name1\"]"
1750 char * json_command_list_fault_pair_double =
1752 "\"commandList\": ["
1755 "\"commandType\": \"throttlingSpecification\", "
1756 "\"eventDomainThrottleSpecification\": {"
1757 "\"eventDomain\": \"fault\", "
1758 "\"suppressedNvPairsList\": ["
1760 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1761 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1770 char * expected_post_fault_pair_single =
1772 "\"eventThrottlingState\": {"
1773 "\"eventThrottlingMode\": \"throttled\", "
1774 "\"eventDomainThrottleSpecificationList\": ["
1776 "\"eventDomain\": \"fault\", "
1777 "\"suppressedNvPairsList\": ["
1779 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1780 "\"suppressedNvPairNames\": [\"name1\"]"
1788 char * expected_post_fault_pair_double =
1790 "\"eventThrottlingState\": {"
1791 "\"eventThrottlingMode\": \"throttled\", "
1792 "\"eventDomainThrottleSpecificationList\": ["
1794 "\"eventDomain\": \"fault\", "
1795 "\"suppressedNvPairsList\": ["
1797 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1798 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1806 /***************************************************************************/
1807 /* Initialize and provide a specification with a single nvpair with a */
1808 /* single sub-field suppressed. */
1809 /***************************************************************************/
1810 evel_throttle_initialize();
1811 handle_json_response(json_command_list_fault_pair_single, &post);
1813 /***************************************************************************/
1814 /* Check that the FAULT domain is throttled. */
1815 /***************************************************************************/
1816 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1817 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1819 if (domain != EVEL_DOMAIN_FAULT)
1821 assert(evel_get_throttle_spec(domain) == NULL);
1824 assert(post.memory == NULL);
1826 /***************************************************************************/
1827 /* Request and verify the throttling state. */
1828 /***************************************************************************/
1829 handle_json_response(json_command_list_provide, &post);
1830 assert(post.memory != NULL);
1831 compare_strings(expected_post_fault_pair_single,
1833 strlen(expected_post_fault_pair_single),
1834 "Fault - Single Pair, Single Field");
1838 /***************************************************************************/
1839 /* Update a specification with a single nvpair with two sub-fields */
1841 /***************************************************************************/
1842 handle_json_response(json_command_list_fault_pair_double, &post);
1844 /***************************************************************************/
1845 /* Check that the FAULT domain is throttled. */
1846 /***************************************************************************/
1847 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1848 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1850 if (domain != EVEL_DOMAIN_FAULT)
1852 assert(evel_get_throttle_spec(domain) == NULL);
1855 assert(post.memory == NULL);
1857 /***************************************************************************/
1858 /* Request and verify the throttling state. */
1859 /***************************************************************************/
1860 handle_json_response(json_command_list_provide, &post);
1861 assert(post.memory != NULL);
1862 compare_strings(expected_post_fault_pair_double,
1864 strlen(expected_post_fault_pair_double),
1865 "Fault - Double Field");
1869 /***************************************************************************/
1870 /* Now clear the FAULT domain. */
1871 /***************************************************************************/
1872 handle_json_response(json_command_list_fault_clear, &post);
1873 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1875 assert(evel_get_throttle_spec(domain) == NULL);
1878 evel_throttle_terminate();
1881 /**************************************************************************//**
1882 * Test two domains, nv_pair suppression.
1883 *****************************************************************************/
1884 void test_json_throttle_spec_two_domains()
1889 char * json_command_list_two_domains =
1891 "\"commandList\": ["
1894 "\"commandType\": \"throttlingSpecification\", "
1895 "\"eventDomainThrottleSpecification\": {"
1896 "\"eventDomain\": \"fault\", "
1897 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1898 "\"suppressedNvPairsList\": ["
1900 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1901 "\"suppressedNvPairNames\": [\"name1\"]"
1905 "\"commandType\": \"throttlingSpecification\", "
1906 "\"eventDomainThrottleSpecification\": {"
1907 "\"eventDomain\": \"syslog\", "
1908 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1909 "\"suppressedNvPairsList\": ["
1911 "\"nvPairFieldName\": \"additionalFields\", "
1912 "\"suppressedNvPairNames\": [\"name1\"]"
1917 char * expected_post_two_domains =
1919 "\"eventThrottlingState\": {"
1920 "\"eventThrottlingMode\": \"throttled\", "
1921 "\"eventDomainThrottleSpecificationList\": ["
1923 "\"eventDomain\": \"fault\", "
1924 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1925 "\"suppressedNvPairsList\": ["
1927 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1928 "\"suppressedNvPairNames\": [\"name1\"]"
1931 "\"eventDomain\": \"syslog\", "
1932 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1933 "\"suppressedNvPairsList\": ["
1935 "\"nvPairFieldName\": \"additionalFields\", "
1936 "\"suppressedNvPairNames\": [\"name1\"]"
1942 /***************************************************************************/
1943 /* Initialize and provide a specification with a single nvpair with a */
1944 /* single sub-field suppressed. */
1945 /***************************************************************************/
1946 evel_throttle_initialize();
1947 handle_json_response(json_command_list_two_domains, &post);
1949 /***************************************************************************/
1950 /* Check that the FAULT and SYSLOG domains are throttled. */
1951 /***************************************************************************/
1952 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1953 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1954 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1956 if ((domain != EVEL_DOMAIN_FAULT) && (domain != EVEL_DOMAIN_SYSLOG))
1958 assert(evel_get_throttle_spec(domain) == NULL);
1961 assert(post.memory == NULL);
1963 /***************************************************************************/
1964 /* Request and verify the throttling state. */
1965 /***************************************************************************/
1966 handle_json_response(json_command_list_provide, &post);
1967 assert(post.memory != NULL);
1968 compare_strings(expected_post_two_domains,
1970 strlen(expected_post_two_domains),
1971 "Fault - Two Domains");
1975 /***************************************************************************/
1976 /* Now clear the FAULT and SYSLOG domains. */
1977 /***************************************************************************/
1978 handle_json_response(json_command_list_fault_clear, &post);
1979 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
1980 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1981 handle_json_response(json_command_list_syslog_clear, &post);
1982 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1984 assert(evel_get_throttle_spec(domain) == NULL);
1987 evel_throttle_terminate();
1990 /**************************************************************************//**
1991 * Test bad command type.
1992 *****************************************************************************/
1993 void test_json_throttle_spec_bad_command_type()
1998 /***************************************************************************/
1999 /* Search for "dodgy" in the JSON, and you will see the dodgy bits we're */
2000 /* handling in these tests. */
2001 /***************************************************************************/
2002 #define NUM_BAD_COMMANDS 8
2003 char * json_command_list_dodgy_command =
2005 "\"commandList\": ["
2008 "\"commandType\": \"dodgyCommand\", "
2009 "\"eventDomainThrottleSpecification\": {"
2010 "\"eventDomain\": \"fault\", "
2011 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2012 "\"suppressedNvPairsList\": ["
2014 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2015 "\"suppressedNvPairNames\": [\"name1\"]"
2020 char * json_command_list_dodgy_spec =
2022 "\"commandList\": ["
2025 "\"commandType\": \"throttlingSpecification\", "
2026 "\"dodgyEventDomainThrottleSpecification\": {"
2027 "\"eventDomain\": \"fault\", "
2028 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2029 "\"suppressedNvPairsList\": ["
2031 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2032 "\"suppressedNvPairNames\": [\"name1\"]"
2037 char * json_command_list_dodgy_event_domain_key =
2039 "\"commandList\": ["
2042 "\"commandType\": \"throttlingSpecification\", "
2043 "\"eventDomainThrottleSpecification\": {"
2044 "\"dodgyEventDomainKey\": \"fault\", "
2045 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2046 "\"suppressedNvPairsList\": ["
2048 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2049 "\"suppressedNvPairNames\": [\"name1\"]"
2054 char * json_command_list_dodgy_event_domain =
2056 "\"commandList\": ["
2059 "\"commandType\": \"throttlingSpecification\", "
2060 "\"eventDomainThrottleSpecification\": {"
2061 "\"eventDomain\": \"dodgyEventDomain\", "
2062 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2063 "\"suppressedNvPairsList\": ["
2065 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2066 "\"suppressedNvPairNames\": [\"name1\"]"
2071 char * json_command_list_dodgy_field_names_key =
2073 "\"commandList\": ["
2076 "\"commandType\": \"throttlingSpecification\", "
2077 "\"eventDomainThrottleSpecification\": {"
2078 "\"eventDomain\": \"fault\", "
2079 "\"suppressedNvPairsList\": ["
2081 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2082 "\"suppressedNvPairNames\": [\"name1\"]"
2087 char * json_command_list_dodgy_pair_names_list_key =
2089 "\"commandList\": ["
2092 "\"commandType\": \"throttlingSpecification\", "
2093 "\"eventDomainThrottleSpecification\": {"
2094 "\"eventDomain\": \"fault\", "
2095 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2096 "\"dodgySuppressedNvPairsListKey\": ["
2098 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2099 "\"suppressedNvPairNames\": [\"name1\"]"
2104 char * json_command_list_dodgy_pair_field_name_key =
2106 "\"commandList\": ["
2109 "\"commandType\": \"throttlingSpecification\", "
2110 "\"eventDomainThrottleSpecification\": {"
2111 "\"eventDomain\": \"fault\", "
2112 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2113 "\"suppressedNvPairsList\": ["
2115 "\"dodgyNvPairFieldNameKey\": \"alarmAdditionalInformation\", "
2116 "\"suppressedNvPairNames\": [\"name1\"]"
2121 char * json_command_list_dodgy_pair_names_key =
2123 "\"commandList\": ["
2126 "\"commandType\": \"throttlingSpecification\", "
2127 "\"eventDomainThrottleSpecification\": {"
2128 "\"eventDomain\": \"fault\", "
2129 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2130 "\"suppressedNvPairsList\": ["
2132 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2133 "\"dodgySuppressedNvPairNamesKey\": [\"name1\"]"
2138 char * json_command_list_dodgy_depth =
2140 "\"commandList\": ["
2143 "\"commandType\": \"throttlingSpecification\", "
2144 "\"eventDomainThrottleSpecification\": {"
2145 "\"eventDomain\": \"fault\", "
2146 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2147 "\"suppressedNvPairsList\": ["
2149 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2150 "\"dodgySuppressedNvPairNamesKey\": "
2151 "[\"name1\", [[[[[[[[]]]]]]]]]"
2156 char * expected_throttle_state_dodgy_field_names_key =
2158 "\"eventThrottlingState\": {"
2159 "\"eventThrottlingMode\": \"throttled\", "
2160 "\"eventDomainThrottleSpecificationList\": ["
2162 "\"eventDomain\": \"fault\", "
2163 "\"suppressedNvPairsList\": ["
2165 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2166 "\"suppressedNvPairNames\": [\"name1\"]"
2172 char * expected_throttle_state_dodgy_pair_names_list_key =
2174 "\"eventThrottlingState\": {"
2175 "\"eventThrottlingMode\": \"throttled\", "
2176 "\"eventDomainThrottleSpecificationList\": ["
2178 "\"eventDomain\": \"fault\", "
2179 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2185 char * expected_throttle_state_dodgy_pair_field_name_key =
2187 "\"eventThrottlingState\": {"
2188 "\"eventThrottlingMode\": \"throttled\", "
2189 "\"eventDomainThrottleSpecificationList\": ["
2191 "\"eventDomain\": \"fault\", "
2192 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2198 char * expected_throttle_state_dodgy_pair_names_key =
2200 "\"eventThrottlingState\": {"
2201 "\"eventThrottlingMode\": \"throttled\", "
2202 "\"eventDomainThrottleSpecificationList\": ["
2204 "\"eventDomain\": \"fault\", "
2205 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2211 char * json_command_lists[] = {
2212 json_command_list_dodgy_command,
2213 json_command_list_dodgy_spec,
2214 json_command_list_dodgy_event_domain_key,
2215 json_command_list_dodgy_event_domain,
2216 json_command_list_dodgy_depth,
2217 json_command_list_dodgy_field_names_key,
2218 json_command_list_dodgy_pair_names_list_key,
2219 json_command_list_dodgy_pair_field_name_key,
2220 json_command_list_dodgy_pair_names_key
2223 char * expected_posts[] = {
2224 expected_throttle_state_normal,
2225 expected_throttle_state_normal,
2226 expected_throttle_state_normal,
2227 expected_throttle_state_normal,
2228 expected_throttle_state_normal,
2229 expected_throttle_state_dodgy_field_names_key,
2230 expected_throttle_state_dodgy_pair_names_list_key,
2231 expected_throttle_state_dodgy_pair_field_name_key,
2232 expected_throttle_state_dodgy_pair_names_key
2235 const int num_commands =
2236 sizeof(json_command_lists) / sizeof(json_command_lists[0]);
2237 const int num_posts =
2238 sizeof(expected_posts) / sizeof(expected_posts[0]);
2239 assert(num_commands == num_posts);
2241 /***************************************************************************/
2242 /* Initialize and provide a specification with a single nvpair with a */
2243 /* single sub-field suppressed. */
2244 /***************************************************************************/
2245 evel_throttle_initialize();
2248 for (ii = 0; ii < num_commands; ii++)
2250 EVEL_DEBUG("Testing commandList[%d] = %s\n", ii, json_command_lists[ii]);
2251 handle_json_response(json_command_lists[ii], &post);
2253 /*************************************************************************/
2254 /* Check that throttling is in a normal state - because we ignored the */
2255 /* command / ..... */
2256 /*************************************************************************/
2257 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
2259 assert(evel_get_throttle_spec(domain) == NULL);
2261 if (expected_posts[ii] == expected_throttle_state_normal)
2263 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
2267 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2269 assert(post.memory == NULL);
2271 /*************************************************************************/
2272 /* Request and verify the throttling state. */
2273 /*************************************************************************/
2274 handle_json_response(json_command_list_provide, &post);
2275 assert(post.memory != NULL);
2276 compare_strings(expected_posts[ii],
2278 strlen(expected_posts[ii]),
2279 "Throttle State Normal");
2284 evel_throttle_terminate();
2287 void test_encode_fault_throttled()
2291 /***************************************************************************/
2292 /* We also test suppression of the event header parameters here. */
2293 /***************************************************************************/
2294 char * json_command_list =
2296 "\"commandList\": ["
2299 "\"commandType\": \"throttlingSpecification\", "
2300 "\"eventDomainThrottleSpecification\": {"
2301 "\"eventDomain\": \"fault\", "
2302 "\"suppressedFieldNames\": ["
2303 "\"alarmInterfaceA\", "
2305 "\"reportingEntityId\", "
2307 "\"suppressedNvPairsList\": ["
2309 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2310 "\"suppressedNvPairNames\": [\"name3\", \"name4\"]"
2317 "\"commonEventHeader\": {"
2318 "\"domain\": \"fault\", "
2319 "\"eventId\": \"122\", "
2320 "\"functionalRole\": \"UNIT TEST\", "
2321 "\"lastEpochMicrosec\": 1000002, "
2322 "\"priority\": \"Normal\", "
2323 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2324 "\"sequence\": 122, "
2325 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2326 "\"startEpochMicrosec\": 1000002, "
2329 "\"faultFields\": {"
2330 "\"alarmCondition\": \"My alarm condition\", "
2331 "\"eventSeverity\": \"MAJOR\", "
2332 "\"eventSourceType\": \"other\", "
2333 "\"specificProblem\": \"It broke very badly\", "
2334 "\"vfStatus\": \"Active\", "
2335 "\"faultFieldsVersion\": 1.1, "
2336 "\"alarmAdditionalInformation\": ["
2337 "{\"name\": \"name1\", "
2338 "\"value\": \"value1\"}, "
2339 "{\"name\": \"name2\", "
2340 "\"value\": \"value2\"}]"
2343 /***************************************************************************/
2344 /* Initialize and provide a specification with a single fault suppressed. */
2345 /***************************************************************************/
2346 evel_throttle_initialize();
2347 handle_json_response(json_command_list, &post);
2349 /***************************************************************************/
2350 /* Check that the domain is throttled. */
2351 /***************************************************************************/
2352 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2353 assert(post.memory == NULL);
2355 size_t json_size = 0;
2356 char json_body[EVEL_MAX_JSON_BODY];
2357 evel_set_next_event_sequence(122);
2358 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
2359 "It broke very badly",
2360 EVEL_PRIORITY_NORMAL,
2361 EVEL_SEVERITY_MAJOR,
2363 EVEL_VF_STATUS_PREP_TERMINATE);
2364 assert(fault != NULL);
2365 evel_fault_type_set(fault, "Bad things happen...");
2366 evel_fault_addl_info_add(fault, "name1", "value1");
2367 evel_fault_addl_info_add(fault, "name2", "value2");
2369 /***************************************************************************/
2370 /* Suppressed fields. */
2371 /***************************************************************************/
2372 evel_fault_interface_set(fault, "My Interface Card");
2373 evel_fault_addl_info_add(fault, "name3", "value3");
2374 evel_fault_addl_info_add(fault, "name4", "value4");
2376 json_size = evel_json_encode_event(
2377 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
2378 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
2379 assert((json_size == strlen(json_body)) && "Bad size returned");
2381 evel_free_event(fault);
2382 evel_throttle_terminate();
2385 void test_encode_measurement_throttled()
2389 /***************************************************************************/
2390 /* We also test suppression of the event header parameters here. */
2391 /***************************************************************************/
2392 char * json_command_list =
2394 "\"commandList\": ["
2397 "\"commandType\": \"throttlingSpecification\", "
2398 "\"eventDomainThrottleSpecification\": {"
2399 "\"eventDomain\": \"measurementsForVfScaling\", "
2400 "\"suppressedFieldNames\": ["
2402 "\"vnfcScalingMetric\", "
2403 "\"numberOfMediaPortsInUse\", "
2404 "\"aggregateCpuUsage\", "
2407 "\"memoryConfigured\", "
2408 "\"meanRequestLatency\", "
2409 "\"latencyDistribution\", "
2410 "\"concurrentSessions\", "
2411 "\"configuredEntities\", "
2413 "\"reportingEntityId\", "
2415 "\"suppressedNvPairsList\": ["
2417 "\"nvPairFieldName\": \"cpuUsageArray\", "
2418 "\"suppressedNvPairNames\": [\"cpu3\", \"cpu4\"]"
2421 "\"nvPairFieldName\": \"filesystemUsageArray\", "
2422 "\"suppressedNvPairNames\": [\"00-11-22\", \"33-44-55\"]"
2425 "\"nvPairFieldName\": \"vNicUsageArray\", "
2426 "\"suppressedNvPairNames\": [\"eth1\", \"eth0\"]"
2429 "\"nvPairFieldName\": \"featureUsageArray\", "
2430 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2433 "\"nvPairFieldName\": \"codecUsageArray\", "
2434 "\"suppressedNvPairNames\": [\"G729ab\"]"
2437 "\"nvPairFieldName\": \"additionalMeasurements\", "
2438 "\"suppressedNvPairNames\": [\"Group2\"]"
2446 "{\"commonEventHeader\": {"
2447 "\"domain\": \"measurementsForVfScaling\", "
2448 "\"eventId\": \"123\", "
2449 "\"functionalRole\": \"UNIT TEST\", "
2450 "\"lastEpochMicrosec\": 1000002, "
2451 "\"priority\": \"Normal\", "
2452 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2453 "\"sequence\": 123, "
2454 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2455 "\"startEpochMicrosec\": 1000002, "
2458 "\"measurementsForVfScalingFields\": "
2460 "\"measurementInterval\": 5.500000, "
2461 "\"cpuUsageArray\": ["
2462 "{\"cpuIdentifier\": \"cpu1\", "
2463 "\"percentUsage\": 11.110000}, "
2464 "{\"cpuIdentifier\": \"cpu2\", "
2465 "\"percentUsage\": 22.220000}], "
2466 "\"filesystemUsageArray\": ["
2467 "{\"blockConfigured\": 500.110000, "
2468 "\"blockIops\": 77, "
2469 "\"blockUsed\": 500.220000, "
2470 "\"ephemeralConfigured\": 500.110000, "
2471 "\"ephemeralIops\": 88, "
2472 "\"ephemeralUsed\": 600.220000, "
2473 "\"filesystemName\": \"66-77-88\"}], "
2474 "\"featureUsageArray\": ["
2475 "{\"featureIdentifier\": \"FeatureA\", "
2476 "\"featureUtilization\": 123}], "
2477 "\"codecUsageArray\": ["
2478 "{\"codecIdentifier\": \"G711a\", "
2479 "\"numberInUse\": 91}], "
2480 "\"additionalMeasurements\": ["
2481 "{\"name\": \"Group1\", "
2482 "\"measurements\": ["
2483 "{\"name\": \"Name1\", "
2484 "\"value\": \"Value1\"}]}], "
2485 "\"measurementsForVfScalingVersion\": 1.1}}}";
2486 MEASUREMENT_CPU_USE *cpu_use;
2488 /***************************************************************************/
2489 /* Initialize and provide a specification with a single fault suppressed. */
2490 /***************************************************************************/
2491 evel_throttle_initialize();
2492 handle_json_response(json_command_list, &post);
2494 /***************************************************************************/
2495 /* Check that the domain is throttled. */
2496 /***************************************************************************/
2497 assert(evel_get_throttle_spec(EVEL_DOMAIN_MEASUREMENT) != NULL);
2498 assert(post.memory == NULL);
2500 size_t json_size = 0;
2501 char json_body[EVEL_MAX_JSON_BODY];
2502 evel_set_next_event_sequence(123);
2503 EVENT_MEASUREMENT * measurement = evel_new_measurement(5.5);
2504 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
2505 MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
2506 assert(measurement != NULL);
2508 evel_measurement_type_set(measurement, "Perf management...");
2509 evel_measurement_conc_sess_set(measurement, 1);
2510 evel_measurement_cfg_ents_set(measurement, 2);
2511 evel_measurement_mean_req_lat_set(measurement, 4.4);
2512 evel_measurement_mem_cfg_set(measurement, 6.6);
2513 evel_measurement_mem_used_set(measurement, 3.3);
2514 evel_measurement_request_rate_set(measurement, 7);
2516 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
2517 evel_measurement_cpu_use_idle_set(cpu_use,22.22);
2518 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2519 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2520 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2521 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2522 evel_measurement_cpu_use_system_set(cpu_use,77.77);
2523 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2524 evel_measurement_cpu_use_wait_set(cpu_use,99.99);
2526 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
2527 evel_measurement_cpu_use_idle_set(cpu_use,12.22);
2528 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2529 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2530 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2531 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2532 evel_measurement_cpu_use_system_set(cpu_use,77.77);
2533 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2534 evel_measurement_cpu_use_wait_set(cpu_use,19.99);
2536 evel_measurement_fsys_use_add(measurement, "00-11-22",
2538 200.11, 200.22, 44);
2539 evel_measurement_fsys_use_add(measurement, "33-44-55",
2541 400.11, 400.22, 66);
2542 evel_measurement_fsys_use_add(measurement, "66-77-88",
2544 600.11, 600.22, 88);
2546 bucket = evel_new_meas_latency_bucket(20);
2547 evel_meas_latency_bucket_add(measurement, bucket);
2549 bucket = evel_new_meas_latency_bucket(30);
2550 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
2551 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
2552 evel_meas_latency_bucket_add(measurement, bucket);
2554 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
2555 evel_vnic_use_bcast_pkt_in_set(vnic_use, 1);
2556 evel_vnic_use_bcast_pkt_out_set(vnic_use, 2);
2557 evel_vnic_use_mcast_pkt_in_set(vnic_use, 5);
2558 evel_vnic_use_mcast_pkt_out_set(vnic_use, 6);
2559 evel_vnic_use_ucast_pkt_in_set(vnic_use, 7);
2560 evel_vnic_use_ucast_pkt_out_set(vnic_use, 8);
2561 evel_meas_vnic_use_add(measurement, vnic_use);
2563 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
2564 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
2565 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
2566 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
2567 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
2568 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
2569 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
2570 evel_meas_vnic_use_add(measurement, vnic_use);
2572 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
2573 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
2574 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
2575 evel_measurement_codec_use_add(measurement, "G711a", 91);
2576 evel_measurement_codec_use_add(measurement, "G729ab", 92);
2577 evel_measurement_media_port_use_set(measurement, 1234);
2578 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
2579 evel_measurement_custom_measurement_add(measurement,
2580 "Group1", "Name1", "Value1");
2581 evel_measurement_custom_measurement_add(measurement,
2582 "Group2", "Name1", "Value1");
2583 evel_measurement_custom_measurement_add(measurement,
2584 "Group2", "Name2", "Value2");
2586 json_size = evel_json_encode_event(
2587 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
2588 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
2589 assert((json_size == strlen(json_body)) && "Bad size returned");
2591 evel_free_event(measurement);
2592 evel_throttle_terminate();
2595 void test_encode_mobile_throttled()
2599 /***************************************************************************/
2600 /* We also test suppression of the event header parameters here. */
2601 /***************************************************************************/
2602 char * json_command_list =
2604 "\"commandList\": ["
2607 "\"commandType\": \"throttlingSpecification\", "
2608 "\"eventDomainThrottleSpecification\": {"
2609 "\"eventDomain\": \"mobileFlow\", "
2610 "\"suppressedFieldNames\": ["
2611 "\"applicationType\", "
2612 "\"appProtocolType\", "
2613 "\"appProtocolVersion\", "
2615 "\"connectionType\", "
2617 "\"gtpProtocolType\", "
2626 "\"otherFunctionalRole\", "
2628 "\"radioAccessTechnology\", "
2630 "\"samplingAlgorithm\", "
2635 "\"reportingEntityId\", "
2637 "\"suppressedNvPairsList\": ["
2644 "{\"commonEventHeader\": {"
2645 "\"domain\": \"mobileFlow\", "
2646 "\"eventId\": \"1242\", "
2647 "\"functionalRole\": \"UNIT TEST\", "
2648 "\"lastEpochMicrosec\": 1000002, "
2649 "\"priority\": \"Normal\", "
2650 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2651 "\"sequence\": 1242, "
2652 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2653 "\"startEpochMicrosec\": 1000002, "
2656 "\"mobileFlowFields\": {"
2657 "\"flowDirection\": \"Inbound\", "
2658 "\"gtpPerFlowMetrics\": {"
2659 "\"avgBitErrorRate\": 132.000100, "
2660 "\"avgPacketDelayVariation\": 31.200000, "
2661 "\"avgPacketLatency\": 101, "
2662 "\"avgReceiveThroughput\": 2101, "
2663 "\"avgTransmitThroughput\": 501, "
2664 "\"flowActivationEpoch\": 1470409422, "
2665 "\"flowActivationMicrosec\": 988, "
2666 "\"flowDeactivationEpoch\": 1470409432, "
2667 "\"flowDeactivationMicrosec\": 12, "
2668 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
2669 "\"flowStatus\": \"Inactive\", "
2670 "\"maxPacketDelayVariation\": 88, "
2671 "\"numActivationFailures\": 4, "
2672 "\"numBitErrors\": 18, "
2673 "\"numBytesReceived\": 123655, "
2674 "\"numBytesTransmitted\": 4562, "
2675 "\"numDroppedPackets\": 1, "
2676 "\"numL7BytesReceived\": 13, "
2677 "\"numL7BytesTransmitted\": 11, "
2678 "\"numLostPackets\": 2, "
2679 "\"numOutOfOrderPackets\": 4, "
2680 "\"numPacketErrors\": 8, "
2681 "\"numPacketsReceivedExclRetrans\": 900, "
2682 "\"numPacketsReceivedInclRetrans\": 902, "
2683 "\"numPacketsTransmittedInclRetrans\": 303, "
2684 "\"numRetries\": 7, "
2685 "\"numTimeouts\": 3, "
2686 "\"numTunneledL7BytesReceived\": 1, "
2687 "\"roundTripTime\": 111, "
2688 "\"timeToFirstByte\": 226, "
2689 "\"ipTosCountList\": ["
2693 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
2694 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
2695 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
2696 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
2697 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
2698 "\"durConnectionFailedStatus\": 12, "
2699 "\"durTunnelFailedStatus\": 13, "
2700 "\"flowActivatedBy\": \"Remote\", "
2701 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
2702 "\"flowDeactivatedBy\": \"Remote\", "
2703 "\"gtpConnectionStatus\": \"Connected\", "
2704 "\"gtpTunnelStatus\": \"Not tunneling\", "
2705 "\"largePacketRtt\": 80, "
2706 "\"largePacketThreshold\": 600.000000, "
2707 "\"maxReceiveBitRate\": 1357924680, "
2708 "\"maxTransmitBitRate\": 235711, "
2709 "\"numGtpEchoFailures\": 1, "
2710 "\"numGtpTunnelErrors\": 4, "
2711 "\"numHttpErrors\": 2"
2713 "\"ipProtocolType\": \"UDP\", "
2714 "\"ipVersion\": \"IPv6\", "
2715 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
2716 "\"otherEndpointPort\": 2342, "
2717 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
2718 "\"reportingEndpointPort\": 4322"
2721 /***************************************************************************/
2722 /* Initialize and provide a specification with a single fault suppressed. */
2723 /***************************************************************************/
2724 evel_throttle_initialize();
2725 handle_json_response(json_command_list, &post);
2727 /***************************************************************************/
2728 /* Check that the domain is throttled. */
2729 /***************************************************************************/
2730 assert(evel_get_throttle_spec(EVEL_DOMAIN_MOBILE_FLOW) != NULL);
2731 assert(post.memory == NULL);
2733 size_t json_size = 0;
2734 char json_body[EVEL_MAX_JSON_BODY];
2735 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
2736 EVENT_MOBILE_FLOW * mobile_flow = NULL;
2738 /***************************************************************************/
2740 /***************************************************************************/
2741 evel_set_next_event_sequence(1242);
2743 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
2773 assert(metrics != NULL);
2775 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
2776 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
2777 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
2778 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
2779 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
2780 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
2781 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
2782 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
2783 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
2784 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
2785 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
2786 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
2787 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
2788 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
2789 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
2790 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
2791 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
2792 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
2793 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
2794 evel_mobile_gtp_metrics_qci_cos_count_add(
2795 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
2796 evel_mobile_gtp_metrics_qci_cos_count_add(
2797 metrics, EVEL_QCI_COS_LTE_65, 122);
2799 mobile_flow = evel_new_mobile_flow("Inbound",
2807 assert(mobile_flow != NULL);
2809 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
2810 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
2811 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
2812 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
2813 evel_mobile_flow_cid_set(mobile_flow, "65535");
2814 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
2815 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
2816 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
2817 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
2818 evel_mobile_flow_http_header_set(mobile_flow,
2819 "http://www.something.com");
2820 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
2821 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
2822 evel_mobile_flow_lac_set(mobile_flow, "1");
2823 evel_mobile_flow_mcc_set(mobile_flow, "410");
2824 evel_mobile_flow_mnc_set(mobile_flow, "04");
2825 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
2826 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
2827 evel_mobile_flow_rac_set(mobile_flow, "514");
2828 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
2829 evel_mobile_flow_sac_set(mobile_flow, "1");
2830 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
2831 evel_mobile_flow_tac_set(mobile_flow, "2099");
2832 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
2833 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
2835 json_size = evel_json_encode_event(
2836 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
2837 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
2838 assert((json_size == strlen(json_body)) && "Bad size returned");
2840 evel_free_event(mobile_flow);
2841 evel_throttle_terminate();
2844 void test_encode_other_throttled()
2848 /***************************************************************************/
2849 /* We also test suppression of the event header parameters here. */
2850 /***************************************************************************/
2851 char * json_command_list =
2853 "\"commandList\": ["
2856 "\"commandType\": \"throttlingSpecification\", "
2857 "\"eventDomainThrottleSpecification\": {"
2858 "\"eventDomain\": \"other\", "
2859 "\"suppressedFieldNames\": ["
2861 "\"reportingEntityId\", "
2863 "\"suppressedNvPairsList\": ["
2870 "{\"commonEventHeader\": {"
2871 "\"domain\": \"other\", "
2872 "\"eventId\": \"129\", "
2873 "\"functionalRole\": \"UNIT TEST\", "
2874 "\"lastEpochMicrosec\": 1000002, "
2875 "\"priority\": \"Normal\", "
2876 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2877 "\"sequence\": 129, "
2878 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2879 "\"startEpochMicrosec\": 1000002, "
2882 "\"otherFields\": ["
2883 "{\"name\": \"Other field 1\", "
2884 "\"value\": \"Other value 1\"}, "
2885 "{\"name\": \"Other field 2\", "
2886 "\"value\": \"Other value 2\"}"
2890 /***************************************************************************/
2891 /* Initialize and provide a specification with a single fault suppressed. */
2892 /***************************************************************************/
2893 evel_throttle_initialize();
2894 handle_json_response(json_command_list, &post);
2896 /***************************************************************************/
2897 /* Check that the domain is throttled. */
2898 /***************************************************************************/
2899 assert(evel_get_throttle_spec(EVEL_DOMAIN_OTHER) != NULL);
2900 assert(post.memory == NULL);
2902 size_t json_size = 0;
2903 char json_body[EVEL_MAX_JSON_BODY];
2904 EVENT_OTHER * other = NULL;
2905 evel_set_next_event_sequence(129);
2906 other = evel_new_other();
2907 assert(other != NULL);
2908 evel_other_type_set(other, "Other Type");
2909 evel_other_field_add(other,
2912 evel_other_field_add(other,
2916 json_size = evel_json_encode_event(
2917 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
2918 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
2919 assert((json_size == strlen(json_body)) && "Bad size returned");
2921 evel_free_event(other);
2922 evel_throttle_terminate();
2925 void test_encode_report_throttled()
2929 /***************************************************************************/
2930 /* We also test suppression of the event header parameters here. */
2931 /***************************************************************************/
2932 char * json_command_list =
2934 "\"commandList\": ["
2937 "\"commandType\": \"throttlingSpecification\", "
2938 "\"eventDomainThrottleSpecification\": {"
2939 "\"eventDomain\": \"report\", "
2940 "\"suppressedFieldNames\": ["
2942 "\"reportingEntityId\", "
2944 "\"suppressedNvPairsList\": ["
2946 "\"nvPairFieldName\": \"featureUsageArray\", "
2947 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2950 "\"nvPairFieldName\": \"additionalMeasurements\", "
2951 "\"suppressedNvPairNames\": [\"Group2\"]"
2959 "{\"commonEventHeader\": {"
2960 "\"domain\": \"measurementsForVfReporting\", "
2961 "\"eventId\": \"125\", "
2962 "\"functionalRole\": \"UNIT TEST\", "
2963 "\"lastEpochMicrosec\": 1000002, "
2964 "\"priority\": \"Normal\", "
2965 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2966 "\"sequence\": 125, "
2967 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2968 "\"startEpochMicrosec\": 1000002, "
2971 "\"measurementsForVfReportingFields\": "
2972 "{\"measurementInterval\": 1.100000, "
2973 "\"featureUsageArray\": ["
2974 "{\"featureIdentifier\": \"FeatureA\", "
2975 "\"featureUtilization\": 123}], "
2976 "\"additionalMeasurements\": ["
2977 "{\"name\": \"Group1\", "
2978 "\"measurements\": ["
2979 "{\"name\": \"Name1\", "
2980 "\"value\": \"Value1\"}]}], "
2981 "\"measurementFieldsVersion\": 1.1}}}";
2983 /***************************************************************************/
2984 /* Initialize and provide a specification with a single fault suppressed. */
2985 /***************************************************************************/
2986 evel_throttle_initialize();
2987 handle_json_response(json_command_list, &post);
2989 /***************************************************************************/
2990 /* Check that the domain is throttled. */
2991 /***************************************************************************/
2992 assert(evel_get_throttle_spec(EVEL_DOMAIN_REPORT) != NULL);
2993 assert(post.memory == NULL);
2995 size_t json_size = 0;
2996 char json_body[EVEL_MAX_JSON_BODY];
2997 EVENT_REPORT * report = NULL;
2999 /***************************************************************************/
3001 /***************************************************************************/
3002 evel_set_next_event_sequence(125);
3003 report = evel_new_report(1.1);
3004 assert(report != NULL);
3005 evel_report_type_set(report, "Perf reporting...");
3006 evel_report_feature_use_add(report, "FeatureA", 123);
3007 evel_report_feature_use_add(report, "FeatureB", 567);
3008 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
3009 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
3010 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
3012 json_size = evel_json_encode_event(
3013 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
3014 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
3015 assert((json_size == strlen(json_body)) && "Bad size returned");
3017 evel_free_event(report);
3018 evel_throttle_terminate();
3021 void test_encode_service_throttled()
3025 /***************************************************************************/
3026 /* We also test suppression of the event header parameters here. */
3027 /***************************************************************************/
3028 char * json_command_list =
3030 "\"commandList\": ["
3033 "\"commandType\": \"throttlingSpecification\", "
3034 "\"eventDomainThrottleSpecification\": {"
3035 "\"eventDomain\": \"serviceEvents\", "
3036 "\"suppressedFieldNames\": ["
3039 "\"codecSelected\", "
3040 "\"codecSelectedTranscoding\", "
3041 "\"endOfCallVqmSummaries\", "
3044 "\"reportingEntityId\", "
3046 "\"suppressedNvPairsList\": ["
3048 "\"nvPairFieldName\": \"additionalFields\", "
3049 "\"suppressedNvPairNames\": [\"Name1\", \"Name3\"]"
3057 "{\"commonEventHeader\": {"
3058 "\"domain\": \"serviceEvents\", "
3059 "\"eventId\": \"2000\", "
3060 "\"functionalRole\": \"UNIT TEST\", "
3061 "\"lastEpochMicrosec\": 1000002, "
3062 "\"priority\": \"Normal\", "
3063 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3064 "\"sequence\": 2000, "
3065 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3066 "\"startEpochMicrosec\": 1000002, "
3069 "\"serviceEventsFields\": {"
3070 "\"eventInstanceIdentifier\": "
3072 "\"vendorId\": \"vendor_x_id\", "
3073 "\"eventId\": \"vendor_x_event_id\", "
3074 "\"productId\": \"vendor_x_product_id\", "
3075 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3076 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3078 "\"serviceEventsFieldsVersion\": 1.1, "
3079 "\"additionalFields\": ["
3080 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
3081 "{\"name\": \"Name4\", \"value\": \"Value4\"}]"
3084 /***************************************************************************/
3085 /* Initialize and provide a specification with a single fault suppressed. */
3086 /***************************************************************************/
3087 evel_throttle_initialize();
3088 handle_json_response(json_command_list, &post);
3090 /***************************************************************************/
3091 /* Check that the domain is throttled. */
3092 /***************************************************************************/
3093 assert(evel_get_throttle_spec(EVEL_DOMAIN_SERVICE) != NULL);
3094 assert(post.memory == NULL);
3096 size_t json_size = 0;
3097 char json_body[EVEL_MAX_JSON_BODY];
3098 EVENT_SERVICE * event = NULL;
3099 evel_set_next_event_sequence(2000);
3100 event = evel_new_service("vendor_x_id", "vendor_x_event_id");
3101 assert(event != NULL);
3102 evel_service_type_set(event, "Service Event");
3103 evel_service_product_id_set(event, "vendor_x_product_id");
3104 evel_service_subsystem_id_set(event, "vendor_x_subsystem_id");
3105 evel_service_friendly_name_set(event, "vendor_x_frieldly_name");
3106 evel_service_correlator_set(event, "vendor_x_correlator");
3107 evel_service_codec_set(event, "PCMA");
3108 evel_service_codec_set(event, "PCMA");
3109 evel_service_callee_codec_set(event, "PCMA");
3110 evel_service_caller_codec_set(event, "G729A");
3111 evel_service_rtcp_data_set(event, "some_rtcp_data");
3112 evel_service_adjacency_name_set(event, "vendor_x_adjacency");
3113 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
3114 evel_service_endpoint_jitter_set(event, 66);
3115 evel_service_endpoint_rtp_oct_disc_set(event, 100);
3116 evel_service_endpoint_rtp_oct_recv_set(event, 200);
3117 evel_service_endpoint_rtp_oct_sent_set(event, 300);
3118 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
3119 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
3120 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
3121 evel_service_local_jitter_set(event, 99);
3122 evel_service_local_rtp_oct_disc_set(event, 150);
3123 evel_service_local_rtp_oct_recv_set(event, 250);
3124 evel_service_local_rtp_oct_sent_set(event, 350);
3125 evel_service_local_rtp_pkt_disc_set(event, 450);
3126 evel_service_local_rtp_pkt_recv_set(event, 550);
3127 evel_service_local_rtp_pkt_sent_set(event, 650);
3128 evel_service_mos_cqe_set(event, 12.255);
3129 evel_service_packets_lost_set(event, 157);
3130 evel_service_packet_loss_percent_set(event, 0.232);
3131 evel_service_r_factor_set(event, 11);
3132 evel_service_round_trip_delay_set(event, 15);
3133 evel_service_phone_number_set(event, "0888888888");
3134 evel_service_addl_field_add(event, "Name1", "Value1");
3135 evel_service_addl_field_add(event, "Name2", "Value2");
3136 evel_service_addl_field_add(event, "Name3", "Value3");
3137 evel_service_addl_field_add(event, "Name4", "Value4");
3138 json_size = evel_json_encode_event(
3139 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3140 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
3141 assert((json_size == strlen(json_body)) && "Bad size returned");
3143 evel_free_event(event);
3144 evel_throttle_terminate();
3147 void test_encode_signaling_throttled()
3151 /***************************************************************************/
3152 /* We also test suppression of the event header parameters here. */
3153 /***************************************************************************/
3154 char * json_command_list =
3156 "\"commandList\": ["
3159 "\"commandType\": \"throttlingSpecification\", "
3160 "\"eventDomainThrottleSpecification\": {"
3161 "\"eventDomain\": \"signaling\", "
3162 "\"suppressedFieldNames\": ["
3165 "\"reportingEntityId\", "
3167 "\"localIpAddress\", "
3169 "\"remoteIpAddress\", "
3171 "\"compressedSip\", "
3173 "\"suppressedNvPairsList\": ["
3180 "{\"commonEventHeader\": {"
3181 "\"domain\": \"signaling\", "
3182 "\"eventId\": \"2001\", "
3183 "\"functionalRole\": \"UNIT TEST\", "
3184 "\"lastEpochMicrosec\": 1000002, "
3185 "\"priority\": \"Normal\", "
3186 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3187 "\"sequence\": 2001, "
3188 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3189 "\"startEpochMicrosec\": 1000002, "
3192 "\"signalingFields\": {"
3193 "\"eventInstanceIdentifier\": "
3195 "\"vendorId\": \"vendor_x_id\", "
3196 "\"eventId\": \"vendor_x_event_id\", "
3197 "\"productId\": \"vendor_x_product_id\", "
3198 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3199 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3201 "\"signalingFieldsVersion\": 1.1"
3204 /***************************************************************************/
3205 /* Initialize and provide a specification with a single fault suppressed. */
3206 /***************************************************************************/
3207 evel_throttle_initialize();
3208 handle_json_response(json_command_list, &post);
3210 /***************************************************************************/
3211 /* Check that the domain is throttled. */
3212 /***************************************************************************/
3213 assert(evel_get_throttle_spec(EVEL_DOMAIN_SIGNALING) != NULL);
3214 assert(post.memory == NULL);
3216 size_t json_size = 0;
3217 char json_body[EVEL_MAX_JSON_BODY];
3218 EVENT_SIGNALING * event = NULL;
3219 evel_set_next_event_sequence(2001);
3220 event = evel_new_signaling("vendor_x_id",
3221 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
3222 assert(event != NULL);
3223 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
3224 evel_signaling_vnfname_set(event, "vendor_x_vnf");
3225 evel_signaling_type_set(event, "Signaling");
3226 evel_signaling_product_id_set(event, "vendor_x_product_id");
3227 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
3228 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
3229 evel_signaling_correlator_set(event, "vendor_x_correlator");
3230 evel_signaling_local_ip_address_set(event, "1.0.3.1");
3231 evel_signaling_local_port_set(event, "1031");
3232 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
3233 evel_signaling_remote_port_set(event, "5330");
3234 evel_signaling_compressed_sip_set(event, "compressed_sip");
3235 evel_signaling_summary_sip_set(event, "summary_sip");
3236 json_size = evel_json_encode_event(
3237 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3238 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
3239 assert((json_size == strlen(json_body)) && "Bad size returned");
3241 evel_free_event(event);
3242 evel_throttle_terminate();
3245 void test_encode_state_change_throttled()
3249 /***************************************************************************/
3250 /* We also test suppression of the event header parameters here. */
3251 /***************************************************************************/
3252 char * json_command_list =
3254 "\"commandList\": ["
3257 "\"commandType\": \"throttlingSpecification\", "
3258 "\"eventDomainThrottleSpecification\": {"
3259 "\"eventDomain\": \"stateChange\", "
3260 "\"suppressedFieldNames\": ["
3262 "\"reportingEntityId\", "
3264 "\"suppressedNvPairsList\": ["
3266 "\"nvPairFieldName\": \"additionalFields\", "
3267 "\"suppressedNvPairNames\": [\"Name1\"]"
3275 "{\"commonEventHeader\": {"
3276 "\"domain\": \"stateChange\", "
3277 "\"eventId\": \"128\", "
3278 "\"functionalRole\": \"UNIT TEST\", "
3279 "\"lastEpochMicrosec\": 1000002, "
3280 "\"priority\": \"Normal\", "
3281 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3282 "\"sequence\": 128, "
3283 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3284 "\"startEpochMicrosec\": 1000002, "
3287 "\"stateChangeFields\": {"
3288 "\"newState\": \"inService\", "
3289 "\"oldState\": \"outOfService\", "
3290 "\"stateInterface\": \"An Interface\", "
3291 "\"additionalFields\": ["
3292 "{\"name\": \"Name2\", "
3293 "\"value\": \"Value2\"}"
3295 "\"stateChangeFieldsVersion\": 1.1"
3298 /***************************************************************************/
3299 /* Initialize and provide a specification with a single fault suppressed. */
3300 /***************************************************************************/
3301 evel_throttle_initialize();
3302 handle_json_response(json_command_list, &post);
3304 /***************************************************************************/
3305 /* Check that the domain is throttled. */
3306 /***************************************************************************/
3307 assert(evel_get_throttle_spec(EVEL_DOMAIN_STATE_CHANGE) != NULL);
3308 assert(post.memory == NULL);
3310 size_t json_size = 0;
3311 char json_body[EVEL_MAX_JSON_BODY];
3312 EVENT_STATE_CHANGE * state_change = NULL;
3313 evel_set_next_event_sequence(128);
3314 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
3315 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
3317 assert(state_change != NULL);
3318 evel_state_change_type_set(state_change, "SC Type");
3319 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
3320 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
3322 json_size = evel_json_encode_event(
3323 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
3324 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
3325 assert((json_size == strlen(json_body)) && "Bad size returned");
3327 evel_free_event(state_change);
3328 evel_throttle_terminate();
3331 void test_encode_syslog_throttled()
3335 /***************************************************************************/
3336 /* We also test suppression of the event header parameters here. */
3337 /***************************************************************************/
3338 char * json_command_list =
3340 "\"commandList\": ["
3343 "\"commandType\": \"throttlingSpecification\", "
3344 "\"eventDomainThrottleSpecification\": {"
3345 "\"eventDomain\": \"syslog\", "
3346 "\"suppressedFieldNames\": ["
3347 "\"eventSourceHost\", "
3348 "\"syslogFacility\", "
3350 "\"syslogProcId\", "
3354 "\"reportingEntityId\", "
3356 "\"suppressedNvPairsList\": ["
3358 "\"nvPairFieldName\": \"additionalFields\", "
3359 "\"suppressedNvPairNames\": [\"Name2\"]"
3367 "{\"commonEventHeader\": {"
3368 "\"domain\": \"syslog\", "
3369 "\"eventId\": \"126\", "
3370 "\"functionalRole\": \"UNIT TEST\", "
3371 "\"lastEpochMicrosec\": 1000002, "
3372 "\"priority\": \"Normal\", "
3373 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3374 "\"sequence\": 126, "
3375 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3376 "\"startEpochMicrosec\": 1000002, "
3379 "\"syslogFields\": {"
3380 "\"eventSourceType\": \"virtualNetworkFunction\", "
3381 "\"syslogMsg\": \"SL Message\", "
3382 "\"syslogTag\": \"SL Tag\", "
3383 "\"syslogFieldsVersion\": 1.1, "
3384 "\"additionalFields\": ["
3385 "{\"name\": \"Name1\", "
3386 "\"value\": \"Value1\"}"
3390 /***************************************************************************/
3391 /* Initialize and provide a specification with a single fault suppressed. */
3392 /***************************************************************************/
3393 evel_throttle_initialize();
3394 handle_json_response(json_command_list, &post);
3396 /***************************************************************************/
3397 /* Check that the domain is throttled. */
3398 /***************************************************************************/
3399 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
3400 assert(post.memory == NULL);
3402 size_t json_size = 0;
3403 char json_body[EVEL_MAX_JSON_BODY];
3404 EVENT_SYSLOG * syslog = NULL;
3405 evel_set_next_event_sequence(126);
3406 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
3409 assert(syslog != NULL);
3410 evel_syslog_type_set(syslog, "SL Type");
3411 evel_syslog_event_source_host_set(syslog, "SL Host");
3412 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
3413 evel_syslog_proc_set(syslog, "SL Proc");
3414 evel_syslog_proc_id_set(syslog, 2);
3415 evel_syslog_version_set(syslog, 1);
3416 evel_syslog_s_data_set(syslog, "SL SDATA");
3417 evel_syslog_addl_field_add(syslog, "Name1", "Value1");
3418 evel_syslog_addl_field_add(syslog, "Name2", "Value2");
3420 json_size = evel_json_encode_event(
3421 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
3422 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
3423 assert((json_size == strlen(json_body)) && "Bad size returned");
3425 evel_free_event(syslog);
3426 evel_throttle_terminate();
3429 void test_encode_fault_with_escaping()
3433 "\"commonEventHeader\": {"
3434 "\"domain\": \"fault\", "
3435 "\"eventId\": \"122\", "
3436 "\"functionalRole\": \"UNIT TEST\", "
3437 "\"lastEpochMicrosec\": 1000002, "
3438 "\"priority\": \"Normal\", "
3439 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3440 "\"sequence\": 122, "
3441 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3442 "\"startEpochMicrosec\": 1000002, "
3443 "\"version\": 1.2, "
3444 "\"eventType\": \"Bad things happen...\\\\\", "
3445 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
3446 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
3448 "\"faultFields\": {"
3449 "\"alarmCondition\": \"My alarm condition\", "
3450 "\"eventSeverity\": \"MAJOR\", "
3451 "\"eventSourceType\": \"other\", "
3452 "\"specificProblem\": \"It broke \\\"very\\\" badly\", "
3453 "\"vfStatus\": \"Active\", "
3454 "\"faultFieldsVersion\": 1.1, "
3455 "\"alarmAdditionalInformation\": ["
3456 "{\"name\": \"name1\", "
3457 "\"value\": \"value1\"}, "
3458 "{\"name\": \"name2\", "
3459 "\"value\": \"value2\"}], "
3460 "\"alarmInterfaceA\": \"My Interface Card\""
3463 size_t json_size = 0;
3464 char json_body[EVEL_MAX_JSON_BODY];
3465 evel_set_next_event_sequence(122);
3466 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
3467 "It broke \"very\" badly",
3468 EVEL_PRIORITY_NORMAL,
3469 EVEL_SEVERITY_MAJOR,
3471 EVEL_VF_STATUS_PREP_TERMINATE);
3472 assert(fault != NULL);
3473 evel_fault_type_set(fault, "Bad things happen...\\");
3474 evel_fault_interface_set(fault, "My Interface Card");
3475 evel_fault_addl_info_add(fault, "name1", "value1");
3476 evel_fault_addl_info_add(fault, "name2", "value2");
3478 json_size = evel_json_encode_event(
3479 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
3480 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
3481 assert((json_size == strlen(json_body)) && "Bad size returned");
3483 evel_free_event(fault);