Skip to content
Open
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
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build --jobs=2
build --local_resources=memory=4096
build --local_resources=cpu=2
build --sandbox_add_mount_pair=/opt/homebrew/opt/gmp
build --sandbox_add_mount_pair=/opt/homebrew/opt/libpcap
build --copt=-DNDEBUG
build --cxxopt=-DNDEBUG
build --copt=-Wno-implicit-function-declaration
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.5.0
35 changes: 35 additions & 0 deletions .github/workflows/ci-bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Bazel CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-test:
runs-on: ubuntu-22.04

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Bazel artifacts
uses: actions/cache@v4
with:
path: ~/.cache/bazel
key: bazel-${{ runner.os }}-${{ hashFiles('MODULE.bazel', '**/BUILD') }}
restore-keys: |
bazel-${{ runner.os }}-

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake pkg-config \
libgmp-dev libpcap-dev libboost-all-dev

- name: Build simple_switch_grpc with Bazel
run: bazelisk build //targets/simple_switch_grpc:simple_switch_grpc

- name: Run unit tests with Bazel
run: bazelisk test //targets/simple_switch_grpc:simple_switch_grpc_test --test_output=short
112 changes: 8 additions & 104 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,106 +1,10 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Bazel build outputs
bazel-*
MODULE.bazel.lock

# Precompiled Headers
*.gch
*.pch
# CMake build directory
build_cmake/

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Python byte code
*.pyc

build/
lib*

# Vim
*.swp

# Emacs
*~

*.pcap

# Tags
GPATH
GRTAGS
GSYMS
GTAGS

tools/bm_runtime/

# Files generated by autotools
.deps
Makefile
Makefile.in
configure
config.log
config.h
aclocal.m4
autom4te.cache/
compile
/config.h.in
config.status
depcomp
install-sh
missing
stamp-h1
targets/simple_router/simple_router
test-driver
.dirstamp
tests/test_*
!tests/test_*.cpp
!tests/testdata/*.pcap
*.log
*.trs
config.guess
config.sub
ltmain.sh
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
py-compile
.libs

*.ts

# gcov
*.gcno
*.gcda
*.gcov

# doxygen
doxygen-out

# thrift
gen-cpp
gen-py

VERSION-build

# dist archives
*.tar.gz

core
vgcore*
# Generated protobuf files
services/generated/
third_party/p4runtime/
54 changes: 54 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "bmv2_core",
srcs = glob(
[
"src/**/*.cpp",
"src/**/*.c",
"PI/src/*.cpp",
"targets/simple_switch/simple_switch.cpp",
"targets/simple_switch/primitives.cpp",
],
exclude = [
"src/bm_apps/**",
"src/bm_runtime/**",
"src/bf_lpm_trie/**",
"src/bm_sim/md5.c",
],
),
hdrs = glob([
"include/**/*.h",
"src/**/*.h",
"targets/**/*.h",
"third_party/spdlog/**/*.h",
"third_party/spdlog/**/*.cc",
"PI/**/*.h",
]),
includes = [
"include",
"third_party/spdlog",
"PI",
"src/BMI",
"src/bm_sim",
"targets/simple_switch",
"PI/src",
],
linkopts = [
"-L/opt/homebrew/opt/gmp/lib", "-lgmp",
"-L/opt/homebrew/opt/libpcap/lib", "-lpcap",
],
visibility = ["//visibility:public"],
deps = [
"@protobuf//:protobuf",
"//third_party/gmp:gmp",
"//third_party/jsoncpp:jsoncpp",
"@pi//:pi",
"@grpc//:grpc++",
"@boost.thread//:boost.thread",
"@boost.filesystem//:boost.filesystem",
"@boost.program_options//:boost.program_options",
"@boost.multiprecision//:boost.multiprecision",
"@boost.variant//:boost.variant",
],
)
23 changes: 23 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module(
name = "behavioral_model",
version = "1.0.0",
)

bazel_dep(name = "rules_cc", version = "0.2.4")
bazel_dep(name = "protobuf", version = "29.1")
bazel_dep(name = "googletest", version = "1.15.2")
bazel_dep(name = "grpc", version = "1.71.0")
bazel_dep(name = "jsoncpp", version = "1.9.5")
bazel_dep(name = "fmt", version = "10.1.1")
bazel_dep(name = "boost.thread", version = "1.83.0.bcr.4")
bazel_dep(name = "boost.filesystem", version = "1.83.0.bcr.4")
bazel_dep(name = "boost.program_options", version = "1.83.0.bcr.4")
bazel_dep(name = "boost.multiprecision", version = "1.83.0.bcr.4")
bazel_dep(name = "boost.variant", version = "1.83.0.bcr.4")
bazel_dep(name = "pi", version = "1.0.0")

git_override(
module_name = "pi",
remote = "https://github.com/kunal9812/PI",
commit = "cad594e",
)
2 changes: 2 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Intentionally empty.
# Enables bzlmod mode — Bazel will use MODULE.bazel instead of WORKSPACE.bazel.
4 changes: 4 additions & 0 deletions include/bm/bm_sim/dynamic_bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ inline int find_lowest_bit<uint64_t>(uint64_t v) {
find_lowest_bit<uint32_t>(sw);
}

template<>
inline int find_lowest_bit<unsigned long>(unsigned long v) {
return find_lowest_bit<uint64_t>(static_cast<uint64_t>(v));
}
class DynamicBitset {
public:
using Block = unsigned long; // NOLINT(runtime/int)
Expand Down
48 changes: 48 additions & 0 deletions include/bm/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef _INCLUDE_BM_CONFIG_H
#define _INCLUDE_BM_CONFIG_H 1

/* Generated statically for Bazel build */

/* Enable debugger */
/* #undef BM_DEBUG_ON */

/* Enable nanomsg event logger */
/* #undef BM_ELOG_ON */

/* Enable dynamic loading of modules */
/* #undef BM_ENABLE_MODULES */

#define BM_HAVE_ALGORITHM 1
#define BM_HAVE_ARRAY 1
#define BM_HAVE_CASSERT 1
#define BM_HAVE_CMATH 1
#define BM_HAVE_CSTDIO 1
#define BM_HAVE_CTIME 1
#define BM_HAVE_DLFCN_H 1
#define BM_HAVE_DLOPEN 1
#define BM_HAVE_QUEUE 1
#define BM_HAVE_STRING 1
#define BM_HAVE_SYS_STAT_H 1
#define BM_HAVE_SYS_TYPES_H 1
#define BM_HAVE_TUPLE 1
#define BM_HAVE_UNISTD_H 1
#define BM_HAVE_UNORDERED_MAP 1
#define BM_HAVE_UTILITY 1
#define BM_HAVE_VECTOR 1

/* Enable compile-time macro for debug logging */
/* #undef BM_LOG_DEBUG_ON */

/* Enable compile-time macro for trace logging */
/* #undef BM_LOG_TRACE_ON */

/* Enable Nanomsg support */
/* #undef BM_NANOMSG_ON */

/* Enable Thrift support */
/* #undef BM_THRIFT_ON */

/* Implement stacks as per P4_16 spec */
/* #undef BM_WP4_16_STACKS */

#endif /* _INCLUDE_BM_CONFIG_H */
19 changes: 19 additions & 0 deletions services/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "dataplane_interface_grpc",
srcs = [
"generated/p4/bm/dataplane_interface.pb.cc",
"generated/p4/bm/dataplane_interface.grpc.pb.cc",
],
hdrs = [
"generated/p4/bm/dataplane_interface.pb.h",
"generated/p4/bm/dataplane_interface.grpc.pb.h",
],
includes = ["generated"],
deps = [
"@protobuf//:protobuf",
"@grpc//:grpc++",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions services/p4/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# intentionally empty
18 changes: 18 additions & 0 deletions services/p4/bm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "dataplane_interface_grpc",
srcs = [
"//services:generated/p4/bm/dataplane_interface.pb.cc",
"//services:generated/p4/bm/dataplane_interface.grpc.pb.cc",
],
hdrs = [
"//services:generated/p4/bm/dataplane_interface.pb.h",
"//services:generated/p4/bm/dataplane_interface.grpc.pb.h",
],
deps = [
"@protobuf//:protobuf",
"@grpc//:grpc++",
],
visibility = ["//visibility:public"],
)
Loading
Loading