-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skeleton implementation for PNA (#1255)
- Loading branch information
1 parent
89691ff
commit f0f82bf
Showing
15 changed files
with
831 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/pna_nic | ||
pnic_runtime | ||
pna_nic_CLI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.