| 705 | } |
| 706 | |
| 707 | CommandResponse L2Forward::CommandPopulate( |
| 708 | const bess::pb::L2ForwardCommandPopulateArg &arg) { |
| 709 | const char *base; |
| 710 | char base_str[6] = {0}; |
| 711 | uint64_t base_u64; |
| 712 | |
| 713 | if (!arg.base().length()) { |
| 714 | return CommandFailure(EINVAL, "base must exist in gen, and must be string"); |
| 715 | } |
| 716 | |
| 717 | // parse base addr |
| 718 | base = arg.base().c_str(); |
| 719 | if (parse_mac_addr(base, base_str) != 0) { |
| 720 | return CommandFailure(EINVAL, "%s is not a proper mac address", base_str); |
| 721 | } |
| 722 | |
| 723 | base_u64 = l2_addr_to_u64(base_str); |
| 724 | |
| 725 | int cnt = arg.count(); |
| 726 | int gate_cnt = arg.gate_count(); |
| 727 | |
| 728 | base_u64 = bess::utils::be64_t::swap(base_u64) >> 16; |
| 729 | base_u64 = base_u64 >> 16; |
| 730 | |
| 731 | for (int i = 0; i < cnt; i++) { |
| 732 | l2_add_entry(&l2_table_, bess::utils::be64_t::swap(base_u64 << 16), |
| 733 | i % gate_cnt); |
| 734 | |
| 735 | base_u64++; |
| 736 | } |
| 737 | |
| 738 | return CommandSuccess(); |
| 739 | } |
| 740 | |
| 741 | ADD_MODULE(L2Forward, "l2_forward", |
| 742 | "classifies packets with destination MAC address") |
nothing calls this directly
no test coverage detected