├── .github └── workflows │ └── ansible-lint.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Jenkinsfile ├── Jenkinsfile.implementation ├── LICENSE ├── README.md ├── ansible ├── nica.yml └── roles │ └── nica │ ├── .ansible-lint │ ├── README.md │ ├── defaults │ └── main.yml │ ├── handlers │ └── main.yml │ ├── meta │ └── main.yml │ ├── tasks │ └── main.yml │ ├── tests │ ├── inventory │ └── test.yml │ └── vars │ ├── Debian.yml │ ├── RedHat.yml │ └── main.yml ├── cmake └── Modules │ ├── FindPylint.cmake │ └── Findibverbs.cmake ├── emulation ├── CMakeLists.txt ├── emu-top.cpp └── emu.hpp ├── ikernels ├── CMakeLists.txt ├── hls │ ├── cms-ikernel.cpp │ ├── cms-ikernel.hpp │ ├── cms-impl.hpp │ ├── cms.cpp │ ├── cms.hpp │ ├── coap.cpp │ ├── coap.hpp │ ├── echo-impl.hpp │ ├── echo.cpp │ ├── echo.hpp │ ├── heap.hpp │ ├── indexed_heap.hpp │ ├── memcached-ik.hpp │ ├── memcached.cpp │ ├── memcached_cache.hpp │ ├── passthrough-impl.hpp │ ├── passthrough.cpp │ ├── passthrough.hpp │ ├── pktgen-impl.hpp │ ├── pktgen.cpp │ ├── pktgen.hpp │ ├── tests │ │ ├── cache_tests.cpp │ │ ├── cms-ikernel_tests.cpp │ │ ├── cms.pcap │ │ ├── cms_tests.cpp │ │ ├── coap-filtered.pcap │ │ ├── coap-requests.pcap │ │ ├── coap_tests.cpp │ │ ├── echo_tests.cpp │ │ ├── heap_tests.cpp │ │ ├── ikernel_tests.hpp │ │ ├── memcached-all-responses-16.pcap │ │ ├── memcached-all-responses.pcap │ │ ├── memcached-requests-16.pcap │ │ ├── memcached-requests.pcap │ │ ├── memcached-responses-16.pcap │ │ ├── memcached-responses.pcap │ │ ├── memcached-set-16.pcap │ │ ├── memcached_tests.cpp │ │ ├── passthrough_tests.cpp │ │ ├── ping.pcap │ │ ├── pktgen_tests.cpp │ │ ├── pong.pcap │ │ ├── threshold_tests.cpp │ │ └── udp_rr.pcap │ ├── threshold-impl.hpp │ ├── threshold.cpp │ └── threshold.hpp ├── ikernel.tcl.in └── verilog │ ├── cms_heap.v │ ├── cms_wrapper.v │ ├── heap_stage.v │ └── last_heap_stage.v ├── libnica ├── CMakeLists.txt ├── nica.cpp ├── nica.h └── nicamgr.h ├── manager ├── CMakeLists.txt ├── README.md ├── idpool.py ├── memcached.py ├── memcachedctl.py ├── nica.py ├── nica_manager.py ├── nicactl.py ├── pylint.sh ├── sigmon.py └── util.py ├── nica ├── CMakeLists.txt ├── arbiter.tcl ├── custom_ring.tcl ├── demux.tcl ├── flow_table.tcl ├── hls │ ├── arbiter-impl.hpp │ ├── arbiter.cpp │ ├── arbiter.hpp │ ├── axi_data.hpp │ ├── custom_rx_ring-impl.hpp │ ├── custom_rx_ring.cpp │ ├── custom_rx_ring.hpp │ ├── demux.cpp │ ├── demux.hpp │ ├── drop_or_pass.hpp │ ├── either.hpp │ ├── flow_table.cpp │ ├── flow_table.hpp │ ├── flow_table_impl.hpp │ ├── gateway.hpp │ ├── hls_helper.h │ ├── ib_pack.h │ ├── ikernel-types.hpp │ ├── ikernel.cpp │ ├── ikernel.hpp │ ├── link_with_reg.hpp │ ├── linux_types.h │ ├── mlx.cpp │ ├── mlx.h │ ├── nica-impl.hpp │ ├── nica-top.hpp │ ├── nica.cpp │ ├── rxe_hdr.h │ ├── tb.h │ ├── tc-ports.hpp │ ├── tests │ │ ├── 0bad.pcap │ │ ├── add_bth.py │ │ ├── arbiter_tests.cpp │ │ ├── f00d.pcap │ │ ├── flow_table_tests.cpp │ │ ├── gen_packets.py │ │ ├── input.pcap │ │ ├── main.cpp │ │ ├── pad_small_packets.py │ │ ├── passthrough.pcap │ │ ├── remove_eth_padding.py │ │ ├── roce.py │ │ └── tb.cpp │ ├── udp.cpp │ └── udp.h ├── ikernel.tcl ├── udp.tcl ├── verilog │ ├── coap_coap_top.v │ ├── csa_32x3.v │ ├── csa_32x4.v │ ├── csa_32x6.v │ ├── ddr_address_mapping.v │ ├── exp_hls.v │ ├── sha256_core.v │ ├── sha256_k_constants.v │ ├── sha256_stream.v │ ├── sha256_top.v │ ├── sha256_w_mem.v │ ├── sigmon_counter.v │ ├── sigmon_counters.v │ ├── sigmon_events.v │ ├── sigmon_logic_block.v │ ├── sigmon_logic_blocks.v │ ├── sigmon_monitor.v │ ├── sigmon_monitors.v │ ├── sigmon_pattern.v │ └── sigmon_top.v └── xci │ ├── .gitignore │ ├── axis_16x512b_fifo │ └── axis_16x512b_fifo.xci │ ├── axis_512x256b_fifo │ └── axis_512x256b_fifo.xci │ ├── axis_512x512b_fifo │ └── axis_512x512b_fifo.xci │ ├── axis_data_fifo_0 │ └── axis_data_fifo_0.xci │ ├── ddr_adrs_mapping │ └── ddr_adrs_mapping.xci │ ├── event_fifo_1Kx36b │ └── event_fifo_1Kx36b.xci │ ├── sigmon_fifo_128Kx32b │ └── sigmon_fifo_128Kx32b.xci │ ├── sigmon_fifo_64Kx32b │ └── sigmon_fifo_64Kx32b.xci │ ├── tc_data_512x289b │ └── tc_data_512x289b.xci │ └── tc_meta_512 │ └── tc_meta_512.xci ├── scripts ├── add-license.sh ├── capture.sh ├── custom-ring-setup.sh ├── disable-mellanox-shell-credits.sh ├── dump-flow-table.sh ├── fpga-debug-mode.sh ├── fpga-load.sh ├── fpga-status.sh ├── fpga.inc.sh ├── mellanox-shell-scripts.patch ├── mlx_ip.sh ├── mlx_netdev.sh ├── packets_stats.sh ├── pkt-drop-rate-measure.sh ├── pktgen_scripts │ ├── get_rx_throughput.sh │ ├── get_tx_throughput.sh │ ├── ipktgen.sh │ ├── kill_sockperf_client.sh │ ├── manual_ikernel_pktgen.sh │ ├── packets_stats.sh │ ├── plot_bar.py │ ├── run_experiments.sh │ ├── run_sockperf_client.sh │ ├── run_variable_tokens.sh │ └── send_packets_pktgen.sh ├── prepare-mellanox-shell.sh ├── register.sh ├── reset-fpga.sh ├── run_client.sh ├── run_cms.sh ├── run_echo.sh ├── run_threshold.sh ├── sha256.py ├── start-tools.sh ├── udp_client.py ├── update-mellanox-shell-scripts-patch.sh └── watch-counter.sh └── software ├── .gitignore ├── CMakeLists.txt ├── CmsServerMain.cpp ├── CmsUdpServer.cpp ├── CmsUdpServer.hpp ├── EchoServerMain.cpp ├── EchoUdpServer.cpp ├── EchoUdpServer.hpp ├── RunnableServerBase.cpp ├── RunnableServerBase.hpp ├── RunnableUdpClient.cpp ├── StatisticsUdpServer.cpp ├── StatisticsUdpServer.hpp ├── ThresholdServerMain.cpp ├── UdpClient.cpp ├── UdpClient.hpp ├── UdpServer.cpp ├── UdpServer.hpp ├── run-servers ├── run-servers-vma └── run-vma /.github/workflows/ansible-lint.yml: -------------------------------------------------------------------------------- 1 | name: Ansible Lint # feel free to pick your own name 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | # Important: This sets up your GITHUB_WORKSPACE environment variable 12 | - uses: actions/checkout@v2 13 | 14 | - name: Lint Ansible Playbook 15 | # replace "master" with any valid ref 16 | uses: ansible/ansible-lint-action@master 17 | with: 18 | # [required] 19 | # Paths to ansible files (i.e., playbooks, tasks, handlers etc..) 20 | # or valid Ansible directories according to the Ansible role 21 | # directory structure. 22 | # If you want to lint multiple ansible files, use the following syntax 23 | # targets: | 24 | # playbook_1.yml 25 | # playbook_2.yml 26 | targets: "ansible/" 27 | # [optional] 28 | # Arguments to override a package and its version to be set explicitly. 29 | # Must follow the example syntax. 30 | # override-deps: | 31 | # ansible==4.7 32 | # ansible-lint==5.2.1 33 | # [optional] 34 | # Arguments to be passed to the ansible-lint 35 | 36 | # Options: 37 | # -q quieter, although not silent output 38 | # -p parseable output in the format of pep8 39 | # --parseable-severity parseable output including severity of rule 40 | # -r RULESDIR specify one or more rules directories using one or 41 | # more -r arguments. Any -r flags override the default 42 | # rules in ansiblelint/rules, unless -R is also used. 43 | # -R Use default rules in ansiblelint/rules in addition to 44 | # any extra 45 | # rules directories specified with -r. There is no need 46 | # to specify this if no -r flags are used 47 | # -t TAGS only check rules whose id/tags match these values 48 | # -x SKIP_LIST only check rules whose id/tags do not match these 49 | # values 50 | # --nocolor disable colored output 51 | # --exclude=EXCLUDE_PATHS 52 | # path to directories or files to skip. This option is 53 | # repeatable. 54 | # -c C Specify configuration file to use. Defaults to ".ansible-lint" 55 | args: "" 56 | 57 | 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | tests/netperf_tb 3 | test_project 4 | export_project 5 | threshold/ 6 | tags 7 | \#*\# 8 | *~ 9 | .*.swp 10 | vivado_hls.log 11 | temp.log 12 | *.pyc 13 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ntl"] 2 | path = ntl 3 | url = https://github.com/acsl-technion/ntl 4 | [submodule "ansible/roles/mlnx-ofed"] 5 | path = ansible/roles/mlnx-ofed 6 | url = https://github.com/haggaie/ansible-role-mlnx-ofed 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /ansible/nica.yml: -------------------------------------------------------------------------------- 1 | # Example playbook for NICA 2 | - hosts: all 3 | become: yes 4 | roles: 5 | - nica 6 | -------------------------------------------------------------------------------- /ansible/roles/nica/.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - '403' # Package installs should not use latest 3 | -------------------------------------------------------------------------------- /ansible/roles/nica/README.md: -------------------------------------------------------------------------------- 1 | Role Name 2 | ========= 3 | 4 | A brief description of the role goes here. 5 | 6 | Requirements 7 | ------------ 8 | 9 | Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. 10 | 11 | Role Variables 12 | -------------- 13 | 14 | A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. 15 | 16 | Dependencies 17 | ------------ 18 | 19 | A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. 20 | 21 | Example Playbook 22 | ---------------- 23 | 24 | Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: 25 | 26 | - hosts: servers 27 | roles: 28 | - { role: username.rolename, x: 42 } 29 | 30 | License 31 | ------- 32 | 33 | BSD 34 | 35 | Author Information 36 | ------------------ 37 | 38 | An optional section for the role authors to include contact information, or a website (HTML is not allowed). 39 | -------------------------------------------------------------------------------- /ansible/roles/nica/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for nica -------------------------------------------------------------------------------- /ansible/roles/nica/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for nica -------------------------------------------------------------------------------- /ansible/roles/nica/meta/main.yml: -------------------------------------------------------------------------------- 1 | galaxy_info: 2 | role_name: nica 3 | namespace: haggaie 4 | author: Haggai Eran 5 | description: PhD student 6 | company: Technion 7 | 8 | # If the issue tracker for your role is not on github, uncomment the 9 | # next line and provide a value 10 | # issue_tracker_url: http://example.com/issue/tracker 11 | 12 | # Some suggested licenses: 13 | # - BSD (default) 14 | # - MIT 15 | # - GPLv2 16 | # - GPLv3 17 | # - Apache 18 | # - CC-BY 19 | license: BSD 20 | 21 | min_ansible_version: 1.2 22 | 23 | # If this a Container Enabled role, provide the minimum Ansible Container version. 24 | # min_ansible_container_version: 25 | 26 | # Optionally specify the branch Galaxy will use when accessing the GitHub 27 | # repo for this role. During role install, if no tags are available, 28 | # Galaxy will use this branch. During import Galaxy will access files on 29 | # this branch. If Travis integration is configured, only notifications for this 30 | # branch will be accepted. Otherwise, in all cases, the repo's default branch 31 | # (usually master) will be used. 32 | #github_branch: 33 | 34 | # 35 | # platforms is a list of platforms, and each platform has a name and a list of versions. 36 | # 37 | platforms: 38 | - name: Ubuntu 39 | versions: 40 | - bionic 41 | - focal 42 | - name: CentOS 43 | versions: 44 | - 7 45 | 46 | galaxy_tags: [] 47 | # List tags for your role here, one per line. A tag is a keyword that describes 48 | # and categorizes the role. Users find roles by searching for tags. Be sure to 49 | # remove the '[]' above, if you add tags to this list. 50 | # 51 | # NOTE: A tag is limited to a single word comprised of alphanumeric characters. 52 | # Maximum 20 tags per role. 53 | 54 | dependencies: 55 | - src: https://github.com/haggaie/ansible-role-mlnx-ofed/ 56 | name: haggaie.mlnx_ofed 57 | 58 | -------------------------------------------------------------------------------- /ansible/roles/nica/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for nica 3 | - name: Include OS-specific variables 4 | include_vars: "{{ ansible_os_family }}.yml" 5 | 6 | - name: NICA rpm dependencies 7 | package: 8 | name: 9 | - cmake3 10 | - libuuid-devel 11 | - python36-pip 12 | - python36-scapy 13 | - boost-devel 14 | - libpcap-devel 15 | when: ansible_os_family == 'RedHat' 16 | 17 | - name: NICA deb dependencies 18 | package: 19 | name: 20 | - cmake 21 | - uuid-dev 22 | - python3-pip 23 | - python3-scapy 24 | - libboost-all-dev 25 | - libcap-dev 26 | state: latest 27 | when: ansible_os_family == 'Debian' 28 | 29 | - name: NICA pip dependencies 30 | pip: 31 | executable: "{{ pip.executable }}" 32 | name: pyinterval 33 | -------------------------------------------------------------------------------- /ansible/roles/nica/tests/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | 3 | -------------------------------------------------------------------------------- /ansible/roles/nica/tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | remote_user: root 4 | roles: 5 | - nica -------------------------------------------------------------------------------- /ansible/roles/nica/vars/Debian.yml: -------------------------------------------------------------------------------- 1 | pip: 2 | executable: pip3 3 | -------------------------------------------------------------------------------- /ansible/roles/nica/vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | pip: 2 | executable: pip3.6 3 | -------------------------------------------------------------------------------- /ansible/roles/nica/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for nica 3 | -------------------------------------------------------------------------------- /cmake/Modules/FindPylint.cmake: -------------------------------------------------------------------------------- 1 | # https://stackoverflow.com/questions/44740414/cmake-check-if-pylint-is-installed 2 | 3 | # - Find Pylint 4 | # Find the Pylint executable and extract the version number 5 | # 6 | # OUTPUT Variables 7 | # 8 | # PYLINT_FOUND 9 | # True if the pylint package was found 10 | # PYLINT_EXECUTABLE 11 | # The pylint executable location 12 | # PYLINT_VERSION 13 | # A string denoting the version of pylint that has been found 14 | 15 | find_program ( PYLINT_EXECUTABLE NAMES pylint pylint-3 PATHS /usr/bin ) 16 | 17 | if ( PYLINT_EXECUTABLE ) 18 | execute_process ( COMMAND ${PYLINT_EXECUTABLE} --version OUTPUT_VARIABLE PYLINT_VERSION_RAW ERROR_QUIET ) 19 | if (PYLINT_VERSION_RAW) 20 | string ( REGEX REPLACE "^pylint ([0-9]+.[0-9]+.[0-9]+),.*" "\\1" PYLINT_VERSION ${PYLINT_VERSION_RAW}) 21 | else () 22 | set ( PYLINT_VERSION "unknown" ) 23 | endif() 24 | endif () 25 | 26 | include(FindPackageHandleStandardArgs) 27 | FIND_PACKAGE_HANDLE_STANDARD_ARGS ( Pylint DEFAULT_MSG PYLINT_EXECUTABLE ) 28 | 29 | mark_as_advanced ( PYLINT_EXECUTABLE PYLINT_VERSION ) 30 | -------------------------------------------------------------------------------- /cmake/Modules/Findibverbs.cmake: -------------------------------------------------------------------------------- 1 | # Find the ibverbs libraries 2 | # 3 | # The following variables are optionally searched for defaults 4 | # IBVERBS_ROOT_DIR: Base directory where all ibverbs components are found 5 | # IBVERBS_INCLUDE_DIR: Directory where ibverbs headers are found 6 | # IBVERBS_LIB_DIR: Directory where ibverbs libraries are found 7 | 8 | # The following are set after configuration is done: 9 | # IBVERBS_FOUND 10 | # IBVERBS_INCLUDE_DIRS 11 | # IBVERBS_LIBRARIES 12 | 13 | find_path(IBVERBS_INCLUDE_DIRS 14 | NAMES infiniband/verbs.h 15 | HINTS 16 | ${IBVERBS_INCLUDE_DIR} 17 | ${IBVERBS_ROOT_DIR} 18 | ${IBVERBS_ROOT_DIR}/include) 19 | 20 | find_library(IBVERBS_LIBRARIES 21 | NAMES ibverbs 22 | HINTS 23 | ${IBVERBS_LIB_DIR} 24 | ${IBVERBS_ROOT_DIR} 25 | ${IBVERBS_ROOT_DIR}/lib) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(ibverbs DEFAULT_MSG IBVERBS_INCLUDE_DIRS IBVERBS_LIBRARIES) 29 | mark_as_advanced(IBVERBS_INCLUDE_DIR IBVERBS_LIBRARIES) 30 | -------------------------------------------------------------------------------- /emulation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Emulation library 2 | add_library(nica-emu SHARED emu-top.cpp) 3 | include_directories(../nica/hls ../ikernels/hls) 4 | target_link_libraries(nica-emu nica-csim) 5 | set(ikernels threshold passthrough pktgen memcached coap) 6 | foreach(ikernel ${ikernels}) 7 | target_link_libraries(nica-emu ${ikernel}-emu) 8 | endforeach(ikernel) 9 | target_compile_features(nica-emu PRIVATE cxx_constexpr) 10 | -------------------------------------------------------------------------------- /emulation/emu.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include 27 | #include 28 | 29 | namespace emulation { 30 | 31 | void step(); 32 | 33 | void reg_read(uint32_t address, uint32_t* value); 34 | void reg_write(uint32_t address, uint32_t value); 35 | 36 | enum interface { 37 | Net = 1, 38 | Host = 2, 39 | }; 40 | 41 | struct packet { 42 | interface dir; 43 | char *data; 44 | size_t len; 45 | }; 46 | 47 | void send_packet(const packet* pkt); 48 | 49 | packet* get_packet(); 50 | } 51 | -------------------------------------------------------------------------------- /ikernels/hls/cms-ikernel.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef CMS_IKERNEL_HPP 27 | #define CMS_IKERNEL_HPP 28 | 29 | // e805b0d0-79ba-4c5d-b975-45316e452672 30 | #define CMS_UUID { 0xe8, 0x05, 0xb0, 0xd0, 0x79, 0xba, 0x4c, 0x5d, 0xb9, 0x75, 0x45, 0x31, 0x6e, 0x45, 0x26, 0x72 } 31 | 32 | #define READ_TOP_K 0 33 | #define TOPK_READ_NEXT_VALUE 1 34 | #define READ_K_VALUE 2 35 | #define HASHES_BASE 3 36 | 37 | #endif //CMS_IKERNEL_HPP 38 | -------------------------------------------------------------------------------- /ikernels/hls/cms-impl.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include "cms-ikernel.hpp" 29 | #include "cms.hpp" 30 | #include 31 | #include 32 | 33 | typedef ap_uint<32> value; 34 | 35 | struct value_and_frequency { 36 | value entity; 37 | value frequency; 38 | }; 39 | 40 | void cms_ikernel(hls_ik::ports& ik, hls_ik::ikernel_id& uuid, 41 | hls_ik::virt_gateway_registers& gateway, 42 | value_and_frequency& to_heap, 43 | hls::stream& heap_out, 44 | ap_uint<32> k_value, 45 | hls_ik::tc_ikernel_data_counts& tc); 46 | 47 | class cms : public hls_ik::ikernel { 48 | public: 49 | 50 | void step(hls_ik::ports& ports, hls_ik::tc_ikernel_data_counts& tc); 51 | int reg_write(int address, int value, hls_ik::ikernel_id_t ikernel_id); 52 | int reg_read(int address, int* value, hls_ik::ikernel_id_t ikernel_id); 53 | 54 | void write_to_heap(value_and_frequency& kv); 55 | void read_heap(hls::stream& heap_out, ap_uint<32> k_value); 56 | 57 | protected: 58 | enum { METADATA, FIRST_WORD, OTHER_WORDS } _state; 59 | enum { INITIAL, ENTITY, FREQUENCY } _read_state; 60 | 61 | hls::stream _values_stream; 62 | hls::stream _hashes_addresses; 63 | hls::stream _hashes_values; 64 | hls::stream _topK_read_request; 65 | hls::stream _topK_values; 66 | 67 | bool _reading_heap; 68 | unsigned _reading_index, _k; 69 | value_and_frequency _next_topK_pair; 70 | 71 | CountMinSketch sketch; 72 | 73 | void net_ingress(hls_ik::pipeline_ports&); 74 | }; 75 | 76 | -------------------------------------------------------------------------------- /ikernels/hls/cms.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef CMS_HPP 27 | #define CMS_HPP 28 | 29 | /** 30 | Daniel Alabi 31 | Count-Min Sketch Implementation based on paper by 32 | Muthukrishnan and Cormode, 2004 33 | https://github.com/alabid/countminsketch 34 | **/ 35 | 36 | #include 37 | #include 38 | 39 | // define some constants 40 | # define LONG_PRIME 32993 41 | # define ERROR 0.01 // 0.01 < ERROR < 1 42 | # define GAMMA 0.1 // probability for accuracy, 0 < gamma < 1 43 | # define WIDTH 272 44 | # define DEPTH 3 45 | 46 | // The WIDTH and DEPTH parameters are hardcoded due to HLS limitations 47 | //const unsigned int WIDTH = std::ceil(exp(1)/ERROR); 48 | //const unsigned int DEPTH = std::ceil(log(1/GAMMA)); 49 | 50 | /** CountMinSketch class definition here **/ 51 | struct CountMinSketch { 52 | // aj, bj \in Z_p 53 | // both elements of fild Z_p used in generation of hash 54 | // function 55 | unsigned int aj, bj; 56 | 57 | // total count so far 58 | unsigned int total; 59 | 60 | // array of arrays of counters 61 | int C[DEPTH][WIDTH]; 62 | 63 | // array of hash values for a particular item 64 | // contains two element arrays {aj,bj} 65 | int hashes[DEPTH][2]; 66 | 67 | // constructor 68 | CountMinSketch(); 69 | 70 | void setHashes(int hashes[DEPTH][2]); 71 | int getCell(const int row, const int col) const; 72 | 73 | // update item (int) by count c 74 | void update(int item, int c); 75 | // update item (string) by count c 76 | void update(const char *item, int c); 77 | 78 | // directly increase a specific counter 79 | void updateByAddress(int address, int value); 80 | 81 | // estimate count of item i and return count 82 | unsigned int estimate(int item); 83 | unsigned int estimate(const char *item); 84 | 85 | // return total count 86 | unsigned int totalcount(); 87 | 88 | // generates a hash value for a string 89 | // same as djb2 hash function 90 | unsigned int hashstr(const char *str); 91 | 92 | static void generateHashes(int hashes[DEPTH][2]); 93 | 94 | // destructor 95 | ~CountMinSketch(); 96 | }; 97 | 98 | #endif //CMS_HPP 99 | -------------------------------------------------------------------------------- /ikernels/hls/echo-impl.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include "echo.hpp" 29 | 30 | // 6d1efc9b-8655-42d7-8000-9e3e998dbd5c 31 | #include 32 | #include 33 | #include 34 | 35 | class echo : public hls_ik::ikernel { 36 | public: 37 | echo(); 38 | 39 | void step(hls_ik::ports& p, hls_ik::tc_ikernel_data_counts& tc); 40 | 41 | int reg_write(int address, int value, hls_ik::ikernel_id_t ikernel_id); 42 | int reg_read(int address, int* value, hls_ik::ikernel_id_t ikernel_id); 43 | 44 | private: 45 | void echo_pipeline(hls_ik::ports& p, hls_ik::tc_ikernel_data_counts& tc); 46 | 47 | enum { METADATA, DATA } state; 48 | /* First data word */ 49 | bool first; 50 | /* Respond to the current packet */ 51 | bool respond; 52 | /* Metadata of the current packet */ 53 | hls_ik::metadata metadata; 54 | 55 | hls::stream port_dummy_update; 56 | 57 | /* By default, respond to all packets. When true, respond to sockperf 58 | * packets with "pong" requests. */ 59 | bool respond_to_sockperf; 60 | /* A register with the gateway exposed value. */ 61 | bool respond_to_sockperf_cache; 62 | /* Updates from the gateway */ 63 | hls::stream respond_to_sockperf_update; 64 | }; 65 | 66 | DECLARE_TOP_FUNCTION(echo_top); 67 | -------------------------------------------------------------------------------- /ikernels/hls/echo.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef ECHO_HPP 27 | #define ECHO_HPP 28 | 29 | // 6d1efc9b-8655-42d7-8000-9e3e998dbd5c 30 | #define ECHO_UUID { 0x6d, 0x1e, 0xfc, 0x9b, 0x86, 0x55, 0x42, 0xd7, 0x80, 0x00, 0x9e, 0x3e, 0x99, 0x8d, 0xbd, 0x5c } 31 | 32 | #define LOG_NUM_ECHO_CONTEXTS 6 33 | 34 | #define ECHO_RESPOND_TO_SOCKPERF 0 35 | 36 | #endif // ECHO_HPP 37 | -------------------------------------------------------------------------------- /ikernels/hls/passthrough-impl.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef PASSTHROUGH_IMPL_HPP 27 | #define PASSTHROUGH_IMPL_HPP 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #define LOG_NUM_PASSTHROUGH_CONTEXTS 6 35 | #define NUM_PASSTHROUGH_CONTEXTS (1 << LOG_NUM_PASSTHROUGH_CONTEXTS) 36 | 37 | #include "passthrough.hpp" 38 | 39 | DECLARE_TOP_FUNCTION(passthrough_top); 40 | 41 | struct passthrough_context { 42 | passthrough_context() : ring_id(0), ignore_credits(false) {} 43 | 44 | hls_ik::ring_id_t ring_id; 45 | bool ignore_credits; 46 | }; 47 | 48 | class passthrough_contexts : public ntl::context_manager 49 | { 50 | public: 51 | int rpc(int address, int *value, hls_ik::ikernel_id_t ikernel_id, bool read); 52 | }; 53 | 54 | class passthrough : public hls_ik::ikernel 55 | { 56 | public: 57 | int reg_write(int address, int value, hls_ik::ikernel_id_t ikernel_id); 58 | int reg_read(int address, int* value, hls_ik::ikernel_id_t ikernel_id); 59 | void step(hls_ik::ports& p, hls_ik::tc_ikernel_data_counts& tc); 60 | protected: 61 | enum { DECISION, STREAM } _state; 62 | 63 | hls::stream _decisions; 64 | drop_or_pass dropper; 65 | void intercept_in(hls_ik::pipeline_ports& p, hls_ik::tc_pipeline_data_counts& tc); 66 | passthrough_contexts contexts; 67 | }; 68 | 69 | #endif // PASSTHROUGH_IMPL_HPP 70 | -------------------------------------------------------------------------------- /ikernels/hls/passthrough.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef PASSTHROUGH_HPP 27 | #define PASSTHROUGH_HPP 28 | 29 | // 38a8ea3c-cf7d-4bfb-abe0-ebe355cc948d 30 | #define PASSTHROUGH_UUID { 0x38,0xa8,0xea,0x3c,0xcf,0x7d,0x4b,0xfb,0xab,0xe0,0xeb,0xe3,0x55,0xcc,0x94,0x8d } 31 | 32 | #define PASSTHROUGH_RING_ID 0x10 33 | #define PASSTHROUGH_IGNORE_CREDITS 0x11 34 | 35 | #endif // PASSTHROUGH_HPP 36 | -------------------------------------------------------------------------------- /ikernels/hls/pktgen.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef PKTGEN_HPP 27 | #define PKTGEN_HPP 28 | 29 | // 2f8e8996-1b5e-4c02-908c-0f2878b0d4e4 30 | #define PKTGEN_UUID { 0x2f, 0x8e, 0x89, 0x96, 0x1b, 0x5e, 0x4c, 0x02, 0x90, 0x8c, 0x0f, 0x28, 0x78, 0xb0, 0xd4, 0xe4 } 31 | 32 | /* Number of packets to send on each burst */ 33 | #define PKTGEN_BURST_SIZE 0x10 34 | /* Current packet (R/O) (goes down from burst size to zero) */ 35 | #define PKTGEN_CUR_PACKET 0x11 36 | 37 | #define PKTGEN_SCHEDULER 0x20 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /ikernels/hls/tests/cache_tests.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #define CACHE_ENABLE_DEBUG_COMMANDS 27 | 28 | #include 29 | #include "gtest/gtest.h" 30 | 31 | namespace ntl { 32 | 33 | #define CACHE_SIZE 10 34 | 35 | class CacheTest : public testing::Test { 36 | protected: 37 | // SetUp() is run immediately before a test starts. 38 | virtual void SetUp() { 39 | } 40 | 41 | // TearDown() is invoked immediately after a test finishes. 42 | virtual void TearDown() { 43 | _cache = cache(); 44 | } 45 | 46 | cache _cache; 47 | }; 48 | 49 | TEST_F(CacheTest, insert) { 50 | for (int i = 0; i < CACHE_SIZE; ++i) { 51 | ASSERT_TRUE(_cache.insert(i, i)); 52 | } 53 | 54 | ASSERT_FALSE(_cache.insert(CACHE_SIZE + 1, CACHE_SIZE + 1)); 55 | } 56 | 57 | TEST_F(CacheTest, find) { 58 | ASSERT_TRUE(_cache.insert(0, 0)); 59 | 60 | ASSERT_TRUE(_cache.find(0).valid()); 61 | ASSERT_EQ(0, _cache.find(0).value()); 62 | 63 | ASSERT_FALSE(_cache.find(1).valid()); 64 | } 65 | 66 | // h(key) returns key % CACHE_SIZE 67 | // This test makes sure that the linear probing implementation 68 | // indeed moves a key in order to fill the hole and support correct 69 | // lookup after a key is removed from the cache 70 | TEST_F(CacheTest, erase) { 71 | ASSERT_TRUE(_cache.insert(0, 0)); 72 | ASSERT_TRUE(_cache.insert(CACHE_SIZE, 0)); 73 | ASSERT_TRUE(_cache.insert(2*CACHE_SIZE, 0)); 74 | 75 | ASSERT_TRUE(_cache.erase(CACHE_SIZE)); 76 | 77 | ASSERT_TRUE(_cache.find(0).valid()); 78 | ASSERT_TRUE(_cache.find(2*CACHE_SIZE).valid()); 79 | } 80 | } 81 | 82 | int main(int argc, char **argv) { 83 | testing::InitGoogleTest(&argc, argv); 84 | return RUN_ALL_TESTS(); 85 | } 86 | -------------------------------------------------------------------------------- /ikernels/hls/tests/cms.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/cms.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/cms_tests.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "cms.hpp" 27 | #include "gtest/gtest.h" 28 | 29 | namespace { 30 | 31 | // The fixture for testing class CMS. 32 | class cms_tests : public ::testing::Test { 33 | protected: 34 | int hashes[DEPTH][2]; 35 | CountMinSketch sketch; 36 | 37 | cms_tests() : hashes() {} 38 | 39 | virtual ~cms_tests() {} 40 | 41 | virtual void SetUp() { 42 | CountMinSketch::generateHashes(hashes); 43 | sketch = CountMinSketch(); 44 | sketch.setHashes(hashes); 45 | } 46 | 47 | virtual void TearDown() { 48 | } 49 | 50 | }; 51 | 52 | 53 | TEST_F(cms_tests, EstimateIntegers) { 54 | sketch.update(1, 3); 55 | sketch.update(2, 2); 56 | sketch.update(3, 1); 57 | sketch.update(1, 1); 58 | 59 | EXPECT_EQ(sketch.estimate(1), 3 + 1); 60 | EXPECT_EQ(sketch.estimate(2), 2); 61 | EXPECT_EQ(sketch.estimate(3), 1); 62 | EXPECT_EQ(sketch.estimate(29), 0); 63 | } 64 | 65 | TEST_F(cms_tests, EstimateStrings) { 66 | sketch.update("hello", 1); 67 | sketch.update("world", 2); 68 | sketch.update("hello", 4); 69 | sketch.update(",", 29); 70 | sketch.update("!", 2); 71 | 72 | EXPECT_EQ(sketch.estimate("hello"), 1 + 4); 73 | EXPECT_EQ(sketch.estimate("world"), 2); 74 | EXPECT_EQ(sketch.estimate(","), 29); 75 | EXPECT_EQ(sketch.estimate("!"), 2); 76 | EXPECT_EQ(sketch.estimate("ikernel"), 0); 77 | } 78 | 79 | } // namespace 80 | 81 | int main(int argc, char **argv) { 82 | testing::InitGoogleTest(&argc, argv); 83 | return RUN_ALL_TESTS(); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /ikernels/hls/tests/coap-filtered.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/coap-filtered.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/coap-requests.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/coap-requests.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-all-responses-16.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-all-responses-16.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-all-responses.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-all-responses.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-requests-16.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-requests-16.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-requests.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-requests.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-responses-16.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-responses-16.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-responses.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-responses.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/memcached-set-16.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/memcached-set-16.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/passthrough_tests.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "ikernel_tests.hpp" 27 | #include "passthrough-impl.hpp" 28 | 29 | using namespace hls_ik; 30 | 31 | namespace { 32 | 33 | class passthrough_test : public ikernel_test 34 | { 35 | public: 36 | passthrough_test() : ikernel_test(15) 37 | {} 38 | }; 39 | 40 | INSTANTIATE_TEST_CASE_P(ikernel_test_instance, all_ikernels_test, 41 | ::testing::Values(&passthrough_top)); 42 | 43 | TEST_P(passthrough_test, custom_ring) { 44 | metadata m; 45 | packet_metadata pkt; 46 | pkt.eth_dst = 1; 47 | pkt.eth_src = 2; 48 | pkt.ip_dst = 3; 49 | pkt.ip_src = 4; 50 | pkt.udp_dst = 5; 51 | pkt.udp_src = 6; 52 | m.set_packet_metadata(pkt); 53 | m.length = 32; 54 | m.ikernel_id = 1; 55 | m.flow_id = 2; 56 | 57 | write(PASSTHROUGH_RING_ID, 1, m.ikernel_id); 58 | 59 | const int total = 100; 60 | update_credits(1, total); 61 | std::vector vec; 62 | 63 | for (int i = 0; i < total; ++i) { 64 | p.net.metadata_input.write(m); 65 | ap_uint<32> rand_val = rand();//(rand()%100); 66 | // cout << "[" << i << "] : " << rand_val << "\n"; 67 | ap_uint<256> data = (ap_uint<14*8>(0),ap_uint<32>(rand_val), ap_uint<256 - 32 - 14*8>(0)); 68 | axi_data d(data, 0xffffffff, true); 69 | vec.push_back(d); 70 | p.net.data_input.write(d); 71 | 72 | for (int i = 0; i < 10; ++i) 73 | top(); 74 | } 75 | 76 | for (int i = 0; i < total; ++i) { 77 | m = p.net.metadata_output.read(); 78 | EXPECT_EQ(m.ring_id, 1) << i; 79 | EXPECT_EQ(m.get_custom_ring_metadata().end_of_message, true) << i; 80 | EXPECT_EQ(m.ikernel_id, 1) << i; 81 | EXPECT_EQ(m.flow_id, 2) << i; 82 | EXPECT_EQ(vec[i], axi_data(p.net.data_output.read())) << i; 83 | } 84 | } 85 | 86 | INSTANTIATE_TEST_CASE_P(passthrough_test_instance, passthrough_test, 87 | ::testing::Values(&passthrough_top)); 88 | 89 | } // namespace 90 | 91 | int main(int argc, char **argv) { 92 | testing::InitGoogleTest(&argc, argv); 93 | return RUN_ALL_TESTS(); 94 | } 95 | 96 | 97 | -------------------------------------------------------------------------------- /ikernels/hls/tests/ping.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/ping.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/pong.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/pong.pcap -------------------------------------------------------------------------------- /ikernels/hls/tests/udp_rr.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/ikernels/hls/tests/udp_rr.pcap -------------------------------------------------------------------------------- /ikernels/hls/threshold-impl.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "threshold.hpp" 35 | 36 | DECLARE_TOP_FUNCTION(threshold_top); 37 | 38 | typedef ap_uint<32> value; 39 | 40 | struct threshold_context { 41 | threshold_context() : 42 | threshold_value(0), 43 | min(-1U), max(0), count(0), dropped(0), sum(0), 44 | ring_id(0) 45 | {} 46 | 47 | /** Used by net_ingress to determine whether packets should be passed or 48 | * dropped */ 49 | value threshold_value; 50 | value min, max, count, dropped, dropped_backpressure; 51 | ap_uint<64> sum; 52 | hls_ik::ring_id_t ring_id; 53 | }; 54 | 55 | class threshold_contexts : public ntl::context_manager 56 | { 57 | public: 58 | int rpc(int address, int *value, hls_ik::ikernel_id_t ikernel_id, bool read); 59 | 60 | hls_ik::ring_id_t find_ring(const hls_ik::ikernel_id_t& ikernel_id); 61 | }; 62 | 63 | class threshold : public hls_ik::ikernel { 64 | public: 65 | void step(hls_ik::ports& ports, hls_ik::tc_ikernel_data_counts& tc); 66 | int reg_write(int address, int value, hls_ik::ikernel_id_t ikernel_id); 67 | int reg_read(int address, int* value, hls_ik::ikernel_id_t ikernel_id); 68 | void update_stats(hls_ik::ikernel_id_t id, value v, bool drop, bool backpressure); 69 | 70 | protected: 71 | threshold_contexts contexts; 72 | 73 | void net_ingress(hls_ik::pipeline_ports& p, hls_ik::tc_pipeline_data_counts& tc); 74 | void parser(); 75 | void egress(); 76 | 77 | hls::stream parsed; 78 | hls_ik::data_stream data_dup_to_parser, data_dup_to_egress, 79 | _data_egress_to_filter; 80 | 81 | struct decision_t { 82 | value v; 83 | hls_ik::ring_id_t ring_id; 84 | }; 85 | hls::stream decisions; 86 | hls::stream _decision_pass; 87 | decision_t egress_last_decision; 88 | 89 | enum { FIRST, REST } parser_state; 90 | 91 | enum { IDLE, STREAM } egress_state; 92 | 93 | drop_or_pass _dropper; 94 | }; 95 | -------------------------------------------------------------------------------- /ikernels/hls/threshold.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef THRESHOLD_HPP 27 | #define THRESHOLD_HPP 28 | 29 | // 2b49fec3-d30c-464d-a6a1-171f9e4443f1 30 | #define THRESHOLD_UUID { 0x2b, 0x49, 0xfe, 0xc3, 0xd3, 0x0c, 0x46, 0x4d, 0xa6, 0xa1, 0x17, 0x1f, 0x9e, 0x44, 0x43, 0xf1 } 31 | 32 | #define THRESHOLD_MIN 0x10 33 | #define THRESHOLD_MAX 0x14 34 | #define THRESHOLD_COUNT 0x18 35 | #define THRESHOLD_SUM_LO 0x1c 36 | #define THRESHOLD_SUM_HI 0x20 37 | #define THRESHOLD_VALUE 0x24 38 | #define THRESHOLD_DROPPED 0x28 39 | #define THRESHOLD_DROPPED_BACKPRESSURE 0x29 40 | #define THRESHOLD_RING_ID 0x2c 41 | 42 | #define LOG_NUM_THRESHOLD_CONTEXTS 6 43 | #define NUM_THRESHOLD_CONTEXTS (1 << LOG_NUM_THRESHOLD_CONTEXTS) 44 | 45 | #endif // THRESHOLD_HPP 46 | -------------------------------------------------------------------------------- /ikernels/ikernel.tcl.in: -------------------------------------------------------------------------------- 1 | source "@CMAKE_SOURCE_DIR@/nica/ikernel.tcl" 2 | 3 | create_project @IKERNEL@ @IKERNEL_TOP@ @CMAKE_CURRENT_SOURCE_DIR@ {@IKERNEL_SOURCES@} \ 4 | {@IKERNEL_TESTBENCH_SOURCES@} 5 | exit 6 | -------------------------------------------------------------------------------- /libnica/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Emulation library 2 | find_package(Boost COMPONENTS thread filesystem REQUIRED) 3 | find_package(ibverbs REQUIRED) 4 | add_library(nica SHARED nica.cpp) 5 | include_directories(${UUID_INCLUDE_DIRS}) 6 | target_link_libraries(nica ${IBVERBS_LIBRARIES} ${UUID_LIBRARIES} ${Boost_THREAD_LIBRARY} ${Boost_FILESYSTEM_LIBRARY}) 7 | target_compile_features(nica PRIVATE cxx_rvalue_references) 8 | -------------------------------------------------------------------------------- /libnica/nicamgr.h: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation and/or 11 | * other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #pragma once 26 | 27 | /* NICA manager protocol definitions */ 28 | 29 | #define NICA_MANAGER_PATH "/var/run/nica-manager.socket" 30 | 31 | /* For IFNAMSIZ */ 32 | #include 33 | 34 | struct nicamgr_header { 35 | uint16_t opcode; 36 | uint16_t length; 37 | uint16_t flags; 38 | uint16_t status; 39 | }; 40 | 41 | enum nicamgr_opcode { 42 | NICA_IK_CREATE = 1, 43 | NICA_IK_DESTROY, 44 | NICA_IK_RPC, 45 | NICA_IK_ATTACH, 46 | NICA_IK_DETACH, 47 | NICA_CR_CREATE, 48 | NICA_CR_DESTROY, 49 | NICA_CR_UPDATE_CREDITS, 50 | NICA_IK_CREATE_ATTRS, 51 | }; 52 | 53 | enum { 54 | /* Request have this bit set, responses have it cleared. */ 55 | NICA_MANAGER_FLAG_REQUEST = 1 << 0, 56 | }; 57 | 58 | struct nica_req_ik_create { 59 | char netdev[IFNAMSIZ]; 60 | uuid_t uuid; 61 | }; 62 | 63 | struct nica_resp_ik_create { 64 | uint32_t ik; 65 | }; 66 | 67 | struct nica_req_ik_create_attrs { 68 | uint32_t size; 69 | char netdev[IFNAMSIZ]; 70 | uuid_t uuid; 71 | uint32_t log_dram_size; 72 | }; 73 | 74 | struct nica_resp_ik_create_attrs { 75 | uint32_t size; 76 | uint32_t ik; 77 | }; 78 | 79 | struct nica_req_ik_destroy { 80 | uint32_t ik; 81 | }; 82 | 83 | struct nica_resp_ik_destroy { 84 | uint32_t reserved; 85 | }; 86 | 87 | struct nica_req_ik_attach { 88 | uint32_t ik; 89 | /* Send the socket file descriptor over SCM_RIGHTS */ 90 | }; 91 | 92 | struct nica_resp_ik_attach { 93 | uint32_t h2n_flow_id; 94 | uint32_t n2h_flow_id; 95 | }; 96 | 97 | struct nica_req_ik_detach { 98 | uint32_t ik; 99 | /* Send the socket file descriptor over SCM_RIGHTS */ 100 | }; 101 | 102 | struct nica_resp_ik_detach { 103 | uint32_t reserved; 104 | }; 105 | 106 | struct nica_req_ik_rpc { 107 | uint32_t ik; 108 | int address; 109 | int value; 110 | int write; 111 | }; 112 | 113 | struct nica_resp_ik_rpc { 114 | int value; 115 | }; 116 | 117 | struct nica_req_cr_create { 118 | uint32_t ik; 119 | uint32_t qp_num; 120 | }; 121 | 122 | struct nica_resp_cr_create { 123 | uint32_t cr; 124 | }; 125 | 126 | struct nica_req_cr_destroy { 127 | uint32_t cr; 128 | }; 129 | 130 | struct nica_resp_cr_destroy { 131 | uint32_t reserved; 132 | }; 133 | 134 | struct nica_req_cr_update_credits { 135 | uint32_t cr; 136 | uint32_t credits; 137 | }; 138 | 139 | struct nica_resp_cr_update_credits { 140 | uint32_t reserved; 141 | }; 142 | -------------------------------------------------------------------------------- /manager/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Pylint) 2 | 3 | if(Pylint_FOUND) 4 | add_custom_target(pylint ALL 5 | ${CMAKE_CURRENT_SOURCE_DIR}/pylint.sh ${PYLINT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/nica_manager.py ${CMAKE_CURRENT_SOURCE_DIR}/nica.py) 6 | endif() 7 | -------------------------------------------------------------------------------- /manager/README.md: -------------------------------------------------------------------------------- 1 | # NICA manager 2 | 3 | ## Dependencies 4 | 5 | Install Python 3 and netifaces module 6 | 7 | ``` 8 | sudo yum -y install epel-release && sudo yum -y install python34 python34-pip python34-devel 9 | sudo pip3 install netifaces pyinterval 10 | ``` 11 | -------------------------------------------------------------------------------- /manager/idpool.py: -------------------------------------------------------------------------------- 1 | # https://gist.github.com/sunetos/1068329 2 | 3 | __author__ = 'Adam R. Smith' 4 | 5 | import errno 6 | 7 | class IDPool(object): 8 | ''' 9 | Create a pool of IDs to allow reuse. The "new_id" function generates the next 10 | valid ID from the previous one. If not given, defaults to incrementing an integer. 11 | ''' 12 | 13 | def __init__(self, min_id=-1, max_id=None, new_id=None): 14 | self.max_id = max_id 15 | if new_id is None: new_id = lambda x: x + 1 16 | 17 | self.ids_in_use = set() 18 | self.ids_free = set() 19 | self.new_id = new_id 20 | self.last_id = min_id 21 | 22 | def get_id(self, condition=lambda _: True): 23 | filtered_free = [id_ for id_ in self.ids_free if condition(id_)] 24 | if len(filtered_free) > 0: 25 | id_ = filtered_free[0] 26 | self.ids_free.remove(id_) 27 | else: 28 | id_ = self.new_id(self.last_id) 29 | self.last_id = id_ 30 | while not condition(id_): 31 | prev = id_ 32 | id_ = self.new_id(self.last_id) 33 | self.last_id = id_ 34 | self.ids_free.add(prev) 35 | if self.max_id and id_ >= self.max_id: 36 | raise OSError(errno.ENOSPC) 37 | self.ids_in_use.add(id_) 38 | return id_ 39 | 40 | def release_id(self, the_id): 41 | if the_id in self.ids_in_use: 42 | self.ids_in_use.remove(the_id) 43 | self.ids_free.add(the_id) 44 | 45 | if __name__ == '__main__': 46 | pool = IDPool() 47 | for i in range(5): 48 | print('got id: %d' % pool.get_id()) 49 | print('releasing id 3') 50 | pool.release_id(3) 51 | print('got id: %d' % pool.get_id()) 52 | print('got id: %d' % pool.get_id()) 53 | -------------------------------------------------------------------------------- /manager/memcached.py: -------------------------------------------------------------------------------- 1 | class Memcached(object): 2 | def __init__(self, nica): 3 | self.gw = nica.ikernel0 4 | 5 | MEMCACHED_REG_CACHE_SIZE = 0 6 | MEMCACHED_STATS_GET_REQUESTS = 0x10 7 | MEMCACHED_STATS_GET_REQUESTS_HITS = 0x11 8 | MEMCACHED_STATS_GET_REQUESTS_MISSES = 0x12 9 | MEMCACHED_STATS_SET_REQUESTS = 0x13 10 | MEMCACHED_STATS_N2H_UNKNOWN = 0x14 11 | MEMCACHED_STATS_GET_RESPONSE = 0x15 12 | MEMCACHED_STATS_H2N_UNKNOWN = 0x16 13 | MEMCACHED_DROPPED_BACKPRESSURE = 0x17 14 | MEMCACHED_RING_ID = 0x18 15 | MEMCACHED_STATS_GET_REQUESTS_DROPPED_HITS = 0x19 16 | MEMCACHED_STATS_DROPPED_TC_BACKPRESSURE = 0x20 17 | 18 | def set_ring_id(self, ikernel_id, ring_id, delay=None): 19 | self.gw.write(self.MEMCACHED_RING_ID, ring_id, ikernel_id=ikernel_id, 20 | delay=delay) 21 | 22 | def set_cache_size(self, ikernel_id, log_dram_size, delay=None): 23 | self.gw.write(self.MEMCACHED_REG_CACHE_SIZE, log_dram_size, 24 | ikernel_id=ikernel_id, delay=delay) 25 | -------------------------------------------------------------------------------- /manager/memcachedctl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | memcachedctl - CLI to access the memcached ikernel 5 | """ 6 | 7 | import argparse 8 | import os 9 | import sys 10 | from nica import NicaHardware, default_mst_device 11 | from memcached import Memcached 12 | 13 | # TODO control through NICA manager 14 | 15 | MST_DEVICE = default_mst_device() 16 | 17 | def define_parser(): 18 | '''Parse command line arguments.''' 19 | parser = argparse.ArgumentParser(description='Control NICA.') 20 | parser.add_argument('-d', metavar='DEVICE', dest='device', default=MST_DEVICE, 21 | help='MST device to use (default: {})'.format(MST_DEVICE)) 22 | parser.add_argument('-i,--ikernel', metavar='IKERNEL_ID', 23 | dest='ikernel_id', type=int, nargs='+', 24 | help='ikernel IDs to access') 25 | parser.add_argument('command', help='Subcommand to run') 26 | return parser 27 | 28 | PARSER = define_parser() 29 | 30 | def init_nica(): 31 | '''Initialize a Netdev object for the expected one underlying card.''' 32 | args = PARSER.parse_args() 33 | if os.path.exists(args.device): 34 | nica = NicaHardware(args.device) 35 | 36 | return nica, args 37 | 38 | # global NICA 39 | NICA, ARGS = init_nica() 40 | MEMCACHED = Memcached(NICA) 41 | 42 | def print_help(): 43 | '''Command line help''' 44 | PARSER.print_help() 45 | print('Commands:') 46 | print('\n'.join(COMMANDS.keys())) 47 | 48 | COUNTERS = [ 49 | ('get req.', Memcached.MEMCACHED_STATS_GET_REQUESTS), 50 | ('get req. hits', Memcached.MEMCACHED_STATS_GET_REQUESTS_HITS), 51 | ('dropped tc backpressure', Memcached.MEMCACHED_STATS_DROPPED_TC_BACKPRESSURE), 52 | ('get req. dropped hits', Memcached.MEMCACHED_STATS_GET_REQUESTS_DROPPED_HITS), 53 | ('get req. misses', Memcached.MEMCACHED_STATS_GET_REQUESTS_MISSES), 54 | ('dropped cr backpressure', Memcached.MEMCACHED_DROPPED_BACKPRESSURE), 55 | ('set req.', Memcached.MEMCACHED_STATS_SET_REQUESTS), 56 | ('unknown req.', Memcached.MEMCACHED_STATS_N2H_UNKNOWN), 57 | ('get resp.', Memcached.MEMCACHED_STATS_GET_RESPONSE), 58 | ('unknown resp.', Memcached.MEMCACHED_STATS_H2N_UNKNOWN), 59 | ] 60 | 61 | def reset(): 62 | '''Reset all counters of a given ikernel.''' 63 | for ikernel_id in ARGS.ikernel_id: 64 | for _, reg in COUNTERS: 65 | MEMCACHED.gw.write(reg, 0, ikernel_id=ikernel_id) 66 | print('Reset counters for ikernel: {}'.format(ikernel_id)) 67 | 68 | def status(): 69 | '''Print the current counters of a given ikernel.''' 70 | for ikernel_id in ARGS.ikernel_id: 71 | print('ikernel ID: {}\n'.format(ikernel_id)) 72 | namewidth = max(len(name) for name, _ in COUNTERS) + 2 73 | formatting_title = '{{:<{}}}{{:<{}}}'.format(namewidth, namewidth) 74 | print(formatting_title.format('Name', 'Value')) 75 | print('-' * (namewidth * 2)) 76 | for name, reg in COUNTERS: 77 | count = MEMCACHED.gw.read(reg, ikernel_id=ikernel_id) 78 | print(formatting_title.format(name, count)) 79 | print('-' * (namewidth * 2) + '\n') 80 | 81 | COMMANDS = { 82 | 'help': print_help, 83 | 'reset': reset, 84 | 'status': status, 85 | } 86 | def main(): 87 | '''Main entrypoint''' 88 | if not hasattr(ARGS, 'command'): 89 | print('Unrecognized command') 90 | PARSER.print_help() 91 | sys.exit(1) 92 | COMMANDS[ARGS.command]() 93 | 94 | if __name__ == '__main__': 95 | main() 96 | -------------------------------------------------------------------------------- /manager/nicactl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | nicactl - CLI to control NICA properties 5 | """ 6 | 7 | import argparse 8 | import os 9 | import sys 10 | from nica import NicaHardware, default_mst_device 11 | 12 | # TODO control through NICA manager 13 | 14 | MST_DEVICE = default_mst_device() 15 | 16 | def define_parser(): 17 | '''Parse command line arguments.''' 18 | parser = argparse.ArgumentParser(description='Control NICA.') 19 | parser.add_argument('-d', metavar='DEVICE', dest='device', default=MST_DEVICE, 20 | help='MST device to use (default: {})'.format(MST_DEVICE)) 21 | parser.add_argument('command', help='Subcommand to run') 22 | return parser 23 | 24 | PARSER = define_parser() 25 | 26 | def init_nica(): 27 | '''Initialize a Netdev object for the expected one underlying card.''' 28 | args = PARSER.parse_args(sys.argv[1:2]) 29 | if os.path.exists(args.device): 30 | nica = NicaHardware(args.device) 31 | 32 | return nica, args 33 | 34 | # global NICA 35 | NICA, ARGS = init_nica() 36 | 37 | def print_help(): 38 | '''Command line help''' 39 | PARSER.print_help() 40 | print('Commands:') 41 | print('\n'.join(COMMANDS.keys())) 42 | 43 | def set_quantum(): 44 | '''Set the quantum of a given TC to a number of flits.''' 45 | parser = argparse.ArgumentParser(description='Set quantum of a given TC') 46 | parser.add_argument('tc', type=int) 47 | parser.add_argument('quantum', type=int) 48 | args = parser.parse_args(sys.argv[2:]) 49 | 50 | NICA.n2h_arbiter.set_quantum(args.tc, args.quantum) 51 | NICA.h2n_arbiter.set_quantum(args.tc, args.quantum) 52 | 53 | def status(): 54 | '''Set the quantum of a given TC to a number of flits.''' 55 | print('TC\tNet-to-Host Quantum\tHost-to-Net Quantum') 56 | for traffic_class in range(4): 57 | n2h_quantum = NICA.n2h_arbiter.get_quantum(traffic_class) 58 | h2n_quantum = NICA.h2n_arbiter.get_quantum(traffic_class) 59 | print('{}\t{}\t\t\t{}'.format(traffic_class, n2h_quantum, h2n_quantum)) 60 | 61 | COMMANDS = { 62 | 'help': print_help, 63 | 'set-quantum': set_quantum, 64 | 'status': status, 65 | } 66 | def main(): 67 | '''Main entrypoint''' 68 | if not hasattr(ARGS, 'command'): 69 | print('Unrecognized command') 70 | PARSER.print_help() 71 | sys.exit(1) 72 | COMMANDS[ARGS.command]() 73 | 74 | if __name__ == '__main__': 75 | main() 76 | -------------------------------------------------------------------------------- /manager/pylint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pylint=$1 4 | shift 5 | 6 | $pylint "$@" 7 | ret="$?" 8 | 9 | if [[ "$ret" -lt 3 ]] ; then 10 | exit 1 11 | else 12 | exit 0 13 | fi 14 | -------------------------------------------------------------------------------- /manager/util.py: -------------------------------------------------------------------------------- 1 | '''Utility functions for NICA manager.''' 2 | 3 | import socket 4 | import struct 5 | 6 | def mac_to_str(mac): 7 | '''Convert a MAC bytes object to a string representation.''' 8 | return ':'.join('%02x' % b for b in mac) 9 | 10 | def str_to_mac(mac): 11 | '''Convert a MAC string representation into a bytes object.''' 12 | return bytes.fromhex(mac.replace(':', '')) 13 | 14 | def inet_ntoa(ip_addr): 15 | '''Convert an IP address from a number to a string representation.''' 16 | return socket.inet_ntoa(struct.pack('!L', ip_addr)) 17 | -------------------------------------------------------------------------------- /nica/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | project( nica C CXX ) 4 | 5 | include_directories(hls ../ikernels/hls ../ikernels/hls/tests) 6 | 7 | foreach(pcap_file passthrough.pcap input.pcap 8 | 0bad.pcap f00d.pcap 9 | ) 10 | add_custom_target(${pcap_file} 11 | DEPENDS ${CMAKE_SOURCE_DIR}/nica/hls/tests/${pcap_file} 12 | COMMAND cp ${CMAKE_SOURCE_DIR}/nica/hls/tests/${pcap_file} ${pcap_file}) 13 | endforeach(pcap_file) 14 | 15 | set(nica_sources hls/nica.cpp hls/udp.cpp hls/mlx.cpp hls/flow_table.cpp 16 | hls/custom_rx_ring.cpp hls/ikernel.cpp) 17 | set(nica_testbench_sources hls/tests/main.cpp hls/tests/tb.cpp 18 | ../ikernels/hls/passthrough.cpp ../ikernels/hls/threshold.cpp ../ikernels/hls/pktgen.cpp 19 | ) 20 | set(nica_pcap_files passthrough.pcap input.pcap 21 | passthrough-padded.pcap 22 | input-padded.pcap all_sizes.pcap all_sizes-padded.pcap 23 | 0bad.pcap 0bad-padded.pcap f00d.pcap 24 | f00d-padded.pcap 25 | input-bth.pcap) 26 | 27 | add_custom_target(pcap_files ALL DEPENDS ${nica_pcap_files}) 28 | 29 | # HLS 30 | hls_target(nica nica "${nica_sources}" "${nica_testbench_sources};${nica_pcap_files}" nica) 31 | 32 | # NICA 33 | add_library(nica-csim ${nica_sources}) 34 | set_property(TARGET nica-csim PROPERTY POSITION_INDEPENDENT_CODE ON) 35 | target_compile_features(nica-csim PRIVATE cxx_auto_type) 36 | target_link_libraries(nica-csim pcap) 37 | 38 | add_executable(nica_tests EXCLUDE_FROM_ALL ${nica_testbench_sources}) 39 | add_dependencies(check nica_tests) 40 | target_compile_features(nica_tests PRIVATE cxx_auto_type) 41 | target_link_libraries(nica_tests pcap nica-csim ${GTEST_LIBRARIES} Threads::Threads) 42 | add_dependencies(nica_tests pcap_files) 43 | 44 | foreach(f passthrough input all_sizes 0bad) 45 | add_custom_command(OUTPUT ${f}-padded.pcap 46 | COMMAND python ${CMAKE_SOURCE_DIR}/nica/hls/tests/pad_small_packets.py ${f}.pcap ${f}-padded.pcap 47 | DEPENDS ${f}.pcap ${CMAKE_SOURCE_DIR}/nica/hls/tests/pad_small_packets.py) 48 | endforeach(f) 49 | add_custom_command(OUTPUT all_sizes.pcap 50 | COMMAND python ${CMAKE_SOURCE_DIR}/nica/hls/tests/gen_packets.py 51 | DEPENDS hls/tests/gen_packets.py) 52 | add_custom_command(OUTPUT f00d-padded.pcap 53 | COMMAND python ${CMAKE_SOURCE_DIR}/nica/hls/tests/pad_small_packets.py f00d.pcap f00d-padded.pcap --dest-port 2989 54 | DEPENDS f00d.pcap ${CMAKE_SOURCE_DIR}/nica/hls/tests/pad_small_packets.py) 55 | foreach(f input) 56 | add_custom_command(OUTPUT ${f}-bth.pcap 57 | COMMAND python ${CMAKE_SOURCE_DIR}/nica/hls/tests/add_bth.py ${f}.pcap ${f}-bth.pcap 58 | DEPENDS ${f}.pcap ${CMAKE_SOURCE_DIR}/nica/hls/tests/add_bth.py 59 | ${CMAKE_SOURCE_DIR}/nica/hls/tests/roce.py) 60 | endforeach(f) 61 | 62 | add_test(NAME nica_tests COMMAND nica_tests) 63 | 64 | ### add hash table / flow table tests 65 | add_executable(flow_table_tests EXCLUDE_FROM_ALL 66 | hls/tests/flow_table_tests.cpp) 67 | add_dependencies(check flow_table_tests) 68 | add_test(flow_table_tests flow_table_tests) 69 | add_gtest(flow_table) 70 | 71 | add_executable(arbiter_tests EXCLUDE_FROM_ALL hls/tests/arbiter_tests.cpp hls/arbiter.cpp hls/demux.cpp) 72 | add_dependencies(check arbiter_tests) 73 | add_test(arbiter_tests arbiter_tests) 74 | add_gtest(arbiter) 75 | -------------------------------------------------------------------------------- /nica/arbiter.tcl: -------------------------------------------------------------------------------- 1 | set basename [info script] 2 | set basedir [file join [pwd] {*}[lrange [file split $basename] 0 end-1]] 3 | source "$basedir/ikernel.tcl" 4 | 5 | create_project arbiter arbiter_top $basedir/hls { 6 | arbiter.cpp 7 | } {tests/arbiter_tests.cpp udp.cpp} 8 | exit 9 | -------------------------------------------------------------------------------- /nica/custom_ring.tcl: -------------------------------------------------------------------------------- 1 | set basename [info script] 2 | set basedir [file join [pwd] {*}[lrange [file split $basename] 0 end-1]] 3 | source "$basedir/ikernel.tcl" 4 | 5 | create_project custom_ring custom_ring_top $basedir/hls { 6 | custom_rx_ring.cpp 7 | } {} 8 | exit 9 | -------------------------------------------------------------------------------- /nica/demux.tcl: -------------------------------------------------------------------------------- 1 | set basename [info script] 2 | set basedir [file join [pwd] {*}[lrange [file split $basename] 0 end-1]] 3 | source "$basedir/ikernel.tcl" 4 | 5 | create_project demux demux_arb_top $basedir/hls { 6 | demux.cpp arbiter.cpp 7 | } {tests/arbiter_tests.cpp udp.cpp} 8 | exit 9 | -------------------------------------------------------------------------------- /nica/flow_table.tcl: -------------------------------------------------------------------------------- 1 | set basename [info script] 2 | set basedir [file join [pwd] {*}[lrange [file split $basename] 0 end-1]] 3 | source "$basedir/ikernel.tcl" 4 | 5 | create_project flow_table flow_table_top $basedir/hls { 6 | flow_table.cpp udp.cpp ikernel.cpp 7 | } {tests/flow_table_tests.cpp} 8 | exit 9 | -------------------------------------------------------------------------------- /nica/hls/arbiter.hpp: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation and/or 11 | * other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #pragma once 26 | 27 | struct arbiter_per_port_stats { 28 | arbiter_per_port_stats() : 29 | not_empty(), 30 | no_tokens(), 31 | cur_tokens() 32 | {} 33 | 34 | ap_uint<64> not_empty; 35 | ap_uint<64> no_tokens; 36 | int cur_tokens; 37 | }; 38 | 39 | struct arbiter_tx_per_port_stats { 40 | arbiter_tx_per_port_stats() : words(), packets() 41 | {} 42 | 43 | ap_uint<64> words; 44 | ap_uint<64> packets; 45 | }; 46 | 47 | template 48 | struct arbiter_stats { 49 | arbiter_stats() : out_full() {} 50 | 51 | arbiter_per_port_stats port[num_ports]; 52 | arbiter_tx_per_port_stats tx_port[num_ports]; 53 | ap_uint<64> out_full; 54 | }; 55 | 56 | /* Each port has the two SCHED_DRR_* registers at offsets starting from 57 | * ARBITER_SCHEDULER and with stride ARBITER_SCHEDULER_STRIDE */ 58 | #define ARBITER_NUM_TC 0x0 59 | #define ARBITER_SCHEDULER 0x10 60 | #define ARBITER_SCHEDULER_STRIDE 0x2 61 | -------------------------------------------------------------------------------- /nica/hls/axi_data.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2019 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | namespace hls_ik { 31 | using ntl::axi_data; 32 | 33 | typedef hls::stream > data_stream; 34 | } 35 | -------------------------------------------------------------------------------- /nica/hls/custom_rx_ring-impl.hpp: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation and/or 11 | * other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "ikernel.hpp" 28 | #include "udp.h" 29 | #include "gateway.hpp" 30 | #include 31 | #include 32 | #include 33 | 34 | struct ring_context 35 | { 36 | ap_uint<48> eth_dst; 37 | ap_uint<32> ip_dst; 38 | ap_uint<24> dest_qpn; 39 | ap_uint<24> psn; 40 | }; 41 | 42 | class ring_context_manager : public ntl::context_manager { 43 | public: 44 | int gateway_write(int address, int value); 45 | int gateway_read(int address, int* value); 46 | 47 | /* Query QPN and increment PSN */ 48 | ring_context next_packet(hls_ik::ring_id_t ring_id); 49 | }; 50 | 51 | struct hdr_to_data 52 | { 53 | hls_ik::ring_id_t ring_id; 54 | }; 55 | 56 | /* Build RoCE UC send packets from ikernel outputs */ 57 | class custom_rx_ring 58 | { 59 | public: 60 | custom_rx_ring(); 61 | /** Builds packets from split header and data streams, and re-calculates 62 | * the checksum. */ 63 | void custom_ring(udp::udp_builder_metadata_stream& header_in, hls_ik::data_stream& data_in, 64 | udp::udp_builder_metadata_stream& header_out, hls_ik::data_stream& data_out, 65 | hls_ik::gateway_registers& r); 66 | 67 | int reg_read(int address, int* value); 68 | int reg_write(int address, int value); 69 | void gateway_update() {} 70 | 71 | #if !defined(__SYNTHESIS__) 72 | void verify(); 73 | #endif 74 | 75 | private: 76 | void ring_hdrs(udp::udp_builder_metadata_stream& hdr_in, udp::udp_builder_metadata_stream& hdr_out); 77 | hls_ik::axi_data gen_bth(const ring_context& context, ap_uint<16>& len); 78 | 79 | /* Metadata used for trasmitting to the host */ 80 | hls_ik::packet_metadata metadata, metadata_cache; 81 | hls::stream metadata_updates; 82 | ring_context_manager contexts; 83 | hls_ik::data_stream bth, data_bth_to_icrc; 84 | hls::stream > icrc; 85 | hls::stream empty_packet, empty_packet_bth, empty_packet_icrc, 86 | enable_stream, enable_bth, enable_icrc; 87 | ntl::push_header<12 * 8> push_bth; 88 | ntl::push_suffix<4> push_icrc; 89 | 90 | /* Data-path state */ 91 | enum { IDLE, STREAM } state; 92 | udp::udp_builder_metadata cur_metadata; 93 | 94 | ntl::gateway_impl gateway; 95 | }; 96 | -------------------------------------------------------------------------------- /nica/hls/custom_rx_ring.hpp: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation and/or 11 | * other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #pragma once 26 | 27 | enum { 28 | CR_SRC_MAC_LO = 0x2, 29 | CR_SRC_MAC_HI = 0x3, 30 | CR_SRC_IP = 0x5, 31 | CR_DST_UDP = 0x6, 32 | CR_SRC_UDP = 0x7, 33 | 34 | CR_NUM_CONTEXTS = 0xa, 35 | 36 | /* Per context settings */ 37 | CR_DST_MAC_LO = 0x0, 38 | CR_DST_MAC_HI = 0x1, 39 | CR_DST_IP = 0x4, 40 | CR_DST_QPN = 0x10, 41 | CR_PSN = 0x11, 42 | 43 | CR_WRITE_CONTEXT = 0x1e, 44 | CR_READ_CONTEXT = 0x1f, 45 | }; 46 | -------------------------------------------------------------------------------- /nica/hls/demux.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include 27 | #include 28 | 29 | #include "demux.hpp" 30 | 31 | void demux_top(udp::udp_builder_metadata_stream& meta_in, hls_ik::data_stream& data_in, 32 | tc_ports& tc) 33 | { 34 | #pragma HLS inline 35 | 36 | static demultiplexor demux; 37 | 38 | demux.demux(meta_in, data_in, tc); 39 | } 40 | -------------------------------------------------------------------------------- /nica/hls/drop_or_pass.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | /* Assumes in/out are AXI4-Stream (blocking read/writes) */ 31 | class drop_or_pass { 32 | public: 33 | drop_or_pass() : _state(DECISION) {} 34 | 35 | void filter(hls::stream& decision, hls_ik::data_stream& in, 36 | hls_ik::data_stream& out) { 37 | #pragma HLS pipeline enable_flush ii=1 38 | switch (_state) { 39 | case DECISION: 40 | if (decision.empty()) 41 | break; 42 | 43 | _pass = decision.read(); 44 | 45 | _state = STREAM; 46 | /* Fall through */ 47 | 48 | case STREAM: 49 | if (in.empty()) 50 | break; 51 | 52 | hls_ik::axi_data d = in.read(); 53 | 54 | if (_pass) 55 | out.write(d); 56 | 57 | if (d.last) 58 | _state = DECISION; 59 | 60 | break; 61 | } 62 | } 63 | private: 64 | enum { DECISION, STREAM } _state; 65 | bool _pass; 66 | }; 67 | -------------------------------------------------------------------------------- /nica/hls/either.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | #include 31 | 32 | /** Holds a value of either one of two types (Left or Right). 33 | * Left and Right must implement conversion functions to ap_uint and expose a 34 | * static width field with their required number of bits 35 | */ 36 | template 37 | class either : public boost::equality_comparable > 38 | { 39 | public: 40 | enum { width = 1 + ntl::max(Left::width, Right::width), }; 41 | 42 | bool is_left() const { return !data(width - 1, width - 1); } 43 | 44 | template 45 | T get() const 46 | { 47 | const int cast_width = T::width; 48 | const ap_uint cast_data = data(cast_width - 1, 0); 49 | return T(cast_data); 50 | } 51 | 52 | either(const Left& x) : 53 | data((ap_uint(0), 54 | static_cast >(x))) 55 | { 56 | assert(is_left()); 57 | } 58 | 59 | either(const Right& x) : 60 | data((ap_uint(0), 61 | static_cast >(x))) 62 | { 63 | data(width - 1, width - 1) = 1; 64 | assert(!is_left()); 65 | } 66 | 67 | either(const ap_uint d = ap_uint(0)) : data(d) {} 68 | 69 | bool operator ==(const either& o) const { 70 | if (is_left() != o.is_left()) return false; 71 | if (is_left()) return get() == o.get(); 72 | else return get() == o.get(); 73 | } 74 | 75 | operator ap_uint() const { 76 | return data; 77 | } 78 | 79 | private: 80 | ap_uint data; 81 | }; 82 | -------------------------------------------------------------------------------- /nica/hls/flow_table.hpp: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation and/or 11 | * other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #ifndef FLOW_TABLE_HPP 26 | #define FLOW_TABLE_HPP 27 | 28 | enum flow_table_action { 29 | FT_PASSTHROUGH = 0, 30 | FT_DROP = 1, 31 | FT_IKERNEL = 2, 32 | }; 33 | 34 | enum flow_table_fields { 35 | FT_FIELD_SRC_IP = 1 << 0, 36 | FT_FIELD_DST_IP = 1 << 1, 37 | FT_FIELD_SRC_PORT = 1 << 2, 38 | FT_FIELD_DST_PORT = 1 << 3, 39 | FT_FIELD_VM_ID = 1 << 4, 40 | }; 41 | 42 | #define FLOW_TABLE_LOG_SIZE 10 43 | #define FLOW_TABLE_SIZE (1 << FLOW_TABLE_LOG_SIZE) 44 | 45 | #define FT_FIELDS 0 46 | /* A read from this address causes the flow that was previously set through the 47 | * FT_KEY_* and FT_RESULT_* registers to be added to the flow table, returning 48 | * the flow ID or zero if the operation failed. */ 49 | #define FT_ADD_FLOW 0x1 50 | /* A read from this address causes the flow that was set through FT_KEY_* 51 | * registers to be removed from the flow table. */ 52 | #define FT_DELETE_FLOW 0x2 53 | #define FT_SET_ENTRY 0x4 54 | #define FT_READ_ENTRY 0x5 55 | 56 | #define FT_KEY_SADDR 0x10 57 | #define FT_KEY_DADDR 0x11 58 | #define FT_KEY_SPORT 0x12 59 | #define FT_KEY_DPORT 0x13 60 | #define FT_RESULT_ACTION 0x18 61 | #define FT_RESULT_ENGINE 0x19 62 | #define FT_RESULT_IKERNEL_ID 0x1a 63 | 64 | /* Used with FT_SET_ENTRY and FT_READ_ENTRY to indicate valid/invalid entries */ 65 | #define FT_VALID 0x20 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /nica/hls/gateway.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | #include "ikernel-types.hpp" 31 | 32 | #define VIRT_GATEWAY_OFFSET(gateway, offset_cmd, offset_data, offset_done, offset_ikernel_id) \ 33 | GATEWAY_OFFSET(gateway.common, offset_cmd, offset_data, offset_done) \ 34 | DO_PRAGMA_SYN(HLS interface s_axilite port=gateway.ikernel_id offset=offset_ikernel_id) 35 | 36 | using ntl::GW_FAIL; 37 | using ntl::GW_DONE; 38 | using ntl::GW_BUSY; 39 | 40 | namespace hls_ik { 41 | enum { 42 | GW_WRITE = (1U << 30), 43 | }; 44 | 45 | struct gateway_registers : public ntl::gateway_registers { 46 | }; 47 | 48 | struct virt_gateway_registers { 49 | virt_gateway_registers() : common(), ikernel_id(0) {} 50 | 51 | gateway_registers common; 52 | 53 | /** Write: ikernel ID to associate the command with. */ 54 | ikernel_id_t ikernel_id; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /nica/hls/ikernel-types.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | 30 | #include "flow_table.hpp" 31 | 32 | #define CUSTOM_RINGS_LOG_NUM 6 33 | #define LOG_NUM_IKERNELS 6 34 | #define LOG_NUM_VMS 6 35 | #define LOG_NUM_ENGINES 1 36 | #ifndef NUM_TC 37 | # define NUM_TC 8 38 | #endif 39 | 40 | namespace hls_ik { 41 | /* One more bit for the UDP traffic */ 42 | typedef ap_uint ring_id_t; 43 | typedef ap_uint ikernel_id_t; 44 | typedef ap_uint engine_id_t; 45 | typedef ap_uint vm_id_t; 46 | /* One more bit for the miss flows */ 47 | typedef ap_uint flow_id_t; 48 | 49 | typedef ap_uint<1> direction_t; 50 | #define HOST (0) 51 | #define NET (1) 52 | 53 | typedef ap_uint<11> pkt_len_t; 54 | } 55 | -------------------------------------------------------------------------------- /nica/hls/link_with_reg.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef LINK_WITH_REG 27 | #define LINK_WITH_REG 28 | 29 | /* don't check the output for full FIFO when using AXI4 Stream outputs */ 30 | template 31 | class link_with_reg 32 | { 33 | public: 34 | void link(hls::stream& in, hls::stream& out) 35 | { 36 | #pragma HLS pipeline enable_flush ii=1 37 | if (valid && (!check_full || !out.full())) { 38 | out.write(reg); 39 | valid = false; 40 | } 41 | 42 | if (!in.empty() && !valid) { 43 | reg = in.read(); 44 | valid = true; 45 | } 46 | } 47 | 48 | protected: 49 | bool valid; 50 | T reg; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /nica/hls/linux_types.h: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation and/or 11 | * other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #pragma once 26 | 27 | typedef uint8_t u8; 28 | typedef uint16_t u16; 29 | typedef uint32_t u32; 30 | typedef uint64_t u64; 31 | 32 | constexpr u16 be16_to_cpu(u16 i) 33 | { 34 | return (i >> 8) | (i << 8); 35 | } 36 | constexpr u16 cpu_to_be16(u16 i) { return be16_to_cpu(i); } 37 | 38 | constexpr u32 be32_to_cpu(u32 i) 39 | { 40 | return u32(be16_to_cpu(i >> 16)) | (u32(be16_to_cpu(i)) << 16); 41 | } 42 | constexpr u32 cpu_to_be32(u32 i) { return be32_to_cpu(i); } 43 | 44 | constexpr u64 be64_to_cpu(u64 i) 45 | { 46 | return u64(be32_to_cpu(i >> 32)) | (u64(be32_to_cpu(i)) << 32); 47 | } 48 | constexpr u64 cpu_to_be64(u64 i) { return be64_to_cpu(i); } 49 | -------------------------------------------------------------------------------- /nica/hls/nica-top.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef NICA_TOP_HPP 27 | #define NICA_TOP_HPP 28 | 29 | #include "ikernel.hpp" 30 | #include "udp.h" 31 | #include "tc-ports.hpp" 32 | #include "arbiter.hpp" 33 | 34 | #include 35 | 36 | struct nica_ikernel_stats { 37 | ap_uint<32> packets; 38 | }; 39 | 40 | struct nica_pipeline_stats { 41 | udp::udp_stats udp; 42 | arbiter_stats arbiter; 43 | #define BOOST_PP_LOCAL_MACRO(i) \ 44 | nica_ikernel_stats ik ## i; 45 | #define BOOST_PP_LOCAL_LIMITS (0, NUM_IKERNELS - 1) 46 | %:include BOOST_PP_LOCAL_ITERATE() 47 | }; 48 | 49 | struct nica_stats { 50 | nica_pipeline_stats n2h, h2n; 51 | int flow_table_size; 52 | }; 53 | 54 | struct nica_config { 55 | udp::config_n2h n2h; 56 | udp::config_h2n h2n; 57 | }; 58 | 59 | using hls_ik::trace_event; 60 | #define NUM_TRACE_EVENTS 8 61 | enum { 62 | TRACE_ARBITER_PORT_0 = 0, 63 | TRACE_ARBITER_PORT_1 = 1, 64 | TRACE_ARBITER_PORT_2 = 2, 65 | TRACE_ARBITER_EVICTED = 3, 66 | 67 | TRACE_N2H = 0, 68 | TRACE_H2N = 4, 69 | }; 70 | 71 | void nica(mlx::stream& nwp2sbu, mlx::stream& sbu2nwp, mlx::stream& cxp2sbu, 72 | mlx::stream& sbu2cxp, 73 | nica_config* cfg, nica_stats* stats, 74 | trace_event events[NUM_TRACE_EVENTS], 75 | DECL_IKERNEL_PARAMS(), 76 | tc_ports& h2n_tc_out, tc_ports& h2n_tc_in, 77 | tc_ports& n2h_tc_out, tc_ports& n2h_tc_in 78 | ); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /nica/hls/tc-ports.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2018 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #pragma once 27 | 28 | #include "udp.h" 29 | 30 | #include 31 | 32 | /* All traffic class ports (inputs or outputs) */ 33 | struct tc_ports { 34 | #define BOOST_PP_LOCAL_MACRO(i) \ 35 | udp::udp_builder_metadata_stream meta ## i; \ 36 | hls_ik::data_stream data ## i; 37 | #define BOOST_PP_LOCAL_LIMITS (0, NUM_TC - 1) 38 | %:include BOOST_PP_LOCAL_ITERATE() 39 | }; 40 | 41 | static inline void link_fifo(tc_ports& in, tc_ports& out) 42 | { 43 | #pragma HLS inline 44 | #define BOOST_PP_LOCAL_MACRO(i) \ 45 | hls_helpers::link_fifo(in.meta ## i, out.meta ## i); \ 46 | hls_helpers::link_fifo(in.data ## i, out.data ## i); 47 | #define BOOST_PP_LOCAL_LIMITS (0, NUM_TC - 1) 48 | %:include BOOST_PP_LOCAL_ITERATE() 49 | } 50 | 51 | /* Blocking reads, non-blocking writes */ 52 | static inline void link_axi_to_fifo(tc_ports& in, tc_ports& out) 53 | { 54 | #pragma HLS inline 55 | #define BOOST_PP_LOCAL_MACRO(i) \ 56 | hls_helpers::link_axi_to_fifo(in.meta ## i, out.meta ## i); \ 57 | hls_helpers::link_axi_to_fifo(in.data ## i, out.data ## i); 58 | #define BOOST_PP_LOCAL_LIMITS (0, NUM_TC - 1) 59 | %:include BOOST_PP_LOCAL_ITERATE() 60 | } 61 | -------------------------------------------------------------------------------- /nica/hls/tests/0bad.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/nica/hls/tests/0bad.pcap -------------------------------------------------------------------------------- /nica/hls/tests/f00d.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/nica/hls/tests/f00d.pcap -------------------------------------------------------------------------------- /nica/hls/tests/gen_packets.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, 6 | # are permitted provided that the following conditions are met: 7 | # 8 | # * Redistributions of source code must retain the above copyright notice, this 9 | # list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation and/or 12 | # other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | from scapy.all import * 26 | 27 | class Vector(Packet): 28 | name = "Vector" 29 | fields_desc = [FieldListField("list", None, ByteField("element", 0))] 30 | 31 | def make_pkt(sz): 32 | payload = [sz % 256] * sz 33 | pkt = Ether()/IP()/UDP(dport=0x0bad, sport=sz)/Vector(list=payload) 34 | return pkt 35 | 36 | sizes = list(range(32)) + [2**x + x for x in range(5, 10)] + [1500 - 14 - 20 - 8] 37 | pkts = [] 38 | for sz in sizes: 39 | pkt = make_pkt(sz) 40 | pkts.append(pkt) 41 | 42 | wrpcap("all_sizes.pcap", pkts) 43 | -------------------------------------------------------------------------------- /nica/hls/tests/input.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/nica/hls/tests/input.pcap -------------------------------------------------------------------------------- /nica/hls/tests/pad_small_packets.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | 27 | from scapy.all import * 28 | import sys 29 | from optparse import OptionParser 30 | 31 | parser = OptionParser() 32 | parser.add_option("-r", "--reverse", action="store_true", dest="reverse", 33 | default=False, help="Reverse destination and source addresses") 34 | parser.add_option("", "--dest-port", dest="dport", 35 | help="Filter UDP destination port") 36 | options, args = parser.parse_args() 37 | infile, outfile = args 38 | 39 | pkts = rdpcap(infile) 40 | out = [] 41 | for p in pkts: 42 | if p.haslayer(IP) and p.haslayer(UDP): 43 | if options.dport is None or options.dport == p[UDP].dport: 44 | p[IP].chksum = 0 45 | p[IP].flags = 0 46 | p[UDP].chksum = 0 47 | if options.reverse: 48 | p[UDP].sport, p[UDP].dport = p[UDP].dport, p[UDP].sport 49 | p[IP].src, p[IP].dst = p[IP].dst, p[IP].src 50 | p[Ether].src, p[Ether].dst = p[Ether].dst, p[Ether].src 51 | if len(p) < 60: 52 | p = Ether(str(p) + '\0' * (60 - len(p))) 53 | out.append(p) 54 | 55 | wrpcap(outfile, out) 56 | -------------------------------------------------------------------------------- /nica/hls/tests/passthrough.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acsl-technion/nica/b43de25be1549805340c5da37bdc451ff09cd936/nica/hls/tests/passthrough.pcap -------------------------------------------------------------------------------- /nica/hls/tests/remove_eth_padding.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, 6 | # are permitted provided that the following conditions are met: 7 | # 8 | # * Redistributions of source code must retain the above copyright notice, this 9 | # list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation and/or 12 | # other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | from scapy.all import * 26 | import sys 27 | 28 | pkts = rdpcap(sys.argv[1]) 29 | # https://stackoverflow.com/questions/28967976/how-to-remove-trailer-of-the-packet-in-python-using-scapy 30 | def packet_without_trailer(packet): 31 | if packet.type == ETH_P_IP: 32 | return Ether(src = packet.src, dst = packet.dst, type = packet.type) / str(packet[IP])[0:packet[IP].len] 33 | elif packet.type == ETH_P_IPV6: 34 | return Ether(src = packet.src, dst = packet.dst, type = packet.type) / str(packet[IPv6])[0:40 + packet[IPv6].len] 35 | else: 36 | return packet 37 | 38 | wrpcap(sys.argv[2], [packet_without_trailer(p) for p in pkts]) 39 | 40 | -------------------------------------------------------------------------------- /nica/hls/tests/roce.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | 27 | from scapy.all import * 28 | from binascii import crc32 29 | 30 | class BTH(Packet): 31 | name = "BTH" 32 | fields_desc = [ 33 | XByteField("opcode", 0), 34 | BitField("solicited", 0, 1), 35 | BitField("migreq", 0, 1), 36 | BitField("padcount", 0, 2), 37 | BitField("version", 0, 4), 38 | XShortField("pkey", 0x0000), 39 | XByteField("reserved", 0), 40 | BitField("dqpn", 0, 24), 41 | BitField("ackreq", 0, 1), 42 | BitField("reserved", 0, 7), 43 | BitField("psn", 0, 24)] 44 | 45 | class ICRC(Packet): 46 | name = "ICRC" 47 | fields_desc = [XIntField("icrc", 0)] 48 | 49 | def icrc(packet): 50 | p = copy.deepcopy(packet[IP]) 51 | dummy_lrh = 0xffffffffffffffff 52 | p.ttl = 0xff 53 | p.chksum = 0xffff 54 | p.tos = 0xff 55 | p[UDP].chksum = 0xffff 56 | return ICRC(icrc=(crc32(str(p)) & 0xffffffff)) 57 | -------------------------------------------------------------------------------- /nica/ikernel.tcl: -------------------------------------------------------------------------------- 1 | package require Tcl 8.5 2 | 3 | set nica_basename [info script] 4 | set nica_basedir [file join [pwd] {*}[lrange [file split $nica_basename] 0 end-1]] 5 | 6 | proc get_env {var defvalue} { 7 | if {[info exists ::env($var)]} { 8 | return $::env($var) 9 | } else { 10 | return $defvalue 11 | } 12 | } 13 | 14 | proc create_project {name top dir files tb_files} { 15 | set simulation_build [info exists ::env(SIMULATION_BUILD)] 16 | 17 | if {$simulation_build} { 18 | open_project -reset "$name-sim" 19 | } else { 20 | open_project -reset "$name" 21 | } 22 | 23 | set num_ikernels [get_env "NUM_IKERNELS" 1] 24 | set num_tc [get_env "NUM_TC" 8] 25 | set memcached_cache_size [get_env "MEMCACHED_CACHE_SIZE" 4096] 26 | set memcached_key_size [get_env "MEMCACHED_KEY_SIZE" 10] 27 | set memcached_value_size [get_env "MEMCACHED_VALUE_SIZE" 10] 28 | 29 | global env nica_basedir 30 | set gtest_root $env(GTEST_ROOT) 31 | set_top $top 32 | set uuid_cflags [exec pkg-config --cflags uuid] 33 | set uuid_ldflags [exec pkg-config --libs uuid] 34 | set cflags "-std=gnu++0x $uuid_cflags \ 35 | -I$nica_basedir/hls \ 36 | -I$nica_basedir/../ntl \ 37 | -I$nica_basedir/../ikernels/hls \ 38 | -I$nica_basedir/../ikernels/hls/tests \ 39 | -I$gtest_root/include \ 40 | -Wno-gnu-designator -DNUM_IKERNELS=$num_ikernels \ 41 | -DNUM_TC=$num_tc" 42 | if {$simulation_build} { 43 | set cflags "$cflags -DSIMULATION_BUILD=1" 44 | } 45 | puts $memcached_cache_size 46 | if {$memcached_cache_size ne ""} { 47 | set cflags "$cflags -DMEMCACHED_CACHE_SIZE=$memcached_cache_size" 48 | } 49 | puts $memcached_key_size 50 | if {$memcached_key_size ne ""} { 51 | set cflags "$cflags -DMEMCACHED_KEY_SIZE=$memcached_key_size" 52 | } 53 | puts $memcached_value_size 54 | if {$memcached_value_size ne ""} { 55 | set cflags "$cflags -DMEMCACHED_VALUE_SIZE=$memcached_value_size" 56 | } 57 | 58 | set ldflags "-lpcap -lssl -lcrypto $uuid_ldflags -L$gtest_root -lgtest -L$nica_basedir/../build/nica/ -lnica-csim" 59 | 60 | foreach f $files { 61 | set f [file join $dir $f] 62 | add_files $f -cflags $cflags 63 | } 64 | 65 | foreach f $tb_files { 66 | if {![file exists $f]} { 67 | set f [file join $dir $f] 68 | } 69 | add_files -tb $f -cflags $cflags 70 | } 71 | 72 | open_solution "40Gbps" 73 | set_part {xcku060-ffva1156-2-i} 74 | create_clock -period "5.185ns" 75 | config_rtl -prefix ${name}_ 76 | config_rtl -disable_start_propagation 77 | config_interface -m_axi_addr64 78 | if {[string match "*2018.2" $::ap_root]} { 79 | # Our pattern of using a class to hold state breaks dataflow strict mode 80 | config_dataflow -strict_mode off 81 | } 82 | #if {[llength $tb_files] > 0} { 83 | # csim_design -ldflags $ldflags 84 | #} 85 | csynth_design 86 | if {$simulation_build && [llength $tb_files] > 0} { 87 | cosim_design -O -ldflags $ldflags -trace_level none 88 | } else { 89 | export_design -format ip_catalog 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /nica/udp.tcl: -------------------------------------------------------------------------------- 1 | set basename [info script] 2 | set basedir [file join [pwd] {*}[lrange [file split $basename] 0 end-1]] 3 | source "$basedir/ikernel.tcl" 4 | 5 | create_project udp udp_top $basedir/hls { 6 | udp.cpp flow_table.cpp 7 | } {} 8 | exit 9 | -------------------------------------------------------------------------------- /nica/verilog/csa_32x3.v: -------------------------------------------------------------------------------- 1 | module csa_32x3( 2 | input wire [31:0] in1, 3 | input wire [31:0] in2, 4 | input wire [31:0] in3, 5 | output wire [31:0] sum, 6 | output wire [31:0] carry 7 | ); 8 | 9 | assign sum = in1 ^ in2 ^ in3; 10 | assign carry = in1 & in2 | in1 & in3 | in2 & in3; 11 | 12 | endmodule // csa_32x3 13 | 14 | -------------------------------------------------------------------------------- /nica/verilog/csa_32x4.v: -------------------------------------------------------------------------------- 1 | module csa_32x4( 2 | input wire [31:0] in1, 3 | input wire [31:0] in2, 4 | input wire [31:0] in3, 5 | input wire [31:0] in4, 6 | output wire [31:0] sum, 7 | output wire [31:0] carry 8 | ); 9 | 10 | wire [31:0] sum1; 11 | wire [31:0] carry1; 12 | 13 | csa_32x3 csa_32x3_1( 14 | .in1(in1), 15 | .in2(in2), 16 | .in3(in3), 17 | .sum(sum1), 18 | .carry(carry1) 19 | ); 20 | 21 | csa_32x3 csa_32x3_2( 22 | .in1(in4), 23 | .in2(sum1), 24 | .in3({carry1[30:0], 1'b0}), 25 | .sum(sum), 26 | .carry(carry) 27 | ); 28 | 29 | endmodule // csa_32x4 30 | 31 | -------------------------------------------------------------------------------- /nica/verilog/csa_32x6.v: -------------------------------------------------------------------------------- 1 | module csa_32x6( 2 | input wire [31:0] in1, 3 | input wire [31:0] in2, 4 | input wire [31:0] in3, 5 | input wire [31:0] in4, 6 | input wire [31:0] in5, 7 | input wire [31:0] in6, 8 | output wire [31:0] sum, 9 | output wire [31:0] carry 10 | ); 11 | 12 | wire [31:0] sum1; 13 | wire [31:0] sum2; 14 | wire [31:0] sum3; 15 | wire [31:0] carry1; 16 | wire [31:0] carry2; 17 | wire [31:0] carry3; 18 | 19 | csa_32x3 csa_32x3_1( 20 | .in1(in1), 21 | .in2(in2), 22 | .in3(in3), 23 | .sum(sum1), 24 | .carry(carry1) 25 | ); 26 | 27 | csa_32x3 csa_32x3_2( 28 | .in1(in4), 29 | .in2(in5), 30 | .in3(in6), 31 | .sum(sum2), 32 | .carry(carry2) 33 | ); 34 | 35 | csa_32x3 csa_32x3_3( 36 | .in1(sum1), 37 | .in2(sum2), 38 | .in3({carry1[30:0], 1'b0}), 39 | .sum(sum3), 40 | .carry(carry3) 41 | ); 42 | 43 | csa_32x3 csa_32x3_4( 44 | .in1(sum3), 45 | .in2({carry2[30:0], 1'b0}), 46 | .in3({carry3[30:0], 1'b0}), 47 | .sum(sum), 48 | .carry(carry) 49 | ); 50 | 51 | endmodule // csa_32x6 52 | 53 | -------------------------------------------------------------------------------- /nica/verilog/sha256_stream.v: -------------------------------------------------------------------------------- 1 | //====================================================================== 2 | // 3 | // sha256_stream.v 4 | // -------- 5 | // Top level wrapper for the SHA-256 hash function providing 6 | // a simple stream interface with 512 bit data access. 7 | // 8 | // 9 | // Author: Olof Kindgren 10 | // Copyright (c) 2016, Olof Kindgren 11 | // All rights reserved. 12 | // 13 | // Redistribution and use in source and binary forms, with or 14 | // without modification, are permitted provided that the following 15 | // conditions are met: 16 | // 17 | // 1. Redistributions of source code must retain the above copyright 18 | // notice, this list of conditions and the following disclaimer. 19 | // 20 | // 2. Redistributions in binary form must reproduce the above copyright 21 | // notice, this list of conditions and the following disclaimer in 22 | // the documentation and/or other materials provided with the 23 | // distribution. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 36 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | // 38 | //====================================================================== 39 | 40 | module sha256_stream 41 | (input clk, 42 | input rst, 43 | input mode, 44 | input [511:0] s_tdata_i, 45 | input s_tlast_i, 46 | input s_tvalid_i, 47 | output s_tready_o, 48 | output [255:0] digest_o, 49 | output digest_valid_o); 50 | 51 | reg first_block; 52 | 53 | always @(posedge clk) begin 54 | if (s_tvalid_i & s_tready_o) 55 | first_block <= s_tlast_i; 56 | 57 | if (rst) begin 58 | first_block <= 1'b1; 59 | end 60 | end 61 | 62 | sha256_core core 63 | (.clk (clk), 64 | .reset_n (~rst), 65 | 66 | .init(s_tvalid_i & first_block), 67 | .next(s_tvalid_i & !first_block), 68 | .mode (mode), 69 | 70 | .block(s_tdata_i), 71 | 72 | .ready(s_tready_o), 73 | 74 | .digest (digest_o), 75 | .digest_valid (digest_valid_o)); 76 | 77 | endmodule 78 | -------------------------------------------------------------------------------- /nica/xci/.gitignore: -------------------------------------------------------------------------------- 1 | *.dcp 2 | *.veo 3 | *.vho 4 | *.xdc 5 | *.xml 6 | *.v 7 | *.vhdl 8 | *.log 9 | 10 | doc/ 11 | hdl/ 12 | sim/ 13 | simulation/ 14 | synth/ 15 | misc/ 16 | -------------------------------------------------------------------------------- /scripts/add-license.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker run --rm --volume `pwd`:/usr/src/ osterman/copyright-header:latest \ 4 | --license BSD-2-CLAUSE \ 5 | --add-path . \ 6 | --guess-extension \ 7 | --copyright-holder 'Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork' \ 8 | --copyright-software 'NICA' \ 9 | --copyright-software-description 'Framework for NIC application acceleration on the FPGA' \ 10 | --copyright-year 2016-2017 \ 11 | --word-wrap 80 \ 12 | --output-dir /usr/src/ 13 | -------------------------------------------------------------------------------- /scripts/capture.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cmd="sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga" 4 | read="$cmd read" 5 | write="$cmd write" 6 | 7 | capture_next=0x60 8 | capture_ack=0x68 9 | 10 | capture_ap_vld=0x160 11 | capture_start=0x134 12 | 13 | echo Hold on... 14 | echo $write $capture_next 0 15 | $write $capture_next 0 16 | echo $write $capture_ack 1 17 | $write $capture_ack 1 18 | #sleep 1 19 | echo $write $capture_ack 0 20 | $write $capture_ack 0 21 | echo $write $capture_next 1 22 | $write $capture_next 1 23 | 24 | echo Capturing... 25 | #sleep 3 26 | 27 | let addr=$[$capture_start] 28 | while [[ $addr -lt $[$capture_ap_vld] ]] ; do 29 | echo $read $addr 30 | $read $addr 31 | let addr=$[addr + 4] 32 | done 33 | -------------------------------------------------------------------------------- /scripts/custom-ring-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | # Find FPGA Innova netdev 6 | dev=$($basedir/mlx_netdev.sh) 7 | 8 | echo Setting up custom ring related settings for \"$dev\" 9 | 10 | ip=10.0.0.1 11 | fpga_mac=00:00:00:00:00:01 12 | 13 | mlnx_qos -i $dev --pfc=1,0,0,0,0,0,0,0 14 | 15 | # Find local ConnectX MAC 16 | local_mac=$(ip link show $dev | sed -n s'# *link/ether \(.*\) brd.*#\1#p') 17 | local_ip=$(/sbin/ip -o -4 addr list $dev | awk '{print $4}' | cut -d/ -f1) 18 | 19 | # Set a static route 20 | sudo ip route replace $ip/32 dev $dev 21 | sudo ip neigh replace to $ip dev $dev lladdr $fpga_mac 22 | 23 | # Disable ICRC and RoCE IP header checksum checks in ConnectX hardware 24 | # .rxt.checks.rxt_checks_packet_checks_wrapper.g_check_mask.packet_checks_action0.bits_ng.bad_icrc 25 | sudo mcra /dev/mst/mt4117_pciconf0 0x5363c.12:1 0 26 | # .rxt.checks.rxt_checks_packet_checks_wrapper.g_check_mask.packet_checks_action1.bits_ng.bad_icrc 27 | sudo mcra /dev/mst/mt4117_pciconf0 0x5367c.12:1 0 28 | # .rxt.checks.rxt_checks_packet_checks_wrapper.g_check_mask.packet_checks_action0.bits_ng.bad_roce_l3_header_corrupted 29 | sudo mcra /dev/mst/mt4117_pciconf0 0x53628.3:1 0 30 | # .rxt.checks.rxt_checks_packet_checks_wrapper.g_check_mask.packet_checks_action1.bits_ng.bad_roce_l3_header_corrupted 31 | sudo mcra /dev/mst/mt4117_pciconf0 0x53668.3:1 0 32 | -------------------------------------------------------------------------------- /scripts/disable-mellanox-shell-credits.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find FPGA Innova netdev 4 | devs=$(ls /dev/mst/mt4117_pciconf*_fpga_i2c) 5 | 6 | echo Disabling Mellanox shell credits 7 | 8 | function set_credits_enable() { 9 | local dev="$1" 10 | local reg="$2" 11 | cur=$(sudo mlx_fpga -d $dev r $reg | grep -v 'Unsupported SBU ID') 12 | sudo mlx_fpga -d $dev w $reg $[$cur | (1 << 15)] | grep -v 'Unsupported SBU ID' 13 | } 14 | 15 | for dev in $devs ; do 16 | # .cxp.prt_config.prt_config_buffers.rxb_config.fifo0_rxb_credits_enable 17 | set_credits_enable $dev 0x990004 18 | # .nwp.prt_config.prt_config_buffers.rxb_config.fifo0_rxb_credits_enable 19 | set_credits_enable $dev 0x9b0004 20 | done 21 | 22 | function set_mtu() { 23 | local dev="$1" 24 | local reg="$2" 25 | local mtu="$3" 26 | 27 | cur=$(sudo mlx_fpga -d $dev r $reg | grep -v 'Unsupported SBU ID') 28 | printf "cur = 0x%x\n" $cur 29 | new=$[($cur & ~((1 << 14) - 1)) | $mtu] 30 | printf "new = 0x%x\n" $new 31 | sudo mlx_fpga -d $dev w $reg $new | grep -v 'Unsupported SBU ID' 32 | } 33 | 34 | echo Setting shell MTU to 1522 35 | for dev in $devs ; do 36 | # cxp.prt_config.prt_config_common.mtu_frame_size 37 | set_mtu $dev 0x99201c 1522 38 | # .nwp.prt_config.prt_config_common.mtu_frame_size 39 | set_mtu $dev 0x9b201c 1522 40 | done 41 | -------------------------------------------------------------------------------- /scripts/dump-flow-table.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare -A regs=([source ip]=0x10 \ 4 | [dest ip]=0x11 \ 5 | [source port]=0x12 \ 6 | [dest port]=0x13 \ 7 | [dest port]=0x13 \ 8 | [result_action]=0x18 \ 9 | [valid]=0x20) 10 | 11 | for reg in "${!regs[@]}" ; do 12 | printf "$reg," 13 | done 14 | 15 | printf "entry\n" 16 | 17 | #for entry in $(seq 1023) ; do 18 | for entry in 149 150 956 957 ; do 19 | register.sh 0x418 w 0x5 $entry 20 | for reg in "${!regs[@]}" ; do 21 | register.sh 0x418 r ${regs[$reg]} | xargs echo -n 22 | printf "," 23 | done 24 | printf "$entry\n" 25 | done 26 | -------------------------------------------------------------------------------- /scripts/fpga-debug-mode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dir=$(dirname $0) 4 | . $dir/fpga.inc.sh 5 | 6 | regs=(0x9b0000 0x9b1000 0x990000 0x991000) 7 | values=(0x20 0x1 0x20 0x1) 8 | set=$1 9 | let i=0 10 | for reg in ${regs[@]} ; do 11 | cur=$($read_cmd $reg) 12 | if [[ -z "$set" ]] ; then 13 | echo $cur 14 | elif [[ "$set" == "set" ]] ; then 15 | cur=$[$cur | ${values[$i]}] 16 | elif [[ "$set" == "clear" ]] ; then 17 | cur=$[$cur & ~${values[$i]}] 18 | fi 19 | echo $write_cmd $reg $cur 20 | $write_cmd $reg $cur 21 | let i=$[i+1] 22 | done 23 | 24 | -------------------------------------------------------------------------------- /scripts/fpga-load.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | device=/dev/mst/mt4117_pciconf0 28 | dataset=0xf2018 29 | dataclear=0xf201c 30 | 31 | image_select=0x200 32 | force_load=0x100 33 | 34 | factory=$1 35 | 36 | if [[ -n "$factory" ]] ; then 37 | # use factory image 38 | sudo mcra $device $dataset $image_select 39 | sleep 1 40 | sudo mcra $device $dataset 0x0 41 | 42 | echo Expect factory to be selected 43 | fi 44 | 45 | ./fpga-status.sh 46 | 47 | # disable the load bit 48 | sudo mcra $device $dataclear $force_load 49 | sleep 1 50 | sudo mcra $device $dataclear 0 51 | 52 | # reenable the load bit 53 | sudo mcra $device $dataset $force_load 54 | sleep 1 55 | sudo mcra $device $dataclear 0 56 | 57 | sleep 3 58 | echo Expect image to be loaded 59 | ./fpga-status.sh 60 | -------------------------------------------------------------------------------- /scripts/fpga-status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | . fpga.inc.sh 28 | 29 | gpio_datain=$(sudo mcra /dev/mst/mt4117_pciconf0 0xf2004) 30 | fpga_done=$[$gpio_datain & (1 << 6)] 31 | image_select=$[$gpio_datain & (1 << 9)] 32 | force_load=$[$gpio_datain & (1 << 8)] 33 | 34 | if [ "$fpga_done" -eq 0 ] ; then 35 | echo "FPGA not loaded" 36 | else 37 | echo "FPGA loaded" 38 | fi 39 | 40 | if [ "$image_select" -eq 0 ] ; then 41 | echo "Image: user" 42 | else 43 | echo "Image: factory" 44 | fi 45 | 46 | if [ "$force_load" -eq 0 ] ; then 47 | echo "Not force loading" 48 | else 49 | echo "Force load" 50 | fi 51 | 52 | mlnx_image_number=$[$($read_cmd 0x900000)] 53 | build_number=$[$($read_cmd 0x900024) >> 16] 54 | 55 | echo "Mellanox image #${mlnx_image_number}" 56 | echo "Build number #${build_number}" 57 | -------------------------------------------------------------------------------- /scripts/fpga.inc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | device=$(ls /dev/mst/mt4117_pciconf*_fpga_i2c) 28 | read_cmd="sudo mlx_fpga -d $device read" 29 | write_cmd="sudo mlx_fpga -d $device write" 30 | -------------------------------------------------------------------------------- /scripts/mlx_ip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dir=$(dirname $0) 4 | dev=${1:-$($dir/mlx_netdev.sh)} 5 | ip -4 a show dev $dev | grep inet | awk '{print $2}' | cut -f1 -d'/' 6 | -------------------------------------------------------------------------------- /scripts/mlx_netdev.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find the first ConnectX device with an IP assigned. 4 | # TODO find an Innova device 5 | 6 | # fpga_mst_dev=$(ls /dev/mst/*fpga_i2c) 7 | # cx_mst_dev=${fpga_mst_dev%%_fpga_i2c} 8 | 9 | # bdf=$(sudo mst status | grep -Pzo "${cx_mst_dev}.*\n.*domain:bus:dev.fn=\K(.*)(?= addr)") 10 | # netdev=$(ls -d /sys/bus/pci/devices/$bdf/net/* | xargs -n1 basename) 11 | # echo $netdev 12 | 13 | candidates=$(ls -d /sys/bus/pci/drivers/mlx5_core/*/net/* | xargs -n1 basename) 14 | declare -a ether 15 | ether=() 16 | for netdev in ${candidates[@]} ; do 17 | if ip link show $netdev | grep ether > /dev/null ; then 18 | ether+=($netdev) 19 | fi 20 | done 21 | declare -a has_ip 22 | has_ip=() 23 | for netdev in ${ether[@]} ; do 24 | if ip addr show dev $netdev | grep inet > /dev/null ; then 25 | has_ip+=($netdev) 26 | fi 27 | done 28 | echo ${has_ip[@]} 29 | -------------------------------------------------------------------------------- /scripts/packets_stats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0xc8) 27 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0xd4) 28 | let to_ikernel=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0xe0) 29 | echo --------flow table n2h--------- 30 | echo n2h_flow_table_passthrough: $passthrough 31 | echo n2h_flow_table_drop: $drop 32 | echo n2h_flow_table_to_ikernel: $to_ikernel 33 | echo 34 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x2c0) 35 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x2cc) 36 | let to_ikernel=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x2d8) 37 | echo --------flow table h2n--------- 38 | echo h2n_flow_table_passthrough: $passthrough 39 | echo h2n_flow_table_drop: $drop 40 | echo h2n_flow_table_to_ikernel: $to_ikernel 41 | echo 42 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x26c) 43 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x278) 44 | let generated=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x284) 45 | echo --------ikernel n2h--------- 46 | echo n2h_ik0_passthrough: $passthrough 47 | echo n2h_ik0_drop: $drop 48 | echo n2h_ik0_generated: $generated 49 | echo 50 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x4bc) 51 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x4c8) 52 | let generated=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x4d4) 53 | echo --------ikernel h2n--------- 54 | echo h2n_ik0_passthrough: $passthrough 55 | echo h2n_ik0_drop: $drop 56 | echo h2n_ik0_generated: $generated 57 | echo 58 | ikernels=$(seq 0 5) 59 | sudo ../manager/memcachedctl.py status -i $ikernels 60 | for ik in $ikernels ; do 61 | let memcached_ring_id=$(. register.sh 0x1014 r 0x18 $ik) 62 | echo MEMCACHED_RING_ID $memcached_ring_id 63 | done 64 | -------------------------------------------------------------------------------- /scripts/pkt-drop-rate-measure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function measure() 4 | { 5 | start=$(cat /sys/class/net/enp2s0/statistics/rx_dropped) 6 | sleep 5 7 | end=$(cat /sys/class/net/enp2s0/statistics/rx_dropped) 8 | echo "scale=2 ; ($end - $start) / 5" | bc 9 | } 10 | 11 | for i in {1..3} ; do 12 | measure 13 | done 14 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/get_rx_throughput.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/bash 3 | #input broadcast/unicast packets/bits 4 | 5 | if [ $# -ne 2 ]; then 6 | echo "Usage: ./get_throughput.sh [broadcast/unicast] [packets/bytes]" 7 | exit 1 8 | fi 9 | 10 | mode=$1 11 | pkts_bits=$2 12 | escape_char=\' 13 | 14 | if [ $mode == unicast ] ; then 15 | if [ $pkts_bits == packets ] ; then 16 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep rx_vport_unicast_packets|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep rx_vport_unicast_packets|cut -d: -f2); echo $[$end - $start]/1000000 | bc -l`; echo $result Mpps' 17 | else 18 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep rx_vport_unicast_bytes|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep rx_vport_unicast_bytes|cut -d: -f2); echo $[8*($end - $start)]/1024/1024/1024 | bc -l`; echo $result Gbps' 19 | fi 20 | else 21 | if [ $pkts_bits == packets ] ; then 22 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep rx_vport_broadcast_packets|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep rx_vport_broadcast_packets|cut -d: -f2); echo $[$end - $start]/1000000 | bc -l`; echo $result Mpps' 23 | else 24 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep rx_vport_broadcast_bytes|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep rx_vport_broadcast_bytes|cut -d: -f2); echo $[8*($end - $start)]/1024/1024/1024 | bc -l`; echo $result Gbps' 25 | fi 26 | fi 27 | 28 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/get_tx_throughput.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/bash 3 | #input multicast/unicast packets/bits 4 | 5 | if [ $# -ne 2 ]; then 6 | echo "Usage: ./get_throughput.sh [multicast/unicast] [packets/bytes]" 7 | exit 1 8 | fi 9 | 10 | mode=$1 11 | pkts_bits=$2 12 | escape_char=\' 13 | 14 | if [ $mode == unicast ] ; then 15 | if [ $pkts_bits == packets ] ; then 16 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep tx_vport_unicast_packets|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep tx_vport_unicast_packets|cut -d: -f2); echo $[$end - $start]/1000000 | bc -l`; echo $result Mpps' 17 | else 18 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep tx_vport_unicast_bytes|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep tx_vport_unicast_bytes|cut -d: -f2); echo $[8*($end - $start)]/1024/1024/1024 | bc -l`; echo $result Gbps' 19 | fi 20 | else 21 | if [ $pkts_bits == packets ] ; then 22 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep tx_vport_multicast_packets|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep tx_vport_multicast_packets|cut -d: -f2); echo $[$end - $start]/1000000 | bc -l`; echo $result Mpps' 23 | else 24 | watch -n0 'result=`start=$(ethtool -S enp2s0|grep tx_vport_multicast_bytes|cut -d: -f2); sleep 1 ; end=$(ethtool -S enp2s0|grep tx_vport_multicast_bytes|cut -d: -f2); echo $[8*($end - $start)]/1024/1024/1024 | bc -l`; echo $result Gbps' 25 | fi 26 | fi 27 | 28 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/ipktgen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #[input]: packet_size burst_size ikernel_tokens host_tokens [nwp_sx_gen_credits_init cxp_rx_passthrough_credits_init] 3 | 4 | register=../register.sh 5 | 6 | if [ $# -lt 4 ]; then 7 | echo "Usage: ./ipktgen.sh packet_size burst_size ikernel_tokens host_tokens [nwp_sx_gen_credits_init cxp_rx_passthrough_credits_init]" 8 | exit 1 9 | fi 10 | 11 | headers_size=46 12 | packet_size=$1 13 | payload_size=$[$packet_size-$headers_size] 14 | burst_size=$2 15 | #tokens=`$register 0x458 r 0x21` 16 | #gen_credits_init="" 17 | #passthrough_credits_init="" 18 | 19 | if [ $# -gt 2 ]; then 20 | #tokens=$3 21 | #if [ $# -eq 4 ]; then 22 | # echo "you have to update credits in cxp and nwp simultaneously" 23 | # exit 1 24 | #fi 25 | #if [ $# -eq 5 ]; then 26 | #gen_credits_init=$4 27 | #passthrough_credits_init=$5 28 | #num1=`echo $[0x40]`; num2=`echo $[0xc0]` 29 | #echo $num1 $num2 30 | #let exp_total=($num1 + $num2) 31 | #let input_total=($gen_credits_init + $passthrough_credits_init) 32 | #if [ $input_total -gt $exp_total ]; then 33 | # echo "input_total is $input_total not equal to $exp_total" 34 | # exit 1 35 | #fi 36 | #fi 37 | fi 38 | 39 | ../disable-mellanox-shell-credits.sh 40 | 41 | # update credits in lossless fifo (cxp_rx and nwp_sx) 42 | #echo passthrugh_credits_init = $passthrough_credits_init 43 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x990004.9 1 44 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x990004.0 $passthrough_credits_init 45 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x990004.9 0 46 | #echo gen_credits_init = $gen_credits_init 47 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x9b1010.9 1 48 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x9b1010.0 $gen_credits_init 49 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x9b1010.9 0 50 | 51 | #change saturation and log_quota 52 | echo passthrough and genearted: saturation=0xf log_qouta=0xf 53 | $register 0x458 w 0x22 0xf 54 | $register 0x458 w 0x23 0xf 55 | $register 0x458 w 0x2 0xf 56 | $register 0x458 w 0x3 0xf 57 | 58 | 59 | # change the number of tokens 60 | #echo tokens=$tokens 61 | #$register 0x458 w 0x21 $tokens 62 | 63 | echo run_client... 64 | ../run_client.sh $burst_size $payload_size offload $burst_size 65 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/kill_sockperf_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for pid in $(ps -ef | grep "sockperf" | awk '{print $2}'); do sudo kill -2 $pid; done 4 | 5 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/manual_ikernel_pktgen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #[input]: packet_size burst_size [tokens nwp_sx_gen_credits_init cxp_rx_passthrough_credits_init] 3 | 4 | if [ $# -lt 2 ]; then 5 | echo "Usage: ./ipktgen.sh packet_size burst_size [tokens [nwp_sx_gen_credits_init cxp_rx_passthrough_credits_init] ]" 6 | exit 1 7 | fi 8 | 9 | packet_size=$1 10 | burst_size=$2 11 | #tokens=0 12 | #gen_credits_init="" 13 | #passthrough_credits_init="" 14 | 15 | #if [ $# -gt 2 ]; then 16 | # tokens=$3 17 | # if [ $# -eq 4 ]; then 18 | # echo "you have to update credits in cxp and nwp simultaneously" 19 | # exit 1 20 | # fi 21 | # if [ $# -eq 5 ]; then 22 | # gen_credits_init=$4 23 | # passthrough_credits_init=$5 24 | # num1=`echo $[0x40]`; num2=`echo $[0xc0]` 25 | # echo $num1 $num2 26 | # let exp_total=($num1 + $num2) 27 | # let input_total=($gen_credits_init + $passthrough_credits_init) 28 | # if [ $exp_total -ne $input_total ]; then 29 | # echo "input_total is $input_total not equal to $exp_total" 30 | # exit 1 31 | # fi 32 | # fi 33 | #fi 34 | 35 | 36 | # -1) update credits in lossless fifo (cxp_rx and nwp_sx) 37 | #echo passthrugh_credits_init = $passthrough_credits_init 38 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x990004.9 1 39 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x990004.0 $passthrough_credits_init 40 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x990004.9 0 41 | #echo gen_credits_init = $gen_credits_init 42 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x9b1010.9 1 43 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x9b1010.0 $gen_credits_init 44 | #sudo mcra -a ~haggai/newton.adb /dev/mst/mt4117_pciconf0_fpga 0x9b1010.9 0 45 | 46 | ../disable-mellanox-shell-credits.sh 47 | 48 | # 0) enable nica pipeline 49 | echo enable nica pipeline 50 | sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga w 0x410 1 51 | sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga w 0x10 1 52 | 53 | # 1) init burst_size in pktgen ikernel 54 | echo burst_size = $burst_size 55 | ./register.sh 0x1014 w 0x10 $burst_size 56 | 57 | # 2) attatch the ikernel manually 58 | echo ik_attach 59 | ./register.sh 0x418 w 0x18 2 60 | ./register.sh 0x418 w 0 0 61 | 62 | # 3) change the number of tokens 63 | if [ `echo $[$tokens]` -ne 0 ];then 64 | ./register.sh 0x458 w 0x21 $tokens 65 | fi 66 | echo tokens=`./register.sh 0x458 r 0x21` 67 | 68 | # 4) send packets 69 | dd if=/dev/zero of=$packet_size"_file" bs=$packet_size count=1 70 | file $packet_size"_file" 71 | echo run_client... 72 | echo $packet_size"_file" 73 | cat $packet_size"_file" > /dev/udp/192.168.0.3/1111 74 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/packets_stats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0xa8) 27 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0xb4) 28 | let generated=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0xc0) 29 | echo --------flow table n2h--------- 30 | echo n2h_flow_table_passthrough: $passthrough 31 | echo n2h_flow_table_drop: $drop 32 | echo n2h_flow_table_generated: $generated 33 | echo 34 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x298) 35 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x2a4) 36 | let generated=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x2b0) 37 | echo --------flow table h2n--------- 38 | echo h2n_flow_table_passthrough: $passthrough 39 | echo h2n_flow_table_drop: $drop 40 | echo h2n_flow_table_generated: $generated 41 | echo 42 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x244) 43 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x250) 44 | let generated=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x25c) 45 | echo --------flow table n2h--------- 46 | echo n2h_ik0_passthrough: $passthrough 47 | echo n2h_ik0_drop: $drop 48 | echo n2h_ik0_generated: $generated 49 | echo 50 | let passthrough=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x484) 51 | let drop=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x490) 52 | let generated=$(sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga r 0x49c) 53 | echo --------flow table h2n--------- 54 | echo h2n_ik0_passthrough: $passthrough 55 | echo h2n_ik0_drop: $drop 56 | echo h2n_ik0_generated: $generated 57 | 58 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/plot_bar.py: -------------------------------------------------------------------------------- 1 | # a stacked bar plot with errorbars 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import argparse 5 | from scipy import stats 6 | import math 7 | 8 | 9 | def avg(numbers): 10 | return float(sum(numbers)) / max(len(numbers), 1) 11 | 12 | 13 | parser = argparse.ArgumentParser() 14 | parser.add_argument('-n', '--name', help="graph name", required=True) 15 | parser.add_argument('-ib', '--baseline_input', help="baseline input data - FILE", required=True) 16 | parser.add_argument('-ii', '--ikernel_input', help="ikernel input data - FILE", required=True) 17 | parser.add_argument('-x', '--x_axis', help="X axis name", required=True) 18 | parser.add_argument('-y', '--y_axis', help="Y axis name", required=True) 19 | parser.add_argument('-o', '--output', help="graph jpg name", required=True) 20 | 21 | args = parser.parse_args() 22 | 23 | x_b = [] 24 | y_b = [] 25 | conf_int_b = [] 26 | x_i = [] 27 | y_i = [] 28 | conf_int_i = [] 29 | 30 | with open(args.baseline_input) as fp: 31 | for line in fp: 32 | temp = line.split(" ") 33 | temp.pop() 34 | x_b.append(float(temp[0])) 35 | temp.pop(0) 36 | data = [] 37 | for val in temp: 38 | data.append(float(val)) 39 | mean, sigma = np.mean(data), np.std(data) 40 | conf_int = stats.t.interval(0.95,len(data)-1,loc=mean,scale=sigma/math.sqrt(len(data))) 41 | y_b.append(avg(data)) 42 | conf_int_b.append(conf_int) 43 | fp.close() 44 | 45 | with open(args.ikernel_input) as fp: 46 | for line in fp: 47 | temp = line.split(" ") 48 | temp.pop() 49 | x_i.append(float(temp[0])) 50 | temp.pop(0) 51 | data = [] 52 | for val in temp: 53 | data.append(float(val)) 54 | mean, sigma = np.mean(data), np.std(data) 55 | conf_int = stats.t.interval(0.95,len(data)-1,loc=mean,scale=sigma/math.sqrt(len(data))) 56 | y_i.append(avg(data)) 57 | conf_int_i.append(conf_int) 58 | fp.close() 59 | 60 | fig = plt.figure() 61 | N = len(x_i) #or x_i 62 | ind = np.arange(N) # the x locations for the groups 63 | width = 3 # the width of the bars: can also be len(x) sequence 64 | 65 | x_axis_fixed = [] 66 | for val in x_i: #or x_i 67 | x_axis_fixed.append(val+(width/2.0)) 68 | 69 | i=0 70 | for xe,ye in zip(x_axis_fixed,conf_int_b): 71 | new_ye = [] 72 | for val in ye: 73 | new_ye.append(val + y_i[i]) 74 | i+=1 75 | plt.plot([xe] * len(new_ye), new_ye, 'g-') 76 | for xe,ye in zip(x_axis_fixed,conf_int_i): 77 | plt.plot([xe] * len(ye), ye,'g-') 78 | 79 | 80 | N = len(x_b) #or x_i 81 | ind = np.arange(N) # the x locations for the groups 82 | width = 3 # the width of the bars: can also be len(x) sequence 83 | 84 | p1=plt.bar(x_i,y_i,width,color="r") 85 | p2=plt.bar(x_i,y_b,width,bottom=y_i) 86 | 87 | plt.ylabel(args.y_axis) 88 | plt.xlabel(args.x_axis) 89 | plt.title(args.name) 90 | plt.xticks(x_axis_fixed, x_i) #or x_i 91 | plt.yticks(np.arange(0, 46, 5)) 92 | plt.legend((p1[0], p2[0]), ('ikernel', 'baseline')) 93 | 94 | fig.savefig(args.output+'.jpg') 95 | #plt.show() 96 | 97 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/run_experiments.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sizes=(64 128 256 512) 4 | 5 | for packet_size in "${sizes[@]}"; do 6 | ./run_variable_tokens.sh 'host_'$packet_size'.log' 'ikernel_'$packet_size'.log' $packet_size 7 | done 8 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/run_sockperf_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #GDB="gdb --args" 4 | #[input] : [time_to_run_in_seconds[default-inf] packet_size] 5 | 6 | LIBVMA=/home/maroun/libvma/src/vma/.libs/libvma.so 7 | 8 | cores=6 9 | time_to_run=1000000 10 | packet_size=64 11 | headers_size=46 12 | 13 | if [ $# -eq 2 ]; then 14 | time_to_run=$1 15 | packet_size=$2 16 | fi 17 | 18 | payload_size=$[$packet_size-$headers_size] 19 | 20 | for i in `seq 1 1 $cores`; do 21 | echo running server number $i 22 | let j=($i-1) 23 | let k=(1111+$j) 24 | 25 | sudo \ 26 | taskset -c $j \ 27 | $GDB env \ 28 | # LD_PRELOAD=$LIBVMA \ 29 | VMA_MTU=200 \ 30 | VMA_RX_POLL=200000 \ 31 | VMA_RX_POLL_INIT=200000 \ 32 | VMA_RX_UDP_POLL_OS_RATIO=0 \ 33 | VMA_RX_BUFS=30000 \ 34 | VMA_THREAD_MODE=0 \ 35 | VMA_TX_BUFS=200000 \ 36 | VMA_TX_WRE=16000 \ 37 | /home/maroun/sockperf/sockperf tp --mc-tx-if=192.168.0.5 -i 192.168.0.8 -m $payload_size -t $time_to_run --load-vma --daemonize --nonblocked --dontwarmup --mps max 38 | 39 | #/home/maroun/sockperf/sockperf tp --mc-tx-if=192.168.0.5 -i 224.4.4.4 -m $payload_size -t $time_to_run --load-vma --daemonize --nonblocked --dontwarmup --mps max 40 | done 41 | 42 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/run_variable_tokens.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #input: file_name packet_size 3 | 4 | if [ $# -ne 4 ]; then 5 | echo "Usag: ./... password ikernel_file_name host_file_name packet_size" 6 | exit 1 7 | fi 8 | 9 | password=$1;shift 10 | ikernel_file=$1 11 | host_file=$2 12 | packet_size=$3 13 | 14 | if [ -f $ikernel_file ]; then 15 | rm -f $ikernel_file 16 | fi 17 | if [ -f $host_file ]; then 18 | rm -f $host_file 19 | fi 20 | 21 | MAX_DELTA=100 #92 22 | burst_size=$[300<<22] 23 | #nwp_sx_generate_credits=0xc0 24 | #cxp_rx_passthrough_credits=0x40 25 | nwp_sx_generate_credits="" 26 | cxp_rx_passthrough_credits="" 27 | 28 | 29 | sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga load 30 | sudo modprobe -vr mlx_accel_tools 31 | sudo modprobe -v mlx_accel_tools && sudo mst restart --with_fpga 32 | sleep 5s 33 | 34 | if [ -f temp_host ];then 35 | rm -f temp_host 36 | fi 37 | if [ -f temp_ikernel ];then 38 | rm -f temp_ikernel 39 | fi 40 | 41 | for ((delta = 0; $delta <= $MAX_DELTA ; delta=$delta+10)); do 42 | rm -f temp_ikernel 43 | rm -f temp_host 44 | host_tokens=$[$MAX_DELTA-$delta] 45 | ikernel_tokens=$delta 46 | echo $host_tokens >> temp_host 47 | echo $ikernel_tokens >> temp_ikernel 48 | for i in `seq 1 5`; do 49 | ./ipktgen.sh $packet_size $burst_size $ikernel_tokens $host_tokens $nwp_sx_generate_credits $cxp_rx_passthrough_credits 50 | ./run_sockperf_client.sh 20s $packet_size & 51 | sleep 2s 52 | echo $password | sudo -S sshpass -p $password ssh -tt maroun@gpu-os07.ef.technion.ac.il "~/pktgen/get_stats.sh unicast bits" >> temp_ikernel 53 | echo $password | sudo -S sshpass -p $password ssh -tt maroun@gpu-os07.ef.technion.ac.il "~/pktgen/get_stats.sh broadcast bits" >> temp_host 54 | sleep 7s 55 | ./kill_sockperf_client.sh 56 | sudo mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga load 57 | sudo modprobe -vr mlx_accel_tools 58 | sudo modprobe -v mlx_accel_tools && sudo mst restart --with_fpga 59 | sleep 5s 60 | done 61 | less temp_ikernel | grep -v $password | cut -d" " -f1 | tr '\n' ' ' >> $ikernel_file 62 | echo "" >> $ikernel_file 63 | less temp_host | grep -v $password | cut -d" " -f1 | tr '\n' ' ' >> $host_file 64 | echo "" >> $host_file 65 | if [ "$delta" -eq 80 ] ; then 66 | delta=82 #to get the max number of tokens in the next iteration 67 | fi 68 | done 69 | 70 | 71 | #change from tokens to MAX Gbps 72 | awk '{ temp=$1/92*40;$1=""; {printf "%.1f",temp};print $0}' $host_file > host_temp && cat host_temp > $host_file 73 | rm -rf host_temp 74 | awk '{ temp=$1/92*40;$1=""; {printf "%.1f",temp};print $0}' $ikernel_file > ikernel_temp && cat ikernel_temp > $ikernel_file 75 | rm -rf ikernel_temp 76 | 77 | python plot_bar.py -n 'Pktgen ikernel' -ib $host_file -ii $ikernel_file -x 'Max BandWidth for ikernel [Gbps]' -y 'Bandwidth [Gbps]' -o 'pktgen_bandwidth_'$packet_size 78 | -------------------------------------------------------------------------------- /scripts/pktgen_scripts/send_packets_pktgen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #[input]: unicast/broadcast cores 3 | 4 | if [ $# -lt 3 ]; then 5 | echo "Usage: ./get_throughput.sh password [broadcast/unicast] packet_size" 6 | exit 1 7 | fi 8 | 9 | password=$1 ;shift 10 | cores=12 11 | mode=$1;shift 12 | packet_size=$1 13 | mac_addr="ff:ff:ff:ff:ff:ff" 14 | 15 | if [ $mode == unicast ] ; then 16 | mac_addr="7c:fe:90:5f:9d:1e" 17 | fi 18 | 19 | echo $password | sudo -S /home/haggai/pktgen/pktgen_sample02_multiqueue.sh -i enp2s0 -d 192.168.0.3 -m $mac_addr -s 18 -t $cores -c 30 -p 1 20 | -------------------------------------------------------------------------------- /scripts/prepare-mellanox-shell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | tarball=$(readlink -f ${1:-newton_ku060_2_40g_v640.tar}) 28 | 29 | if [ "$#" -lt 1 ] ; then 30 | echo "Missing argument: tarball" 31 | echo "Using: $tarball as a default" 32 | fi 33 | 34 | if [ ! -f "$tarball" ] ; then 35 | echo "File not found: $tarball" 36 | exit 1 37 | fi 38 | 39 | rm -rf user 40 | mkdir -p user 41 | cd user 42 | 43 | dirs=({examples/exp_hls/{vlog,xdc},mlx,project,scripts,tb/exp_vlog}) 44 | tar xvf $tarball ${dirs[@]} 45 | cd .. 46 | patch -p1 -d user < ../scripts/mellanox-shell-scripts.patch 47 | 48 | ln -snf examples/exp_hls user/sources 49 | 50 | ln -snf ../../../../nica/nica/40Gbps/impl/ip/hdl/verilog user/examples/exp_hls/vlog/nica 51 | for ikernel in cms echo memcached passthrough pktgen threshold coap ; do 52 | ln -snf ../../../../ikernels/$ikernel/40Gbps/impl/ip/hdl/verilog user/examples/exp_hls/vlog/$ikernel 53 | done 54 | 55 | ln -snf ../../../../nica/xci user/examples/exp_hls/xci 56 | cd user/examples/exp_hls/vlog 57 | cp -sf ../../../../../nica/verilog/* . 58 | cd - 59 | 60 | # Disable XDC as it has been removed from the repository 61 | # (coap now works with a single clock) 62 | # 63 | # cd user/examples/exp_hls/xdc 64 | # cp -sf ../../../../../ikernels/xdc/* . 65 | # cd - 66 | -------------------------------------------------------------------------------- /scripts/register.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | #[input] : base read/write(r/w) addr_hexa [value_hexa] [ikernel_id] 27 | 28 | base="$1" 29 | cmd="$2" 30 | addr="$3" 31 | if [[ "$cmd" == "w" ]] ; then 32 | value="$4" 33 | ikernel_id="$5" 34 | else 35 | value="" 36 | ikernel_id="$4" 37 | fi 38 | 39 | cmd_reg=$[$base + 0x0] 40 | data_i_reg=$[$base + 0x8] 41 | data_o_reg=$[$base + 0x10] 42 | done_reg=$[$base + 0x18] 43 | ikernel_id_reg=$[$base + 0x20] 44 | 45 | device=/dev/mst/mt4117_pciconf0_fpga_i2c 46 | 47 | if [[ "$cmd" == "w" ]] 48 | then 49 | if [[ -n "$ikernel_id" ]] ; then 50 | sudo mlx_fpga -d $device w $ikernel_id_reg $ikernel_id 51 | fi 52 | sudo mlx_fpga -d $device w $data_i_reg $value 53 | sudo mlx_fpga -d $device w $cmd_reg $[0xc0000000|$addr] 54 | # verify the command is done by reading 1 from the gateway_done register (0x102c): 55 | res=0 56 | while [[ $[$res] == 0 ]] 57 | do 58 | res=`sudo mlx_fpga -d $device r $done_reg` 59 | done 60 | # finally resetting the gateway for the next command and verifying the reset is done: 61 | sudo mlx_fpga -d $device w $cmd_reg 0x0 62 | res=1 63 | while [[ $[$res] == 1 ]] 64 | do 65 | res=`sudo mlx_fpga -d $device r $done_reg` 66 | done 67 | else 68 | if [[ -n "$ikernel_id" ]] ; then 69 | sudo mlx_fpga -d $device w $ikernel_id_reg $ikernel_id 70 | fi 71 | sudo mlx_fpga -d $device w $cmd_reg $[0x80000000|$addr] 72 | res=0 73 | while [[ $[$res] == 0 ]] 74 | do 75 | res=`sudo mlx_fpga -d $device r $done_reg` 76 | done 77 | sudo mlx_fpga -d $device r $data_o_reg 78 | # finally resetting the gateway for the next command and verifying the reset is done: 79 | sudo mlx_fpga -d $device w $cmd_reg 0x0 80 | res=1 81 | while [[ $[$res] == 1 ]] 82 | do 83 | res=`sudo mlx_fpga -d $device r $done_reg` 84 | done 85 | fi 86 | -------------------------------------------------------------------------------- /scripts/reset-fpga.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Start tools driver 4 | modprobe -v mlx_accel_tools 5 | 6 | # Re-load fpga 7 | mlx_fpga -d /dev/mst/mt4117_pciconf0_fpga load 8 | 9 | # Unload drivers 10 | modprobe -vr mlx_accel_tools 11 | 12 | sudo mlxfwreset --yes -d /dev/mst/mt4117_pciconf0 --level 3 reset 13 | 14 | # Start driver 15 | modprobe -v mlx5_ib 16 | 17 | # delay 18 | sleep 1s 19 | 20 | # Start tools driver 21 | modprobe -v mlx_accel_tools 22 | 23 | # Start tools 24 | mst start --with_fpga 25 | -------------------------------------------------------------------------------- /scripts/run_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #input: number_of_packets payload_size [offlad burst_size] 3 | 4 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | 6 | if [ $# -lt 2 ];then 7 | echo "Usage: ./run_client.sh number_of_packets payload_size [offlad burst_size]" 8 | exit 1 9 | fi 10 | 11 | number_of_packets=$1 12 | payload_size=$2 13 | 14 | offload=FALSE 15 | if [ $# -gt 3 ] ; then 16 | offload=TRUE 17 | burst_size=$4 18 | fi 19 | 20 | libvma_dirs=($(readlink -f $basedir/../../../libvma/src/vma/.libs) $(readlink -f $basedir/../../libvma/src/vma/.libs)) 21 | if [[ "${#libvma_dirs}" -eq 0 ]] ; then 22 | echo "Error: couldn't find libvma dir." 23 | fi 24 | libvma_dir=${libvma_dirs[0]} 25 | client=$basedir/../build/software/client 26 | # Find an mlx5_core netdev 27 | dev=$($basedir/mlx_netdev.sh) 28 | # Find local IP address 29 | local_ip=$($basedir/mlx_ip.sh $dev) 30 | remote_ip=192.168.0.8 31 | cmd="LD_PRELOAD=libvma.so LD_LIBRARY_PATH=$libvma_dir $client -c $number_of_packets -I $dev -H $remote_ip -p 1111 -l $local_ip -s $payload_size" 32 | 33 | if [ $offload == TRUE ] ; then 34 | echo env VMA_RX_NO_CSUM=1 VMA_NICA_ACCESS_MODE=0 $cmd --offload -b $burst_size 35 | sudo env VMA_RX_NO_CSUM=1 VMA_NICA_ACCESS_MODE=0 $cmd --offload -b $burst_size 36 | else 37 | echo $cmd 38 | sudo env $cmd 39 | fi 40 | -------------------------------------------------------------------------------- /scripts/run_cms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | # [input]: secs threshold_value b/i [baseline/ikernel] 27 | #sudo env VMA_RX_NO_CSUM=1 VMA_NICA_ACCESS_MODE=0 LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ ./threshold_server -s $1 -v $2 -I enp2s0 28 | if [[ "$2" == "b" ]] 29 | then 30 | sudo env LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ LD_PRELOAD=libvma.so VMA_NICA_EMULATION=1 ./cms_server -s $1 -I enp2s0 31 | else 32 | sudo env VMA_NICA_ACCESS_MODE=0 VMA_RX_NO_CSUM=1 LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ ./cms_server -s $1 -I enp2s0 33 | fi 34 | #sudo env LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ VMA_NICA_EMULATION=1 ./threshold_server -s $1 -v $2 -I enp2s0 35 | 36 | -------------------------------------------------------------------------------- /scripts/run_echo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # [input]: secs b/i [baseline/ikernel] 3 | if [[ "$2" == "b" ]] 4 | then 5 | sudo env LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ LD_PRELOAD=libvma.so VMA_NICA_EMULATION=1 ./echo_server -s $1 -I enp2s0 6 | else 7 | sudo env VMA_NICA_ACCESS_MODE=0 VMA_RX_NO_CSUM=1 LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ ./echo_server -s $1 -I enp2s0 8 | fi 9 | 10 | -------------------------------------------------------------------------------- /scripts/run_threshold.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | # [input]: secs threshold_value b/i [baseline/ikernel] 27 | #sudo env VMA_RX_NO_CSUM=1 VMA_NICA_ACCESS_MODE=0 LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ ./threshold_server -s $1 -v $2 -I enp2s0 28 | if [[ "$3" == "b" ]] 29 | then 30 | sudo env LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ VMA_NICA_EMULATION=1 ./threshold_server -s $1 -v $2 -I enp2s0 31 | else 32 | sudo env VMA_NICA_ACCESS_MODE=0 VMA_RX_NO_CSUM=1 LD_PRELOAD=libvma.so LD_LIBRARY_PATH=~/libvma/src/vma/.libs/ ./threshold_server -s $1 -v $2 -I enp2s0 33 | fi 34 | -------------------------------------------------------------------------------- /scripts/start-tools.sh: -------------------------------------------------------------------------------- 1 | sudo modprobe -v mlx_accel_tools && sudo mst start --with_fpga && sudo mst status 2 | -------------------------------------------------------------------------------- /scripts/udp_client.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, 6 | # are permitted provided that the following conditions are met: 7 | # 8 | # * Redistributions of source code must retain the above copyright notice, this 9 | # list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation and/or 12 | # other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | from scapy.all import * 26 | import socket 27 | 28 | my_reader = PcapReader('../tests/input.pcap') 29 | i = 0 30 | udp_ip = "127.0.0.1" 31 | udp_port = 9000 32 | 33 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 34 | 35 | for packet in my_reader: 36 | sock.sendto(packet.load, (udp_ip, udp_port)) 37 | i += 1 38 | 39 | print "Total packets: {}".format(i) -------------------------------------------------------------------------------- /scripts/update-mellanox-shell-scripts-patch.sh: -------------------------------------------------------------------------------- 1 | (for f in `find user-mod -name *.tcl` ; do diff -uN user/${f##user-mod/} $f ; done ) > ../scripts/mellanox-shell-scripts.patch 2 | -------------------------------------------------------------------------------- /scripts/watch-counter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | counter=$1 4 | dev=$2 5 | 6 | start=$(ethtool -S $dev | grep $counter | cut -d: -f2) 7 | sleep 1 8 | end=$(ethtool -S $dev | grep $counter | cut -d: -f2) 9 | 10 | echo $[$end - $start] 11 | -------------------------------------------------------------------------------- /software/.gitignore: -------------------------------------------------------------------------------- 1 | client 2 | server 3 | -------------------------------------------------------------------------------- /software/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | find_package(Boost COMPONENTS system program_options REQUIRED) 3 | find_package(ibverbs REQUIRED) 4 | 5 | find_path(NICA_HLS_DIR nica-top.hpp 6 | HINTS 7 | ../nica/hls/ 8 | ) 9 | 10 | find_path(THRESHOLD_IKERNEL_DIR threshold.hpp 11 | HINTS 12 | ../ikernels/hls/ 13 | ) 14 | 15 | include(FindPkgConfig) 16 | pkg_check_modules(UUID REQUIRED uuid) 17 | 18 | include_directories(${UDP_INCLUDE_DIR} ${THRESHOLD_IKERNEL_DIR} ${NICA_HLS_DIR} 19 | ${UUID_INCLUDE_DIRS} ${IBVERBS_INCLUDE_DIRS} ../libnica) 20 | 21 | set(THREADS_PREFER_PTHREAD_FLAG ON) 22 | find_package(Threads REQUIRED) 23 | 24 | add_executable(threshold_server ThresholdServerMain.cpp RunnableServerBase.cpp 25 | StatisticsUdpServer.cpp UdpServer.cpp) 26 | add_executable(cms_server CmsServerMain.cpp RunnableServerBase.cpp 27 | CmsUdpServer.cpp UdpServer.cpp ../ikernels/hls/cms.cpp) 28 | add_executable(echo_server EchoServerMain.cpp RunnableServerBase.cpp 29 | EchoUdpServer.cpp UdpServer.cpp UdpClient.cpp) 30 | 31 | add_executable(client RunnableUdpClient.cpp UdpClient.cpp) 32 | 33 | foreach(executable threshold_server cms_server echo_server client) 34 | target_link_libraries(${executable} Threads::Threads) 35 | target_link_libraries(${executable} ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) 36 | target_link_libraries(${executable} nica) 37 | target_link_libraries(${executable} ${UUID_LIBRARIES}) 38 | target_link_libraries(${executable} ${IBVERBS_LIBRARIES}) 39 | target_compile_features(${executable} PRIVATE cxx_rvalue_references cxx_generalized_initializers) 40 | endforeach(executable) 41 | -------------------------------------------------------------------------------- /software/CmsServerMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "RunnableServerBase.hpp" 27 | #include "CmsUdpServer.hpp" 28 | #include "cms-ikernel.hpp" 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | class cms_main : public RunnableServerBase { 35 | public: 36 | cms_main(const unsigned char *uuid, int argc, char **argv) 37 | : RunnableServerBase(uuid, argc, argv) {} 38 | 39 | protected: 40 | 41 | virtual void preflight() { 42 | topKs = std::vector>>(thread_num); 43 | } 44 | 45 | std::string vec_to_str(const std::vector& vec) { 46 | std::ostringstream sstream; 47 | 48 | if (vec.size() > 0) { 49 | std::copy(&vec[0], &vec[vec.size() - 1], std::ostream_iterator(sstream, " ")); 50 | sstream << vec[vec.size() - 1]; 51 | 52 | } 53 | 54 | return sstream.str(); 55 | } 56 | 57 | virtual void postflight() { 58 | if (ikernel_top_k.size() > 0) { 59 | std::cout << "iKernel topK: " << vec_to_str(ikernel_top_k) << std::endl; 60 | } else { 61 | std::cout << "iKernel topK is empty" << std::endl; 62 | } 63 | 64 | std::cout << "Host topK per thread: " << std::endl; 65 | 66 | for (int i = 0; i < thread_num; ++i) { 67 | std::vector host_top_k = topKs[i].get(); 68 | std::cout << "Thread " << i << ": " << vec_to_str(host_top_k) << std::endl; 69 | } 70 | } 71 | 72 | virtual void start_server(const int &thread_id) { 73 | CmsUdpServer::args args = { 74 | .port = short(port + thread_id), 75 | .interface = vm["interface"].as(), 76 | }; 77 | std::promise> topK; 78 | topKs[thread_id] = topK.get_future(); 79 | CmsUdpServer s(io_service, args); 80 | s.do_receive(); 81 | io_service.run(); 82 | 83 | topK.set_value(s.get_host_topK()); 84 | 85 | if (thread_id == 0) { 86 | ikernel_top_k = s.get_topK(); 87 | } 88 | } 89 | 90 | std::vector>> topKs; 91 | std::vector ikernel_top_k; 92 | 93 | }; 94 | 95 | int main(int argc, char **argv) { 96 | uuid_t uuid = CMS_UUID; 97 | 98 | return cms_main(uuid, argc, argv).run(); 99 | } 100 | -------------------------------------------------------------------------------- /software/CmsUdpServer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef IKERNEL_CMSUDPSERVER_HPP 27 | #define IKERNEL_CMSUDPSERVER_HPP 28 | 29 | #include "UdpServer.hpp" 30 | #include "cms.hpp" 31 | #include 32 | #include 33 | 34 | #define K 256 35 | 36 | class ikernel; 37 | struct heap_data; 38 | 39 | using fibHeap = boost::heap::fibonacci_heap; 40 | 41 | struct value_frequency_pair { 42 | int value; 43 | unsigned int frequency; 44 | 45 | void increment() { 46 | frequency += 1; 47 | } 48 | }; 49 | 50 | struct heap_data { 51 | value_frequency_pair payload; 52 | fibHeap::handle_type handle; 53 | 54 | heap_data(value_frequency_pair pair) : payload(pair), handle() {} 55 | 56 | bool operator<(heap_data const & rhs) const { 57 | return payload.frequency > rhs.payload.frequency; 58 | } 59 | }; 60 | 61 | 62 | class CmsUdpServer : public UdpServer { 63 | public: 64 | struct args { 65 | short port; 66 | std::string interface; 67 | }; 68 | 69 | CmsUdpServer(boost::asio::io_service& io_service, const args& args); 70 | virtual void process(std::size_t length); 71 | 72 | std::vector get_topK(); 73 | std::vector get_host_topK(); 74 | 75 | virtual ~CmsUdpServer(); 76 | private: 77 | ikernel* ik; 78 | CountMinSketch countMinSketch; 79 | int hashes[DEPTH][2]; 80 | uint32_t _k; 81 | fibHeap topK; 82 | std::map index; 83 | 84 | static void write_hashes(ikernel* ik); 85 | void read_k_value(ikernel* ik); 86 | int read_int(); 87 | }; 88 | 89 | 90 | #endif //IKERNEL_CMSUDPSERVER_HPP 91 | -------------------------------------------------------------------------------- /software/EchoServerMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "EchoUdpServer.hpp" 27 | #include "RunnableServerBase.hpp" 28 | #include "passthrough.hpp" 29 | #include "echo.hpp" 30 | #include 31 | 32 | #include 33 | 34 | class echo_main : public RunnableServerBase { 35 | public: 36 | echo_main(const unsigned char *ikernel_uuid, int argc, char **argv) 37 | : RunnableServerBase(ikernel_uuid, argc, argv), _uuid(ikernel_uuid) {} 38 | 39 | protected: 40 | 41 | virtual void preflight() { 42 | counts = std::vector >(thread_num); 43 | } 44 | 45 | virtual void postflight() { 46 | long total = 0; 47 | 48 | for (int i = 0; i < thread_num; ++i) { 49 | total += counts[i].get(); 50 | } 51 | 52 | std::cout << "packets forwarded to server : " << total << std::endl; 53 | std::cout << "throughput : " << total / secs << std::endl; 54 | } 55 | 56 | virtual void start_server(const int &thread_id) { 57 | EchoUdpServer::args args = { 58 | .port = short(port + thread_id), 59 | .secs = secs, 60 | .interface = vm["interface"].as(), 61 | .uuid = _uuid 62 | }; 63 | std::promise count; 64 | counts[thread_id] = count.get_future(); 65 | EchoUdpServer s(io_service, args); 66 | s.do_receive(); 67 | io_service.run(); 68 | 69 | count.set_value(s.get_count()); 70 | } 71 | 72 | std::vector > counts; 73 | const unsigned char *_uuid; 74 | }; 75 | 76 | int main(int argc, char **argv) { 77 | uuid_t passthrough = PASSTHROUGH_UUID, echo = ECHO_UUID, uuid; 78 | 79 | if (std::getenv("SIMULATION")) { 80 | uuid_copy(uuid, passthrough); 81 | } else { 82 | uuid_copy(uuid, echo); 83 | } 84 | 85 | return echo_main(uuid, argc, argv).run(); 86 | } 87 | -------------------------------------------------------------------------------- /software/EchoUdpServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "EchoUdpServer.hpp" 27 | #include 28 | #include 29 | 30 | EchoUdpServer::EchoUdpServer(boost::asio::io_service &io_service, const args &args) 31 | : UdpServer(io_service, args.port, args.interface), secs(args.secs), 32 | count(0), client(args.local_ip) 33 | { 34 | ik = ik_create(args.interface.c_str(), args.uuid); 35 | if (!ik) { 36 | std::cerr << "Warning: couldn't create ikernel\n"; 37 | } else { 38 | int fd = socket_.native_handle(); 39 | ik_attach(fd, ik, NULL, NULL); 40 | } 41 | } 42 | 43 | void EchoUdpServer::process(std::size_t length) { 44 | assert(length >= 4); 45 | 46 | int new_data = read_int(); 47 | new_data = htonl(new_data); 48 | 49 | client.send_to(&new_data, sizeof(new_data), sender_endpoint_); 50 | ++count; 51 | } 52 | 53 | int EchoUdpServer::read_int() { 54 | return ntohl(*reinterpret_cast(data_)); 55 | } 56 | 57 | int EchoUdpServer::get_count() { 58 | return count; 59 | } 60 | 61 | void EchoUdpServer::print_statistics() { 62 | std::cout << double(count) / secs << std::endl; 63 | } 64 | -------------------------------------------------------------------------------- /software/EchoUdpServer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef ECHOUDPSERVER_HPP 27 | #define ECHOUDPSERVER_HPP 28 | 29 | #include "UdpServer.hpp" 30 | #include "UdpClient.hpp" 31 | 32 | class ikernel; 33 | 34 | class EchoUdpServer : public UdpServer { 35 | public: 36 | struct args { 37 | short port; 38 | int secs; 39 | std::string interface; 40 | const unsigned char *uuid; 41 | std::string local_ip; 42 | }; 43 | 44 | EchoUdpServer(boost::asio::io_service& io_service, const args& args); 45 | virtual void process(std::size_t length); 46 | void print_statistics(); 47 | 48 | int get_count(); 49 | 50 | private: 51 | int secs; 52 | int count; 53 | UdpClient client; 54 | ikernel* ik; 55 | 56 | int read_int(); 57 | }; 58 | 59 | #endif //ECHOUDPSERVER_HPP 60 | -------------------------------------------------------------------------------- /software/RunnableServerBase.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef IKERNEL_RUNNABLESERVERBASE_HPP 27 | #define IKERNEL_RUNNABLESERVERBASE_HPP 28 | 29 | #include 30 | #include 31 | 32 | struct ikernel_attributes; 33 | 34 | using boost::program_options::variables_map; 35 | 36 | class RunnableServerBase { 37 | public: 38 | RunnableServerBase(const unsigned char* ikernel_uuid, int argc, char** argv); 39 | virtual ~RunnableServerBase(); 40 | virtual int run(); 41 | virtual int parse_command_line_options(); 42 | 43 | virtual void preflight() = 0; 44 | virtual void postflight() = 0; 45 | virtual void start_server(const int& thread_id) = 0; 46 | 47 | protected: 48 | const unsigned char* ikernel_uuid; 49 | short port; 50 | int thread_num; 51 | int secs; 52 | uint32_t threshold; 53 | variables_map vm; 54 | int argc; 55 | char** argv; 56 | boost::asio::io_service io_service; 57 | }; 58 | 59 | 60 | #endif //IKERNEL_RUNNABLESERVERBASE_HPP 61 | -------------------------------------------------------------------------------- /software/StatisticsUdpServer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef STATISTICSUDPSERVER_HPP 27 | #define STATISTICSUDPSERVER_HPP 28 | 29 | #include "UdpServer.hpp" 30 | #include 31 | 32 | class ikernel; 33 | class custom_ring; 34 | 35 | class StatisticsUdpServer : public UdpServer { 36 | public: 37 | struct args { 38 | short port; 39 | int secs; 40 | std::string interface; 41 | }; 42 | 43 | StatisticsUdpServer(boost::asio::io_service& io_service, const args& args, const uint32_t threshold, bool use_custom_ring); 44 | ~StatisticsUdpServer(); 45 | virtual void process(std::size_t length); 46 | void print_statistics(); 47 | 48 | int get_dropped_count(); 49 | int get_host_count(); 50 | 51 | virtual void do_receive(); 52 | 53 | private: 54 | int post_recv(int first_entry, int num_entries); 55 | 56 | uint32_t secs; 57 | uint32_t max; 58 | uint32_t min; 59 | uint32_t sum; 60 | uint32_t count; 61 | uint32_t threshold_count; 62 | uint32_t threshold; 63 | 64 | bool use_custom_ring; 65 | ikernel* ik; 66 | uint64_t* receive_buffer; 67 | ibv_mr *mr; 68 | custom_ring* cr; 69 | 70 | uint32_t consumer_index; // last read 71 | uint32_t producer_index; // last received 72 | uint32_t posted_receive_buffers; // of all times 73 | uint32_t outstanding_recv_wrs; // remaining 74 | uint32_t read_uint(); 75 | }; 76 | 77 | #endif //STATISTICSUDPSERVER_HPP 78 | -------------------------------------------------------------------------------- /software/ThresholdServerMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "StatisticsUdpServer.hpp" 27 | #include "RunnableServerBase.hpp" 28 | #include "threshold.hpp" 29 | #include 30 | #include 31 | 32 | class threshold_main : public RunnableServerBase { 33 | public: 34 | threshold_main(const unsigned char *uuid, int argc, char **argv) 35 | : RunnableServerBase(uuid, argc, argv) {} 36 | 37 | protected: 38 | 39 | virtual void preflight() { 40 | dropped_counts = std::vector >(thread_num); 41 | host_counts = std::vector >(thread_num); 42 | 43 | } 44 | 45 | virtual void postflight() { 46 | long total = 0, host_total = 0; 47 | 48 | for (int i = 0; i < thread_num; ++i) { 49 | total += dropped_counts[i].get();// + host_counts[i].get(); 50 | host_total += host_counts[i].get(); 51 | } 52 | total += host_total; 53 | double ratio = total > 0 ? (((double)(host_total))/total)*100 : 100; 54 | std::cout << "packets to host: " << ratio << " %" << std::endl; 55 | std::cout << "throughput: " << total / secs << std::endl; 56 | } 57 | 58 | virtual void start_server(const int &thread_id) { 59 | StatisticsUdpServer::args args = { 60 | .port = short(port + thread_id), 61 | .secs = secs, 62 | .interface = vm["interface"].as(), 63 | }; 64 | std::promise dropped_count,host_count; 65 | dropped_counts[thread_id] = dropped_count.get_future(); 66 | host_counts[thread_id] = host_count.get_future(); 67 | StatisticsUdpServer s(io_service, args, threshold, vm.count("use_custom_ring")); 68 | s.do_receive(); 69 | io_service.run(); 70 | dropped_count.set_value(s.get_dropped_count()); 71 | 72 | host_count.set_value(s.get_host_count()); 73 | } 74 | 75 | std::vector > dropped_counts,host_counts; 76 | }; 77 | 78 | int main(int argc, char **argv) { 79 | uuid_t uuid = THRESHOLD_UUID; 80 | 81 | return threshold_main(uuid, argc, argv).run(); 82 | } 83 | -------------------------------------------------------------------------------- /software/UdpClient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "UdpClient.hpp" 27 | #include 28 | 29 | UdpClient::~UdpClient() {} 30 | UdpClient::UdpClient(const std::string& local_ip) : _io_service(), _socket(_io_service), _resolver(_io_service) { 31 | _socket.open(udp::v4()); 32 | _socket.set_option(udp::socket::reuse_address(true)); 33 | if (!local_ip.empty()) { 34 | udp::endpoint local (boost::asio::ip::address::from_string(local_ip), 0); 35 | _socket.bind(local); 36 | } 37 | _socket.bind(udp::endpoint()); 38 | } 39 | 40 | void UdpClient::send_to(void *data, size_t size_in_bytes, const std::string &hostname, const std::string &port) { 41 | send_to(data, size_in_bytes, get_endpoint(hostname, port)); 42 | } 43 | udp::endpoint UdpClient::get_endpoint(const std::string &hostname, const std::string &port) { 44 | return *_resolver.resolve({udp::v4(), hostname, port}); 45 | } 46 | void UdpClient::send_to(void *data, size_t size_in_bytes, const udp::endpoint &endpoint) { 47 | _socket.send_to(boost::asio::buffer(data, size_in_bytes), endpoint); 48 | } 49 | udp::socket& UdpClient::get_socket() { return _socket; } 50 | -------------------------------------------------------------------------------- /software/UdpClient.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef UDPCLIENT_HPP 27 | #define UDPCLIENT_HPP 28 | 29 | #include 30 | 31 | using boost::asio::ip::udp; 32 | 33 | class UdpClient { 34 | public: 35 | explicit UdpClient(const std::string& interface); 36 | virtual ~UdpClient(); 37 | void send_to(void *data, size_t size_in_bytes, const std::string& hostname, const std::string& port); 38 | void send_to(void *data, size_t size_in_bytes, const udp::endpoint& endpoint); 39 | udp::endpoint get_endpoint(const std::string& hostname, const std::string& port); 40 | udp::socket& get_socket(); 41 | 42 | private: 43 | boost::asio::io_service _io_service; 44 | udp::socket _socket; 45 | udp::resolver _resolver; 46 | }; 47 | 48 | #endif //UDPCLIENT_HPP 49 | -------------------------------------------------------------------------------- /software/UdpServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #include "UdpServer.hpp" 27 | #include 28 | #include 29 | 30 | UdpServer::UdpServer(boost::asio::io_service &io_service, short port, const std::string& interface) 31 | : io_service(io_service), socket_(io_service, udp::endpoint(udp::v4(), port)) { 32 | int fd = socket_.native_handle(); 33 | int ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, interface.c_str(), interface.length()); 34 | if (ret) { 35 | // throw std::system_error(errno, std::system_category()); 36 | std::error_condition econd = std::system_category().default_error_condition(errno); 37 | std::cerr << "Warning: couldn't bind socket to requested interface: " << econd.message() << "\n"; 38 | } 39 | } 40 | 41 | void UdpServer::do_receive() { 42 | socket_.async_receive_from( 43 | boost::asio::buffer(data_, max_length), sender_endpoint_, 44 | [this](boost::system::error_code ec, std::size_t bytes_recvd) { 45 | if (!ec && bytes_recvd > 0) { 46 | process(bytes_recvd); 47 | } 48 | 49 | do_receive(); 50 | }); 51 | } 52 | -------------------------------------------------------------------------------- /software/UdpServer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, 6 | // are permitted provided that the following conditions are met: 7 | // 8 | // * Redistributions of source code must retain the above copyright notice, this 9 | // list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation and/or 12 | // other materials provided with the distribution. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | // 25 | 26 | #ifndef UDPSERVER_HPP 27 | #define UDPSERVER_HPP 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | using boost::asio::ip::udp; 34 | 35 | class UdpServer { 36 | public: 37 | UdpServer(boost::asio::io_service& io_service, short port, const std::string& interface); 38 | 39 | virtual void do_receive(); 40 | 41 | protected: 42 | 43 | virtual void process(std::size_t length) = 0; 44 | 45 | boost::asio::io_service& io_service; 46 | udp::socket socket_; 47 | udp::endpoint sender_endpoint_; 48 | enum { max_length = 1024 }; 49 | unsigned char data_[max_length]; 50 | }; 51 | 52 | #endif //UDPSERVER_HPP 53 | -------------------------------------------------------------------------------- /software/run-servers: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | for i in $(seq 0 $(($1-1))); do 28 | # taskset -c $i \ 29 | # taskset -c $((1 + $i)) \ 30 | ./server $((1982+$i)) 1 5 & 31 | done 32 | 33 | wait 34 | 35 | -------------------------------------------------------------------------------- /software/run-servers-vma: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | #GDB="gdb --args" 28 | 29 | LIBVMA=/home/haggai/src/libvma/src/vma/.libs/libvma.so 30 | 31 | for i in $(seq 0 $(($1-1))); do 32 | # taskset -c $i \ 33 | # VMA_TRACELEVEL=debug \ 34 | all=$(($1 > 5)) 35 | core=$(( $all ? ($i) : ($i + 1) )) 36 | echo running $((1982+$i)) on $core 37 | sudo \ 38 | taskset -c $core \ 39 | $GDB env \ 40 | LD_PRELOAD=$LIBVMA \ 41 | VMA_MTU=200 \ 42 | VMA_RX_POLL=200000 \ 43 | VMA_RX_POLL_INIT=200000 \ 44 | VMA_RX_UDP_POLL_OS_RATIO=0 \ 45 | VMA_RX_BUFS=30000 \ 46 | VMA_THREAD_MODE=0 \ 47 | ./server $((1982+$i)) & 48 | done 49 | 50 | wait 51 | -------------------------------------------------------------------------------- /software/run-vma: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2016-2017 Haggai Eran, Gabi Malka, Lior Zeno, Maroun Tork 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation and/or 13 | # other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | #GDB="gdb --args" 28 | 29 | LIBVMA=/home/haggai/src/libvma/src/vma/.libs/libvma.so 30 | 31 | # VMA_TRACELEVEL=debug \ 32 | # VMA_THREAD_MODE=0 \ 33 | # VMA_RX_BUFS=30000 \ 34 | sudo \ 35 | $GDB env \ 36 | LD_PRELOAD=$LIBVMA \ 37 | VMA_MTU=200 \ 38 | VMA_RX_POLL=200000 \ 39 | VMA_RX_POLL_INIT=200000 \ 40 | VMA_RX_UDP_POLL_OS_RATIO=0 \ 41 | ./server 1982 $1 15 42 | --------------------------------------------------------------------------------