From 2d4b5bba62676f60e46a80e8f404db61a52bf5a7 Mon Sep 17 00:00:00 2001 From: Melvin Walls Date: Sat, 8 Aug 2020 14:22:37 -0700 Subject: [PATCH 1/2] bessctl: add init/cmd argument introspection --- core/bessctl.cc | 73 +++++++++++++++++++++++++++++++++++++---- core/commands.h | 7 +++- core/gate.h | 7 ++-- core/module.cc | 5 +-- core/module.h | 45 ++++++++++++++++--------- core/port.cc | 5 +-- core/port.h | 25 ++++++++++++-- core/port_test.cc | 6 ++-- protobuf/bess_msg.proto | 15 +++++++++ protobuf/service.proto | 5 +++ 10 files changed, 157 insertions(+), 36 deletions(-) diff --git a/core/bessctl.cc b/core/bessctl.cc index ee39e41aa..869e490fd 100644 --- a/core/bessctl.cc +++ b/core/bessctl.cc @@ -447,6 +447,55 @@ class BESSControlImpl final : public BESSControl::Service { return Status::OK; } + Status DumpDescriptors(ServerContext*, const EmptyRequest*, + DumpDescriptorsResponse* response) override { + std::lock_guard lock(mutex_); + + auto& module_descs = *response->mutable_modules(); + for (const auto & [ mclass, builder ] : + ModuleBuilder::all_module_builders()) { + if (const auto dp = builder.init_descriptor(); dp != nullptr) { + google::protobuf::DescriptorProto desc; + dp->CopyTo(&desc); + desc.set_name(dp->full_name()); + module_descs[mclass] = desc; + } + } + + auto& module_cmd_descs = *response->mutable_module_commands(); + for (const auto & [ mclass, builder ] : + ModuleBuilder::all_module_builders()) { + auto& cmds = *module_cmd_descs[mclass].mutable_commands(); + for (const auto & [ cmd, arg_type ] : builder.cmds()) { + if (std::holds_alternative( + arg_type)) { + const auto dp = + std::get(arg_type); + // to be safe + if (dp == nullptr) { + continue; + } + google::protobuf::DescriptorProto desc; + dp->CopyTo(&desc); + desc.set_name(dp->full_name()); + cmds[cmd] = desc; + } + } + } + + auto& port_descs = *response->mutable_ports(); + for (const auto & [ driver, builder ] : PortBuilder::all_port_builders()) { + if (const auto dp = builder.init_descriptor(); dp != nullptr) { + google::protobuf::DescriptorProto desc; + dp->CopyTo(&desc); + desc.set_name(dp->full_name()); + port_descs[driver] = desc; + } + } + + return Status::OK; + } + Status ResetAll(ServerContext* context, const EmptyRequest* request, EmptyResponse* response) override { std::lock_guard lock(mutex_); @@ -1472,9 +1521,15 @@ class BESSControlImpl final : public BESSControl::Service { response->set_name(cls->class_name()); response->set_help(cls->help_text()); - for (const auto& cmd : cls->cmds()) { - response->add_cmds(cmd.first); - response->add_cmd_args(cmd.second); + for (const auto & [ cmd, arg_type ] : cls->cmds()) { + response->add_cmds(cmd); + if (std::holds_alternative(arg_type)) { + response->add_cmd_args(std::get(arg_type)); + } else if (const auto dp = + std::get(arg_type); + dp != nullptr) { + response->add_cmd_args(dp->name()); + } } return Status::OK; } @@ -1750,9 +1805,15 @@ class BESSControlImpl final : public BESSControl::Service { response->set_name(cls->class_name()); response->set_help(cls->help_text()); - for (const auto& cmd : cls->cmds()) { - response->add_cmds(cmd.first); - response->add_cmd_args(cmd.second); + for (const auto & [ cmd, arg_type ] : cls->cmds()) { + response->add_cmds(cmd); + if (std::holds_alternative(arg_type)) { + response->add_cmd_args(std::get(arg_type)); + } else if (const auto dp = + std::get(arg_type); + dp != nullptr) { + response->add_cmd_args(dp->name()); + } } return Status::OK; } diff --git a/core/commands.h b/core/commands.h index d7df54a39..b8b181970 100644 --- a/core/commands.h +++ b/core/commands.h @@ -31,8 +31,11 @@ #ifndef BESS_COMMANDS_H_ #define BESS_COMMANDS_H_ +#include #include +#include + #include "message.h" // TODO(torek): refactor; instead of "module command" and "gate command" @@ -50,6 +53,8 @@ using module_cmd_func_t = pb_func_t; using gate_hook_cmd_func_t = pb_func_t; +using CommandArgType = + std::variant; // Describes a single command that can be issued to a module // or gate hook (according to cmd_func_t). @@ -58,7 +63,7 @@ struct GenericCommand { enum ThreadSafety { THREAD_UNSAFE = 0, THREAD_SAFE = 1 }; std::string cmd; - std::string arg_type; + CommandArgType arg_type; cmd_func_t func; // If set to THREAD_SAFE, workers don't need to be paused in order to run diff --git a/core/gate.h b/core/gate.h index cff9c0992..130307708 100644 --- a/core/gate.h +++ b/core/gate.h @@ -164,10 +164,11 @@ class GateHookBuilder { const std::string &name_template() const { return name_template_; } const std::string &help_text() const { return help_text_; } - const std::vector> cmds() const { - std::vector> ret; - for (auto &cmd : cmds_) + const std::vector> cmds() const { + std::vector> ret; + for (auto &cmd : cmds_) { ret.push_back(std::make_pair(cmd.cmd, cmd.arg_type)); + } return ret; } diff --git a/core/module.cc b/core/module.cc index f9b290cf6..a153ab29e 100644 --- a/core/module.cc +++ b/core/module.cc @@ -47,11 +47,12 @@ bool ModuleBuilder::RegisterModuleClass( std::function module_generator, const std::string &class_name, const std::string &name_template, const std::string &help_text, const gate_idx_t igates, const gate_idx_t ogates, const Commands &cmds, - module_init_func_t init_func) { + module_init_func_t init_func, const Descriptor *init_descriptor) { all_module_builders_holder().emplace( std::piecewise_construct, std::forward_as_tuple(class_name), std::forward_as_tuple(module_generator, class_name, name_template, - help_text, igates, ogates, cmds, init_func)); + help_text, igates, ogates, cmds, init_func, + init_descriptor)); return true; } diff --git a/core/module.h b/core/module.h index 6bb24020e..1bafbbdfd 100644 --- a/core/module.h +++ b/core/module.h @@ -41,6 +41,9 @@ #include #include +#include +#include + #include "commands.h" #include "event.h" #include "gate.h" @@ -50,6 +53,7 @@ #include "worker.h" using bess::gate_idx_t; +using google::protobuf::Descriptor; #define INVALID_TASK_ID ((task_id_t)-1) #define MAX_NUMA_NODE 16 @@ -74,8 +78,6 @@ struct Context { gate_idx_t gate_without_hook[bess::PacketBatch::kMaxBurst]; }; -using module_cmd_func_t = - pb_func_t; using module_init_func_t = pb_func_t; @@ -101,6 +103,12 @@ static inline module_init_func_t MODULE_INIT_FUNC( }; } +template +static inline const Descriptor *MODULE_INIT_DESC( + CommandResponse (M::*)(const T &)) { + return T::descriptor(); +} + class Module; // A class for managing modules of 'a particular type'. @@ -112,7 +120,8 @@ class ModuleBuilder { const std::string &name_template, const std::string &help_text, const gate_idx_t igates, const gate_idx_t ogates, const Commands &cmds, std::function - init_func) + init_func, + const Descriptor *init_descriptor) : module_generator_(module_generator), num_igates_(igates), num_ogates_(ogates), @@ -120,15 +129,14 @@ class ModuleBuilder { name_template_(name_template), help_text_(help_text), cmds_(cmds), - init_func_(init_func) {} - - static bool RegisterModuleClass(std::function module_generator, - const std::string &class_name, - const std::string &name_template, - const std::string &help_text, - const gate_idx_t igates, - const gate_idx_t ogates, const Commands &cmds, - module_init_func_t init_func); + init_func_(init_func), + init_descriptor_(init_descriptor) {} + + static bool RegisterModuleClass( + std::function module_generator, const std::string &class_name, + const std::string &name_template, const std::string &help_text, + const gate_idx_t igates, const gate_idx_t ogates, const Commands &cmds, + module_init_func_t init_func, const Descriptor *init_descriptor); static bool DeregisterModuleClass(const std::string &class_name); static std::map &all_module_builders_holder( @@ -146,10 +154,11 @@ class ModuleBuilder { const std::string &name_template() const { return name_template_; } const std::string &help_text() const { return help_text_; } - const std::vector> cmds() const { - std::vector> ret; - for (auto &cmd : cmds_) + const std::vector> cmds() const { + std::vector> ret; + for (auto &cmd : cmds_) { ret.push_back(std::make_pair(cmd.cmd, cmd.arg_type)); + } return ret; } @@ -158,6 +167,8 @@ class ModuleBuilder { CommandResponse RunInit(Module *m, const google::protobuf::Any &arg) const; + const Descriptor *init_descriptor() const { return init_descriptor_; } + private: const std::function module_generator_; @@ -169,6 +180,7 @@ class ModuleBuilder { const std::string help_text_; const Commands cmds_; const module_init_func_t init_func_; + const Descriptor *init_descriptor_; }; class Task; @@ -723,7 +735,8 @@ static inline void set_attr(Module *m, int attr_id, bess::Packet *pkt, T val) { ModuleBuilder::RegisterModuleClass( \ std::function([]() { return new _MOD(); }), #_MOD, \ _NAME_TEMPLATE, _HELP, _MOD::kNumIGates, _MOD::kNumOGates, \ - _MOD::cmds, MODULE_INIT_FUNC(&_MOD::Init)); \ + _MOD::cmds, MODULE_INIT_FUNC(&_MOD::Init), \ + MODULE_INIT_DESC(&_MOD::Init)); \ } \ ~_MOD##_class() { ModuleBuilder::DeregisterModuleClass(#_MOD); } \ }; diff --git a/core/port.cc b/core/port.cc index 347ebf81f..a2c1c89a5 100644 --- a/core/port.cc +++ b/core/port.cc @@ -128,11 +128,12 @@ bool PortBuilder::RegisterPortClass( std::function port_generator, const std::string &class_name, const std::string &name_template, const std::string &help_text, std::function - init_func) { + init_func, + const Descriptor *init_descriptor) { all_port_builders_holder().emplace( std::piecewise_construct, std::forward_as_tuple(class_name), std::forward_as_tuple(port_generator, class_name, name_template, - help_text, init_func)); + help_text, init_func, init_descriptor)); return true; } diff --git a/core/port.h b/core/port.h index 193d13105..1ff3735ab 100644 --- a/core/port.h +++ b/core/port.h @@ -41,6 +41,9 @@ #include #include +#include +#include + #include "message.h" #include "module.h" #include "packet.h" @@ -51,6 +54,8 @@ typedef uint8_t queue_t; +using google::protobuf::Descriptor; + #define MAX_QUEUES_PER_DIR 128 /* [0, 31] (for each RX/TX) */ #define DRIVER_FLAG_SELF_INC_STATS 0x0001 @@ -87,6 +92,12 @@ static inline port_init_func_t PORT_INIT_FUNC( }; } +template +static inline const Descriptor *PORT_INIT_DESC( + CommandResponse (P::*)(const T &)) { + return T::descriptor(); +} + // A class to generate new Port objects of specific types. Each instance can // generate Port objects of a specific class and specification. Represents a // "driver" of that port. @@ -98,12 +109,14 @@ class PortBuilder { PortBuilder(std::function port_generator, const std::string &class_name, const std::string &name_template, - const std::string &help_text, port_init_func_t init_func) + const std::string &help_text, port_init_func_t init_func, + const Descriptor *init_descriptor) : port_generator_(port_generator), class_name_(class_name), name_template_(name_template), help_text_(help_text), init_func_(init_func), + init_descriptor_(init_descriptor), initialized_(false) {} // Returns a new Port object of the type represented by this PortBuilder @@ -135,7 +148,8 @@ class PortBuilder { const std::string &class_name, const std::string &name_template, const std::string &help_text, - port_init_func_t init_func); + port_init_func_t init_func, + const Descriptor *init_descriptor); static const std::map &all_port_builders(); @@ -150,6 +164,8 @@ class PortBuilder { return init_func_(p, arg); } + const Descriptor *init_descriptor() const { return init_descriptor_; } + private: // To avoid the static initialization ordering problem, this pseudo-getter // function contains the real static all_port_builders class variable and @@ -171,6 +187,8 @@ class PortBuilder { std::string help_text_; // Help text about this port type. port_init_func_t init_func_; // Initialization function of this Port class + const Descriptor + *init_descriptor_; // Descriptor for this Port's initialization arguments bool initialized_; // Has this port class been initialized via // InitPortClass()? @@ -337,6 +355,7 @@ class Port { #define ADD_DRIVER(_DRIVER, _NAME_TEMPLATE, _HELP) \ bool __driver__##_DRIVER = PortBuilder::RegisterPortClass( \ std::function([]() { return new _DRIVER(); }), #_DRIVER, \ - _NAME_TEMPLATE, _HELP, PORT_INIT_FUNC(&_DRIVER::Init)); + _NAME_TEMPLATE, _HELP, PORT_INIT_FUNC(&_DRIVER::Init), \ + PORT_INIT_DESC(&_DRIVER::Init)); #endif // BESS_PORT_H_ diff --git a/core/port_test.cc b/core/port_test.cc index 1a4d57bab..04e05d920 100644 --- a/core/port_test.cc +++ b/core/port_test.cc @@ -286,9 +286,9 @@ TEST_F(PortTest, InitDrivers) { // Checks that when we register a portclass, the global table of PortBuilders // contains it. TEST_F(PortBuilderTest, RegisterPortClassDirectCall) { - PortBuilder::RegisterPortClass([]() { return new DummyPort(); }, "DummyPort", - "dummy_port", "dummy help", - PORT_INIT_FUNC(&DummyPort::Init)); + PortBuilder::RegisterPortClass( + []() { return new DummyPort(); }, "DummyPort", "dummy_port", "dummy help", + PORT_INIT_FUNC(&DummyPort::Init), PORT_INIT_DESC(&DummyPort::Init)); ASSERT_EQ(1, PortBuilder::all_port_builders().size()); ASSERT_EQ(1, PortBuilder::all_port_builders().count("DummyPort")); diff --git a/protobuf/bess_msg.proto b/protobuf/bess_msg.proto index 9e1b79a33..cbd7df795 100644 --- a/protobuf/bess_msg.proto +++ b/protobuf/bess_msg.proto @@ -31,6 +31,7 @@ syntax = "proto3"; import "google/protobuf/any.proto"; +import "google/protobuf/descriptor.proto"; import "error.proto"; /// - "timestamp" represents the current time in seconds since the Epoch. @@ -621,3 +622,17 @@ message PauseWorkerRequest { message ResumeWorkerRequest { int64 wid = 1; /// ID of the worker to be resumed } + +// ------------------------------------------------------------------------- +// Introspection commands +// ------------------------------------------------------------------------- +message DumpDescriptorsResponse { + message CommandDescriptors { + map commands = 1; + } + + Error error = 1; + map modules = 2; + map module_commands = 3; + map ports = 4; +} diff --git a/protobuf/service.proto b/protobuf/service.proto index ae1aba053..b4d2c84b7 100644 --- a/protobuf/service.proto +++ b/protobuf/service.proto @@ -312,4 +312,9 @@ service BESSControl { /// Enable/Disable a resume hook. rpc ConfigureResumeHook (ConfigureResumeHookRequest) returns (CommandResponse) {} + + // ------------------------------------------------------------------------- + // Introspection + // ------------------------------------------------------------------------- + rpc DumpDescriptors (EmptyRequest) returns (DumpDescriptorsResponse) {} } From af1b6fdcdd59f8c7ea045e7a0765ed022f79519c Mon Sep 17 00:00:00 2001 From: Melvin Walls Date: Wed, 12 Aug 2020 15:54:39 -0700 Subject: [PATCH 2/2] modules: include cmd desciptors also run clang-format --- core/modules/acl.cc | 6 ++--- core/modules/arp_responder.cc | 4 ++-- core/modules/bpf.cc | 14 ++++++------ core/modules/drr.cc | 8 ++++--- core/modules/dump.cc | 4 ++-- core/modules/exact_match.cc | 21 +++++++++-------- core/modules/flowgen.cc | 20 ++++++++-------- core/modules/hash_lb.cc | 4 ++-- core/modules/ip_checksum.cc | 9 ++++---- core/modules/ip_lookup.cc | 42 ++++++++++++++++------------------ core/modules/l2_forward.cc | 19 +++++++-------- core/modules/l4_checksum.cc | 18 ++++++++------- core/modules/measure.cc | 6 ++--- core/modules/mpls_pop.cc | 2 +- core/modules/nat.cc | 24 ++++++++++--------- core/modules/port_inc.cc | 6 ++--- core/modules/port_out.cc | 4 ++-- core/modules/queue.cc | 14 ++++++------ core/modules/queue_inc.cc | 6 ++--- core/modules/random_split.cc | 4 ++-- core/modules/random_update.cc | 8 +++---- core/modules/replicate.cc | 2 +- core/modules/rewrite.cc | 8 +++---- core/modules/round_robin.cc | 4 ++-- core/modules/set_metadata.cc | 2 +- core/modules/source.cc | 4 ++-- core/modules/static_nat.cc | 8 +++---- core/modules/update.cc | 8 +++---- core/modules/url_filter.cc | 41 ++++++++++++++++++--------------- core/modules/vlan_pop.cc | 2 +- core/modules/vlan_push.cc | 13 ++++++----- core/modules/vlan_split.cc | 2 +- core/modules/vxlan_decap.cc | 2 +- core/modules/wildcard_match.cc | 20 ++++++++-------- core/modules/worker_split.cc | 4 ++-- 35 files changed, 189 insertions(+), 174 deletions(-) diff --git a/core/modules/acl.cc b/core/modules/acl.cc index 88e20b693..cbed5e1db 100644 --- a/core/modules/acl.cc +++ b/core/modules/acl.cc @@ -34,10 +34,10 @@ #include "../utils/udp.h" const Commands ACL::cmds = { - {"add", "ACLArg", MODULE_CMD_FUNC(&ACL::CommandAdd), + {"add", bess::pb::ACLArg::descriptor(), MODULE_CMD_FUNC(&ACL::CommandAdd), Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&ACL::CommandClear), - Command::THREAD_UNSAFE}}; + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&ACL::CommandClear), Command::THREAD_UNSAFE}}; CommandResponse ACL::Init(const bess::pb::ACLArg &arg) { for (const auto &rule : arg.rules()) { diff --git a/core/modules/arp_responder.cc b/core/modules/arp_responder.cc index 58267eadb..67c8eae81 100644 --- a/core/modules/arp_responder.cc +++ b/core/modules/arp_responder.cc @@ -36,8 +36,8 @@ using bess::utils::Arp; using bess::utils::be16_t; const Commands ArpResponder::cmds = { - {"add", "ArpResponderArg", MODULE_CMD_FUNC(&ArpResponder::CommandAdd), - Command::THREAD_UNSAFE}}; + {"add", bess::pb::ArpResponderArg::descriptor(), + MODULE_CMD_FUNC(&ArpResponder::CommandAdd), Command::THREAD_UNSAFE}}; CommandResponse ArpResponder::CommandAdd(const bess::pb::ArpResponderArg &arg) { be32_t ip_addr; diff --git a/core/modules/bpf.cc b/core/modules/bpf.cc index ac579106c..f8d04ea36 100644 --- a/core/modules/bpf.cc +++ b/core/modules/bpf.cc @@ -49,14 +49,14 @@ #define SNAPLEN 0xffff const Commands BPF::cmds = { - {"add", "BPFArg", MODULE_CMD_FUNC(&BPF::CommandAdd), + {"add", bess::pb::BPFArg::descriptor(), MODULE_CMD_FUNC(&BPF::CommandAdd), Command::THREAD_UNSAFE}, - {"delete", "BPFArg", MODULE_CMD_FUNC(&BPF::CommandDelete), - Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&BPF::CommandClear), - Command::THREAD_UNSAFE}, - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&BPF::GetInitialArg), - Command::THREAD_SAFE}}; + {"delete", bess::pb::BPFArg::descriptor(), + MODULE_CMD_FUNC(&BPF::CommandDelete), Command::THREAD_UNSAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&BPF::CommandClear), Command::THREAD_UNSAFE}, + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&BPF::GetInitialArg), Command::THREAD_SAFE}}; CommandResponse BPF::Init(const bess::pb::BPFArg &arg) { return CommandAdd(arg); diff --git a/core/modules/drr.cc b/core/modules/drr.cc index 840183e5e..e9fea7e65 100644 --- a/core/modules/drr.cc +++ b/core/modules/drr.cc @@ -51,9 +51,9 @@ uint32_t RoundToPowerTwo(uint32_t v) { } const Commands DRR::cmds = { - {"set_quantum_size", "DRRQuantumArg", + {"set_quantum_size", bess::pb::DRRQuantumArg::descriptor(), MODULE_CMD_FUNC(&DRR::CommandQuantumSize), Command::THREAD_UNSAFE}, - {"set_max_flow_queue_size", "DRRMaxFlowQueueSizeArg", + {"set_max_flow_queue_size", bess::pb::DRRMaxFlowQueueSizeArg::descriptor(), MODULE_CMD_FUNC(&DRR::CommandMaxFlowQueueSize), Command::THREAD_UNSAFE}}; DRR::DRR() @@ -152,7 +152,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/dump.cc b/core/modules/dump.cc index 28a7a13be..0c00e411f 100644 --- a/core/modules/dump.cc +++ b/core/modules/dump.cc @@ -40,8 +40,8 @@ static const uint64_t DEFAULT_INTERVAL_NS = 1 * NS_PER_SEC; /* 1 sec */ const Commands Dump::cmds = { - {"set_interval", "DumpArg", MODULE_CMD_FUNC(&Dump::CommandSetInterval), - Command::THREAD_UNSAFE}, + {"set_interval", bess::pb::DumpArg::descriptor(), + MODULE_CMD_FUNC(&Dump::CommandSetInterval), Command::THREAD_UNSAFE}, }; CommandResponse Dump::Init(const bess::pb::DumpArg &arg) { diff --git a/core/modules/exact_match.cc b/core/modules/exact_match.cc index 072a0333d..efff4a0c1 100644 --- a/core/modules/exact_match.cc +++ b/core/modules/exact_match.cc @@ -43,19 +43,20 @@ static inline int is_valid_gate(gate_idx_t gate) { } const Commands ExactMatch::cmds = { - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&ExactMatch::GetInitialArg), - Command::THREAD_SAFE}, - {"get_runtime_config", "EmptyArg", + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&ExactMatch::GetInitialArg), Command::THREAD_SAFE}, + {"get_runtime_config", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&ExactMatch::GetRuntimeConfig), Command::THREAD_SAFE}, - {"set_runtime_config", "ExactMatchConfig", + {"set_runtime_config", bess::pb::ExactMatchConfig::descriptor(), MODULE_CMD_FUNC(&ExactMatch::SetRuntimeConfig), Command::THREAD_UNSAFE}, - {"add", "ExactMatchCommandAddArg", MODULE_CMD_FUNC(&ExactMatch::CommandAdd), - Command::THREAD_UNSAFE}, - {"delete", "ExactMatchCommandDeleteArg", + {"add", bess::pb::ExactMatchCommandAddArg::descriptor(), + MODULE_CMD_FUNC(&ExactMatch::CommandAdd), Command::THREAD_UNSAFE}, + {"delete", bess::pb::ExactMatchCommandDeleteArg::descriptor(), MODULE_CMD_FUNC(&ExactMatch::CommandDelete), Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&ExactMatch::CommandClear), - Command::THREAD_UNSAFE}, - {"set_default_gate", "ExactMatchCommandSetDefaultGateArg", + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&ExactMatch::CommandClear), Command::THREAD_UNSAFE}, + {"set_default_gate", + bess::pb::ExactMatchCommandSetDefaultGateArg::descriptor(), MODULE_CMD_FUNC(&ExactMatch::CommandSetDefaultGate), Command::THREAD_SAFE}}; diff --git a/core/modules/flowgen.cc b/core/modules/flowgen.cc index 8793e1ce8..1d7e117e8 100644 --- a/core/modules/flowgen.cc +++ b/core/modules/flowgen.cc @@ -39,8 +39,8 @@ #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::Ethernet; using bess::utils::Ipv4; @@ -53,9 +53,9 @@ using bess::utils::be32_t; const double PARETO_TAIL_LIMIT = 0.99; const Commands FlowGen::cmds = { - {"update", "FlowGenArg", MODULE_CMD_FUNC(&FlowGen::CommandUpdate), - Command::THREAD_UNSAFE}, - {"set_burst", "FlowGenCommandSetBurstArg", + {"update", bess::pb::FlowGenArg::descriptor(), + MODULE_CMD_FUNC(&FlowGen::CommandUpdate), Command::THREAD_UNSAFE}, + {"set_burst", bess::pb::FlowGenCommandSetBurstArg::descriptor(), MODULE_CMD_FUNC(&FlowGen::CommandSetBurst), Command::THREAD_SAFE}}; /* find x from CDF of pareto distribution from given y in [0.0, 1.0) */ @@ -181,10 +181,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 { @@ -434,7 +435,6 @@ bess::Packet *FlowGen::FillUdpPacket(struct flow *f) { return pkt; } - bess::Packet *FlowGen::FillTcpPacket(struct flow *f) { bess::Packet *pkt; @@ -532,7 +532,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/hash_lb.cc b/core/modules/hash_lb.cc index c31ac9696..20bf850cf 100644 --- a/core/modules/hash_lb.cc +++ b/core/modules/hash_lb.cc @@ -73,9 +73,9 @@ static inline int is_valid_gate(gate_idx_t gate) { } const Commands HashLB::cmds = { - {"set_mode", "HashLBCommandSetModeArg", + {"set_mode", bess::pb::HashLBCommandSetModeArg::descriptor(), MODULE_CMD_FUNC(&HashLB::CommandSetMode), Command::THREAD_UNSAFE}, - {"set_gates", "HashLBCommandSetGatesArg", + {"set_gates", bess::pb::HashLBCommandSetGatesArg::descriptor(), MODULE_CMD_FUNC(&HashLB::CommandSetGates), Command::THREAD_UNSAFE}}; CommandResponse HashLB::CommandSetMode( diff --git a/core/modules/ip_checksum.cc b/core/modules/ip_checksum.cc index ecaba24d7..18bf33963 100644 --- a/core/modules/ip_checksum.cc +++ b/core/modules/ip_checksum.cc @@ -37,10 +37,10 @@ enum { FORWARD_GATE = 0, FAIL_GATE }; void IPChecksum::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { - using bess::utils::be16_t; using bess::utils::Ethernet; using bess::utils::Ipv4; using bess::utils::Vlan; + using bess::utils::be16_t; int cnt = batch->cnt(); @@ -56,8 +56,8 @@ void IPChecksum::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { data = qinq + 1; ether_type = qinq->ether_type; if (ether_type != be16_t(Ethernet::Type::kVlan)) { - EmitPacket(ctx, batch->pkts()[i], FORWARD_GATE); - continue; + EmitPacket(ctx, batch->pkts()[i], FORWARD_GATE); + continue; } } @@ -75,7 +75,8 @@ void IPChecksum::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { } if (verify_) { - EmitPacket(ctx, batch->pkts()[i], (VerifyIpv4Checksum(*ip)) ? FORWARD_GATE : FAIL_GATE); + EmitPacket(ctx, batch->pkts()[i], + (VerifyIpv4Checksum(*ip)) ? FORWARD_GATE : FAIL_GATE); } else { ip->checksum = CalculateIpv4Checksum(*ip); EmitPacket(ctx, batch->pkts()[i], FORWARD_GATE); diff --git a/core/modules/ip_lookup.cc b/core/modules/ip_lookup.cc index 3c8b11571..51d1c40cc 100644 --- a/core/modules/ip_lookup.cc +++ b/core/modules/ip_lookup.cc @@ -46,12 +46,12 @@ 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}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&IPLookup::CommandClear), - Command::THREAD_UNSAFE}}; + {"add", bess::pb::IPLookupCommandAddArg::descriptor(), + MODULE_CMD_FUNC(&IPLookup::CommandAdd), Command::THREAD_UNSAFE}, + {"delete", bess::pb::IPLookupCommandDeleteArg::descriptor(), + MODULE_CMD_FUNC(&IPLookup::CommandDelete), Command::THREAD_UNSAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&IPLookup::CommandClear), Command::THREAD_UNSAFE}}; CommandResponse IPLookup::Init(const bess::pb::IPLookupArg &arg) { struct rte_lpm_config conf = { @@ -150,8 +150,8 @@ void IPLookup::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { } } -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; @@ -160,25 +160,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); } @@ -190,7 +188,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)) { @@ -216,7 +214,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/l2_forward.cc b/core/modules/l2_forward.cc index 546462513..b684a8879 100644 --- a/core/modules/l2_forward.cc +++ b/core/modules/l2_forward.cc @@ -69,7 +69,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; @@ -360,8 +360,8 @@ static uint64_t l2_addr_to_u64(char *addr) { return a | (b << 32); } -/******************************************************************************/ -// TODO(barath): Move this test code elsewhere. + /******************************************************************************/ + // TODO(barath): Move this test code elsewhere. #include #include @@ -542,15 +542,16 @@ static int parse_mac_addr(const char *str, char *addr) { /******************************************************************************/ const Commands L2Forward::cmds = { - {"add", "L2ForwardCommandAddArg", MODULE_CMD_FUNC(&L2Forward::CommandAdd), - Command::THREAD_UNSAFE}, - {"delete", "L2ForwardCommandDeleteArg", + {"add", bess::pb::L2ForwardCommandAddArg::descriptor(), + MODULE_CMD_FUNC(&L2Forward::CommandAdd), Command::THREAD_UNSAFE}, + {"delete", bess::pb::L2ForwardCommandDeleteArg::descriptor(), MODULE_CMD_FUNC(&L2Forward::CommandDelete), Command::THREAD_UNSAFE}, - {"set_default_gate", "L2ForwardCommandSetDefaultGateArg", + {"set_default_gate", + bess::pb::L2ForwardCommandSetDefaultGateArg::descriptor(), MODULE_CMD_FUNC(&L2Forward::CommandSetDefaultGate), Command::THREAD_SAFE}, - {"lookup", "L2ForwardCommandLookupArg", + {"lookup", bess::pb::L2ForwardCommandLookupArg::descriptor(), MODULE_CMD_FUNC(&L2Forward::CommandLookup), Command::THREAD_SAFE}, - {"populate", "L2ForwardCommandPopulateArg", + {"populate", bess::pb::L2ForwardCommandPopulateArg::descriptor(), MODULE_CMD_FUNC(&L2Forward::CommandPopulate), Command::THREAD_UNSAFE}, }; diff --git a/core/modules/l4_checksum.cc b/core/modules/l4_checksum.cc index 3ad1f23d6..7715a0975 100644 --- a/core/modules/l4_checksum.cc +++ b/core/modules/l4_checksum.cc @@ -39,11 +39,11 @@ enum { FORWARD_GATE = 0, FAIL_GATE }; void L4Checksum::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { - using bess::utils::be16_t; using bess::utils::Ethernet; using bess::utils::Ipv4; using bess::utils::Tcp; using bess::utils::Udp; + using bess::utils::be16_t; int cnt = batch->cnt(); @@ -63,21 +63,23 @@ void L4Checksum::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { Udp *udp = reinterpret_cast(reinterpret_cast(ip) + ip_bytes); if (verify_) { - EmitPacket(ctx, batch->pkts()[i], - (VerifyIpv4UdpChecksum(*ip, *udp)) ? FORWARD_GATE : FAIL_GATE); + EmitPacket( + ctx, batch->pkts()[i], + (VerifyIpv4UdpChecksum(*ip, *udp)) ? FORWARD_GATE : FAIL_GATE); } else { - udp->checksum = CalculateIpv4UdpChecksum(*ip, *udp); - EmitPacket(ctx, batch->pkts()[i], FORWARD_GATE); + udp->checksum = CalculateIpv4UdpChecksum(*ip, *udp); + EmitPacket(ctx, batch->pkts()[i], FORWARD_GATE); } } else if (ip->protocol == Ipv4::Proto::kTcp) { size_t ip_bytes = (ip->header_length) << 2; Tcp *tcp = reinterpret_cast(reinterpret_cast(ip) + ip_bytes); if (verify_) - EmitPacket(ctx, batch->pkts()[i], - (VerifyIpv4TcpChecksum(*ip, *tcp)) ? FORWARD_GATE : FAIL_GATE); + EmitPacket( + ctx, batch->pkts()[i], + (VerifyIpv4TcpChecksum(*ip, *tcp)) ? FORWARD_GATE : FAIL_GATE); else - tcp->checksum = CalculateIpv4TcpChecksum(*ip, *tcp); + tcp->checksum = CalculateIpv4TcpChecksum(*ip, *tcp); } } } diff --git a/core/modules/measure.cc b/core/modules/measure.cc index e2b6dcebb..733e15bc5 100644 --- a/core/modules/measure.cc +++ b/core/modules/measure.cc @@ -54,10 +54,10 @@ static bool IsTimestamped(bess::Packet *pkt, size_t offset, uint64_t *time) { } const Commands Measure::cmds = { - {"get_summary", "MeasureCommandGetSummaryArg", + {"get_summary", bess::pb::MeasureCommandGetSummaryArg::descriptor(), MODULE_CMD_FUNC(&Measure::CommandGetSummary), Command::THREAD_SAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&Measure::CommandClear), - Command::THREAD_SAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&Measure::CommandClear), Command::THREAD_SAFE}, }; CommandResponse Measure::Init(const bess::pb::MeasureArg &arg) { diff --git a/core/modules/mpls_pop.cc b/core/modules/mpls_pop.cc index 9055ed462..a15b1a5f5 100644 --- a/core/modules/mpls_pop.cc +++ b/core/modules/mpls_pop.cc @@ -36,7 +36,7 @@ using bess::utils::Ethernet; using bess::utils::Mpls; -const Commands MPLSPop::cmds = {{"set", "MplsPopArg", +const Commands MPLSPop::cmds = {{"set", bess::pb::MplsPopArg::descriptor(), MODULE_CMD_FUNC(&MPLSPop::CommandSet), Command::THREAD_UNSAFE}}; diff --git a/core/modules/nat.cc b/core/modules/nat.cc index 70c830458..d6fd14f34 100644 --- a/core/modules/nat.cc +++ b/core/modules/nat.cc @@ -45,21 +45,21 @@ 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), - Command::THREAD_SAFE}, - {"get_runtime_config", "EmptyArg", MODULE_CMD_FUNC(&NAT::GetRuntimeConfig), - Command::THREAD_SAFE}, - {"set_runtime_config", "EmptyArg", MODULE_CMD_FUNC(&NAT::SetRuntimeConfig), - Command::THREAD_SAFE}}; + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&NAT::GetInitialArg), Command::THREAD_SAFE}, + {"get_runtime_config", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&NAT::GetRuntimeConfig), Command::THREAD_SAFE}, + {"set_runtime_config", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&NAT::SetRuntimeConfig), Command::THREAD_SAFE}}; // TODO(torek): move this to set/get runtime config CommandResponse NAT::Init(const bess::pb::NATArg &arg) { @@ -88,7 +88,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/port_inc.cc b/core/modules/port_inc.cc index acdb6b1b6..c4b79ab1f 100644 --- a/core/modules/port_inc.cc +++ b/core/modules/port_inc.cc @@ -32,10 +32,10 @@ #include "../utils/format.h" const Commands PortInc::cmds = { - {"set_burst", "PortIncCommandSetBurstArg", + {"set_burst", bess::pb::PortIncCommandSetBurstArg::descriptor(), MODULE_CMD_FUNC(&PortInc::CommandSetBurst), Command::THREAD_SAFE}, - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&PortInc::GetInitialArg), - Command::THREAD_SAFE}, + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&PortInc::GetInitialArg), Command::THREAD_SAFE}, }; CommandResponse PortInc::Init(const bess::pb::PortIncArg &arg) { diff --git a/core/modules/port_out.cc b/core/modules/port_out.cc index d798a71a3..6784f499e 100644 --- a/core/modules/port_out.cc +++ b/core/modules/port_out.cc @@ -32,8 +32,8 @@ #include "../utils/format.h" const Commands PortOut::cmds = { - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&PortOut::GetInitialArg), - Command::THREAD_SAFE}, + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&PortOut::GetInitialArg), Command::THREAD_SAFE}, }; CommandResponse PortOut::Init(const bess::pb::PortOutArg &arg) { diff --git a/core/modules/queue.cc b/core/modules/queue.cc index 2bd806550..9e92cb00e 100644 --- a/core/modules/queue.cc +++ b/core/modules/queue.cc @@ -37,17 +37,17 @@ #define DEFAULT_QUEUE_SIZE 1024 const Commands Queue::cmds = { - {"set_burst", "QueueCommandSetBurstArg", + {"set_burst", bess::pb::QueueCommandSetBurstArg::descriptor(), MODULE_CMD_FUNC(&Queue::CommandSetBurst), Command::THREAD_SAFE}, - {"set_size", "QueueCommandSetSizeArg", + {"set_size", bess::pb::QueueCommandSetSizeArg::descriptor(), MODULE_CMD_FUNC(&Queue::CommandSetSize), Command::THREAD_UNSAFE}, - {"get_status", "QueueCommandGetStatusArg", + {"get_status", bess::pb::QueueCommandGetStatusArg::descriptor(), MODULE_CMD_FUNC(&Queue::CommandGetStatus), Command::THREAD_SAFE}, - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&Queue::GetInitialArg), - Command::THREAD_SAFE}, - {"get_runtime_config", "EmptyArg", + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&Queue::GetInitialArg), Command::THREAD_SAFE}, + {"get_runtime_config", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&Queue::GetRuntimeConfig), Command::THREAD_SAFE}, - {"set_runtime_config", "QueueArg", + {"set_runtime_config", bess::pb::QueueArg::descriptor(), MODULE_CMD_FUNC(&Queue::SetRuntimeConfig), Command::THREAD_UNSAFE}}; int Queue::Resize(int slots) { diff --git a/core/modules/queue_inc.cc b/core/modules/queue_inc.cc index f857bb5df..00545d16e 100644 --- a/core/modules/queue_inc.cc +++ b/core/modules/queue_inc.cc @@ -33,9 +33,9 @@ #include "../port.h" #include "../utils/format.h" -const Commands QueueInc::cmds = {{"set_burst", "QueueIncCommandSetBurstArg", - MODULE_CMD_FUNC(&QueueInc::CommandSetBurst), - Command::THREAD_SAFE}}; +const Commands QueueInc::cmds = { + {"set_burst", bess::pb::QueueIncCommandSetBurstArg::descriptor(), + MODULE_CMD_FUNC(&QueueInc::CommandSetBurst), Command::THREAD_SAFE}}; CommandResponse QueueInc::Init(const bess::pb::QueueIncArg &arg) { const char *port_name; diff --git a/core/modules/random_split.cc b/core/modules/random_split.cc index 559e58171..236e7616d 100644 --- a/core/modules/random_split.cc +++ b/core/modules/random_split.cc @@ -38,9 +38,9 @@ static inline bool is_valid_gate(gate_idx_t gate) { } const Commands RandomSplit::cmds = { - {"set_droprate", "RandomSplitCommandSetDroprateArg", + {"set_droprate", bess::pb::RandomSplitCommandSetDroprateArg::descriptor(), MODULE_CMD_FUNC(&RandomSplit::CommandSetDroprate), Command::THREAD_UNSAFE}, - {"set_gates", "RandomSplitCommandSetGatesArg", + {"set_gates", bess::pb::RandomSplitCommandSetGatesArg::descriptor(), MODULE_CMD_FUNC(&RandomSplit::CommandSetGates), Command::THREAD_UNSAFE}}; CommandResponse RandomSplit::Init(const bess::pb::RandomSplitArg &arg) { diff --git a/core/modules/random_update.cc b/core/modules/random_update.cc index 29a91a9b1..df09f47a3 100644 --- a/core/modules/random_update.cc +++ b/core/modules/random_update.cc @@ -33,10 +33,10 @@ using bess::utils::be32_t; const Commands RandomUpdate::cmds = { - {"add", "RandomUpdateArg", MODULE_CMD_FUNC(&RandomUpdate::CommandAdd), - Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&RandomUpdate::CommandClear), - Command::THREAD_UNSAFE}, + {"add", bess::pb::RandomUpdateArg::descriptor(), + MODULE_CMD_FUNC(&RandomUpdate::CommandAdd), Command::THREAD_UNSAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&RandomUpdate::CommandClear), Command::THREAD_UNSAFE}, }; CommandResponse RandomUpdate::Init(const bess::pb::RandomUpdateArg &arg) { diff --git a/core/modules/replicate.cc b/core/modules/replicate.cc index ccf3e8c0a..cbaf8fbe2 100644 --- a/core/modules/replicate.cc +++ b/core/modules/replicate.cc @@ -30,7 +30,7 @@ #include "replicate.h" const Commands Replicate::cmds = { - {"set_gates", "ReplicateCommandSetGatesArg", + {"set_gates", bess::pb::ReplicateCommandSetGatesArg::descriptor(), MODULE_CMD_FUNC(&Replicate::CommandSetGates), Command::THREAD_UNSAFE}, }; diff --git a/core/modules/rewrite.cc b/core/modules/rewrite.cc index 95463c865..65dd1de27 100644 --- a/core/modules/rewrite.cc +++ b/core/modules/rewrite.cc @@ -35,10 +35,10 @@ #include "../utils/copy.h" const Commands Rewrite::cmds = { - {"add", "RewriteArg", MODULE_CMD_FUNC(&Rewrite::CommandAdd), - Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&Rewrite::CommandClear), - Command::THREAD_UNSAFE}, + {"add", bess::pb::RewriteArg::descriptor(), + MODULE_CMD_FUNC(&Rewrite::CommandAdd), Command::THREAD_UNSAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&Rewrite::CommandClear), Command::THREAD_UNSAFE}, }; CommandResponse Rewrite::Init(const bess::pb::RewriteArg &arg) { diff --git a/core/modules/round_robin.cc b/core/modules/round_robin.cc index 670583215..abcf00683 100644 --- a/core/modules/round_robin.cc +++ b/core/modules/round_robin.cc @@ -31,9 +31,9 @@ #include "round_robin.h" const Commands RoundRobin::cmds = { - {"set_mode", "RoundRobinCommandSetModeArg", + {"set_mode", bess::pb::RoundRobinCommandSetModeArg::descriptor(), MODULE_CMD_FUNC(&RoundRobin::CommandSetMode), Command::THREAD_UNSAFE}, - {"set_gates", "RoundRobinCommandSetGatesArg", + {"set_gates", bess::pb::RoundRobinCommandSetGatesArg::descriptor(), MODULE_CMD_FUNC(&RoundRobin::CommandSetGates), Command::THREAD_UNSAFE}, }; diff --git a/core/modules/set_metadata.cc b/core/modules/set_metadata.cc index d3441c1d8..e1b98694e 100644 --- a/core/modules/set_metadata.cc +++ b/core/modules/set_metadata.cc @@ -40,7 +40,7 @@ using bess::metadata::mt_offset_t; const Commands SetMetadata::cmds = { - {"get_initial_arg", "EmptyArg", + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&SetMetadata::GetInitialArg), Command::THREAD_SAFE}, }; diff --git a/core/modules/source.cc b/core/modules/source.cc index db99dbc20..0eb23e098 100644 --- a/core/modules/source.cc +++ b/core/modules/source.cc @@ -31,9 +31,9 @@ #include "source.h" const Commands Source::cmds = { - {"set_pkt_size", "SourceCommandSetPktSizeArg", + {"set_pkt_size", bess::pb::SourceCommandSetPktSizeArg::descriptor(), MODULE_CMD_FUNC(&Source::CommandSetPktSize), Command::THREAD_SAFE}, - {"set_burst", "SourceCommandSetBurstArg", + {"set_burst", bess::pb::SourceCommandSetBurstArg::descriptor(), MODULE_CMD_FUNC(&Source::CommandSetBurst), Command::THREAD_SAFE}, }; diff --git a/core/modules/static_nat.cc b/core/modules/static_nat.cc index 5f5ef7859..9fb01b1d6 100644 --- a/core/modules/static_nat.cc +++ b/core/modules/static_nat.cc @@ -36,11 +36,11 @@ #include "../utils/udp.h" const Commands StaticNAT::cmds = { - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&StaticNAT::GetInitialArg), - Command::THREAD_SAFE}, - {"get_runtime_config", "EmptyArg", + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&StaticNAT::GetInitialArg), Command::THREAD_SAFE}, + {"get_runtime_config", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&StaticNAT::GetRuntimeConfig), Command::THREAD_SAFE}, - {"set_runtime_config", "EmptyArg", + {"set_runtime_config", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&StaticNAT::SetRuntimeConfig), Command::THREAD_SAFE}}; CommandResponse StaticNAT::Init(const bess::pb::StaticNATArg &arg) { diff --git a/core/modules/update.cc b/core/modules/update.cc index 42d4e2d54..c5a6c97f0 100644 --- a/core/modules/update.cc +++ b/core/modules/update.cc @@ -33,10 +33,10 @@ #include "../utils/endian.h" const Commands Update::cmds = { - {"add", "UpdateArg", MODULE_CMD_FUNC(&Update::CommandAdd), - Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&Update::CommandClear), - Command::THREAD_UNSAFE}, + {"add", bess::pb::UpdateArg::descriptor(), + MODULE_CMD_FUNC(&Update::CommandAdd), Command::THREAD_UNSAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&Update::CommandClear), Command::THREAD_UNSAFE}, }; CommandResponse Update::Init(const bess::pb::UpdateArg &arg) { diff --git a/core/modules/url_filter.cc b/core/modules/url_filter.cc index 3d72e555b..eb7052071 100644 --- a/core/modules/url_filter.cc +++ b/core/modules/url_filter.cc @@ -46,16 +46,16 @@ using bess::utils::be16_t; const uint64_t TIME_OUT_NS = 10ull * 1000 * 1000 * 1000; // 10 seconds const Commands UrlFilter::cmds = { - {"get_initial_arg", "EmptyArg", MODULE_CMD_FUNC(&UrlFilter::GetInitialArg), - Command::THREAD_SAFE}, - {"get_runtime_config", "EmptyArg", + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&UrlFilter::GetInitialArg), Command::THREAD_SAFE}, + {"get_runtime_config", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&UrlFilter::GetRuntimeConfig), Command::THREAD_SAFE}, - {"set_runtime_config", "UrlFilterConfig", + {"set_runtime_config", bess::pb::UrlFilterConfig::descriptor(), MODULE_CMD_FUNC(&UrlFilter::SetRuntimeConfig), Command::THREAD_UNSAFE}, - {"add", "UrlFilterArg", MODULE_CMD_FUNC(&UrlFilter::CommandAdd), - Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&UrlFilter::CommandClear), - Command::THREAD_UNSAFE}}; + {"add", bess::pb::UrlFilterArg::descriptor(), + MODULE_CMD_FUNC(&UrlFilter::CommandAdd), Command::THREAD_UNSAFE}, + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&UrlFilter::CommandClear), Command::THREAD_UNSAFE}}; // Template for generating TCP packets without data struct[[gnu::packed]] PacketTemplate { @@ -360,23 +360,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/vlan_pop.cc b/core/modules/vlan_pop.cc index 5df318ad8..7baafaa30 100644 --- a/core/modules/vlan_pop.cc +++ b/core/modules/vlan_pop.cc @@ -33,8 +33,8 @@ #include "../utils/ether.h" void VLANPop::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { - using bess::utils::be16_t; using bess::utils::Ethernet; + using bess::utils::be16_t; int cnt = batch->cnt(); diff --git a/core/modules/vlan_push.cc b/core/modules/vlan_push.cc index d5c492160..3fb89265e 100644 --- a/core/modules/vlan_push.cc +++ b/core/modules/vlan_push.cc @@ -36,13 +36,13 @@ #include "../utils/format.h" #include "../utils/simd.h" +using bess::utils::Ethernet; using bess::utils::be16_t; using bess::utils::be32_t; -using bess::utils::Ethernet; const Commands VLANPush::cmds = { - {"set_tci", "VLANPushArg", MODULE_CMD_FUNC(&VLANPush::CommandSetTci), - Command::THREAD_UNSAFE}, + {"set_tci", bess::pb::VLANPushArg::descriptor(), + MODULE_CMD_FUNC(&VLANPush::CommandSetTci), Command::THREAD_UNSAFE}, }; CommandResponse VLANPush::Init(const bess::pb::VLANPushArg &arg) { @@ -74,9 +74,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/vlan_split.cc b/core/modules/vlan_split.cc index 24eb9d1fa..e21fcfd22 100644 --- a/core/modules/vlan_split.cc +++ b/core/modules/vlan_split.cc @@ -33,8 +33,8 @@ #include "../utils/ether.h" void VLANSplit::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { - using bess::utils::be16_t; using bess::utils::Ethernet; + using bess::utils::be16_t; int cnt = batch->cnt(); diff --git a/core/modules/vxlan_decap.cc b/core/modules/vxlan_decap.cc index fcdded78f..fce120887 100644 --- a/core/modules/vxlan_decap.cc +++ b/core/modules/vxlan_decap.cc @@ -56,11 +56,11 @@ CommandResponse VXLANDecap::Init( } void VXLANDecap::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { - using bess::utils::be32_t; using bess::utils::Ethernet; using bess::utils::Ipv4; using bess::utils::Udp; using bess::utils::Vxlan; + using bess::utils::be32_t; int cnt = batch->cnt(); diff --git a/core/modules/wildcard_match.cc b/core/modules/wildcard_match.cc index 1b7bfeb6c..68a8cd969 100644 --- a/core/modules/wildcard_match.cc +++ b/core/modules/wildcard_match.cc @@ -56,19 +56,20 @@ static inline int is_valid_gate(gate_idx_t gate) { } const Commands WildcardMatch::cmds = { - {"get_initial_arg", "EmptyArg", + {"get_initial_arg", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&WildcardMatch::GetInitialArg), Command::THREAD_SAFE}, - {"get_runtime_config", "EmptyArg", + {"get_runtime_config", bess::pb::EmptyArg::descriptor(), MODULE_CMD_FUNC(&WildcardMatch::GetRuntimeConfig), Command::THREAD_SAFE}, - {"set_runtime_config", "WildcardMatchConfig", + {"set_runtime_config", bess::pb::WildcardMatchConfig::descriptor(), MODULE_CMD_FUNC(&WildcardMatch::SetRuntimeConfig), Command::THREAD_UNSAFE}, - {"add", "WildcardMatchCommandAddArg", + {"add", bess::pb::WildcardMatchCommandAddArg::descriptor(), MODULE_CMD_FUNC(&WildcardMatch::CommandAdd), Command::THREAD_UNSAFE}, - {"delete", "WildcardMatchCommandDeleteArg", + {"delete", bess::pb::WildcardMatchCommandDeleteArg::descriptor(), MODULE_CMD_FUNC(&WildcardMatch::CommandDelete), Command::THREAD_UNSAFE}, - {"clear", "EmptyArg", MODULE_CMD_FUNC(&WildcardMatch::CommandClear), - Command::THREAD_UNSAFE}, - {"set_default_gate", "WildcardMatchCommandSetDefaultGateArg", + {"clear", bess::pb::EmptyArg::descriptor(), + MODULE_CMD_FUNC(&WildcardMatch::CommandClear), Command::THREAD_UNSAFE}, + {"set_default_gate", + bess::pb::WildcardMatchCommandSetDefaultGateArg::descriptor(), MODULE_CMD_FUNC(&WildcardMatch::CommandSetDefaultGate), Command::THREAD_SAFE}}; @@ -136,7 +137,8 @@ CommandResponse WildcardMatch::Init(const bess::pb::WildcardMatchArg &arg) { inline gate_idx_t WildcardMatch::LookupEntry(const wm_hkey_t &key, gate_idx_t def_gate) { struct WmData result = { - .priority = INT_MIN, .ogate = def_gate, + .priority = INT_MIN, + .ogate = def_gate, }; for (auto &tuple : tuples_) { diff --git a/core/modules/worker_split.cc b/core/modules/worker_split.cc index bb1d9c261..3177a13f5 100644 --- a/core/modules/worker_split.cc +++ b/core/modules/worker_split.cc @@ -31,8 +31,8 @@ #include "worker_split.h" const Commands WorkerSplit::cmds = { - {"reset", "WorkerSplitArg", MODULE_CMD_FUNC(&WorkerSplit::CommandReset), - Command::THREAD_UNSAFE}}; + {"reset", bess::pb::WorkerSplitArg::descriptor(), + MODULE_CMD_FUNC(&WorkerSplit::CommandReset), Command::THREAD_UNSAFE}}; CommandResponse WorkerSplit::Init(const bess::pb::WorkerSplitArg &arg) { return CommandReset(arg);