From 4b3a40dc28f39fcc7221f1f3f7444938b9ae138d Mon Sep 17 00:00:00 2001 From: gab-arrobo Date: Sat, 18 Feb 2023 17:48:50 -0800 Subject: [PATCH] Add GitHub Action for checking code format (C/C++ and Protobuf) (#15) * Add GitHub Action for checking code format (C/C++ and Protobuf) * Update GitHub Action to only remove the OS from the matrix * Address issues with format compliance for protobuf files * Add missing file that was not formatted * Update parameters for GitHub Action * Add missing license/copyright header and add an exception --- core/.clang-format => .clang-format | 0 .github/workflows/clang-format-check.yaml | 30 + .gitignore | 3 +- .reuse/dep5 | 2 +- CONTRIBUTING.md | 2 +- core/bessctl.h | 2 +- core/debug.cc | 10 +- core/drivers/pmd.cc | 44 +- core/metadata.h | 2 +- core/modules/arp_responder.h | 2 +- core/modules/drr.cc | 4 +- core/modules/drr.h | 2 +- core/modules/ether_encap.cc | 4 +- core/modules/exact_match.cc | 24 +- core/modules/flowgen.cc | 18 +- core/modules/ip_encap.cc | 7 +- core/modules/ip_lookup.cc | 43 +- core/modules/ip_lookup.h | 2 +- core/modules/l2_forward.cc | 2 +- core/modules/nat.cc | 12 +- core/modules/round_robin.h | 2 +- core/modules/timestamp.h | 4 +- core/modules/url_filter.cc | 29 +- core/modules/url_filter.h | 4 +- core/modules/vlan_push.cc | 7 +- core/modules/vxlan_decap.cc | 4 +- core/modules/wildcard_match.h | 2 +- core/opts.cc | 10 +- core/packet.h | 2 +- core/packet_pool.cc | 7 +- core/traffic_class_test.cc | 5 +- core/utils/arp.h | 17 +- core/utils/bits_test.cc | 2 +- core/utils/bpf.cc | 1185 ++++++++++---------- core/utils/bpf.h | 16 +- core/utils/checksum.h | 5 +- core/utils/checksum_test.cc | 5 +- core/utils/codel.h | 79 +- core/utils/copy_bench.cc | 4 +- core/utils/cuckoo_map.h | 8 +- core/utils/cuckoo_map_test.cc | 6 +- core/utils/endian.h | 2 +- core/utils/endian_test.cc | 2 +- core/utils/ether_test.cc | 2 +- core/utils/exact_match_table_test.cc | 7 +- core/utils/extended_priority_queue_test.cc | 2 +- core/utils/fifo_opener.cc | 2 +- core/utils/fifo_test.cc | 2 +- core/utils/histogram_test.cc | 2 +- core/utils/http_parser.cc | 46 +- core/utils/icmp.h | 2 +- core/utils/ip.h | 2 +- core/utils/ip_test.cc | 2 +- core/utils/llqueue_test.cc | 4 +- core/utils/lock_less_queue.h | 8 +- core/utils/mcslock.h | 3 +- core/utils/mpls.h | 12 +- core/utils/pcap_handle.cc | 2 +- core/utils/queue.h | 7 +- core/utils/simd.cc | 4 +- core/utils/syscallthread.cc | 2 +- core/utils/tcp.h | 2 +- core/utils/time.cc | 2 +- core/utils/trie_test.cc | 2 +- core/utils/udp.h | 2 +- core/utils/vxlan.h | 2 +- protobuf/bess_msg.proto | 121 +- protobuf/module_msg.proto | 787 +++++++------ protobuf/ports/port_msg.proto | 4 +- protobuf/service.proto | 106 +- protobuf/tests/test_msg.proto | 4 +- protobuf/util_msg.proto | 19 +- sample_plugin/modules/sequential_update.cc | 44 +- sample_plugin/modules/sequential_update.h | 14 +- sample_plugin/protobuf/supdate_msg.proto | 26 +- 75 files changed, 1499 insertions(+), 1369 deletions(-) rename core/.clang-format => .clang-format (100%) create mode 100644 .github/workflows/clang-format-check.yaml diff --git a/core/.clang-format b/.clang-format similarity index 100% rename from core/.clang-format rename to .clang-format diff --git a/.github/workflows/clang-format-check.yaml b/.github/workflows/clang-format-check.yaml new file mode 100644 index 0000000000..63dc4c44c1 --- /dev/null +++ b/.github/workflows/clang-format-check.yaml @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2023 Intel Corporation + +name: C++/C/Protobuf Format Check +on: + - pull_request +jobs: + format-check: + runs-on: '${{ matrix.os }}' + strategy: + matrix: + os: + - ubuntu-20.04 + path: + - check: 'core' + exclude: '(kmod)' # Exclude "kmod" dir because of different format + - check: 'protobuf' + exclude: '' # Nothing to exclude + - check: 'sample_plugin/modules' + exclude: '' # Nothing to exclude + - check: 'sample_plugin/protobuf' + exclude: '' # Nothing to exclude + steps: + - uses: actions/checkout@v3 + - name: Run clang-format style check for C/C++/Protobuf programs. + uses: jidicula/clang-format-action@v4.9.0 + with: + clang-format-version: '12' + check-path: ${{ matrix.path['check'] }} + exclude-regex: ${{ matrix.path['exclude'] }} diff --git a/.gitignore b/.gitignore index 5fba308b21..bd1afe7f17 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ compile_commands.json # virtualenv venv/ -# Keep GitHub Actions and Reuse +# Keep GitHub Actions, reuse, and clang-format file !.github !.reuse +!.clang-format diff --git a/.reuse/dep5 b/.reuse/dep5 index 49b5fbe46b..700508dea9 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -3,7 +3,7 @@ Upstream-Name: bess Upstream-Contact: OMEC Developers Source: https://github.com/omec-project/bess -Files: .codecov.yml .gitattributes .gitignore CONTRIBUTING.md README.md requirements.txt .hooks/pre-commit bessctl/server.py bessctl/conf/port/vhost/README.md bessctl/conf/samples/mpls_test.bess bessctl/conf/samples/tc/wfs_double.bess bessctl/module_tests/*.pcap bessctl/static/*.* core/.clang-format core/.gitignore core/coverage core/*.suppress core/memory*.* core/packet_pool.* core/kmod/.clang-format core/kmod/.gitignore core/kmod/install core/pb/.gitignore core/resume_hooks/README.md core/testdata/test-pktcaptures/*.bytes core/testdata/test-pktcaptures/*.pcap deps/bpf_validate.patch deps/ethdev_include.patch doxygen/README.md doxygen/bess.dox env/*.yml env/Dockerfile env/README.md env/Vagrantfile pybess/**/__init__.py pybess/**/.gitignore sample_plugin/README.md +Files: .codecov.yml .gitattributes .gitignore CONTRIBUTING.md README.md requirements.txt .hooks/pre-commit bessctl/server.py bessctl/conf/port/vhost/README.md bessctl/conf/samples/mpls_test.bess bessctl/conf/samples/tc/wfs_double.bess bessctl/module_tests/*.pcap bessctl/static/*.* .clang-format core/.gitignore core/coverage core/*.suppress core/memory*.* core/packet_pool.* core/kmod/.clang-format core/kmod/.gitignore core/kmod/install core/pb/.gitignore core/resume_hooks/README.md core/testdata/test-pktcaptures/*.bytes core/testdata/test-pktcaptures/*.pcap deps/bpf_validate.patch deps/ethdev_include.patch doxygen/README.md doxygen/bess.dox env/*.yml env/Dockerfile env/README.md env/Vagrantfile pybess/**/__init__.py pybess/**/.gitignore sample_plugin/README.md Copyright: 2016-2017, Nefeli Networks, Inc. Copyright: 2017, The Regents of the University of California. License: BSD-3-Clause diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d96a49855..a0e9892340 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ You are welcome to [make a GitHub Pull Request](https://github.com/omec-project/ Please respect the following coding styles. Let's not be too dogmatic, though. * C++: [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) - * There is a [`.clang_format`](https://github.com/omec-project/bess/blob/master/core/.clang-format) file that you can utilize directly with [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) or integrate with your favorite editor ([Vim](https://github.com/rhysd/vim-clang-format), [Emacs](https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.el), [Atom](https://atom.io/packages/clang-format), etc.) + * There is a [`.clang_format`](https://github.com/omec-project/bess/blob/master/.clang-format) file that you can utilize directly with [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) or integrate with your favorite editor ([Vim](https://github.com/rhysd/vim-clang-format), [Emacs](https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.el), [Atom](https://atom.io/packages/clang-format), etc.) * C: [Linux kernel coding style](https://github.com/torvalds/linux/blob/master/Documentation/process/coding-style.rst) * Currently C is only used for the Linux kernel module. * Python: [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/) diff --git a/core/bessctl.h b/core/bessctl.h index 6bf36ce376..bb16fb121f 100644 --- a/core/bessctl.h +++ b/core/bessctl.h @@ -32,8 +32,8 @@ #ifndef BESS_BESSCTL_H_ #define BESS_BESSCTL_H_ -#include #include +#include // gRPC server encapsulation. Usage: // ApiServer server; diff --git a/core/debug.cc b/core/debug.cc index 39459ec295..3ced41baea 100644 --- a/core/debug.cc +++ b/core/debug.cc @@ -55,10 +55,10 @@ #include #include "module.h" +#include "opts.h" #include "packet.h" #include "scheduler.h" #include "traffic_class.h" -#include "opts.h" #include "utils/format.h" namespace bess { @@ -378,7 +378,7 @@ static bool SkipSymbol(char *symbol) { abort(); } -[[ gnu::noinline, noreturn ]] void GoPanic() { +[[gnu::noinline, noreturn]] void GoPanic() { if (oops_msg == "") oops_msg = DumpStack(); @@ -452,7 +452,11 @@ static void TrapHandler(int sig_num, siginfo_t *info, void *ucontext) { void SetTrapHandler() { const int signals[] = { - SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT, + SIGSEGV, + SIGBUS, + SIGILL, + SIGFPE, + SIGABRT, // SIGUSR1 is special in that it is triggered by user and does not abort SIGUSR1, }; diff --git a/core/drivers/pmd.cc b/core/drivers/pmd.cc index 2b779126ca..aec5f6dfdd 100644 --- a/core/drivers/pmd.cc +++ b/core/drivers/pmd.cc @@ -259,8 +259,7 @@ CommandResponse flow_create_one(dpdk_port_t port_id, #define NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0])) -enum FlowProfile : uint32_t -{ +enum FlowProfile : uint32_t { profileN3 = 3, profileN6 = 6, profileN9 = 9, @@ -270,19 +269,17 @@ CommandResponse flow_create(dpdk_port_t port_id, const uint32_t &flow_profile) { CommandResponse err; rte_flow_item_type N39_NSA[] = { - RTE_FLOW_ITEM_TYPE_ETH, RTE_FLOW_ITEM_TYPE_IPV4, RTE_FLOW_ITEM_TYPE_UDP, - RTE_FLOW_ITEM_TYPE_GTPU, RTE_FLOW_ITEM_TYPE_IPV4, - RTE_FLOW_ITEM_TYPE_END}; + RTE_FLOW_ITEM_TYPE_ETH, RTE_FLOW_ITEM_TYPE_IPV4, RTE_FLOW_ITEM_TYPE_UDP, + RTE_FLOW_ITEM_TYPE_GTPU, RTE_FLOW_ITEM_TYPE_IPV4, RTE_FLOW_ITEM_TYPE_END}; rte_flow_item_type N39_SA[] = { - RTE_FLOW_ITEM_TYPE_ETH, RTE_FLOW_ITEM_TYPE_IPV4, RTE_FLOW_ITEM_TYPE_UDP, - RTE_FLOW_ITEM_TYPE_GTPU, RTE_FLOW_ITEM_TYPE_GTP_PSC, - RTE_FLOW_ITEM_TYPE_IPV4, + RTE_FLOW_ITEM_TYPE_ETH, RTE_FLOW_ITEM_TYPE_IPV4, + RTE_FLOW_ITEM_TYPE_UDP, RTE_FLOW_ITEM_TYPE_GTPU, + RTE_FLOW_ITEM_TYPE_GTP_PSC, RTE_FLOW_ITEM_TYPE_IPV4, RTE_FLOW_ITEM_TYPE_END}; - rte_flow_item_type N6[] = { - RTE_FLOW_ITEM_TYPE_ETH, RTE_FLOW_ITEM_TYPE_IPV4, - RTE_FLOW_ITEM_TYPE_END}; + rte_flow_item_type N6[] = {RTE_FLOW_ITEM_TYPE_ETH, RTE_FLOW_ITEM_TYPE_IPV4, + RTE_FLOW_ITEM_TYPE_END}; switch (flow_profile) { uint64_t rss_types; @@ -302,8 +299,8 @@ CommandResponse flow_create(dpdk_port_t port_id, const uint32_t &flow_profile) { // N6 traffic case profileN6: rss_types = ETH_RSS_IPV4 | ETH_RSS_L3_DST_ONLY; - err = flow_create_one(port_id, flow_profile, NUM_ELEMENTS(N6), - rss_types, N6); + err = flow_create_one(port_id, flow_profile, NUM_ELEMENTS(N6), rss_types, + N6); break; // N9 traffic with and without PDU Session container @@ -384,15 +381,16 @@ CommandResponse PMDPort::Init(const bess::pb::PMDPortArg &arg) { return CommandFailure(-ret, "rte_eth_dev_configure() failed"); } - int sid = arg.socket_case() == bess::pb::PMDPortArg::kSocketId ? - arg.socket_id() : rte_eth_dev_socket_id(ret_port_id); + int sid = arg.socket_case() == bess::pb::PMDPortArg::kSocketId + ? arg.socket_id() + : rte_eth_dev_socket_id(ret_port_id); /* if socket_id is invalid, set to 0 */ if (sid < 0 || sid > RTE_MAX_NUMA_NODES) { LOG(WARNING) << "Invalid socket, falling back... "; sid = 0; } LOG(INFO) << "Initializing Port:" << ret_port_id - << " with memory from socket " << sid; + << " with memory from socket " << sid; eth_rxconf = dev_info.default_rxconf; eth_rxconf.rx_drop_en = 1; @@ -470,8 +468,9 @@ CommandResponse PMDPort::Init(const bess::pb::PMDPortArg &arg) { } dpdk_port_id_ = ret_port_id; - int numa_node = arg.socket_case() == bess::pb::PMDPortArg::kSocketId ? - sid : rte_eth_dev_socket_id(ret_port_id); + int numa_node = arg.socket_case() == bess::pb::PMDPortArg::kSocketId + ? sid + : rte_eth_dev_socket_id(ret_port_id); node_placement_ = numa_node == -1 ? UNCONSTRAINED_SOCKET : (1ull << numa_node); @@ -483,7 +482,7 @@ CommandResponse PMDPort::Init(const bess::pb::PMDPortArg &arg) { driver_ = dev_info.driver_name ?: "unknown"; - if (arg.flow_profiles_size() > 0){ + if (arg.flow_profiles_size() > 0) { for (int i = 0; i < arg.flow_profiles_size(); ++i) { err = flow_create(ret_port_id, arg.flow_profiles(i)); if (err.error().code() != 0) { @@ -603,10 +602,9 @@ void PMDPort::CollectStats(bool reset) { // ice/i40e/net_e1000_igb PMD drivers, ixgbevf and net_bonding vdevs don't // support per-queue stats - if (driver_ == "net_ice" || driver_ == "net_iavf" || - driver_ == "net_i40e" || driver_ == "net_i40e_vf" || - driver_ == "net_ixgbe_vf" || driver_ == "net_bonding" || - driver_ == "net_e1000_igb") { + if (driver_ == "net_ice" || driver_ == "net_iavf" || driver_ == "net_i40e" || + driver_ == "net_i40e_vf" || driver_ == "net_ixgbe_vf" || + driver_ == "net_bonding" || driver_ == "net_e1000_igb") { // NOTE: // - if link is down, tx bytes won't increase // - if destination MAC address is incorrect, rx pkts won't increase diff --git a/core/metadata.h b/core/metadata.h index 27b8f79c61..6304bacd3e 100644 --- a/core/metadata.h +++ b/core/metadata.h @@ -211,7 +211,7 @@ class Pipeline { // count(=int) represents how many modules registered the attribute, and the // attribute is deregistered once it reaches back to 0. // Those modules should agree on the same size(=size_t). - std::map > registered_attrs_; + std::map> registered_attrs_; }; extern bess::metadata::Pipeline default_pipeline; diff --git a/core/modules/arp_responder.h b/core/modules/arp_responder.h index a05735d8ef..82ab0692b2 100644 --- a/core/modules/arp_responder.h +++ b/core/modules/arp_responder.h @@ -41,8 +41,8 @@ #include "../utils/ether.h" #include "../utils/ip.h" -using bess::utils::Ethernet; using bess::utils::be32_t; +using bess::utils::Ethernet; // ARP cache entry struct which keeps mapping between IP and MAC struct arp_entry { diff --git a/core/modules/drr.cc b/core/modules/drr.cc index b86e5d8bf7..204b2406c1 100644 --- a/core/modules/drr.cc +++ b/core/modules/drr.cc @@ -154,7 +154,9 @@ struct task_result DRR::RunTask(Context *ctx, bess::PacketBatch *batch, void *) { if (children_overload_ > 0) { return { - .block = true, .packets = 0, .bits = 0, + .block = true, + .packets = 0, + .bits = 0, }; } diff --git a/core/modules/drr.h b/core/modules/drr.h index a23fb1ffdb..a2c1e9a2d1 100644 --- a/core/modules/drr.h +++ b/core/modules/drr.h @@ -44,8 +44,8 @@ #include "../utils/cuckoo_map.h" #include "../utils/ip.h" -using bess::utils::Ipv4Prefix; using bess::utils::CuckooMap; +using bess::utils::Ipv4Prefix; // // This module implements Deficit Round Robin, a fair queueing algorithm, for diff --git a/core/modules/ether_encap.cc b/core/modules/ether_encap.cc index 1432778758..6009e13b5f 100644 --- a/core/modules/ether_encap.cc +++ b/core/modules/ether_encap.cc @@ -42,8 +42,8 @@ enum { ATTR_R_ETHER_TYPE, }; -CommandResponse EtherEncap::Init( - const bess::pb::EtherEncapArg &arg[[maybe_unused]]) { +CommandResponse EtherEncap::Init(const bess::pb::EtherEncapArg &arg + [[maybe_unused]]) { using AccessMode = bess::metadata::Attribute::AccessMode; AddMetadataAttr("ether_src", sizeof(Ethernet::Address), AccessMode::kRead); diff --git a/core/modules/exact_match.cc b/core/modules/exact_match.cc index 7fc5fdbf28..078a5172fd 100644 --- a/core/modules/exact_match.cc +++ b/core/modules/exact_match.cc @@ -329,19 +329,18 @@ void ExactMatch::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { int cnt = batch->cnt(); Value default_value(default_gate); - int icnt=0; - for(int lcnt=0; lcnt=64) ? 64 : cnt-lcnt ; + int icnt = 0; + for (int lcnt = 0; lcnt < cnt; lcnt = lcnt + icnt) { + icnt = ((cnt - lcnt) >= 64) ? 64 : cnt - lcnt; ValueTuple *res[icnt]; - uint64_t hit_mask = table_.Find(keys+lcnt, res, icnt); + uint64_t hit_mask = table_.Find(keys + lcnt, res, icnt); for (int j = 0; j < icnt; j++) { - if ((hit_mask & ((uint64_t)1ULL << j)) == 0) - EmitPacket(ctx, batch->pkts()[j+lcnt], default_gate); - else { - setValues(batch->pkts()[j+lcnt], res[j]->action); - EmitPacket(ctx, batch->pkts()[j+lcnt], res[j]->gate); + if ((hit_mask & ((uint64_t)1ULL << j)) == 0) + EmitPacket(ctx, batch->pkts()[j + lcnt], default_gate); + else { + setValues(batch->pkts()[j + lcnt], res[j]->action); + EmitPacket(ctx, batch->pkts()[j + lcnt], res[j]->gate); } } } @@ -381,7 +380,8 @@ void ExactMatch::RuleFieldsFromPb( } for (int j = 0; j < field_size; j++) { rule->back().push_back(rule64 & 0xFFULL); - DLOG(INFO) << "Pushed " << std::hex << (rule64 & 0xFFULL) << " to rule."; + DLOG(INFO) << "Pushed " << std::hex << (rule64 & 0xFFULL) + << " to rule."; rule64 >>= 8; } } @@ -429,7 +429,7 @@ CommandResponse ExactMatch::CommandSetDefaultGate( } void ExactMatch::DeInit() { - table_.DeInit(); + table_.DeInit(); } ADD_MODULE(ExactMatch, "em", "Multi-field classifier with an exact match table") diff --git a/core/modules/flowgen.cc b/core/modules/flowgen.cc index 95f71c34e9..86c6a73126 100644 --- a/core/modules/flowgen.cc +++ b/core/modules/flowgen.cc @@ -41,15 +41,15 @@ #include "../utils/ip.h" #include "../utils/simd.h" #include "../utils/tcp.h" -#include "../utils/udp.h" #include "../utils/time.h" +#include "../utils/udp.h" +using bess::utils::be16_t; +using bess::utils::be32_t; using bess::utils::Ethernet; using bess::utils::Ipv4; using bess::utils::Tcp; using bess::utils::Udp; -using bess::utils::be16_t; -using bess::utils::be32_t; /* we ignore the last 1% tail to make the variance finite */ const double PARETO_TAIL_LIMIT = 0.99; @@ -183,10 +183,11 @@ void FlowGen::PopulateInitialFlows() { } } -CommandResponse FlowGen::ProcessUpdatableArguments(const bess::pb::FlowGenArg &arg) { - +CommandResponse FlowGen::ProcessUpdatableArguments( + const bess::pb::FlowGenArg &arg) { if (arg.template_().length() == 0) { - if (strnlen(reinterpret_cast(tmpl_), MAX_TEMPLATE_SIZE) == 0) { + if (strnlen(reinterpret_cast(tmpl_), MAX_TEMPLATE_SIZE) == + 0) { return CommandFailure(EINVAL, "must specify 'template'"); } } else { @@ -436,7 +437,6 @@ bess::Packet *FlowGen::FillUdpPacket(struct flow *f) { return pkt; } - bess::Packet *FlowGen::FillTcpPacket(struct flow *f) { bess::Packet *pkt; @@ -534,7 +534,9 @@ struct task_result FlowGen::RunTask(Context *ctx, bess::PacketBatch *batch, void *) { if (children_overload_ > 0) { return { - .block = true, .packets = 0, .bits = 0, + .block = true, + .packets = 0, + .bits = 0, }; } diff --git a/core/modules/ip_encap.cc b/core/modules/ip_encap.cc index e093def732..c60ddb2800 100644 --- a/core/modules/ip_encap.cc +++ b/core/modules/ip_encap.cc @@ -36,10 +36,10 @@ #include "../utils/ether.h" #include "../utils/ip.h" -using bess::utils::Ethernet; -using bess::utils::Ipv4; using bess::utils::be16_t; using bess::utils::be32_t; +using bess::utils::Ethernet; +using bess::utils::Ipv4; enum { ATTR_R_IP_SRC, @@ -49,7 +49,8 @@ enum { ATTR_W_ETHER_TYPE, }; -CommandResponse IPEncap::Init(const bess::pb::IPEncapArg &arg[[maybe_unused]]) { +CommandResponse IPEncap::Init(const bess::pb::IPEncapArg &arg + [[maybe_unused]]) { using AccessMode = bess::metadata::Attribute::AccessMode; AddMetadataAttr("ip_src", 4, AccessMode::kRead); diff --git a/core/modules/ip_lookup.cc b/core/modules/ip_lookup.cc index e112a2773b..2181640afb 100644 --- a/core/modules/ip_lookup.cc +++ b/core/modules/ip_lookup.cc @@ -49,8 +49,8 @@ static inline int is_valid_gate(gate_idx_t gate) { const Commands IPLookup::cmds = { {"add", "IPLookupCommandAddArg", MODULE_CMD_FUNC(&IPLookup::CommandAdd), Command::THREAD_UNSAFE}, - {"delete", "IPLookupCommandDeleteArg", MODULE_CMD_FUNC(&IPLookup::CommandDelete), - Command::THREAD_UNSAFE}, + {"delete", "IPLookupCommandDeleteArg", + MODULE_CMD_FUNC(&IPLookup::CommandDelete), Command::THREAD_UNSAFE}, {"clear", "EmptyArg", MODULE_CMD_FUNC(&IPLookup::CommandClear), Command::THREAD_UNSAFE}}; @@ -71,9 +71,11 @@ CommandResponse IPLookup::Init(const bess::pb::IPLookupArg &arg) { default_gate_ = DROP_GATE; #if RTE_VERSION < RTE_VERSION_NUM(19, 11, 0, 0) - lpm_ = rte_lpm_create(name().c_str(), /* socket_id = */ rte_socket_id(), &conf); + lpm_ = + rte_lpm_create(name().c_str(), /* socket_id = */ rte_socket_id(), &conf); #else - lpm_ = rte_fib_create(name().c_str(), /* socket_id = */ rte_socket_id(), &conf); + lpm_ = + rte_fib_create(name().c_str(), /* socket_id = */ rte_socket_id(), &conf); #endif if (!lpm_) { @@ -184,14 +186,15 @@ void IPLookup::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { RunNextModule(ctx, batch); else for (i = 0; i < cnt; i++) { - EmitPacket(ctx, batch->pkts()[i], (next_hops[i] == DROP_GATE) ? default_gate_ : next_hops[i]); + EmitPacket(ctx, batch->pkts()[i], + (next_hops[i] == DROP_GATE) ? default_gate_ : next_hops[i]); } USED(default_gate); #endif } -ParsedPrefix IPLookup::ParseIpv4Prefix( - const std::string &prefix, uint64_t prefix_len) { +ParsedPrefix IPLookup::ParseIpv4Prefix(const std::string &prefix, + uint64_t prefix_len) { using bess::utils::Format; be32_t net_addr; be32_t net_mask; @@ -200,25 +203,23 @@ ParsedPrefix IPLookup::ParseIpv4Prefix( return std::make_tuple(EINVAL, "prefix' is missing", be32_t(0)); } if (!bess::utils::ParseIpv4Address(prefix, &net_addr)) { - return std::make_tuple(EINVAL, - Format("Invalid IP prefix: %s", prefix.c_str()), - be32_t(0)); + return std::make_tuple( + EINVAL, Format("Invalid IP prefix: %s", prefix.c_str()), be32_t(0)); } if (prefix_len > 32) { - return std::make_tuple(EINVAL, - Format("Invalid prefix length: %" PRIu64, - prefix_len), - be32_t(0)); + return std::make_tuple( + EINVAL, Format("Invalid prefix length: %" PRIu64, prefix_len), + be32_t(0)); } net_mask = be32_t(bess::utils::SetBitsLow(prefix_len)); if ((net_addr & ~net_mask).value()) { - return std::make_tuple(EINVAL, - Format("Invalid IP prefix %s/%" PRIu64 " %x %x", - prefix.c_str(), prefix_len, net_addr.value(), - net_mask.value()), - be32_t(0)); + return std::make_tuple( + EINVAL, + Format("Invalid IP prefix %s/%" PRIu64 " %x %x", prefix.c_str(), + prefix_len, net_addr.value(), net_mask.value()), + be32_t(0)); } return std::make_tuple(0, "", net_addr); } @@ -230,7 +231,7 @@ CommandResponse IPLookup::CommandAdd( ParsedPrefix prefix = ParseIpv4Prefix(arg.prefix(), prefix_len); if (std::get<0>(prefix)) { return CommandFailure(std::get<0>(prefix), "%s", - std::get<1>(prefix).c_str()); + std::get<1>(prefix).c_str()); } if (!is_valid_gate(gate)) { @@ -261,7 +262,7 @@ CommandResponse IPLookup::CommandDelete( ParsedPrefix prefix = ParseIpv4Prefix(arg.prefix(), prefix_len); if (std::get<0>(prefix)) { return CommandFailure(std::get<0>(prefix), "%s", - std::get<1>(prefix).c_str()); + std::get<1>(prefix).c_str()); } if (prefix_len == 0) { diff --git a/core/modules/ip_lookup.h b/core/modules/ip_lookup.h index c8ba0e9704..180c58d1e7 100644 --- a/core/modules/ip_lookup.h +++ b/core/modules/ip_lookup.h @@ -40,7 +40,7 @@ #if RTE_VERSION < RTE_VERSION_NUM(19, 11, 0, 0) #include #else -#define USED(x) (void)(x) +#define USED(x) (void)(x) extern "C" { #include } diff --git a/core/modules/l2_forward.cc b/core/modules/l2_forward.cc index 88d5953dd6..3fc9db8da1 100644 --- a/core/modules/l2_forward.cc +++ b/core/modules/l2_forward.cc @@ -71,7 +71,7 @@ static int l2_init(struct l2_table *l2tbl, int size, int bucket) { return -EINVAL; } - l2tbl->table = new(std::nothrow) l2_entry[size * bucket]{}; + l2tbl->table = new (std::nothrow) l2_entry[size * bucket]{}; if (l2tbl->table == nullptr) { return -ENOMEM; diff --git a/core/modules/nat.cc b/core/modules/nat.cc index da5a3118e9..2ee9262e7d 100644 --- a/core/modules/nat.cc +++ b/core/modules/nat.cc @@ -47,13 +47,13 @@ using bess::utils::Ethernet; using bess::utils::Ipv4; using IpProto = bess::utils::Ipv4::Proto; -using bess::utils::Udp; -using bess::utils::Tcp; -using bess::utils::Icmp; using bess::utils::ChecksumIncrement16; using bess::utils::ChecksumIncrement32; -using bess::utils::UpdateChecksumWithIncrement; +using bess::utils::Icmp; +using bess::utils::Tcp; +using bess::utils::Udp; using bess::utils::UpdateChecksum16; +using bess::utils::UpdateChecksumWithIncrement; const Commands NAT::cmds = { {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&NAT::GetInitialArg), @@ -90,7 +90,9 @@ CommandResponse NAT::Init(const bess::pb::NATArg &arg) { std::vector port_list; if (address_range.port_ranges().size() == 0) { port_list.emplace_back(PortRange{ - .begin = 0u, .end = 65535u, .suspended = false, + .begin = 0u, + .end = 65535u, + .suspended = false, }); } for (const auto &range : address_range.port_ranges()) { diff --git a/core/modules/round_robin.h b/core/modules/round_robin.h index cc4e6e5770..14ff208f2a 100644 --- a/core/modules/round_robin.h +++ b/core/modules/round_robin.h @@ -62,7 +62,7 @@ * * mode: whether to schedule with per-packet or per-batch granularity * options * are "packet" or "batch". -*/ + */ class RoundRobin final : public Module { public: static const gate_idx_t kNumOGates = MAX_GATES; diff --git a/core/modules/timestamp.h b/core/modules/timestamp.h index 86bc4cdb94..7c52072061 100644 --- a/core/modules/timestamp.h +++ b/core/modules/timestamp.h @@ -41,7 +41,9 @@ class Timestamp final : public Module { using MarkerType = uint32_t; static const MarkerType kMarker = 0x54C5BE55; - Timestamp() : Module(), offset_(), attr_id_(-1) { max_allowed_workers_ = Worker::kMaxWorkers; } + Timestamp() : Module(), offset_(), attr_id_(-1) { + max_allowed_workers_ = Worker::kMaxWorkers; + } CommandResponse Init(const bess::pb::TimestampArg &arg); diff --git a/core/modules/url_filter.cc b/core/modules/url_filter.cc index 4dc53c6b82..2d3395e126 100644 --- a/core/modules/url_filter.cc +++ b/core/modules/url_filter.cc @@ -40,10 +40,10 @@ #include "../utils/http_parser.h" #include "../utils/ip.h" +using bess::utils::be16_t; using bess::utils::Ethernet; using bess::utils::Ipv4; using bess::utils::Tcp; -using bess::utils::be16_t; const uint64_t TIME_OUT_NS = 10ull * 1000 * 1000 * 1000; // 10 seconds @@ -60,7 +60,7 @@ const Commands UrlFilter::cmds = { Command::THREAD_UNSAFE}}; // Template for generating TCP packets without data -struct[[gnu::packed]] PacketTemplate { +struct [[gnu::packed]] PacketTemplate { Ethernet eth; Ipv4 ip; Tcp tcp; @@ -362,23 +362,26 @@ void UrlFilter::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { it->second.SetAnalyzed(); // Inject RST to destination - EmitPacket(ctx, GenerateResetPacket(eth->src_addr, eth->dst_addr, ip->src, - ip->dst, tcp->src_port, tcp->dst_port, - tcp->seq_num, tcp->ack_num), + EmitPacket(ctx, + GenerateResetPacket(eth->src_addr, eth->dst_addr, ip->src, + ip->dst, tcp->src_port, tcp->dst_port, + tcp->seq_num, tcp->ack_num), 0); // Inject 403 to source. 403 should arrive earlier than RST. - EmitPacket(ctx, Generate403Packet(eth->dst_addr, eth->src_addr, ip->dst, - ip->src, tcp->dst_port, tcp->src_port, - tcp->ack_num, tcp->seq_num), + EmitPacket(ctx, + Generate403Packet(eth->dst_addr, eth->src_addr, ip->dst, + ip->src, tcp->dst_port, tcp->src_port, + tcp->ack_num, tcp->seq_num), 1); // Inject RST to source - EmitPacket(ctx, GenerateResetPacket( - eth->dst_addr, eth->src_addr, ip->dst, ip->src, - tcp->dst_port, tcp->src_port, - be32_t(tcp->ack_num.value() + strlen(HTTP_403_BODY)), - tcp->seq_num), + EmitPacket(ctx, + GenerateResetPacket( + eth->dst_addr, eth->src_addr, ip->dst, ip->src, + tcp->dst_port, tcp->src_port, + be32_t(tcp->ack_num.value() + strlen(HTTP_403_BODY)), + tcp->seq_num), 1); // Drop the data packet diff --git a/core/modules/url_filter.h b/core/modules/url_filter.h index 87ada0f07b..36ba8d8e67 100644 --- a/core/modules/url_filter.h +++ b/core/modules/url_filter.h @@ -47,10 +47,10 @@ #include "../utils/tcp_flow_reconstruct.h" #include "../utils/trie.h" -using bess::utils::TcpFlowReconstruct; -using bess::utils::Trie; using bess::utils::be16_t; using bess::utils::be32_t; +using bess::utils::TcpFlowReconstruct; +using bess::utils::Trie; // A helper class that defines a TCP flow class alignas(16) Flow { diff --git a/core/modules/vlan_push.cc b/core/modules/vlan_push.cc index 18a349fb40..c4ad56ce08 100644 --- a/core/modules/vlan_push.cc +++ b/core/modules/vlan_push.cc @@ -76,9 +76,10 @@ void VLANPush::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { ethh = _mm_loadu_si128(reinterpret_cast<__m128i *>(new_head + 4)); be16_t tpid(be16_t::swap(_mm_extract_epi16(ethh, 6))); - ethh = _mm_insert_epi32(ethh, (tpid.value() == Ethernet::Type::kVlan) - ? qinq_tag.raw_value() - : vlan_tag.raw_value(), + ethh = _mm_insert_epi32(ethh, + (tpid.value() == Ethernet::Type::kVlan) + ? qinq_tag.raw_value() + : vlan_tag.raw_value(), 3); _mm_storeu_si128(reinterpret_cast<__m128i *>(new_head), ethh); diff --git a/core/modules/vxlan_decap.cc b/core/modules/vxlan_decap.cc index aefaacf45c..8251654905 100644 --- a/core/modules/vxlan_decap.cc +++ b/core/modules/vxlan_decap.cc @@ -46,8 +46,8 @@ enum { ATTR_W_TUN_ID, }; -CommandResponse VXLANDecap::Init( - const bess::pb::VXLANDecapArg &arg[[maybe_unused]]) { +CommandResponse VXLANDecap::Init(const bess::pb::VXLANDecapArg &arg + [[maybe_unused]]) { using AccessMode = bess::metadata::Attribute::AccessMode; AddMetadataAttr("tun_ip_src", 4, AccessMode::kWrite); diff --git a/core/modules/wildcard_match.h b/core/modules/wildcard_match.h index ae23da39ce..28b661ea41 100644 --- a/core/modules/wildcard_match.h +++ b/core/modules/wildcard_match.h @@ -212,7 +212,7 @@ class WildcardMatch final : public Module { size_t total_key_size_; /* a multiple of sizeof(uint64_t) */ size_t total_value_size_; /* a multiple of sizeof(uint64_t) */ - size_t entries_; /* a power of 2 */ + size_t entries_; /* a power of 2 */ // TODO(melvinw): this can be refactored to use ExactMatchTable std::vector fields_; diff --git a/core/opts.cc b/core/opts.cc index 5e32428d8b..346d5e65ef 100644 --- a/core/opts.cc +++ b/core/opts.cc @@ -64,7 +64,7 @@ static bool ValidateIovaMode(const char *, const std::string &value) { return (value == "") || (value == "pa") || (value == "va"); } DEFINE_string(iova, "", "DPDK IOVA mode: pa or va. Set auto if not specified"); -static bool _iova_dummy[[maybe_unused]] = +static bool _iova_dummy [[maybe_unused]] = google::RegisterFlagValidator(&FLAGS_iova, &ValidateIovaMode); static bool ValidateCoreID(const char *, int32_t value) { @@ -76,7 +76,7 @@ static bool ValidateCoreID(const char *, int32_t value) { return true; } DEFINE_int32(c, 0, "Core ID for the default worker thread"); -static const bool _c_dummy[[maybe_unused]] = +static const bool _c_dummy [[maybe_unused]] = google::RegisterFlagValidator(&FLAGS_c, &ValidateCoreID); static bool ValidateTCPPort(const char *, int32_t value) { @@ -98,7 +98,7 @@ DEFINE_int32( p, kDefaultPort, "Specifies the TCP port on which BESS listens for controller connections, " "if --grpc_url is empty. Deprecated, please use --grpc_url instead"); -static const bool _p_dummy[[maybe_unused]] = +static const bool _p_dummy [[maybe_unused]] = google::RegisterFlagValidator(&FLAGS_p, &ValidateTCPPort); static bool ValidateMegabytesPerSocket(const char *, int32_t value) { @@ -112,7 +112,7 @@ static bool ValidateMegabytesPerSocket(const char *, int32_t value) { DEFINE_int32(m, 1024, "Specifies per-socket hugepages to allocate (in MBs). " "If set to 0, no hugepage is used"); -static const bool _m_dummy[[maybe_unused]] = +static const bool _m_dummy [[maybe_unused]] = google::RegisterFlagValidator(&FLAGS_m, &ValidateMegabytesPerSocket); static bool ValidateBuffersPerSocket(const char *, int32_t value) { @@ -129,5 +129,5 @@ static bool ValidateBuffersPerSocket(const char *, int32_t value) { DEFINE_int32(buffers, 262144, "Specifies how many packet buffers to allocate per socket," " must be a power of 2."); -static const bool _buffers_dummy[[maybe_unused]] = +static const bool _buffers_dummy [[maybe_unused]] = google::RegisterFlagValidator(&FLAGS_buffers, &ValidateBuffersPerSocket); diff --git a/core/packet.h b/core/packet.h index 98c3b5a363..81fc0be7ae 100644 --- a/core/packet.h +++ b/core/packet.h @@ -269,7 +269,7 @@ class alignas(64) Packet { Packet *next_; // Next segment. nullptr if not scattered. // offset 88: - uint64_t _dummy8; // rte_mbuf.tx_offload + uint64_t _dummy8; // rte_mbuf.tx_offload // TODO: Add struct rte_mbuf_ext_shared_info *shinfo; uint16_t _dummy9; // rte_mbuf.priv_size uint16_t _dummy10; // rte_mbuf.timesync diff --git a/core/packet_pool.cc b/core/packet_pool.cc index c453fccd2c..8cf4340c0a 100644 --- a/core/packet_pool.cc +++ b/core/packet_pool.cc @@ -170,7 +170,8 @@ PlainPacketPool::PlainPacketPool(size_t capacity, int socket_id) size_t page_shift = __builtin_ffs(getpagesize()); size_t min_chunk_size, align; - size_t size = rte_mempool_op_calc_mem_size_default(pool_, pool_->size, page_shift, &min_chunk_size, &align); + size_t size = rte_mempool_op_calc_mem_size_default( + pool_, pool_->size, page_shift, &min_chunk_size, &align); void *addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); @@ -201,8 +202,8 @@ BessPacketPool::BessPacketPool(size_t capacity, int socket_id) while (pool_->populated_size < pool_->size) { size_t deficit = pool_->size - pool_->populated_size; size_t min_chunk_size, align; - size_t bytes = - rte_mempool_op_calc_mem_size_default(pool_, deficit, page_shift, &min_chunk_size, &align); + size_t bytes = rte_mempool_op_calc_mem_size_default( + pool_, deficit, page_shift, &min_chunk_size, &align); auto [addr, alloced_bytes] = mem_.AllocUpto(bytes); if (addr == nullptr) { diff --git a/core/traffic_class_test.cc b/core/traffic_class_test.cc index 6d203d0f1e..432847c482 100644 --- a/core/traffic_class_test.cc +++ b/core/traffic_class_test.cc @@ -409,8 +409,9 @@ TEST(DefaultScheduleOnce, TwoLeavesWeightedFair) { // (lowest) priority leaf that is unblocked at that time. TEST(DefaultScheduleOnce, TwoLeavesPriority) { DummyModule dm; - DefaultScheduler s(CT("root", {PRIORITY}, {{0, CT("rr_1", {ROUND_ROBIN})}, - {1, CT("rr_2", {ROUND_ROBIN})}})); + DefaultScheduler s( + CT("root", {PRIORITY}, + {{0, CT("rr_1", {ROUND_ROBIN})}, {1, CT("rr_2", {ROUND_ROBIN})}})); ASSERT_EQ(3, TrafficClassBuilder::Find("root")->Size()); RoundRobinTrafficClass *rr_1 = diff --git a/core/utils/arp.h b/core/utils/arp.h index 99b82f71f3..a29243c86a 100644 --- a/core/utils/arp.h +++ b/core/utils/arp.h @@ -40,7 +40,7 @@ namespace bess { namespace utils { // A basic ARP header definition -struct[[gnu::packed]] Arp { +struct [[gnu::packed]] Arp { // Ethernet hardware format for hrd enum HardwareAddress : uint16_t { kEthernet = 1, @@ -55,23 +55,22 @@ struct[[gnu::packed]] Arp { kInvReply = 9, }; - be16_t hw_addr; // format of hardware address (hrd) - be16_t proto_addr; // format of protocol address (pro) - uint8_t hw_addr_length; // length of hardware address (hln) - uint8_t proto_addr_length; // length of protocol address (pln) - be16_t opcode; // ARP opcode (command) (op) + be16_t hw_addr; // format of hardware address (hrd) + be16_t proto_addr; // format of protocol address (pro) + uint8_t hw_addr_length; // length of hardware address (hln) + uint8_t proto_addr_length; // length of protocol address (pln) + be16_t opcode; // ARP opcode (command) (op) // ARP Data Ethernet::Address sender_hw_addr; // sender hardware address (sha) be32_t sender_ip_addr; // sender IP address (sip) Ethernet::Address target_hw_addr; // target hardware address (tha) - be32_t target_ip_addr; // target IP address (tip) + be32_t target_ip_addr; // target IP address (tip) }; - static_assert(sizeof(Arp) == 28, "struct Arp size is incorrect"); +static_assert(sizeof(Arp) == 28, "struct Arp size is incorrect"); } // namespace utils } // namespace bess #endif // BESS_UTILS_ARP_H_ - diff --git a/core/utils/bits_test.cc b/core/utils/bits_test.cc index 3a136c6730..0e741f934b 100644 --- a/core/utils/bits_test.cc +++ b/core/utils/bits_test.cc @@ -307,4 +307,4 @@ TEST(Mask, ExtraLongUnAligned) { } } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/bpf.cc b/core/utils/bpf.cc index 133d41f267..bfbefbf269 100644 --- a/core/utils/bpf.cc +++ b/core/utils/bpf.cc @@ -6,17 +6,17 @@ * * SPDX-License-Identifier: BSD-3-Clause * -*/ + */ #include "bpf.h" namespace bess { namespace utils { -#ifdef __x86_64 // JIT compilation code only works in 64-bit - /* - * Registers - */ +#ifdef __x86_64 // JIT compilation code only works in 64-bit + /* + * Registers + */ #define RAX 0 #define RCX 1 #define RDX 2 @@ -72,7 +72,7 @@ namespace utils { #define BPF_JIT_FJMP 0x08 #define BPF_JIT_FLEN 0x10 -#define BPF_JIT_FLAG_ALL \ +#define BPF_JIT_FLAG_ALL \ (BPF_JIT_FPKT | BPF_JIT_FMEM | BPF_JIT_FJMP | BPF_JIT_FLEN) /* A stream of native binary code */ @@ -111,350 +111,350 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); */ /* movl i32,r32 */ -#define MOVid(i32, r32) \ - do { \ - emitm(&stream, (11 << 4) | (1 << 3) | (r32 & 0x7), 1); \ - emitm(&stream, i32, 4); \ +#define MOVid(i32, r32) \ + do { \ + emitm(&stream, (11 << 4) | (1 << 3) | (r32 & 0x7), 1); \ + emitm(&stream, i32, 4); \ } while (0) /* movq i64,r64 */ -#define MOViq(i64, r64) \ - do { \ - emitm(&stream, 0x48, 1); \ - emitm(&stream, (11 << 4) | (1 << 3) | (r64 & 0x7), 1); \ - emitm(&stream, i64, 4); \ - emitm(&stream, (i64 >> 32), 4); \ +#define MOViq(i64, r64) \ + do { \ + emitm(&stream, 0x48, 1); \ + emitm(&stream, (11 << 4) | (1 << 3) | (r64 & 0x7), 1); \ + emitm(&stream, i64, 4); \ + emitm(&stream, (i64 >> 32), 4); \ } while (0) /* movl sr32,dr32 */ -#define MOVrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x89, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define MOVrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x89, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* movl sr32,dr32 (dr32 = %r8-15d) */ -#define MOVrd2(sr32, dr32) \ - do { \ - emitm(&stream, 0x8941, 2); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define MOVrd2(sr32, dr32) \ + do { \ + emitm(&stream, 0x8941, 2); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* movl sr32,dr32 (sr32 = %r8-15d) */ -#define MOVrd3(sr32, dr32) \ - do { \ - emitm(&stream, 0x8944, 2); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define MOVrd3(sr32, dr32) \ + do { \ + emitm(&stream, 0x8944, 2); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* movq sr64,dr64 */ -#define MOVrq(sr64, dr64) \ - do { \ - emitm(&stream, 0x8948, 2); \ - emitm(&stream, (3 << 6) | ((sr64 & 0x7) << 3) | (dr64 & 0x7), 1); \ +#define MOVrq(sr64, dr64) \ + do { \ + emitm(&stream, 0x8948, 2); \ + emitm(&stream, (3 << 6) | ((sr64 & 0x7) << 3) | (dr64 & 0x7), 1); \ } while (0) /* movq sr64,dr64 (dr64 = %r8-15) */ -#define MOVrq2(sr64, dr64) \ - do { \ - emitm(&stream, 0x8949, 2); \ - emitm(&stream, (3 << 6) | ((sr64 & 0x7) << 3) | (dr64 & 0x7), 1); \ +#define MOVrq2(sr64, dr64) \ + do { \ + emitm(&stream, 0x8949, 2); \ + emitm(&stream, (3 << 6) | ((sr64 & 0x7) << 3) | (dr64 & 0x7), 1); \ } while (0) /* movq sr64,dr64 (sr64 = %r8-15) */ -#define MOVrq3(sr64, dr64) \ - do { \ - emitm(&stream, 0x894c, 2); \ - emitm(&stream, (3 << 6) | ((sr64 & 0x7) << 3) | (dr64 & 0x7), 1); \ +#define MOVrq3(sr64, dr64) \ + do { \ + emitm(&stream, 0x894c, 2); \ + emitm(&stream, (3 << 6) | ((sr64 & 0x7) << 3) | (dr64 & 0x7), 1); \ } while (0) /* movl (sr64,or64,1),dr32 */ -#define MOVobd(sr64, or64, dr32) \ - do { \ - emitm(&stream, 0x8b, 1); \ - emitm(&stream, ((dr32 & 0x7) << 3) | 4, 1); \ - emitm(&stream, ((or64 & 0x7) << 3) | (sr64 & 0x7), 1); \ +#define MOVobd(sr64, or64, dr32) \ + do { \ + emitm(&stream, 0x8b, 1); \ + emitm(&stream, ((dr32 & 0x7) << 3) | 4, 1); \ + emitm(&stream, ((or64 & 0x7) << 3) | (sr64 & 0x7), 1); \ } while (0) /* movw (sr64,or64,1),dr16 */ -#define MOVobw(sr64, or64, dr16) \ - do { \ - emitm(&stream, 0x8b66, 2); \ - emitm(&stream, ((dr16 & 0x7) << 3) | 4, 1); \ - emitm(&stream, ((or64 & 0x7) << 3) | (sr64 & 0x7), 1); \ +#define MOVobw(sr64, or64, dr16) \ + do { \ + emitm(&stream, 0x8b66, 2); \ + emitm(&stream, ((dr16 & 0x7) << 3) | 4, 1); \ + emitm(&stream, ((or64 & 0x7) << 3) | (sr64 & 0x7), 1); \ } while (0) /* movb (sr64,or64,1),dr8 */ -#define MOVobb(sr64, or64, dr8) \ - do { \ - emitm(&stream, 0x8a, 1); \ - emitm(&stream, ((dr8 & 0x7) << 3) | 4, 1); \ - emitm(&stream, ((or64 & 0x7) << 3) | (sr64 & 0x7), 1); \ +#define MOVobb(sr64, or64, dr8) \ + do { \ + emitm(&stream, 0x8a, 1); \ + emitm(&stream, ((dr8 & 0x7) << 3) | 4, 1); \ + emitm(&stream, ((or64 & 0x7) << 3) | (sr64 & 0x7), 1); \ } while (0) /* movl sr32,(dr64,or64,1) */ -#define MOVomd(sr32, dr64, or64) \ - do { \ - emitm(&stream, 0x89, 1); \ - emitm(&stream, ((sr32 & 0x7) << 3) | 4, 1); \ - emitm(&stream, ((or64 & 0x7) << 3) | (dr64 & 0x7), 1); \ +#define MOVomd(sr32, dr64, or64) \ + do { \ + emitm(&stream, 0x89, 1); \ + emitm(&stream, ((sr32 & 0x7) << 3) | 4, 1); \ + emitm(&stream, ((or64 & 0x7) << 3) | (dr64 & 0x7), 1); \ } while (0) /* bswapl dr32 */ -#define BSWAP(dr32) \ - do { \ - emitm(&stream, 0xf, 1); \ - emitm(&stream, (0x19 << 3) | dr32, 1); \ +#define BSWAP(dr32) \ + do { \ + emitm(&stream, 0xf, 1); \ + emitm(&stream, (0x19 << 3) | dr32, 1); \ } while (0) /* xchgb %al,%ah */ -#define SWAP_AX() \ - do { \ - emitm(&stream, 0xc486, 2); \ +#define SWAP_AX() \ + do { \ + emitm(&stream, 0xc486, 2); \ } while (0) /* pushq r64 */ -#define PUSH(r64) \ - do { \ - emitm(&stream, (5 << 4) | (0 << 3) | (r64 & 0x7), 1); \ +#define PUSH(r64) \ + do { \ + emitm(&stream, (5 << 4) | (0 << 3) | (r64 & 0x7), 1); \ } while (0) /* leaveq */ -#define LEAVE() \ - do { \ - emitm(&stream, 0xc9, 1); \ +#define LEAVE() \ + do { \ + emitm(&stream, 0xc9, 1); \ } while (0) /* retq */ -#define RET() \ - do { \ - emitm(&stream, 0xc3, 1); \ +#define RET() \ + do { \ + emitm(&stream, 0xc3, 1); \ } while (0) /* addl sr32,dr32 */ -#define ADDrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x01, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define ADDrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x01, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* addl i32,%eax */ -#define ADD_EAXi(i32) \ - do { \ - emitm(&stream, 0x05, 1); \ - emitm(&stream, i32, 4); \ +#define ADD_EAXi(i32) \ + do { \ + emitm(&stream, 0x05, 1); \ + emitm(&stream, i32, 4); \ } while (0) /* addl i8,r32 */ -#define ADDib(i8, r32) \ - do { \ - emitm(&stream, 0x83, 1); \ - emitm(&stream, (24 << 3) | r32, 1); \ - emitm(&stream, i8, 1); \ +#define ADDib(i8, r32) \ + do { \ + emitm(&stream, 0x83, 1); \ + emitm(&stream, (24 << 3) | r32, 1); \ + emitm(&stream, i8, 1); \ } while (0) /* subl sr32,dr32 */ -#define SUBrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x29, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define SUBrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x29, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* subl i32,%eax */ -#define SUB_EAXi(i32) \ - do { \ - emitm(&stream, 0x2d, 1); \ - emitm(&stream, i32, 4); \ +#define SUB_EAXi(i32) \ + do { \ + emitm(&stream, 0x2d, 1); \ + emitm(&stream, i32, 4); \ } while (0) /* subq i8,r64 */ -#define SUBib(i8, r64) \ - do { \ - emitm(&stream, 0x8348, 2); \ - emitm(&stream, (29 << 3) | (r64 & 0x7), 1); \ - emitm(&stream, i8, 1); \ +#define SUBib(i8, r64) \ + do { \ + emitm(&stream, 0x8348, 2); \ + emitm(&stream, (29 << 3) | (r64 & 0x7), 1); \ + emitm(&stream, i8, 1); \ } while (0) /* mull r32 */ -#define MULrd(r32) \ - do { \ - emitm(&stream, 0xf7, 1); \ - emitm(&stream, (7 << 5) | (r32 & 0x7), 1); \ +#define MULrd(r32) \ + do { \ + emitm(&stream, 0xf7, 1); \ + emitm(&stream, (7 << 5) | (r32 & 0x7), 1); \ } while (0) /* divl r32 */ -#define DIVrd(r32) \ - do { \ - emitm(&stream, 0xf7, 1); \ - emitm(&stream, (15 << 4) | (r32 & 0x7), 1); \ +#define DIVrd(r32) \ + do { \ + emitm(&stream, 0xf7, 1); \ + emitm(&stream, (15 << 4) | (r32 & 0x7), 1); \ } while (0) /* andb i8,r8 */ -#define ANDib(i8, r8) \ - do { \ - if (r8 == AL) { \ - emitm(&stream, 0x24, 1); \ - } else { \ - emitm(&stream, 0x80, 1); \ - emitm(&stream, (7 << 5) | r8, 1); \ - } \ - emitm(&stream, i8, 1); \ +#define ANDib(i8, r8) \ + do { \ + if (r8 == AL) { \ + emitm(&stream, 0x24, 1); \ + } else { \ + emitm(&stream, 0x80, 1); \ + emitm(&stream, (7 << 5) | r8, 1); \ + } \ + emitm(&stream, i8, 1); \ } while (0) /* andl i32,r32 */ -#define ANDid(i32, r32) \ - do { \ - if (r32 == EAX) { \ - emitm(&stream, 0x25, 1); \ - } else { \ - emitm(&stream, 0x81, 1); \ - emitm(&stream, (7 << 5) | r32, 1); \ - } \ - emitm(&stream, i32, 4); \ +#define ANDid(i32, r32) \ + do { \ + if (r32 == EAX) { \ + emitm(&stream, 0x25, 1); \ + } else { \ + emitm(&stream, 0x81, 1); \ + emitm(&stream, (7 << 5) | r32, 1); \ + } \ + emitm(&stream, i32, 4); \ } while (0) /* andl sr32,dr32 */ -#define ANDrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x21, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define ANDrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x21, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* testl i32,r32 */ -#define TESTid(i32, r32) \ - do { \ - if (r32 == EAX) { \ - emitm(&stream, 0xa9, 1); \ - } else { \ - emitm(&stream, 0xf7, 1); \ - emitm(&stream, (3 << 6) | r32, 1); \ - } \ - emitm(&stream, i32, 4); \ +#define TESTid(i32, r32) \ + do { \ + if (r32 == EAX) { \ + emitm(&stream, 0xa9, 1); \ + } else { \ + emitm(&stream, 0xf7, 1); \ + emitm(&stream, (3 << 6) | r32, 1); \ + } \ + emitm(&stream, i32, 4); \ } while (0) /* testl sr32,dr32 */ -#define TESTrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x85, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define TESTrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x85, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* orl sr32,dr32 */ -#define ORrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x09, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define ORrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x09, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* orl i32,r32 */ -#define ORid(i32, r32) \ - do { \ - if (r32 == EAX) { \ - emitm(&stream, 0x0d, 1); \ - } else { \ - emitm(&stream, 0x81, 1); \ - emitm(&stream, (25 << 3) | r32, 1); \ - } \ - emitm(&stream, i32, 4); \ +#define ORid(i32, r32) \ + do { \ + if (r32 == EAX) { \ + emitm(&stream, 0x0d, 1); \ + } else { \ + emitm(&stream, 0x81, 1); \ + emitm(&stream, (25 << 3) | r32, 1); \ + } \ + emitm(&stream, i32, 4); \ } while (0) /* shll i8,r32 */ -#define SHLib(i8, r32) \ - do { \ - emitm(&stream, 0xc1, 1); \ - emitm(&stream, (7 << 5) | (r32 & 0x7), 1); \ - emitm(&stream, i8, 1); \ +#define SHLib(i8, r32) \ + do { \ + emitm(&stream, 0xc1, 1); \ + emitm(&stream, (7 << 5) | (r32 & 0x7), 1); \ + emitm(&stream, i8, 1); \ } while (0) /* shll %cl,dr32 */ -#define SHL_CLrb(dr32) \ - do { \ - emitm(&stream, 0xd3, 1); \ - emitm(&stream, (7 << 5) | (dr32 & 0x7), 1); \ +#define SHL_CLrb(dr32) \ + do { \ + emitm(&stream, 0xd3, 1); \ + emitm(&stream, (7 << 5) | (dr32 & 0x7), 1); \ } while (0) /* shrl i8,r32 */ -#define SHRib(i8, r32) \ - do { \ - emitm(&stream, 0xc1, 1); \ - emitm(&stream, (29 << 3) | (r32 & 0x7), 1); \ - emitm(&stream, i8, 1); \ +#define SHRib(i8, r32) \ + do { \ + emitm(&stream, 0xc1, 1); \ + emitm(&stream, (29 << 3) | (r32 & 0x7), 1); \ + emitm(&stream, i8, 1); \ } while (0) /* shrl %cl,dr32 */ -#define SHR_CLrb(dr32) \ - do { \ - emitm(&stream, 0xd3, 1); \ - emitm(&stream, (29 << 3) | (dr32 & 0x7), 1); \ +#define SHR_CLrb(dr32) \ + do { \ + emitm(&stream, 0xd3, 1); \ + emitm(&stream, (29 << 3) | (dr32 & 0x7), 1); \ } while (0) /* negl r32 */ -#define NEGd(r32) \ - do { \ - emitm(&stream, 0xf7, 1); \ - emitm(&stream, (27 << 3) | (r32 & 0x7), 1); \ +#define NEGd(r32) \ + do { \ + emitm(&stream, 0xf7, 1); \ + emitm(&stream, (27 << 3) | (r32 & 0x7), 1); \ } while (0) /* cmpl sr32,dr32 */ -#define CMPrd(sr32, dr32) \ - do { \ - emitm(&stream, 0x39, 1); \ - emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ +#define CMPrd(sr32, dr32) \ + do { \ + emitm(&stream, 0x39, 1); \ + emitm(&stream, (3 << 6) | ((sr32 & 0x7) << 3) | (dr32 & 0x7), 1); \ } while (0) /* cmpl i32,dr32 */ -#define CMPid(i32, dr32) \ - do { \ - if (dr32 == EAX) { \ - emitm(&stream, 0x3d, 1); \ - emitm(&stream, i32, 4); \ - } else { \ - emitm(&stream, 0x81, 1); \ - emitm(&stream, (0x1f << 3) | (dr32 & 0x7), 1); \ - emitm(&stream, i32, 4); \ - } \ +#define CMPid(i32, dr32) \ + do { \ + if (dr32 == EAX) { \ + emitm(&stream, 0x3d, 1); \ + emitm(&stream, i32, 4); \ + } else { \ + emitm(&stream, 0x81, 1); \ + emitm(&stream, (0x1f << 3) | (dr32 & 0x7), 1); \ + emitm(&stream, i32, 4); \ + } \ } while (0) /* jb off8 */ -#define JBb(off8) \ - do { \ - emitm(&stream, 0x72, 1); \ - emitm(&stream, off8, 1); \ +#define JBb(off8) \ + do { \ + emitm(&stream, 0x72, 1); \ + emitm(&stream, off8, 1); \ } while (0) /* jae off8 */ -#define JAEb(off8) \ - do { \ - emitm(&stream, 0x73, 1); \ - emitm(&stream, off8, 1); \ +#define JAEb(off8) \ + do { \ + emitm(&stream, 0x73, 1); \ + emitm(&stream, off8, 1); \ } while (0) /* jne off8 */ -#define JNEb(off8) \ - do { \ - emitm(&stream, 0x75, 1); \ - emitm(&stream, off8, 1); \ +#define JNEb(off8) \ + do { \ + emitm(&stream, 0x75, 1); \ + emitm(&stream, off8, 1); \ } while (0) /* ja off8 */ -#define JAb(off8) \ - do { \ - emitm(&stream, 0x77, 1); \ - emitm(&stream, off8, 1); \ +#define JAb(off8) \ + do { \ + emitm(&stream, 0x77, 1); \ + emitm(&stream, off8, 1); \ } while (0) /* jmp off32 */ -#define JMP(off32) \ - do { \ - emitm(&stream, 0xe9, 1); \ - emitm(&stream, off32, 4); \ +#define JMP(off32) \ + do { \ + emitm(&stream, 0xe9, 1); \ + emitm(&stream, off32, 4); \ } while (0) /* xorl r32,r32 */ -#define ZEROrd(r32) \ - do { \ - emitm(&stream, 0x31, 1); \ - emitm(&stream, (3 << 6) | ((r32 & 0x7) << 3) | (r32 & 0x7), 1); \ +#define ZEROrd(r32) \ + do { \ + emitm(&stream, 0x31, 1); \ + emitm(&stream, (3 << 6) | ((r32 & 0x7) << 3) | (r32 & 0x7), 1); \ } while (0) /* @@ -472,8 +472,9 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); if (ins->jt != 0 && ins->jf != 0) { \ /* 5 is the size of the following jmp */ \ emitm(&stream, ((t) << 8) | 0x0f, 2); \ - emitm(&stream, stream.refs[stream.bpf_pc + ins->jt] - \ - stream.refs[stream.bpf_pc] + 5, \ + emitm(&stream, \ + stream.refs[stream.bpf_pc + ins->jt] - \ + stream.refs[stream.bpf_pc] + 5, \ 4); \ JMP(stream.refs[stream.bpf_pc + ins->jf] - stream.refs[stream.bpf_pc]); \ } else if (ins->jt != 0) { \ @@ -489,10 +490,10 @@ typedef void (*emit_func)(bpf_bin_stream *stream, u_int value, u_int n); } \ } while (0) -#define JUMP(off) \ - do { \ - if ((off) != 0) \ - JMP(stream.refs[stream.bpf_pc + (off)] - stream.refs[stream.bpf_pc]); \ +#define JUMP(off) \ + do { \ + if ((off) != 0) \ + JMP(stream.refs[stream.bpf_pc + (off)] - stream.refs[stream.bpf_pc]); \ } while (0) /* @@ -509,21 +510,21 @@ static void emit_length(bpf_bin_stream *stream, u_int, u_int len) { */ static void emit_code(bpf_bin_stream *stream, u_int value, u_int len) { switch (len) { - case 1: - stream->ibuf[stream->cur_ip] = (u_char)value; - stream->cur_ip++; - break; - - case 2: - *(reinterpret_cast(stream->ibuf + stream->cur_ip)) = - (u_short)value; - stream->cur_ip += 2; - break; - - case 4: - *(reinterpret_cast(stream->ibuf + stream->cur_ip)) = value; - stream->cur_ip += 4; - break; + case 1: + stream->ibuf[stream->cur_ip] = (u_char)value; + stream->cur_ip++; + break; + + case 2: + *(reinterpret_cast(stream->ibuf + stream->cur_ip)) = + (u_short)value; + stream->cur_ip += 2; + break; + + case 4: + *(reinterpret_cast(stream->ibuf + stream->cur_ip)) = value; + stream->cur_ip += 4; + break; } return; @@ -542,36 +543,36 @@ static int bpf_jit_optimize(struct bpf_insn *prog, u_int nins) { for (flags = 0, i = 0; i < nins; i++) { switch (prog[i].code) { - case BPF_LD | BPF_W | BPF_ABS: - case BPF_LD | BPF_H | BPF_ABS: - case BPF_LD | BPF_B | BPF_ABS: - case BPF_LD | BPF_W | BPF_IND: - case BPF_LD | BPF_H | BPF_IND: - case BPF_LD | BPF_B | BPF_IND: - case BPF_LDX | BPF_MSH | BPF_B: - flags |= BPF_JIT_FPKT; - break; - case BPF_LD | BPF_MEM: - case BPF_LDX | BPF_MEM: - case BPF_ST: - case BPF_STX: - flags |= BPF_JIT_FMEM; - break; - case BPF_LD | BPF_W | BPF_LEN: - case BPF_LDX | BPF_W | BPF_LEN: - flags |= BPF_JIT_FLEN; - break; - case BPF_JMP | BPF_JA: - case BPF_JMP | BPF_JGT | BPF_K: - case BPF_JMP | BPF_JGE | BPF_K: - case BPF_JMP | BPF_JEQ | BPF_K: - case BPF_JMP | BPF_JSET | BPF_K: - case BPF_JMP | BPF_JGT | BPF_X: - case BPF_JMP | BPF_JGE | BPF_X: - case BPF_JMP | BPF_JEQ | BPF_X: - case BPF_JMP | BPF_JSET | BPF_X: - flags |= BPF_JIT_FJMP; - break; + case BPF_LD | BPF_W | BPF_ABS: + case BPF_LD | BPF_H | BPF_ABS: + case BPF_LD | BPF_B | BPF_ABS: + case BPF_LD | BPF_W | BPF_IND: + case BPF_LD | BPF_H | BPF_IND: + case BPF_LD | BPF_B | BPF_IND: + case BPF_LDX | BPF_MSH | BPF_B: + flags |= BPF_JIT_FPKT; + break; + case BPF_LD | BPF_MEM: + case BPF_LDX | BPF_MEM: + case BPF_ST: + case BPF_STX: + flags |= BPF_JIT_FMEM; + break; + case BPF_LD | BPF_W | BPF_LEN: + case BPF_LDX | BPF_W | BPF_LEN: + flags |= BPF_JIT_FLEN; + break; + case BPF_JMP | BPF_JA: + case BPF_JMP | BPF_JGT | BPF_K: + case BPF_JMP | BPF_JGE | BPF_K: + case BPF_JMP | BPF_JEQ | BPF_K: + case BPF_JMP | BPF_JSET | BPF_K: + case BPF_JMP | BPF_JGT | BPF_X: + case BPF_JMP | BPF_JGE | BPF_X: + case BPF_JMP | BPF_JEQ | BPF_X: + case BPF_JMP | BPF_JSET | BPF_X: + flags |= BPF_JIT_FJMP; + break; } if (flags == BPF_JIT_FLAG_ALL) break; @@ -641,380 +642,380 @@ bpf_filter_func_t bpf_jit_compile(struct bpf_insn *prog, u_int nins, stream.bpf_pc++; switch (ins->code) { - default: - abort(); - - case BPF_RET | BPF_K: - MOVid(ins->k, EAX); - if (fmem) - LEAVE(); - RET(); - break; + default: + abort(); + + case BPF_RET | BPF_K: + MOVid(ins->k, EAX); + if (fmem) + LEAVE(); + RET(); + break; - case BPF_RET | BPF_A: - if (fmem) - LEAVE(); - RET(); - break; + case BPF_RET | BPF_A: + if (fmem) + LEAVE(); + RET(); + break; - case BPF_LD | BPF_W | BPF_ABS: - MOVid(ins->k, ESI); - CMPrd(EDI, ESI); - JAb(12); - MOVrd(EDI, ECX); - SUBrd(ESI, ECX); - CMPid(sizeof(int32_t), ECX); - if (fmem) { - JAEb(4); - ZEROrd(EAX); - LEAVE(); - } else { - JAEb(3); + case BPF_LD | BPF_W | BPF_ABS: + MOVid(ins->k, ESI); + CMPrd(EDI, ESI); + JAb(12); + MOVrd(EDI, ECX); + SUBrd(ESI, ECX); + CMPid(sizeof(int32_t), ECX); + if (fmem) { + JAEb(4); + ZEROrd(EAX); + LEAVE(); + } else { + JAEb(3); + ZEROrd(EAX); + } + RET(); + MOVrq3(R8, RCX); + MOVobd(RCX, RSI, EAX); + BSWAP(EAX); + break; + + case BPF_LD | BPF_H | BPF_ABS: ZEROrd(EAX); - } - RET(); - MOVrq3(R8, RCX); - MOVobd(RCX, RSI, EAX); - BSWAP(EAX); - break; + MOVid(ins->k, ESI); + CMPrd(EDI, ESI); + JAb(12); + MOVrd(EDI, ECX); + SUBrd(ESI, ECX); + CMPid(sizeof(int16_t), ECX); + if (fmem) { + JAEb(2); + LEAVE(); + } else + JAEb(1); + RET(); + MOVrq3(R8, RCX); + MOVobw(RCX, RSI, AX); + SWAP_AX(); + break; - case BPF_LD | BPF_H | BPF_ABS: - ZEROrd(EAX); - MOVid(ins->k, ESI); - CMPrd(EDI, ESI); - JAb(12); - MOVrd(EDI, ECX); - SUBrd(ESI, ECX); - CMPid(sizeof(int16_t), ECX); - if (fmem) { - JAEb(2); - LEAVE(); - } else - JAEb(1); - RET(); - MOVrq3(R8, RCX); - MOVobw(RCX, RSI, AX); - SWAP_AX(); - break; + case BPF_LD | BPF_B | BPF_ABS: + ZEROrd(EAX); + MOVid(ins->k, ESI); + CMPrd(EDI, ESI); + if (fmem) { + JBb(2); + LEAVE(); + } else + JBb(1); + RET(); + MOVrq3(R8, RCX); + MOVobb(RCX, RSI, AL); + break; - case BPF_LD | BPF_B | BPF_ABS: - ZEROrd(EAX); - MOVid(ins->k, ESI); - CMPrd(EDI, ESI); - if (fmem) { - JBb(2); - LEAVE(); - } else - JBb(1); - RET(); - MOVrq3(R8, RCX); - MOVobb(RCX, RSI, AL); - break; + case BPF_LD | BPF_W | BPF_LEN: + MOVrd3(R9D, EAX); + break; - case BPF_LD | BPF_W | BPF_LEN: - MOVrd3(R9D, EAX); - break; + case BPF_LDX | BPF_W | BPF_LEN: + MOVrd3(R9D, EDX); + break; - case BPF_LDX | BPF_W | BPF_LEN: - MOVrd3(R9D, EDX); - break; + case BPF_LD | BPF_W | BPF_IND: + CMPrd(EDI, EDX); + JAb(27); + MOVid(ins->k, ESI); + MOVrd(EDI, ECX); + SUBrd(EDX, ECX); + CMPrd(ESI, ECX); + JBb(14); + ADDrd(EDX, ESI); + MOVrd(EDI, ECX); + SUBrd(ESI, ECX); + CMPid(sizeof(int32_t), ECX); + if (fmem) { + JAEb(4); + ZEROrd(EAX); + LEAVE(); + } else { + JAEb(3); + ZEROrd(EAX); + } + RET(); + MOVrq3(R8, RCX); + MOVobd(RCX, RSI, EAX); + BSWAP(EAX); + break; - case BPF_LD | BPF_W | BPF_IND: - CMPrd(EDI, EDX); - JAb(27); - MOVid(ins->k, ESI); - MOVrd(EDI, ECX); - SUBrd(EDX, ECX); - CMPrd(ESI, ECX); - JBb(14); - ADDrd(EDX, ESI); - MOVrd(EDI, ECX); - SUBrd(ESI, ECX); - CMPid(sizeof(int32_t), ECX); - if (fmem) { - JAEb(4); + case BPF_LD | BPF_H | BPF_IND: ZEROrd(EAX); - LEAVE(); - } else { - JAEb(3); - ZEROrd(EAX); - } - RET(); - MOVrq3(R8, RCX); - MOVobd(RCX, RSI, EAX); - BSWAP(EAX); - break; - - case BPF_LD | BPF_H | BPF_IND: - ZEROrd(EAX); - CMPrd(EDI, EDX); - JAb(27); - MOVid(ins->k, ESI); - MOVrd(EDI, ECX); - SUBrd(EDX, ECX); - CMPrd(ESI, ECX); - JBb(14); - ADDrd(EDX, ESI); - MOVrd(EDI, ECX); - SUBrd(ESI, ECX); - CMPid(sizeof(int16_t), ECX); - if (fmem) { - JAEb(2); - LEAVE(); - } else - JAEb(1); - RET(); - MOVrq3(R8, RCX); - MOVobw(RCX, RSI, AX); - SWAP_AX(); - break; - - case BPF_LD | BPF_B | BPF_IND: - ZEROrd(EAX); - CMPrd(EDI, EDX); - JAEb(13); - MOVid(ins->k, ESI); - MOVrd(EDI, ECX); - SUBrd(EDX, ECX); - CMPrd(ESI, ECX); - if (fmem) { - JAb(2); - LEAVE(); - } else - JAb(1); - RET(); - MOVrq3(R8, RCX); - ADDrd(EDX, ESI); - MOVobb(RCX, RSI, AL); - break; + CMPrd(EDI, EDX); + JAb(27); + MOVid(ins->k, ESI); + MOVrd(EDI, ECX); + SUBrd(EDX, ECX); + CMPrd(ESI, ECX); + JBb(14); + ADDrd(EDX, ESI); + MOVrd(EDI, ECX); + SUBrd(ESI, ECX); + CMPid(sizeof(int16_t), ECX); + if (fmem) { + JAEb(2); + LEAVE(); + } else + JAEb(1); + RET(); + MOVrq3(R8, RCX); + MOVobw(RCX, RSI, AX); + SWAP_AX(); + break; - case BPF_LDX | BPF_MSH | BPF_B: - MOVid(ins->k, ESI); - CMPrd(EDI, ESI); - if (fmem) { - JBb(4); + case BPF_LD | BPF_B | BPF_IND: ZEROrd(EAX); - LEAVE(); - } else { - JBb(3); - ZEROrd(EAX); - } - RET(); - ZEROrd(EDX); - MOVrq3(R8, RCX); - MOVobb(RCX, RSI, DL); - ANDib(0x0f, DL); - SHLib(2, EDX); - break; + CMPrd(EDI, EDX); + JAEb(13); + MOVid(ins->k, ESI); + MOVrd(EDI, ECX); + SUBrd(EDX, ECX); + CMPrd(ESI, ECX); + if (fmem) { + JAb(2); + LEAVE(); + } else + JAb(1); + RET(); + MOVrq3(R8, RCX); + ADDrd(EDX, ESI); + MOVobb(RCX, RSI, AL); + break; - case BPF_LD | BPF_IMM: - MOVid(ins->k, EAX); - break; + case BPF_LDX | BPF_MSH | BPF_B: + MOVid(ins->k, ESI); + CMPrd(EDI, ESI); + if (fmem) { + JBb(4); + ZEROrd(EAX); + LEAVE(); + } else { + JBb(3); + ZEROrd(EAX); + } + RET(); + ZEROrd(EDX); + MOVrq3(R8, RCX); + MOVobb(RCX, RSI, DL); + ANDib(0x0f, DL); + SHLib(2, EDX); + break; - case BPF_LDX | BPF_IMM: - MOVid(ins->k, EDX); - break; + case BPF_LD | BPF_IMM: + MOVid(ins->k, EAX); + break; - case BPF_LD | BPF_MEM: - MOVid(ins->k * sizeof(uint32_t), ESI); - MOVobd(RSP, RSI, EAX); - break; + case BPF_LDX | BPF_IMM: + MOVid(ins->k, EDX); + break; - case BPF_LDX | BPF_MEM: - MOVid(ins->k * sizeof(uint32_t), ESI); - MOVobd(RSP, RSI, EDX); - break; + case BPF_LD | BPF_MEM: + MOVid(ins->k * sizeof(uint32_t), ESI); + MOVobd(RSP, RSI, EAX); + break; - case BPF_ST: - /* - * XXX this command and the following could - * be optimized if the previous instruction - * was already of this type - */ - MOVid(ins->k * sizeof(uint32_t), ESI); - MOVomd(EAX, RSP, RSI); - break; + case BPF_LDX | BPF_MEM: + MOVid(ins->k * sizeof(uint32_t), ESI); + MOVobd(RSP, RSI, EDX); + break; - case BPF_STX: - MOVid(ins->k * sizeof(uint32_t), ESI); - MOVomd(EDX, RSP, RSI); - break; + case BPF_ST: + /* + * XXX this command and the following could + * be optimized if the previous instruction + * was already of this type + */ + MOVid(ins->k * sizeof(uint32_t), ESI); + MOVomd(EAX, RSP, RSI); + break; - case BPF_JMP | BPF_JA: - JUMP(ins->k); - break; + case BPF_STX: + MOVid(ins->k * sizeof(uint32_t), ESI); + MOVomd(EDX, RSP, RSI); + break; - case BPF_JMP | BPF_JGT | BPF_K: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JA: + JUMP(ins->k); break; - } - CMPid(ins->k, EAX); - JCC(JA, JBE); - break; - case BPF_JMP | BPF_JGE | BPF_K: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JGT | BPF_K: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + CMPid(ins->k, EAX); + JCC(JA, JBE); break; - } - CMPid(ins->k, EAX); - JCC(JAE, JB); - break; - case BPF_JMP | BPF_JEQ | BPF_K: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JGE | BPF_K: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + CMPid(ins->k, EAX); + JCC(JAE, JB); break; - } - CMPid(ins->k, EAX); - JCC(JE, JNE); - break; - case BPF_JMP | BPF_JSET | BPF_K: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JEQ | BPF_K: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + CMPid(ins->k, EAX); + JCC(JE, JNE); break; - } - TESTid(ins->k, EAX); - JCC(JNE, JE); - break; - case BPF_JMP | BPF_JGT | BPF_X: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JSET | BPF_K: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + TESTid(ins->k, EAX); + JCC(JNE, JE); break; - } - CMPrd(EDX, EAX); - JCC(JA, JBE); - break; - case BPF_JMP | BPF_JGE | BPF_X: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JGT | BPF_X: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + CMPrd(EDX, EAX); + JCC(JA, JBE); break; - } - CMPrd(EDX, EAX); - JCC(JAE, JB); - break; - case BPF_JMP | BPF_JEQ | BPF_X: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JGE | BPF_X: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + CMPrd(EDX, EAX); + JCC(JAE, JB); break; - } - CMPrd(EDX, EAX); - JCC(JE, JNE); - break; - case BPF_JMP | BPF_JSET | BPF_X: - if (ins->jt == ins->jf) { - JUMP(ins->jt); + case BPF_JMP | BPF_JEQ | BPF_X: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + CMPrd(EDX, EAX); + JCC(JE, JNE); break; - } - TESTrd(EDX, EAX); - JCC(JNE, JE); - break; - case BPF_ALU | BPF_ADD | BPF_X: - ADDrd(EDX, EAX); - break; + case BPF_JMP | BPF_JSET | BPF_X: + if (ins->jt == ins->jf) { + JUMP(ins->jt); + break; + } + TESTrd(EDX, EAX); + JCC(JNE, JE); + break; - case BPF_ALU | BPF_SUB | BPF_X: - SUBrd(EDX, EAX); - break; + case BPF_ALU | BPF_ADD | BPF_X: + ADDrd(EDX, EAX); + break; - case BPF_ALU | BPF_MUL | BPF_X: - MOVrd(EDX, ECX); - MULrd(EDX); - MOVrd(ECX, EDX); - break; + case BPF_ALU | BPF_SUB | BPF_X: + SUBrd(EDX, EAX); + break; - case BPF_ALU | BPF_DIV | BPF_X: - TESTrd(EDX, EDX); - if (fmem) { - JNEb(4); - ZEROrd(EAX); - LEAVE(); - } else { - JNEb(3); - ZEROrd(EAX); - } - RET(); - MOVrd(EDX, ECX); - ZEROrd(EDX); - DIVrd(ECX); - MOVrd(ECX, EDX); - break; + case BPF_ALU | BPF_MUL | BPF_X: + MOVrd(EDX, ECX); + MULrd(EDX); + MOVrd(ECX, EDX); + break; - case BPF_ALU | BPF_AND | BPF_X: - ANDrd(EDX, EAX); - break; + case BPF_ALU | BPF_DIV | BPF_X: + TESTrd(EDX, EDX); + if (fmem) { + JNEb(4); + ZEROrd(EAX); + LEAVE(); + } else { + JNEb(3); + ZEROrd(EAX); + } + RET(); + MOVrd(EDX, ECX); + ZEROrd(EDX); + DIVrd(ECX); + MOVrd(ECX, EDX); + break; - case BPF_ALU | BPF_OR | BPF_X: - ORrd(EDX, EAX); - break; + case BPF_ALU | BPF_AND | BPF_X: + ANDrd(EDX, EAX); + break; - case BPF_ALU | BPF_LSH | BPF_X: - MOVrd(EDX, ECX); - SHL_CLrb(EAX); - break; + case BPF_ALU | BPF_OR | BPF_X: + ORrd(EDX, EAX); + break; - case BPF_ALU | BPF_RSH | BPF_X: - MOVrd(EDX, ECX); - SHR_CLrb(EAX); - break; + case BPF_ALU | BPF_LSH | BPF_X: + MOVrd(EDX, ECX); + SHL_CLrb(EAX); + break; - case BPF_ALU | BPF_ADD | BPF_K: - ADD_EAXi(ins->k); - break; + case BPF_ALU | BPF_RSH | BPF_X: + MOVrd(EDX, ECX); + SHR_CLrb(EAX); + break; - case BPF_ALU | BPF_SUB | BPF_K: - SUB_EAXi(ins->k); - break; + case BPF_ALU | BPF_ADD | BPF_K: + ADD_EAXi(ins->k); + break; - case BPF_ALU | BPF_MUL | BPF_K: - MOVrd(EDX, ECX); - MOVid(ins->k, EDX); - MULrd(EDX); - MOVrd(ECX, EDX); - break; + case BPF_ALU | BPF_SUB | BPF_K: + SUB_EAXi(ins->k); + break; - case BPF_ALU | BPF_DIV | BPF_K: - MOVrd(EDX, ECX); - ZEROrd(EDX); - MOVid(ins->k, ESI); - DIVrd(ESI); - MOVrd(ECX, EDX); - break; + case BPF_ALU | BPF_MUL | BPF_K: + MOVrd(EDX, ECX); + MOVid(ins->k, EDX); + MULrd(EDX); + MOVrd(ECX, EDX); + break; - case BPF_ALU | BPF_AND | BPF_K: - ANDid(ins->k, EAX); - break; + case BPF_ALU | BPF_DIV | BPF_K: + MOVrd(EDX, ECX); + ZEROrd(EDX); + MOVid(ins->k, ESI); + DIVrd(ESI); + MOVrd(ECX, EDX); + break; - case BPF_ALU | BPF_OR | BPF_K: - ORid(ins->k, EAX); - break; + case BPF_ALU | BPF_AND | BPF_K: + ANDid(ins->k, EAX); + break; - case BPF_ALU | BPF_LSH | BPF_K: - SHLib((ins->k) & 0xff, EAX); - break; + case BPF_ALU | BPF_OR | BPF_K: + ORid(ins->k, EAX); + break; - case BPF_ALU | BPF_RSH | BPF_K: - SHRib((ins->k) & 0xff, EAX); - break; + case BPF_ALU | BPF_LSH | BPF_K: + SHLib((ins->k) & 0xff, EAX); + break; - case BPF_ALU | BPF_NEG: - NEGd(EAX); - break; + case BPF_ALU | BPF_RSH | BPF_K: + SHRib((ins->k) & 0xff, EAX); + break; - case BPF_MISC | BPF_TAX: - MOVrd(EAX, EDX); - break; + case BPF_ALU | BPF_NEG: + NEGd(EAX); + break; - case BPF_MISC | BPF_TXA: - MOVrd(EDX, EAX); - break; + case BPF_MISC | BPF_TAX: + MOVrd(EAX, EDX); + break; + + case BPF_MISC | BPF_TXA: + MOVrd(EDX, EAX); + break; } ins++; } @@ -1064,5 +1065,5 @@ bpf_filter_func_t bpf_jit_compile(struct bpf_insn *prog, u_int nins, } #endif -} // end namespace bess -} // end namespace utils +} // namespace utils +} // namespace bess diff --git a/core/utils/bpf.h b/core/utils/bpf.h index 4bdb5f603b..e3c45c3596 100644 --- a/core/utils/bpf.h +++ b/core/utils/bpf.h @@ -6,7 +6,7 @@ * * SPDX-License-Identifier: BSD-3-Clause * -*/ + */ #ifndef BESS_UTILS_BPF_H_ #define BESS_UTILS_BPF_H_ @@ -24,21 +24,21 @@ using bpf_filter_func_t = u_int (*)(u_char *, u_int, u_int); struct Filter { #ifdef __x86_64 bpf_filter_func_t func; - size_t mmap_size; // needed for munmap() + size_t mmap_size; // needed for munmap() #else bpf_program il_code; #endif int gate; - int priority; // higher number == higher priority - std::string exp; // original filter expression string + int priority; // higher number == higher priority + std::string exp; // original filter expression string }; #ifdef __x86_64 bpf_filter_func_t bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size); -#endif //__x86_64 +#endif //__x86_64 -} // namespace utils -} // namespace bess +} // namespace utils +} // namespace bess -#endif // BESS_UTILS_ARP_H_ +#endif // BESS_UTILS_ARP_H_ diff --git a/core/utils/checksum.h b/core/utils/checksum.h index 688f8326af..96ec7d4c21 100644 --- a/core/utils/checksum.h +++ b/core/utils/checksum.h @@ -145,11 +145,10 @@ static inline uint32_t CalculateSum(const void *buf, size_t len) { sum64 = (sum64 >> 32) + (sum64 & 0xFFFFFFFF); #else // Use stantard C language for 32 bit or other non-Intel - typedef union[[gnu::may_alias]] { + typedef union [[gnu::may_alias]] { uint32_t u64; uint16_t u16[4]; - } - u16_64; + } u16_64; const u16_64 *ubuf64; ubuf64 = reinterpret_cast(buf64); while (len >= sizeof(uint64_t)) { diff --git a/core/utils/checksum_test.cc b/core/utils/checksum_test.cc index e35f93ed55..063982c5a1 100644 --- a/core/utils/checksum_test.cc +++ b/core/utils/checksum_test.cc @@ -99,7 +99,8 @@ TEST(ChecksumTest, Ipv4NoOptChecksum) { ip->src = be32_t(0x12345678); ip->dst = be32_t(0x12347890); - uint16_t cksum_dpdk = rte_ipv4_cksum(reinterpret_cast(ip)); + uint16_t cksum_dpdk = + rte_ipv4_cksum(reinterpret_cast(ip)); uint16_t cksum_bess = CalculateIpv4NoOptChecksum(*ip); EXPECT_EQ(cksum_dpdk, cksum_bess); @@ -456,4 +457,4 @@ TEST(ChecksumTest, IncrementalUpdateSrcIpPort) { EXPECT_TRUE(VerifyIpv4TcpChecksum(*ip, *tcp)); } } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/codel.h b/core/utils/codel.h index ab4bb99ab9..f9d93c0e97 100644 --- a/core/utils/codel.h +++ b/core/utils/codel.h @@ -39,22 +39,22 @@ #include -#include "time.h" #include "queue.h" +#include "time.h" namespace bess { namespace utils { // Codel(Controlled Delay Management) is an Queue controller based on this // article http://queue.acm.org/detail.cfm?id=2209336 -// It provides an active queue management to help prevent bufferbloat by dropping -// queue entries at an increasing rate if the delay in the queue is above the -// target queue delay. The equation used to calculate drop intervals is based on TCP -// throughput response to drop probability. +// It provides an active queue management to help prevent bufferbloat by +// dropping queue entries at an increasing rate if the delay in the queue is +// above the target queue delay. The equation used to calculate drop intervals +// is based on TCP throughput response to drop probability. // template argument T is the type that is going to be enqueued/dequeued. template -class Codel final: public Queue { +class Codel final : public Queue { public: // default delay target for codel static const uint64_t kDefaultTarget = 5000000; @@ -68,10 +68,10 @@ class Codel final: public Queue { // Takes a drop function which is a function that should take a dropped object // and handle it removing the object potentially including freeing the object. // If there is no need to handle a dropped object, NULL can be passed instead. - // target is the target delay in nanoseconds and the window is the buffer time u - // in nanosecond before changing into drop state. - Codel(void (*drop_func)(T)= NULL, size_t max_entries=0, uint64_t target = kDefaultTarget, - uint64_t window = kDefaultWindow) + // target is the target delay in nanoseconds and the window is the buffer time + // u in nanosecond before changing into drop state. + Codel(void (*drop_func)(T) = NULL, size_t max_entries = 0, + uint64_t target = kDefaultTarget, uint64_t window = kDefaultWindow) : delay_target_(target), window_(window), time_above_target_(0), @@ -80,7 +80,7 @@ class Codel final: public Queue { dropping_(0), max_size_(max_entries), queue_(), - drop_func_(drop_func) { } + drop_func_(drop_func) {} // deconstructor that drops all objects still left in the internal queue. virtual ~Codel() { @@ -99,7 +99,7 @@ class Codel final: public Queue { return 0; } - int Push(T* ptr, size_t count) override { + int Push(T *ptr, size_t count) override { size_t i = 0; for (; i < count; i++) { if (Push(ptr[i])) { @@ -109,8 +109,9 @@ class Codel final: public Queue { return i; } - // Retrieves the next entry from the queue and in the process, potentially drops - // objects as well as changes between dropping state and not dropping state. + // Retrieves the next entry from the queue and in the process, potentially + // drops objects as well as changes between dropping state and not dropping + // state. int Pop(T &obj) override { bool drop = false; Wrapper w; @@ -126,7 +127,7 @@ class Codel final: public Queue { // than the current time. err = DropDequeue(w, drop); } else if (drop && ((now - next_drop_time_ < window_) || - (now - time_above_target_ >= window_))) { + (now - time_above_target_ >= window_))) { // if not in dropping state, determine whether to enter drop state and if // so, drop current object, get a new object and reset the drop counter. Drop(w); @@ -151,10 +152,11 @@ class Codel final: public Queue { return err; } - // Retrieves the next count entries from the queue and in the process, potentially - // drops objects as well as changes between dropping state and not dropping state. - // Does not necessarily return count if there are count present but some are dropped. - int Pop(T* objs, size_t count) override { + // Retrieves the next count entries from the queue and in the process, + // potentially drops objects as well as changes between dropping state and not + // dropping state. Does not necessarily return count if there are count + // present but some are dropped. + int Pop(T *objs, size_t count) override { size_t i = 0; T next_obj; for (; i < count; i++) { @@ -166,9 +168,10 @@ class Codel final: public Queue { } return i; } - // the underlying queue is deque which is a dynamically sized queue with a max size - // determined by system limit. Therefore, the capacity is a specified value used to - // limit the queue or if no value is specified, the queue's system limit. + // the underlying queue is deque which is a dynamically sized queue with a max + // size determined by system limit. Therefore, the capacity is a specified + // value used to limit the queue or if no value is specified, the queue's + // system limit. size_t Capacity() override { if (max_size_ != 0) { return max_size_; @@ -187,10 +190,10 @@ class Codel final: public Queue { size_t Size() override { return queue_.size(); } - // The undelying queue is deque which is a dynamically sized queue with a max size - // determined by system limits. Therefore, the resize method will error if the new_capacity - // is outside of the queue's system limits or otherwise, only change the imposed limit on - // the capacity of the queue. + // The undelying queue is deque which is a dynamically sized queue with a max + // size determined by system limits. Therefore, the resize method will error + // if the new_capacity is outside of the queue's system limits or otherwise, + // only change the imposed limit on the capacity of the queue. int Resize(size_t new_capacity) override { if (new_capacity <= Size()) { return -1; @@ -206,7 +209,7 @@ class Codel final: public Queue { // Calls the drop_func on the object if the drop function exists void Drop(Wrapper w) { if (drop_func_ != NULL) { - drop_func_(w.second); + drop_func_(w.second); } } @@ -218,8 +221,8 @@ class Codel final: public Queue { // Gets the next object from the queue and determines based on current state, // whether set the passed drop boolean to true(to tell the calling function to - // drop it). Takes a Wrapper to set to the next entry in the queue and a boolean - // to set if the entry should be dropped. Returns 0 on success. + // drop it). Takes a Wrapper to set to the next entry in the queue and a + // boolean to set if the entry should be dropped. Returns 0 on success. int RingDequeue(Wrapper &w, bool &drop) { if (!queue_.empty()) { w = queue_.front(); @@ -244,11 +247,11 @@ class Codel final: public Queue { return 0; } - // Called while Codel is in drop state to determine whether to drop the current - // entries and dequeue the next entry. Will continue to drop entries until the - // next drop is greater than the current time. Takes a Wrapper which is the next - // entry in the queue which will potentially be replaced and a boolean determing - // if the entry should be dropped. Returns 0 on success. + // Called while Codel is in drop state to determine whether to drop the + // current entries and dequeue the next entry. Will continue to drop entries + // until the next drop is greater than the current time. Takes a Wrapper which + // is the next entry in the queue which will potentially be replaced and a + // boolean determing if the entry should be dropped. Returns 0 on success. int DropDequeue(Wrapper &w, bool &drop) { uint64_t now = NanoSecondTime(); if (!drop) { @@ -270,9 +273,7 @@ class Codel final: public Queue { } // Returns the current time in microseconds. - uint64_t NanoSecondTime() { - return tsc_to_ns(rdtsc()); - } + uint64_t NanoSecondTime() { return tsc_to_ns(rdtsc()); } uint64_t delay_target_; // the delay that codel will adjust for uint64_t window_; // minimum time before changing state @@ -283,10 +284,10 @@ class Codel final: public Queue { // the number of objects dropped while delay has been above target uint32_t drop_count_; - uint8_t dropping_; // whether in dropping state(above target for window) + uint8_t dropping_; // whether in dropping state(above target for window) size_t max_size_; std::deque queue_; // queue - void (*drop_func_)(T); // the function to call to drop a value + void (*drop_func_)(T); // the function to call to drop a value }; } // namespace utils diff --git a/core/utils/copy_bench.cc b/core/utils/copy_bench.cc index 93fe3d75ed..905d566478 100644 --- a/core/utils/copy_bench.cc +++ b/core/utils/copy_bench.cc @@ -80,7 +80,7 @@ class CopyFixture : public benchmark::Fixture { void TearDown(benchmark::State &) override { CHECK_EQ(dst_[-1], '\xff'); - //CHECK_EQ(dst_[size_], '\xff'); // Copy(sloppy=true) may violate this + // CHECK_EQ(dst_[size_], '\xff'); // Copy(sloppy=true) may violate this for (size_t i = 0; i < size_; i++) { CHECK_EQ(dst_[i], src_[i]) << "Byte " << i << " is different"; @@ -136,7 +136,7 @@ BENCHMARK_DEFINE_F(CopyFixture, Memcpy)(benchmark::State &state) { static void SetArguments(benchmark::internal::Benchmark *b) { // skip argument names for brevity - //b->ArgNames({"dst_align", "src_align", "size"}); + // b->ArgNames({"dst_align", "src_align", "size"}); b->Args({0, 0, 4}) ->Args({0, 0, 7}) ->Args({0, 0, 8}) diff --git a/core/utils/cuckoo_map.h b/core/utils/cuckoo_map.h index 24c61de545..eda3a41749 100644 --- a/core/utils/cuckoo_map.h +++ b/core/utils/cuckoo_map.h @@ -251,9 +251,7 @@ class CuckooMap { return -1; } - int find_dpdk(const void* key, void** data = 0, - hash_sig_t sig = 0) - { + int find_dpdk(const void* key, void** data = 0, hash_sig_t sig = 0) { if (IsDpdk) { if (data && !sig) return rte_hash_lookup_data(hash, key, data); @@ -267,9 +265,7 @@ class CuckooMap { return -1; } - int find_dpdk(const void* key, void** data = 0, - hash_sig_t sig = 0) const - { + int find_dpdk(const void* key, void** data = 0, hash_sig_t sig = 0) const { if (IsDpdk) { if (data && !sig) return rte_hash_lookup_data(hash, key, data); diff --git a/core/utils/cuckoo_map_test.cc b/core/utils/cuckoo_map_test.cc index a86b804b1d..9910988731 100644 --- a/core/utils/cuckoo_map_test.cc +++ b/core/utils/cuckoo_map_test.cc @@ -44,7 +44,7 @@ struct CopyConstructorOnly { CopyConstructorOnly() = default; CopyConstructorOnly(CopyConstructorOnly &&other) = delete; - CopyConstructorOnly(int aa, int bb): a(aa), b(bb) {} + CopyConstructorOnly(int aa, int bb) : a(aa), b(bb) {} CopyConstructorOnly(const CopyConstructorOnly &other) : a(other.a), b(other.b) {} @@ -57,7 +57,7 @@ struct MoveConstructorOnly { MoveConstructorOnly() = default; MoveConstructorOnly(const MoveConstructorOnly &other) = delete; - MoveConstructorOnly(int aa, int bb): a(aa), b(bb) {} + MoveConstructorOnly(int aa, int bb) : a(aa), b(bb) {} MoveConstructorOnly(MoveConstructorOnly &&other) noexcept : a(other.a), b(other.b) { other.a = 0; @@ -97,7 +97,7 @@ TEST(CuckooMapTest, Insert) { EXPECT_EQ(cuckoo.Insert(1, 1)->second, 1); } -template +template void CompileTimeInstantiation() { std::map m1; std::map m2; diff --git a/core/utils/endian.h b/core/utils/endian.h index 98c15979a5..5b824274c3 100644 --- a/core/utils/endian.h +++ b/core/utils/endian.h @@ -83,7 +83,7 @@ class EndianBase { // will be different depending on whether rhs is native or big endian, // which may not be immediately clear from the variable name. template -class[[gnu::packed]] BigEndian final : public EndianBase { +class [[gnu::packed]] BigEndian final : public EndianBase { public: BigEndian() = default; BigEndian(const BigEndian &o) = default; diff --git a/core/utils/endian_test.cc b/core/utils/endian_test.cc index e273ed7151..aa19634f41 100644 --- a/core/utils/endian_test.cc +++ b/core/utils/endian_test.cc @@ -184,4 +184,4 @@ TEST(EndianTest, Shift) { } } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/ether_test.cc b/core/utils/ether_test.cc index 8ee9f32bd6..85521decdf 100644 --- a/core/utils/ether_test.cc +++ b/core/utils/ether_test.cc @@ -91,4 +91,4 @@ TEST(EthernetTest, RandomAddr) { EXPECT_NE(c, d); } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/exact_match_table_test.cc b/core/utils/exact_match_table_test.cc index 3c9938553b..44fe48f845 100644 --- a/core/utils/exact_match_table_test.cc +++ b/core/utils/exact_match_table_test.cc @@ -150,11 +150,12 @@ TEST(EmTableTest, AddField) { // batch.clear(); // for (size_t i = 0; i < n; i++) { // bess::Packet *pkt = pkts[i]; -// bess::utils::Copy(pkt->append(sizeof(databuf)), databuf, sizeof(databuf)); -// batch.add(pkt); +// bess::utils::Copy(pkt->append(sizeof(databuf)), databuf, +// sizeof(databuf)); batch.add(pkt); // } -// const auto buffer_fn = [](const bess::Packet *pkt, const ExactMatchField &) { +// const auto buffer_fn = [](const bess::Packet *pkt, const ExactMatchField &) +// { // return pkt->head_data(); // }; // em.MakeKeys(&batch, buffer_fn, keys); diff --git a/core/utils/extended_priority_queue_test.cc b/core/utils/extended_priority_queue_test.cc index fabf559d95..a250c031a8 100644 --- a/core/utils/extended_priority_queue_test.cc +++ b/core/utils/extended_priority_queue_test.cc @@ -86,4 +86,4 @@ TEST(ExtendedPriorityQueueTest, Delete) { EXPECT_EQ(queue.top(), 1000); } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/fifo_opener.cc b/core/utils/fifo_opener.cc index f7ba665468..3f244f1af4 100644 --- a/core/utils/fifo_opener.cc +++ b/core/utils/fifo_opener.cc @@ -300,5 +300,5 @@ void FifoOpener::MarkDead(int fd, uint32_t gen) { } } -} // namespace bess } // namespace utils +} // namespace bess diff --git a/core/utils/fifo_test.cc b/core/utils/fifo_test.cc index 39459403b3..ee1a845227 100644 --- a/core/utils/fifo_test.cc +++ b/core/utils/fifo_test.cc @@ -670,4 +670,4 @@ TEST_F(FifoTestFixture, MultipleFancyFifos) { // everything down now. } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/histogram_test.cc b/core/utils/histogram_test.cc index f5af95a143..f41da1b803 100644 --- a/core/utils/histogram_test.cc +++ b/core/utils/histogram_test.cc @@ -80,4 +80,4 @@ TEST(HistogramTest, DoubleQuartiles) { EXPECT_DOUBLE_EQ(6.0, ret.percentile_values[3]); // 100th percentile } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/http_parser.cc b/core/utils/http_parser.cc index 84be123eec..7f5a91c806 100644 --- a/core/utils/http_parser.cc +++ b/core/utils/http_parser.cc @@ -69,29 +69,29 @@ } #define RANGES2_LENGTH (2 * 2) /* 2 pairs of start <= byte <= end */ -#define ADVANCE_TOKEN(tok, toklen) \ - do { \ - const char *tok_start = buf; \ - static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; \ - int found2; \ - buf = findchar_fast(buf, buf_end, ranges2, RANGES2_LENGTH, &found2); \ - if (!found2) { \ - CHECK_EOF(); \ - } \ - while (1) { \ - if (*buf == ' ') { \ - break; \ - } else if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { \ - if ((unsigned char)*buf < '\040' || *buf == '\177') { \ - *ret = -1; \ - return NULL; \ - } \ - } \ - ++buf; \ - CHECK_EOF(); \ - } \ - tok = tok_start; \ - toklen = buf - tok_start; \ +#define ADVANCE_TOKEN(tok, toklen) \ + do { \ + const char *tok_start = buf; \ + static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; \ + int found2; \ + buf = findchar_fast(buf, buf_end, ranges2, RANGES2_LENGTH, &found2); \ + if (!found2) { \ + CHECK_EOF(); \ + } \ + while (1) { \ + if (*buf == ' ') { \ + break; \ + } else if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { \ + if ((unsigned char)*buf < '\040' || *buf == '\177') { \ + *ret = -1; \ + return NULL; \ + } \ + } \ + ++buf; \ + CHECK_EOF(); \ + } \ + tok = tok_start; \ + toklen = buf - tok_start; \ } while (0) static const char *token_char_map = diff --git a/core/utils/icmp.h b/core/utils/icmp.h index 8002778e37..ebb2bf67f3 100644 --- a/core/utils/icmp.h +++ b/core/utils/icmp.h @@ -35,7 +35,7 @@ namespace bess { namespace utils { // A basic ICMP header definition. -struct[[gnu::packed]] Icmp { +struct [[gnu::packed]] Icmp { uint8_t type; // ICMP packet type. uint8_t code; // ICMP packet code. uint16_t checksum; // ICMP packet checksum. diff --git a/core/utils/ip.h b/core/utils/ip.h index 37cf842fbf..6e652a08e4 100644 --- a/core/utils/ip.h +++ b/core/utils/ip.h @@ -46,7 +46,7 @@ bool ParseIpv4Address(const std::string &str, be32_t *addr); std::string ToIpv4Address(be32_t addr); // An IPv4 header definition loosely based on the BSD version. -struct[[gnu::packed]] Ipv4 { +struct [[gnu::packed]] Ipv4 { enum Flag : uint16_t { kMF = 1 << 13, // More fragments kDF = 1 << 14, // Do not fragment diff --git a/core/utils/ip_test.cc b/core/utils/ip_test.cc index 620605b947..cd8bff8015 100644 --- a/core/utils/ip_test.cc +++ b/core/utils/ip_test.cc @@ -101,4 +101,4 @@ TEST(IPTest, PrefixCalc) { } } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/llqueue_test.cc b/core/utils/llqueue_test.cc index c14b43fdfa..941df115a1 100644 --- a/core/utils/llqueue_test.cc +++ b/core/utils/llqueue_test.cc @@ -105,8 +105,8 @@ TEST(LLQueueTest, Resize) { ASSERT_EQ(q.Push(vals2, n), n); ASSERT_EQ(q.Size(), 2 * n); - int** output = new int*[2*n]; - ASSERT_EQ(q.Pop(output, 2 * n), 2*n); + int** output = new int*[2 * n]; + ASSERT_EQ(q.Pop(output, 2 * n), 2 * n); for (int i = 0; i < n; i++) { ASSERT_EQ(output[i], vals1[i]); ASSERT_EQ(output[i + n], vals2[i]); diff --git a/core/utils/lock_less_queue.h b/core/utils/lock_less_queue.h index f120542d02..36b77e960b 100644 --- a/core/utils/lock_less_queue.h +++ b/core/utils/lock_less_queue.h @@ -45,7 +45,9 @@ namespace utils { // template argument T which is the type to be enqueued and dequeued. template class LockLessQueue final : public Queue { - static_assert(std::is_pointer::value, "LockLessQueue only supports pointer types"); + static_assert(std::is_pointer::value, + "LockLessQueue only supports pointer types"); + public: static const size_t kDefaultRingSize = 256; @@ -80,13 +82,13 @@ class LockLessQueue final : public Queue { } int Push(T* objs, size_t count) override { - if(!llring_enqueue_bulk(ring_, reinterpret_cast(objs), count)) { + if (!llring_enqueue_bulk(ring_, reinterpret_cast(objs), count)) { return count; } return 0; } - int Pop(T &obj) override { + int Pop(T& obj) override { return llring_dequeue(ring_, reinterpret_cast(&obj)); } diff --git a/core/utils/mcslock.h b/core/utils/mcslock.h index c3da47d1a9..8a579cf37a 100644 --- a/core/utils/mcslock.h +++ b/core/utils/mcslock.h @@ -72,7 +72,8 @@ static inline void mcs_lock(mcslock_t *lock, mcslock_node_t *mynode) { static inline void mcs_unlock(mcslock_t *lock, mcslock_node_t *mynode) { if (mynode->next == nullptr) { - if (__sync_bool_compare_and_swap(&lock->tail, mynode, nullptr)) return; + if (__sync_bool_compare_and_swap(&lock->tail, mynode, nullptr)) + return; while (mynode->next == nullptr) { asm volatile("lfence" ::: "memory"); diff --git a/core/utils/mpls.h b/core/utils/mpls.h index ce08fbe828..2c3bced89e 100644 --- a/core/utils/mpls.h +++ b/core/utils/mpls.h @@ -65,17 +65,11 @@ struct Mpls { (bos ? (1 << kMplsBosShift) : 0) | (ttl << kMplsTtlShift)); } - uint32_t Label() { - return (tag.value() & kMplsLabelMask) >> kMplsLabelShift; - } + uint32_t Label() { return (tag.value() & kMplsLabelMask) >> kMplsLabelShift; } - uint8_t Ttl() { - return (tag.value() & kMplsTtlMask) >> kMplsTtlShift; - } + uint8_t Ttl() { return (tag.value() & kMplsTtlMask) >> kMplsTtlShift; } - uint8_t Tc() { - return (tag.value() & kMplsTcMask) >> kMplsTcShift; - } + uint8_t Tc() { return (tag.value() & kMplsTcMask) >> kMplsTcShift; } bool isBottomOfStack() { return (tag.value() & kMplsBosMask) >> kMplsBosShift; diff --git a/core/utils/pcap_handle.cc b/core/utils/pcap_handle.cc index 3c94c9af37..9f5f0ed60b 100644 --- a/core/utils/pcap_handle.cc +++ b/core/utils/pcap_handle.cc @@ -39,7 +39,7 @@ PcapHandle::PcapHandle(const std::string& dev) : handle_() { handle_ = pcap_open_live(dev.c_str(), PCAP_SNAPLEN, 1, -1, errbuf); } -PcapHandle::PcapHandle(pcap_t *handle) : handle_(handle) {} +PcapHandle::PcapHandle(pcap_t* handle) : handle_(handle) {} PcapHandle::PcapHandle(PcapHandle&& other) : handle_(other.handle_) { other.handle_ = nullptr; diff --git a/core/utils/queue.h b/core/utils/queue.h index 6f8964bb53..3dc127060e 100644 --- a/core/utils/queue.h +++ b/core/utils/queue.h @@ -54,10 +54,9 @@ class Queue { // zero on success virtual int Pop(T&) = 0; - - // Dequeue several objects. Takes table to put objects and the number of objects - // to be dequeued into the table returns the number of objects dequeued into the - // table + // Dequeue several objects. Takes table to put objects and the number of + // objects to be dequeued into the table returns the number of objects + // dequeued into the table virtual int Pop(T*, size_t) = 0; // Returns the total capacity of the queue diff --git a/core/utils/simd.cc b/core/utils/simd.cc index a6270bc362..464fd8386e 100644 --- a/core/utils/simd.cc +++ b/core/utils/simd.cc @@ -53,8 +53,8 @@ std::string m256i_to_str(__m256i a) { }; vec = a; - return bess::utils::Format("[%08x %08x %08x %08x %08x %08x %08x %08x]", - b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); + return bess::utils::Format("[%08x %08x %08x %08x %08x %08x %08x %08x]", b[0], + b[1], b[2], b[3], b[4], b[5], b[6], b[7]); } #endif diff --git a/core/utils/syscallthread.cc b/core/utils/syscallthread.cc index 7fdd841d80..d41cd89506 100644 --- a/core/utils/syscallthread.cc +++ b/core/utils/syscallthread.cc @@ -176,5 +176,5 @@ void SyscallThreadAny::WaitForKnockThread() { } } -} // namespace bess } // namespace utils +} // namespace bess diff --git a/core/utils/tcp.h b/core/utils/tcp.h index 8d3826e176..6a90d37c09 100644 --- a/core/utils/tcp.h +++ b/core/utils/tcp.h @@ -36,7 +36,7 @@ namespace bess { namespace utils { // A basic TCP header definition loosely based on the BSD version. -struct[[gnu::packed]] Tcp { +struct [[gnu::packed]] Tcp { enum Flag : uint8_t { kFin = 0x01, kSyn = 0x02, diff --git a/core/utils/time.cc b/core/utils/time.cc index 4f3eea1ca1..f8ef8a69c3 100644 --- a/core/utils/time.cc +++ b/core/utils/time.cc @@ -49,4 +49,4 @@ class TscHzSetter { } } _dummy; -} // namespace (unnamed) +} // namespace diff --git a/core/utils/trie_test.cc b/core/utils/trie_test.cc index bfd5225ba5..a491deff57 100644 --- a/core/utils/trie_test.cc +++ b/core/utils/trie_test.cc @@ -241,4 +241,4 @@ TEST(TrieTest, Dump) { EXPECT_EQ(expected_results, trie.Dump()); } -} // namespace (unnamed) +} // namespace diff --git a/core/utils/udp.h b/core/utils/udp.h index 0ef3bb7230..245faaeafc 100644 --- a/core/utils/udp.h +++ b/core/utils/udp.h @@ -36,7 +36,7 @@ namespace bess { namespace utils { // A basic UDP header definition. -struct[[gnu::packed]] Udp { +struct [[gnu::packed]] Udp { be16_t src_port; // Source port. be16_t dst_port; // Destination port. be16_t length; // Length of header and data. diff --git a/core/utils/vxlan.h b/core/utils/vxlan.h index 9a7ee700e5..2db487cf2c 100644 --- a/core/utils/vxlan.h +++ b/core/utils/vxlan.h @@ -41,7 +41,7 @@ namespace utils { // +-------+-------+-------+--------+ // | VNI | Rsvd. | // +-------+-------+-------+--------+ -struct[[gnu::packed]] Vxlan { +struct [[gnu::packed]] Vxlan { be32_t vx_flags; be32_t vx_vni; }; diff --git a/protobuf/bess_msg.proto b/protobuf/bess_msg.proto index 52e85bbbdc..a50617e3be 100644 --- a/protobuf/bess_msg.proto +++ b/protobuf/bess_msg.proto @@ -46,8 +46,7 @@ package bess.pb; option go_package = "github.com/omec-project/upf-epc/pfcpiface/bess_pb"; -message EmptyRequest { -} +message EmptyRequest {} message EmptyResponse { /// Contains a non-zero error code and a non-empty message if and only if @@ -70,14 +69,14 @@ message UnloadPluginRequest { message ListPluginsResponse { Error error = 1; - repeated string paths = 2; /// Paths to the module library (*.so file) + repeated string paths = 2; /// Paths to the module library (*.so file) } message ListWorkersResponse { message WorkerStatus { - int64 wid = 1; /// Worker ID, starting from 0 - int64 core = 2; /// CPU core ID on which the worker is pinned - bool running = 3; /// True if running, otherwise False. + int64 wid = 1; /// Worker ID, starting from 0 + int64 core = 2; /// CPU core ID on which the worker is pinned + bool running = 3; /// True if running, otherwise False. /// Number of traffic classes running on the worker int64 num_tcs = 4; @@ -103,9 +102,9 @@ message DestroyWorkerRequest { } message TrafficClass { - string parent = 1; /// Name of parent TC - string name = 2; /// Name of TC - bool blocked = 3; /// Is it running or ready to run at the moment? + string parent = 1; /// Name of parent TC + string name = 2; /// Name of TC + bool blocked = 3; /// Is it running or ready to run at the moment? /// One of "priority", "weighted_fair", "round_robin", "rate_limit", "leaf" string policy = 4; @@ -214,8 +213,8 @@ message GetDriverInfoRequest { message GetDriverInfoResponse { Error error = 1; - string name = 2; /// Name of port driver - string help = 3; /// 1-line description of the driver + string name = 2; /// Name of port driver + string help = 3; /// 1-line description of the driver repeated string commands = 4; /// List of supported commands (TODO) } @@ -232,7 +231,8 @@ message ListPortsResponse { uint64 size_inc_q = 6; /// Size of each incoming queue (# of packets). uint64 size_out_q = 7; - /// Driver specific argument that was used for port initialization. See port_msg.proto + /// Driver specific argument that was used for port initialization. See + /// port_msg.proto google.protobuf.Any driver_arg = 8; } @@ -342,7 +342,7 @@ message GetPortStatsResponse { } message GetLinkStatusRequest { - string name = 1; /// name of the port to query + string name = 1; /// name of the port to query } message GetLinkStatusResponse { @@ -353,10 +353,6 @@ message GetLinkStatusResponse { bool link_up = 5; /// link up? } - - - - message ListMclassResponse { Error error = 1; repeated string names = 2; /// List of module types @@ -415,21 +411,21 @@ message GetModuleInfoRequest { message GetModuleInfoResponse { message GateHook { - string class_name = 1; /// gate hook class_name and - string hook_name = 2; /// gate hook name + string class_name = 1; /// gate hook class_name and + string hook_name = 2; /// gate hook name } message IGate { message OGate { uint64 ogate = 1; /// Output gate of "previous" module string name = 2; /// Name of "previous" module } - uint64 igate = 1; /// Input gate ID - repeated OGate ogates = 2; /// The list of upstream output gates - uint64 cnt = 3; /// # of packet batches seen - uint64 pkts = 4; /// # of packets seen - uint64 bytes = 5; /// # of bytes seen - double timestamp = 6; /// The time that cnt/pkts counters were read - reserved 7; // repeated string hook_name = 7; + uint64 igate = 1; /// Input gate ID + repeated OGate ogates = 2; /// The list of upstream output gates + uint64 cnt = 3; /// # of packet batches seen + uint64 pkts = 4; /// # of packets seen + uint64 bytes = 5; /// # of bytes seen + double timestamp = 6; /// The time that cnt/pkts counters were read + reserved 7; // repeated string hook_name = 7; repeated GateHook gatehooks = 8; /// List of gate hook } message OGate { @@ -440,8 +436,8 @@ message GetModuleInfoResponse { double timestamp = 5; /// The time thatcnt/pkts counters were read string name = 6; /// Name of the "next" module it connects to uint64 igate = 7; /// Input gate ID of the "next" module - reserved 8; // repeated string hook_name = 7; - repeated GateHook gatehooks = 9; /// List of gate hook + reserved 8; // repeated string hook_name = 7; + repeated GateHook gatehooks = 9; /// List of gate hook } message Attribute { string name = 1; /// Name of per-packet metadata attribute @@ -456,14 +452,15 @@ message GetModuleInfoResponse { repeated IGate igates = 6; /// List of connected input gates repeated OGate ogates = 7; /// List of connected output gates repeated Attribute metadata = 8; /// List of metadata used by the module - uint64 deadends = 9; /// Number of packets deadended or explicitly dropped by this module + uint64 deadends = + 9; /// Number of packets deadended or explicitly dropped by this module } message ConnectModulesRequest { - string m1 = 1; /// Name of "previous" module name - string m2 = 2; /// name of "next" module name - uint64 ogate = 3; /// m1's output gate ID - uint64 igate = 4; /// m2's input gate ID + string m1 = 1; /// Name of "previous" module name + string m2 = 2; /// name of "next" module name + uint64 ogate = 3; /// m1's output gate ID + uint64 igate = 4; /// m2's input gate ID /// If true do not attach default hooks at the input/output gate. /// (Currently, the only default hook is the "Track" hook at the ogate) bool skip_default_hooks = 5; @@ -475,26 +472,28 @@ message DisconnectModulesRequest { } message MempoolDump { - int32 socket = 1; /// The socket this mempool belongs to - bool initialized = 2; /// True when this mempool has been initialized - uint32 mp_size = 3; /// The maximum size of this mempool - uint32 mp_cache_size = 4; /// Size of per-lcore default local cache. - uint32 mp_element_size = 5; /// Size of one element - uint32 mp_populated_size = 6; /// Number of populated objects - uint32 mp_available_count = 7; /// Number of entries in this mempool - uint32 mp_in_use_count = 8; /// Number of elements which have been allocated from this mempool - uint32 ring_count = 9; /// Number of entries in the backing ring - uint32 ring_free_count = 10; /// Number of free entries in the backing ring - uint64 ring_bytes = 11; /// Size of the backing ring in bytes + int32 socket = 1; /// The socket this mempool belongs to + bool initialized = 2; /// True when this mempool has been initialized + uint32 mp_size = 3; /// The maximum size of this mempool + uint32 mp_cache_size = 4; /// Size of per-lcore default local cache. + uint32 mp_element_size = 5; /// Size of one element + uint32 mp_populated_size = 6; /// Number of populated objects + uint32 mp_available_count = 7; /// Number of entries in this mempool + uint32 mp_in_use_count = + 8; /// Number of elements which have been allocated from this mempool + uint32 ring_count = 9; /// Number of entries in the backing ring + uint32 ring_free_count = 10; /// Number of free entries in the backing ring + uint64 ring_bytes = 11; /// Size of the backing ring in bytes } message DumpMempoolRequest { - int32 socket = 1; // ID of the socket whose mempool should be dumped. -1 for all sockets + int32 socket = + 1; // ID of the socket whose mempool should be dumped. -1 for all sockets } message DumpMempoolResponse { - Error error = 1; - repeated MempoolDump dumps = 2; /// The list of requested mempool dumps + Error error = 1; + repeated MempoolDump dumps = 2; /// The list of requested mempool dumps } message CommandRequest { @@ -508,7 +507,6 @@ message CommandResponse { google.protobuf.Any data = 2; /// Command response (see *_msg.proto) } - // ------------------------------------------------------------------------- // Gate hooks // ------------------------------------------------------------------------- @@ -550,9 +548,9 @@ message TrackArg { /// /// NOTE: There should be no running worker to run this command. message TcpdumpArg { - string fifo = 5; /// Path to the FIFO file. - bool defer = 6; /// If set, we'll defer opening the FIFO. - bool reconnect = 7; /// If set, we'll reconnect after failure. + string fifo = 5; /// Path to the FIFO file. + bool defer = 6; /// If set, we'll defer opening the FIFO. + bool reconnect = 7; /// If set, we'll reconnect after failure. } /// Enable/Disable pcapng tapping at an input/output gate. @@ -566,19 +564,18 @@ message TcpdumpArg { /// /// NOTE: There should be no running worker to run this command. message PcapngArg { - string fifo = 5; /// Path to the FIFO file. - bool defer = 6; /// If set, we'll defer opening the FIFO. - bool reconnect = 7; /// If set, we'll reconnect after failure. + string fifo = 5; /// Path to the FIFO file. + bool defer = 6; /// If set, we'll defer opening the FIFO. + bool reconnect = 7; /// If set, we'll reconnect after failure. } - message GateHookInfo { - string class_name = 1; /// Name of the hook class - string hook_name = 2; /// Name of the hook - string module_name = 3; /// Name of module + string class_name = 1; /// Name of the hook class + string hook_name = 2; /// Name of the hook + string module_name = 3; /// Name of module oneof gate { - int64 igate = 4; /// Input gate index. All input gates if -1 - int64 ogate = 5; /// Output gate index. All output gates if -1 + int64 igate = 4; /// Input gate index. All input gates if -1 + int64 ogate = 5; /// Output gate index. All output gates if -1 } google.protobuf.Any arg = 6; /// Hook-specific arguments } @@ -619,9 +616,9 @@ message ConfigureResumeHookRequest { // ------------------------------------------------------------------------- message PauseWorkerRequest { - int64 wid = 1; /// ID of the worker to be paused + int64 wid = 1; /// ID of the worker to be paused } message ResumeWorkerRequest { - int64 wid = 1; /// ID of the worker to be resumed + int64 wid = 1; /// ID of the worker to be resumed } diff --git a/protobuf/module_msg.proto b/protobuf/module_msg.proto index 86fb842f7b..6910c0408c 100644 --- a/protobuf/module_msg.proto +++ b/protobuf/module_msg.proto @@ -44,61 +44,59 @@ import "util_msg.proto"; // For your comments to come out in the auto-documentation: // Format comments with two stars at the top, or use three slashes (///) -// Anything you write will show up as markdown, so feel free to add italics, etc. +// Anything you write will show up as markdown, so feel free to add italics, +// etc. -/// The module_msg.proto file is stored in `bess/protobuf/` and it supplies the glue between -/// bessd modules and the outside world via GRPC. -/// bessctl uses GRPC to update modules. Whenever you call a function in bessctl, a corresponding function -/// is called on modules in bessd. This file lists all modules, their initialization parameters -/// and any functions that may be called on them. +/// The module_msg.proto file is stored in `bess/protobuf/` and it supplies the +/// glue between bessd modules and the outside world via GRPC. bessctl uses GRPC +/// to update modules. Whenever you call a function in bessctl, a corresponding +/// function is called on modules in bessd. This file lists all modules, their +/// initialization parameters and any functions that may be called on them. -message EmptyArg { -} +message EmptyArg {} /** * The BPF module has a command `clear()` that takes no parameters. * This command removes all filters from the module. */ -message BPFCommandClearArg { -} +message BPFCommandClearArg {} /** * The ExactMatch module has a command `add(...)` that takes two parameters. - * The ExactMatch initializer specifies what fields in a packet to inspect; add() specifies - * which values to check for over these fields. - * add() inserts a new rule into the ExactMatch module such that traffic matching - * that bytestring will be forwarded - * out a specified gate. - * Example use: `add(fields=[aton('12.3.4.5'), aton('5.4.3.2')], gate=2)` + * The ExactMatch initializer specifies what fields in a packet to inspect; + * add() specifies which values to check for over these fields. add() inserts a + * new rule into the ExactMatch module such that traffic matching that + * bytestring will be forwarded out a specified gate. Example use: + * `add(fields=[aton('12.3.4.5'), aton('5.4.3.2')], gate=2)` */ message ExactMatchCommandAddArg { - uint64 gate = 1; /// The gate to forward out packets that mach this rule. - repeated FieldData fields = 2; /// The exact match values to check for - repeated FieldData values = 3; /// The exact match values to check for + uint64 gate = 1; /// The gate to forward out packets that mach this rule. + repeated FieldData fields = 2; /// The exact match values to check for + repeated FieldData values = 3; /// The exact match values to check for } /** - * The ExactMatch module has a command `delete(...)` which deletes an existing rule. - * Example use: `delete(fields=[aton('12.3.4.5'), aton('5.4.3.2')])` + * The ExactMatch module has a command `delete(...)` which deletes an existing + * rule. Example use: `delete(fields=[aton('12.3.4.5'), aton('5.4.3.2')])` */ message ExactMatchCommandDeleteArg { - repeated FieldData fields = 2; /// The field values for the rule to be deleted. + repeated FieldData fields = + 2; /// The field values for the rule to be deleted. } /** * The ExactMatch module has a command `clear()` which takes no parameters. * This command removes all rules from the ExactMatch module. */ -message ExactMatchCommandClearArg { -} +message ExactMatchCommandClearArg {} /** - * The ExactMatch module has a command `set_default_gate(...)` which takes one parameter. - * This command routes all traffic which does _not_ match a rule to a specified gate. - * Example use in bessctl: `setDefaultGate(gate=2)` + * The ExactMatch module has a command `set_default_gate(...)` which takes one + * parameter. This command routes all traffic which does _not_ match a rule to a + * specified gate. Example use in bessctl: `setDefaultGate(gate=2)` */ message ExactMatchCommandSetDefaultGateArg { - uint64 gate = 1; /// The gate number to send the default traffic out. + uint64 gate = 1; /// The gate number to send the default traffic out. } /** @@ -113,24 +111,25 @@ message FlowGenCommandSetBurstArg { /** * The HashLB module has a command `set_mode(...)` which takes two parameters. * The `mode` parameter specifies whether the load balancer will hash over the - * src/dest ethernet header (`'l2'`), over the src/dest IP addresses (`'l3'`), or over - * the flow 5-tuple (`'l4'`). Alternatively, if the `fields` parameter is set, the - * load balancer will hash over the N-tuple with the specified offsets and - * sizes. - * Example use in bessctl: `lb.set_mode('l2')` + * src/dest ethernet header (`'l2'`), over the src/dest IP addresses (`'l3'`), + * or over the flow 5-tuple (`'l4'`). Alternatively, if the `fields` parameter + * is set, the load balancer will hash over the N-tuple with the specified + * offsets and sizes. Example use in bessctl: `lb.set_mode('l2')` */ message HashLBCommandSetModeArg { - string mode = 1; /// What fields to hash over, `'l2'`, `'l3'`, and `'l4'` are only valid values. - repeated Field fields = 2; /// A list of fields that define a custom tuple. + string mode = 1; /// What fields to hash over, `'l2'`, `'l3'`, and `'l4'` are + /// only valid values. + repeated Field fields = 2; /// A list of fields that define a custom tuple. } /** * The HashLB module has a command `set_gates(...)` which takes one parameter. - * This function takes in a list of gate numbers to send hashed traffic out over. - * Example use in bessctl: `lb.setGates(gates=[0,1,2,3])` + * This function takes in a list of gate numbers to send hashed traffic out + * over. Example use in bessctl: `lb.setGates(gates=[0,1,2,3])` */ message HashLBCommandSetGatesArg { - repeated int64 gates = 1; ///A list of gate numbers to load balance traffic over + repeated int64 gates = + 1; /// A list of gate numbers to load balance traffic over } /** @@ -140,9 +139,9 @@ message HashLBCommandSetGatesArg { * Example use in bessctl: `table.add(prefix='10.0.0.0', prefix_len=8, gate=2)` */ message IPLookupCommandAddArg { - string prefix = 1; /// The CIDR IP part of the prefix to match - uint64 prefix_len = 2; /// The prefix length - uint64 gate = 3; /// The number of the gate to forward matching traffic on. + string prefix = 1; /// The CIDR IP part of the prefix to match + uint64 prefix_len = 2; /// The prefix length + uint64 gate = 3; /// The number of the gate to forward matching traffic on. } /** @@ -151,8 +150,8 @@ message IPLookupCommandAddArg { * Example use in bessctl: `table.delete(prefix='10.0.0.0', prefix_len=8)` */ message IPLookupCommandDeleteArg { - string prefix = 1; /// The CIDR IP part of the prefix to match - uint64 prefix_len = 2; /// The prefix length + string prefix = 1; /// The CIDR IP part of the prefix to match + uint64 prefix_len = 2; /// The prefix length } /** @@ -160,8 +159,7 @@ message IPLookupCommandDeleteArg { * This function removes all rules in the IPLookup table. * Example use in bessctl: `myiplookuptable.clear()` */ -message IPLookupCommandClearArg { -} +message IPLookupCommandClearArg {} /** * The L2Forward module forwards traffic via exact match over the Ethernet @@ -170,10 +168,10 @@ message IPLookupCommandClearArg { */ message L2ForwardCommandAddArg { message Entry { - string addr = 1; /// The MAC address to match - int64 gate = 2; /// Which gate to send out traffic matching this address. + string addr = 1; /// The MAC address to match + int64 gate = 2; /// Which gate to send out traffic matching this address. } - repeated Entry entries = 1; /// A list of L2Forward entries. + repeated Entry entries = 1; /// A list of L2Forward entries. } /** @@ -181,7 +179,8 @@ message L2ForwardCommandAddArg { * from the MAC forwarding table. */ message L2ForwardCommandDeleteArg { - repeated string addrs = 1; /// The address to remove from the forwarding table + repeated string addrs = + 1; /// The address to remove from the forwarding table } /** @@ -190,7 +189,8 @@ message L2ForwardCommandDeleteArg { * to direct unmatched traffic to. */ message L2ForwardCommandSetDefaultGateArg { - int64 gate = 1; /// The default gate to forward traffic which matches no entry to. + int64 gate = + 1; /// The default gate to forward traffic which matches no entry to. } /** @@ -198,46 +198,51 @@ message L2ForwardCommandSetDefaultGateArg { * a given MAC address will be forwared to; it returns the gate ID number. */ message L2ForwardCommandLookupArg { - repeated string addrs = 1; /// The MAC address to query for + repeated string addrs = 1; /// The MAC address to query for } /** - * This message type provides the reponse to the L2Forward function `lookup(..)`. - * It returns the gate that a requested MAC address is currently assigned to. + * This message type provides the reponse to the L2Forward function + * `lookup(..)`. It returns the gate that a requested MAC address is currently + * assigned to. */ message L2ForwardCommandLookupResponse { - repeated uint64 gates = 1; /// The gate ID that the requested MAC address maps to + repeated uint64 gates = + 1; /// The gate ID that the requested MAC address maps to } /** - * The L2Forward module has a command `populate(...)` which allows for fast creation - * of the forwarding table given a range of MAC addresses. The function takes in a - * 'base' MAC address, a count (number of MAC addresses), and a gate_id. The module - * will route all MAC addresses starting from the base address, up to base+count address - * round-robin over gate_count total gates. - * For example, `populate(base='11:22:33:44:00', count = 10, gate_count = 2)` would - * route addresses `11:22:33:44::(00, 02, 04, 06, 08)` out a gate 0 and the odd-suffixed - * addresses out gate 1. + * The L2Forward module has a command `populate(...)` which allows for fast + * creation of the forwarding table given a range of MAC addresses. The function + * takes in a 'base' MAC address, a count (number of MAC addresses), and a + * gate_id. The module will route all MAC addresses starting from the base + * address, up to base+count address round-robin over gate_count total gates. + * For example, `populate(base='11:22:33:44:00', count = 10, gate_count = 2)` + * would route addresses `11:22:33:44::(00, 02, 04, 06, 08)` out a gate 0 and + * the odd-suffixed addresses out gate 1. */ message L2ForwardCommandPopulateArg { - string base = 1; /// The base MAC address - int64 count = 2; /// How many addresses beyond base to populate into the routing table - int64 gate_count = 3; /// How many gates to create in the L2Forward module. + string base = 1; /// The base MAC address + int64 count = + 2; /// How many addresses beyond base to populate into the routing table + int64 gate_count = 3; /// How many gates to create in the L2Forward module. } /** * The Measure module measures and collects latency/jitter data for packets - * annotated by a Timestamp module. Note that Timestamp and Measure module must reside - * on the server for accurate measurement (as a result, the most typical use case is - * measuring roundtrip time). - * Optionally, you can also retrieve percentile values by specifying points in - * "percentiles". For example, "percentiles" of [50.0, 99.0] will return - * [median, 99'th %-ile tail latency] in "percentile_values_ns" in the response. + * annotated by a Timestamp module. Note that Timestamp and Measure module must + * reside on the server for accurate measurement (as a result, the most typical + * use case is measuring roundtrip time). Optionally, you can also retrieve + * percentile values by specifying points in "percentiles". For example, + * "percentiles" of [50.0, 99.0] will return [median, 99'th %-ile tail latency] + * in "percentile_values_ns" in the response. */ message MeasureCommandGetSummaryArg { - bool clear = 1; /// if true, the data will be all cleared after read - repeated double latency_percentiles = 2; /// ascending list of real numbers in [0.0, 100.0] - repeated double jitter_percentiles = 3; /// ascending list of real numbers in [0.0, 100.0] + bool clear = 1; /// if true, the data will be all cleared after read + repeated double latency_percentiles = + 2; /// ascending list of real numbers in [0.0, 100.0] + repeated double jitter_percentiles = + 3; /// ascending list of real numbers in [0.0, 100.0] } /** @@ -250,9 +255,11 @@ message MeasureCommandGetSummaryArg { */ message MeasureCommandGetSummaryResponse { message Histogram { - uint64 count = 1; /// Total # of measured data points, including above_range - uint64 above_range = 2; /// # of data points for the "too large value" bucket - uint64 resolution_ns = 8; /// resolution of measured data + uint64 count = + 1; /// Total # of measured data points, including above_range + uint64 above_range = + 2; /// # of data points for the "too large value" bucket + uint64 resolution_ns = 8; /// resolution of measured data uint64 min_ns = 3; uint64 avg_ns = 4; uint64 max_ns = 5; @@ -260,60 +267,63 @@ message MeasureCommandGetSummaryResponse { repeated uint64 percentile_values_ns = 7; } - double timestamp = 1; /// Seconds since boot. - uint64 packets = 2; /// Total # of packets seen by this module. - uint64 bits = 3; /// Total # of bits seen by this module. + double timestamp = 1; /// Seconds since boot. + uint64 packets = 2; /// Total # of packets seen by this module. + uint64 bits = 3; /// Total # of bits seen by this module. Histogram latency = 4; Histogram jitter = 5; } - /** * The Module DRR provides fair scheduling of flows based on a quantum which is - * number of bytes allocated to each flow on each round of going through all flows. - * Examples can be found [./bessctl/conf/samples/drr.bess] + * number of bytes allocated to each flow on each round of going through all + * flows. Examples can be found [./bessctl/conf/samples/drr.bess] * * __Input_Gates__: 1 * __Output_Gates__: 1 */ message DRRArg { uint32 num_flows = 1; /// Number of flows to handle in module - uint64 quantum = 2; /// the number of bytes to allocate to each on every round - uint32 max_flow_queue_size = 3; /// the max size that any Flows queue can get + uint64 quantum = + 2; /// the number of bytes to allocate to each on every round + uint32 max_flow_queue_size = 3; /// the max size that any Flows queue can get } /** * the SetQuantumSize function sets a new quantum for DRR module to operate on. */ message DRRQuantumArg { - uint32 quantum = 1; /// the number of bytes to allocate to each on every round + uint32 quantum = + 1; /// the number of bytes to allocate to each on every round } /** - * The SetMaxQueueSize function sets a new maximum flow queue size for DRR module. - * If the flow's queue gets to this size, the module starts dropping packets to - * that flow until the queue is below this size. + * The SetMaxQueueSize function sets a new maximum flow queue size for DRR + * module. If the flow's queue gets to this size, the module starts dropping + * packets to that flow until the queue is below this size. */ message DRRMaxFlowQueueSizeArg { uint32 max_queue_size = 1; /// the max size that any Flows queue can get } /** - * The module PortInc has a function `set_burst(...)` that allows you to specify the - * maximum number of packets to be stored in a single PacketBatch released by - * the module. + * The module PortInc has a function `set_burst(...)` that allows you to specify + * the maximum number of packets to be stored in a single PacketBatch released + * by the module. */ message PortIncCommandSetBurstArg { - uint64 burst = 1; /// The maximum "burst" of packets (ie, the maximum batch size) + uint64 burst = + 1; /// The maximum "burst" of packets (ie, the maximum batch size) } /** - * The module QueueInc has a function `set_burst(...)` that allows you to specify - * the maximum number of packets to be stored in a single PacketBatch released - * by the module. + * The module QueueInc has a function `set_burst(...)` that allows you to + * specify the maximum number of packets to be stored in a single PacketBatch + * released by the module. */ message QueueIncCommandSetBurstArg { - uint64 burst = 1; /// The maximum "burst" of packets (ie, the maximum batch size) + uint64 burst = + 1; /// The maximum "burst" of packets (ie, the maximum batch size) } /** @@ -322,7 +332,8 @@ message QueueIncCommandSetBurstArg { * by the module. */ message QueueCommandSetBurstArg { - uint64 burst = 1; /// The maximum "burst" of packets (ie, the maximum batch size) + uint64 burst = + 1; /// The maximum "burst" of packets (ie, the maximum batch size) } /** @@ -330,7 +341,7 @@ message QueueCommandSetBurstArg { * size of the queue in total number of packets. */ message QueueCommandSetSizeArg { - uint64 size = 1; /// The maximum number of packets to store in the queue. + uint64 size = 1; /// The maximum number of packets to store in the queue. } /** @@ -345,33 +356,30 @@ message QueueCommandGetStatusArg {} * size. */ message QueueCommandGetStatusResponse { - uint64 count = 1; /// The number of packets currently in the queue. - uint64 size = 2; /// The maximum number of packets the queue can contain. - uint64 enqueued = 3; /// total enqueued - uint64 dequeued = 4; /// total dequeued - uint64 dropped = 5; /// total dropped + uint64 count = 1; /// The number of packets currently in the queue. + uint64 size = 2; /// The maximum number of packets the queue can contain. + uint64 enqueued = 3; /// total enqueued + uint64 dequeued = 4; /// total dequeued + uint64 dropped = 5; /// total dropped } /** * The function `clear()` for RandomUpdate takes no parameters and clears all * state in the module. */ -message RandomUpdateCommandClearArg { -} +message RandomUpdateCommandClearArg {} /** * The function `clear()` for Rewrite takes no parameters and clears all state * in the module. */ -message RewriteCommandClearArg { -} +message RewriteCommandClearArg {} /** * The function `clear()` for Update takes no parameters and clears all state in * the module. */ -message UpdateCommandClearArg { -} +message UpdateCommandClearArg {} /** * The module WildcardMatch has a command `add(...)` which inserts a new rule @@ -379,39 +387,48 @@ message UpdateCommandClearArg { * `bess/bessctl/conf/samples/wildcardmatch.bess`. */ message WildcardMatchCommandAddArg { - uint64 gate = 1; /// Traffic matching this new rule will be sent to this gate. - int64 priority = 2; ///If a packet matches multiple rules, the rule with higher priority will be applied. If priorities are equal behavior is undefined. - repeated FieldData values = 3; /// The values to check for in each field. - repeated FieldData masks = 4; /// The bitmask for each field -- set `0x0` to ignore the field altogether. - repeated FieldData valuesv = 5; /// The values to check for in each fieldv. + uint64 gate = + 1; /// Traffic matching this new rule will be sent to this gate. + int64 priority = + 2; /// If a packet matches multiple rules, the rule with higher priority + /// will be applied. If priorities are equal behavior is undefined. + repeated FieldData values = 3; /// The values to check for in each field. + repeated FieldData masks = 4; /// The bitmask for each field -- set `0x0` to + /// ignore the field altogether. + repeated FieldData valuesv = 5; /// The values to check for in each fieldv. } /** - * The module WildcardMatch has a command `delete(...)` which removes a rule -- simply specify the values and masks from the previously inserted rule to remove them. + * The module WildcardMatch has a command `delete(...)` which removes a rule -- + * simply specify the values and masks from the previously inserted rule to + * remove them. */ message WildcardMatchCommandDeleteArg { - repeated FieldData values = 1; /// The values being checked for in the rule - repeated FieldData masks = 2; /// The bitmask from the rule. + repeated FieldData values = 1; /// The values being checked for in the rule + repeated FieldData masks = 2; /// The bitmask from the rule. } /** * The function `clear()` for WildcardMatch takes no parameters, it clears - * all state in the WildcardMatch module (is equivalent to calling delete for all rules) + * all state in the WildcardMatch module (is equivalent to calling delete for + * all rules) */ -message WildcardMatchCommandClearArg { -} +message WildcardMatchCommandClearArg {} /** * For traffic which does not match any rule in the WildcardMatch module, - * the `set_default_gate(...)` function specifies which gate to send this extra traffic to. + * the `set_default_gate(...)` function specifies which gate to send this extra + * traffic to. */ message WildcardMatchCommandSetDefaultGateArg { uint64 gate = 1; } /** - * The module ACL creates an access control module which by default blocks all traffic, unless it contains a rule which specifies otherwise. - * Examples of ACL can be found in [acl.bess](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/acl.bess) + * The module ACL creates an access control module which by default blocks all + * traffic, unless it contains a rule which specifies otherwise. Examples of ACL + * can be found in + * [acl.bess](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/acl.bess) * * __Input Gates__: 1 * __Output Gates__: 1 @@ -421,18 +438,20 @@ message ACLArg { * One ACL rule is represented by the following 6-tuple. */ message Rule { - string src_ip = 1; /// Source IP block in CIDR. Wildcard if "". - string dst_ip = 2; /// Destination IP block in CIDR. Wildcard if "". - uint32 src_port = 3; /// TCP/UDP source port. Wildcard if 0. - uint32 dst_port = 4; /// TCP/UDP Destination port. Wildcard if 0. - bool established = 5; /// Not implemented - bool drop = 6; /// Drop matched packets if true, forward if false. By default ACL drops all traffic. + string src_ip = 1; /// Source IP block in CIDR. Wildcard if "". + string dst_ip = 2; /// Destination IP block in CIDR. Wildcard if "". + uint32 src_port = 3; /// TCP/UDP source port. Wildcard if 0. + uint32 dst_port = 4; /// TCP/UDP Destination port. Wildcard if 0. + bool established = 5; /// Not implemented + bool drop = 6; /// Drop matched packets if true, forward if false. By + /// default ACL drops all traffic. } - repeated Rule rules = 1; ///A list of ACL rules. + repeated Rule rules = 1; /// A list of ACL rules. } /** - * The BPF module is an access control module that sends packets out on a particular gate based on whether they match a BPF filter. + * The BPF module is an access control module that sends packets out on a + * particular gate based on whether they match a BPF filter. * * __Input Gates__: 1 * __Output Gates__: many (configurable) @@ -442,28 +461,33 @@ message BPFArg { * One BPF filter is represented by the following 3-tuple. */ message Filter { - int64 priority = 1; /// The priority level for this rule. If a packet matches multiple rules, it will be forwarded out the gate with the highest priority. If a packet matches multiple rules with the same priority, the behavior is undefined. - string filter = 2; /// The actual BPF string. - int64 gate = 3; ///What gate to forward packets that match this BPF to. + int64 priority = + 1; /// The priority level for this rule. If a packet matches multiple + /// rules, it will be forwarded out the gate with the highest + /// priority. If a packet matches multiple rules with the same + /// priority, the behavior is undefined. + string filter = 2; /// The actual BPF string. + int64 gate = 3; /// What gate to forward packets that match this BPF to. } - repeated Filter filters = 1; /// The BPF initialized function takes a list of BPF filters. + repeated Filter filters = + 1; /// The BPF initialized function takes a list of BPF filters. } /** - * The Buffer module takes no parameters to initialize (ie, `Buffer()` is sufficient to create one). - * Buffer accepts packets and stores them; it may forward them to the next module only after it has - * received enough packets to fill an entire PacketBatch. + * The Buffer module takes no parameters to initialize (ie, `Buffer()` is + * sufficient to create one). Buffer accepts packets and stores them; it may + * forward them to the next module only after it has received enough packets to + * fill an entire PacketBatch. * * __Input Gates__: 1 * __Output Gates__: 1 */ -message BufferArg { -} +message BufferArg {} /** - * The Bypass module forwards packets by emulating pre-defined packet processing overhead. - * It burns cpu cycles per_batch, per_packet, and per-bytes. - * Bypass is useful primarily for testing and performance evaluation. + * The Bypass module forwards packets by emulating pre-defined packet processing + * overhead. It burns cpu cycles per_batch, per_packet, and per-bytes. Bypass is + * useful primarily for testing and performance evaluation. * * __Input Gates__: 1 * __Output Gates__: 1 @@ -475,41 +499,49 @@ message BypassArg { } /** - * The Dump module blindly forwards packets without modifying them. It periodically samples a packet and prints out out to the BESS log (by default stored in `/tmp/bessd.INFO`). + * The Dump module blindly forwards packets without modifying them. It + * periodically samples a packet and prints out out to the BESS log (by default + * stored in `/tmp/bessd.INFO`). * * __Input Gates__: 1 * __Output Gates__: 1 */ message DumpArg { - double interval = 1; ///How frequently to sample and print a packet, in seconds. + double interval = + 1; /// How frequently to sample and print a packet, in seconds. } /** - * The EtherEncap module wraps packets in an Ethernet header, but it takes no parameters. Instead, Ethernet source, destination, and type are pulled from a packet's metadata attributes. - * For example: `SetMetadata('dst_mac', 11:22:33:44:55) -> EtherEncap()` - * This is useful when upstream modules wish to assign a MAC address to a packet, e.g., due to an ARP request. + * The EtherEncap module wraps packets in an Ethernet header, but it takes no + * parameters. Instead, Ethernet source, destination, and type are pulled from a + * packet's metadata attributes. For example: `SetMetadata('dst_mac', + * 11:22:33:44:55) -> EtherEncap()` This is useful when upstream modules wish to + * assign a MAC address to a packet, e.g., due to an ARP request. * * __Input Gates__: 1 * __Output Gates__: 1 */ -message EtherEncapArg { -} +message EtherEncapArg {} /** - * The ExactMatch module splits packets along output gates according to exact match values in arbitrary packet fields. - * To instantiate an ExactMatch module, you must specify which fields in the packet to match over. You can add rules using the function `ExactMatch.add(...)` - * Fields may be stored either in the packet data or its metadata attributes. - * An example script using the ExactMatch code is found - * in [`bess/bessctl/conf/samples/exactmatch.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/exactmatch.bess). + * The ExactMatch module splits packets along output gates according to exact + * match values in arbitrary packet fields. To instantiate an ExactMatch module, + * you must specify which fields in the packet to match over. You can add rules + * using the function `ExactMatch.add(...)` Fields may be stored either in the + * packet data or its metadata attributes. An example script using the + * ExactMatch code is found in + * [`bess/bessctl/conf/samples/exactmatch.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/exactmatch.bess). * * __Input Gates__: 1 * __Output Gates__: many (configurable) */ message ExactMatchArg { - repeated Field fields = 1; ///A list of ExactMatch Fields - repeated FieldData masks = 2; /// mask(i) corresponds to the mask for field(i) - repeated Field values = 3; /// A list of ExactMatch Values - repeated FieldData masksv = 4; /// mask(i) corresponds to the mask for value(i) + repeated Field fields = 1; /// A list of ExactMatch Fields + repeated FieldData masks = + 2; /// mask(i) corresponds to the mask for field(i) + repeated Field values = 3; /// A list of ExactMatch Values + repeated FieldData masksv = + 4; /// mask(i) corresponds to the mask for value(i) uint64 entries = 5; } @@ -524,25 +556,46 @@ message ExactMatchConfig { } /** - * The FlowGen module generates simulated TCP flows of packets with correct SYN/FIN flags and sequence numbers. - * This module is useful for testing, e.g., a NAT module or other flow-aware code. - * Packets are generated off a base, "template" packet by modifying the IP src/dst and TCP src/dst. By default, only the ports are changed and will be modified by incrementing the template ports by up to 20000 more than the template values. + * The FlowGen module generates simulated TCP flows of packets with correct + * SYN/FIN flags and sequence numbers. This module is useful for testing, e.g., + * a NAT module or other flow-aware code. Packets are generated off a base, + * "template" packet by modifying the IP src/dst and TCP src/dst. By default, + * only the ports are changed and will be modified by incrementing the template + * ports by up to 20000 more than the template values. * * __Input Gates__: 0 * __Output Gates__: 1 */ message FlowGenArg { - bytes template = 1; /// The packet "template". All data packets are derived from this template and contain the same payload. - double pps = 2; /// The total number of packets per second to generate. - double flow_rate = 3; /// The number of new flows to create every second. flow_rate must be <= pps. - double flow_duration = 4; /// The lifetime of a flow in seconds. - string arrival = 5; /// The packet arrival distribution -- must be either "uniform" or "exponential" - string duration = 6; /// The flow duration distribution -- must be either "uniform" or "pareto" - bool quick_rampup = 7; /// Whether or not to populate the flowgenerator with initial flows (start generating full pps rate immediately) or to wait for new flows to be generated naturally (all flows have a SYN packet). - uint32 ip_src_range = 8; /// When generating new flows, FlowGen modifies the template packet by changing the IP src, incrementing it by at most ip_src_range (e.g., if the base packet is 10.0.0.1 and range is 5, it will generate packets with IPs 10.0.0.1-10.0.0.6). - uint32 ip_dst_range = 9; /// When generating new flows, FlowGen modifies the template packet by changing the IP dst, incrementing it by at most ip_dst_range. - uint32 port_src_range = 10; /// When generating new flows, FlowGen modifies the template packet by changing the TCP port, incrementing it by at most port_src_range. - uint32 port_dst_range = 11; /// When generating new flows, FlowGen modifies the template packet by changing the TCP dst port, incrementing it by at most port_dst_range. + bytes template = 1; /// The packet "template". All data packets are derived + /// from this template and contain the same payload. + double pps = 2; /// The total number of packets per second to generate. + double flow_rate = 3; /// The number of new flows to create every second. + /// flow_rate must be <= pps. + double flow_duration = 4; /// The lifetime of a flow in seconds. + string arrival = 5; /// The packet arrival distribution -- must be either + /// "uniform" or "exponential" + string duration = 6; /// The flow duration distribution -- must be either + /// "uniform" or "pareto" + bool quick_rampup = + 7; /// Whether or not to populate the flowgenerator with initial flows + /// (start generating full pps rate immediately) or to wait for new + /// flows to be generated naturally (all flows have a SYN packet). + uint32 ip_src_range = + 8; /// When generating new flows, FlowGen modifies the template packet by + /// changing the IP src, incrementing it by at most ip_src_range + /// (e.g., if the base packet is 10.0.0.1 and range is 5, it will + /// generate packets with IPs 10.0.0.1-10.0.0.6). + uint32 ip_dst_range = + 9; /// When generating new flows, FlowGen modifies the template packet by + /// changing the IP dst, incrementing it by at most ip_dst_range. + uint32 port_src_range = 10; /// When generating new flows, FlowGen modifies + /// the template packet by changing the TCP port, + /// incrementing it by at most port_src_range. + uint32 port_dst_range = + 11; /// When generating new flows, FlowGen modifies the template packet + /// by changing the TCP dst port, incrementing it by at most + /// port_dst_range. } /** @@ -552,7 +605,7 @@ message FlowGenArg { * __Ouptut Gates__: 1 */ message GenericDecapArg { - uint64 bytes = 1; /// The number of bytes to strip off. + uint64 bytes = 1; /// The number of bytes to strip off. } /** @@ -567,9 +620,9 @@ message GenericDecapArg { * {'size': 2, 'value': 0x1234}])` * will prepend a 8-byte header: * `de ad be ef 12 34` - * where the 2-byte ` ` comes from the value of metadata attribute `'foo'` - * for each packet. - * An example script using GenericEncap is in [`bess/bessctl/conf/samples/generic_encap.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/generic_encap.bess). + * where the 2-byte ` ` comes from the value of metadata attribute + * `'foo'` for each packet. An example script using GenericEncap is in + * [`bess/bessctl/conf/samples/generic_encap.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/generic_encap.bess). * * __Input Gates__: 1 * __Output Gates__: 1 @@ -579,10 +632,11 @@ message GenericEncapArg { * An EncapField represents one field in the new packet header. */ message EncapField { - uint64 size = 1; /// The length of the field. + uint64 size = 1; /// The length of the field. oneof insertion { - string attribute = 2; /// The metadata attribute name to pull the field value from - FieldData value = 3; /// Or, the fixed value to insert into the packet. + string attribute = + 2; /// The metadata attribute name to pull the field value from + FieldData value = 3; /// Or, the fixed value to insert into the packet. } } repeated EncapField fields = 1; @@ -590,28 +644,29 @@ message GenericEncapArg { /** * The HashLB module partitions packets between output gates according to either - * a hash over their MAC src/dst (`mode='l2'`), their IP src/dst (`mode='l3'`), the full - * IP/TCP 5-tuple (`mode='l4'`), or the N-tuple defined by `fields`. + * a hash over their MAC src/dst (`mode='l2'`), their IP src/dst (`mode='l3'`), + * the full IP/TCP 5-tuple (`mode='l4'`), or the N-tuple defined by `fields`. * * __Input Gates__: 1 * __Output Gates__: many (configurable) */ message HashLBArg { - repeated int64 gates = 1; /// A list of gate numbers over which to partition packets - string mode = 2; /// The mode (`'l2'`, `'l3'`, or `'l4'`) for the hash function. - repeated Field fields = 3; /// A list of fields that define a custom tuple. + repeated int64 gates = + 1; /// A list of gate numbers over which to partition packets + string mode = + 2; /// The mode (`'l2'`, `'l3'`, or `'l4'`) for the hash function. + repeated Field fields = 3; /// A list of fields that define a custom tuple. } /** - * Encapsulates a packet with an IP header, where IP src, dst, and proto are filled in - * by metadata values carried with the packet. Metadata attributes must include: - * ip_src, ip_dst, ip_proto, ip_nexthop, and ether_type. + * Encapsulates a packet with an IP header, where IP src, dst, and proto are + * filled in by metadata values carried with the packet. Metadata attributes + * must include: ip_src, ip_dst, ip_proto, ip_nexthop, and ether_type. * * __Input Gates__: 1 * __Output Gates__: 1 */ -message IPEncapArg { -} +message IPEncapArg {} /** * An IPLookup module perfroms LPM lookups over a packet destination. @@ -622,40 +677,43 @@ message IPEncapArg { * __Output Gates__: many (configurable, depending on rule values) */ message IPLookupArg { - uint32 max_rules = 1; /// Maximum number of rules (default: 1024) - uint32 max_tbl8s = 2; /// Maximum number of IP prefixes with smaller than /24 (default: 128) + uint32 max_rules = 1; /// Maximum number of rules (default: 1024) + uint32 max_tbl8s = + 2; /// Maximum number of IP prefixes with smaller than /24 (default: 128) } /** - * An L2Forward module forwards packets to an output gate according to exact-match rules over - * an Ethernet destination. - * Note that this is _not_ a learning switch -- forwards according to fixed - * routes specified by `add(..)`. + * An L2Forward module forwards packets to an output gate according to + * exact-match rules over an Ethernet destination. Note that this is _not_ a + * learning switch -- forwards according to fixed routes specified by `add(..)`. * * __Input Gates__: 1 * __Ouput Gates__: many (configurable, depending on rules) */ message L2ForwardArg { - int64 size = 1; /// Configures the forwarding hash table -- total number of hash table entries. - int64 bucket = 2; /// Configures the forwarding hash table -- total number of slots per hash value. + int64 size = 1; /// Configures the forwarding hash table -- total number of + /// hash table entries. + int64 bucket = 2; /// Configures the forwarding hash table -- total number of + /// slots per hash value. } /** - * The MACSwap module takes no arguments. It swaps the src/destination MAC addresses - * within a packet. + * The MACSwap module takes no arguments. It swaps the src/destination MAC + * addresses within a packet. * * __Input Gates__: 1 * __Output Gates__: 1 */ -message MACSwapArg { -} +message MACSwapArg {} /** - * The measure module tracks latencies, packets per second, and other statistics. - * It should be paired with a Timestamp module, which attaches a timestamp to packets. - * The measure module will log how long (in nanoseconds) it has been for each packet it received since it was timestamped. - * This module is somewhat experimental and undergoing various changes. - * There is a test for the the Measure module in [`bessctl/module_tests/timestamp.py`](https://github.com/omec-project/bess/blob/master/bessctl/module_tests/timestamp.py). + * The measure module tracks latencies, packets per second, and other + * statistics. It should be paired with a Timestamp module, which attaches a + * timestamp to packets. The measure module will log how long (in nanoseconds) + * it has been for each packet it received since it was timestamped. This module + * is somewhat experimental and undergoing various changes. There is a test for + * the the Measure module in + * [`bessctl/module_tests/timestamp.py`](https://github.com/omec-project/bess/blob/master/bessctl/module_tests/timestamp.py). * * __Input Gates__: 1 * __Output Gates__: 1 @@ -663,12 +721,16 @@ message MACSwapArg { message MeasureArg { // int64 warmup = 1; /// removed: instead of warmup delay, user should Clear() oneof type { - uint64 offset = 2; /// Where to store the current time within the packet, offset in bytes. - string attr_name = 6; /// Where to store the current time as attribute + uint64 offset = 2; /// Where to store the current time within the packet, + /// offset in bytes. + string attr_name = 6; /// Where to store the current time as attribute } - double jitter_sample_prob = 3; /// How often the module should sample packets for inter-packet arrival measurements (to measure jitter). - uint64 latency_ns_max = 4; /// maximum latency expected, in ns (default 0.1 s) - uint32 latency_ns_resolution = 5; /// resolution, in ns (default 100) + double jitter_sample_prob = + 3; /// How often the module should sample packets for inter-packet + /// arrival measurements (to measure jitter). + uint64 latency_ns_max = + 4; /// maximum latency expected, in ns (default 0.1 s) + uint32 latency_ns_resolution = 5; /// resolution, in ns (default 100) } /** @@ -678,8 +740,7 @@ message MeasureArg { * __Input Gates__: many (configurable) * __Output Gates__: 1 */ -message MergeArg { -} +message MergeArg {} /** * The MetadataTest module is used for internal testing purposes. @@ -701,7 +762,8 @@ message MetadataTestArg { * Currently only supports TCP/UDP/ICMP. * Note that address/port in packet payload (e.g., FTP) are NOT translated. * - * __Input Gates__: 2 (0 for internal->external, and 1 for external->internal direction) + * __Input Gates__: 2 (0 for internal->external, and 1 for external->internal + * direction) * __Output Gates__: 2 (same as the input gate) */ message NATArg { @@ -714,7 +776,7 @@ message NATArg { string ext_addr = 1; repeated PortRange port_ranges = 2; } - repeated ExternalAddress ext_addrs = 1; /// list of external IP addresses + repeated ExternalAddress ext_addrs = 1; /// list of external IP addresses } /** @@ -733,18 +795,19 @@ message NATArg { * * Note that address in packet payload (e.g., FTP) are NOT translated. * - * __Input Gates__: 2 (0 for internal->external, and 1 for external->internal direction) + * __Input Gates__: 2 (0 for internal->external, and 1 for external->internal + * direction) * __Output Gates__: 2 (same as the input gate) */ message StaticNATArg { message AddressRange { - string start = 1; /// first IP address to use - string end = 2; /// last IP address to use + string start = 1; /// first IP address to use + string end = 2; /// last IP address to use } message AddressRangePair { AddressRange int_range = 1; - AddressRange ext_range = 2; /// should be the same size as int_range + AddressRange ext_range = 2; /// should be the same size as int_range } repeated AddressRangePair pairs = 1; @@ -753,8 +816,7 @@ message StaticNATArg { /** * This module is used for testing purposes. */ -message NoOpArg { -} +message NoOpArg {} /** * The PortInc module connects a physical or virtual port and releases @@ -766,8 +828,8 @@ message NoOpArg { * __Output Gates__: 1 */ message PortIncArg { - string port = 1; /// The portname to connect to. - bool prefetch = 2; /// Whether or not to prefetch packets from the port. + string port = 1; /// The portname to connect to. + bool prefetch = 2; /// Whether or not to prefetch packets from the port. } /** @@ -779,7 +841,7 @@ message PortIncArg { * __Output Gates__: 0 */ message PortOutArg { - string port = 1; /// The portname to connect to. + string port = 1; /// The portname to connect to. } /** @@ -792,9 +854,11 @@ message PortOutArg { * __Output Gates__: 1 */ message QueueIncArg { - string port = 1; /// The portname to connect to (read from). - uint64 qid = 2; /// The queue on that port to read from. qid starts from 0. - bool prefetch = 3; /// When prefetch is enabled, the module will perform CPU prefetch on the first 64B of each packet onto CPU L1 cache. Default value is false. + string port = 1; /// The portname to connect to (read from). + uint64 qid = 2; /// The queue on that port to read from. qid starts from 0. + bool prefetch = 3; /// When prefetch is enabled, the module will perform CPU + /// prefetch on the first 64B of each packet onto CPU L1 + /// cache. Default value is false. } /** @@ -807,8 +871,8 @@ message QueueIncArg { * __Output Gates__: 0 */ message QueueOutArg { - string port = 1; /// The portname to connect to. - uint64 qid = 2; /// The queue on that port to write out to. + string port = 1; /// The portname to connect to. + uint64 qid = 2; /// The queue on that port to write out to. } /** @@ -818,9 +882,12 @@ message QueueOutArg { * __Output Gates__: 1 */ message QueueArg { - uint64 size = 1; /// The maximum number of packets to store in the queue. - bool prefetch = 2; /// When prefetch is enabled, the module will perform CPU prefetch on the first 64B of each packet onto CPU L1 cache. Default value is false. - bool backpressure = 3; // When backpressure is enabled, the module will notify upstream if it is overloaded. + uint64 size = 1; /// The maximum number of packets to store in the queue. + bool prefetch = 2; /// When prefetch is enabled, the module will perform CPU + /// prefetch on the first 64B of each packet onto CPU L1 + /// cache. Default value is false. + bool backpressure = 3; // When backpressure is enabled, the module will + // notify upstream if it is overloaded. } /** @@ -830,8 +897,8 @@ message QueueArg { * __Output Gates__: many (configurable) */ message RandomSplitArg { - double drop_rate = 1; /// Probability of dropping packet. - repeated int64 gates = 2; /// A list of gate numbers to split the traffic. + double drop_rate = 1; /// Probability of dropping packet. + repeated int64 gates = 2; /// A list of gate numbers to split the traffic. } /** @@ -839,7 +906,7 @@ message RandomSplitArg { * the probability of dropping packets */ message RandomSplitCommandSetDroprateArg { - double drop_rate = 1; /// Probability of dropping packet. + double drop_rate = 1; /// Probability of dropping packet. } /** @@ -847,12 +914,12 @@ message RandomSplitCommandSetDroprateArg { * the total number of output gates in the module. */ message RandomSplitCommandSetGatesArg { - repeated int64 gates = 1; /// A list of gate numbers to split the traffic. + repeated int64 gates = 1; /// A list of gate numbers to split the traffic. } /** - * The RandomUpdate module rewrites a specified field (`offset` and `size`) in a packet - * with a random value between a specified min and max values. + * The RandomUpdate module rewrites a specified field (`offset` and `size`) in a + * packet with a random value between a specified min and max values. * * __Input Gates__: 1 * __Output Gates__: 1 @@ -863,12 +930,12 @@ message RandomUpdateArg { * in each packet processed. */ message Field { - int64 offset = 1; /// Offset in bytes of where to rewrite. - uint64 size = 2; /// The number of bytes to write. - uint64 min = 3; /// The minimum value to insert into the packet. - uint64 max = 4; /// The maximum value to insert into the packet. + int64 offset = 1; /// Offset in bytes of where to rewrite. + uint64 size = 2; /// The number of bytes to write. + uint64 min = 3; /// The minimum value to insert into the packet. + uint64 max = 4; /// The maximum value to insert into the packet. } - repeated Field fields = 1; /// A list of Random Update Fields. + repeated Field fields = 1; /// A list of Random Update Fields. } /** @@ -880,7 +947,8 @@ message RandomUpdateArg { * __Output Gates__: 1 */ message RewriteArg { - repeated bytes templates = 1; /// A list of bytestrings representing packet templates. + repeated bytes templates = + 1; /// A list of bytestrings representing packet templates. } /** @@ -888,7 +956,8 @@ message RewriteArg { * the total number of output gates in the module. */ message RoundRobinCommandSetGatesArg { - repeated int64 gates = 1; /// A list of gate numbers to round-robin the traffic over. + repeated int64 gates = + 1; /// A list of gate numbers to round-robin the traffic over. } /** @@ -896,19 +965,21 @@ message RoundRobinCommandSetGatesArg { * to balance traffic across gates per-packet or per-batch. */ message RoundRobinCommandSetModeArg { - string mode = 1; /// whether to perform `'packet'` or `'batch'` round robin partitioning. + string mode = 1; /// whether to perform `'packet'` or `'batch'` round robin + /// partitioning. } /** - * The RoundRobin module splits packets from one input gate across multiple output - * gates. + * The RoundRobin module splits packets from one input gate across multiple + * output gates. * * __Input Gates__: 1 * __Output Gates__: many (configurable) */ message RoundRobinArg { - repeated int64 gates = 1; /// A list of gate numbers to split packets across. - string mode = 2; /// Whether to split across gate with every `'packet'` or every `'batch'`. + repeated int64 gates = 1; /// A list of gate numbers to split packets across. + string mode = 2; /// Whether to split across gate with every `'packet'` or + /// every `'batch'`. } /** @@ -919,7 +990,8 @@ message RoundRobinArg { * __Output Gates__: many (configurable) */ message ReplicateArg { - repeated int64 gates = 1; /// A list of gate numbers to send packet copies to. + repeated int64 gates = + 1; /// A list of gate numbers to send packet copies to. } /** @@ -927,12 +999,13 @@ message ReplicateArg { * the total number of output gates in the module. */ message ReplicateCommandSetGatesArg { - repeated int64 gates = 1; /// A list of gate numbers to replicate the traffic over. + repeated int64 gates = + 1; /// A list of gate numbers to replicate the traffic over. } /** - * The SetMetadata module adds metadata attributes to packets, which are not stored - * or sent out with packet data. For examples of SetMetadata use, see + * The SetMetadata module adds metadata attributes to packets, which are not + * stored or sent out with packet data. For examples of SetMetadata use, see * [`bess/bessctl/conf/attr_match.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/metadata/attr_match.bess) * * __Input Gates__: 1 @@ -940,23 +1013,32 @@ message ReplicateCommandSetGatesArg { */ message SetMetadataArg { /** - * SetMetadata Attribute describes a metadata attribute and value to attach to every packet. - * If copying data from a packet buffer, SetMetadata can also logically shift - * then mask the value before storing it as metadata, i.e., + * SetMetadata Attribute describes a metadata attribute and value to attach to + * every packet. If copying data from a packet buffer, SetMetadata can also + * logically shift then mask the value before storing it as metadata, i.e., * metadata_value = (packet_value >> `rshift_bits`) & `mask`. */ message Attribute { - string name = 1; /// The metadata attribute name. - uint64 size = 2; /// The size of values stored in this attribute in bytes. + string name = 1; /// The metadata attribute name. + uint64 size = 2; /// The size of values stored in this attribute in bytes. oneof value { - uint64 value_int = 3; /// An integer value to store in the packet (host-order). - bytes value_bin = 4; /// A binary value to store in the packet (host-order). + uint64 value_int = + 3; /// An integer value to store in the packet (host-order). + bytes value_bin = + 4; /// A binary value to store in the packet (host-order). } - int32 offset = 5; /// An index in the packet data to store copy into the metadata attribute. - bytes mask = 6; /// An array of bit masks to apply to each of the bytes copied starting from `offset`. If empty, the mask `[0xFF,....,0xFF]` will be used. - int32 rshift_bits = 7; /// The number of bits to shift the value at `offset` by before masking. Must be a multiple of 8. Positive and negative values represent right and left shifts respectively. + int32 offset = 5; /// An index in the packet data to store copy into the + /// metadata attribute. + bytes mask = 6; /// An array of bit masks to apply to each of the bytes + /// copied starting from `offset`. If empty, the mask + /// `[0xFF,....,0xFF]` will be used. + int32 rshift_bits = + 7; /// The number of bits to shift the value at `offset` by before + /// masking. Must be a multiple of 8. Positive and negative values + /// represent right and left shifts respectively. } - repeated Attribute attrs = 1; /// A list of attributes to attach to the packet. + repeated Attribute attrs = + 1; /// A list of attributes to attach to the packet. } /** @@ -965,8 +1047,7 @@ message SetMetadataArg { * __Input Gates__: 1 * __Output Gates__: 0 */ -message SinkArg { -} +message SinkArg {} /** * The Source module has a function `set_burst(...)` which @@ -974,7 +1055,8 @@ message SinkArg { * from the module. */ message SourceCommandSetBurstArg { - uint64 burst = 1; /// The maximum number of packets to release in a packetbatch from the module. + uint64 burst = 1; /// The maximum number of packets to release in a + /// packetbatch from the module. } /** @@ -982,7 +1064,8 @@ message SourceCommandSetBurstArg { * of packets to be produced by the Source module. */ message SourceCommandSetPktSizeArg { - uint64 pkt_size = 1; /// The size (in bytes) of the packets for Source to create. + uint64 pkt_size = + 1; /// The size (in bytes) of the packets for Source to create. } /** @@ -992,35 +1075,35 @@ message SourceCommandSetPktSizeArg { * __Output Gates__: 1 */ message SourceArg { - uint64 pkt_size = 1; /// The size (in bytes) of packet data to produce. + uint64 pkt_size = 1; /// The size (in bytes) of packet data to produce. } /** -* The IPChecksum module calculates the IPv4 checksum of packets. If -* verify is set to true, the module can be used to validate the checksum -* of the IPv4 packet. All non-IPv4 packets are forwarded without -* modification. Output gates: (0) Default, (1) Drop. -* -* __Input Gates__: 1 -* __Output Gates__: 2 -*/ + * The IPChecksum module calculates the IPv4 checksum of packets. If + * verify is set to true, the module can be used to validate the checksum + * of the IPv4 packet. All non-IPv4 packets are forwarded without + * modification. Output gates: (0) Default, (1) Drop. + * + * __Input Gates__: 1 + * __Output Gates__: 2 + */ message IPChecksumArg { - bool verify = 1; /// check checksum - bool hw = 2; /// enable hardware offload + bool verify = 1; /// check checksum + bool hw = 2; /// enable hardware offload } /** -* The L4Checksum module calculates the UDP/IPv4 checksum of packets. If -* verify is set to true, the module can be used to validate the checksum -* of the UDP/IPv4 packet. All non-IPv4 packets are forwarded without -* modification. Output gates: (0) Default, (1) Drop. -* -* __Input Gates__: MAX_GATES -* __Output Gates__: 2 -*/ + * The L4Checksum module calculates the UDP/IPv4 checksum of packets. If + * verify is set to true, the module can be used to validate the checksum + * of the UDP/IPv4 packet. All non-IPv4 packets are forwarded without + * modification. Output gates: (0) Default, (1) Drop. + * + * __Input Gates__: MAX_GATES + * __Output Gates__: 2 + */ message L4ChecksumArg { - bool verify = 1; /// check checksum - bool hw = 2; /// enable hardware offload + bool verify = 1; /// check checksum + bool hw = 2; /// enable hardware offload } /** @@ -1032,7 +1115,7 @@ message L4ChecksumArg { * __Output Gates__: 1 */ message GtpuEchoArg { - uint32 s1u_sgw_ip = 1; /// IP address of S1U interface + uint32 s1u_sgw_ip = 1; /// IP address of S1U interface } /** @@ -1044,8 +1127,8 @@ message GtpuEchoArg { * __Output Gates__: 1 */ message IPDefragArg { - uint32 num_flows = 1; /// max number of flows the module can handle - int32 numa = 2; /// numa placement for ip frags memory management + uint32 num_flows = 1; /// max number of flows the module can handle + int32 numa = 2; /// numa placement for ip frags memory management } /** @@ -1056,7 +1139,8 @@ message IPDefragArg { * __Output Gates__: 1 */ message IPFragArg { - int32 mtu = 1; /// full Ethernet frame size (including CRC) for encapsulated ipv4 frag datagrams + int32 mtu = 1; /// full Ethernet frame size (including CRC) for encapsulated + /// ipv4 frag datagrams } /** @@ -1066,7 +1150,7 @@ message IPFragArg { * Example use in bessctl: `counter.add(ctr_id=0x1)` */ message CounterAddArg { - uint32 ctr_id = 1; /// counter id + uint32 ctr_id = 1; /// counter id } /** @@ -1076,7 +1160,7 @@ message CounterAddArg { * Example use in bessctl: `counter.remove(ctr_id=0x1)` */ message CounterRemoveArg { - uint32 ctr_id = 1; /// counter id + uint32 ctr_id = 1; /// counter id } /** @@ -1084,11 +1168,12 @@ message CounterRemoveArg { * * __Input Gates__: 1 * __Output Gates__: 1 -*/ + */ message CounterArg { - string name_id = 1; /// Name of the counter_id - bool check_exist = 2; /// verify each counter pre-exists before any operation (default = False) - uint32 total = 3; /// Total number of entries it can support + string name_id = 1; /// Name of the counter_id + bool check_exist = 2; /// verify each counter pre-exists before any operation + /// (default = False) + uint32 total = 3; /// Total number of entries it can support } /** @@ -1096,9 +1181,9 @@ message CounterArg { * * __Input Gates__: 1 * __Output Gates__: 1 -*/ + */ message GtpuEncapArg { - bool add_psc = 1; /// Add PDU session container in encap (default = False) + bool add_psc = 1; /// Add PDU session container in encap (default = False) } /** @@ -1110,10 +1195,10 @@ message GtpuEncapArg { * __Output Gates__: many (up to 2^(size * 8)) */ message SplitArg { - uint64 size = 1; /// The size of the value to read in bytes + uint64 size = 1; /// The size of the value to read in bytes oneof type { - string attribute = 2; /// The name of the metadata field to read. - int64 offset = 3; /// The offset (in bytes) of the data field to read. + string attribute = 2; /// The name of the metadata field to read. + int64 offset = 3; /// The offset (in bytes) of the data field to read. } } @@ -1141,14 +1226,15 @@ message TimestampArg { */ message UpdateArg { /** - * Update Field describes where in a packet's data to rewrite, and with what value. + * Update Field describes where in a packet's data to rewrite, and with what + * value. */ message Field { - int64 offset = 1; /// The offset in the packet in bytes to rewrite at. - uint64 size = 2; /// The number of bytes to rewrite (max 8 bytes). - uint64 value = 3; /// The value to write into the packet, max 8 bytes. + int64 offset = 1; /// The offset in the packet in bytes to rewrite at. + uint64 size = 2; /// The number of bytes to rewrite (max 8 bytes). + uint64 value = 3; /// The value to write into the packet, max 8 bytes. } - repeated Field fields = 1; /// A list of Update Fields. + repeated Field fields = 1; /// A list of Update Fields. } /** @@ -1169,7 +1255,7 @@ message UrlFilterArg { string host = 1; /// Host field, e.g. "www.google.com" string path = 2; /// Path prefix, e.g. "/" } - repeated Url blacklist = 1; /// A list of Urls to block. + repeated Url blacklist = 1; /// A list of Urls to block. } /** @@ -1188,8 +1274,7 @@ message UrlFilterConfig { * __Input Gates__: 1 * __Output Gates__: 1 */ -message VLANPopArg { -} +message VLANPopArg {} /** * VLANPush appends a VLAN tag with a specified TCI value. @@ -1198,17 +1283,17 @@ message VLANPopArg { * __Output Gates__: 1 */ message VLANPushArg { - uint64 tci = 1; /// The TCI value to insert in the VLAN tag. + uint64 tci = 1; /// The TCI value to insert in the VLAN tag. } /** - * Splits packets across output gates according to VLAN id (e.g., id 3 goes out gate 3). + * Splits packets across output gates according to VLAN id (e.g., id 3 goes out + * gate 3). * * __Input Gates__: 1 * __Output Gates__: many */ -message VLANSplitArg { -} +message VLANSplitArg {} /** * VXLANDecap module decapsulates a VXLAN header on a packet. @@ -1216,32 +1301,33 @@ message VLANSplitArg { * __Input Gates__: 1 * __Output Gates__: 1 */ -message VXLANDecapArg { -} +message VXLANDecapArg {} /** - * VXLANEncap module wraps a packet in a VXLAN header with a specified destination port. + * VXLANEncap module wraps a packet in a VXLAN header with a specified + * destination port. * * __Input Gates__: 1 * __Output Gates__: 1 */ message VXLANEncapArg { - uint64 dstport = 1; /// The destination UDP port + uint64 dstport = 1; /// The destination UDP port } /** * The WildcardMatch module matches over multiple fields in a packet and - * pushes packets that do match out a specified gate, and those that don't out a default - * gate. WildcardMatch is initialized with the fields it should inspect over, - * rules are added via the `add(...)` function. - * An example of WildcardMatch is in [`bess/bessctl/conf/samples/wildcardmatch.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/wildcardmatch.bess) + * pushes packets that do match out a specified gate, and those that don't out a + * default gate. WildcardMatch is initialized with the fields it should inspect + * over, rules are added via the `add(...)` function. An example of + * WildcardMatch is in + * [`bess/bessctl/conf/samples/wildcardmatch.bess`](https://github.com/omec-project/bess/blob/master/bessctl/conf/samples/wildcardmatch.bess) * * __Input Gates__: 1 * __Output Gates__: many (configurable) */ message WildcardMatchArg { - repeated Field fields = 1; /// A list of WildcardMatch fields. - repeated Field values = 2; /// A list of WildcardMatch values. + repeated Field fields = 1; /// A list of WildcardMatch fields. + repeated Field values = 2; /// A list of WildcardMatch values. uint64 entries = 3; } @@ -1265,8 +1351,8 @@ message WildcardMatchConfig { * __Output Gates__: 1 */ message ArpResponderArg { - string ip = 1; /// The IP - string mac_addr = 2; /// The MAC address + string ip = 1; /// The IP + string mac_addr = 2; /// The MAC address } /** @@ -1276,8 +1362,8 @@ message ArpResponderArg { * __Output Gates__: 2 */ message MplsPopArg { - bool remove_eth_header = 1; /// Remove ETH header with the pop - uint32 next_eth_type = 2; /// The next ETH type to set + bool remove_eth_header = 1; /// Remove ETH header with the pop + uint32 next_eth_type = 2; /// The next ETH type to set } /** @@ -1296,7 +1382,7 @@ message MplsPopArg { * __Output Gates__: many */ message WorkerSplitArg { - map worker_gates = 1; // ogate -> worker mask + map worker_gates = 1; // ogate -> worker mask } message QosArg { @@ -1312,9 +1398,7 @@ message QosCommandAddArg { uint64 cbs = 4; uint64 pbs = 5; uint64 ebs = 6; - oneof optional_deduct_len { - int64 deduct_len = 9; - } + oneof optional_deduct_len { int64 deduct_len = 9; } repeated FieldData fields = 7; repeated FieldData values = 8; } @@ -1325,14 +1409,15 @@ message QosCommandDeleteArg { /** * The function `clear()` for WildcardMatch takes no parameters, it clears - * all state in the WildcardMatch module (is equivalent to calling delete for all rules) + * all state in the WildcardMatch module (is equivalent to calling delete for + * all rules) */ -message QosCommandClearArg { -} +message QosCommandClearArg {} /** * For traffic which does not match any rule in the WildcardMatch module, - * the `set_default_gate(...)` function specifies which gate to send this extra traffic to. + * the `set_default_gate(...)` function specifies which gate to send this extra + * traffic to. */ message QosCommandSetDefaultGateArg { uint64 gate = 1; @@ -1341,20 +1426,24 @@ message QosCommandSetDefaultGateArg { message FlowMeasureArg { string flag_attr_name = 1; uint64 entries = 2; - bool leader = 3; // If true, this module will decide the buffer side + bool leader = 3; // If true, this module will decide the buffer side } message FlowMeasureCommandReadArg { - bool clear = 1; // If true, the data will be all cleared after read - repeated double latency_percentiles = 2; /// ascending list of real numbers in [0.0, 100.0] - repeated double jitter_percentiles = 3; /// ascending list of real numbers in [0.0, 100.0] - uint64 flag_to_read = 4; /// Which buffer to read from + bool clear = 1; // If true, the data will be all cleared after read + repeated double latency_percentiles = + 2; /// ascending list of real numbers in [0.0, 100.0] + repeated double jitter_percentiles = + 3; /// ascending list of real numbers in [0.0, 100.0] + uint64 flag_to_read = 4; /// Which buffer to read from } message FlowMeasureReadResponse { message Statistic { message Histogram { - uint64 count = 1; /// Total # of measured data points, including above_range - uint64 above_range = 2; /// # of data points for the "too large value" bucket - uint64 resolution_ns = 8; /// resolution of measured data + uint64 count = + 1; /// Total # of measured data points, including above_range + uint64 above_range = + 2; /// # of data points for the "too large value" bucket + uint64 resolution_ns = 8; /// resolution of measured data uint64 min_ns = 3; uint64 avg_ns = 4; uint64 max_ns = 5; diff --git a/protobuf/ports/port_msg.proto b/protobuf/ports/port_msg.proto index c716139c72..12fe79f040 100644 --- a/protobuf/ports/port_msg.proto +++ b/protobuf/ports/port_msg.proto @@ -51,9 +51,7 @@ message PMDPortArg { bool vlan_offload_rx_strip = 5; bool vlan_offload_rx_filter = 6; bool vlan_offload_rx_qinq = 7; - oneof socket { - int32 socket_id = 8; - } + oneof socket { int32 socket_id = 8; } bool promiscuous_mode = 9; bool hwcksum = 10; diff --git a/protobuf/service.proto b/protobuf/service.proto index b5f4dc11b1..8aac6e773e 100644 --- a/protobuf/service.proto +++ b/protobuf/service.proto @@ -38,13 +38,12 @@ package bess.pb; option go_package = "github.com/omec-project/upf-epc/pfcpiface/bess_pb"; service BESSControl { - // ------------------------------------------------------------------------- // System // ------------------------------------------------------------------------- /// Query version of bessd - rpc GetVersion (EmptyRequest) returns (VersionResponse) {} + rpc GetVersion(EmptyRequest) returns (VersionResponse) {} /// Reset the current packet processing datapath to the initial state. /// @@ -57,7 +56,7 @@ service BESSControl { /// started (if not, it is a bug; please report). /// /// NOTE: There should be no running worker to run this command. - rpc ResetAll (EmptyRequest) returns (EmptyResponse) {} + rpc ResetAll(EmptyRequest) returns (EmptyResponse) {} /// Terminate the BESS daemon. /// @@ -67,26 +66,25 @@ service BESSControl { /// /// NOTE: There should be no running worker to run this command. /// FIXME: rename (e.g., Terminate) - rpc KillBess (EmptyRequest) returns (EmptyResponse) {} + rpc KillBess(EmptyRequest) returns (EmptyResponse) {} /// Import a plugin /// /// At the moment plugins can only contain module types, /// but might also support drivers/hooks/schedulers in the future. - rpc ImportPlugin (ImportPluginRequest) returns (EmptyResponse) {} + rpc ImportPlugin(ImportPluginRequest) returns (EmptyResponse) {} /// Unload a plugin /// /// At the moment plugins can only contain module types, /// but might also support drivers/hooks/schedulers in the future. - rpc UnloadPlugin (UnloadPluginRequest) returns (EmptyResponse) {} + rpc UnloadPlugin(UnloadPluginRequest) returns (EmptyResponse) {} /// List imported plugins /// /// At the moment plugins can only contain module types, /// but might also support drivers/hooks/schedulers in the future. - rpc ListPlugins (EmptyRequest) returns (ListPluginsResponse) {} - + rpc ListPlugins(EmptyRequest) returns (ListPluginsResponse) {} // ------------------------------------------------------------------------- // Worker @@ -103,45 +101,45 @@ service BESSControl { /// ... /// ResumeAll() /// Keep the duration as short as possible, to avoid packet drops. - rpc PauseAll (EmptyRequest) returns (EmptyResponse) {} + rpc PauseAll(EmptyRequest) returns (EmptyResponse) {} /// Pause the specified worker temporarily /// /// Some RPC commands to BESS or individual modules/ports require that /// threads must be inactive, to avoid race conditions. - /// For such commands, use PauseWorker at the beginning and ResumeWorker at the end. + /// For such commands, use PauseWorker at the beginning and ResumeWorker at + /// the end. /// PauseWorker(0) /// SomeCommand1() /// SomeCommand2() /// ... /// ResumeWorker(0) /// Keep the duration as short as possible, to avoid packet drops. - rpc PauseWorker (PauseWorkerRequest) returns (EmptyResponse) {} + rpc PauseWorker(PauseWorkerRequest) returns (EmptyResponse) {} /// Resume the specified worker - rpc ResumeWorker (ResumeWorkerRequest) returns (EmptyResponse) {} + rpc ResumeWorker(ResumeWorkerRequest) returns (EmptyResponse) {} /// Resume all paused workers - rpc ResumeAll (EmptyRequest) returns (EmptyResponse) {} + rpc ResumeAll(EmptyRequest) returns (EmptyResponse) {} /// Remove all existing workers /// /// NOTE: There should be no running worker to run this command. - rpc ResetWorkers (EmptyRequest) returns (EmptyResponse) {} + rpc ResetWorkers(EmptyRequest) returns (EmptyResponse) {} /// Enumerate all existing workers - rpc ListWorkers (EmptyRequest) returns (ListWorkersResponse) {} + rpc ListWorkers(EmptyRequest) returns (ListWorkersResponse) {} /// Create a new worker /// /// NOTE: There should be no running worker to run this command. - rpc AddWorker (AddWorkerRequest) returns (EmptyResponse) {} + rpc AddWorker(AddWorkerRequest) returns (EmptyResponse) {} /// Remove a single worker /// /// NOTE: There should be no running worker to run this command. - rpc DestroyWorker (DestroyWorkerRequest) returns (EmptyResponse) {} - + rpc DestroyWorker(DestroyWorkerRequest) returns (EmptyResponse) {} // ------------------------------------------------------------------------- // Traffic classe & task @@ -150,39 +148,39 @@ service BESSControl { /// Remove all existing traffic classes /// /// NOTE: There should be no running worker to run this command. - rpc ResetTcs (EmptyRequest) returns (EmptyResponse) {} + rpc ResetTcs(EmptyRequest) returns (EmptyResponse) {} /// Enumerate all existing workers - rpc ListTcs (ListTcsRequest) returns (ListTcsResponse) {} + rpc ListTcs(ListTcsRequest) returns (ListTcsResponse) {} /// Check scheduling contraints - rpc CheckSchedulingConstraints (EmptyRequest) returns (CheckSchedulingConstraintsResponse) {} + rpc CheckSchedulingConstraints(EmptyRequest) + returns (CheckSchedulingConstraintsResponse) {} /// Create a new traffic class /// /// NOTE: There should be no running worker to run this command. - rpc AddTc (AddTcRequest) returns (EmptyResponse) {} + rpc AddTc(AddTcRequest) returns (EmptyResponse) {} /// Update parameters of an existing traffic class /// /// NOTE: There should be no running worker to run this command. - rpc UpdateTcParams (UpdateTcParamsRequest) returns (EmptyResponse) {} + rpc UpdateTcParams(UpdateTcParamsRequest) returns (EmptyResponse) {} /// Change parent (and child arguments) of an existing traffic class /// /// NOTE: There should be no running worker to run this command. - rpc UpdateTcParent (UpdateTcParentRequest) returns (EmptyResponse) {} + rpc UpdateTcParent(UpdateTcParentRequest) returns (EmptyResponse) {} /// Collect statistics of a traffic class - rpc GetTcStats (GetTcStatsRequest) returns (GetTcStatsResponse) {} - + rpc GetTcStats(GetTcStatsRequest) returns (GetTcStatsResponse) {} // ------------------------------------------------------------------------- // Port // ------------------------------------------------------------------------- /// Enumerate all port drivers available - rpc ListDrivers (EmptyRequest) returns (ListDriversResponse) {} + rpc ListDrivers(EmptyRequest) returns (ListDriversResponse) {} /// Query detailed information of a port driver rpc GetDriverInfo(GetDriverInfoRequest) returns (GetDriverInfoResponse) {} @@ -193,60 +191,59 @@ service BESSControl { /// (e.g., PortInc, PortOut, QueueInc, QueueOut) /// /// NOTE: There should be no running worker to run this command. - rpc ResetPorts (EmptyRequest) returns (EmptyResponse) {} + rpc ResetPorts(EmptyRequest) returns (EmptyResponse) {} /// Enumerate all initialized ports - rpc ListPorts (EmptyRequest) returns (ListPortsResponse) {} + rpc ListPorts(EmptyRequest) returns (ListPortsResponse) {} /// Create a new port from the specified driver - rpc CreatePort (CreatePortRequest) returns (CreatePortResponse) {} + rpc CreatePort(CreatePortRequest) returns (CreatePortResponse) {} /// Remove a port /// /// The port should not be being used by a port-related module. /// (e.g., PortInc, PortOut, QueueInc, QueueOut) - rpc DestroyPort (DestroyPortRequest) returns (EmptyResponse) {} + rpc DestroyPort(DestroyPortRequest) returns (EmptyResponse) {} /// Runtime-updatable configuration - rpc SetPortConf (SetPortConfRequest) returns (CommandResponse) {} - rpc GetPortConf (GetPortConfRequest) returns (GetPortConfResponse) {} + rpc SetPortConf(SetPortConfRequest) returns (CommandResponse) {} + rpc GetPortConf(GetPortConfRequest) returns (GetPortConfResponse) {} /// Collect port statistics /// /// At the moment, per-queue stats are not supported. - rpc GetPortStats (GetPortStatsRequest) returns (GetPortStatsResponse) {} + rpc GetPortStats(GetPortStatsRequest) returns (GetPortStatsResponse) {} /// Query link status - rpc GetLinkStatus (GetLinkStatusRequest) returns (GetLinkStatusResponse) {} + rpc GetLinkStatus(GetLinkStatusRequest) returns (GetLinkStatusResponse) {} // TODO: Add PortCommand, like ModuleCommand, which performs driver-specific // actions on a port. - // ------------------------------------------------------------------------- // Module // ------------------------------------------------------------------------- /// Enumerate all module types available - rpc ListMclass (EmptyRequest) returns (ListMclassResponse) {} + rpc ListMclass(EmptyRequest) returns (ListMclassResponse) {} /// Query detailed information of a module type - rpc GetMclassInfo (GetMclassInfoRequest) returns (GetMclassInfoResponse) {} + rpc GetMclassInfo(GetMclassInfoRequest) returns (GetMclassInfoResponse) {} /// Remove all modules. /// /// This RPC will always succeed (unless there is a running worker) /// /// NOTE: There should be no running worker to run this command. - rpc ResetModules (EmptyRequest) returns (EmptyResponse) {} + rpc ResetModules(EmptyRequest) returns (EmptyResponse) {} /// Enumerate all initialized modules - rpc ListModules (EmptyRequest) returns (ListModulesResponse) {} + rpc ListModules(EmptyRequest) returns (ListModulesResponse) {} /// Create a new module instance from the given module type /// /// NOTE: There should be no running worker to run this command. - rpc CreateModule (CreateModuleRequest) returns (CreateModuleResponse) {} + rpc CreateModule(CreateModuleRequest) returns (CreateModuleResponse) {} /// Destroy an exsting module /// @@ -254,10 +251,10 @@ service BESSControl { /// disconnected first. All tasks created by the module will also be destoyed. /// /// NOTE: There should be no running worker to run this command. - rpc DestroyModule (DestroyModuleRequest) returns (EmptyResponse) {} + rpc DestroyModule(DestroyModuleRequest) returns (EmptyResponse) {} /// Fetch detailed information of an module instance - rpc GetModuleInfo (GetModuleInfoRequest) returns (GetModuleInfoResponse) {} + rpc GetModuleInfo(GetModuleInfoRequest) returns (GetModuleInfoResponse) {} /// Connect two modules. /// @@ -266,7 +263,7 @@ service BESSControl { /// while the igate can be connected to multiple output gates. /// /// NOTE: There should be no running worker to run this command. - rpc ConnectModules (ConnectModulesRequest) returns (EmptyResponse) {} + rpc ConnectModules(ConnectModulesRequest) returns (EmptyResponse) {} /// Disconnect two modules. /// @@ -276,10 +273,10 @@ service BESSControl { /// to any input gate. /// /// NOTE: There should be no running worker to run this command. - rpc DisconnectModules (DisconnectModulesRequest) returns (EmptyResponse) {} + rpc DisconnectModules(DisconnectModulesRequest) returns (EmptyResponse) {} /// Dump various stats about BESS's packet pools - rpc DumpMempool (DumpMempoolRequest) returns (DumpMempoolResponse) {} + rpc DumpMempool(DumpMempoolRequest) returns (DumpMempoolResponse) {} /// Send a command to the specified module instance. /// @@ -289,31 +286,34 @@ service BESSControl { /// /// NOTE: Some commands cannot be used if there are running workers. /// For those commands you must pause all workers first. - rpc ModuleCommand (CommandRequest) returns (CommandResponse) {} + rpc ModuleCommand(CommandRequest) returns (CommandResponse) {} // ------------------------------------------------------------------------- // Gate hooks // ------------------------------------------------------------------------- /// Enumerate all gatehook types available - rpc ListGateHookClass (EmptyRequest) returns (ListGateHookClassResponse) {} + rpc ListGateHookClass(EmptyRequest) returns (ListGateHookClassResponse) {} /// Query detailed information of a gatehook type - rpc GetGateHookClassInfo (GetGateHookClassInfoRequest) returns (GetGateHookClassInfoResponse) {} + rpc GetGateHookClassInfo(GetGateHookClassInfoRequest) + returns (GetGateHookClassInfoResponse) {} /// Enable/Disable a gate hook. - rpc ConfigureGateHook (ConfigureGateHookRequest) returns (ConfigureGateHookResponse) {} + rpc ConfigureGateHook(ConfigureGateHookRequest) + returns (ConfigureGateHookResponse) {} /// Enumerate all gatehook installed - rpc ListGateHooks (EmptyRequest) returns (ListGateHooksResponse) {} + rpc ListGateHooks(EmptyRequest) returns (ListGateHooksResponse) {} /// Send command to gate hook instance. - rpc GateHookCommand (GateHookCommandRequest) returns (CommandResponse) {} + rpc GateHookCommand(GateHookCommandRequest) returns (CommandResponse) {} // ------------------------------------------------------------------------- // Resume hooks // ------------------------------------------------------------------------- /// Enable/Disable a resume hook. - rpc ConfigureResumeHook (ConfigureResumeHookRequest) returns (CommandResponse) {} + rpc ConfigureResumeHook(ConfigureResumeHookRequest) + returns (CommandResponse) {} } diff --git a/protobuf/tests/test_msg.proto b/protobuf/tests/test_msg.proto index e71517f937..280a497f94 100644 --- a/protobuf/tests/test_msg.proto +++ b/protobuf/tests/test_msg.proto @@ -33,7 +33,9 @@ syntax = "proto3"; package bess.pb.test; -message UnnestedDictMsg { map dict = 1; } +message UnnestedDictMsg { + map dict = 1; +} message NestedDictMsg { UnnestedDictMsg a = 1; diff --git a/protobuf/util_msg.proto b/protobuf/util_msg.proto index 84d80dc6e0..3688414a57 100644 --- a/protobuf/util_msg.proto +++ b/protobuf/util_msg.proto @@ -29,27 +29,28 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -syntax="proto3"; +syntax = "proto3"; /// This file contains some standard "types" for messages to/from BESS package bess.pb; option go_package = "github.com/omec-project/upf-epc/pfcpiface/bess_pb"; -/// The Field message represents one field in a packet -- either stored in metadata or in the packet body. +/// The Field message represents one field in a packet -- either stored in +/// metadata or in the packet body. message Field { oneof position { - string attr_name = 1; /// The metadata attribute assigned to store the data - uint32 offset = 2; /// The offset in bytes to store the data into + string attr_name = 1; /// The metadata attribute assigned to store the data + uint32 offset = 2; /// The offset in bytes to store the data into } - uint32 num_bytes = 3; /// The size of the data in bytes + uint32 num_bytes = 3; /// The size of the data in bytes } -/// The FieldData message encodes a value to insert into a packet; the value can be supplied as either an int or a bytestring. +/// The FieldData message encodes a value to insert into a packet; the value can +/// be supplied as either an int or a bytestring. message FieldData { oneof encoding { - bytes value_bin = 1; /// The value as a bytestring - uint64 value_int = 2; /// The value in integer format + bytes value_bin = 1; /// The value as a bytestring + uint64 value_int = 2; /// The value in integer format } } - diff --git a/sample_plugin/modules/sequential_update.cc b/sample_plugin/modules/sequential_update.cc index c41e46191b..b010101c5e 100644 --- a/sample_plugin/modules/sequential_update.cc +++ b/sample_plugin/modules/sequential_update.cc @@ -41,8 +41,8 @@ const Commands SequentialUpdate::cmds = { Command::THREAD_UNSAFE}, }; -CommandResponse -SequentialUpdate::Init(const sample::supdate::pb::SequentialUpdateArg &arg) { +CommandResponse SequentialUpdate::Init( + const sample::supdate::pb::SequentialUpdateArg &arg) { return CommandAdd(arg); } @@ -69,26 +69,26 @@ CommandResponse SequentialUpdate::CommandAdd( max = var.max(); switch (size) { - case 1: - mask = be32_t(0x00ffffff); - min = std::min(min, static_cast(0xff)); - max = std::min(max, static_cast(0xff)); - break; - - case 2: - mask = be32_t(0x0000ffff); - min = std::min(min, static_cast(0xffff)); - max = std::min(max, static_cast(0xffff)); - break; - - case 4: - mask = be32_t(0x00000000); - min = std::min(min, static_cast(0xffffffffu)); - max = std::min(max, static_cast(0xffffffffu)); - break; - - default: - return CommandFailure(EINVAL, "'size' must be 1, 2, or 4"); + case 1: + mask = be32_t(0x00ffffff); + min = std::min(min, static_cast(0xff)); + max = std::min(max, static_cast(0xff)); + break; + + case 2: + mask = be32_t(0x0000ffff); + min = std::min(min, static_cast(0xffff)); + max = std::min(max, static_cast(0xffff)); + break; + + case 4: + mask = be32_t(0x00000000); + min = std::min(min, static_cast(0xffffffffu)); + max = std::min(max, static_cast(0xffffffffu)); + break; + + default: + return CommandFailure(EINVAL, "'size' must be 1, 2, or 4"); } if (offset + size > SNBUF_DATA) { diff --git a/sample_plugin/modules/sequential_update.h b/sample_plugin/modules/sequential_update.h index 6203c25a6f..df72f9a446 100644 --- a/sample_plugin/modules/sequential_update.h +++ b/sample_plugin/modules/sequential_update.h @@ -41,7 +41,7 @@ static const size_t kMaxVariable = 16; class SequentialUpdate final : public Module { -public: + public: static const Commands cmds; SequentialUpdate() : Module(), num_vars_(), vars_() {} @@ -50,21 +50,21 @@ class SequentialUpdate final : public Module { void ProcessBatch(Context *ctx, bess::PacketBatch *batch) override; - CommandResponse - CommandAdd(const sample::supdate::pb::SequentialUpdateArg &arg); + CommandResponse CommandAdd( + const sample::supdate::pb::SequentialUpdateArg &arg); CommandResponse CommandClear(const bess::pb::EmptyArg &arg); -private: + private: size_t num_vars_; struct { - bess::utils::be32_t mask; // bits with 1 won't be updated + bess::utils::be32_t mask; // bits with 1 won't be updated uint32_t min; - uint32_t range; // max - min + 1 + uint32_t range; // max - min + 1 uint32_t cur; size_t offset; size_t bit_shift; } vars_[kMaxVariable]; }; -#endif // BESS_MODULES_SEQUENTIALUPDATE_H_ +#endif // BESS_MODULES_SEQUENTIALUPDATE_H_ diff --git a/sample_plugin/protobuf/supdate_msg.proto b/sample_plugin/protobuf/supdate_msg.proto index 82b2b5b9ad..b755c09f83 100644 --- a/sample_plugin/protobuf/supdate_msg.proto +++ b/sample_plugin/protobuf/supdate_msg.proto @@ -34,29 +34,29 @@ syntax = "proto3"; package sample.supdate.pb; /** - * The function `clear()` for SequentialUpdate takes no parameters and clears all - * state in the module. + * The function `clear()` for SequentialUpdate takes no parameters and clears + * all state in the module. */ -message SequentialUpdateCommandClearArg { -} +message SequentialUpdateCommandClearArg {} /** - * The SequentialUpdate module rewrites a specified field (`offset` and `size`) in a packet - * with a sequentially increased value from a specified min to max values. + * The SequentialUpdate module rewrites a specified field (`offset` and `size`) + * in a packet with a sequentially increased value from a specified min to max + * values. * * __Input Gates__: 1 * __Output Gates__: 1 */ message SequentialUpdateArg { /** - * SequentialUpdate's Field specifies where to rewrite, and what values to rewrite - * in each packet processed. + * SequentialUpdate's Field specifies where to rewrite, and what values to + * rewrite in each packet processed. */ message Field { - int64 offset = 1; /// Offset in bytes for where to rewrite. - uint64 size = 2; /// The number of bytes to write. - uint64 min = 3; /// The minimum value to insert into the packet. - uint64 max = 4; /// The maximum value to insert into the packet. + int64 offset = 1; /// Offset in bytes for where to rewrite. + uint64 size = 2; /// The number of bytes to write. + uint64 min = 3; /// The minimum value to insert into the packet. + uint64 max = 4; /// The maximum value to insert into the packet. } - repeated Field fields = 1; /// A list of SequentialUpdate Fields. + repeated Field fields = 1; /// A list of SequentialUpdate Fields. }