[
  {
    "path": ".gitignore",
    "content": "*.ll\n*.o\n*.pyc\n*.swp\nrss\nxdpdump\ntmp_bpftool.txt\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"libbpf\"]\n\tpath = libbpf\n\turl = https://github.com/libbpf/libbpf.git\n"
  },
  {
    "path": "COPYING",
    "content": "                    The BSD 2-Clause License\n\nCopyright (C) 2018 Netronome Systems, Inc.\n\n    Redistribution and use in source and binary forms, with or\n    without modification, are permitted provided that the following\n    conditions are met:\n\n     1. Redistributions of source code must retain the above\n        copyright notice, this list of conditions and the following\n        disclaimer.\n\n     2. Redistributions in binary form must reproduce the above\n        copyright notice, this list of conditions and the following\n        disclaimer in the documentation and/or other materials\n        provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n                    GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.,\n 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Lesser General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n                            NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.\n"
  },
  {
    "path": "README.rst",
    "content": ".. SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n\nXDP Demo Apps\n=============\n\nTesting XDP, on software and on hardware\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis repository contains eBPF XDP demo applications.\n\nMost demos can be run on XDP compatible drivers or hardware. Each subdirectory\nprovides instructions for loading the programs in “driver” and/or in “offload”\nmode. “Driver mode” loads the XDP program into the kernel where the processing\nis carried out by the host CPU, whilst “offloaded XDP” allows for the program\nto be run on hardware, such as with the Netronome Agilio® CX SmartNIC.\n\nTo enable XDP offload on a Agilio CX, please refer to `Netronome eBPF user guides`_.\n\n.. _Netronome eBPF user guides: https://help.netronome.com/support/solutions/folders/36000172266\n\nList of available demos\n~~~~~~~~~~~~~~~~~~~~~~~\n\nThe sources for each demo are located in a specific subdirectory.\n\n======================== ===============\nApplication              Kernel Required\n======================== ===============\n`Layer 4 Load Balancer`_     4.17\n`Programmable RSS`_          4.18\n`xdpdump`_                   4.18\n======================== ===============\n\n.. _Layer 4 Load Balancer: l4lb/\n.. _Programmable RSS: programmable_rss/\n.. _xdpdump: xdpdump/\n\nlibbpf\n~~~~~~\n\nThe ``libbpf`` directory is a git submodule and contains libraries required for\ncompiling the samples. To obtain the submodule content, the following git\nclone command is required:\n\n git clone --recurse-submodules https://github.com/Netronome/bpf-samples.git\n\nNotes\n~~~~~\n\n- These applications are prototypes and are not suitable for production use.\n"
  },
  {
    "path": "headers/bpf_endian.h",
    "content": "/* SPDX-License-Identifier: GPL-2.0 */\n/* Copied from $(LINUX)/tools/testing/selftests/bpf/bpf_endian.h */\n#ifndef __BPF_ENDIAN__\n#define __BPF_ENDIAN__\n\n#include <linux/swab.h>\n\n/* LLVM's BPF target selects the endianness of the CPU\n * it compiles on, or the user specifies (bpfel/bpfeb),\n * respectively. The used __BYTE_ORDER__ is defined by\n * the compiler, we cannot rely on __BYTE_ORDER from\n * libc headers, since it doesn't reflect the actual\n * requested byte order.\n *\n * Note, LLVM's BPF target has different __builtin_bswapX()\n * semantics. It does map to BPF_ALU | BPF_END | BPF_TO_BE\n * in bpfel and bpfeb case, which means below, that we map\n * to cpu_to_be16(). We could use it unconditionally in BPF\n * case, but better not rely on it, so that this header here\n * can be used from application and BPF program side, which\n * use different targets.\n */\n#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\n# define __bpf_ntohs(x)__builtin_bswap16(x)\n# define __bpf_htons(x)__builtin_bswap16(x)\n# define __bpf_constant_ntohs(x)___constant_swab16(x)\n# define __bpf_constant_htons(x)___constant_swab16(x)\n# define __bpf_ntohl(x)__builtin_bswap32(x)\n# define __bpf_htonl(x)__builtin_bswap32(x)\n# define __bpf_constant_ntohl(x)___constant_swab32(x)\n# define __bpf_constant_htonl(x)___constant_swab32(x)\n#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__\n# define __bpf_ntohs(x)(x)\n# define __bpf_htons(x)(x)\n# define __bpf_constant_ntohs(x)(x)\n# define __bpf_constant_htons(x)(x)\n# define __bpf_ntohl(x)(x)\n# define __bpf_htonl(x)(x)\n# define __bpf_constant_ntohl(x)(x)\n# define __bpf_constant_htonl(x)(x)\n#else\n# error \"Fix your compiler's __BYTE_ORDER__?!\"\n#endif\n\n#define bpf_htons(x)\\\n  (__builtin_constant_p(x) ?\\\n   __bpf_constant_htons(x) : __bpf_htons(x))\n#define bpf_ntohs(x)\\\n  (__builtin_constant_p(x) ?\\\n   __bpf_constant_ntohs(x) : __bpf_ntohs(x))\n#define bpf_htonl(x)\\\n  (__builtin_constant_p(x) ?\\\n   __bpf_constant_htonl(x) : __bpf_htonl(x))\n#define bpf_ntohl(x)\\\n  (__builtin_constant_p(x) ?\\\n   __bpf_constant_ntohl(x) : __bpf_ntohl(x))\n\n#endif /* __BPF_ENDIAN__ */\n"
  },
  {
    "path": "headers/bpf_helpers.h",
    "content": "/* SPDX-License-Identifier: GPL-2.0 */\n/* Copied from $(LINUX)/tools/testing/selftests/bpf/bpf_helpers.h */\n#ifndef __BPF_HELPERS_H\n#define __BPF_HELPERS_H\n\n/* helper macro to place programs, maps, license in\n * different sections in elf_bpf file. Section names\n * are interpreted by elf_bpf loader\n */\n#define SEC(NAME) __attribute__((section(NAME), used))\n\n/* helper functions called from eBPF programs written in C */\nstatic void *(*bpf_map_lookup_elem)(void *map, void *key) =\n\t(void *) BPF_FUNC_map_lookup_elem;\nstatic int (*bpf_map_update_elem)(void *map, void *key, void *value,\n\t\t\t\t  unsigned long long flags) =\n\t(void *) BPF_FUNC_map_update_elem;\nstatic int (*bpf_map_delete_elem)(void *map, void *key) =\n\t(void *) BPF_FUNC_map_delete_elem;\nstatic int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =\n\t(void *) BPF_FUNC_probe_read;\nstatic unsigned long long (*bpf_ktime_get_ns)(void) =\n\t(void *) BPF_FUNC_ktime_get_ns;\nstatic int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =\n\t(void *) BPF_FUNC_trace_printk;\nstatic void (*bpf_tail_call)(void *ctx, void *map, int index) =\n\t(void *) BPF_FUNC_tail_call;\nstatic unsigned long long (*bpf_get_smp_processor_id)(void) =\n\t(void *) BPF_FUNC_get_smp_processor_id;\nstatic unsigned long long (*bpf_get_current_pid_tgid)(void) =\n\t(void *) BPF_FUNC_get_current_pid_tgid;\nstatic unsigned long long (*bpf_get_current_uid_gid)(void) =\n\t(void *) BPF_FUNC_get_current_uid_gid;\nstatic int (*bpf_get_current_comm)(void *buf, int buf_size) =\n\t(void *) BPF_FUNC_get_current_comm;\nstatic unsigned long long (*bpf_perf_event_read)(void *map,\n\t\t\t\t\t\t unsigned long long flags) =\n\t(void *) BPF_FUNC_perf_event_read;\nstatic int (*bpf_clone_redirect)(void *ctx, int ifindex, int flags) =\n\t(void *) BPF_FUNC_clone_redirect;\nstatic int (*bpf_redirect)(int ifindex, int flags) =\n\t(void *) BPF_FUNC_redirect;\nstatic int (*bpf_perf_event_output)(void *ctx, void *map,\n\t\t\t\t    unsigned long long flags, void *data,\n\t\t\t\t    int size) =\n\t(void *) BPF_FUNC_perf_event_output;\nstatic int (*bpf_get_stackid)(void *ctx, void *map, int flags) =\n\t(void *) BPF_FUNC_get_stackid;\nstatic int (*bpf_probe_write_user)(void *dst, void *src, int size) =\n\t(void *) BPF_FUNC_probe_write_user;\nstatic int (*bpf_current_task_under_cgroup)(void *map, int index) =\n\t(void *) BPF_FUNC_current_task_under_cgroup;\nstatic int (*bpf_skb_get_tunnel_key)(void *ctx, void *key, int size, int flags) =\n\t(void *) BPF_FUNC_skb_get_tunnel_key;\nstatic int (*bpf_skb_set_tunnel_key)(void *ctx, void *key, int size, int flags) =\n\t(void *) BPF_FUNC_skb_set_tunnel_key;\nstatic int (*bpf_skb_get_tunnel_opt)(void *ctx, void *md, int size) =\n\t(void *) BPF_FUNC_skb_get_tunnel_opt;\nstatic int (*bpf_skb_set_tunnel_opt)(void *ctx, void *md, int size) =\n\t(void *) BPF_FUNC_skb_set_tunnel_opt;\nstatic unsigned long long (*bpf_get_prandom_u32)(void) =\n\t(void *) BPF_FUNC_get_prandom_u32;\nstatic int (*bpf_xdp_adjust_head)(void *ctx, int offset) =\n\t(void *) BPF_FUNC_xdp_adjust_head;\n\n/* llvm builtin functions that eBPF C program may use to\n * emit BPF_LD_ABS and BPF_LD_IND instructions\n */\nstruct sk_buff;\nunsigned long long load_byte(void *skb,\n\t\t\t     unsigned long long off) asm(\"llvm.bpf.load.byte\");\nunsigned long long load_half(void *skb,\n\t\t\t     unsigned long long off) asm(\"llvm.bpf.load.half\");\nunsigned long long load_word(void *skb,\n\t\t\t     unsigned long long off) asm(\"llvm.bpf.load.word\");\n\n/* a helper structure used by eBPF C program\n * to describe map attributes to elf_bpf loader\n */\nstruct bpf_map_def {\n\tunsigned int type;\n\tunsigned int key_size;\n\tunsigned int value_size;\n\tunsigned int max_entries;\n\tunsigned int map_flags;\n\tunsigned int inner_map_idx;\n};\n\nstatic int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =\n\t(void *) BPF_FUNC_skb_load_bytes;\nstatic int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =\n\t(void *) BPF_FUNC_skb_store_bytes;\nstatic int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) =\n\t(void *) BPF_FUNC_l3_csum_replace;\nstatic int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) =\n\t(void *) BPF_FUNC_l4_csum_replace;\nstatic int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =\n\t(void *) BPF_FUNC_skb_under_cgroup;\nstatic int (*bpf_skb_change_head)(void *, int len, int flags) =\n\t(void *) BPF_FUNC_skb_change_head;\n\n#if defined(__x86_64__)\n\n#define PT_REGS_PARM1(x) ((x)->di)\n#define PT_REGS_PARM2(x) ((x)->si)\n#define PT_REGS_PARM3(x) ((x)->dx)\n#define PT_REGS_PARM4(x) ((x)->cx)\n#define PT_REGS_PARM5(x) ((x)->r8)\n#define PT_REGS_RET(x) ((x)->sp)\n#define PT_REGS_FP(x) ((x)->bp)\n#define PT_REGS_RC(x) ((x)->ax)\n#define PT_REGS_SP(x) ((x)->sp)\n#define PT_REGS_IP(x) ((x)->ip)\n\n#elif defined(__s390x__)\n\n#define PT_REGS_PARM1(x) ((x)->gprs[2])\n#define PT_REGS_PARM2(x) ((x)->gprs[3])\n#define PT_REGS_PARM3(x) ((x)->gprs[4])\n#define PT_REGS_PARM4(x) ((x)->gprs[5])\n#define PT_REGS_PARM5(x) ((x)->gprs[6])\n#define PT_REGS_RET(x) ((x)->gprs[14])\n#define PT_REGS_FP(x) ((x)->gprs[11]) /* Works only with CONFIG_FRAME_POINTER */\n#define PT_REGS_RC(x) ((x)->gprs[2])\n#define PT_REGS_SP(x) ((x)->gprs[15])\n#define PT_REGS_IP(x) ((x)->psw.addr)\n\n#elif defined(__aarch64__)\n\n#define PT_REGS_PARM1(x) ((x)->regs[0])\n#define PT_REGS_PARM2(x) ((x)->regs[1])\n#define PT_REGS_PARM3(x) ((x)->regs[2])\n#define PT_REGS_PARM4(x) ((x)->regs[3])\n#define PT_REGS_PARM5(x) ((x)->regs[4])\n#define PT_REGS_RET(x) ((x)->regs[30])\n#define PT_REGS_FP(x) ((x)->regs[29]) /* Works only with CONFIG_FRAME_POINTER */\n#define PT_REGS_RC(x) ((x)->regs[0])\n#define PT_REGS_SP(x) ((x)->sp)\n#define PT_REGS_IP(x) ((x)->pc)\n\n#elif defined(__powerpc__)\n\n#define PT_REGS_PARM1(x) ((x)->gpr[3])\n#define PT_REGS_PARM2(x) ((x)->gpr[4])\n#define PT_REGS_PARM3(x) ((x)->gpr[5])\n#define PT_REGS_PARM4(x) ((x)->gpr[6])\n#define PT_REGS_PARM5(x) ((x)->gpr[7])\n#define PT_REGS_RC(x) ((x)->gpr[3])\n#define PT_REGS_SP(x) ((x)->sp)\n#define PT_REGS_IP(x) ((x)->nip)\n\n#elif defined(__sparc__)\n\n#define PT_REGS_PARM1(x) ((x)->u_regs[UREG_I0])\n#define PT_REGS_PARM2(x) ((x)->u_regs[UREG_I1])\n#define PT_REGS_PARM3(x) ((x)->u_regs[UREG_I2])\n#define PT_REGS_PARM4(x) ((x)->u_regs[UREG_I3])\n#define PT_REGS_PARM5(x) ((x)->u_regs[UREG_I4])\n#define PT_REGS_RET(x) ((x)->u_regs[UREG_I7])\n#define PT_REGS_RC(x) ((x)->u_regs[UREG_I0])\n#define PT_REGS_SP(x) ((x)->u_regs[UREG_FP])\n#if defined(__arch64__)\n#define PT_REGS_IP(x) ((x)->tpc)\n#else\n#define PT_REGS_IP(x) ((x)->pc)\n#endif\n\n#endif\n\n#ifdef __powerpc__\n#define BPF_KPROBE_READ_RET_IP(ip, ctx)\t\t({ (ip) = (ctx)->link; })\n#define BPF_KRETPROBE_READ_RET_IP\t\tBPF_KPROBE_READ_RET_IP\n#elif defined(__sparc__)\n#define BPF_KPROBE_READ_RET_IP(ip, ctx)\t\t({ (ip) = PT_REGS_RET(ctx); })\n#define BPF_KRETPROBE_READ_RET_IP\t\tBPF_KPROBE_READ_RET_IP\n#else\n#define BPF_KPROBE_READ_RET_IP(ip, ctx)\t\t({\t\t\t\t\\\n\t\tbpf_probe_read(&(ip), sizeof(ip), (void *)PT_REGS_RET(ctx)); })\n#define BPF_KRETPROBE_READ_RET_IP(ip, ctx)\t({\t\t\t\t\\\n\t\tbpf_probe_read(&(ip), sizeof(ip),\t\t\t\t\\\n\t\t\t\t(void *)(PT_REGS_FP(ctx) + sizeof(ip))); })\n#endif\n\n#endif\n"
  },
  {
    "path": "headers/jhash.h",
    "content": "#ifndef _LINUX_JHASH_H\n#define _LINUX_JHASH_H\n\n/* Copied from $(LINUX)/include/linux/jhash.h (kernel 4.18) */\n\n/* jhash.h: Jenkins hash support.\n *\n * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)\n *\n * http://burtleburtle.net/bob/hash/\n *\n * These are the credits from Bob's sources:\n *\n * lookup3.c, by Bob Jenkins, May 2006, Public Domain.\n *\n * These are functions for producing 32-bit hashes for hash table lookup.\n * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()\n * are externally useful functions.  Routines to test the hash are included\n * if SELF_TEST is defined.  You can use this free for any purpose.  It's in\n * the public domain.  It has no warranty.\n *\n * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)\n */\n\nstatic inline __u32 rol32(__u32 word, unsigned int shift)\n{\n\treturn (word << shift) | (word >> ((-shift) & 31));\n}\n\n/* copy paste of jhash from kernel sources (include/linux/jhash.h) to make sure\n * LLVM can compile it into valid sequence of BPF instructions\n */\n#define __jhash_mix(a, b, c)\t\t\t\\\n{\t\t\t\t\t\t\\\n\ta -= c;  a ^= rol32(c, 4);  c += b;\t\\\n\tb -= a;  b ^= rol32(a, 6);  a += c;\t\\\n\tc -= b;  c ^= rol32(b, 8);  b += a;\t\\\n\ta -= c;  a ^= rol32(c, 16); c += b;\t\\\n\tb -= a;  b ^= rol32(a, 19); a += c;\t\\\n\tc -= b;  c ^= rol32(b, 4);  b += a;\t\\\n}\n\n#define __jhash_final(a, b, c)\t\t\t\\\n{\t\t\t\t\t\t\\\n\tc ^= b; c -= rol32(b, 14);\t\t\\\n\ta ^= c; a -= rol32(c, 11);\t\t\\\n\tb ^= a; b -= rol32(a, 25);\t\t\\\n\tc ^= b; c -= rol32(b, 16);\t\t\\\n\ta ^= c; a -= rol32(c, 4);\t\t\\\n\tb ^= a; b -= rol32(a, 14);\t\t\\\n\tc ^= b; c -= rol32(b, 24);\t\t\\\n}\n\n#define JHASH_INITVAL\t\t0xdeadbeef\n\ntypedef unsigned int u32;\n\n/* jhash - hash an arbitrary key\n * @k: sequence of bytes as key\n * @length: the length of the key\n * @initval: the previous hash, or an arbitray value\n *\n * The generic version, hashes an arbitrary sequence of bytes.\n * No alignment or length assumptions are made about the input key.\n *\n * Returns the hash value of the key. The result depends on endianness.\n */\nstatic inline u32 jhash(const void *key, u32 length, u32 initval)\n{\n\tu32 a, b, c;\n\tconst unsigned char *k = key;\n\n\t/* Set up the internal state */\n\ta = b = c = JHASH_INITVAL + length + initval;\n\n\t/* All but the last block: affect some 32 bits of (a,b,c) */\n\twhile (length > 12) {\n\t\ta += *(u32 *)(k);\n\t\tb += *(u32 *)(k + 4);\n\t\tc += *(u32 *)(k + 8);\n\t\t__jhash_mix(a, b, c);\n\t\tlength -= 12;\n\t\tk += 12;\n\t}\n\t/* Last block: affect all 32 bits of (c) */\n\tswitch (length) {\n\tcase 12: c += (u32)k[11]<<24;\t/* fall through */\n\tcase 11: c += (u32)k[10]<<16;\t/* fall through */\n\tcase 10: c += (u32)k[9]<<8;\t/* fall through */\n\tcase 9:  c += k[8];\t\t/* fall through */\n\tcase 8:  b += (u32)k[7]<<24;\t/* fall through */\n\tcase 7:  b += (u32)k[6]<<16;\t/* fall through */\n\tcase 6:  b += (u32)k[5]<<8;\t/* fall through */\n\tcase 5:  b += k[4];\t\t/* fall through */\n\tcase 4:  a += (u32)k[3]<<24;\t/* fall through */\n\tcase 3:  a += (u32)k[2]<<16;\t/* fall through */\n\tcase 2:  a += (u32)k[1]<<8;\t/* fall through */\n\tcase 1:  a += k[0];\n\t\t __jhash_final(a, b, c);\n\tcase 0: /* Nothing left to add */\n\t\tbreak;\n\t}\n\n\treturn c;\n}\n\n/* jhash2 - hash an array of u32's\n * @k: the key which must be an array of u32's\n * @length: the number of u32's in the key\n * @initval: the previous hash, or an arbitray value\n *\n * Returns the hash value of the key.\n */\nstatic inline u32 jhash2(const u32 *k, u32 length, u32 initval)\n{\n\tu32 a, b, c;\n\n\t/* Set up the internal state */\n\ta = b = c = JHASH_INITVAL + (length<<2) + initval;\n\n\t/* Handle most of the key */\n\twhile (length > 3) {\n\t\ta += k[0];\n\t\tb += k[1];\n\t\tc += k[2];\n\t\t__jhash_mix(a, b, c);\n\t\tlength -= 3;\n\t\tk += 3;\n\t}\n\n\t/* Handle the last 3 u32's */\n\tswitch (length) {\n\tcase 3: c += k[2];\t/* fall through */\n\tcase 2: b += k[1];\t/* fall through */\n\tcase 1: a += k[0];\n\t\t__jhash_final(a, b, c);\n\tcase 0:\t/* Nothing left to add */\n\t\tbreak;\n\t}\n\n\treturn c;\n}\n\n\n/* __jhash_nwords - hash exactly 3, 2 or 1 word(s) */\nstatic inline u32 __jhash_nwords(u32 a, u32 b, u32 c, u32 initval)\n{\n\ta += initval;\n\tb += initval;\n\tc += initval;\n\n\t__jhash_final(a, b, c);\n\n\treturn c;\n}\n\nstatic inline u32 jhash_3words(u32 a, u32 b, u32 c, u32 initval)\n{\n\treturn __jhash_nwords(a, b, c, initval + JHASH_INITVAL + (3 << 2));\n}\n\nstatic inline u32 jhash_2words(u32 a, u32 b, u32 initval)\n{\n\treturn __jhash_nwords(a, b, 0, initval + JHASH_INITVAL + (2 << 2));\n}\n\nstatic inline u32 jhash_1word(u32 a, u32 initval)\n{\n\treturn __jhash_nwords(a, 0, 0, initval + JHASH_INITVAL + (1 << 2));\n}\n\n#endif /* _LINUX_JHASH_H */\n"
  },
  {
    "path": "headers/perf-sys.h",
    "content": "/* SPDX-License-Identifier: GPL-2.0 */\n/* Copied from $(LINUX)/tools/perf/perf-sys.h (kernel 4.18) */\n#ifndef _PERF_SYS_H\n#define _PERF_SYS_H\n\n#include <unistd.h>\n#include <sys/types.h>\n#include <sys/syscall.h>\n#include <linux/types.h>\n#include <linux/perf_event.h>\n/*\n * remove the following headers to allow for userspace program compilation\n * #include <linux/compiler.h>\n * #include <asm/barrier.h>\n */\n#ifdef __powerpc__\n#define CPUINFO_PROC\t{\"cpu\"}\n#endif\n\n#ifdef __s390__\n#define CPUINFO_PROC\t{\"vendor_id\"}\n#endif\n\n#ifdef __sh__\n#define CPUINFO_PROC\t{\"cpu type\"}\n#endif\n\n#ifdef __hppa__\n#define CPUINFO_PROC\t{\"cpu\"}\n#endif\n\n#ifdef __sparc__\n#define CPUINFO_PROC\t{\"cpu\"}\n#endif\n\n#ifdef __alpha__\n#define CPUINFO_PROC\t{\"cpu model\"}\n#endif\n\n#ifdef __arm__\n#define CPUINFO_PROC\t{\"model name\", \"Processor\"}\n#endif\n\n#ifdef __mips__\n#define CPUINFO_PROC\t{\"cpu model\"}\n#endif\n\n#ifdef __arc__\n#define CPUINFO_PROC\t{\"Processor\"}\n#endif\n\n#ifdef __xtensa__\n#define CPUINFO_PROC\t{\"core ID\"}\n#endif\n\n#ifndef CPUINFO_PROC\n#define CPUINFO_PROC\t{ \"model name\", }\n#endif\n\nstatic inline int\nsys_perf_event_open(struct perf_event_attr *attr,\n\t\t      pid_t pid, int cpu, int group_fd,\n\t\t      unsigned long flags)\n{\n\tint fd;\n\n\tfd = syscall(__NR_perf_event_open, attr, pid, cpu,\n\t\t     group_fd, flags);\n\n#ifdef HAVE_ATTR_TEST\n\tif (unlikely(test_attr__enabled))\n\t\ttest_attr__open(attr, pid, cpu, fd, group_fd, flags);\n#endif\n\treturn fd;\n}\n\n#endif /* _PERF_SYS_H */\n"
  },
  {
    "path": "l4lb/Makefile",
    "content": "# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n\nLLVM_VERSION ?=\nLLVM := $(shell clang$(LLVM_VERSION) --version)\nCLANG_FLAGS ?= -W -Wall \\\n\t-Wno-compare-distinct-pointer-types\n\nSRCS=$(wildcard *.c)\nOBJS=$(patsubst %.c,%.o,$(SRCS))\nQ ?= @\n\nINCLUDE_DIRS ?= -I../headers/\n\n%.o: %.c\n\t@echo \"\\tLLVM CC $@\"\n\t$(Q) clang$(LLVM_VERSION) $(INCLUDE_DIRS) -O2 -emit-llvm -c $< $(CLANG_FLAGS) -o $(patsubst %.o,%.llvm,$@)\n\t$(Q) llc$(LLVM_VERSION) -march=bpf -filetype=obj -o $@ $(patsubst %.o,%.llvm,$@)\n\t$(Q) rm $(patsubst %.o,%.llvm,$@)\n\nifeq ($(LLVM),)\nall:\n\t$(warning Install LLVM to compile BPF sources)\nelse\nall: $(OBJS)\nendif\n\nclean:\n\trm -f *.llvm\n\trm -f *.o\n\n.PHONY: all clean\n"
  },
  {
    "path": "l4lb/README.rst",
    "content": "Layer 4 Load Balancer Demo\n==========================\n\nThis program will demonstrate how a XDP load balancer can be used to distribute\nincoming traffic by hashing the layer 3 and layer 4 headers.\n\nThe XDP program, will process incoming network packets and compute a hash\nbased on the sender IP address, along with the TCP or UDP network ports.\nThis hash value is subsequently used as the key for a eBPF map.\n\nThe eBPF map is filled with the available servers to which the XDP program can\nredirect the packet to. The XDP program will extend and insert an outer IP\nheader with this map data. After processing, the program will subsequently\nsend the packet back out of the network interface to the destination server.\n\nThe map fill and stats scripts are written in python and utilize bpftool to\nshowcase how a program can be deployed using iproute2 and bpftool utilities.\n\nMinimum Requirements for Demo\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n- Linux kernel 4.17\n- iproute2 v4.16.0 (a.k.a ss180402)\n- clang / LLVM 4.0\n- bpftool\n- Python 3\n- Agilio® eBPF firmware (only for HW offload) - July 2018\n  (available from `Netronome's support website`_)\n\n.. _Netronome's support website: https://help.netronome.com/\n\nLoading the Demo\n~~~~~~~~~~~~~~~~\n\nTo compile the XDP program ::\n\n $ make\n\nThe program can be loaded using iproute2 using the following commands\n\nXDP driver mode ::\n\n # ip link set dev { DEV } xdpdrv obj l4lb_xdp.o sec xdp\n\nXDP offload ::\n\n # ip link set dev { DEV } xdpoffload obj l4lb_xdp.o sec xdp\n\nThe load balancer map can be filled with the l4lb_map.py script. Note that\nsample files with lists of destinations are provided under\n`destination_samples/`_ ::\n\n # ./l4lb_map.py -i { DEV } -f { file containing destinations }\n\nTraffic statistics may be seen using the l4lb_stats.py script ::\n\n # ./l4lb_stats.py -i { DEV }\n\n.. _destination_samples/: destination_samples/\n\nTraffic Generation\n~~~~~~~~~~~~~~~~~~\n\nTraffic can be generated using a variety of tools. A command is shown below\nwhich utilises the hping3 utility to generate the traffic. The command should\nbe run on a different host connected to the server running the eBPF l4lb\nprogram. In this example the traffic generator uses interface ens0 and is\ntransmitting traffic to IP address 10.0.0.4 ::\n\n hping3 10.0.0.4 --rand-source -i ens0 --flood\n\nExample\n~~~~~~~\n\nTo demo the program on offload mode on interface ens4np0, with 32 destinations ::\n\n # ip link set dev ens4np0 xdpoffload obj l4lb_xdp.o sec xdp\n  Note: 12 bytes struct bpf_elf_map fixup performed due to size mismatch!\n\n # ./l4lb_map.py -i ens4np0 -f destination_samples/32_destinations.csv\n  Loading file with 32 destinations\n\n # ./l4lb_stats.py -i ens4np0\n  == Load balancer outbound statistics [Offload] ==\n\n     1\t10.0.0.57      \t   1,029,744 pkts/s\t  1,186,266,224 bits/s\n     2\t10.0.125.19    \t   1,031,841 pkts/s\t  1,188,681,760 bits/s\n     3\t10.0.129.60    \t   1,033,649 pkts/s\t  1,190,763,984 bits/s\n     4\t10.0.14.88     \t   1,031,274 pkts/s\t  1,188,028,704 bits/s\n     5\t10.0.143.99    \t   1,032,110 pkts/s\t  1,188,991,816 bits/s\n     6\t10.0.159.176   \t   1,031,466 pkts/s\t  1,188,249,616 bits/s\n     7\t10.0.16.109    \t   1,031,213 pkts/s\t  1,187,957,968 bits/s\n     8\t10.0.161.129   \t   1,031,025 pkts/s\t  1,187,740,928 bits/s\n     9\t10.0.175.130   \t   1,032,664 pkts/s\t  1,189,629,368 bits/s\n    10\t10.0.178.75    \t   1,032,625 pkts/s\t  1,189,584,800 bits/s\n    11\t10.0.181.34    \t   1,031,332 pkts/s\t  1,188,094,584 bits/s\n    12\t10.0.185.52    \t   1,033,361 pkts/s\t  1,190,432,608 bits/s\n    13\t10.0.192.32    \t   1,032,855 pkts/s\t  1,189,849,312 bits/s\n    14\t10.0.199.54    \t   1,032,126 pkts/s\t  1,189,009,256 bits/s\n    15\t10.0.214.65    \t   1,032,921 pkts/s\t  1,189,925,864 bits/s\n    16\t10.0.23.41     \t   1,033,084 pkts/s\t  1,190,112,864 bits/s\n    17\t10.0.234.48    \t   1,031,888 pkts/s\t  1,188,735,048 bits/s\n    18\t10.0.24.77     \t   1,031,594 pkts/s\t  1,188,396,896 bits/s\n    19\t10.0.244.158   \t   1,031,127 pkts/s\t  1,187,859,136 bits/s\n    20\t10.0.31.144    \t   1,032,068 pkts/s\t  1,188,942,400 bits/s\n    21\t10.0.32.134    \t   1,031,787 pkts/s\t  1,188,619,744 bits/s\n    22\t10.0.32.35     \t   1,031,222 pkts/s\t  1,187,968,624 bits/s\n    23\t10.0.50.179    \t   1,031,597 pkts/s\t  1,188,400,768 bits/s\n    24\t10.0.56.49     \t   1,032,840 pkts/s\t  1,189,831,872 bits/s\n    25\t10.0.63.10     \t   1,031,564 pkts/s\t  1,188,362,008 bits/s\n    26\t10.0.75.126    \t   1,032,512 pkts/s\t  1,189,454,960 bits/s\n    27\t10.0.75.197    \t   1,030,993 pkts/s\t  1,187,705,080 bits/s\n    28\t10.0.75.209    \t   1,033,445 pkts/s\t  1,190,529,504 bits/s\n    29\t10.0.89.127    \t   1,033,593 pkts/s\t  1,190,700,032 bits/s\n    30\t10.0.90.135    \t   1,031,819 pkts/s\t  1,188,655,600 bits/s\n    31\t10.0.90.214    \t   1,032,841 pkts/s\t  1,189,832,848 bits/s\n    32\t10.0.92.11     \t   1,032,581 pkts/s\t  1,189,534,416 bits/s\n\n  [Totals]\t\t  33,026,761 pkts/s\t 38,046,848,592 bits/s\n\nNote: This example was produced with a high performance traffic generator,\nlower rates are expected with hping3.\n\nRemoving the Demo\n~~~~~~~~~~~~~~~~\n\nXDP driver mode ::\n\n# ip link set dev { DEV } xdpdrv off\n\nXDP offload ::\n\n# ip link set dev { DEV } xdpoffload off\n"
  },
  {
    "path": "l4lb/bpftool_utils.py",
    "content": "#!/usr/bin/env python3\n# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n# Copyright (c) 2018 Netronome Systems, Inc.\n\nimport json\nimport subprocess\nimport struct\nimport sys\n\ndef check_output_json(cmd):\n    return json.loads(subprocess.check_output(cmd, shell=True).decode(\"utf-8\"))\n\ndef get_xdp_prog(interface):\n    cmd_iplink = 'ip -j link show %s' % interface\n    iplink = check_output_json(cmd_iplink)\n    return iplink[0]['xdp']['prog']['id']\n\ndef get_map_ids(interface):\n    prog_id = get_xdp_prog(interface)\n    cmd_progshow = 'bpftool prog show id %d -p' % prog_id\n    prog_info = check_output_json(cmd_progshow)\n\n    maps = check_output_json('bpftool map -p')\n    map_ids = []\n\n    for m in maps:\n            if m['id'] in prog_info['map_ids']:\n                    map_ids.append(m['id'])\n    return map_ids\n\ndef get_map_entries(map_id):\n    cmd_mapshow = 'bpftool map show id %s -p' % map_id\n    map_info = check_output_json(cmd_mapshow)\n    return map_info['max_entries']\n\ndef get_map_dev(map_id):\n    cmd_mapshow = 'bpftool map show id %s -p' % map_id\n    map_info = check_output_json(cmd_mapshow)\n\n    if \"dev\" in map_info:\n        return \"Offload\"\n    else:\n        return \"Driver\"\n\ndef dump_map(map_id):\n    cmd_map = 'bpftool map dump id %s -p' % map_id\n    return check_output_json(cmd_map)\n\ndef hex_list_to_int(hex_list):\n    hex_str = ''.join([byte.replace('0x', '') for byte in hex_list])\n    return (int.from_bytes(bytes.fromhex(hex_str), byteorder='little'))\n"
  },
  {
    "path": "l4lb/destination_samples/128_destinations.csv",
    "content": "10.0.88.205, 00:15:4d:58:cd:73\n10.0.18.70, 00:15:4d:12:46:fd\n10.0.195.112, 00:15:4d:c3:70:25\n10.0.78.90, 00:15:4d:4e:5a:71\n10.0.163.40, 00:15:4d:a3:28:8f\n10.0.73.36, 00:15:4d:49:24:22\n10.0.84.187, 00:15:4d:54:bb:24\n10.0.91.5, 00:15:4d:5b:05:c4\n10.0.94.163, 00:15:4d:5e:a3:8f\n10.0.107.139, 00:15:4d:6b:8b:b3\n10.0.62.8, 00:15:4d:3e:08:5b\n10.0.167.5, 00:15:4d:a7:05:6a\n10.0.95.82, 00:15:4d:5f:52:15\n10.0.103.166, 00:15:4d:67:a6:1b\n10.0.130.78, 00:15:4d:82:4e:d3\n10.0.160.22, 00:15:4d:a0:16:15\n10.0.26.39, 00:15:4d:1a:27:ba\n10.0.28.178, 00:15:4d:1c:b2:a7\n10.0.61.219, 00:15:4d:3d:db:e1\n10.0.136.80, 00:15:4d:88:50:7b\n10.0.143.131, 00:15:4d:8f:83:43\n10.0.59.23, 00:15:4d:3b:17:ce\n10.0.33.220, 00:15:4d:21:dc:45\n10.0.115.238, 00:15:4d:73:ee:78\n10.0.94.5, 00:15:4d:5e:05:7d\n10.0.169.254, 00:15:4d:a9:fe:fa\n10.0.67.201, 00:15:4d:43:c9:a2\n10.0.179.40, 00:15:4d:b3:28:64\n10.0.178.157, 00:15:4d:b2:9d:bd\n10.0.234.135, 00:15:4d:ea:87:f6\n10.0.215.81, 00:15:4d:d7:51:a3\n10.0.204.92, 00:15:4d:cc:5c:6a\n10.0.2.126, 00:15:4d:02:7e:0c\n10.0.233.124, 00:15:4d:e9:7c:fe\n10.0.249.99, 00:15:4d:f9:63:14\n10.0.74.62, 00:15:4d:4a:3e:e6\n10.0.240.222, 00:15:4d:f0:de:c9\n10.0.215.184, 00:15:4d:d7:b8:59\n10.0.126.211, 00:15:4d:7e:d3:f9\n10.0.75.224, 00:15:4d:4b:e0:83\n10.0.63.180, 00:15:4d:3f:b4:33\n10.0.146.203, 00:15:4d:92:cb:70\n10.0.49.18, 00:15:4d:31:12:b6\n10.0.103.246, 00:15:4d:67:f6:73\n10.0.213.88, 00:15:4d:d5:58:5f\n10.0.237.180, 00:15:4d:ed:b4:c0\n10.0.5.222, 00:15:4d:05:de:6e\n10.0.200.90, 00:15:4d:c8:5a:c3\n10.0.98.151, 00:15:4d:62:97:bd\n10.0.24.54, 00:15:4d:18:36:45\n10.0.26.187, 00:15:4d:1a:bb:a2\n10.0.125.254, 00:15:4d:7d:fe:92\n10.0.197.161, 00:15:4d:c5:a1:b9\n10.0.140.219, 00:15:4d:8c:db:aa\n10.0.150.216, 00:15:4d:96:d8:f2\n10.0.244.207, 00:15:4d:f4:cf:c6\n10.0.111.29, 00:15:4d:6f:1d:0c\n10.0.118.29, 00:15:4d:76:1d:e1\n10.0.166.72, 00:15:4d:a6:48:9e\n10.0.186.225, 00:15:4d:ba:e1:46\n10.0.165.164, 00:15:4d:a5:a4:59\n10.0.155.148, 00:15:4d:9b:94:ab\n10.0.27.97, 00:15:4d:1b:61:8e\n10.0.94.250, 00:15:4d:5e:fa:53\n10.0.251.119, 00:15:4d:fb:77:83\n10.0.53.117, 00:15:4d:35:75:1b\n10.0.50.29, 00:15:4d:32:1d:df\n10.0.221.217, 00:15:4d:dd:d9:48\n10.0.43.49, 00:15:4d:2b:31:ea\n10.0.46.83, 00:15:4d:2e:53:44\n10.0.84.51, 00:15:4d:54:33:c9\n10.0.79.91, 00:15:4d:4f:5b:03\n10.0.50.159, 00:15:4d:32:9f:76\n10.0.108.221, 00:15:4d:6c:dd:54\n10.0.113.222, 00:15:4d:71:de:39\n10.0.9.3, 00:15:4d:09:03:6b\n10.0.39.182, 00:15:4d:27:b6:f1\n10.0.240.28, 00:15:4d:f0:1c:56\n10.0.234.128, 00:15:4d:ea:80:e7\n10.0.188.84, 00:15:4d:bc:54:34\n10.0.107.88, 00:15:4d:6b:58:28\n10.0.124.246, 00:15:4d:7c:f6:20\n10.0.12.20, 00:15:4d:0c:14:4e\n10.0.224.183, 00:15:4d:e0:b7:e4\n10.0.34.66, 00:15:4d:22:42:97\n10.0.67.128, 00:15:4d:43:80:1e\n10.0.63.198, 00:15:4d:3f:c6:84\n10.0.11.128, 00:15:4d:0b:80:0b\n10.0.241.166, 00:15:4d:f1:a6:f5\n10.0.250.72, 00:15:4d:fa:48:73\n10.0.22.29, 00:15:4d:16:1d:bc\n10.0.181.193, 00:15:4d:b5:c1:87\n10.0.92.78, 00:15:4d:5c:4e:ee\n10.0.95.136, 00:15:4d:5f:88:a9\n10.0.90.99, 00:15:4d:5a:63:f8\n10.0.148.153, 00:15:4d:94:99:c9\n10.0.93.121, 00:15:4d:5d:79:0f\n10.0.163.157, 00:15:4d:a3:9d:50\n10.0.95.55, 00:15:4d:5f:37:1f\n10.0.32.37, 00:15:4d:20:25:1f\n10.0.10.129, 00:15:4d:0a:81:6b\n10.0.125.0, 00:15:4d:7d:00:64\n10.0.90.54, 00:15:4d:5a:36:2b\n10.0.90.92, 00:15:4d:5a:5c:65\n10.0.186.52, 00:15:4d:ba:34:12\n10.0.226.220, 00:15:4d:e2:dc:37\n10.0.11.231, 00:15:4d:0b:e7:73\n10.0.158.164, 00:15:4d:9e:a4:23\n10.0.56.200, 00:15:4d:38:c8:90\n10.0.201.210, 00:15:4d:c9:d2:e0\n10.0.107.116, 00:15:4d:6b:74:3c\n10.0.117.250, 00:15:4d:75:fa:30\n10.0.57.172, 00:15:4d:39:ac:b7\n10.0.222.139, 00:15:4d:de:8b:19\n10.0.13.222, 00:15:4d:0d:de:06\n10.0.179.42, 00:15:4d:b3:2a:66\n10.0.223.214, 00:15:4d:df:d6:9c\n10.0.238.67, 00:15:4d:ee:43:df\n10.0.234.248, 00:15:4d:ea:f8:48\n10.0.106.113, 00:15:4d:6a:71:a6\n10.0.2.228, 00:15:4d:02:e4:81\n10.0.48.179, 00:15:4d:30:b3:bb\n10.0.179.135, 00:15:4d:b3:87:64\n10.0.249.63, 00:15:4d:f9:3f:8b\n10.0.27.194, 00:15:4d:1b:c2:14\n10.0.68.55, 00:15:4d:44:37:d0\n10.0.20.7, 00:15:4d:14:07:8c\n10.0.134.42, 00:15:4d:86:2a:97\n"
  },
  {
    "path": "l4lb/destination_samples/256_destinations.csv",
    "content": "10.0.128.192, 00:15:4d:80:c0:f1\n10.0.96.178, 00:15:4d:60:b2:77\n10.0.239.127, 00:15:4d:ef:7f:12\n10.0.211.136, 00:15:4d:d3:88:b0\n10.0.55.164, 00:15:4d:37:a4:34\n10.0.189.181, 00:15:4d:bd:b5:ed\n10.0.87.208, 00:15:4d:57:d0:d4\n10.0.32.185, 00:15:4d:20:b9:ed\n10.0.166.207, 00:15:4d:a6:cf:c8\n10.0.11.243, 00:15:4d:0b:f3:7e\n10.0.88.196, 00:15:4d:58:c4:cf\n10.0.154.213, 00:15:4d:9a:d5:10\n10.0.7.163, 00:15:4d:07:a3:86\n10.0.160.228, 00:15:4d:a0:e4:f4\n10.0.76.250, 00:15:4d:4c:fa:38\n10.0.46.174, 00:15:4d:2e:ae:cf\n10.0.40.103, 00:15:4d:28:67:72\n10.0.198.22, 00:15:4d:c6:16:72\n10.0.25.200, 00:15:4d:19:c8:7f\n10.0.219.121, 00:15:4d:db:79:67\n10.0.202.8, 00:15:4d:ca:08:12\n10.0.177.221, 00:15:4d:b1:dd:4f\n10.0.146.225, 00:15:4d:92:e1:87\n10.0.33.182, 00:15:4d:21:b6:67\n10.0.5.40, 00:15:4d:05:28:96\n10.0.167.116, 00:15:4d:a7:74:86\n10.0.72.188, 00:15:4d:48:bc:c9\n10.0.20.135, 00:15:4d:14:87:73\n10.0.82.123, 00:15:4d:52:7b:7e\n10.0.244.235, 00:15:4d:f4:eb:a1\n10.0.6.154, 00:15:4d:06:9a:6b\n10.0.69.98, 00:15:4d:45:62:19\n10.0.54.169, 00:15:4d:36:a9:0d\n10.0.0.14, 00:15:4d:00:0e:71\n10.0.45.244, 00:15:4d:2d:f4:5c\n10.0.109.138, 00:15:4d:6d:8a:a0\n10.0.38.41, 00:15:4d:26:29:bb\n10.0.158.7, 00:15:4d:9e:07:f7\n10.0.43.23, 00:15:4d:2b:17:60\n10.0.124.78, 00:15:4d:7c:4e:30\n10.0.139.197, 00:15:4d:8b:c5:1d\n10.0.144.16, 00:15:4d:90:10:89\n10.0.187.199, 00:15:4d:bb:c7:65\n10.0.72.66, 00:15:4d:48:42:bd\n10.0.68.224, 00:15:4d:44:e0:04\n10.0.138.44, 00:15:4d:8a:2c:e4\n10.0.214.119, 00:15:4d:d6:77:80\n10.0.126.135, 00:15:4d:7e:87:5c\n10.0.232.141, 00:15:4d:e8:8d:13\n10.0.192.72, 00:15:4d:c0:48:e7\n10.0.223.209, 00:15:4d:df:d1:6b\n10.0.10.140, 00:15:4d:0a:8c:04\n10.0.152.163, 00:15:4d:98:a3:df\n10.0.230.94, 00:15:4d:e6:5e:95\n10.0.82.48, 00:15:4d:52:30:ec\n10.0.217.198, 00:15:4d:d9:c6:35\n10.0.11.61, 00:15:4d:0b:3d:f8\n10.0.206.111, 00:15:4d:ce:6f:82\n10.0.192.56, 00:15:4d:c0:38:91\n10.0.33.205, 00:15:4d:21:cd:7d\n10.0.232.230, 00:15:4d:e8:e6:07\n10.0.71.148, 00:15:4d:47:94:60\n10.0.172.38, 00:15:4d:ac:26:83\n10.0.81.78, 00:15:4d:51:4e:d1\n10.0.52.216, 00:15:4d:34:d8:20\n10.0.102.62, 00:15:4d:66:3e:8e\n10.0.102.83, 00:15:4d:66:53:aa\n10.0.131.31, 00:15:4d:83:1f:26\n10.0.87.161, 00:15:4d:57:a1:2d\n10.0.63.138, 00:15:4d:3f:8a:99\n10.0.151.7, 00:15:4d:97:07:16\n10.0.194.195, 00:15:4d:c2:c3:9a\n10.0.53.62, 00:15:4d:35:3e:79\n10.0.253.245, 00:15:4d:fd:f5:5f\n10.0.47.229, 00:15:4d:2f:e5:cb\n10.0.209.139, 00:15:4d:d1:8b:44\n10.0.24.212, 00:15:4d:18:d4:78\n10.0.130.236, 00:15:4d:82:ec:da\n10.0.168.214, 00:15:4d:a8:d6:15\n10.0.92.44, 00:15:4d:5c:2c:dc\n10.0.237.23, 00:15:4d:ed:17:80\n10.0.232.87, 00:15:4d:e8:57:ad\n10.0.14.93, 00:15:4d:0e:5d:34\n10.0.32.144, 00:15:4d:20:90:34\n10.0.137.63, 00:15:4d:89:3f:61\n10.0.198.84, 00:15:4d:c6:54:4f\n10.0.233.119, 00:15:4d:e9:77:a5\n10.0.102.71, 00:15:4d:66:47:58\n10.0.52.238, 00:15:4d:34:ee:2d\n10.0.22.167, 00:15:4d:16:a7:8c\n10.0.66.62, 00:15:4d:42:3e:57\n10.0.228.217, 00:15:4d:e4:d9:4b\n10.0.187.180, 00:15:4d:bb:b4:49\n10.0.127.118, 00:15:4d:7f:9e:0a\n10.0.249.242, 00:15:4d:f9:f2:ac\n10.0.91.117, 00:15:4d:5b:75:67\n10.0.113.105, 00:15:4d:71:69:b0\n10.0.122.65, 00:15:4d:7a:41:b9\n10.0.128.99, 00:15:4d:80:63:15\n10.0.120.15, 00:15:4d:78:0f:6b\n10.0.193.21, 00:15:4d:c1:15:7d\n10.0.238.226, 00:15:4d:ee:e2:b6\n10.0.15.155, 00:15:4d:0f:9b:92\n10.0.70.112, 00:15:4d:46:70:85\n10.0.183.249, 00:15:4d:b7:f9:3f\n10.0.19.39, 00:15:4d:13:27:e0\n10.0.192.234, 00:15:4d:c0:ea:40\n10.0.2.130, 00:15:4d:02:82:17\n10.0.213.214, 00:15:4d:d5:d6:be\n10.0.221.60, 00:15:4d:dd:3c:bd\n10.0.124.225, 00:15:4d:7c:e1:75\n10.0.17.29, 00:15:4d:11:1d:01\n10.0.27.105, 00:15:4d:1b:69:6a\n10.0.57.226, 00:15:4d:39:e2:7e\n10.0.217.250, 00:15:4d:d9:fa:5c\n10.0.111.82, 00:15:4d:6f:52:cd\n10.0.126.126, 00:15:4d:7e:7e:34\n10.0.20.130, 00:15:4d:14:82:17\n10.0.87.156, 00:15:4d:57:9c:a1\n10.0.207.63, 00:15:4d:cf:3f:c0\n10.0.121.65, 00:15:4d:79:41:c4\n10.0.149.155, 00:15:4d:95:9b:c4\n10.0.19.174, 00:15:4d:13:ae:27\n10.0.132.129, 00:15:4d:84:81:f6\n10.0.92.248, 00:15:4d:5c:f8:8a\n10.0.28.5, 00:15:4d:1c:05:8d\n10.0.140.124, 00:15:4d:8c:7c:89\n10.0.6.6, 00:15:4d:06:06:3c\n10.0.70.136, 00:15:4d:46:88:67\n10.0.203.195, 00:15:4d:cb:c3:95\n10.0.230.202, 00:15:4d:e6:ca:c9\n10.0.90.47, 00:15:4d:5a:2f:96\n10.0.89.179, 00:15:4d:59:b3:b8\n10.0.161.13, 00:15:4d:a1:0d:a7\n10.0.0.208, 00:15:4d:00:d0:89\n10.0.155.69, 00:15:4d:9b:45:b5\n10.0.165.214, 00:15:4d:a5:d6:c1\n10.0.35.186, 00:15:4d:23:ba:49\n10.0.97.127, 00:15:4d:61:7f:76\n10.0.136.252, 00:15:4d:88:fc:75\n10.0.96.125, 00:15:4d:60:7d:0c\n10.0.121.36, 00:15:4d:79:24:6f\n10.0.37.187, 00:15:4d:25:bb:b5\n10.0.4.6, 00:15:4d:04:06:b3\n10.0.245.164, 00:15:4d:f5:a4:64\n10.0.239.210, 00:15:4d:ef:d2:2e\n10.0.55.27, 00:15:4d:37:1b:28\n10.0.86.174, 00:15:4d:56:ae:79\n10.0.134.50, 00:15:4d:86:32:e0\n10.0.101.204, 00:15:4d:65:cc:83\n10.0.237.57, 00:15:4d:ed:39:4f\n10.0.57.209, 00:15:4d:39:d1:ce\n10.0.146.250, 00:15:4d:92:fa:a3\n10.0.119.232, 00:15:4d:77:e8:9d\n10.0.85.15, 00:15:4d:55:0f:19\n10.0.180.61, 00:15:4d:b4:3d:7a\n10.0.146.83, 00:15:4d:92:53:ca\n10.0.166.74, 00:15:4d:a6:4a:91\n10.0.216.47, 00:15:4d:d8:2f:aa\n10.0.168.1, 00:15:4d:a8:01:cf\n10.0.230.23, 00:15:4d:e6:17:31\n10.0.160.173, 00:15:4d:a0:ad:cf\n10.0.199.92, 00:15:4d:c7:5c:0d\n10.0.172.117, 00:15:4d:ac:75:7b\n10.0.222.145, 00:15:4d:de:91:d4\n10.0.202.187, 00:15:4d:ca:bb:8d\n10.0.58.144, 00:15:4d:3a:90:55\n10.0.127.158, 00:15:4d:7f:9e:a2\n10.0.103.252, 00:15:4d:67:fc:c9\n10.0.236.159, 00:15:4d:ec:9f:9c\n10.0.21.75, 00:15:4d:15:4b:4a\n10.0.84.174, 00:15:4d:54:ae:89\n10.0.237.211, 00:15:4d:ed:d3:97\n10.0.42.215, 00:15:4d:2a:d7:a2\n10.0.161.77, 00:15:4d:a1:4d:15\n10.0.200.22, 00:15:4d:c8:16:c9\n10.0.225.119, 00:15:4d:e1:77:cc\n10.0.191.81, 00:15:4d:bf:51:be\n10.0.216.179, 00:15:4d:d8:b3:29\n10.0.93.76, 00:15:4d:5d:4c:6f\n10.0.169.90, 00:15:4d:a9:5a:85\n10.0.64.189, 00:15:4d:40:bd:3d\n10.0.91.155, 00:15:4d:5b:9b:67\n10.0.78.130, 00:15:4d:4e:82:5d\n10.0.33.95, 00:15:4d:21:5f:fd\n10.0.126.140, 00:15:4d:7e:8c:3b\n10.0.21.67, 00:15:4d:15:43:7b\n10.0.221.142, 00:15:4d:dd:8e:2c\n10.0.169.5, 00:15:4d:a9:05:67\n10.0.167.45, 00:15:4d:a7:2d:78\n10.0.160.190, 00:15:4d:a0:be:7a\n10.0.234.5, 00:15:4d:ea:05:4e\n10.0.84.135, 00:15:4d:54:87:50\n10.0.184.95, 00:15:4d:b8:5f:bb\n10.0.165.206, 00:15:4d:a5:ce:43\n10.0.199.194, 00:15:4d:c7:c2:25\n10.0.27.212, 00:15:4d:1b:d4:4b\n10.0.200.251, 00:15:4d:c8:fb:a3\n10.0.205.148, 00:15:4d:cd:94:b6\n10.0.1.126, 00:15:4d:01:7e:4b\n10.0.3.62, 00:15:4d:03:3e:37\n10.0.218.217, 00:15:4d:da:d9:7b\n10.0.198.133, 00:15:4d:c6:85:49\n10.0.16.236, 00:15:4d:10:ec:30\n10.0.234.222, 00:15:4d:ea:de:b2\n10.0.253.132, 00:15:4d:fd:84:f5\n10.0.132.30, 00:15:4d:84:1e:9f\n10.0.143.171, 00:15:4d:8f:ab:03\n10.0.71.83, 00:15:4d:47:53:c6\n10.0.58.71, 00:15:4d:3a:47:46\n10.0.233.90, 00:15:4d:e9:5a:5d\n10.0.189.106, 00:15:4d:bd:6a:0c\n10.0.121.16, 00:15:4d:79:10:78\n10.0.128.90, 00:15:4d:80:5a:c9\n10.0.58.48, 00:15:4d:3a:30:bc\n10.0.57.73, 00:15:4d:39:49:c5\n10.0.108.135, 00:15:4d:6c:87:c0\n10.0.196.63, 00:15:4d:c4:3f:82\n10.0.1.107, 00:15:4d:01:6b:50\n10.0.57.28, 00:15:4d:39:1c:b4\n10.0.188.212, 00:15:4d:bc:d4:d1\n10.0.165.35, 00:15:4d:a5:23:77\n10.0.25.98, 00:15:4d:19:62:c1\n10.0.189.132, 00:15:4d:bd:84:84\n10.0.104.132, 00:15:4d:68:84:bd\n10.0.86.48, 00:15:4d:56:30:10\n10.0.21.186, 00:15:4d:15:ba:d5\n10.0.169.205, 00:15:4d:a9:cd:5c\n10.0.163.38, 00:15:4d:a3:26:65\n10.0.46.226, 00:15:4d:2e:e2:00\n10.0.77.208, 00:15:4d:4d:d0:96\n10.0.103.157, 00:15:4d:67:9d:de\n10.0.168.42, 00:15:4d:a8:2a:e9\n10.0.28.203, 00:15:4d:1c:cb:17\n10.0.169.159, 00:15:4d:a9:9f:f2\n10.0.83.227, 00:15:4d:53:e3:4a\n10.0.102.227, 00:15:4d:66:e3:37\n10.0.177.228, 00:15:4d:b1:e4:d5\n10.0.150.123, 00:15:4d:96:7b:ec\n10.0.178.155, 00:15:4d:b2:9b:84\n10.0.136.160, 00:15:4d:88:a0:fe\n10.0.124.147, 00:15:4d:7c:93:b8\n10.0.252.201, 00:15:4d:fc:c9:be\n10.0.126.29, 00:15:4d:7e:1d:0c\n10.0.146.116, 00:15:4d:92:74:22\n10.0.164.177, 00:15:4d:a4:b1:ef\n10.0.114.234, 00:15:4d:72:ea:83\n10.0.226.20, 00:15:4d:e2:14:c4\n10.0.28.135, 00:15:4d:1c:87:54\n10.0.182.104, 00:15:4d:b6:68:7b\n10.0.101.8, 00:15:4d:65:08:af\n10.0.86.119, 00:15:4d:56:77:4a\n10.0.159.173, 00:15:4d:9f:ad:ee\n10.0.153.183, 00:15:4d:99:b7:ac\n10.0.91.173, 00:15:4d:5b:ad:04\n10.0.230.48, 00:15:4d:e6:30:86\n"
  },
  {
    "path": "l4lb/destination_samples/32_destinations.csv",
    "content": "10.0.89.127, 00:15:4d:59:7f:ad\n10.0.214.65, 00:15:4d:d6:41:bd\n10.0.178.75, 00:15:4d:b2:4b:c8\n10.0.24.77, 00:15:4d:18:4d:d8\n10.0.199.54, 00:15:4d:c7:36:9f\n10.0.234.48, 00:15:4d:ea:30:28\n10.0.175.130, 00:15:4d:af:82:8c\n10.0.244.158, 00:15:4d:f4:9e:b3\n10.0.185.52, 00:15:4d:b9:34:6d\n10.0.159.176, 00:15:4d:9f:b0:37\n10.0.125.19, 00:15:4d:7d:13:9f\n10.0.56.49, 00:15:4d:38:31:6f\n10.0.75.197, 00:15:4d:4b:c5:1f\n10.0.75.209, 00:15:4d:4b:d1:a9\n10.0.92.11, 00:15:4d:5c:0b:d3\n10.0.31.144, 00:15:4d:1f:90:cb\n10.0.32.134, 00:15:4d:20:86:6c\n10.0.50.179, 00:15:4d:32:b3:09\n10.0.0.57, 00:15:4d:00:39:c4\n10.0.16.109, 00:15:4d:10:6d:cf\n10.0.192.32, 00:15:4d:c0:20:d2\n10.0.90.135, 00:15:4d:5a:87:1e\n10.0.75.126, 00:15:4d:4b:7e:c4\n10.0.63.10, 00:15:4d:3f:0a:ae\n10.0.161.129, 00:15:4d:a1:81:9f\n10.0.129.60, 00:15:4d:81:3c:5e\n10.0.143.99, 00:15:4d:8f:63:5c\n10.0.32.35, 00:15:4d:20:23:a7\n10.0.14.88, 00:15:4d:0e:58:7a\n10.0.23.41, 00:15:4d:17:29:ae\n10.0.90.214, 00:15:4d:5a:d6:d0\n10.0.181.34, 00:15:4d:b5:22:c3\n"
  },
  {
    "path": "l4lb/destination_samples/512_destinations.csv",
    "content": "10.0.212.70, 00:15:4d:d4:46:8f\n10.0.47.219, 00:15:4d:2f:db:39\n10.0.68.55, 00:15:4d:44:37:3d\n10.0.214.11, 00:15:4d:d6:0b:f3\n10.0.160.168, 00:15:4d:a0:a8:b0\n10.0.106.197, 00:15:4d:6a:c5:04\n10.0.250.85, 00:15:4d:fa:55:37\n10.0.207.173, 00:15:4d:cf:ad:f0\n10.0.56.197, 00:15:4d:38:c5:8a\n10.0.226.152, 00:15:4d:e2:98:e1\n10.0.58.44, 00:15:4d:3a:2c:f5\n10.0.229.45, 00:15:4d:e5:2d:0d\n10.0.187.142, 00:15:4d:bb:8e:64\n10.0.24.34, 00:15:4d:18:22:4f\n10.0.166.54, 00:15:4d:a6:36:ae\n10.0.93.206, 00:15:4d:5d:ce:db\n10.0.231.249, 00:15:4d:e7:f9:1f\n10.0.65.76, 00:15:4d:41:4c:26\n10.0.15.234, 00:15:4d:0f:ea:c3\n10.0.230.55, 00:15:4d:e6:37:15\n10.0.136.86, 00:15:4d:88:56:03\n10.0.148.53, 00:15:4d:94:35:2f\n10.0.183.116, 00:15:4d:b7:74:16\n10.0.180.50, 00:15:4d:b4:32:33\n10.0.254.80, 00:15:4d:fe:50:28\n10.0.233.102, 00:15:4d:e9:66:26\n10.0.102.227, 00:15:4d:66:e3:67\n10.0.113.54, 00:15:4d:71:36:c4\n10.0.40.225, 00:15:4d:2b:e1:86\n10.0.88.87, 00:15:4d:58:57:67\n10.0.175.163, 00:15:4d:af:a3:e5\n10.0.9.218, 00:15:4d:09:da:d5\n10.0.40.86, 00:15:4d:28:56:cf\n10.0.75.65, 00:15:4d:4b:41:df\n10.0.250.93, 00:15:4d:fa:5d:c8\n10.0.56.38, 00:15:4d:38:26:4c\n10.0.206.8, 00:15:4d:ce:08:a6\n10.0.196.245, 00:15:4d:c4:f5:0d\n10.0.186.51, 00:15:4d:ba:33:9e\n10.0.145.16, 00:15:4d:91:10:4e\n10.0.186.6, 00:15:4d:ba:06:41\n10.0.72.74, 00:15:4d:48:4a:95\n10.0.88.233, 00:15:4d:58:e9:40\n10.0.170.57, 00:15:4d:aa:39:19\n10.0.174.71, 00:15:4d:ae:47:83\n10.0.205.107, 00:15:4d:cd:6b:ca\n10.0.167.246, 00:15:4d:a7:f6:ed\n10.0.174.232, 00:15:4d:ae:e8:2b\n10.0.168.32, 00:15:4d:a8:20:53\n10.0.224.43, 00:15:4d:e0:2b:c7\n10.0.93.164, 00:15:4d:5d:a4:8f\n10.0.158.161, 00:15:4d:9e:a1:32\n10.0.181.253, 00:15:4d:b5:fd:fc\n10.0.207.193, 00:15:4d:cf:c1:d1\n10.0.156.0, 00:15:4d:9c:00:95\n10.0.120.164, 00:15:4d:78:a6:04\n10.0.165.105, 00:15:4d:a5:69:9d\n10.0.145.130, 00:15:4d:91:82:26\n10.0.171.20, 00:15:4d:ab:14:9f\n10.0.68.20, 00:15:4d:44:14:bd\n10.0.82.179, 00:15:4d:52:b3:32\n10.0.248.39, 00:15:4d:f8:27:2d\n10.0.168.14, 00:15:4d:a8:0e:66\n10.0.195.102, 00:15:4d:c3:66:c8\n10.0.165.167, 00:15:4d:a5:a7:39\n10.0.176.113, 00:15:4d:b0:71:f8\n10.0.120.227, 00:15:4d:78:e3:0b\n10.0.219.90, 00:15:4d:db:5a:7e\n10.0.178.140, 00:15:4d:b2:8c:40\n10.0.59.79, 00:15:4d:3b:4f:44\n10.0.158.189, 00:15:4d:9e:bd:d3\n10.0.40.70, 00:15:4d:28:46:34\n10.0.225.152, 00:15:4d:e1:98:a9\n10.0.36.165, 00:15:4d:24:a5:82\n10.0.94.93, 00:15:4d:5e:5d:15\n10.0.83.128, 00:15:4d:53:80:4f\n10.0.76.13, 00:15:4d:4c:0d:ec\n10.0.118.86, 00:15:4d:76:56:f4\n10.0.176.235, 00:15:4d:b0:eb:75\n10.0.188.233, 00:15:4d:bc:e9:d8\n10.0.202.241, 00:15:4d:ca:f1:ee\n10.0.37.168, 00:15:4d:25:a8:1f\n10.0.195.176, 00:15:4d:c3:b0:59\n10.0.65.57, 00:15:4d:41:39:f6\n10.0.221.4, 00:15:4d:dd:04:44\n10.0.44.138, 00:15:4d:2c:8a:39\n10.0.142.65, 00:15:4d:8e:41:43\n10.0.88.84, 00:15:4d:58:54:bd\n10.0.163.174, 00:15:4d:a3:ae:5a\n10.0.199.94, 00:15:4d:c7:5e:9e\n10.0.219.201, 00:15:4d:db:c9:3e\n10.0.26.231, 00:15:4d:1a:e7:12\n10.0.43.225, 00:15:4d:2b:e1:73\n10.0.160.35, 00:15:4d:a0:23:fe\n10.0.92.199, 00:15:4d:5c:c7:9d\n10.0.120.114, 00:15:4d:78:72:46\n10.0.253.62, 00:15:4d:fd:3e:dd\n10.0.135.200, 00:15:4d:87:c8:4e\n10.0.92.114, 00:15:4d:5c:72:8e\n10.0.219.222, 00:15:4d:db:de:92\n10.0.154.138, 00:15:4d:9a:8a:b3\n10.0.167.68, 00:15:4d:a7:44:8a\n10.0.231.143, 00:15:4d:e7:8f:c3\n10.0.237.28, 00:15:4d:ed:1c:eb\n10.0.226.243, 00:15:4d:e2:f3:60\n10.0.8.3, 00:15:4d:08:03:b8\n10.0.52.35, 00:15:4d:34:23:c0\n10.0.175.212, 00:15:4d:af:d4:84\n10.0.184.67, 00:15:4d:b8:43:33\n10.0.147.13, 00:15:4d:93:0d:36\n10.0.222.50, 00:15:4d:de:32:69\n10.0.1.222, 00:15:4d:01:de:bb\n10.0.74.63, 00:15:4d:4a:3f:bd\n10.0.194.127, 00:15:4d:c2:7f:b4\n10.0.99.66, 00:15:4d:63:42:df\n10.0.10.74, 00:15:4d:0a:4a:b7\n10.0.253.143, 00:15:4d:fd:8f:b1\n10.0.44.2, 00:15:4d:2c:02:cd\n10.0.3.250, 00:15:4d:03:fe:13\n10.0.114.169, 00:15:4d:72:a9:1c\n10.0.133.177, 00:15:4d:85:b1:2b\n10.0.189.77, 00:15:4d:bd:4d:fd\n10.0.239.11, 00:15:4d:ef:0b:8a\n10.0.203.91, 00:15:4d:cb:5b:f9\n10.0.185.3, 00:15:4d:b9:03:55\n10.0.251.239, 00:15:4d:fb:ef:fb\n10.0.236.208, 00:15:4d:ec:d0:7a\n10.0.231.78, 00:15:4d:e7:4e:a1\n10.0.185.48, 00:15:4d:b9:30:88\n10.0.62.14, 00:15:4d:3e:0e:fa\n10.0.14.18, 00:15:4d:0e:12:8e\n10.0.206.174, 00:15:4d:ce:ae:6b\n10.0.26.17, 00:15:4d:1a:11:62\n10.0.77.101, 00:15:4d:4d:65:d6\n10.0.112.140, 00:15:4d:70:8c:4a\n10.0.219.48, 00:15:4d:db:30:19\n10.0.132.137, 00:15:4d:84:89:13\n10.0.19.129, 00:15:4d:13:81:39\n10.0.190.195, 00:15:4d:be:c3:2e\n10.0.123.113, 00:15:4d:7b:71:ae\n10.0.113.176, 00:15:4d:71:b0:24\n10.0.171.218, 00:15:4d:ab:da:de\n10.0.120.166, 00:15:4d:78:a6:6c\n10.0.76.254, 00:15:4d:4c:fe:5e\n10.0.38.73, 00:15:4d:26:49:c5\n10.0.86.85, 00:15:4d:56:55:52\n10.0.19.189, 00:15:4d:13:bd:8f\n10.0.55.21, 00:15:4d:37:15:13\n10.0.99.239, 00:15:4d:63:ef:a5\n10.0.191.51, 00:15:4d:bf:33:f8\n10.0.249.221, 00:15:4d:f9:dd:40\n10.0.239.35, 00:15:4d:ef:23:52\n10.0.247.191, 00:15:4d:f7:bf:05\n10.0.5.139, 00:15:4d:05:8b:3c\n10.0.16.140, 00:15:4d:10:8c:a6\n10.0.247.85, 00:15:4d:f7:55:53\n10.0.202.235, 00:15:4d:ca:eb:a7\n10.0.8.55, 00:15:4d:08:37:37\n10.0.127.137, 00:15:4d:7f:89:ce\n10.0.0.223, 00:15:4d:00:df:1e\n10.0.89.25, 00:15:4d:59:19:fe\n10.0.132.108, 00:15:4d:84:6c:a3\n10.0.5.225, 00:15:4d:05:e1:ed\n10.0.58.29, 00:15:4d:3a:1d:1e\n10.0.8.205, 00:15:4d:08:cd:d4\n10.0.105.65, 00:15:4d:69:41:4c\n10.0.219.15, 00:15:4d:db:0f:c7\n10.0.102.77, 00:15:4d:66:4d:90\n10.0.97.50, 00:15:4d:61:32:35\n10.0.167.214, 00:15:4d:a7:d6:29\n10.0.13.176, 00:15:4d:0d:b0:f6\n10.0.124.183, 00:15:4d:7c:b7:be\n10.0.75.32, 00:15:4d:4b:20:8f\n10.0.144.206, 00:15:4d:90:ce:cc\n10.0.135.178, 00:15:4d:87:b2:3a\n10.0.53.31, 00:15:4d:35:1f:c8\n10.0.123.205, 00:15:4d:7b:cd:17\n10.0.220.17, 00:15:4d:dc:11:b8\n10.0.109.84, 00:15:4d:6d:54:d0\n10.0.71.210, 00:15:4d:47:d2:ec\n10.0.93.37, 00:15:4d:5d:25:1c\n10.0.19.124, 00:15:4d:13:7c:b4\n10.0.169.14, 00:15:4d:a9:0e:39\n10.0.145.187, 00:15:4d:91:bb:dd\n10.0.102.249, 00:15:4d:66:f9:ed\n10.0.237.106, 00:15:4d:ed:6a:5b\n10.0.55.84, 00:15:4d:37:54:a7\n10.0.188.122, 00:15:4d:bc:7a:82\n10.0.232.114, 00:15:4d:e8:72:f6\n10.0.242.119, 00:15:4d:f2:77:4f\n10.0.160.140, 00:15:4d:a0:8c:91\n10.0.118.103, 00:15:4d:76:67:a3\n10.0.22.206, 00:15:4d:16:ce:39\n10.0.109.90, 00:15:4d:6d:5a:6c\n10.0.142.196, 00:15:4d:8e:c4:65\n10.0.35.181, 00:15:4d:23:b5:f0\n10.0.99.62, 00:15:4d:63:3e:fc\n10.0.32.79, 00:15:4d:20:4f:e7\n10.0.189.14, 00:15:4d:bd:0e:0f\n10.0.40.158, 00:15:4d:28:9e:6e\n10.0.12.166, 00:15:4d:0c:a6:b5\n10.0.25.39, 00:15:4d:19:27:5a\n10.0.161.44, 00:15:4d:a1:2c:b6\n10.0.89.203, 00:15:4d:59:cb:b2\n10.0.67.183, 00:15:4d:43:b7:2c\n10.0.110.191, 00:15:4d:6e:bf:80\n10.0.81.247, 00:15:4d:51:f7:d1\n10.0.77.229, 00:15:4d:4d:e5:57\n10.0.178.19, 00:15:4d:b2:13:ae\n10.0.204.89, 00:15:4d:cc:59:0f\n10.0.30.0, 00:15:4d:1e:00:7b\n10.0.148.51, 00:15:4d:94:33:4d\n10.0.213.43, 00:15:4d:d5:2b:56\n10.0.105.225, 00:15:4d:69:e1:31\n10.0.150.197, 00:15:4d:96:c5:41\n10.0.2.69, 00:15:4d:02:45:eb\n10.0.0.135, 00:15:4d:00:87:4f\n10.0.85.113, 00:15:4d:55:71:e1\n10.0.132.23, 00:15:4d:84:17:28\n10.0.14.185, 00:15:4d:0e:b9:f3\n10.0.89.21, 00:15:4d:59:15:57\n10.0.99.52, 00:15:4d:63:34:70\n10.0.43.173, 00:15:4d:2b:ad:22\n10.0.122.212, 00:15:4d:7a:d4:fd\n10.0.106.106, 00:15:4d:6a:6a:f5\n10.0.86.91, 00:15:4d:56:5b:cb\n10.0.217.233, 00:15:4d:d9:e9:d0\n10.0.195.226, 00:15:4d:c3:e2:58\n10.0.79.46, 00:15:4d:4f:2e:6a\n10.0.85.18, 00:15:4d:55:12:8c\n10.0.213.194, 00:15:4d:d5:c2:76\n10.0.4.188, 00:15:4d:04:bc:5a\n10.0.237.180, 00:15:4d:ed:b4:1b\n10.0.252.132, 00:15:4d:fc:84:34\n10.0.128.254, 00:15:4d:80:fe:42\n10.0.228.232, 00:15:4d:e4:e8:d2\n10.0.168.106, 00:15:4d:a8:6a:83\n10.0.40.6, 00:15:4d:28:06:67\n10.0.196.226, 00:15:4d:c4:e2:96\n10.0.170.161, 00:15:4d:aa:a1:7f\n10.0.40.189, 00:15:4d:28:bd:48\n10.0.53.194, 00:15:4d:35:c2:db\n10.0.87.236, 00:15:4d:57:ec:33\n10.0.44.224, 00:15:4d:2c:e0:db\n10.0.207.53, 00:15:4d:cf:35:7b\n10.0.68.76, 00:15:4d:44:4c:b2\n10.0.132.145, 00:15:4d:84:91:4a\n10.0.25.139, 00:15:4d:19:8b:2b\n10.0.67.154, 00:15:4d:43:9a:6e\n10.0.103.66, 00:15:4d:67:42:66\n10.0.39.134, 00:15:4d:27:86:4f\n10.0.43.223, 00:15:4d:2b:df:ce\n10.0.198.164, 00:15:4d:c6:a4:ba\n10.0.177.27, 00:15:4d:b1:1b:88\n10.0.251.73, 00:15:4d:fb:49:c7\n10.0.186.213, 00:15:4d:ba:d5:a7\n10.0.34.102, 00:15:4d:22:66:b4\n10.0.135.108, 00:15:4d:87:6c:5c\n10.0.98.20, 00:15:4d:62:14:aa\n10.0.113.179, 00:15:4d:71:b3:7b\n10.0.110.135, 00:15:4d:6e:87:01\n10.0.131.15, 00:15:4d:83:0f:ea\n10.0.3.254, 00:15:4d:03:fe:57\n10.0.168.63, 00:15:4d:a8:3f:17\n10.0.124.178, 00:15:4d:7c:b2:dd\n10.0.185.87, 00:15:4d:b9:57:97\n10.0.112.208, 00:15:4d:70:d0:ad\n10.0.113.94, 00:15:4d:71:5e:af\n10.0.129.153, 00:15:4d:81:99:5b\n10.0.48.197, 00:15:4d:30:c5:c4\n10.0.25.15, 00:15:4d:19:0f:62\n10.0.54.242, 00:15:4d:36:f2:19\n10.0.251.68, 00:15:4d:fb:44:da\n10.0.167.196, 00:15:4d:a7:c4:5a\n10.0.105.214, 00:15:4d:69:d6:b1\n10.0.100.134, 00:15:4d:64:86:8d\n10.0.228.199, 00:15:4d:e4:c7:09\n10.0.82.46, 00:15:4d:52:2e:83\n10.0.58.164, 00:15:4d:3a:a4:05\n10.0.60.204, 00:15:4d:3c:cc:cd\n10.0.171.150, 00:15:4d:ab:96:af\n10.0.182.61, 00:15:4d:b6:3d:33\n10.0.100.183, 00:15:4d:64:b7:ad\n10.0.239.85, 00:15:4d:ef:55:53\n10.0.53.14, 00:15:4d:35:0e:14\n10.0.56.113, 00:15:4d:38:71:c8\n10.0.100.143, 00:15:4d:64:8f:54\n10.0.243.248, 00:15:4d:f3:f8:02\n10.0.92.90, 00:15:4d:5c:5a:1c\n10.0.51.144, 00:15:4d:33:90:44\n10.0.79.214, 00:15:4d:4f:d6:7f\n10.0.151.85, 00:15:4d:97:55:a6\n10.0.207.40, 00:15:4d:cf:28:28\n10.0.103.109, 00:15:4d:67:6d:15\n10.0.9.131, 00:15:4d:09:83:6b\n10.0.50.245, 00:15:4d:32:f5:bf\n10.0.81.211, 00:15:4d:51:d3:81\n10.0.185.21, 00:15:4d:b9:15:26\n10.0.83.173, 00:15:4d:53:ad:71\n10.0.72.140, 00:15:4d:48:8c:1c\n10.0.79.150, 00:15:4d:4f:96:0d\n10.0.158.190, 00:15:4d:9e:be:4d\n10.0.180.72, 00:15:4d:b4:48:9d\n10.0.23.181, 00:15:4d:17:b5:0b\n10.0.1.232, 00:15:4d:01:e8:1b\n10.0.153.111, 00:15:4d:99:6f:31\n10.0.218.135, 00:15:4d:da:87:06\n10.0.253.85, 00:15:4d:fd:55:49\n10.0.143.64, 00:15:4d:8f:40:05\n10.0.16.146, 00:15:4d:10:92:ca\n10.0.16.16, 00:15:4d:10:10:8a\n10.0.79.100, 00:15:4d:4f:64:e3\n10.0.44.54, 00:15:4d:2c:36:6a\n10.0.191.185, 00:15:4d:bf:b9:83\n10.0.245.194, 00:15:4d:f5:c2:a2\n10.0.168.84, 00:15:4d:a8:54:14\n10.0.103.162, 00:15:4d:67:a2:2b\n10.0.96.176, 00:15:4d:60:b0:8d\n10.0.135.33, 00:15:4d:87:21:52\n10.0.192.144, 00:15:4d:c0:90:53\n10.0.122.33, 00:15:4d:7a:21:38\n10.0.220.42, 00:15:4d:dc:2a:52\n10.0.137.134, 00:15:4d:89:86:94\n10.0.3.129, 00:15:4d:03:81:ea\n10.0.125.118, 00:15:4d:7d:76:9d\n10.0.86.111, 00:15:4d:56:6f:6c\n10.0.62.129, 00:15:4d:3e:81:68\n10.0.65.218, 00:15:4d:41:da:7e\n10.0.122.65, 00:15:4d:7a:41:0b\n10.0.91.117, 00:15:4d:5b:75:a1\n10.0.79.140, 00:15:4d:4f:8c:a4\n10.0.161.205, 00:15:4d:a1:cd:15\n10.0.110.186, 00:15:4d:6e:ba:66\n10.0.107.6, 00:15:4d:6b:06:79\n10.0.249.132, 00:15:4d:f9:84:ec\n10.0.42.84, 00:15:4d:2a:54:10\n10.0.210.142, 00:15:4d:d2:8e:0c\n10.0.205.123, 00:15:4d:cd:7b:a4\n10.0.12.122, 00:15:4d:0c:7a:d2\n10.0.149.177, 00:15:4d:95:b1:51\n10.0.167.49, 00:15:4d:a7:31:62\n10.0.6.59, 00:15:4d:06:3b:33\n10.0.63.239, 00:15:4d:3f:ef:40\n10.0.128.241, 00:15:4d:80:f1:be\n10.0.52.202, 00:15:4d:34:ca:06\n10.0.240.205, 00:15:4d:f0:cd:42\n10.0.228.221, 00:15:4d:e4:dd:f6\n10.0.234.90, 00:15:4d:ea:5a:09\n10.0.81.203, 00:15:4d:51:cb:12\n10.0.170.147, 00:15:4d:aa:93:b7\n10.0.223.175, 00:15:4d:df:af:86\n10.0.246.221, 00:15:4d:f6:dd:70\n10.0.196.31, 00:15:4d:c4:1f:32\n10.0.1.40, 00:15:4d:01:28:48\n10.0.97.220, 00:15:4d:61:dc:28\n10.0.248.112, 00:15:4d:f8:70:d0\n10.0.87.205, 00:15:4d:57:cd:e1\n10.0.160.95, 00:15:4d:a0:5f:bc\n10.0.185.69, 00:15:4d:b9:45:3f\n10.0.204.194, 00:15:4d:cc:c2:76\n10.0.48.123, 00:15:4d:30:7b:5e\n10.0.103.27, 00:15:4d:67:1b:51\n10.0.29.131, 00:15:4d:1d:83:79\n10.0.39.185, 00:15:4d:27:b9:50\n10.0.74.136, 00:15:4d:4a:88:17\n10.0.173.112, 00:15:4d:ad:70:19\n10.0.88.173, 00:15:4d:58:ad:5e\n10.0.203.15, 00:15:4d:cb:0f:ae\n10.0.11.122, 00:15:4d:0b:7a:41\n10.0.148.58, 00:15:4d:94:3a:1c\n10.0.236.123, 00:15:4d:ec:7b:99\n10.0.101.95, 00:15:4d:65:5f:b3\n10.0.185.218, 00:15:4d:b9:da:24\n10.0.8.59, 00:15:4d:08:3b:88\n10.0.172.55, 00:15:4d:ac:37:96\n10.0.184.32, 00:15:4d:b8:20:a2\n10.0.191.221, 00:15:4d:bf:dd:05\n10.0.207.182, 00:15:4d:cf:b6:a4\n10.0.115.120, 00:15:4d:73:78:62\n10.0.46.33, 00:15:4d:2e:21:24\n10.0.200.39, 00:15:4d:c8:27:89\n10.0.41.185, 00:15:4d:29:b9:f4\n10.0.83.242, 00:15:4d:53:f2:95\n10.0.132.80, 00:15:4d:84:50:8a\n10.0.16.221, 00:15:4d:10:dd:11\n10.0.105.98, 00:15:4d:69:62:aa\n10.0.205.125, 00:15:4d:cd:7d:a1\n10.0.82.144, 00:15:4d:52:90:36\n10.0.135.51, 00:15:4d:87:33:76\n10.0.206.129, 00:15:4d:ce:81:fe\n10.0.159.156, 00:15:4d:9f:9c:e1\n10.0.152.36, 00:15:4d:98:24:a5\n10.0.133.111, 00:15:4d:85:6f:b1\n10.0.156.207, 00:15:4d:9c:cf:90\n10.0.14.145, 00:15:4d:0e:91:c4\n10.0.106.49, 00:15:4d:6a:31:55\n10.0.10.184, 00:15:4d:0a:b8:89\n10.0.68.115, 00:15:4d:44:73:7e\n10.0.195.89, 00:15:4d:c3:59:34\n10.0.43.111, 00:15:4d:2b:6f:09\n10.0.73.101, 00:15:4d:49:65:84\n10.0.179.181, 00:15:4d:b3:b5:a5\n10.0.211.149, 00:15:4d:d3:95:af\n10.0.40.212, 00:15:4d:28:d4:71\n10.0.203.64, 00:15:4d:cb:40:eb\n10.0.212.158, 00:15:4d:d4:9e:a6\n10.0.173.114, 00:15:4d:ad:72:93\n10.0.252.163, 00:15:4d:fc:a3:aa\n10.0.250.41, 00:15:4d:fa:29:0e\n10.0.247.142, 00:15:4d:f7:8e:60\n10.0.27.73, 00:15:4d:1b:49:48\n10.0.76.231, 00:15:4d:4c:e7:7e\n10.0.124.124, 00:15:4d:7c:7c:73\n10.0.86.88, 00:15:4d:56:58:e3\n10.0.18.175, 00:15:4d:12:af:78\n10.0.157.82, 00:15:4d:9d:52:5b\n10.0.149.16, 00:15:4d:95:10:d7\n10.0.183.176, 00:15:4d:b7:b0:83\n10.0.192.110, 00:15:4d:c0:6e:70\n10.0.139.55, 00:15:4d:8b:37:c3\n10.0.206.27, 00:15:4d:ce:1b:a9\n10.0.248.152, 00:15:4d:f8:98:06\n10.0.118.176, 00:15:4d:76:b0:74\n10.0.246.88, 00:15:4d:f6:58:25\n10.0.161.3, 00:15:4d:a1:03:d3\n10.0.132.208, 00:15:4d:84:d0:d5\n10.0.100.185, 00:15:4d:64:b9:28\n10.0.51.191, 00:15:4d:33:bf:a2\n10.0.15.149, 00:15:4d:0f:95:8d\n10.0.196.197, 00:15:4d:c4:c5:0d\n10.0.171.170, 00:15:4d:ab:aa:e7\n10.0.59.69, 00:15:4d:3b:45:64\n10.0.52.141, 00:15:4d:34:8d:7b\n10.0.129.164, 00:15:4d:81:a4:98\n10.0.0.98, 00:15:4d:00:62:0c\n10.0.222.19, 00:15:4d:de:13:08\n10.0.164.29, 00:15:4d:a4:1d:7b\n10.0.86.26, 00:15:4d:56:1a:11\n10.0.127.171, 00:15:4d:7f:ab:bb\n10.0.114.10, 00:15:4d:72:0a:85\n10.0.55.123, 00:15:4d:37:7b:f3\n10.0.89.92, 00:15:4d:59:5c:d6\n10.0.31.168, 00:15:4d:1f:a8:be\n10.0.138.99, 00:15:4d:8a:63:91\n10.0.4.32, 00:15:4d:04:20:81\n10.0.149.72, 00:15:4d:95:48:2f\n10.0.213.222, 00:15:4d:d5:de:95\n10.0.30.251, 00:15:4d:1e:fb:23\n10.0.60.103, 00:15:4d:3c:67:11\n10.0.137.88, 00:15:4d:89:58:2d\n10.0.86.16, 00:15:4d:56:10:15\n10.0.164.119, 00:15:4d:a4:77:07\n10.0.44.89, 00:15:4d:2c:59:1a\n10.0.149.205, 00:15:4d:95:cd:61\n10.0.148.1, 00:15:4d:94:01:47\n10.0.147.115, 00:15:4d:93:73:9a\n10.0.254.89, 00:15:4d:fe:59:3c\n10.0.165.84, 00:15:4d:a5:54:4b\n10.0.238.19, 00:15:4d:ee:13:a2\n10.0.148.122, 00:15:4d:94:7a:b7\n10.0.9.51, 00:15:4d:09:33:55\n10.0.2.202, 00:15:4d:02:ca:eb\n10.0.253.117, 00:15:4d:fd:75:72\n10.0.55.186, 00:15:4d:37:ba:77\n10.0.166.31, 00:15:4d:a6:1f:9d\n10.0.89.164, 00:15:4d:59:a4:07\n10.0.117.157, 00:15:4d:75:9d:23\n10.0.87.226, 00:15:4d:57:e2:21\n10.0.56.68, 00:15:4d:38:44:5e\n10.0.153.26, 00:15:4d:99:1a:d3\n10.0.39.103, 00:15:4d:27:67:15\n10.0.124.144, 00:15:4d:7c:90:f5\n10.0.96.17, 00:15:4d:60:11:c5\n10.0.195.128, 00:15:4d:c3:80:ae\n10.0.104.150, 00:15:4d:68:96:7e\n10.0.156.200, 00:15:4d:9c:c8:96\n10.0.204.190, 00:15:4d:cc:be:1f\n10.0.86.105, 00:15:4d:56:69:0f\n10.0.213.5, 00:15:4d:d5:05:45\n10.0.62.172, 00:15:4d:3e:ac:77\n10.0.129.232, 00:15:4d:81:e8:7a\n10.0.176.5, 00:15:4d:b0:05:48\n10.0.190.93, 00:15:4d:be:5d:60\n10.0.19.112, 00:15:4d:13:70:bd\n10.0.184.232, 00:15:4d:b8:e8:26\n10.0.98.248, 00:15:4d:62:f8:e2\n10.0.69.84, 00:15:4d:45:54:e2\n10.0.92.106, 00:15:4d:5c:6a:d7\n10.0.47.188, 00:15:4d:2f:bc:54\n10.0.218.82, 00:15:4d:da:52:57\n10.0.132.60, 00:15:4d:84:3c:c8\n10.0.71.181, 00:15:4d:47:b5:b6\n10.0.187.5, 00:15:4d:bb:05:fa\n10.0.194.25, 00:15:4d:c2:19:7c\n10.0.92.6, 00:15:4d:5c:06:ea\n10.0.198.249, 00:15:4d:c6:f9:57\n10.0.187.141, 00:15:4d:bb:8d:58\n10.0.180.111, 00:15:4d:b4:6f:e5\n10.0.23.1, 00:15:4d:17:01:9f\n10.0.84.243, 00:15:4d:54:f3:3f\n10.0.241.172, 00:15:4d:f1:ac:6b\n10.0.227.128, 00:15:4d:e3:80:0b\n10.0.110.106, 00:15:4d:6e:6a:7f\n10.0.95.143, 00:15:4d:5f:8f:85\n10.0.46.63, 00:15:4d:2e:3f:59\n10.0.176.140, 00:15:4d:b0:8c:7d\n10.0.195.155, 00:15:4d:c3:9b:6b\n10.0.214.76, 00:15:4d:d6:4c:93\n10.0.6.174, 00:15:4d:06:ae:5a\n10.0.58.186, 00:15:4d:3a:ba:88\n10.0.169.249, 00:15:4d:a9:f9:e6\n10.0.187.211, 00:15:4d:bb:d3:2c\n"
  },
  {
    "path": "l4lb/l4lb_map.py",
    "content": "#!/usr/bin/env python3\n# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n# Copyright (c) 2018 Netronome Systems, Inc.\n\nimport argparse\nimport csv\nimport json\nimport os\nimport subprocess\nfrom bpftool_utils import *\n\nparser = argparse.ArgumentParser(description=\"Initialize load balancer map\")\nparser.add_argument('-i', '--interface', action='store', required=True,\n                    help='xdp network interface')\nparser.add_argument('-f', '--file', action='store', required=True,\n                    help='Input file containing destination data')\nparser.add_argument('-s', '--saddr', action='store', required=False, type=str,\n                    default='10.0.0.1', help='source ip for outgoing packets')\nargs = parser.parse_args()\n\ntmpfile = 'tmp_bpftool.txt' # batch map updates into a file for bpftool\nstats_zero = '00 00 00 00 00 00 00 00' # initialize stats to (u64) zero\n\ninterface = args.interface\n\ntry:\n    map_id = str(get_map_ids(interface)[0])\n    max_dest = get_map_entries(map_id) # map size as defined by xdp program\nexcept:\n    print(\"Error finding map for dev: %s\" % interface)\n    sys.exit(1)\n\ntry:\n    dest_file = open(args.file, 'r')\n    dest_hosts = list(csv.reader(dest_file))\n    dest_count = len(dest_hosts)\nexcept:\n    print(\"Error reading file\")\n    sys.exit(1)\n\nif dest_count > max_dest:\n    print(\"Warning: only the first %d destinations will be used\" % max_dest)\nelse:\n    print(\"Loading file with %d destinations\" % dest_count)\n\nbatchfile = open(tmpfile, 'w')\n\n# iterate through data in input file, if it contains less values than max_dest\n# map will be filled as round robin\nfor key in range (0, max_dest):\n    target_id = key % dest_count\n\n    # bpftool requires data as individual bytes\n    keyval1 = str(key & 0xFF)\n    keyval2 = str(key >> 8)\n\n    saddr = args.saddr.split('.') # source IP for egress packets\n    daddr = dest_hosts[target_id][0].split('.') # IP of the target server\n\n    dmac_hex = dest_hosts[target_id][1].split(':') # MAC of the target server\n    dmac = [str(int(byte, 16)) for byte in dmac_hex] # convert hex to integers\n\n    # Fill in map using struct iptnl_info arrangement as specified in l4lb_xdp.c\n    COMMAND = (['map update id', map_id,\n                'key', keyval1, keyval2, '00 00',\n                'value', saddr[0], saddr[1], saddr[2], saddr[3],\n                         daddr[0], daddr[1], daddr[2], daddr[3],\n                         stats_zero, stats_zero,\n                         dmac[0], dmac[1], dmac[2], dmac[3], dmac[4], dmac[5],\n                         '00 00 \\n'])\n    COMMAND = ' '.join(COMMAND)\n    batchfile.write(COMMAND)\n\nbatchfile.close()\nsubprocess.check_output('bpftool batch file %s' % tmpfile, shell=True)\n"
  },
  {
    "path": "l4lb/l4lb_stats.py",
    "content": "#!/usr/bin/env python3\n# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n# Copyright (c) 2018 Netronome Systems, Inc.\n\nimport argparse\nimport json\nimport os\nimport subprocess\nimport sys\nimport time\nfrom bpftool_utils import *\n\nparser = argparse.ArgumentParser(description=\"Display load balancer statistics\")\nparser.add_argument('-i', '--interface', action='store', required=True,\n                    help='xdp network interface')\nargs = parser.parse_args()\ninterface = args.interface\n\nprev = {}\n\nwhile True:\n    n = 1\n    pkt_tot = 0\n    bit_tot = 0\n    values = {}\n    clock = time.time()\n\n    # obtain map values\n    try:\n        map_id = get_map_ids(interface)[0]\n        map_vals = dump_map(map_id)\n        xdp_type = get_map_dev(map_id)\n    except:\n        print(\"Error accessing eBPF map\")\n        time.sleep(1)\n        continue\n\n    # get totals for each destination ip\n    for record in map_vals:\n        # obtain values from map from positions defined by struct iptnl_info\n        dest_ip = [int(byte, 16) for byte in record['value'][4:8]]\n        bw = hex_list_to_int(record['value'][8:16])\n        pkt = hex_list_to_int(record['value'][16:24])\n\n        ip = '%s.%s.%s.%s' % (dest_ip[0], dest_ip[1], dest_ip[2], dest_ip[3])\n\n        if ip in values:\n            values[ip][0] += pkt\n            values[ip][1] += bw\n        else:\n            values[ip] = [pkt, bw]\n\n    os.system(\"clear\")\n    pr = (\"== Load balancer outbound statistics [%s] ==\\n\\n\" % xdp_type)\n\n    # Calculate network rate using diff from previous sample\n    for key in sorted(values):\n        bitrate = 0\n        pktrate = 0\n\n        if key in prev:\n            sample_period = clock - prev[key][2]\n            pktrate = int((values[key][0] - prev[key][0]) / sample_period)\n            bitrate = int((values[key][1] - prev[key][1]) / sample_period) * 8\n\n        prev[key] = [values[key][0], values[key][1], clock]\n\n        if pktrate >= 0: # on map refill stats are reset causes neg stats\n            pr += (\"{:4d}\\t{:15s}\\t{:12,} pkts/s\\t{:15,} bits/s\\n\"\n                  .format(n, key, pktrate, bitrate))\n            pkt_tot += pktrate\n            bit_tot += bitrate\n            n += 1\n\n    pr += \"\\n[Totals]\\t\\t{:12,} pkts/s\\t{:15,} bits/s\".format(pkt_tot, bit_tot)\n    print(pr)\n\n    time.sleep(max(0, 1 - (time.time() - clock)))\n"
  },
  {
    "path": "l4lb/l4lb_xdp.c",
    "content": "// SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n// Copyright (c) 2018 Netronome Systems, Inc.\n\n#include <stdbool.h>\n#include <stddef.h>\n#include <string.h>\n#include <linux/bpf.h>\n#include <linux/icmp.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n#include <linux/in.h>\n#include <linux/ip.h>\n#include <linux/tcp.h>\n#include <linux/udp.h>\n#include \"bpf_endian.h\"\n#include \"bpf_helpers.h\"\n#include \"jhash.h\"\n\n#define MAX_SERVERS 512\n/* 0x3FFF mask to check for fragment offset field */\n#define IP_FRAGMENTED 65343\n\nstruct pkt_meta {\n\t__be32 src;\n\t__be32 dst;\n\tunion {\n\t\t__u32 ports;\n\t\t__u16 port16[2];\n\t};\n};\n\nstruct dest_info {\n\t__u32 saddr;\n\t__u32 daddr;\n\t__u64 bytes;\n\t__u64 pkts;\n\t__u8 dmac[6];\n};\n\nstruct bpf_map_def SEC(\"maps\") servers = {\n\t.type = BPF_MAP_TYPE_HASH,\n\t.key_size = sizeof(__u32),\n\t.value_size = sizeof(struct dest_info),\n\t.max_entries = MAX_SERVERS,\n};\n\nstatic __always_inline struct dest_info *hash_get_dest(struct pkt_meta *pkt)\n{\n\t__u32 key;\n\tstruct dest_info *tnl;\n\n\t/* hash packet source ip with both ports to obtain a destination */\n\tkey = jhash_2words(pkt->src, pkt->ports, MAX_SERVERS) % MAX_SERVERS;\n\n\t/* get destination's network details from map */\n\ttnl = bpf_map_lookup_elem(&servers, &key);\n\tif (!tnl) {\n\t\t/* if entry does not exist, fallback to key 0 */\n\t\tkey = 0;\n\t\ttnl = bpf_map_lookup_elem(&servers, &key);\n\t}\n\treturn tnl;\n}\n\nstatic __always_inline bool parse_udp(void *data, __u64 off, void *data_end,\n\t\t\t\t      struct pkt_meta *pkt)\n{\n\tstruct udphdr *udp;\n\n\tudp = data + off;\n\tif (udp + 1 > data_end)\n\t\treturn false;\n\n\tpkt->port16[0] = udp->source;\n\tpkt->port16[1] = udp->dest;\n\n\treturn true;\n}\n\nstatic __always_inline bool parse_tcp(void *data, __u64 off, void *data_end,\n\t\t\t\t      struct pkt_meta *pkt)\n{\n\tstruct tcphdr *tcp;\n\n\ttcp = data + off;\n\tif (tcp + 1 > data_end)\n\t\treturn false;\n\n\tpkt->port16[0] = tcp->source;\n\tpkt->port16[1] = tcp->dest;\n\n\treturn true;\n}\n\nstatic __always_inline void set_ethhdr(struct ethhdr *new_eth,\n\t\t\t\t       const struct ethhdr *old_eth,\n\t\t\t\t       const struct dest_info *tnl,\n\t\t\t\t       __be16 h_proto)\n{\n\tmemcpy(new_eth->h_source, old_eth->h_dest, sizeof(new_eth->h_source));\n\tmemcpy(new_eth->h_dest, tnl->dmac, sizeof(new_eth->h_dest));\n\tnew_eth->h_proto = h_proto;\n}\n\nstatic __always_inline int process_packet(struct xdp_md *ctx, __u64 off)\n{\n\tvoid *data_end = (void *)(long)ctx->data_end;\n\tvoid *data = (void *)(long)ctx->data;\n\tstruct pkt_meta pkt = {};\n\tstruct ethhdr *new_eth;\n\tstruct ethhdr *old_eth;\n\tstruct dest_info *tnl;\n\tstruct iphdr iph_tnl;\n\tstruct iphdr *iph;\n\t__u16 *next_iph_u16;\n\t__u16 pkt_size;\n\t__u16 payload_len;\n\t__u8 protocol;\n\tu32 csum = 0;\n\n\tiph = data + off;\n\tif (iph + 1 > data_end)\n\t\treturn XDP_DROP;\n\tif (iph->ihl != 5)\n\t\treturn XDP_DROP;\n\n\tprotocol = iph->protocol;\n\tpayload_len = bpf_ntohs(iph->tot_len);\n\toff += sizeof(struct iphdr);\n\n\t/* do not support fragmented packets as L4 headers may be missing */\n\tif (iph->frag_off & IP_FRAGMENTED)\n\t\treturn XDP_DROP;\n\n\tpkt.src = iph->saddr;\n\tpkt.dst = iph->daddr;\n\n\t/* obtain port numbers for UDP and TCP traffic */\n\tif (protocol == IPPROTO_TCP) {\n\t\tif (!parse_tcp(data, off, data_end, &pkt))\n\t\t\treturn XDP_DROP;\n\t} else if (protocol == IPPROTO_UDP) {\n\t\tif (!parse_udp(data, off, data_end, &pkt))\n\t\t\treturn XDP_DROP;\n\t} else {\n\t\treturn XDP_PASS;\n\t}\n\n\t/* allocate a destination using packet hash and map lookup */\n\ttnl = hash_get_dest(&pkt);\n\tif (!tnl)\n\t\treturn XDP_DROP;\n\n\t/* extend the packet for ip header encapsulation */\n\tif (bpf_xdp_adjust_head(ctx, 0 - (int)sizeof(struct iphdr)))\n\t\treturn XDP_DROP;\n\n\tdata = (void *)(long)ctx->data;\n\tdata_end = (void *)(long)ctx->data_end;\n\n\t/* relocate ethernet header to start of packet and set MACs */\n\tnew_eth = data;\n\told_eth = data + sizeof(*iph);\n\n\tif (new_eth + 1 > data_end || old_eth + 1 > data_end ||\n\t    iph + 1 > data_end)\n\t\treturn XDP_DROP;\n\n\tset_ethhdr(new_eth, old_eth, tnl, bpf_htons(ETH_P_IP));\n\n\t/* create an additional ip header for encapsulation */\n\tiph_tnl.version = 4;\n\tiph_tnl.ihl = sizeof(*iph) >> 2;\n\tiph_tnl.frag_off = 0;\n\tiph_tnl.protocol = IPPROTO_IPIP;\n\tiph_tnl.check = 0;\n\tiph_tnl.id = 0;\n\tiph_tnl.tos = 0;\n\tiph_tnl.tot_len = bpf_htons(payload_len + sizeof(*iph));\n\tiph_tnl.daddr = tnl->daddr;\n\tiph_tnl.saddr = tnl->saddr;\n\tiph_tnl.ttl = 8;\n\n\t/* calculate ip header checksum */\n\tnext_iph_u16 = (__u16 *)&iph_tnl;\n\t#pragma clang loop unroll(full)\n\tfor (int i = 0; i < (int)sizeof(*iph) >> 1; i++)\n\t\tcsum += *next_iph_u16++;\n\tiph_tnl.check = ~((csum & 0xffff) + (csum >> 16));\n\n\tiph = data + sizeof(*new_eth);\n\t*iph = iph_tnl;\n\n\t/* increment map counters */\n\tpkt_size = (__u16)(data_end - data); /* payload size excl L2 crc */\n\t__sync_fetch_and_add(&tnl->pkts, 1);\n\t__sync_fetch_and_add(&tnl->bytes, pkt_size);\n\n\treturn XDP_TX;\n}\n\nSEC(\"xdp\")\nint loadbal(struct xdp_md *ctx)\n{\n\tvoid *data_end = (void *)(long)ctx->data_end;\n\tvoid *data = (void *)(long)ctx->data;\n\tstruct ethhdr *eth = data;\n\t__u32 eth_proto;\n\t__u32 nh_off;\n\n\tnh_off = sizeof(struct ethhdr);\n\tif (data + nh_off > data_end)\n\t\treturn XDP_DROP;\n\teth_proto = eth->h_proto;\n\n\t/* demo program only accepts ipv4 packets */\n\tif (eth_proto == bpf_htons(ETH_P_IP))\n\t\treturn process_packet(ctx, nh_off);\n\telse\n\t\treturn XDP_PASS;\n}\n"
  },
  {
    "path": "programmable_rss/Makefile",
    "content": "# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n\nTARGET := rss\n\nLLC ?= llc\nCLANG ?= clang\nCC ?= gcc\n\nLIBBPF_DIR = ../libbpf/src/\n\nXDP_C = ${TARGET:=_kern.c}\nXDP_OBJ = ${XDP_C:.c=.o}\nUSER_C = ${TARGET:=_user.c}\nUSER_OBJ = ${USER_C:.c=.o}\nOBJECT_LIBBPF = $(LIBBPF_DIR)/libbpf.a\n\nCFLAGS ?= -I$(LIBBPF_DIR)/root/usr/include/\nCFLAGS += -I../headers/\nLDFLAGS ?= -L$(LIBBPF_DIR)\n\nLIBS = -lbpf -lelf\n\nall: llvm-check $(TARGET) $(XDP_OBJ)\n\n.PHONY: clean $(CLANG) $(LLC)\n\nclean:\n\tcd $(LIBBPF_DIR) && $(MAKE) clean;\n\trm -f $(TARGET)\n\trm -f $(XDP_OBJ)\n\trm -f $(USER_OBJ)\n\trm -f *.ll\n\nllvm-check: $(CLANG) $(LLC)\n\t@for TOOL in $^ ; do \\\n\t\tif [ ! $$(command -v $${TOOL} 2>/dev/null) ]; then \\\n\t\t\techo \"*** ERROR: Cannot find tool $${TOOL}\" ;\\\n\t\t\texit 1; \\\n\t\telse true; fi; \\\n\tdone\n\n$(OBJECT_LIBBPF):\n\t@if [ ! -d $(LIBBPF_DIR) ]; then \\\n\t\techo \"Error: Need libbpf submodule\"; \\\n\t\techo \"May need to run git submodule update --init\"; \\\n\t\texit 1; \\\n\telse \\\n\t\tcd $(LIBBPF_DIR) && $(MAKE) all; \\\n\t\tmkdir -p root; DESTDIR=root $(MAKE) install_headers; \\\n\tfi\n\n$(TARGET): %: %_user.c $(OBJECT_LIBBPF) Makefile\n\t$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)\n\n$(XDP_OBJ): %.o: %.c\n\t$(CLANG) -S \\\n\t    -D __BPF_TRACING__ \\\n\t    $(CFLAGS) \\\n\t    -Wall \\\n\t    -Wno-unused-value -Wno-pointer-sign \\\n\t    -Wno-compare-distinct-pointer-types \\\n\t    -Werror \\\n\t    -O2 -emit-llvm -c -g $<\n\t$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}\n"
  },
  {
    "path": "programmable_rss/README.rst",
    "content": "Programmable RSS Demo\n=====================\n\nOverview of RSS\n~~~~~~~~~~~~~~~\n\nReceive Side Scaling (RSS) is utilised in modern network cards to distribute\nnetwork traffic between the host CPUs through the use of multiple queues [1]_.\nA hash function is applied to the packet headers (commonly the 4 tuple) to\ngenerate a hash for the flow. This hash value is subsequently used as the index\nto an indirection table which designates the destination RSS queue.\n\nSymmetric RSS is a RSS implementation where packets in both direction of a flow\nmap to the same queue, i.e. for a connection between hosts A and B, both packets\nsent by A and by B will be placed on the same queue.\nThis is useful for IDS/Firewalls monitoring traffic flows, by ensuring CPU state\naccess locality across all packets of the flow one can minimise cache bouncing\nand achieve higher performance.\n\nCustom header RSS (or Encapsulated RSS) allows users to benefit from RSS even if\nthey are using custom headers or uncommon encapsulations. Default RSS\nimplementations are only able to parse common protocols. With programmable RSS\nusers can include any field of the headers in RSS calculation. Users can also\nparse any encapsulation protocol they have in their networks. This is beneficial\nto overlay and trunk networks, where the outer IP header is relatively static\nresulting in a badly distributed RSS. The inner IP header addresses can have\nmore variance hence a better RSS distribution.\n\nThe RSS algorithms available on network cards are commonly closed source or\nfixed in hardware. In Linux kernel 4.18, the capability of programming the\nRX RSS through eBPF was introduced.\n\nDemo App\n~~~~~~~~\n\nThis program will demonstrate how XDP offload can be utilised to provide user\nprogrammable RSS. As this is a demo, it showcases multiple RSS capabilities,\nhowever a deployment would likely only implement one of these RSS options.\n\nThe demo allows for incoming packets to be distributed to\n\n- a single queue, chosen by the user through a userspace utility\n- distributed queues using a hash algorithm\n- distributed queues using a Symmetric RSS hash algorithm\n- distributed queues using a hash algorithm against the IPinIP inner headers\n\nThis demo shows support for simple IPinIP encapsulation because it's easy to set\nup and test, but UDP encapsulations (VXLAN, Geneve, FOU, GUE, etc.), NSH, QUIC\nor any other protocol can easily be implemented.\n\nMinimum Requirements for Demo\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis program requires a XDP offload compatible SmartNIC. It cannot be run in\ndriver mode.\n\n- Linux kernel 4.18\n- clang / LLVM 4.0\n- libelf-dev (Ubuntu) / elfutils-devel (Fedora)\n- Agilio® eBPF firmware for HW offload - July 2018\n  (available from `Netronome's support website`_)\n\n.. _Netronome's support website: https://help.netronome.com/\n\nLoading the Demo\n~~~~~~~~~~~~~~~~\n\nThe program is compiled using an included libbpf. To compile the user space and\nXDP programs ::\n\n $ make\n\nTo load the program ::\n\n # ./rss -i INTERFACE\n\nTraffic Generation\n~~~~~~~~~~~~~~~~~~\n\nTraffic can be generated using a variety of tools, but for ease of use a pcap\nfile has been supplied (traffic_IPIP.pcap). This traffic can be replayed\nusing the following instructions.\n\nFor the host running the eBPF program, ensure promiscuous mode is enabled to\nallow for all packets to be received. This is required as the destination MAC\naddress set within the pcap file has been set for another host ::\n\n # ip link set dev ens4np0 promisc on\n\nOn the traffic generator, use tcpreplay to retransmit the test traffic ::\n\n # tcpreplay -i ens0 -l 500 traffic_IPIP.pcap\n\nExamples\n~~~~~~~~\n\nThe following examples will utilise the interface ens4np0 which has 8 queues\nset within ethtool. All examples are run against the same IPinIP traffic ::\n\n # ethtool -L ens4np0 combined 8 rx 0 tx 0\n\nSending all traffic to queue 5 ::\n\n # ./rss -i ens4np0 -q 5\n -------------------------------------------------\n RSS Queue 0: 0\n RSS Queue 1: 0\n RSS Queue 2: 0\n RSS Queue 3: 0\n RSS Queue 4: 0\n RSS Queue 5: 804,081\n RSS Queue 6: 0\n RSS Queue 7: 0\n\nDistributing traffic using jhash algorithm ::\n\n # ./rss -i ens4np0 -j\n -------------------------------------------------\n RSS Queue 0: 0\n RSS Queue 1: 0\n RSS Queue 2: 0\n RSS Queue 3: 0\n RSS Queue 4: 0\n RSS Queue 5: 402,400\n RSS Queue 6: 402,400\n RSS Queue 7: 0\n\nDistributing traffic using jhash algorithm with Symmetric RSS ::\n\n # ./rss -i ens4np0 -j -s\n -------------------------------------------------\n RSS Queue 0: 0\n RSS Queue 1: 0\n RSS Queue 2: 0\n RSS Queue 3: 0\n RSS Queue 4: 0\n RSS Queue 5: 0\n RSS Queue 6: 804,797\n RSS Queue 7: 0\n\nDistributing traffic using jhash algorithm with encapsulated IPs ::\n\n # ./rss -i ens4np0 -j -e\n -------------------------------------------------\n RSS Queue 0: 72,449\n RSS Queue 1: 104,648\n RSS Queue 2: 120,747\n RSS Queue 3: 128,797\n RSS Queue 4: 64,398\n RSS Queue 5: 128,792\n RSS Queue 6: 72,447\n RSS Queue 7: 112,693\n\nDistributing traffic using jhash algorithm with encapsulated IPs on 4 queues ::\n\n # ./rss -i ens4np0 -j -e -m 4\n -------------------------------------------------\n RSS Queue 0: 136,820\n RSS Queue 1: 233,403\n RSS Queue 2: 193,158\n RSS Queue 3: 241,450\n\nRemoving the Demo\n~~~~~~~~~~~~~~~~~\n\nThe XDP program will automatically be unloaded on exiting the rss program\n\n.. [1] https://www.kernel.org/doc/Documentation/networking/scaling.txt\n"
  },
  {
    "path": "programmable_rss/rss_common.h",
    "content": "// SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n// Copyright (c) 2018 Netronome Systems, Inc.\n\n#define MAX_RSS_QUEUES 64\n\nenum {\n\tQUEUE_STATIC = 0,\n\tQUEUE_HASH,\n\tQUEUE_SYMMETRIC,\n\tQUEUE_ENCAP,\n};\n\nstruct queue_select_ctrl {\n\t__u8 select_mode;\n\t__u8 queue_static;\n};\n\nstruct indirect_queue {\n\t__u32 packet_cnt;\n\t__u8 queue_num;\n};\n"
  },
  {
    "path": "programmable_rss/rss_kern.c",
    "content": "// SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n// Copyright (c) 2018 Netronome Systems, Inc.\n\n#include <stdbool.h>\n#include <stddef.h>\n#include <linux/bpf.h>\n#include <linux/if_ether.h>\n#include <linux/in.h>\n#include <linux/ip.h>\n#include <linux/ipv6.h>\n#include <linux/string.h>\n#include <linux/tcp.h>\n#include <linux/udp.h>\n#include \"bpf_endian.h\"\n#include \"bpf_helpers.h\"\n#include \"jhash.h\"\n#include \"rss_common.h\"\n\nstruct pkt_meta {\n\t__be32 src;\n\t__be32 dst;\n\t__be32 srcv6[4];\n\t__be32 dstv6[4];\n\tunion {\n\t\t__u32 ports;\n\t\t__u16 port16[2];\n\t};\n\t__u8 protocol;\n};\n\nstruct bpf_map_def SEC(\"maps\") ctrl_map = {\n\t.type = BPF_MAP_TYPE_ARRAY,\n\t.key_size = sizeof(__u32),\n\t.value_size = sizeof(struct queue_select_ctrl),\n\t.max_entries = 1,\n};\n\nstruct bpf_map_def SEC(\"maps\") indirect_map = {\n\t.type = BPF_MAP_TYPE_ARRAY,\n\t.key_size = sizeof(__u32),\n\t.value_size = sizeof(struct indirect_queue),\n\t.max_entries = MAX_RSS_QUEUES,\n};\n\nstatic __always_inline __u32 hash_tuples(struct pkt_meta *pkt, bool is_ip6)\n{\n\t__u32 a;\n\t__u32 b;\n\n\t/* hash packet ip and ports to obtain a key for rss indirection tbl */\n\tif (is_ip6) {\n\t\ta = jhash2(pkt->srcv6, 4, 0xc55);\n\t\tb = jhash2(pkt->dstv6, 4, 0x1234);\n\t\treturn jhash_3words(a, b, pkt->ports, 0xeb0f);\n\t} else {\n\t\treturn jhash_3words(pkt->src, pkt->dst, pkt->ports, 0xeb0f);\n\t}\n}\n\nstatic __always_inline bool parse_udp(void *data, __u64 off, void *data_end,\n\t\t\t\t      struct pkt_meta *pkt)\n{\n\tstruct udphdr *udp;\n\n\tudp = data + off;\n\tif (udp + 1 > data_end)\n\t\treturn false;\n\n\tpkt->port16[0] = udp->source;\n\tpkt->port16[1] = udp->dest;\n\n\treturn true;\n}\n\nstatic __always_inline bool parse_tcp(void *data, __u64 off, void *data_end,\n\t\t\t\t      struct pkt_meta *pkt)\n{\n\tstruct tcphdr *tcp;\n\n\ttcp = data + off;\n\tif (tcp + 1 > data_end)\n\t\treturn false;\n\n\tpkt->port16[0] = tcp->source;\n\tpkt->port16[1] = tcp->dest;\n\n\treturn true;\n}\n\nstatic __always_inline bool parse_ip4(void *data, __u64 off, void *data_end,\n\t\t\t\t      struct pkt_meta *pkt)\n{\n\tstruct iphdr *iph;\n\n\tiph = data + off;\n\tif (iph + 1 > data_end)\n\t\treturn false;\n\n\tif (iph->ihl != 5)\n\t\treturn false;\n\n\tpkt->src = iph->saddr;\n\tpkt->dst = iph->daddr;\n\tpkt->protocol = iph->protocol;\n\n\treturn true;\n}\n\nstatic __always_inline bool parse_ip6(void *data, __u64 off, void *data_end,\n\t\t\t\t      struct pkt_meta *pkt)\n{\n\tstruct ipv6hdr *ip6h;\n\n\tip6h = data + off;\n\tif (ip6h + 1 > data_end)\n\t\treturn false;\n\n\tmemcpy(pkt->srcv6, ip6h->saddr.s6_addr32, 16);\n\tmemcpy(pkt->dstv6, ip6h->daddr.s6_addr32, 16);\n\tpkt->protocol = ip6h->nexthdr;\n\n\treturn true;\n}\n\nstatic __always_inline void sort_tuple(struct pkt_meta *pkt, bool is_ip6)\n{\n\t__be32 temp_ipv6[4];\n\t__be32 temp_ip;\n\t__u16 temp_port;\n\t__u64 tot_dst;\n\t__u64 tot_src;\n\n\t/* sort tuple to ensure consistency for both flow directions */\n\tif (is_ip6) {\n\t\ttot_src = pkt->srcv6[0] + pkt->srcv6[1]\n\t\t\t   + pkt->srcv6[2] + pkt->srcv6[3];\n\t\ttot_dst = pkt->dstv6[0] + pkt->dstv6[1]\n\t\t\t   + pkt->dstv6[2] + pkt->dstv6[3];\n\n\t\tif (tot_src < tot_dst) {\n\t\t\tmemcpy(temp_ipv6, pkt->srcv6, 16);\n\t\t\tmemcpy(pkt->srcv6, pkt->dstv6, 16);\n\t\t\tmemcpy(pkt->dstv6, temp_ipv6, 16);\n\t\t}\n\t} else {\n\t\tif (pkt->src < pkt->dst) {\n\t\t\ttemp_ip = pkt->src;\n\t\t\tpkt->src = pkt->dst;\n\t\t\tpkt->dst = temp_ip;\n\t\t}\n\t}\n\n\tif (pkt->port16[0] < pkt->port16[1]) {\n\t\ttemp_port = pkt->port16[0];\n\t\tpkt->port16[0] = pkt->port16[1];\n\t\tpkt->port16[1] = temp_port;\n\t}\n}\n\nSEC(\"xdp\")\nint process_packet(struct xdp_md *ctx)\n{\n\tvoid *data_end = (void *)(long)ctx->data_end;\n\tvoid *data = (void *)(long)ctx->data;\n\tstruct queue_select_ctrl *queue_ctrl;\n\tstruct indirect_queue *dest_q;\n\tstruct ethhdr *eth = data;\n\tstruct pkt_meta pkt = {};\n\tbool symmetric = false;\n\tbool use_encap = false;\n\tbool is_ip6 = false;\n\tbool jhash = false;\n\t__u32 eth_proto;\n\t__u32 hash;\n\t__u32 key;\n\t__u32 off;\n\n\t/* determine hashing mode using map lookup */\n\tkey = 0;\n\n\tqueue_ctrl = bpf_map_lookup_elem(&ctrl_map, &key);\n\tif (!queue_ctrl)\n\t\treturn XDP_PASS;\n\n\tswitch (queue_ctrl->select_mode) {\n\tcase QUEUE_STATIC:\n\t\tjhash = false;\n\t\tkey = queue_ctrl->queue_static;\n\t\tbreak;\n\tcase QUEUE_HASH:\n\t\tjhash = true;\n\t\tbreak;\n\tcase QUEUE_SYMMETRIC:\n\t\tjhash = true;\n\t\tsymmetric = true;\n\t\tbreak;\n\tcase QUEUE_ENCAP:\n\t\tjhash = true;\n\t\tuse_encap = true;\n\t\tbreak;\n\tdefault:\n\t\treturn XDP_PASS;\n\t}\n\n\t/* parse packet for IP Addresses and Ports */\n\toff = sizeof(struct ethhdr);\n\tif (data + off > data_end)\n\t\treturn XDP_PASS;\n\n\teth_proto = eth->h_proto;\n\n\tif (eth_proto == bpf_htons(ETH_P_IP)) {\n\t\tif (!parse_ip4(data, off, data_end, &pkt))\n\t\t\treturn XDP_PASS;\n\t\toff += sizeof(struct iphdr);\n\t} else if (eth_proto == bpf_htons(ETH_P_IPV6)) {\n\t\tif (!parse_ip6(data, off, data_end, &pkt))\n\t\t\treturn XDP_PASS;\n\t\tis_ip6 = true;\n\t\toff += sizeof(struct ipv6hdr);\n\t} else {\n\t\treturn XDP_PASS;\n\t}\n\n\t/* if IPinIP packet allow for second IP header */\n\tif (pkt.protocol == IPPROTO_IPIP) {\n\t\tif (use_encap) {\n\t\t\tif (!parse_ip4(data, off, data_end, &pkt))\n\t\t\t\treturn XDP_PASS;\n\t\t\tis_ip6 = false;\n\t\t}\n\t\toff += sizeof(struct iphdr);\n\t} else if (pkt.protocol == IPPROTO_IPV6) {\n\t\tif (use_encap) {\n\t\t\tif (!parse_ip6(data, off, data_end, &pkt))\n\t\t\t\treturn XDP_PASS;\n\t\t\tis_ip6 = true;\n\t\t}\n\t\toff += sizeof(struct ipv6hdr);\n\t}\n\n\tif (data + off > data_end)\n\t\treturn XDP_PASS;\n\n\t/* obtain port numbers for UDP and TCP traffic */\n\tif (pkt.protocol == IPPROTO_TCP) {\n\t\tif (!parse_tcp(data, off, data_end, &pkt))\n\t\t\treturn XDP_PASS;\n\t} else if (pkt.protocol == IPPROTO_UDP) {\n\t\tif (!parse_udp(data, off, data_end, &pkt))\n\t\t\treturn XDP_PASS;\n\t} else {\n\t\tpkt.ports = 0;\n\t}\n\n\tif (symmetric)\n\t\tsort_tuple(&pkt, is_ip6);\n\n\tif (jhash) {\n\t\t/* set map lookup key using 4 tuple hash */\n\t\thash = hash_tuples(&pkt, is_ip6);\n\t\tkey = hash % MAX_RSS_QUEUES;\n\t}\n\n\t/* HW cannot perform modulus on varying values so use indirection tbl */\n\tdest_q = bpf_map_lookup_elem(&indirect_map, &key);\n\tif (!dest_q)\n\t\treturn XDP_PASS;\n\n\tctx->rx_queue_index = dest_q->queue_num;\n\t/* increment queue packet counter */\n\t__sync_fetch_and_add(&dest_q->packet_cnt, 1);\n\n\treturn XDP_PASS;\n}\n"
  },
  {
    "path": "programmable_rss/rss_user.c",
    "content": "// SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)\n// Copyright (c) 2018 Netronome Systems, Inc.\n\n#include <libgen.h>\n#include <locale.h>\n#include <signal.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n#include <unistd.h>\n#include <bpf/bpf.h>\n#include <bpf/libbpf.h>\n#include <linux/ethtool.h>\n#include <linux/if_link.h>\n#include <linux/in.h>\n#include <linux/sockios.h>\n#include <net/if.h>\n#include <sys/ioctl.h>\n#include \"rss_common.h\"\n\nstatic int ifindex;\nstatic __u32 xdp_flags;\n\nstatic void unload_prog(int sig)\n{\n\tbpf_set_link_xdp_fd(ifindex, -1, xdp_flags);\n\tprintf(\"unloading xdp program...\\n\");\n\texit(0);\n}\n\nstatic int get_interface_rx_channels(int ifindex)\n{\n\tstruct ethtool_channels cmd;\n\tstruct ifreq req;\n\tint socketfd;\n\n\tsocketfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);\n\tif (socketfd == -1)\n\t\treturn -1;\n\n\t/* get interface name */\n\treq.ifr_ifindex = ifindex;\n\tif (ioctl(socketfd, SIOCGIFNAME, &req) == -1)\n\t\treturn -1;\n\n\t/* get ethtool channels */\n\treq.ifr_data = (void *)&cmd;\n\tcmd.cmd = ETHTOOL_GCHANNELS;\n\n\tif (ioctl(socketfd, SIOCETHTOOL, &req) == -1)\n\t\treturn -1;\n\n\treturn cmd.combined_count + cmd.rx_count;\n}\n\nstatic int poll_stats(int indirect_map_fd, int queues_enabled, int poll_secs)\n{\n\tstruct indirect_queue indirect_lookup;\n\tint values[queues_enabled];\n\tint prev[queues_enabled];\n\tstruct timespec t1, t2;\n\tdouble time_taken;\n\tlong queue_rate;\n\tint queue;\n\tint i;\n\n\t/* initialize arrays */\n\tmemset(prev, 0, sizeof(prev));\n\tmemset(values, 0, sizeof(prev));\n\t/* use thousand separators in printf */\n\tsetlocale(LC_NUMERIC, \"en_US\");\n\n\tclock_gettime(CLOCK_MONOTONIC_RAW, &t1);\n\n\twhile (true) {\n\t\tprintf(\"-------------------------------------------------\\n\\n\");\n\t\tfor (i = 0; i < MAX_RSS_QUEUES; i++) {\n\t\t\tif (bpf_map_lookup_elem(indirect_map_fd, &i,\n\t\t\t\t\t\t&indirect_lookup) != 0) {\n\t\t\t\tprintf(\"Err lookup failed\\n\");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tqueue = indirect_lookup.queue_num;\n\t\t\tvalues[queue] += indirect_lookup.packet_cnt;\n\t\t}\n\n\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &t2);\n\t\t/* calc sample period to allow rate to be obtained */\n\t\ttime_taken = (t2.tv_sec + 1.0e-9 * t2.tv_nsec) -\n\t\t\t     (t1.tv_sec + 1.0e-9 * t1.tv_nsec);\n\n\t\tfor (i = 0; i < queues_enabled; i++) {\n\t\t\tqueue_rate = (values[i] - prev[i]) / time_taken;\n\t\t\tprintf(\"RSS Queue %d: %'ld\\n\", i, queue_rate);\n\t\t\tprev[i] = values[i];\n\t\t\tvalues[i] = 0;\n\t\t}\n\t\tt1 = t2;\n\t\tusleep(poll_secs * 1000 * 1000);\n\t}\n}\n\nstatic void usage(const char *prog)\n{\n\tfprintf(stderr,\n\t\t\"%s -i interface [OPTS]\\n\\n\"\n\t\t\"OPTS:\\n\"\n\t\t\" -q  QUEUE send all traffic to single queue\\n\"\n\t\t\" -j        jhash incoming IP and ports\\n\"\n\t\t\" -s        jhash with Symmetric RSS\\n\"\n\t\t\" -e        jhash Encapsulated IPinIP headers\\n\"\n\t\t\" -m QUEUES set maximum number of queues for jhash\\n\",\n\t\tprog);\n}\n\nint main(int argc, char **argv)\n{\n\tstruct bpf_prog_load_attr prog_load_attr = {\n\t\t.prog_type = BPF_PROG_TYPE_XDP,\n\t\t.file = \"rss_kern.o\",\n\t};\n\tstruct indirect_queue indirect_rec = {};\n\tstruct queue_select_ctrl mapctrl;\n\tstruct bpf_map *indirect_map;\n\tstruct bpf_map *ctrl_map;\n\tstruct bpf_object *obj;\n\tint queues_enabled = 0;\n\tint indirect_map_fd;\n\tint ethtool_queues;\n\tint ctrl_map_fd;\n\tint prog_fd;\n\tint key;\n\tint opt;\n\tint i;\n\n\tmapctrl.select_mode = QUEUE_HASH;\n\txdp_flags = XDP_FLAGS_HW_MODE;   /* set HW offload flag */\n\n\tif (optind == argc) {\n\t\tusage(basename(argv[0]));\n\t\treturn -1;\n\t}\n\n\twhile ((opt = getopt(argc, argv, \"hi:q:jsem:\")) != -1) {\n\t\tswitch (opt) {\n\t\tcase 'h':\n\t\t\tusage(basename(argv[0]));\n\t\t\treturn 0;\n\t\tcase 'i':\n\t\t\tifindex = if_nametoindex(optarg);\n\t\t\tbreak;\n\t\tcase 'q':\n\t\t\tmapctrl.select_mode = QUEUE_STATIC;\n\t\t\tmapctrl.queue_static = atoi(optarg);\n\t\t\tbreak;\n\t\tcase 'j':\n\t\t\tmapctrl.select_mode = QUEUE_HASH;\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tmapctrl.select_mode = QUEUE_SYMMETRIC;\n\t\t\tbreak;\n\t\tcase 'e':\n\t\t\tmapctrl.select_mode = QUEUE_ENCAP;\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tqueues_enabled = atoi(optarg);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tprintf(\"incorrect usage\\n\");\n\t\t\tusage(basename(argv[0]));\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tif (ifindex == 0) {\n\t\tprintf(\"Err: Invalid interface\\n\");\n\t\treturn -1;\n\t}\n\tprog_load_attr.ifindex = ifindex; /* set offload dev ifindex */\n\n\tethtool_queues = get_interface_rx_channels(ifindex);\n\tif (ethtool_queues < 1) {\n\t\tprintf(\"Err: Cannot obtain number of NIC channels\\n\");\n\t\treturn -1;\n\t}\n\n\tif (queues_enabled == 0) /* if no user defined max queue limit */\n\t\tqueues_enabled = ethtool_queues;\n\n\tif (queues_enabled > ethtool_queues) {\n\t\tprintf(\"Err: Queues enabled exceeds netdev queues\\n\");\n\t\tprintf(\"Ethtool queues: %d\\n\", ethtool_queues);\n\t\treturn -1;\n\t}\n\n\tif (mapctrl.select_mode == QUEUE_STATIC) {\n\t\tif (mapctrl.queue_static >= queues_enabled) {\n\t\t\tprintf(\"Err: Queue selected exceeds queues enabled\\n\");\n\t\t\tprintf(\"Netdev queues enabled: %d\\n\", queues_enabled);\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\t/* use libbpf to load program */\n\tif (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) {\n\t\tprintf(\"Err: Cannot load file\\n\");\n\t\treturn -1;\n\t}\n\n\tif (prog_fd < 1) {\n\t\tprintf(\"Error creating prog_fd\\n\");\n\t\treturn -1;\n\t}\n\n\tsignal(SIGINT, unload_prog);\n\tsignal(SIGTERM, unload_prog);\n\n\t/* use libbpf to link program to interface with corresponding flags */\n\tif (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 0) {\n\t\tprintf(\"Error linking fd to xdp with offload flags\\n\");\n\t\treturn -1;\n\t}\n\n\tctrl_map = bpf_object__find_map_by_name(obj, \"ctrl_map\");\n\tctrl_map_fd = bpf_map__fd(ctrl_map);\n\tindirect_map = bpf_object__find_map_by_name(obj, \"indirect_map\");\n\tindirect_map_fd = bpf_map__fd(indirect_map);\n\n\tif (!(ctrl_map_fd >= 0 && indirect_map_fd >= 0)) {\n\t\tprintf(\"Err: Cannot find maps\\n\");\n\t\treturn -1;\n\t}\n\n\t/* fill ctrl map with hash mode queues */\n\tkey = 0;\n\tif (bpf_map_update_elem(ctrl_map_fd, &key, &mapctrl, BPF_ANY) != 0) {\n\t\tprintf(\"Err: Map update\\n\");\n\t\treturn -1;\n\t}\n\n\t/* fill indirection map round robin using modulus */\n\tfor (i = 0; i < MAX_RSS_QUEUES; i++) {\n\t\tindirect_rec.queue_num = i % queues_enabled;\n\n\t\tif (bpf_map_update_elem(indirect_map_fd, &i, &indirect_rec,\n\t\t\t\t\tBPF_ANY) != 0) {\n\t\t\tprintf(\"Err: Map update failed\\n\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tpoll_stats(indirect_map_fd, queues_enabled, 1);\n\treturn 0;\n}\n"
  }
]