|
36 | 36 | #include "buffer_dyn_stub.h"
|
37 | 37 | #include "common_functions_stub.h"
|
38 | 38 |
|
| 39 | +static int mcps_data_req_cnt = 0; |
| 40 | +static int mcps_purge_req_cnt = 0; |
| 41 | + |
39 | 42 | static void mcps_data_req_cb(const mac_api_t* api, const mcps_data_req_t *data)
|
40 | 43 | {
|
| 44 | + mcps_data_req_cnt++; |
| 45 | +} |
41 | 46 |
|
| 47 | +static void tester_mcps_purge_request(const mac_api_t* api, |
| 48 | + const mcps_purge_t *data) |
| 49 | +{ |
| 50 | + (void) api; |
| 51 | + (void) data; |
| 52 | + mcps_purge_req_cnt++; |
42 | 53 | }
|
43 | 54 |
|
44 | 55 | bool test_lowpan_adaptation_interface_init()
|
@@ -235,13 +246,6 @@ bool test_lowpan_adapatation_data_process_tx_preprocess()
|
235 | 246 | return true;
|
236 | 247 | }
|
237 | 248 |
|
238 |
| -static void tester_mcps_purge_request(const mac_api_t* api, |
239 |
| - const mcps_purge_t *data) |
240 |
| -{ |
241 |
| - (void) api; |
242 |
| - (void) data; |
243 |
| -} |
244 |
| - |
245 | 249 | bool test_lowpan_adaptation_indirect_purge()
|
246 | 250 | {
|
247 | 251 | mac_api_t api;
|
@@ -552,6 +556,188 @@ bool test_lowpan_adaptation_interface_tx()
|
552 | 556 | return true;
|
553 | 557 | }
|
554 | 558 |
|
| 559 | +bool test_lowpan_adaptation_interface_indirect_tx() |
| 560 | +{ |
| 561 | + mac_api_t api; |
| 562 | + protocol_interface_info_entry_t entry; |
| 563 | + arm_15_4_mac_parameters_t params; |
| 564 | + int data_request_count = mcps_data_req_cnt; |
| 565 | + int data_purge_count = mcps_purge_req_cnt; |
| 566 | + |
| 567 | + params.mac_next_key_index = 1; |
| 568 | + params.mac_channel = 11; |
| 569 | + |
| 570 | + entry.mac_parameters = ¶ms; |
| 571 | + entry.mac_api = &api; |
| 572 | + entry.id = 0; |
| 573 | + |
| 574 | + api.mcps_data_req = &mcps_data_req_cb; |
| 575 | + api.mcps_purge_req = &tester_mcps_purge_request; |
| 576 | + |
| 577 | + buffer_t *test_buf = malloc(sizeof(buffer_t) + 2100); |
| 578 | + memset(test_buf, 0, sizeof(buffer_t) + 2100); |
| 579 | + |
| 580 | + test_buf->dst_sa.addr_type = ADDR_802_15_4_SHORT; |
| 581 | + test_buf->dst_sa.address[0] = 1; |
| 582 | + test_buf->buf_ptr = 10; |
| 583 | + test_buf->buf_end = 210; |
| 584 | + test_buf->link_specific.ieee802_15_4.indirectTxProcess = true; |
| 585 | + buffer_dyn_stub.buffer_ptr = test_buf; |
| 586 | + |
| 587 | + protocol_core_stub.entry_ptr = &entry; |
| 588 | + mle_stub.mle_neigh_table_entry_ptr = NULL; |
| 589 | + |
| 590 | + nsdynmemlib_stub.returnCounter = 1000; |
| 591 | + |
| 592 | + socket_stub.buffer_ptr = NULL; |
| 593 | + |
| 594 | + entry.mac_api = &api; |
| 595 | + api.mcps_data_req = NULL; |
| 596 | + socket_stub.buffer_ptr = NULL; |
| 597 | + |
| 598 | + entry.id = 0; |
| 599 | + api.mcps_data_req = &mcps_data_req_cb; |
| 600 | + |
| 601 | + lowpan_adaptation_interface_init(0, 127); |
| 602 | + |
| 603 | + // Set small and big buffer size to 2 |
| 604 | + if (0 != lowpan_adaptation_indirect_queue_params_set(&entry, 106, 2, 2)) { |
| 605 | + return false; |
| 606 | + } |
| 607 | + |
| 608 | + /* |
| 609 | + * Test#1, |
| 610 | + * Send 3 big packets to one destination and 3 big packets to another |
| 611 | + * destination: |
| 612 | + * Verify that packets are delivered to mac and purging works. |
| 613 | + */ |
| 614 | + |
| 615 | + // first packet will be sent to mac |
| 616 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf)) { |
| 617 | + return false; |
| 618 | + } else if (++data_request_count != mcps_data_req_cnt) { |
| 619 | + // error, no mac request sent |
| 620 | + return false; |
| 621 | + } |
| 622 | + |
| 623 | + // 2nd packet will be cached (no sending/purge) |
| 624 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf)) { |
| 625 | + return false; |
| 626 | + } else if (data_request_count != mcps_data_req_cnt) { |
| 627 | + // error, mac data request sent as it should have been cached |
| 628 | + return false; |
| 629 | + } |
| 630 | + |
| 631 | + // 3rd packet will purge 1st, will sent 2nd packet |
| 632 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf)) { |
| 633 | + return false; |
| 634 | + } else if ((++data_request_count != mcps_data_req_cnt) || |
| 635 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 636 | + // error, either mac request was not sent or purge did not happen |
| 637 | + return false; |
| 638 | + } |
| 639 | + |
| 640 | + // Create buffer for different destination |
| 641 | + buffer_t *test_buf2 = malloc(sizeof(buffer_t) + 2100); |
| 642 | + memset(test_buf2, 0, sizeof(buffer_t) + 2100); |
| 643 | + |
| 644 | + test_buf2->dst_sa.addr_type = ADDR_802_15_4_SHORT; |
| 645 | + test_buf2->dst_sa.address[0] = 2; |
| 646 | + |
| 647 | + test_buf2->link_specific.ieee802_15_4.requestAck = true; |
| 648 | + test_buf2->buf_end = 200; |
| 649 | + test_buf2->link_specific.ieee802_15_4.indirectTxProcess = true; |
| 650 | + |
| 651 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf2)) { |
| 652 | + return false; |
| 653 | + } else if ((++data_request_count != mcps_data_req_cnt) || |
| 654 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 655 | + // error if no previous data purge or no mac request made |
| 656 | + return false; |
| 657 | + } |
| 658 | + |
| 659 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf2)) { |
| 660 | + return false; |
| 661 | + } else if ((data_request_count != mcps_data_req_cnt) || |
| 662 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 663 | + // error if mac data request sent or no purging |
| 664 | + return false; |
| 665 | + } |
| 666 | + |
| 667 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf2)) { |
| 668 | + return false; |
| 669 | + } else if ((++data_request_count != mcps_data_req_cnt) || |
| 670 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 671 | + // error if no mac request and no purge |
| 672 | + return false; |
| 673 | + } |
| 674 | + |
| 675 | + /* |
| 676 | + * Test#2, |
| 677 | + * Send 3 small packets to previous destination |
| 678 | + * Verify that big packets are purged and small packets sent |
| 679 | + */ |
| 680 | + test_buf2->buf_end = 20; |
| 681 | + mle_neigh_table_entry_t mle; |
| 682 | + mle_stub.mle_neigh_table_entry_ptr = &mle; |
| 683 | + // first packet will be sent to mac |
| 684 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf2)) { |
| 685 | + return false; |
| 686 | + } else if ((++data_request_count != mcps_data_req_cnt) && |
| 687 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 688 | + // error if no data request not made or purging didn't happen |
| 689 | + return false; |
| 690 | + } |
| 691 | + |
| 692 | + // 2nd packet will be cached (no sending/purge) |
| 693 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf2)) { |
| 694 | + return false; |
| 695 | + } else if ((++data_request_count != mcps_data_req_cnt) && |
| 696 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 697 | + // error if no data request not made or purging didn't happen |
| 698 | + return false; |
| 699 | + } |
| 700 | + |
| 701 | + // 3rd packet will purge 1st, will sent 2nd packet |
| 702 | + if (0 != lowpan_adaptation_interface_tx(&entry, test_buf2)) { |
| 703 | + return false; |
| 704 | + } else if ((++data_request_count != mcps_data_req_cnt) && |
| 705 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 706 | + // error if no data request not made or purging didn't happen |
| 707 | + return false; |
| 708 | + } |
| 709 | + |
| 710 | + /* |
| 711 | + * Test #3, |
| 712 | + * Confirm data request |
| 713 | + */ |
| 714 | + mcps_data_conf_t data_confirm; |
| 715 | + data_confirm.msduHandle = test_buf2->seq; |
| 716 | + data_confirm.status = MLME_SUCCESS; |
| 717 | + if (0 != lowpan_adaptation_interface_tx_confirm(&entry, &data_confirm)) { |
| 718 | + return false; |
| 719 | + } else if ((++data_request_count != mcps_data_req_cnt) && |
| 720 | + (++data_purge_count != mcps_purge_req_cnt)) { |
| 721 | + // error if no data request not made or purging didn't happen |
| 722 | + return false; |
| 723 | + } |
| 724 | + |
| 725 | + data_confirm.status = MLME_SUCCESS; |
| 726 | + if (0 != lowpan_adaptation_interface_tx_confirm(&entry, &data_confirm)) { |
| 727 | + return false; |
| 728 | + } else if ((data_request_count != mcps_data_req_cnt) && |
| 729 | + (data_purge_count != mcps_purge_req_cnt)) { |
| 730 | + // error if no data request is made or purge happens |
| 731 | + return false; |
| 732 | + } |
| 733 | + |
| 734 | + lowpan_adaptation_interface_free(0); |
| 735 | + nsdynmemlib_stub.returnCounter = 0; |
| 736 | + free(test_buf); |
| 737 | + free(test_buf2); |
| 738 | + return true; |
| 739 | +} |
| 740 | + |
555 | 741 | bool test_lowpan_adaptation_interface_tx_confirm()
|
556 | 742 | {
|
557 | 743 | mac_api_t api;
|
|
0 commit comments