1 /**************************************************************************//**
3 * Unit tests for JSON encoding and throttling.
5 * This software is intended to show the essential elements of the library's
11 * Copyright(c) <2016>, AT&T Intellectual Property. All other rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement: This product includes software
23 * developed by the AT&T.
24 * 4. Neither the name of AT&T nor the names of its contributors may be used to
25 * endorse or promote products derived from this software without specific
26 * prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
29 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *****************************************************************************/
47 #include "evel_internal.h"
48 #include "evel_throttle.h"
60 /*****************************************************************************/
61 /* Local prototypes. */
62 /*****************************************************************************/
63 static void test_encode_heartbeat();
64 static void test_encode_header_overrides();
65 static void test_encode_fault();
66 static void test_encode_fault_with_escaping();
67 static void test_encode_measurement();
68 static void test_encode_mobile_mand();
69 static void test_encode_mobile_opts();
70 static void test_encode_other();
71 static void test_encode_report();
72 static void test_encode_service();
73 static void test_encode_service_subset(const SERVICE_TEST service_test);
74 static void test_encode_signaling();
75 static void test_encode_state_change();
76 static void test_encode_syslog();
77 static void test_json_response_junk();
78 static void test_json_provide_throttle_state();
79 static void test_json_measurement_interval();
80 static void test_json_throttle_spec_field();
81 static void test_json_throttle_spec_nv_pair();
82 static void test_json_throttle_spec_two_domains();
83 static void test_json_throttle_spec_bad_command_type();
84 static void test_encode_fault_throttled();
85 static void test_encode_measurement_throttled();
86 static void test_encode_mobile_throttled();
87 static void test_encode_other_throttled();
88 static void test_encode_report_throttled();
89 static void test_encode_service_throttled();
90 static void test_encode_signaling_throttled();
91 static void test_encode_state_change_throttled();
92 static void test_encode_syslog_throttled();
93 static void compare_strings(char * expected,
98 /**************************************************************************//**
101 * Runs all unit test cases, and fails hard on the first failure.
103 * @param[in] argc Argument count.
104 * @param[in] argv Argument vector - for usage see usage_text.
105 *****************************************************************************/
106 int main(int argc, char ** argv)
109 assert(argv != NULL);
111 /***************************************************************************/
112 /* Fix our timezone to UTC. */
113 /***************************************************************************/
116 /***************************************************************************/
117 /* Initialize metadata. */
118 /***************************************************************************/
119 openstack_metadata_initialize();
121 /***************************************************************************/
122 /* Minimal initialisation to exercise the encoders. */
123 /***************************************************************************/
124 functional_role = "UNIT TEST";
125 log_initialize(EVEL_LOG_DEBUG, "EVEL");
127 /***************************************************************************/
128 /* Test each encoder. */
129 /***************************************************************************/
130 test_encode_heartbeat();
131 test_encode_header_overrides();
133 test_encode_measurement();
134 test_encode_mobile_mand();
135 test_encode_mobile_opts();
137 test_encode_report();
138 test_encode_service();
139 test_encode_signaling();
140 test_encode_state_change();
141 test_encode_syslog();
143 /***************************************************************************/
144 /* Test JSON Throttle. */
145 /***************************************************************************/
146 test_json_response_junk();
147 test_json_provide_throttle_state();
148 test_json_measurement_interval();
149 test_json_throttle_spec_field();
150 test_json_throttle_spec_nv_pair();
151 test_json_throttle_spec_two_domains();
152 test_json_throttle_spec_bad_command_type();
154 /***************************************************************************/
155 /* Test each encoder with throttling applied. */
156 /***************************************************************************/
157 test_encode_fault_throttled();
158 test_encode_measurement_throttled();
159 test_encode_mobile_throttled();
160 test_encode_other_throttled();
161 test_encode_report_throttled();
162 test_encode_service_throttled();
163 test_encode_signaling_throttled();
164 test_encode_state_change_throttled();
165 test_encode_syslog_throttled();
167 /***************************************************************************/
168 /* Test character escaping. */
169 /***************************************************************************/
170 test_encode_fault_with_escaping();
172 printf ("\nAll Tests Passed\n");
177 /*****************************************************************************/
178 /* We link with this gettimeofday so that we get a fixed result */
179 /*****************************************************************************/
180 int gettimeofday(struct timeval *tv,
181 struct timezone *tz __attribute__((unused)))
188 void test_encode_heartbeat()
192 "\"commonEventHeader\": {"
193 "\"domain\": \"heartbeat\", "
194 "\"eventId\": \"121\", "
195 "\"functionalRole\": \"UNIT TEST\", "
196 "\"lastEpochMicrosec\": 1000002, "
197 "\"priority\": \"Normal\", "
198 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
199 "\"sequence\": 121, "
200 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
201 "\"startEpochMicrosec\": 1000002, "
203 "\"eventType\": \"Autonomous heartbeat\", "
204 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
205 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
208 size_t json_size = 0;
209 char json_body[EVEL_MAX_JSON_BODY];
211 /***************************************************************************/
212 /* Test the VM name/uuid once. */
213 /***************************************************************************/
214 evel_set_next_event_sequence(121);
216 EVENT_HEADER * heartbeat = evel_new_heartbeat();
217 assert(heartbeat != NULL);
219 json_size = evel_json_encode_event(
220 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
221 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
222 assert((json_size == strlen(json_body)) && "Bad size returned");
224 evel_free_event(heartbeat);
227 void test_encode_header_overrides()
231 "\"commonEventHeader\": {"
232 "\"domain\": \"heartbeat\", "
233 "\"eventId\": \"121\", "
234 "\"functionalRole\": \"UNIT TEST\", "
235 "\"lastEpochMicrosec\": 1000, "
236 "\"priority\": \"Normal\", "
237 "\"reportingEntityName\": \"entity_name_override\", "
238 "\"sequence\": 121, "
239 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
240 "\"startEpochMicrosec\": 1001, "
242 "\"eventType\": \"Autonomous heartbeat\", "
243 "\"reportingEntityId\": \"entity_id_override\", "
244 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
247 size_t json_size = 0;
248 char json_body[EVEL_MAX_JSON_BODY];
250 /***************************************************************************/
251 /* Test the VM name/uuid once. */
252 /***************************************************************************/
253 evel_set_next_event_sequence(121);
255 EVENT_HEADER * heartbeat = evel_new_heartbeat();
256 assert(heartbeat != NULL);
258 evel_start_epoch_set(heartbeat, 1001);
259 evel_last_epoch_set(heartbeat, 1000);
260 evel_reporting_entity_name_set(heartbeat, "entity_name_override");
261 evel_reporting_entity_id_set(heartbeat, "entity_id_override");
263 json_size = evel_json_encode_event(
264 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) heartbeat);
265 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Heartbeat");
266 assert((json_size == strlen(json_body)) && "Bad size returned");
268 evel_free_event(heartbeat);
271 void test_encode_fault()
275 "\"commonEventHeader\": {"
276 "\"domain\": \"fault\", "
277 "\"eventId\": \"122\", "
278 "\"functionalRole\": \"UNIT TEST\", "
279 "\"lastEpochMicrosec\": 1000002, "
280 "\"priority\": \"Normal\", "
281 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
282 "\"sequence\": 122, "
283 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
284 "\"startEpochMicrosec\": 1000002, "
286 "\"eventType\": \"Bad things happen...\", "
287 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
288 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
291 "\"alarmCondition\": \"My alarm condition\", "
292 "\"eventSeverity\": \"MAJOR\", "
293 "\"eventSourceType\": \"other\", "
294 "\"specificProblem\": \"It broke very badly\", "
295 "\"eventCategory\": \"link\", "
296 "\"vfStatus\": \"Active\", "
297 "\"faultFieldsVersion\": 1.1, "
298 "\"alarmAdditionalInformation\": ["
299 "{\"name\": \"name1\", "
300 "\"value\": \"value1\"}, "
301 "{\"name\": \"name2\", "
302 "\"value\": \"value2\"}], "
303 "\"alarmInterfaceA\": \"My Interface Card\""
306 size_t json_size = 0;
307 char json_body[EVEL_MAX_JSON_BODY];
308 evel_set_next_event_sequence(122);
309 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
310 "It broke very badly",
311 EVEL_PRIORITY_NORMAL,
314 EVEL_VF_STATUS_PREP_TERMINATE);
315 assert(fault != NULL);
316 evel_fault_type_set(fault, "Bad things happen...");
317 evel_fault_interface_set(fault, "My Interface Card");
318 evel_fault_addl_info_add(fault, "name1", "value1");
319 evel_fault_addl_info_add(fault, "name2", "value2");
321 json_size = evel_json_encode_event(
322 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
323 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
324 assert((json_size == strlen(json_body)) && "Bad size returned");
326 evel_free_event(fault);
329 void test_encode_measurement()
333 "{\"commonEventHeader\": {"
334 "\"domain\": \"measurementsForVfScaling\", "
335 "\"eventId\": \"123\", "
336 "\"functionalRole\": \"UNIT TEST\", "
337 "\"lastEpochMicrosec\": 3000, "
338 "\"priority\": \"Normal\", "
339 "\"reportingEntityName\": \"entity_name\", "
340 "\"sequence\": 123, "
341 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
342 "\"startEpochMicrosec\": 2000, "
344 "\"eventType\": \"Perf management...\", "
345 "\"reportingEntityId\": \"entity_id\", "
346 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
348 "\"measurementsForVfScalingFields\": "
350 "\"measurementInterval\": 5.500000, "
351 "\"concurrentSessions\": 1, "
352 "\"configuredEntities\": 2, "
353 "\"cpuUsageArray\": ["
354 "{\"cpuIdentifier\": \"cpu1\", "
355 "\"percentUsage\": 11.110000}, "
356 "{\"cpuIdentifier\": \"cpu2\", "
357 "\"percentUsage\": 22.220000}], "
358 "\"filesystemUsageArray\": ["
359 "{\"blockConfigured\": 100.110000, "
360 "\"blockIops\": 33, "
361 "\"blockUsed\": 100.220000, "
362 "\"ephemeralConfigured\": 100.110000, "
363 "\"ephemeralIops\": 44, "
364 "\"ephemeralUsed\": 200.220000, "
365 "\"filesystemName\": \"00-11-22\"}, "
366 "{\"blockConfigured\": 300.110000, "
367 "\"blockIops\": 55, "
368 "\"blockUsed\": 300.220000, "
369 "\"ephemeralConfigured\": 300.110000, "
370 "\"ephemeralIops\": 66, "
371 "\"ephemeralUsed\": 400.220000, "
372 "\"filesystemName\": \"33-44-55\"}], "
373 "\"latencyDistribution\": ["
374 "{\"countsInTheBucket\": 20}, "
375 "{\"lowEndOfLatencyBucket\": 10.000000, "
376 "\"highEndOfLatencyBucket\": 20.000000, "
377 "\"countsInTheBucket\": 30}], "
378 "\"meanRequestLatency\": 4.400000, "
379 "\"memoryConfigured\": 6.600000, "
380 "\"memoryUsed\": 3.300000, "
381 "\"requestRate\": 7, "
382 "\"vNicUsageArray\": ["
386 "\"packetsIn\": 100, "
387 "\"packetsOut\": 200, "
388 "\"vNicIdentifier\": \"eth0\""
393 "\"packetsIn\": 110, "
394 "\"packetsOut\": 240, "
395 "\"vNicIdentifier\": \"eth1\", "
396 "\"broadcastPacketsIn\": 11, "
397 "\"broadcastPacketsOut\": 12, "
398 "\"multicastPacketsIn\": 15, "
399 "\"multicastPacketsOut\": 16, "
400 "\"unicastPacketsIn\": 17, "
401 "\"unicastPacketsOut\": 18"
404 "\"aggregateCpuUsage\": 8.800000, "
405 "\"numberOfMediaPortsInUse\": 1234, "
406 "\"vnfcScalingMetric\": 1234.567800, "
408 "\"receiveDiscards\": 1, "
409 "\"receiveErrors\": 0, "
410 "\"transmitDiscards\": 2, "
411 "\"transmitErrors\": 1}, "
412 "\"featureUsageArray\": ["
413 "{\"featureIdentifier\": \"FeatureA\", "
414 "\"featureUtilization\": 123}, "
415 "{\"featureIdentifier\": \"FeatureB\", "
416 "\"featureUtilization\": 567}], "
417 "\"codecUsageArray\": ["
418 "{\"codecIdentifier\": \"G711a\", "
419 "\"numberInUse\": 91}, "
420 "{\"codecIdentifier\": \"G729ab\", "
421 "\"numberInUse\": 92}], "
422 "\"additionalMeasurements\": ["
423 "{\"name\": \"Group1\", "
424 "\"measurements\": ["
425 "{\"name\": \"Name1\", "
426 "\"value\": \"Value1\"}]}, "
427 "{\"name\": \"Group2\", "
428 "\"measurements\": ["
429 "{\"name\": \"Name1\", "
430 "\"value\": \"Value1\"}, "
431 "{\"name\": \"Name2\", "
432 "\"value\": \"Value2\"}]}], "
433 "\"measurementsForVfScalingVersion\": 1.1}}}";
435 size_t json_size = 0;
436 char json_body[EVEL_MAX_JSON_BODY];
437 EVENT_MEASUREMENT * measurement = NULL;
438 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
439 MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
440 MEASUREMENT_CPU_USE *cpu_use;
442 /***************************************************************************/
444 /***************************************************************************/
445 evel_set_next_event_sequence(123);
446 measurement = evel_new_measurement(5.5);
447 assert(measurement != NULL);
448 evel_measurement_type_set(measurement, "Perf management...");
449 evel_measurement_conc_sess_set(measurement, 1);
450 evel_measurement_cfg_ents_set(measurement, 2);
451 evel_measurement_mean_req_lat_set(measurement, 4.4);
452 evel_measurement_request_rate_set(measurement, 7);
454 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
455 evel_measurement_cpu_use_idle_set(cpu_use,22.22);
456 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
457 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
458 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
459 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
460 evel_measurement_cpu_use_system_set(cpu_use,77.77);
461 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
462 evel_measurement_cpu_use_wait_set(cpu_use,99.99);
464 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
465 evel_measurement_cpu_use_idle_set(cpu_use,12.22);
466 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
467 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
468 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
469 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
470 evel_measurement_cpu_use_system_set(cpu_use,77.77);
471 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
472 evel_measurement_cpu_use_wait_set(cpu_use,19.99);
475 evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33,
477 evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55,
479 evel_start_epoch_set(&measurement->header, 2000);
480 evel_last_epoch_set(&measurement->header, 3000);
481 evel_reporting_entity_name_set(&measurement->header, "entity_name");
482 evel_reporting_entity_id_set(&measurement->header, "entity_id");
484 /***************************************************************************/
485 /* Latency Bucket with no optional parameters. */
486 /***************************************************************************/
487 bucket = evel_new_meas_latency_bucket(20);
488 evel_meas_latency_bucket_add(measurement, bucket);
490 /***************************************************************************/
491 /* Latency Bucket with all optional parameters. */
492 /***************************************************************************/
493 bucket = evel_new_meas_latency_bucket(30);
494 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
495 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
496 evel_meas_latency_bucket_add(measurement, bucket);
498 /***************************************************************************/
499 /* vNIC Use with no optional parameters. */
500 /***************************************************************************/
501 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
502 evel_meas_vnic_use_add(measurement, vnic_use);
504 /***************************************************************************/
505 /* vNIC Use with all optional parameters. */
506 /***************************************************************************/
507 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
508 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
509 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
510 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
511 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
512 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
513 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
514 evel_meas_vnic_use_add(measurement, vnic_use);
516 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
518 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
519 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
521 evel_measurement_codec_use_add(measurement, "G711a", 91);
522 evel_measurement_codec_use_add(measurement, "G729ab", 92);
524 evel_measurement_media_port_use_set(measurement, 1234);
526 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
528 evel_measurement_custom_measurement_add(measurement,
529 "Group1", "Name1", "Value1");
530 evel_measurement_custom_measurement_add(measurement,
531 "Group2", "Name1", "Value1");
532 evel_measurement_custom_measurement_add(measurement,
533 "Group2", "Name2", "Value2");
535 json_size = evel_json_encode_event(
536 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
537 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
538 assert((json_size == strlen(json_body)) && "Bad size returned");
540 evel_free_event(measurement);
543 void test_encode_mobile_mand()
547 "{\"commonEventHeader\": {"
548 "\"domain\": \"mobileFlow\", "
549 "\"eventId\": \"1241\", "
550 "\"functionalRole\": \"UNIT TEST\", "
551 "\"lastEpochMicrosec\": 1000002, "
552 "\"priority\": \"Normal\", "
553 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
554 "\"sequence\": 1241, "
555 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
556 "\"startEpochMicrosec\": 1000002, "
558 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
559 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
561 "\"mobileFlowFields\": {"
562 "\"flowDirection\": \"Outbound\", "
563 "\"gtpPerFlowMetrics\": {"
564 "\"avgBitErrorRate\": 12.300000, "
565 "\"avgPacketDelayVariation\": 3.120000, "
566 "\"avgPacketLatency\": 100, "
567 "\"avgReceiveThroughput\": 2100, "
568 "\"avgTransmitThroughput\": 500, "
569 "\"flowActivationEpoch\": 1470409421, "
570 "\"flowActivationMicrosec\": 987, "
571 "\"flowDeactivationEpoch\": 1470409431, "
572 "\"flowDeactivationMicrosec\": 11, "
573 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:51 +0000\", "
574 "\"flowStatus\": \"Working\", "
575 "\"maxPacketDelayVariation\": 87, "
576 "\"numActivationFailures\": 3, "
577 "\"numBitErrors\": 17, "
578 "\"numBytesReceived\": 123654, "
579 "\"numBytesTransmitted\": 4561, "
580 "\"numDroppedPackets\": 0, "
581 "\"numL7BytesReceived\": 12, "
582 "\"numL7BytesTransmitted\": 10, "
583 "\"numLostPackets\": 1, "
584 "\"numOutOfOrderPackets\": 3, "
585 "\"numPacketErrors\": 7, "
586 "\"numPacketsReceivedExclRetrans\": 899, "
587 "\"numPacketsReceivedInclRetrans\": 901, "
588 "\"numPacketsTransmittedInclRetrans\": 302, "
589 "\"numRetries\": 6, "
590 "\"numTimeouts\": 2, "
591 "\"numTunneledL7BytesReceived\": 0, "
592 "\"roundTripTime\": 110, "
593 "\"timeToFirstByte\": 225"
595 "\"ipProtocolType\": \"TCP\", "
596 "\"ipVersion\": \"IPv4\", "
597 "\"otherEndpointIpAddress\": \"2.3.4.1\", "
598 "\"otherEndpointPort\": 2341, "
599 "\"reportingEndpointIpAddr\": \"4.2.3.1\", "
600 "\"reportingEndpointPort\": 4321"
603 size_t json_size = 0;
604 char json_body[EVEL_MAX_JSON_BODY];
605 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
606 EVENT_MOBILE_FLOW * mobile_flow = NULL;
608 /***************************************************************************/
610 /***************************************************************************/
611 evel_set_next_event_sequence(1241);
613 metrics = evel_new_mobile_gtp_flow_metrics(12.3,
643 assert(metrics != NULL);
644 mobile_flow = evel_new_mobile_flow("Outbound",
652 assert(mobile_flow != NULL);
654 json_size = evel_json_encode_event(
655 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
656 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
657 assert((json_size == strlen(json_body)) && "Bad size returned");
659 evel_free_event(mobile_flow);
662 void test_encode_mobile_opts()
666 "{\"commonEventHeader\": {"
667 "\"domain\": \"mobileFlow\", "
668 "\"eventId\": \"1242\", "
669 "\"functionalRole\": \"UNIT TEST\", "
670 "\"lastEpochMicrosec\": 1000002, "
671 "\"priority\": \"Normal\", "
672 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
673 "\"sequence\": 1242, "
674 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
675 "\"startEpochMicrosec\": 1000002, "
677 "\"eventType\": \"Mobile flow...\", "
678 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
679 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
681 "\"mobileFlowFields\": {"
682 "\"flowDirection\": \"Inbound\", "
683 "\"gtpPerFlowMetrics\": {"
684 "\"avgBitErrorRate\": 132.000100, "
685 "\"avgPacketDelayVariation\": 31.200000, "
686 "\"avgPacketLatency\": 101, "
687 "\"avgReceiveThroughput\": 2101, "
688 "\"avgTransmitThroughput\": 501, "
689 "\"flowActivationEpoch\": 1470409422, "
690 "\"flowActivationMicrosec\": 988, "
691 "\"flowDeactivationEpoch\": 1470409432, "
692 "\"flowDeactivationMicrosec\": 12, "
693 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
694 "\"flowStatus\": \"Inactive\", "
695 "\"maxPacketDelayVariation\": 88, "
696 "\"numActivationFailures\": 4, "
697 "\"numBitErrors\": 18, "
698 "\"numBytesReceived\": 123655, "
699 "\"numBytesTransmitted\": 4562, "
700 "\"numDroppedPackets\": 1, "
701 "\"numL7BytesReceived\": 13, "
702 "\"numL7BytesTransmitted\": 11, "
703 "\"numLostPackets\": 2, "
704 "\"numOutOfOrderPackets\": 4, "
705 "\"numPacketErrors\": 8, "
706 "\"numPacketsReceivedExclRetrans\": 900, "
707 "\"numPacketsReceivedInclRetrans\": 902, "
708 "\"numPacketsTransmittedInclRetrans\": 303, "
709 "\"numRetries\": 7, "
710 "\"numTimeouts\": 3, "
711 "\"numTunneledL7BytesReceived\": 1, "
712 "\"roundTripTime\": 111, "
713 "\"timeToFirstByte\": 226, "
714 "\"ipTosCountList\": ["
718 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
719 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
720 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
721 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
722 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
723 "\"durConnectionFailedStatus\": 12, "
724 "\"durTunnelFailedStatus\": 13, "
725 "\"flowActivatedBy\": \"Remote\", "
726 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
727 "\"flowDeactivatedBy\": \"Remote\", "
728 "\"gtpConnectionStatus\": \"Connected\", "
729 "\"gtpTunnelStatus\": \"Not tunneling\", "
730 "\"largePacketRtt\": 80, "
731 "\"largePacketThreshold\": 600.000000, "
732 "\"maxReceiveBitRate\": 1357924680, "
733 "\"maxTransmitBitRate\": 235711, "
734 "\"numGtpEchoFailures\": 1, "
735 "\"numGtpTunnelErrors\": 4, "
736 "\"numHttpErrors\": 2"
738 "\"ipProtocolType\": \"UDP\", "
739 "\"ipVersion\": \"IPv6\", "
740 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
741 "\"otherEndpointPort\": 2342, "
742 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
743 "\"reportingEndpointPort\": 4322, "
744 "\"applicationType\": \"Demo application\", "
745 "\"appProtocolType\": \"GSM\", "
746 "\"appProtocolVersion\": \"1\", "
747 "\"cid\": \"65535\", "
748 "\"connectionType\": \"S1-U\", "
749 "\"ecgi\": \"e65535\", "
750 "\"gtpProtocolType\": \"GTP-U\", "
751 "\"gtpVersion\": \"1\", "
752 "\"httpHeader\": \"http://www.something.com\", "
753 "\"imei\": \"209917614823\", "
754 "\"imsi\": \"355251/05/850925/8\", "
758 "\"msisdn\": \"6017123456789\", "
759 "\"otherFunctionalRole\": \"MME\", "
761 "\"radioAccessTechnology\": \"LTE\", "
763 "\"samplingAlgorithm\": 1, "
764 "\"tac\": \"2099\", "
765 "\"tunnelId\": \"Tunnel 1\", "
769 size_t json_size = 0;
770 char json_body[EVEL_MAX_JSON_BODY];
771 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
772 EVENT_MOBILE_FLOW * mobile_flow = NULL;
774 /***************************************************************************/
776 /***************************************************************************/
777 evel_set_next_event_sequence(1242);
779 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
809 assert(metrics != NULL);
811 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
812 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
813 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
814 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
815 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
816 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
817 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
818 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
819 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
820 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
821 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
822 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
823 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
824 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
825 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
826 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
827 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
828 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
829 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
830 evel_mobile_gtp_metrics_qci_cos_count_add(
831 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
832 evel_mobile_gtp_metrics_qci_cos_count_add(
833 metrics, EVEL_QCI_COS_LTE_65, 122);
835 mobile_flow = evel_new_mobile_flow("Inbound",
843 assert(mobile_flow != NULL);
845 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
846 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
847 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
848 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
849 evel_mobile_flow_cid_set(mobile_flow, "65535");
850 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
851 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
852 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
853 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
854 evel_mobile_flow_http_header_set(mobile_flow,
855 "http://www.something.com");
856 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
857 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
858 evel_mobile_flow_lac_set(mobile_flow, "1");
859 evel_mobile_flow_mcc_set(mobile_flow, "410");
860 evel_mobile_flow_mnc_set(mobile_flow, "04");
861 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
862 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
863 evel_mobile_flow_rac_set(mobile_flow, "514");
864 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
865 evel_mobile_flow_sac_set(mobile_flow, "1");
866 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
867 evel_mobile_flow_tac_set(mobile_flow, "2099");
868 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
869 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
871 json_size = evel_json_encode_event(
872 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
873 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
874 assert((json_size == strlen(json_body)) && "Bad size returned");
876 evel_free_event(mobile_flow);
879 void test_encode_report()
883 "{\"commonEventHeader\": {"
884 "\"domain\": \"measurementsForVfReporting\", "
885 "\"eventId\": \"125\", "
886 "\"functionalRole\": \"UNIT TEST\", "
887 "\"lastEpochMicrosec\": 1000002, "
888 "\"priority\": \"Normal\", "
889 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
890 "\"sequence\": 125, "
891 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
892 "\"startEpochMicrosec\": 1000002, "
894 "\"eventType\": \"Perf reporting...\", "
895 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
896 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
898 "\"measurementsForVfReportingFields\": "
899 "{\"measurementInterval\": 1.100000, "
900 "\"featureUsageArray\": ["
901 "{\"featureIdentifier\": \"FeatureA\", "
902 "\"featureUtilization\": 123}, "
903 "{\"featureIdentifier\": \"FeatureB\", "
904 "\"featureUtilization\": 567}], "
905 "\"additionalMeasurements\": ["
906 "{\"name\": \"Group1\", "
907 "\"measurements\": ["
908 "{\"name\": \"Name1\", "
909 "\"value\": \"Value1\"}]}, "
910 "{\"name\": \"Group2\", "
911 "\"measurements\": ["
912 "{\"name\": \"Name1\", "
913 "\"value\": \"Value1\"}, "
914 "{\"name\": \"Name2\", "
915 "\"value\": \"Value2\"}]}], "
916 "\"measurementFieldsVersion\": 1.1}}}";
918 size_t json_size = 0;
919 char json_body[EVEL_MAX_JSON_BODY];
920 EVENT_REPORT * report = NULL;
922 /***************************************************************************/
924 /***************************************************************************/
925 evel_set_next_event_sequence(125);
926 report = evel_new_report(1.1);
927 assert(report != NULL);
928 evel_report_type_set(report, "Perf reporting...");
929 evel_report_feature_use_add(report, "FeatureA", 123);
930 evel_report_feature_use_add(report, "FeatureB", 567);
931 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
932 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
933 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
935 json_size = evel_json_encode_event(
936 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
937 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
938 assert((json_size == strlen(json_body)) && "Bad size returned");
940 evel_free_event(report);
943 void test_encode_service()
945 test_encode_service_subset(SERVICE_NONE);
946 test_encode_service_subset(SERVICE_CODEC);
947 test_encode_service_subset(SERVICE_TRANSCODING);
948 test_encode_service_subset(SERVICE_RTCP);
949 test_encode_service_subset(SERVICE_EOC_VQM);
950 test_encode_service_subset(SERVICE_MARKER);
953 void test_encode_service_subset(const SERVICE_TEST service_test)
955 char * expected_start =
957 "{\"commonEventHeader\": {"
958 "\"domain\": \"serviceEvents\", "
959 "\"eventId\": \"2000\", "
960 "\"functionalRole\": \"UNIT TEST\", "
961 "\"lastEpochMicrosec\": 1000002, "
962 "\"priority\": \"Normal\", "
963 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
964 "\"sequence\": 2000, "
965 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
966 "\"startEpochMicrosec\": 1000002, "
968 "\"eventType\": \"Service Event\", "
969 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
970 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
972 "\"serviceEventsFields\": {"
973 "\"eventInstanceIdentifier\": "
975 "\"vendorId\": \"vendor_x_id\", "
976 "\"eventId\": \"vendor_x_event_id\", "
977 "\"productId\": \"vendor_x_product_id\", "
978 "\"subsystemId\": \"vendor_x_subsystem_id\", "
979 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
981 "\"serviceEventsFieldsVersion\": 1.1, "
982 "\"correlator\": \"vendor_x_correlator\", "
983 "\"additionalFields\": ["
984 "{\"name\": \"Name1\", \"value\": \"Value1\"}, "
985 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
986 "{\"name\": \"Name3\", \"value\": \"Value3\"}, "
987 "{\"name\": \"Name4\", \"value\": \"Value4\"}]";
988 char * expected_codec =
990 "\"codecSelected\": {"
991 "\"codec\": \"PCMA\""
993 char * expected_transcoding =
995 "\"codecSelectedTranscoding\": {"
996 "\"calleeSideCodec\": \"PCMA\", "
997 "\"callerSideCodec\": \"G729A\""
999 char * expected_rtcp =
1001 "\"midCallRtcp\": {"
1002 "\"rtcpData\": \"some_rtcp_data\""
1004 char * expected_eoc_vqm =
1006 "\"endOfCallVqmSummaries\": {"
1007 "\"adjacencyName\": \"vendor_x_adjacency\", "
1008 "\"endpointDescription\": \"Caller\", "
1009 "\"endpointJitter\": 66, "
1010 "\"endpointRtpOctetsDiscarded\": 100, "
1011 "\"endpointRtpOctetsReceived\": 200, "
1012 "\"endpointRtpOctetsSent\": 300, "
1013 "\"endpointRtpPacketsDiscarded\": 400, "
1014 "\"endpointRtpPacketsReceived\": 500, "
1015 "\"endpointRtpPacketsSent\": 600, "
1016 "\"localJitter\": 99, "
1017 "\"localRtpOctetsDiscarded\": 150, "
1018 "\"localRtpOctetsReceived\": 250, "
1019 "\"localRtpOctetsSent\": 350, "
1020 "\"localRtpPacketsDiscarded\": 450, "
1021 "\"localRtpPacketsReceived\": 550, "
1022 "\"localRtpPacketsSent\": 650, "
1023 "\"mosCqe\": 12.255000, "
1024 "\"packetsLost\": 157, "
1025 "\"packetLossPercent\": 0.232000, "
1027 "\"roundTripDelay\": 15"
1029 char * expected_marker =
1032 "\"phoneNumber\": \"0888888888\""
1034 char * expected_end =
1037 char * expected_middle = NULL;
1038 switch (service_test)
1041 expected_middle = "";
1044 expected_middle = expected_codec;
1046 case SERVICE_TRANSCODING:
1047 expected_middle = expected_transcoding;
1050 expected_middle = expected_rtcp;
1052 case SERVICE_EOC_VQM:
1053 expected_middle = expected_eoc_vqm;
1055 case SERVICE_MARKER:
1056 expected_middle = expected_marker;
1059 assert(expected_middle != NULL);
1062 char expected[EVEL_MAX_JSON_BODY];
1063 offset = snprintf(expected + offset,
1064 EVEL_MAX_JSON_BODY - offset,
1070 size_t json_size = 0;
1071 char json_body[EVEL_MAX_JSON_BODY];
1072 EVENT_SGNALING * event = NULL;
1073 evel_set_next_event_sequence(2000);
1074 event = evel_new_signaling("vendor_x_id",
1075 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1076 assert(event != NULL);
1077 evel_signaling_type_set(event, "Signaling");
1078 evel_signaling_correlator_set(event, "vendor_x_correlator");
1079 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1080 evel_signaling_vnfname_set(event, "vendor_x_vnf");
1082 switch (service_test)
1087 evel_signaling_addl_info_add(event, "codec", "PCMA");
1089 case SERVICE_TRANSCODING:
1090 evel_signaling_addl_info_add(event, "calleecodec", "PCMA");
1091 evel_signaling_addl_info_add(event, "callercodec", "G729A");
1094 evel_signaling_addl_info_add(event, "rtcpdata", "abcdefgh");
1096 case SERVICE_EOC_VQM:
1097 evel_signaling_addl_info_add(event, "adjacency", "vendor_x");
1098 /*evel_service_adjacency_name_set(event, "vendor_x_adjacency");
1099 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
1100 evel_service_endpoint_jitter_set(event, 66);
1101 evel_service_endpoint_rtp_oct_disc_set(event, 100);
1102 evel_service_endpoint_rtp_oct_recv_set(event, 200);
1103 evel_service_endpoint_rtp_oct_sent_set(event, 300);
1104 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
1105 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
1106 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
1107 evel_service_local_jitter_set(event, 99);
1108 evel_service_local_rtp_oct_disc_set(event, 150);
1109 evel_service_local_rtp_oct_recv_set(event, 250);
1110 evel_service_local_rtp_oct_sent_set(event, 350);
1111 evel_service_local_rtp_pkt_disc_set(event, 450);
1112 evel_service_local_rtp_pkt_recv_set(event, 550);
1113 evel_service_local_rtp_pkt_sent_set(event, 650);
1114 evel_service_mos_cqe_set(event, 12.255);
1115 evel_service_packets_lost_set(event, 157);
1116 evel_service_packet_loss_percent_set(event, 0.232);
1117 evel_service_r_factor_set(event, 11);
1118 evel_service_round_trip_delay_set(event, 15);*/
1120 case SERVICE_MARKER:
1121 evel_signaling_addl_info_add(event, "service_phone", "0888888888");
1125 json_size = evel_json_encode_event(
1126 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1127 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
1128 assert((json_size == strlen(json_body)) && "Bad size returned");
1130 evel_free_event(event);
1133 void test_encode_signaling()
1137 "{\"commonEventHeader\": {"
1138 "\"domain\": \"signaling\", "
1139 "\"eventId\": \"2001\", "
1140 "\"functionalRole\": \"UNIT TEST\", "
1141 "\"lastEpochMicrosec\": 1000002, "
1142 "\"priority\": \"Normal\", "
1143 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1144 "\"sequence\": 2001, "
1145 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1146 "\"startEpochMicrosec\": 1000002, "
1147 "\"version\": 1.2, "
1148 "\"eventType\": \"Signaling\", "
1149 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1150 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1152 "\"signalingFields\": {"
1153 "\"eventInstanceIdentifier\": "
1155 "\"vendorId\": \"vendor_x_id\", "
1156 "\"eventId\": \"vendor_x_event_id\", "
1157 "\"productId\": \"vendor_x_product_id\", "
1158 "\"subsystemId\": \"vendor_x_subsystem_id\", "
1159 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
1161 "\"signalingFieldsVersion\": 1.1, "
1162 "\"correlator\": \"vendor_x_correlator\", "
1163 "\"localIpAddress\": \"1.0.3.1\", "
1164 "\"localPort\": \"1031\", "
1165 "\"remoteIpAddress\": \"5.3.3.0\", "
1166 "\"remotePort\": \"5330\", "
1167 "\"compressedSip\": \"compressed_sip\", "
1168 "\"summarySip\": \"summary_sip\""
1171 size_t json_size = 0;
1172 char json_body[EVEL_MAX_JSON_BODY];
1173 EVENT_SIGNALING * event = NULL;
1174 evel_set_next_event_sequence(2001);
1175 event = evel_new_signaling("vendor_x_id",
1176 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1177 assert(event != NULL);
1178 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1179 evel_signaling_vnfname_set(event, "vendor_x_vnf");
1180 evel_signaling_type_set(event, "Signaling");
1181 evel_signaling_product_id_set(event, "vendor_x_product_id");
1182 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
1183 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
1184 evel_signaling_correlator_set(event, "vendor_x_correlator");
1185 evel_signaling_local_ip_address_set(event, "1.0.3.1");
1186 evel_signaling_local_port_set(event, "1031");
1187 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
1188 evel_signaling_remote_port_set(event, "5330");
1189 evel_signaling_compressed_sip_set(event, "compressed_sip");
1190 evel_signaling_summary_sip_set(event, "summary_sip");
1191 json_size = evel_json_encode_event(
1192 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
1193 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
1194 assert((json_size == strlen(json_body)) && "Bad size returned");
1196 evel_free_event(event);
1199 void test_encode_state_change()
1203 "{\"commonEventHeader\": {"
1204 "\"domain\": \"stateChange\", "
1205 "\"eventId\": \"128\", "
1206 "\"functionalRole\": \"UNIT TEST\", "
1207 "\"lastEpochMicrosec\": 1000002, "
1208 "\"priority\": \"Normal\", "
1209 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1210 "\"sequence\": 128, "
1211 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1212 "\"startEpochMicrosec\": 1000002, "
1213 "\"version\": 1.2, "
1214 "\"eventType\": \"SC Type\", "
1215 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1216 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1218 "\"stateChangeFields\": {"
1219 "\"newState\": \"inService\", "
1220 "\"oldState\": \"outOfService\", "
1221 "\"stateInterface\": \"An Interface\", "
1222 "\"additionalFields\": ["
1223 "{\"name\": \"Name1\", "
1224 "\"value\": \"Value1\"}, "
1225 "{\"name\": \"Name2\", "
1226 "\"value\": \"Value2\"}"
1228 "\"stateChangeFieldsVersion\": 1.1"
1231 size_t json_size = 0;
1232 char json_body[EVEL_MAX_JSON_BODY];
1233 EVENT_STATE_CHANGE * state_change = NULL;
1234 evel_set_next_event_sequence(128);
1235 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
1236 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
1238 assert(state_change != NULL);
1239 evel_state_change_type_set(state_change, "SC Type");
1240 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
1241 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
1243 json_size = evel_json_encode_event(
1244 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
1245 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
1246 assert((json_size == strlen(json_body)) && "Bad size returned");
1248 evel_free_event(state_change);
1251 void test_encode_syslog()
1255 "{\"commonEventHeader\": {"
1256 "\"domain\": \"syslog\", "
1257 "\"eventId\": \"126\", "
1258 "\"functionalRole\": \"UNIT TEST\", "
1259 "\"lastEpochMicrosec\": 1000002, "
1260 "\"priority\": \"Normal\", "
1261 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1262 "\"sequence\": 126, "
1263 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1264 "\"startEpochMicrosec\": 1000002, "
1265 "\"version\": 1.2, "
1266 "\"eventType\": \"SL Type\", "
1267 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1268 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1270 "\"syslogFields\": {"
1271 "\"eventSourceType\": \"virtualNetworkFunction\", "
1272 "\"syslogMsg\": \"SL Message\", "
1273 "\"syslogTag\": \"SL Tag\", "
1274 "\"syslogFieldsVersion\": 1.1, "
1275 "\"eventSourceHost\": \"SL Host\", "
1276 "\"syslogFacility\": 6, "
1277 "\"syslogProc\": \"SL Proc\", "
1278 "\"syslogProcId\": 2, "
1279 "\"syslogSData\": \"SL SDATA\", "
1282 size_t json_size = 0;
1283 char json_body[EVEL_MAX_JSON_BODY];
1284 EVENT_SYSLOG * syslog = NULL;
1285 evel_set_next_event_sequence(126);
1286 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
1289 assert(syslog != NULL);
1290 evel_syslog_type_set(syslog, "SL Type");
1291 evel_syslog_event_source_host_set(syslog, "SL Host");
1292 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
1293 evel_syslog_proc_set(syslog, "SL Proc");
1294 evel_syslog_proc_id_set(syslog, 2);
1295 evel_syslog_version_set(syslog, 1);
1296 evel_syslog_s_data_set(syslog, "SL SDATA");
1298 json_size = evel_json_encode_event(
1299 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
1300 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
1301 assert((json_size == strlen(json_body)) && "Bad size returned");
1303 evel_free_event(syslog);
1306 void test_encode_other()
1310 "{\"commonEventHeader\": {"
1311 "\"domain\": \"other\", "
1312 "\"eventId\": \"129\", "
1313 "\"functionalRole\": \"UNIT TEST\", "
1314 "\"lastEpochMicrosec\": 1000002, "
1315 "\"priority\": \"Normal\", "
1316 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
1317 "\"sequence\": 129, "
1318 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
1319 "\"startEpochMicrosec\": 1000002, "
1320 "\"version\": 1.2, "
1321 "\"eventType\": \"Other Type\", "
1322 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
1323 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
1325 "\"otherFields\": ["
1326 "{\"name\": \"Other field 1\", "
1327 "\"value\": \"Other value 1\"}, "
1328 "{\"name\": \"Other field 2\", "
1329 "\"value\": \"Other value 2\"}"
1333 size_t json_size = 0;
1334 char json_body[EVEL_MAX_JSON_BODY];
1335 EVENT_OTHER * other = NULL;
1336 evel_set_next_event_sequence(129);
1337 other = evel_new_other();
1338 assert(other != NULL);
1339 evel_other_type_set(other, "Other Type");
1340 evel_other_field_add(other,
1343 evel_other_field_add(other,
1347 json_size = evel_json_encode_event(
1348 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
1349 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
1350 assert((json_size == strlen(json_body)) && "Bad size returned");
1352 evel_free_event(other);
1355 void compare_strings(char * expected,
1360 if (strncmp(expected, actual, max_size) != 0)
1363 while (diff < max_size)
1365 if (expected[diff] != actual[diff])
1372 printf("Comparison Failure at Offset %d\n\n", diff);
1373 printf("Expected:\n%s\n", expected);
1374 printf("Actual:\n%s\n", actual);
1375 printf("Description: %s\n", description);
1380 /**************************************************************************//**
1381 * Copy a json string to a ::MEMORY_CHUNK for testing.
1383 * @param chunk The memory chunk.
1384 * @param string The json string.
1385 *****************************************************************************/
1386 void copy_string_to_chunk(MEMORY_CHUNK * chunk, char * string)
1390 /***************************************************************************/
1391 /* Check preconditions. */
1392 /***************************************************************************/
1393 assert(chunk != NULL);
1394 assert(string != NULL);
1396 mem_size = strlen(string) + 1;
1397 chunk->memory = malloc(mem_size);
1398 memcpy(chunk->memory, string, mem_size);
1399 chunk->size = mem_size;
1402 /**************************************************************************//**
1403 * Copy a json string to a ::MEMORY_CHUNK for testing.
1405 * @param json The JSON string.
1406 * @param post Memory chunk to post a response.
1407 *****************************************************************************/
1408 void handle_json_response(char * json, MEMORY_CHUNK * post)
1411 post->memory = NULL;
1413 copy_string_to_chunk(&chunk, json);
1414 evel_handle_event_response(&chunk, post);
1418 /**************************************************************************//**
1419 * Test that a non-"commandList" JSON buffer leaves the throttle state off.
1420 *****************************************************************************/
1421 void test_json_response_junk()
1428 "\"1\", \"2\", \"3\"], "
1430 "\"1\", \"2\", \"3\"]"
1433 evel_throttle_initialize();
1434 handle_json_response(json_junk, &post);
1436 /***************************************************************************/
1437 /* Check that all domains are not throttled. */
1438 /***************************************************************************/
1439 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1441 assert(evel_get_throttle_spec(domain) == NULL);
1444 /***************************************************************************/
1445 /* Check that we generated no post. */
1446 /***************************************************************************/
1447 assert(post.memory == NULL);
1449 evel_throttle_terminate();
1452 char * json_command_list_provide =
1454 "\"commandList\": ["
1457 "\"commandType\": \"provideThrottlingState\""
1463 char * json_command_list_fault_clear =
1465 "\"commandList\": ["
1468 "\"commandType\": \"throttlingSpecification\", "
1469 "\"eventDomainThrottleSpecification\": {"
1470 "\"eventDomain\": \"fault\""
1477 char * json_command_list_syslog_clear =
1479 "\"commandList\": ["
1482 "\"commandType\": \"throttlingSpecification\", "
1483 "\"eventDomainThrottleSpecification\": {"
1484 "\"eventDomain\": \"syslog\""
1491 char * expected_throttle_state_normal =
1493 "\"eventThrottlingState\": {"
1494 "\"eventThrottlingMode\": \"normal\"}"
1497 /**************************************************************************//**
1498 * Test that we can return the default throttling state.
1499 *****************************************************************************/
1500 void test_json_provide_throttle_state()
1505 char * expected_post = expected_throttle_state_normal;
1507 evel_throttle_initialize();
1508 handle_json_response(json_command_list_provide, &post);
1510 /***************************************************************************/
1511 /* Check that all domains are not throttled. */
1512 /***************************************************************************/
1513 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1515 assert(evel_get_throttle_spec(domain) == NULL);
1518 /***************************************************************************/
1519 /* Check that we generated a throttling specification post. */
1520 /***************************************************************************/
1521 assert(post.memory != NULL);
1522 compare_strings(expected_post, post.memory, strlen(expected_post),
1523 "Throttle State Normal");
1526 evel_throttle_terminate();
1529 /**************************************************************************//**
1530 * Test the measurement interval handling and API.
1531 *****************************************************************************/
1532 void test_json_measurement_interval()
1535 char * json_command_list_interval_only =
1537 "\"commandList\": ["
1540 "\"measurementInterval\": 60"
1546 char * json_command_list_interval_first =
1548 "\"commandList\": ["
1551 "\"measurementInterval\": 30, "
1552 "\"commandType\": \"measurementIntervalChange\""
1558 char * json_command_list_command_first =
1560 "\"commandList\": ["
1563 "\"commandType\": \"measurementIntervalChange\", "
1564 "\"measurementInterval\": 60"
1570 evel_throttle_initialize();
1571 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1573 /***************************************************************************/
1574 /* Check that we're not handling stuff when we shouldn't. */
1575 /***************************************************************************/
1576 handle_json_response(json_command_list_interval_only, &post);
1577 assert(post.memory == NULL);
1578 assert(evel_get_measurement_interval() == EVEL_MEASUREMENT_INTERVAL_UKNOWN);
1580 /***************************************************************************/
1581 /* Check that we're OK with the interval coming first. */
1582 /***************************************************************************/
1583 handle_json_response(json_command_list_interval_first, &post);
1584 assert(post.memory == NULL);
1585 assert(evel_get_measurement_interval() == 30);
1587 /***************************************************************************/
1588 /* Check that we're OK with the command type coming first. */
1589 /***************************************************************************/
1590 handle_json_response(json_command_list_command_first, &post);
1591 assert(post.memory == NULL);
1592 assert(evel_get_measurement_interval() == 60);
1594 evel_throttle_terminate();
1597 /**************************************************************************//**
1598 * Test a single domain, single field suppression.
1599 *****************************************************************************/
1600 void test_json_throttle_spec_field()
1605 char * json_command_list_fault_single =
1607 "\"commandList\": ["
1610 "\"commandType\": \"throttlingSpecification\", "
1611 "\"eventDomainThrottleSpecification\": {"
1612 "\"eventDomain\": \"fault\", "
1613 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1620 char * json_command_list_fault_double =
1622 "\"commandList\": ["
1625 "\"commandType\": \"throttlingSpecification\", "
1626 "\"eventDomainThrottleSpecification\": {"
1627 "\"eventDomain\": \"fault\", "
1628 "\"suppressedFieldNames\": ["
1629 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1636 char * expected_post_fault_single =
1638 "\"eventThrottlingState\": {"
1639 "\"eventThrottlingMode\": \"throttled\", "
1640 "\"eventDomainThrottleSpecificationList\": ["
1642 "\"eventDomain\": \"fault\", "
1643 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
1649 char * expected_post_fault_double =
1651 "\"eventThrottlingState\": {"
1652 "\"eventThrottlingMode\": \"throttled\", "
1653 "\"eventDomainThrottleSpecificationList\": ["
1655 "\"eventDomain\": \"fault\", "
1656 "\"suppressedFieldNames\": ["
1657 "\"alarmInterfaceA\", \"alarmAdditionalInformation\"]"
1663 /***************************************************************************/
1664 /* Initialize and provide a specification with a single fault suppressed. */
1665 /***************************************************************************/
1666 evel_throttle_initialize();
1667 handle_json_response(json_command_list_fault_single, &post);
1669 /***************************************************************************/
1670 /* Check that the FAULT domain is throttled. */
1671 /***************************************************************************/
1672 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1673 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1675 if (domain != EVEL_DOMAIN_FAULT)
1677 assert(evel_get_throttle_spec(domain) == NULL);
1680 assert(post.memory == NULL);
1682 /***************************************************************************/
1683 /* Request and verify the throttling state. */
1684 /***************************************************************************/
1685 handle_json_response(json_command_list_provide, &post);
1686 assert(post.memory != NULL);
1687 compare_strings(expected_post_fault_single,
1689 strlen(expected_post_fault_single),
1690 "Fault - Single Field");
1694 /***************************************************************************/
1695 /* Update a specification with two faults suppressed. */
1696 /***************************************************************************/
1697 handle_json_response(json_command_list_fault_double, &post);
1699 /***************************************************************************/
1700 /* Check that the FAULT domain is throttled. */
1701 /***************************************************************************/
1702 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1703 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1705 if (domain != EVEL_DOMAIN_FAULT)
1707 assert(evel_get_throttle_spec(domain) == NULL);
1710 assert(post.memory == NULL);
1712 /***************************************************************************/
1713 /* Request and verify the throttling state. */
1714 /***************************************************************************/
1715 handle_json_response(json_command_list_provide, &post);
1716 assert(post.memory != NULL);
1717 compare_strings(expected_post_fault_double,
1719 strlen(expected_post_fault_double),
1720 "Fault - Double Field");
1724 /***************************************************************************/
1725 /* Now clear the FAULT domain. */
1726 /***************************************************************************/
1727 handle_json_response(json_command_list_fault_clear, &post);
1728 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1730 assert(evel_get_throttle_spec(domain) == NULL);
1733 evel_throttle_terminate();
1736 /**************************************************************************//**
1737 * Test a single domain, nv_pair suppression.
1738 *****************************************************************************/
1739 void test_json_throttle_spec_nv_pair()
1744 char * json_command_list_fault_pair_single =
1746 "\"commandList\": ["
1749 "\"commandType\": \"throttlingSpecification\", "
1750 "\"eventDomainThrottleSpecification\": {"
1751 "\"eventDomain\": \"fault\", "
1752 "\"suppressedNvPairsList\": ["
1754 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1755 "\"suppressedNvPairNames\": [\"name1\"]"
1764 char * json_command_list_fault_pair_double =
1766 "\"commandList\": ["
1769 "\"commandType\": \"throttlingSpecification\", "
1770 "\"eventDomainThrottleSpecification\": {"
1771 "\"eventDomain\": \"fault\", "
1772 "\"suppressedNvPairsList\": ["
1774 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1775 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1784 char * expected_post_fault_pair_single =
1786 "\"eventThrottlingState\": {"
1787 "\"eventThrottlingMode\": \"throttled\", "
1788 "\"eventDomainThrottleSpecificationList\": ["
1790 "\"eventDomain\": \"fault\", "
1791 "\"suppressedNvPairsList\": ["
1793 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1794 "\"suppressedNvPairNames\": [\"name1\"]"
1802 char * expected_post_fault_pair_double =
1804 "\"eventThrottlingState\": {"
1805 "\"eventThrottlingMode\": \"throttled\", "
1806 "\"eventDomainThrottleSpecificationList\": ["
1808 "\"eventDomain\": \"fault\", "
1809 "\"suppressedNvPairsList\": ["
1811 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1812 "\"suppressedNvPairNames\": [\"name1\", \"name2\"]"
1820 /***************************************************************************/
1821 /* Initialize and provide a specification with a single nvpair with a */
1822 /* single sub-field suppressed. */
1823 /***************************************************************************/
1824 evel_throttle_initialize();
1825 handle_json_response(json_command_list_fault_pair_single, &post);
1827 /***************************************************************************/
1828 /* Check that the FAULT domain is throttled. */
1829 /***************************************************************************/
1830 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1831 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1833 if (domain != EVEL_DOMAIN_FAULT)
1835 assert(evel_get_throttle_spec(domain) == NULL);
1838 assert(post.memory == NULL);
1840 /***************************************************************************/
1841 /* Request and verify the throttling state. */
1842 /***************************************************************************/
1843 handle_json_response(json_command_list_provide, &post);
1844 assert(post.memory != NULL);
1845 compare_strings(expected_post_fault_pair_single,
1847 strlen(expected_post_fault_pair_single),
1848 "Fault - Single Pair, Single Field");
1852 /***************************************************************************/
1853 /* Update a specification with a single nvpair with two sub-fields */
1855 /***************************************************************************/
1856 handle_json_response(json_command_list_fault_pair_double, &post);
1858 /***************************************************************************/
1859 /* Check that the FAULT domain is throttled. */
1860 /***************************************************************************/
1861 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1862 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1864 if (domain != EVEL_DOMAIN_FAULT)
1866 assert(evel_get_throttle_spec(domain) == NULL);
1869 assert(post.memory == NULL);
1871 /***************************************************************************/
1872 /* Request and verify the throttling state. */
1873 /***************************************************************************/
1874 handle_json_response(json_command_list_provide, &post);
1875 assert(post.memory != NULL);
1876 compare_strings(expected_post_fault_pair_double,
1878 strlen(expected_post_fault_pair_double),
1879 "Fault - Double Field");
1883 /***************************************************************************/
1884 /* Now clear the FAULT domain. */
1885 /***************************************************************************/
1886 handle_json_response(json_command_list_fault_clear, &post);
1887 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1889 assert(evel_get_throttle_spec(domain) == NULL);
1892 evel_throttle_terminate();
1895 /**************************************************************************//**
1896 * Test two domains, nv_pair suppression.
1897 *****************************************************************************/
1898 void test_json_throttle_spec_two_domains()
1903 char * json_command_list_two_domains =
1905 "\"commandList\": ["
1908 "\"commandType\": \"throttlingSpecification\", "
1909 "\"eventDomainThrottleSpecification\": {"
1910 "\"eventDomain\": \"fault\", "
1911 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1912 "\"suppressedNvPairsList\": ["
1914 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1915 "\"suppressedNvPairNames\": [\"name1\"]"
1919 "\"commandType\": \"throttlingSpecification\", "
1920 "\"eventDomainThrottleSpecification\": {"
1921 "\"eventDomain\": \"syslog\", "
1922 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1923 "\"suppressedNvPairsList\": ["
1925 "\"nvPairFieldName\": \"additionalFields\", "
1926 "\"suppressedNvPairNames\": [\"name1\"]"
1931 char * expected_post_two_domains =
1933 "\"eventThrottlingState\": {"
1934 "\"eventThrottlingMode\": \"throttled\", "
1935 "\"eventDomainThrottleSpecificationList\": ["
1937 "\"eventDomain\": \"fault\", "
1938 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
1939 "\"suppressedNvPairsList\": ["
1941 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
1942 "\"suppressedNvPairNames\": [\"name1\"]"
1945 "\"eventDomain\": \"syslog\", "
1946 "\"suppressedFieldNames\": [\"syslogProcId\"], "
1947 "\"suppressedNvPairsList\": ["
1949 "\"nvPairFieldName\": \"additionalFields\", "
1950 "\"suppressedNvPairNames\": [\"name1\"]"
1956 /***************************************************************************/
1957 /* Initialize and provide a specification with a single nvpair with a */
1958 /* single sub-field suppressed. */
1959 /***************************************************************************/
1960 evel_throttle_initialize();
1961 handle_json_response(json_command_list_two_domains, &post);
1963 /***************************************************************************/
1964 /* Check that the FAULT and SYSLOG domains are throttled. */
1965 /***************************************************************************/
1966 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
1967 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1968 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
1970 if ((domain != EVEL_DOMAIN_FAULT) && (domain != EVEL_DOMAIN_SYSLOG))
1972 assert(evel_get_throttle_spec(domain) == NULL);
1975 assert(post.memory == NULL);
1977 /***************************************************************************/
1978 /* Request and verify the throttling state. */
1979 /***************************************************************************/
1980 handle_json_response(json_command_list_provide, &post);
1981 assert(post.memory != NULL);
1982 compare_strings(expected_post_two_domains,
1984 strlen(expected_post_two_domains),
1985 "Fault - Two Domains");
1989 /***************************************************************************/
1990 /* Now clear the FAULT and SYSLOG domains. */
1991 /***************************************************************************/
1992 handle_json_response(json_command_list_fault_clear, &post);
1993 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
1994 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
1995 handle_json_response(json_command_list_syslog_clear, &post);
1996 for (domain = EVEL_DOMAIN_FAULT; domain < EVEL_MAX_DOMAINS; domain++)
1998 assert(evel_get_throttle_spec(domain) == NULL);
2001 evel_throttle_terminate();
2004 /**************************************************************************//**
2005 * Test bad command type.
2006 *****************************************************************************/
2007 void test_json_throttle_spec_bad_command_type()
2012 /***************************************************************************/
2013 /* Search for "dodgy" in the JSON, and you will see the dodgy bits we're */
2014 /* handling in these tests. */
2015 /***************************************************************************/
2016 #define NUM_BAD_COMMANDS 8
2017 char * json_command_list_dodgy_command =
2019 "\"commandList\": ["
2022 "\"commandType\": \"dodgyCommand\", "
2023 "\"eventDomainThrottleSpecification\": {"
2024 "\"eventDomain\": \"fault\", "
2025 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2026 "\"suppressedNvPairsList\": ["
2028 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2029 "\"suppressedNvPairNames\": [\"name1\"]"
2034 char * json_command_list_dodgy_spec =
2036 "\"commandList\": ["
2039 "\"commandType\": \"throttlingSpecification\", "
2040 "\"dodgyEventDomainThrottleSpecification\": {"
2041 "\"eventDomain\": \"fault\", "
2042 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2043 "\"suppressedNvPairsList\": ["
2045 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2046 "\"suppressedNvPairNames\": [\"name1\"]"
2051 char * json_command_list_dodgy_event_domain_key =
2053 "\"commandList\": ["
2056 "\"commandType\": \"throttlingSpecification\", "
2057 "\"eventDomainThrottleSpecification\": {"
2058 "\"dodgyEventDomainKey\": \"fault\", "
2059 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2060 "\"suppressedNvPairsList\": ["
2062 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2063 "\"suppressedNvPairNames\": [\"name1\"]"
2068 char * json_command_list_dodgy_event_domain =
2070 "\"commandList\": ["
2073 "\"commandType\": \"throttlingSpecification\", "
2074 "\"eventDomainThrottleSpecification\": {"
2075 "\"eventDomain\": \"dodgyEventDomain\", "
2076 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2077 "\"suppressedNvPairsList\": ["
2079 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2080 "\"suppressedNvPairNames\": [\"name1\"]"
2085 char * json_command_list_dodgy_field_names_key =
2087 "\"commandList\": ["
2090 "\"commandType\": \"throttlingSpecification\", "
2091 "\"eventDomainThrottleSpecification\": {"
2092 "\"eventDomain\": \"fault\", "
2093 "\"suppressedNvPairsList\": ["
2095 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2096 "\"suppressedNvPairNames\": [\"name1\"]"
2101 char * json_command_list_dodgy_pair_names_list_key =
2103 "\"commandList\": ["
2106 "\"commandType\": \"throttlingSpecification\", "
2107 "\"eventDomainThrottleSpecification\": {"
2108 "\"eventDomain\": \"fault\", "
2109 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2110 "\"dodgySuppressedNvPairsListKey\": ["
2112 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2113 "\"suppressedNvPairNames\": [\"name1\"]"
2118 char * json_command_list_dodgy_pair_field_name_key =
2120 "\"commandList\": ["
2123 "\"commandType\": \"throttlingSpecification\", "
2124 "\"eventDomainThrottleSpecification\": {"
2125 "\"eventDomain\": \"fault\", "
2126 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2127 "\"suppressedNvPairsList\": ["
2129 "\"dodgyNvPairFieldNameKey\": \"alarmAdditionalInformation\", "
2130 "\"suppressedNvPairNames\": [\"name1\"]"
2135 char * json_command_list_dodgy_pair_names_key =
2137 "\"commandList\": ["
2140 "\"commandType\": \"throttlingSpecification\", "
2141 "\"eventDomainThrottleSpecification\": {"
2142 "\"eventDomain\": \"fault\", "
2143 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2144 "\"suppressedNvPairsList\": ["
2146 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2147 "\"dodgySuppressedNvPairNamesKey\": [\"name1\"]"
2152 char * json_command_list_dodgy_depth =
2154 "\"commandList\": ["
2157 "\"commandType\": \"throttlingSpecification\", "
2158 "\"eventDomainThrottleSpecification\": {"
2159 "\"eventDomain\": \"fault\", "
2160 "\"suppressedFieldNames\": [\"alarmInterfaceA\"], "
2161 "\"suppressedNvPairsList\": ["
2163 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2164 "\"dodgySuppressedNvPairNamesKey\": "
2165 "[\"name1\", [[[[[[[[]]]]]]]]]"
2170 char * expected_throttle_state_dodgy_field_names_key =
2172 "\"eventThrottlingState\": {"
2173 "\"eventThrottlingMode\": \"throttled\", "
2174 "\"eventDomainThrottleSpecificationList\": ["
2176 "\"eventDomain\": \"fault\", "
2177 "\"suppressedNvPairsList\": ["
2179 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2180 "\"suppressedNvPairNames\": [\"name1\"]"
2186 char * expected_throttle_state_dodgy_pair_names_list_key =
2188 "\"eventThrottlingState\": {"
2189 "\"eventThrottlingMode\": \"throttled\", "
2190 "\"eventDomainThrottleSpecificationList\": ["
2192 "\"eventDomain\": \"fault\", "
2193 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2199 char * expected_throttle_state_dodgy_pair_field_name_key =
2201 "\"eventThrottlingState\": {"
2202 "\"eventThrottlingMode\": \"throttled\", "
2203 "\"eventDomainThrottleSpecificationList\": ["
2205 "\"eventDomain\": \"fault\", "
2206 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2212 char * expected_throttle_state_dodgy_pair_names_key =
2214 "\"eventThrottlingState\": {"
2215 "\"eventThrottlingMode\": \"throttled\", "
2216 "\"eventDomainThrottleSpecificationList\": ["
2218 "\"eventDomain\": \"fault\", "
2219 "\"suppressedFieldNames\": [\"alarmInterfaceA\"]"
2225 char * json_command_lists[] = {
2226 json_command_list_dodgy_command,
2227 json_command_list_dodgy_spec,
2228 json_command_list_dodgy_event_domain_key,
2229 json_command_list_dodgy_event_domain,
2230 json_command_list_dodgy_depth,
2231 json_command_list_dodgy_field_names_key,
2232 json_command_list_dodgy_pair_names_list_key,
2233 json_command_list_dodgy_pair_field_name_key,
2234 json_command_list_dodgy_pair_names_key
2237 char * expected_posts[] = {
2238 expected_throttle_state_normal,
2239 expected_throttle_state_normal,
2240 expected_throttle_state_normal,
2241 expected_throttle_state_normal,
2242 expected_throttle_state_normal,
2243 expected_throttle_state_dodgy_field_names_key,
2244 expected_throttle_state_dodgy_pair_names_list_key,
2245 expected_throttle_state_dodgy_pair_field_name_key,
2246 expected_throttle_state_dodgy_pair_names_key
2249 const int num_commands =
2250 sizeof(json_command_lists) / sizeof(json_command_lists[0]);
2251 const int num_posts =
2252 sizeof(expected_posts) / sizeof(expected_posts[0]);
2253 assert(num_commands == num_posts);
2255 /***************************************************************************/
2256 /* Initialize and provide a specification with a single nvpair with a */
2257 /* single sub-field suppressed. */
2258 /***************************************************************************/
2259 evel_throttle_initialize();
2262 for (ii = 0; ii < num_commands; ii++)
2264 EVEL_DEBUG("Testing commandList[%d] = %s\n", ii, json_command_lists[ii]);
2265 handle_json_response(json_command_lists[ii], &post);
2267 /*************************************************************************/
2268 /* Check that throttling is in a normal state - because we ignored the */
2269 /* command / ..... */
2270 /*************************************************************************/
2271 for (domain = EVEL_DOMAIN_MEASUREMENT; domain < EVEL_MAX_DOMAINS; domain++)
2273 assert(evel_get_throttle_spec(domain) == NULL);
2275 if (expected_posts[ii] == expected_throttle_state_normal)
2277 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) == NULL);
2281 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2283 assert(post.memory == NULL);
2285 /*************************************************************************/
2286 /* Request and verify the throttling state. */
2287 /*************************************************************************/
2288 handle_json_response(json_command_list_provide, &post);
2289 assert(post.memory != NULL);
2290 compare_strings(expected_posts[ii],
2292 strlen(expected_posts[ii]),
2293 "Throttle State Normal");
2298 evel_throttle_terminate();
2301 void test_encode_fault_throttled()
2305 /***************************************************************************/
2306 /* We also test suppression of the event header parameters here. */
2307 /***************************************************************************/
2308 char * json_command_list =
2310 "\"commandList\": ["
2313 "\"commandType\": \"throttlingSpecification\", "
2314 "\"eventDomainThrottleSpecification\": {"
2315 "\"eventDomain\": \"fault\", "
2316 "\"suppressedFieldNames\": ["
2317 "\"alarmInterfaceA\", "
2319 "\"reportingEntityId\", "
2321 "\"suppressedNvPairsList\": ["
2323 "\"nvPairFieldName\": \"alarmAdditionalInformation\", "
2324 "\"suppressedNvPairNames\": [\"name3\", \"name4\"]"
2331 "\"commonEventHeader\": {"
2332 "\"domain\": \"fault\", "
2333 "\"eventId\": \"122\", "
2334 "\"functionalRole\": \"UNIT TEST\", "
2335 "\"lastEpochMicrosec\": 1000002, "
2336 "\"priority\": \"Normal\", "
2337 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2338 "\"sequence\": 122, "
2339 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2340 "\"startEpochMicrosec\": 1000002, "
2343 "\"faultFields\": {"
2344 "\"alarmCondition\": \"My alarm condition\", "
2345 "\"eventSeverity\": \"MAJOR\", "
2346 "\"eventSourceType\": \"other\", "
2347 "\"specificProblem\": \"It broke very badly\", "
2348 "\"vfStatus\": \"Active\", "
2349 "\"faultFieldsVersion\": 1.1, "
2350 "\"alarmAdditionalInformation\": ["
2351 "{\"name\": \"name1\", "
2352 "\"value\": \"value1\"}, "
2353 "{\"name\": \"name2\", "
2354 "\"value\": \"value2\"}]"
2357 /***************************************************************************/
2358 /* Initialize and provide a specification with a single fault suppressed. */
2359 /***************************************************************************/
2360 evel_throttle_initialize();
2361 handle_json_response(json_command_list, &post);
2363 /***************************************************************************/
2364 /* Check that the domain is throttled. */
2365 /***************************************************************************/
2366 assert(evel_get_throttle_spec(EVEL_DOMAIN_FAULT) != NULL);
2367 assert(post.memory == NULL);
2369 size_t json_size = 0;
2370 char json_body[EVEL_MAX_JSON_BODY];
2371 evel_set_next_event_sequence(122);
2372 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
2373 "It broke very badly",
2374 EVEL_PRIORITY_NORMAL,
2375 EVEL_SEVERITY_MAJOR,
2377 EVEL_VF_STATUS_PREP_TERMINATE);
2378 assert(fault != NULL);
2379 evel_fault_type_set(fault, "Bad things happen...");
2380 evel_fault_addl_info_add(fault, "name1", "value1");
2381 evel_fault_addl_info_add(fault, "name2", "value2");
2383 /***************************************************************************/
2384 /* Suppressed fields. */
2385 /***************************************************************************/
2386 evel_fault_interface_set(fault, "My Interface Card");
2387 evel_fault_addl_info_add(fault, "name3", "value3");
2388 evel_fault_addl_info_add(fault, "name4", "value4");
2390 json_size = evel_json_encode_event(
2391 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
2392 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
2393 assert((json_size == strlen(json_body)) && "Bad size returned");
2395 evel_free_event(fault);
2396 evel_throttle_terminate();
2399 void test_encode_measurement_throttled()
2403 /***************************************************************************/
2404 /* We also test suppression of the event header parameters here. */
2405 /***************************************************************************/
2406 char * json_command_list =
2408 "\"commandList\": ["
2411 "\"commandType\": \"throttlingSpecification\", "
2412 "\"eventDomainThrottleSpecification\": {"
2413 "\"eventDomain\": \"measurementsForVfScaling\", "
2414 "\"suppressedFieldNames\": ["
2416 "\"vnfcScalingMetric\", "
2417 "\"numberOfMediaPortsInUse\", "
2418 "\"aggregateCpuUsage\", "
2421 "\"memoryConfigured\", "
2422 "\"meanRequestLatency\", "
2423 "\"latencyDistribution\", "
2424 "\"concurrentSessions\", "
2425 "\"configuredEntities\", "
2427 "\"reportingEntityId\", "
2429 "\"suppressedNvPairsList\": ["
2431 "\"nvPairFieldName\": \"cpuUsageArray\", "
2432 "\"suppressedNvPairNames\": [\"cpu3\", \"cpu4\"]"
2435 "\"nvPairFieldName\": \"filesystemUsageArray\", "
2436 "\"suppressedNvPairNames\": [\"00-11-22\", \"33-44-55\"]"
2439 "\"nvPairFieldName\": \"vNicUsageArray\", "
2440 "\"suppressedNvPairNames\": [\"eth1\", \"eth0\"]"
2443 "\"nvPairFieldName\": \"featureUsageArray\", "
2444 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2447 "\"nvPairFieldName\": \"codecUsageArray\", "
2448 "\"suppressedNvPairNames\": [\"G729ab\"]"
2451 "\"nvPairFieldName\": \"additionalMeasurements\", "
2452 "\"suppressedNvPairNames\": [\"Group2\"]"
2460 "{\"commonEventHeader\": {"
2461 "\"domain\": \"measurementsForVfScaling\", "
2462 "\"eventId\": \"123\", "
2463 "\"functionalRole\": \"UNIT TEST\", "
2464 "\"lastEpochMicrosec\": 1000002, "
2465 "\"priority\": \"Normal\", "
2466 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2467 "\"sequence\": 123, "
2468 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2469 "\"startEpochMicrosec\": 1000002, "
2472 "\"measurementsForVfScalingFields\": "
2474 "\"measurementInterval\": 5.500000, "
2475 "\"cpuUsageArray\": ["
2476 "{\"cpuIdentifier\": \"cpu1\", "
2477 "\"percentUsage\": 11.110000}, "
2478 "{\"cpuIdentifier\": \"cpu2\", "
2479 "\"percentUsage\": 22.220000}], "
2480 "\"filesystemUsageArray\": ["
2481 "{\"blockConfigured\": 500.110000, "
2482 "\"blockIops\": 77, "
2483 "\"blockUsed\": 500.220000, "
2484 "\"ephemeralConfigured\": 500.110000, "
2485 "\"ephemeralIops\": 88, "
2486 "\"ephemeralUsed\": 600.220000, "
2487 "\"filesystemName\": \"66-77-88\"}], "
2488 "\"featureUsageArray\": ["
2489 "{\"featureIdentifier\": \"FeatureA\", "
2490 "\"featureUtilization\": 123}], "
2491 "\"codecUsageArray\": ["
2492 "{\"codecIdentifier\": \"G711a\", "
2493 "\"numberInUse\": 91}], "
2494 "\"additionalMeasurements\": ["
2495 "{\"name\": \"Group1\", "
2496 "\"measurements\": ["
2497 "{\"name\": \"Name1\", "
2498 "\"value\": \"Value1\"}]}], "
2499 "\"measurementsForVfScalingVersion\": 1.1}}}";
2500 MEASUREMENT_CPU_USE *cpu_use;
2502 /***************************************************************************/
2503 /* Initialize and provide a specification with a single fault suppressed. */
2504 /***************************************************************************/
2505 evel_throttle_initialize();
2506 handle_json_response(json_command_list, &post);
2508 /***************************************************************************/
2509 /* Check that the domain is throttled. */
2510 /***************************************************************************/
2511 assert(evel_get_throttle_spec(EVEL_DOMAIN_MEASUREMENT) != NULL);
2512 assert(post.memory == NULL);
2514 size_t json_size = 0;
2515 char json_body[EVEL_MAX_JSON_BODY];
2516 evel_set_next_event_sequence(123);
2517 EVENT_MEASUREMENT * measurement = evel_new_measurement(5.5);
2518 MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
2519 MEASUREMENT_VNIC_PERFORMANCE * vnic_use = NULL;
2520 assert(measurement != NULL);
2522 evel_measurement_type_set(measurement, "Perf management...");
2523 evel_measurement_conc_sess_set(measurement, 1);
2524 evel_measurement_cfg_ents_set(measurement, 2);
2525 evel_measurement_mean_req_lat_set(measurement, 4.4);
2526 evel_measurement_mem_cfg_set(measurement, 6.6);
2527 evel_measurement_mem_used_set(measurement, 3.3);
2528 evel_measurement_request_rate_set(measurement, 7);
2530 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", 11.11);
2531 evel_measurement_cpu_use_idle_set(cpu_use,22.22);
2532 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2533 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2534 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2535 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2536 evel_measurement_cpu_use_system_set(cpu_use,77.77);
2537 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2538 evel_measurement_cpu_use_wait_set(cpu_use,99.99);
2540 cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu2", 22.22);
2541 evel_measurement_cpu_use_idle_set(cpu_use,12.22);
2542 evel_measurement_cpu_use_interrupt_set(cpu_use,33.33);
2543 evel_measurement_cpu_use_nice_set(cpu_use,44.44);
2544 evel_measurement_cpu_use_softirq_set(cpu_use,55.55);
2545 evel_measurement_cpu_use_steal_set(cpu_use,66.66);
2546 evel_measurement_cpu_use_system_set(cpu_use,77.77);
2547 evel_measurement_cpu_use_usageuser_set(cpu_use,88.88);
2548 evel_measurement_cpu_use_wait_set(cpu_use,19.99);
2550 evel_measurement_fsys_use_add(measurement, "00-11-22",
2552 200.11, 200.22, 44);
2553 evel_measurement_fsys_use_add(measurement, "33-44-55",
2555 400.11, 400.22, 66);
2556 evel_measurement_fsys_use_add(measurement, "66-77-88",
2558 600.11, 600.22, 88);
2560 bucket = evel_new_meas_latency_bucket(20);
2561 evel_meas_latency_bucket_add(measurement, bucket);
2563 bucket = evel_new_meas_latency_bucket(30);
2564 evel_meas_latency_bucket_low_end_set(bucket, 10.0);
2565 evel_meas_latency_bucket_high_end_set(bucket, 20.0);
2566 evel_meas_latency_bucket_add(measurement, bucket);
2568 vnic_use = evel_new_measurement_vnic_use("eth0", 100, 200, 3, 4);
2569 evel_vnic_use_bcast_pkt_in_set(vnic_use, 1);
2570 evel_vnic_use_bcast_pkt_out_set(vnic_use, 2);
2571 evel_vnic_use_mcast_pkt_in_set(vnic_use, 5);
2572 evel_vnic_use_mcast_pkt_out_set(vnic_use, 6);
2573 evel_vnic_use_ucast_pkt_in_set(vnic_use, 7);
2574 evel_vnic_use_ucast_pkt_out_set(vnic_use, 8);
2575 evel_meas_vnic_use_add(measurement, vnic_use);
2577 vnic_use = evel_new_measurement_vnic_use("eth1", 110, 240, 13, 14);
2578 evel_vnic_use_bcast_pkt_in_set(vnic_use, 11);
2579 evel_vnic_use_bcast_pkt_out_set(vnic_use, 12);
2580 evel_vnic_use_mcast_pkt_in_set(vnic_use, 15);
2581 evel_vnic_use_mcast_pkt_out_set(vnic_use, 16);
2582 evel_vnic_use_ucast_pkt_in_set(vnic_use, 17);
2583 evel_vnic_use_ucast_pkt_out_set(vnic_use, 18);
2584 evel_meas_vnic_use_add(measurement, vnic_use);
2586 evel_measurement_errors_set(measurement, 1, 0, 2, 1);
2587 evel_measurement_feature_use_add(measurement, "FeatureA", 123);
2588 evel_measurement_feature_use_add(measurement, "FeatureB", 567);
2589 evel_measurement_codec_use_add(measurement, "G711a", 91);
2590 evel_measurement_codec_use_add(measurement, "G729ab", 92);
2591 evel_measurement_media_port_use_set(measurement, 1234);
2592 evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
2593 evel_measurement_custom_measurement_add(measurement,
2594 "Group1", "Name1", "Value1");
2595 evel_measurement_custom_measurement_add(measurement,
2596 "Group2", "Name1", "Value1");
2597 evel_measurement_custom_measurement_add(measurement,
2598 "Group2", "Name2", "Value2");
2600 json_size = evel_json_encode_event(
2601 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) measurement);
2602 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Measurement");
2603 assert((json_size == strlen(json_body)) && "Bad size returned");
2605 evel_free_event(measurement);
2606 evel_throttle_terminate();
2609 void test_encode_mobile_throttled()
2613 /***************************************************************************/
2614 /* We also test suppression of the event header parameters here. */
2615 /***************************************************************************/
2616 char * json_command_list =
2618 "\"commandList\": ["
2621 "\"commandType\": \"throttlingSpecification\", "
2622 "\"eventDomainThrottleSpecification\": {"
2623 "\"eventDomain\": \"mobileFlow\", "
2624 "\"suppressedFieldNames\": ["
2625 "\"applicationType\", "
2626 "\"appProtocolType\", "
2627 "\"appProtocolVersion\", "
2629 "\"connectionType\", "
2631 "\"gtpProtocolType\", "
2640 "\"otherFunctionalRole\", "
2642 "\"radioAccessTechnology\", "
2644 "\"samplingAlgorithm\", "
2649 "\"reportingEntityId\", "
2651 "\"suppressedNvPairsList\": ["
2658 "{\"commonEventHeader\": {"
2659 "\"domain\": \"mobileFlow\", "
2660 "\"eventId\": \"1242\", "
2661 "\"functionalRole\": \"UNIT TEST\", "
2662 "\"lastEpochMicrosec\": 1000002, "
2663 "\"priority\": \"Normal\", "
2664 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2665 "\"sequence\": 1242, "
2666 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2667 "\"startEpochMicrosec\": 1000002, "
2670 "\"mobileFlowFields\": {"
2671 "\"flowDirection\": \"Inbound\", "
2672 "\"gtpPerFlowMetrics\": {"
2673 "\"avgBitErrorRate\": 132.000100, "
2674 "\"avgPacketDelayVariation\": 31.200000, "
2675 "\"avgPacketLatency\": 101, "
2676 "\"avgReceiveThroughput\": 2101, "
2677 "\"avgTransmitThroughput\": 501, "
2678 "\"flowActivationEpoch\": 1470409422, "
2679 "\"flowActivationMicrosec\": 988, "
2680 "\"flowDeactivationEpoch\": 1470409432, "
2681 "\"flowDeactivationMicrosec\": 12, "
2682 "\"flowDeactivationTime\": \"Fri, 05 Aug 2016 15:03:52 +0000\", "
2683 "\"flowStatus\": \"Inactive\", "
2684 "\"maxPacketDelayVariation\": 88, "
2685 "\"numActivationFailures\": 4, "
2686 "\"numBitErrors\": 18, "
2687 "\"numBytesReceived\": 123655, "
2688 "\"numBytesTransmitted\": 4562, "
2689 "\"numDroppedPackets\": 1, "
2690 "\"numL7BytesReceived\": 13, "
2691 "\"numL7BytesTransmitted\": 11, "
2692 "\"numLostPackets\": 2, "
2693 "\"numOutOfOrderPackets\": 4, "
2694 "\"numPacketErrors\": 8, "
2695 "\"numPacketsReceivedExclRetrans\": 900, "
2696 "\"numPacketsReceivedInclRetrans\": 902, "
2697 "\"numPacketsTransmittedInclRetrans\": 303, "
2698 "\"numRetries\": 7, "
2699 "\"numTimeouts\": 3, "
2700 "\"numTunneledL7BytesReceived\": 1, "
2701 "\"roundTripTime\": 111, "
2702 "\"timeToFirstByte\": 226, "
2703 "\"ipTosCountList\": ["
2707 "\"ipTosList\": [\"1\", \"4\", \"17\"], "
2708 "\"tcpFlagList\": [\"CWR\", \"URG\"], "
2709 "\"tcpFlagCountList\": [[\"CWR\", 10], [\"URG\", 121]], "
2710 "\"mobileQciCosList\": [\"conversational\", \"65\"], "
2711 "\"mobileQciCosCountList\": [[\"conversational\", 11], [\"65\", 122]], "
2712 "\"durConnectionFailedStatus\": 12, "
2713 "\"durTunnelFailedStatus\": 13, "
2714 "\"flowActivatedBy\": \"Remote\", "
2715 "\"flowActivationTime\": \"Fri, 05 Aug 2016 15:03:43 +0000\", "
2716 "\"flowDeactivatedBy\": \"Remote\", "
2717 "\"gtpConnectionStatus\": \"Connected\", "
2718 "\"gtpTunnelStatus\": \"Not tunneling\", "
2719 "\"largePacketRtt\": 80, "
2720 "\"largePacketThreshold\": 600.000000, "
2721 "\"maxReceiveBitRate\": 1357924680, "
2722 "\"maxTransmitBitRate\": 235711, "
2723 "\"numGtpEchoFailures\": 1, "
2724 "\"numGtpTunnelErrors\": 4, "
2725 "\"numHttpErrors\": 2"
2727 "\"ipProtocolType\": \"UDP\", "
2728 "\"ipVersion\": \"IPv6\", "
2729 "\"otherEndpointIpAddress\": \"2.3.4.2\", "
2730 "\"otherEndpointPort\": 2342, "
2731 "\"reportingEndpointIpAddr\": \"4.2.3.2\", "
2732 "\"reportingEndpointPort\": 4322"
2735 /***************************************************************************/
2736 /* Initialize and provide a specification with a single fault suppressed. */
2737 /***************************************************************************/
2738 evel_throttle_initialize();
2739 handle_json_response(json_command_list, &post);
2741 /***************************************************************************/
2742 /* Check that the domain is throttled. */
2743 /***************************************************************************/
2744 assert(evel_get_throttle_spec(EVEL_DOMAIN_MOBILE_FLOW) != NULL);
2745 assert(post.memory == NULL);
2747 size_t json_size = 0;
2748 char json_body[EVEL_MAX_JSON_BODY];
2749 MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
2750 EVENT_MOBILE_FLOW * mobile_flow = NULL;
2752 /***************************************************************************/
2754 /***************************************************************************/
2755 evel_set_next_event_sequence(1242);
2757 metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
2787 assert(metrics != NULL);
2789 evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
2790 evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
2791 evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
2792 evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
2793 evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
2794 evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
2795 evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
2796 evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
2797 evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
2798 evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
2799 evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
2800 evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
2801 evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
2802 evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
2803 evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
2804 evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
2805 evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
2806 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
2807 evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
2808 evel_mobile_gtp_metrics_qci_cos_count_add(
2809 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
2810 evel_mobile_gtp_metrics_qci_cos_count_add(
2811 metrics, EVEL_QCI_COS_LTE_65, 122);
2813 mobile_flow = evel_new_mobile_flow("Inbound",
2821 assert(mobile_flow != NULL);
2823 evel_mobile_flow_type_set(mobile_flow, "Mobile flow...");
2824 evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
2825 evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
2826 evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
2827 evel_mobile_flow_cid_set(mobile_flow, "65535");
2828 evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
2829 evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
2830 evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
2831 evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
2832 evel_mobile_flow_http_header_set(mobile_flow,
2833 "http://www.something.com");
2834 evel_mobile_flow_imei_set(mobile_flow, "209917614823");
2835 evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
2836 evel_mobile_flow_lac_set(mobile_flow, "1");
2837 evel_mobile_flow_mcc_set(mobile_flow, "410");
2838 evel_mobile_flow_mnc_set(mobile_flow, "04");
2839 evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
2840 evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
2841 evel_mobile_flow_rac_set(mobile_flow, "514");
2842 evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
2843 evel_mobile_flow_sac_set(mobile_flow, "1");
2844 evel_mobile_flow_samp_alg_set(mobile_flow, 1);
2845 evel_mobile_flow_tac_set(mobile_flow, "2099");
2846 evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
2847 evel_mobile_flow_vlan_id_set(mobile_flow, "15");
2849 json_size = evel_json_encode_event(
2850 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) mobile_flow);
2851 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Mobile");
2852 assert((json_size == strlen(json_body)) && "Bad size returned");
2854 evel_free_event(mobile_flow);
2855 evel_throttle_terminate();
2858 void test_encode_other_throttled()
2862 /***************************************************************************/
2863 /* We also test suppression of the event header parameters here. */
2864 /***************************************************************************/
2865 char * json_command_list =
2867 "\"commandList\": ["
2870 "\"commandType\": \"throttlingSpecification\", "
2871 "\"eventDomainThrottleSpecification\": {"
2872 "\"eventDomain\": \"other\", "
2873 "\"suppressedFieldNames\": ["
2875 "\"reportingEntityId\", "
2877 "\"suppressedNvPairsList\": ["
2884 "{\"commonEventHeader\": {"
2885 "\"domain\": \"other\", "
2886 "\"eventId\": \"129\", "
2887 "\"functionalRole\": \"UNIT TEST\", "
2888 "\"lastEpochMicrosec\": 1000002, "
2889 "\"priority\": \"Normal\", "
2890 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2891 "\"sequence\": 129, "
2892 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2893 "\"startEpochMicrosec\": 1000002, "
2896 "\"otherFields\": ["
2897 "{\"name\": \"Other field 1\", "
2898 "\"value\": \"Other value 1\"}, "
2899 "{\"name\": \"Other field 2\", "
2900 "\"value\": \"Other value 2\"}"
2904 /***************************************************************************/
2905 /* Initialize and provide a specification with a single fault suppressed. */
2906 /***************************************************************************/
2907 evel_throttle_initialize();
2908 handle_json_response(json_command_list, &post);
2910 /***************************************************************************/
2911 /* Check that the domain is throttled. */
2912 /***************************************************************************/
2913 assert(evel_get_throttle_spec(EVEL_DOMAIN_OTHER) != NULL);
2914 assert(post.memory == NULL);
2916 size_t json_size = 0;
2917 char json_body[EVEL_MAX_JSON_BODY];
2918 EVENT_OTHER * other = NULL;
2919 evel_set_next_event_sequence(129);
2920 other = evel_new_other();
2921 assert(other != NULL);
2922 evel_other_type_set(other, "Other Type");
2923 evel_other_field_add(other,
2926 evel_other_field_add(other,
2930 json_size = evel_json_encode_event(
2931 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) other);
2932 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Other");
2933 assert((json_size == strlen(json_body)) && "Bad size returned");
2935 evel_free_event(other);
2936 evel_throttle_terminate();
2939 void test_encode_report_throttled()
2943 /***************************************************************************/
2944 /* We also test suppression of the event header parameters here. */
2945 /***************************************************************************/
2946 char * json_command_list =
2948 "\"commandList\": ["
2951 "\"commandType\": \"throttlingSpecification\", "
2952 "\"eventDomainThrottleSpecification\": {"
2953 "\"eventDomain\": \"report\", "
2954 "\"suppressedFieldNames\": ["
2956 "\"reportingEntityId\", "
2958 "\"suppressedNvPairsList\": ["
2960 "\"nvPairFieldName\": \"featureUsageArray\", "
2961 "\"suppressedNvPairNames\": [\"FeatureB\", \"FeatureC\"]"
2964 "\"nvPairFieldName\": \"additionalMeasurements\", "
2965 "\"suppressedNvPairNames\": [\"Group2\"]"
2973 "{\"commonEventHeader\": {"
2974 "\"domain\": \"measurementsForVfReporting\", "
2975 "\"eventId\": \"125\", "
2976 "\"functionalRole\": \"UNIT TEST\", "
2977 "\"lastEpochMicrosec\": 1000002, "
2978 "\"priority\": \"Normal\", "
2979 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
2980 "\"sequence\": 125, "
2981 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
2982 "\"startEpochMicrosec\": 1000002, "
2985 "\"measurementsForVfReportingFields\": "
2986 "{\"measurementInterval\": 1.100000, "
2987 "\"featureUsageArray\": ["
2988 "{\"featureIdentifier\": \"FeatureA\", "
2989 "\"featureUtilization\": 123}], "
2990 "\"additionalMeasurements\": ["
2991 "{\"name\": \"Group1\", "
2992 "\"measurements\": ["
2993 "{\"name\": \"Name1\", "
2994 "\"value\": \"Value1\"}]}], "
2995 "\"measurementFieldsVersion\": 1.1}}}";
2997 /***************************************************************************/
2998 /* Initialize and provide a specification with a single fault suppressed. */
2999 /***************************************************************************/
3000 evel_throttle_initialize();
3001 handle_json_response(json_command_list, &post);
3003 /***************************************************************************/
3004 /* Check that the domain is throttled. */
3005 /***************************************************************************/
3006 assert(evel_get_throttle_spec(EVEL_DOMAIN_REPORT) != NULL);
3007 assert(post.memory == NULL);
3009 size_t json_size = 0;
3010 char json_body[EVEL_MAX_JSON_BODY];
3011 EVENT_REPORT * report = NULL;
3013 /***************************************************************************/
3015 /***************************************************************************/
3016 evel_set_next_event_sequence(125);
3017 report = evel_new_report(1.1);
3018 assert(report != NULL);
3019 evel_report_type_set(report, "Perf reporting...");
3020 evel_report_feature_use_add(report, "FeatureA", 123);
3021 evel_report_feature_use_add(report, "FeatureB", 567);
3022 evel_report_custom_measurement_add(report, "Group1", "Name1", "Value1");
3023 evel_report_custom_measurement_add(report, "Group2", "Name1", "Value1");
3024 evel_report_custom_measurement_add(report, "Group2", "Name2", "Value2");
3026 json_size = evel_json_encode_event(
3027 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) report);
3028 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Report");
3029 assert((json_size == strlen(json_body)) && "Bad size returned");
3031 evel_free_event(report);
3032 evel_throttle_terminate();
3035 void test_encode_service_throttled()
3039 /***************************************************************************/
3040 /* We also test suppression of the event header parameters here. */
3041 /***************************************************************************/
3042 char * json_command_list =
3044 "\"commandList\": ["
3047 "\"commandType\": \"throttlingSpecification\", "
3048 "\"eventDomainThrottleSpecification\": {"
3049 "\"eventDomain\": \"serviceEvents\", "
3050 "\"suppressedFieldNames\": ["
3053 "\"codecSelected\", "
3054 "\"codecSelectedTranscoding\", "
3055 "\"endOfCallVqmSummaries\", "
3058 "\"reportingEntityId\", "
3060 "\"suppressedNvPairsList\": ["
3062 "\"nvPairFieldName\": \"additionalFields\", "
3063 "\"suppressedNvPairNames\": [\"Name1\", \"Name3\"]"
3071 "{\"commonEventHeader\": {"
3072 "\"domain\": \"serviceEvents\", "
3073 "\"eventId\": \"2000\", "
3074 "\"functionalRole\": \"UNIT TEST\", "
3075 "\"lastEpochMicrosec\": 1000002, "
3076 "\"priority\": \"Normal\", "
3077 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3078 "\"sequence\": 2000, "
3079 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3080 "\"startEpochMicrosec\": 1000002, "
3083 "\"serviceEventsFields\": {"
3084 "\"eventInstanceIdentifier\": "
3086 "\"vendorId\": \"vendor_x_id\", "
3087 "\"eventId\": \"vendor_x_event_id\", "
3088 "\"productId\": \"vendor_x_product_id\", "
3089 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3090 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3092 "\"serviceEventsFieldsVersion\": 1.1, "
3093 "\"additionalFields\": ["
3094 "{\"name\": \"Name2\", \"value\": \"Value2\"}, "
3095 "{\"name\": \"Name4\", \"value\": \"Value4\"}]"
3098 /***************************************************************************/
3099 /* Initialize and provide a specification with a single fault suppressed. */
3100 /***************************************************************************/
3101 evel_throttle_initialize();
3102 handle_json_response(json_command_list, &post);
3104 /***************************************************************************/
3105 /* Check that the domain is throttled. */
3106 /***************************************************************************/
3107 assert(evel_get_throttle_spec(EVEL_DOMAIN_SERVICE) != NULL);
3108 assert(post.memory == NULL);
3110 size_t json_size = 0;
3111 char json_body[EVEL_MAX_JSON_BODY];
3112 EVENT_SERVICE * event = NULL;
3113 evel_set_next_event_sequence(2000);
3114 event = evel_new_service("vendor_x_id", "vendor_x_event_id");
3115 assert(event != NULL);
3116 evel_service_type_set(event, "Service Event");
3117 evel_service_product_id_set(event, "vendor_x_product_id");
3118 evel_service_subsystem_id_set(event, "vendor_x_subsystem_id");
3119 evel_service_friendly_name_set(event, "vendor_x_frieldly_name");
3120 evel_service_correlator_set(event, "vendor_x_correlator");
3121 evel_service_codec_set(event, "PCMA");
3122 evel_service_codec_set(event, "PCMA");
3123 evel_service_callee_codec_set(event, "PCMA");
3124 evel_service_caller_codec_set(event, "G729A");
3125 evel_service_rtcp_data_set(event, "some_rtcp_data");
3126 evel_service_adjacency_name_set(event, "vendor_x_adjacency");
3127 evel_service_endpoint_desc_set(event, EVEL_SERVICE_ENDPOINT_CALLER);
3128 evel_service_endpoint_jitter_set(event, 66);
3129 evel_service_endpoint_rtp_oct_disc_set(event, 100);
3130 evel_service_endpoint_rtp_oct_recv_set(event, 200);
3131 evel_service_endpoint_rtp_oct_sent_set(event, 300);
3132 evel_service_endpoint_rtp_pkt_disc_set(event, 400);
3133 evel_service_endpoint_rtp_pkt_recv_set(event, 500);
3134 evel_service_endpoint_rtp_pkt_sent_set(event, 600);
3135 evel_service_local_jitter_set(event, 99);
3136 evel_service_local_rtp_oct_disc_set(event, 150);
3137 evel_service_local_rtp_oct_recv_set(event, 250);
3138 evel_service_local_rtp_oct_sent_set(event, 350);
3139 evel_service_local_rtp_pkt_disc_set(event, 450);
3140 evel_service_local_rtp_pkt_recv_set(event, 550);
3141 evel_service_local_rtp_pkt_sent_set(event, 650);
3142 evel_service_mos_cqe_set(event, 12.255);
3143 evel_service_packets_lost_set(event, 157);
3144 evel_service_packet_loss_percent_set(event, 0.232);
3145 evel_service_r_factor_set(event, 11);
3146 evel_service_round_trip_delay_set(event, 15);
3147 evel_service_phone_number_set(event, "0888888888");
3148 evel_service_addl_field_add(event, "Name1", "Value1");
3149 evel_service_addl_field_add(event, "Name2", "Value2");
3150 evel_service_addl_field_add(event, "Name3", "Value3");
3151 evel_service_addl_field_add(event, "Name4", "Value4");
3152 json_size = evel_json_encode_event(
3153 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3154 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Service");
3155 assert((json_size == strlen(json_body)) && "Bad size returned");
3157 evel_free_event(event);
3158 evel_throttle_terminate();
3161 void test_encode_signaling_throttled()
3165 /***************************************************************************/
3166 /* We also test suppression of the event header parameters here. */
3167 /***************************************************************************/
3168 char * json_command_list =
3170 "\"commandList\": ["
3173 "\"commandType\": \"throttlingSpecification\", "
3174 "\"eventDomainThrottleSpecification\": {"
3175 "\"eventDomain\": \"signaling\", "
3176 "\"suppressedFieldNames\": ["
3179 "\"reportingEntityId\", "
3181 "\"localIpAddress\", "
3183 "\"remoteIpAddress\", "
3185 "\"compressedSip\", "
3187 "\"suppressedNvPairsList\": ["
3194 "{\"commonEventHeader\": {"
3195 "\"domain\": \"signaling\", "
3196 "\"eventId\": \"2001\", "
3197 "\"functionalRole\": \"UNIT TEST\", "
3198 "\"lastEpochMicrosec\": 1000002, "
3199 "\"priority\": \"Normal\", "
3200 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3201 "\"sequence\": 2001, "
3202 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3203 "\"startEpochMicrosec\": 1000002, "
3206 "\"signalingFields\": {"
3207 "\"eventInstanceIdentifier\": "
3209 "\"vendorId\": \"vendor_x_id\", "
3210 "\"eventId\": \"vendor_x_event_id\", "
3211 "\"productId\": \"vendor_x_product_id\", "
3212 "\"subsystemId\": \"vendor_x_subsystem_id\", "
3213 "\"eventFriendlyName\": \"vendor_x_frieldly_name\""
3215 "\"signalingFieldsVersion\": 1.1"
3218 /***************************************************************************/
3219 /* Initialize and provide a specification with a single fault suppressed. */
3220 /***************************************************************************/
3221 evel_throttle_initialize();
3222 handle_json_response(json_command_list, &post);
3224 /***************************************************************************/
3225 /* Check that the domain is throttled. */
3226 /***************************************************************************/
3227 assert(evel_get_throttle_spec(EVEL_DOMAIN_SIGNALING) != NULL);
3228 assert(post.memory == NULL);
3230 size_t json_size = 0;
3231 char json_body[EVEL_MAX_JSON_BODY];
3232 EVENT_SIGNALING * event = NULL;
3233 evel_set_next_event_sequence(2001);
3234 event = evel_new_signaling("vendor_x_id",
3235 "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
3236 assert(event != NULL);
3237 evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
3238 evel_signaling_vnfname_set(event, "vendor_x_vnf");
3239 evel_signaling_type_set(event, "Signaling");
3240 evel_signaling_product_id_set(event, "vendor_x_product_id");
3241 evel_signaling_subsystem_id_set(event, "vendor_x_subsystem_id");
3242 evel_signaling_friendly_name_set(event, "vendor_x_frieldly_name");
3243 evel_signaling_correlator_set(event, "vendor_x_correlator");
3244 evel_signaling_local_ip_address_set(event, "1.0.3.1");
3245 evel_signaling_local_port_set(event, "1031");
3246 evel_signaling_remote_ip_address_set(event, "5.3.3.0");
3247 evel_signaling_remote_port_set(event, "5330");
3248 evel_signaling_compressed_sip_set(event, "compressed_sip");
3249 evel_signaling_summary_sip_set(event, "summary_sip");
3250 json_size = evel_json_encode_event(
3251 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) event);
3252 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Signaling");
3253 assert((json_size == strlen(json_body)) && "Bad size returned");
3255 evel_free_event(event);
3256 evel_throttle_terminate();
3259 void test_encode_state_change_throttled()
3263 /***************************************************************************/
3264 /* We also test suppression of the event header parameters here. */
3265 /***************************************************************************/
3266 char * json_command_list =
3268 "\"commandList\": ["
3271 "\"commandType\": \"throttlingSpecification\", "
3272 "\"eventDomainThrottleSpecification\": {"
3273 "\"eventDomain\": \"stateChange\", "
3274 "\"suppressedFieldNames\": ["
3276 "\"reportingEntityId\", "
3278 "\"suppressedNvPairsList\": ["
3280 "\"nvPairFieldName\": \"additionalFields\", "
3281 "\"suppressedNvPairNames\": [\"Name1\"]"
3289 "{\"commonEventHeader\": {"
3290 "\"domain\": \"stateChange\", "
3291 "\"eventId\": \"128\", "
3292 "\"functionalRole\": \"UNIT TEST\", "
3293 "\"lastEpochMicrosec\": 1000002, "
3294 "\"priority\": \"Normal\", "
3295 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3296 "\"sequence\": 128, "
3297 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3298 "\"startEpochMicrosec\": 1000002, "
3301 "\"stateChangeFields\": {"
3302 "\"newState\": \"inService\", "
3303 "\"oldState\": \"outOfService\", "
3304 "\"stateInterface\": \"An Interface\", "
3305 "\"additionalFields\": ["
3306 "{\"name\": \"Name2\", "
3307 "\"value\": \"Value2\"}"
3309 "\"stateChangeFieldsVersion\": 1.1"
3312 /***************************************************************************/
3313 /* Initialize and provide a specification with a single fault suppressed. */
3314 /***************************************************************************/
3315 evel_throttle_initialize();
3316 handle_json_response(json_command_list, &post);
3318 /***************************************************************************/
3319 /* Check that the domain is throttled. */
3320 /***************************************************************************/
3321 assert(evel_get_throttle_spec(EVEL_DOMAIN_STATE_CHANGE) != NULL);
3322 assert(post.memory == NULL);
3324 size_t json_size = 0;
3325 char json_body[EVEL_MAX_JSON_BODY];
3326 EVENT_STATE_CHANGE * state_change = NULL;
3327 evel_set_next_event_sequence(128);
3328 state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
3329 EVEL_ENTITY_STATE_OUT_OF_SERVICE,
3331 assert(state_change != NULL);
3332 evel_state_change_type_set(state_change, "SC Type");
3333 evel_state_change_addl_field_add(state_change, "Name1", "Value1");
3334 evel_state_change_addl_field_add(state_change, "Name2", "Value2");
3336 json_size = evel_json_encode_event(
3337 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) state_change);
3338 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "StateChange");
3339 assert((json_size == strlen(json_body)) && "Bad size returned");
3341 evel_free_event(state_change);
3342 evel_throttle_terminate();
3345 void test_encode_syslog_throttled()
3349 /***************************************************************************/
3350 /* We also test suppression of the event header parameters here. */
3351 /***************************************************************************/
3352 char * json_command_list =
3354 "\"commandList\": ["
3357 "\"commandType\": \"throttlingSpecification\", "
3358 "\"eventDomainThrottleSpecification\": {"
3359 "\"eventDomain\": \"syslog\", "
3360 "\"suppressedFieldNames\": ["
3361 "\"eventSourceHost\", "
3362 "\"syslogFacility\", "
3364 "\"syslogProcId\", "
3368 "\"reportingEntityId\", "
3370 "\"suppressedNvPairsList\": ["
3372 "\"nvPairFieldName\": \"additionalFields\", "
3373 "\"suppressedNvPairNames\": [\"Name2\"]"
3381 "{\"commonEventHeader\": {"
3382 "\"domain\": \"syslog\", "
3383 "\"eventId\": \"126\", "
3384 "\"functionalRole\": \"UNIT TEST\", "
3385 "\"lastEpochMicrosec\": 1000002, "
3386 "\"priority\": \"Normal\", "
3387 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3388 "\"sequence\": 126, "
3389 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3390 "\"startEpochMicrosec\": 1000002, "
3393 "\"syslogFields\": {"
3394 "\"eventSourceType\": \"virtualNetworkFunction\", "
3395 "\"syslogMsg\": \"SL Message\", "
3396 "\"syslogTag\": \"SL Tag\", "
3397 "\"syslogFieldsVersion\": 1.1, "
3398 "\"additionalFields\": ["
3399 "{\"name\": \"Name1\", "
3400 "\"value\": \"Value1\"}"
3404 /***************************************************************************/
3405 /* Initialize and provide a specification with a single fault suppressed. */
3406 /***************************************************************************/
3407 evel_throttle_initialize();
3408 handle_json_response(json_command_list, &post);
3410 /***************************************************************************/
3411 /* Check that the domain is throttled. */
3412 /***************************************************************************/
3413 assert(evel_get_throttle_spec(EVEL_DOMAIN_SYSLOG) != NULL);
3414 assert(post.memory == NULL);
3416 size_t json_size = 0;
3417 char json_body[EVEL_MAX_JSON_BODY];
3418 EVENT_SYSLOG * syslog = NULL;
3419 evel_set_next_event_sequence(126);
3420 syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
3423 assert(syslog != NULL);
3424 evel_syslog_type_set(syslog, "SL Type");
3425 evel_syslog_event_source_host_set(syslog, "SL Host");
3426 evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LINE_PRINTER);
3427 evel_syslog_proc_set(syslog, "SL Proc");
3428 evel_syslog_proc_id_set(syslog, 2);
3429 evel_syslog_version_set(syslog, 1);
3430 evel_syslog_s_data_set(syslog, "SL SDATA");
3431 evel_syslog_addl_field_add(syslog, "Name1", "Value1");
3432 evel_syslog_addl_field_add(syslog, "Name2", "Value2");
3434 json_size = evel_json_encode_event(
3435 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) syslog);
3436 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Syslog");
3437 assert((json_size == strlen(json_body)) && "Bad size returned");
3439 evel_free_event(syslog);
3440 evel_throttle_terminate();
3443 void test_encode_fault_with_escaping()
3447 "\"commonEventHeader\": {"
3448 "\"domain\": \"fault\", "
3449 "\"eventId\": \"122\", "
3450 "\"functionalRole\": \"UNIT TEST\", "
3451 "\"lastEpochMicrosec\": 1000002, "
3452 "\"priority\": \"Normal\", "
3453 "\"reportingEntityName\": \"Dummy VM name - No Metadata available\", "
3454 "\"sequence\": 122, "
3455 "\"sourceName\": \"Dummy VM name - No Metadata available\", "
3456 "\"startEpochMicrosec\": 1000002, "
3457 "\"version\": 1.2, "
3458 "\"eventType\": \"Bad things happen...\\\\\", "
3459 "\"reportingEntityId\": \"Dummy VM UUID - No Metadata available\", "
3460 "\"sourceId\": \"Dummy VM UUID - No Metadata available\""
3462 "\"faultFields\": {"
3463 "\"alarmCondition\": \"My alarm condition\", "
3464 "\"eventSeverity\": \"MAJOR\", "
3465 "\"eventSourceType\": \"other\", "
3466 "\"specificProblem\": \"It broke \\\"very\\\" badly\", "
3467 "\"vfStatus\": \"Active\", "
3468 "\"faultFieldsVersion\": 1.1, "
3469 "\"alarmAdditionalInformation\": ["
3470 "{\"name\": \"name1\", "
3471 "\"value\": \"value1\"}, "
3472 "{\"name\": \"name2\", "
3473 "\"value\": \"value2\"}], "
3474 "\"alarmInterfaceA\": \"My Interface Card\""
3477 size_t json_size = 0;
3478 char json_body[EVEL_MAX_JSON_BODY];
3479 evel_set_next_event_sequence(122);
3480 EVENT_FAULT * fault = evel_new_fault("My alarm condition",
3481 "It broke \"very\" badly",
3482 EVEL_PRIORITY_NORMAL,
3483 EVEL_SEVERITY_MAJOR,
3485 EVEL_VF_STATUS_PREP_TERMINATE);
3486 assert(fault != NULL);
3487 evel_fault_type_set(fault, "Bad things happen...\\");
3488 evel_fault_interface_set(fault, "My Interface Card");
3489 evel_fault_addl_info_add(fault, "name1", "value1");
3490 evel_fault_addl_info_add(fault, "name2", "value2");
3492 json_size = evel_json_encode_event(
3493 json_body, EVEL_MAX_JSON_BODY, (EVENT_HEADER *) fault);
3494 compare_strings(expected, json_body, EVEL_MAX_JSON_BODY, "Fault");
3495 assert((json_size == strlen(json_body)) && "Bad size returned");
3497 evel_free_event(fault);