Skip to content

Commit

Permalink
Add skeleton implementation for PNA (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
rupesh-chiluka-marvell authored Jun 12, 2024
1 parent 89691ff commit f0f82bf
Show file tree
Hide file tree
Showing 15 changed files with 831 additions and 1 deletion.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ AC_CONFIG_FILES([Makefile
targets/simple_switch/tests/CLI_tests/Makefile
targets/psa_switch/Makefile
targets/psa_switch/tests/Makefile
targets/pna_nic/Makefile
tests/Makefile
tests/stress_tests/Makefile
tools/Makefile
Expand Down
2 changes: 1 addition & 1 deletion targets/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ if COND_PI
MAYBE_SECONDARY_TARGETS += simple_switch_grpc
endif

SUBDIRS = simple_switch psa_switch $(MAYBE_SECONDARY_TARGETS)
SUBDIRS = simple_switch psa_switch pna_nic $(MAYBE_SECONDARY_TARGETS)
3 changes: 3 additions & 0 deletions targets/pna_nic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/pna_nic
pnic_runtime
pna_nic_CLI
2 changes: 2 additions & 0 deletions targets/pna_nic/CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# in case the src dir is used as the build dir
exclude_files=gen-cpp
135 changes: 135 additions & 0 deletions targets/pna_nic/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
THRIFT_IDL = $(srcdir)/thrift/pna_nic.thrift

noinst_LTLIBRARIES = libpnanic.la

libpnanic_la_SOURCES = \
pna_nic.cpp pna_nic.h \
primitives.cpp

libpnanic_la_LIBADD = \
$(top_builddir)/src/bm_sim/libbmsim.la \
$(top_builddir)/src/bf_lpm_trie/libbflpmtrie.la \
$(top_builddir)/src/BMI/libbmi.la \
$(top_builddir)/third_party/jsoncpp/libjson.la \
-lboost_system $(THRIFT_LIB) -lboost_program_options -lboost_filesystem

if COND_THRIFT

pna_nic_thrift_py_files = \
gen-py/pnic_runtime/constants.py \
gen-py/pnic_runtime/__init__.py \
gen-py/pnic_runtime/PnaNic.py \
gen-py/pnic_runtime/ttypes.py
pna_nic_thrift_files = \
gen-cpp/bm/pna_nic_constants.cpp \
gen-cpp/bm/pna_nic_constants.h \
gen-cpp/bm/PnaNic.cpp \
gen-cpp/bm/PnaNic.h \
gen-cpp/bm/pna_nic_types.cpp \
gen-cpp/bm/pna_nic_types.h

BUILT_SOURCES = $(pna_nic_thrift_files) $(pna_nic_thrift_py_files)

pnicpydir = $(pythondir)/pnic_runtime
nodist_pnicpy_PYTHON = $(pna_nic_thrift_py_files)

python_PYTHON = pnic_CLI.py

# See
# http://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Installation-Directory-Variables.html
edit = sed \
-e 's|@pythondir[@]|$(pythondir)|g'

pna_nic_CLI: Makefile
rm -f $@ $@.tmp
$(edit) $(srcdir)/$@.in >$@.tmp
chmod +x $@.tmp
chmod a-w $@.tmp
mv $@.tmp $@

pna_nic_CLI: pna_nic_CLI.in

EXTRA_DIST = \
pna_nic_CLI.in \
pnic_CLI

bin_SCRIPTS = \
pna_nic_CLI

AM_CPPFLAGS += \
-I$(srcdir)/thrift/src/ \
-I$(builddir)/gen-cpp

libpnanic_la_SOURCES += thrift/src/PnaNic_server.cpp

bin_PROGRAMS = pna_nic

pna_nic_LDADD = \
$(top_builddir)/src/bm_runtime/libbmruntime.la \
$(top_builddir)/thrift_src/libruntimestubs.la \
libpnanic.la \
libpnanic_thrift.la

pna_nic_SOURCES = main.cpp

lib_LTLIBRARIES = libpnanic_thrift.la

nodist_libpnanic_thrift_la_SOURCES = \
$(pna_nic_thrift_files)

# See http://www.gnu.org/software/automake/manual/html_node/Multiple-Outputs.html

EXTRA_DIST += $(THRIFT_IDL)

# We copy the generated Python code to srcdir/ if we have permissions (i.e. not
# for 'make distcheck'). This is to ensure we can run the CLI easily. Maybe I
# will think of a better solution later.
thrift_files.ts: $(THRIFT_IDL)
@rm -f thrift_files.tmp
@touch thrift_files.tmp
@mkdir -p $(builddir)/gen-cpp/bm
$(THRIFT) -out $(builddir)/gen-cpp/bm --gen cpp -r $(THRIFT_IDL)
$(THRIFT) -o $(builddir) --gen py -r $(THRIFT_IDL)
touch $(pna_nic_thrift_files)
if mkdir $(srcdir)/pnic_runtime.test 2>/dev/null; then \
rm -rf $(srcdir)/pnic_runtime/; \
cp -r $(builddir)/gen-py/pnic_runtime/ $(srcdir)/; \
rm -rf $(srcdir)/pnic_runtime.test; else :; \
fi
@mv -f thrift_files.tmp $@

$(BUILT_SOURCES): thrift_files.ts
## Recover from the removal of $@
@if test -f $@; then :; else \
trap 'rm -rf thrift_files.lock thrift_files.ts' 1 2 13 15; \
## mkdir is a simple test-and-set
if mkdir thrift_files.lock 2>/dev/null; then \
## This code is being executed by the first process.
rm -f thrift_files.ts; \
$(MAKE) $(AM_MAKEFLAGS) thrift_files.ts; \
result=$$?; rm -rf thrift_files.lock; exit $$result; \
else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
while test -d thrift_files.lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
test -f thrift_files.ts; \
fi; \
fi

nodist_pkginclude_HEADERS = \
gen-cpp/bm/pna_nic_constants.h \
gen-cpp/bm/PnaNic.h \
gen-cpp/bm/pna_nic_types.h

CLEANFILES = $(BUILT_SOURCES) \
thrift_files.ts \
gen-cpp/bm/PnaNic_server.skeleton.cpp \
$(bin_SCRIPTS)

# I used to do a rm on gen-cpp, but it was removing a .deps directory, instead I
# am adding the skeleton file to CLEANFILES
clean-local:
rm -rf gen-py

endif # COND_THRIFT
66 changes: 66 additions & 0 deletions targets/pna_nic/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Copyright 2024 Marvell Technology, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Rupesh Chiluka ([email protected])
*
*/

/* Nic instance */

#include <bm/PnaNic.h>
#include <bm/bm_runtime/bm_runtime.h>
#include <bm/bm_sim/target_parser.h>

#include "pna_nic.h"

namespace {
bm::pna::PnaNic *pna_nic;
bm::TargetParserBasic *pna_nic_parser;
} // namespace

namespace pnic_runtime {
shared_ptr<PnaNicIf> get_handler(bm::pna::PnaNic *nic);
} // namespace pnic_runtime

int
main(int argc, char* argv[]) {
using bm::pna::PnaNic;
pna_nic = new PnaNic();
pna_nic_parser = new bm::TargetParserBasic();
pna_nic_parser->add_flag_option("enable-swap",
"enable JSON swapping at runtime");
int status = pna_nic->init_from_command_line_options(
argc, argv, pna_nic_parser);
if (status != 0) std::exit(status);

bool enable_swap_flag = false;
if (pna_nic_parser->get_flag_option("enable-swap", &enable_swap_flag)
!= bm::TargetParserBasic::ReturnCode::SUCCESS)
std::exit(1);
if (enable_swap_flag) pna_nic->enable_config_swap();

int thrift_port = pna_nic->get_runtime_port();
bm_runtime::start_server(pna_nic, thrift_port);
using ::pnic_runtime::PnaNicIf;
using ::pnic_runtime::PnaNicProcessor;
bm_runtime::add_service<PnaNicIf, PnaNicProcessor>(
"pna_nic", pnic_runtime::get_handler(pna_nic));
pna_nic->start_and_return();

while (true) std::this_thread::sleep_for(std::chrono::seconds(100));

return 0;
}
Loading

0 comments on commit f0f82bf

Please sign in to comment.