Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action for checking code format (C/C++ and Protobuf) #15

Merged
merged 7 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
30 changes: 30 additions & 0 deletions .github/workflows/clang-format-check.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
clang-format-version: '12'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Upstream-Name: bess
Upstream-Contact: OMEC Developers <[email protected]>
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion core/bessctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#ifndef BESS_BESSCTL_H_
#define BESS_BESSCTL_H_

#include <string>
#include <grpcpp/server_builder.h>
#include <string>

// gRPC server encapsulation. Usage:
// ApiServer server;
Expand Down
10 changes: 7 additions & 3 deletions core/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
#include <string>

#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 {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
};
Expand Down
44 changes: 21 additions & 23 deletions core/drivers/pmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::tuple<size_t, int> > registered_attrs_;
std::map<std::string, std::tuple<size_t, int>> registered_attrs_;
};

extern bess::metadata::Pipeline default_pipeline;
Expand Down
2 changes: 1 addition & 1 deletion core/modules/arp_responder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion core/modules/drr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
2 changes: 1 addition & 1 deletion core/modules/drr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/modules/ether_encap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions core/modules/exact_match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<cnt ;lcnt=lcnt+icnt )
{
icnt = ((cnt-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);
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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")
18 changes: 10 additions & 8 deletions core/modules/flowgen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<const char*>(tmpl_), MAX_TEMPLATE_SIZE) == 0) {
if (strnlen(reinterpret_cast<const char *>(tmpl_), MAX_TEMPLATE_SIZE) ==
0) {
return CommandFailure(EINVAL, "must specify 'template'");
}
} else {
Expand Down Expand Up @@ -436,7 +437,6 @@ bess::Packet *FlowGen::FillUdpPacket(struct flow *f) {
return pkt;
}


bess::Packet *FlowGen::FillTcpPacket(struct flow *f) {
bess::Packet *pkt;

Expand Down Expand Up @@ -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,
};
}

Expand Down
7 changes: 4 additions & 3 deletions core/modules/ip_encap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
Loading