VPP-1504: Remove JVPP
As part of JVPP migration this removes JVPP completely from VPP. Change-Id: I6b74e7961aa474ae471e63fe43a624cd9fc3659b Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
This commit is contained in:

committed by
Damjan Marion

parent
aed6180194
commit
4e633e1043
15
Makefile
15
Makefile
@ -68,21 +68,17 @@ DEB_DEPENDS += python-all python-dev python-virtualenv python-pip libffi6 check
|
||||
DEB_DEPENDS += libboost-all-dev libffi-dev python3-ply libmbedtls-dev
|
||||
DEB_DEPENDS += cmake ninja-build uuid-dev
|
||||
ifeq ($(OS_VERSION_ID),14.04)
|
||||
DEB_DEPENDS += openjdk-8-jdk-headless
|
||||
DEB_DEPENDS += libssl-dev
|
||||
else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-8)
|
||||
DEB_DEPENDS += openjdk-8-jdk-headless
|
||||
DEB_DEPENDS += libssl-dev
|
||||
APT_ARGS = -t jessie-backports
|
||||
else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-9)
|
||||
DEB_DEPENDS += default-jdk-headless
|
||||
DEB_DEPENDS += libssl1.0-dev
|
||||
else
|
||||
DEB_DEPENDS += default-jdk-headless
|
||||
DEB_DEPENDS += libssl-dev
|
||||
endif
|
||||
|
||||
RPM_DEPENDS = redhat-lsb glibc-static java-1.8.0-openjdk-devel
|
||||
RPM_DEPENDS = redhat-lsb glibc-static
|
||||
RPM_DEPENDS += apr-devel
|
||||
RPM_DEPENDS += numactl-devel
|
||||
RPM_DEPENDS += check check-devel
|
||||
@ -119,7 +115,7 @@ SUSE_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/
|
||||
RPM_SUSE_BUILDTOOLS_DEPS = autoconf automake ccache check-devel chrpath
|
||||
RPM_SUSE_BUILDTOOLS_DEPS += clang cmake indent libtool make ninja python3-ply
|
||||
|
||||
RPM_SUSE_DEVEL_DEPS = glibc-devel-static java-1_8_0-openjdk-devel libnuma-devel
|
||||
RPM_SUSE_DEVEL_DEPS = glibc-devel-static libnuma-devel
|
||||
RPM_SUSE_DEVEL_DEPS += libopenssl-devel openssl-devel mbedtls-devel libuuid-devel
|
||||
|
||||
RPM_SUSE_PYTHON_DEPS = python-devel python3-devel python-pip python3-pip
|
||||
@ -285,7 +281,6 @@ install-dep:
|
||||
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
|
||||
ifeq ($(OS_VERSION_ID),14.04)
|
||||
@sudo -E apt-get $(CONFIRM) $(FORCE) install software-properties-common
|
||||
@sudo -E add-apt-repository ppa:openjdk-r/ppa $(CONFIRM)
|
||||
endif
|
||||
ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-8)
|
||||
@grep -q jessie-backports /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null \
|
||||
@ -404,12 +399,12 @@ test-debug:
|
||||
$(call test,vpp,vpp_debug,test)
|
||||
|
||||
test-all:
|
||||
$(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=vpp TAG=vpp vom-install japi-install,)
|
||||
$(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=vpp TAG=vpp vom-install,)
|
||||
$(eval EXTENDED_TESTS=yes)
|
||||
$(call test,vpp,vpp,test)
|
||||
|
||||
test-all-debug:
|
||||
$(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=vpp TAG=vpp_debug vom-install japi-install,)
|
||||
$(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=vpp TAG=vpp_debug vom-install,)
|
||||
$(eval EXTENDED_TESTS=yes)
|
||||
$(call test,vpp,vpp_debug,test)
|
||||
|
||||
@ -581,8 +576,6 @@ verify: install-dep $(BR)/.deps.ok install-ext-deps
|
||||
@make -C build-root PLATFORM=vpp TAG=vpp sample-plugin-install
|
||||
$(call banner,"Building libmemif")
|
||||
@make -C build-root PLATFORM=vpp TAG=vpp libmemif-install
|
||||
$(call banner,"Building JAPI")
|
||||
@make -C build-root PLATFORM=vpp TAG=vpp japi-install
|
||||
$(call banner,"Building VOM")
|
||||
@make -C build-root PLATFORM=vpp TAG=vpp vom-install
|
||||
$(call banner,"Building $(PKG) packages")
|
||||
|
@ -1,44 +0,0 @@
|
||||
# Copyright (c) 2017-2018 Cisco and/or its affiliates.
|
||||
# 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.
|
||||
|
||||
japi_configure_depend = vpp-install
|
||||
japi_source = extras
|
||||
japi_configure_subdir = japi
|
||||
|
||||
ifneq ($(shell which cmake3),)
|
||||
CMAKE?=cmake3
|
||||
else
|
||||
CMAKE?=cmake
|
||||
endif
|
||||
|
||||
japi_cmake_args ?=
|
||||
japi_cmake_args += -DCMAKE_INSTALL_PREFIX:PATH=$(PACKAGE_INSTALL_DIR)
|
||||
japi_cmake_args += -DCMAKE_C_FLAGS="$($(TAG)_TAG_CFLAGS)"
|
||||
japi_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)"
|
||||
japi_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp"
|
||||
ifeq ("$(V)","1")
|
||||
japi_cmake_args += -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
|
||||
endif
|
||||
|
||||
#Use devtoolset on centos 7
|
||||
ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
|
||||
japi_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
|
||||
endif
|
||||
|
||||
japi_configure = \
|
||||
cd $(PACKAGE_BUILD_DIR) && \
|
||||
$(CMAKE) -G Ninja $(japi_cmake_args) $(call find_source_fn,$(PACKAGE_SOURCE))$(PACKAGE_SUBDIR)
|
||||
|
||||
japi_build = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- $(MAKE_PARALLEL_FLAGS)
|
||||
|
||||
japi_install = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- install
|
@ -19,7 +19,7 @@ arm32_uses_dpdk = yes
|
||||
arm32_uses_openssl = no
|
||||
|
||||
arm32_root_packages = vpp vlib vlib-api vnet svm vpp-api-test \
|
||||
jvpp gmod
|
||||
gmod
|
||||
|
||||
vlib_configure_args_arm32 = --with-pre-data=128
|
||||
vnet_configure_args_arm32 = --with-dpdk --without-libssl
|
||||
|
@ -20,7 +20,7 @@ ifeq ($(TARGET_PLATFORM),thunderx)
|
||||
vpp_dpdk_target = arm64-thunderx-linuxapp-gcc
|
||||
endif
|
||||
|
||||
vpp_root_packages = vpp vom japi
|
||||
vpp_root_packages = vpp vom
|
||||
|
||||
vpp_debug_TAG_CFLAGS = -g -O0 -DCLIB_DEBUG -DFORTIFY_SOURCE=2 \
|
||||
-fstack-protector-all -fPIC -Werror
|
||||
|
@ -159,9 +159,9 @@ Once the packages are built they can be found in the build-root directory.
|
||||
If the packages are built correctly, then this should be the corresponding output:
|
||||
|
||||
vpp_18.07-rc0~456-gb361076_amd64.deb vpp-dbg_18.07-rc0~456-gb361076_amd64.deb
|
||||
vpp-api-java_18.07-rc0~456-gb361076_amd64.deb vpp-dev_18.07-rc0~456-gb361076_amd64.deb
|
||||
vpp-api-lua_18.07-rc0~456-gb361076_amd64.deb vpp-lib_18.07-rc0~456-gb361076_amd64.deb
|
||||
vpp-api-python_18.07-rc0~456-gb361076_amd64.deb vpp-plugins_18.07-rc0~456-gb361076_amd64.deb
|
||||
vpp-dev_18.07-rc0~456-gb361076_amd64.deb vpp-api-lua_18.07-rc0~456-gb361076_amd64.deb
|
||||
vpp-lib_18.07-rc0~456-gb361076_amd64.deb vpp-api-python_18.07-rc0~456-gb361076_amd64.deb
|
||||
vpp-plugins_18.07-rc0~456-gb361076_amd64.deb
|
||||
|
||||
Finally, the created packages can be installed using the following commands. Install
|
||||
the package that correspnds to OS that VPP will be running on:
|
||||
|
@ -159,7 +159,7 @@ Here are the contents of .../build-data/platforms/vpp.mk:
|
||||
# Uncoment to enable building unit tests
|
||||
# vpp_enable_tests = yes
|
||||
|
||||
vpp_root_packages = vpp vom japi
|
||||
vpp_root_packages = vpp vom
|
||||
|
||||
# DPDK configuration parameters
|
||||
# vpp_uses_dpdk_mlx4_pmd = yes
|
||||
|
@ -193,7 +193,7 @@ needed:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ sudo yum install vpp-plugins vpp-devel vpp-api-python vpp-api-lua vpp-api-java
|
||||
$ sudo yum install vpp-plugins vpp-devel vpp-api-python vpp-api-lua
|
||||
|
||||
Starting VPP
|
||||
============
|
||||
|
@ -60,11 +60,6 @@ vpp-dev
|
||||
Vector Packet Processing development support. This package contains
|
||||
development support files for the VPP libraries.
|
||||
|
||||
vpp-api-java
|
||||
------------
|
||||
|
||||
JAVA binding for the VPP Binary API.
|
||||
|
||||
vpp-api-python
|
||||
--------------
|
||||
|
||||
|
@ -95,7 +95,7 @@ Install the optional packages by running the following command:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
sudo apt-get install vpp-dbg vpp-dev vpp-api-java vpp-api-python vpp-api-lua
|
||||
sudo apt-get install vpp-dbg vpp-dev vpp-api-python vpp-api-lua
|
||||
|
||||
|
||||
Uninstall the Packages
|
||||
|
@ -27,7 +27,6 @@ Uninstalling the packages:
|
||||
These packages are installed on node localhost
|
||||
Name Version
|
||||
vpp 18.04-release
|
||||
vpp-api-java 18.04-release
|
||||
vpp-api-lua 18.04-release
|
||||
vpp-api-python 18.04-release
|
||||
vpp-dbg 18.04-release
|
||||
@ -88,7 +87,6 @@ Installing the packages:
|
||||
These packages are installed on node localhost
|
||||
Name Version
|
||||
vpp 18.04-release
|
||||
vpp-api-java 18.04-release
|
||||
vpp-api-lua 18.04-release
|
||||
vpp-api-python 18.04-release
|
||||
vpp-dbg 18.04-release
|
||||
|
@ -9,6 +9,5 @@ Reference
|
||||
|
||||
cmdreference/index.rst
|
||||
vppvagrant/index.rst
|
||||
jvpp.rst
|
||||
readthedocs/index.rst
|
||||
github/index.rst
|
||||
|
@ -1,47 +0,0 @@
|
||||
.. _jvpp:
|
||||
|
||||
.. toctree::
|
||||
|
||||
Getting jvpp jar
|
||||
================
|
||||
|
||||
VPP provides java bindings which can be downloaded at:
|
||||
|
||||
* https://nexus.fd.io/content/repositories/fd.io.release/io/fd/vpp/jvpp-core/18.01/jvpp-core-18.01.jar
|
||||
|
||||
Getting jvpp via maven
|
||||
------------------------------------
|
||||
|
||||
**1. Add the following to the repositories section in your ~/.m2/settings.xml to pick up the fd.io maven repo:**
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
<repository>
|
||||
<id>fd.io-release</id>
|
||||
<name>fd.io-release</name>
|
||||
<url>https://nexus.fd.io/content/repositories/fd.io.release/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
For more information on setting up maven repositories in settings.xml, please look at:
|
||||
|
||||
* https://maven.apache.org/guides/mini/guide-multiple-repositories.html
|
||||
|
||||
**2. Then you can get jvpp by putting in the dependencies section of your pom.xml file:**
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
<dependency>
|
||||
<groupId>io.fd.vpp</groupId>
|
||||
<artifactId>jvpp-core</artifactId>
|
||||
<version>17.10</version>
|
||||
</dependency>
|
||||
|
||||
For more information on maven dependency managment, please look at:
|
||||
|
||||
* https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
|
@ -1,77 +0,0 @@
|
||||
# Copyright (c) 2018 Cisco and/or its affiliates.
|
||||
# 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.
|
||||
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
|
||||
project(japi)
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
|
||||
set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
|
||||
set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member)
|
||||
if (compiler_flag_no_address_of_packed_member)
|
||||
add_definitions(-Wno-address-of-packed-member)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../src
|
||||
COMMAND scripts/version
|
||||
OUTPUT_VARIABLE JAPI_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
string(REPLACE "-" ";" JAPI_LIB_VERSION ${JAPI_VERSION})
|
||||
list(GET JAPI_LIB_VERSION 0 JAPI_LIB_VERSION)
|
||||
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
set(CMAKE_INSTALL_MESSAGE NEVER)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
unset(dirlist)
|
||||
|
||||
macro(subdirlist dirlist dirpath)
|
||||
file(GLOB dirs RELATIVE ${dirpath} ${dirpath}/*)
|
||||
foreach(dir ${dirs})
|
||||
if(IS_DIRECTORY ${dirpath}/${dir})
|
||||
list(APPEND dirlist ${dirpath}/${dir})
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
list(APPEND dirlist $ENV{JAVA_HOME})
|
||||
subdirlist(dirlist /usr/lib/jvm)
|
||||
subdirlist(dirlist /usr/lib64/jvm)
|
||||
|
||||
unset(JAVA_HOME_SET)
|
||||
find_path(JAVA_HOME_SET NAMES include/jni.h PATHS ${dirlist})
|
||||
if (NOT JAVA_HOME_SET)
|
||||
message("JAVA_HOME is not found")
|
||||
else()
|
||||
set(ENV{JAVA_HOME} "${JAVA_HOME_SET}")
|
||||
endif()
|
||||
|
||||
message("JAVA_HOME: $ENV{JAVA_HOME}")
|
||||
|
||||
find_package(Java 1.8 REQUIRED COMPONENTS Development)
|
||||
get_filename_component(jvm_path ${Java_JAVAC_EXECUTABLE} DIRECTORY)
|
||||
set (Java_INCLUDE_DIRS ${jvm_path}/../include ${jvm_path}/../include/linux)
|
||||
|
||||
message("Found java headers ${Java_INCLUDE_DIRS}")
|
||||
message("Found javac at: " ${Java_JAVAC_EXECUTABLE})
|
||||
add_subdirectory(java)
|
2
extras/japi/java/.gitignore
vendored
2
extras/japi/java/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
# Negate "No core files" pattern from the toplevel .gitignore
|
||||
!**/core
|
@ -1,191 +0,0 @@
|
||||
# Copyright (c) 2018 Cisco and/or its affiliates.
|
||||
# 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.
|
||||
|
||||
find_path(VNET_INCLUDE_DIR NAMES vnet/api_errno.h)
|
||||
find_library(VPPINFRA_DIR NAMES vppinfra REQUIRED)
|
||||
find_library(VLIBMEMORYCLIENT_DIR NAMES vlibmemoryclient REQUIRED)
|
||||
find_library(SVM_DIR NAMES svm REQUIRED)
|
||||
|
||||
include_directories(${VNET_INCLUDE_DIR}
|
||||
${VNET_INCLUDE_DIR}/vpp_plugins
|
||||
${Java_INCLUDE_DIRS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR/../vpp/plugins})
|
||||
add_compile_options(-Wall)
|
||||
############# Common package ##################
|
||||
add_library(jvpp_common SHARED jvpp-common/jvpp_common.c)
|
||||
set_target_properties(jvpp_common PROPERTIES SOVERSION ${JAPI_LIB_VERSION})
|
||||
target_link_libraries(jvpp_common ${VPPINFRA_DIR})
|
||||
install(TARGETS jvpp_common DESTINATION lib COMPONENT libjvpp_common)
|
||||
install(FILES jvpp-common/jvpp_common.h DESTINATION include/japi/)
|
||||
|
||||
set(JVPP_LIBS jvpp_common ${VPPINFRA_DIR} ${VLIBMEMORYCLIENT_DIR} ${SVM_DIR}
|
||||
Threads::Threads m rt)
|
||||
|
||||
############# Registry package ##################
|
||||
set(PACKAGE_DIR_JVPP_REGISTRY io/fd/vpp/jvpp)
|
||||
unset(files)
|
||||
FILE(GLOB files RELATIVE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/${PACKAGE_DIR_JVPP_REGISTRY}/*.java
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/${PACKAGE_DIR_JVPP_REGISTRY}/*/*.java
|
||||
)
|
||||
|
||||
add_custom_target (jvpp-registry-classes)
|
||||
add_custom_command (TARGET jvpp-registry-classes
|
||||
PRE_BUILD
|
||||
COMMAND mkdir -p jvpp-registry/target
|
||||
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry
|
||||
COMMAND ${Java_JAVAC_EXECUTABLE}
|
||||
ARGS -d ${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/target -h jvpp-registry ${files}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_library(jvpp_registry SHARED jvpp-registry/jvpp_registry.c)
|
||||
target_link_libraries(jvpp_registry ${JVPP_LIBS})
|
||||
include_directories(jvpp-registry)
|
||||
add_dependencies(jvpp_registry jvpp_common jvpp-registry-classes)
|
||||
|
||||
add_custom_target (jvpp-registry)
|
||||
add_dependencies(jvpp-registry jvpp_registry)
|
||||
add_custom_command(TARGET jvpp-registry
|
||||
PRE_BUILD
|
||||
COMMAND cp ${CMAKE_BINARY_DIR}/lib/libjvpp_registry.so jvpp-registry/target
|
||||
COMMAND ${Java_JAR_EXECUTABLE} ARGS cf
|
||||
${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar
|
||||
-C jvpp-registry/target .
|
||||
COMMAND rm ARGS -rf jvpp-registry/target
|
||||
jvpp-registry/io_fd_vpp_jvpp_*.h
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "JAR_GEN registry"
|
||||
)
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar
|
||||
DESTINATION share/java
|
||||
)
|
||||
|
||||
############## Functions #########################
|
||||
function(japigen name)
|
||||
if(NOT VPP_JAVA_APIGEN)
|
||||
set(VPP_JAVA_APIGEN ${CMAKE_CURRENT_SOURCE_DIR}/jvpp/gen/jvpp_gen.py)
|
||||
endif()
|
||||
add_custom_target(japigen-${name} DEPENDS jvpp-registry)
|
||||
add_custom_command(TARGET japigen-${name}
|
||||
POST_BUILD
|
||||
COMMAND mkdir -p jvpp-${name}/target
|
||||
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}
|
||||
COMMAND ${VPP_JAVA_APIGEN}
|
||||
ARGS --plugin_name ${name} --root_dir jvpp-${name} -i ${ARGN}
|
||||
COMMAND find jvpp-${name} -name \*.java > jvpp-${name}/jvpp-${name}.files
|
||||
COMMAND ${Java_JAVAC_EXECUTABLE}
|
||||
ARGS -cp ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar -d
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/jvpp-${name}/target -h jvpp-${name}
|
||||
@jvpp-${name}/jvpp-${name}.files
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "JAVA_API_GEN ${name}"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(jargen name)
|
||||
add_custom_command(TARGET jvpp_${name}
|
||||
POST_BUILD
|
||||
COMMAND cp ${CMAKE_BINARY_DIR}/lib/libjvpp_${name}.so jvpp-${name}/target
|
||||
COMMAND ${Java_JAR_EXECUTABLE} ARGS cf
|
||||
${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar
|
||||
-C jvpp-${name}/target .
|
||||
COMMAND rm ARGS -rf jvpp-${name}/target jvpp-${name}/jvpp-${name}.files
|
||||
jvpp-${name}/jvpp_${name}_gen.h jvpp-${name}/io_fd_vpp_jvpp_*.h
|
||||
jvpp-registry/io_fd_vpp_jvpp_*.h
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "JAR_GEN ${name}"
|
||||
)
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar
|
||||
DESTINATION share/java
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(java_api_binding name src_file)
|
||||
japigen (${name} ${ARGN})
|
||||
add_library(jvpp_${name} SHARED jvpp-${name}/jvpp_${src_file}.c)
|
||||
target_link_libraries(jvpp_${name} ${JVPP_LIBS})
|
||||
include_directories(jvpp-${name})
|
||||
add_dependencies(jvpp_${name} jvpp_common jvpp_registry japigen-${name})
|
||||
jargen (${name})
|
||||
endfunction()
|
||||
|
||||
############ Core Package #######################
|
||||
unset (files)
|
||||
unset (JSON_API_PATH)
|
||||
set (JSON_API_PATH ${CMAKE_BINARY_DIR}/../vpp)
|
||||
|
||||
FILE(GLOB_RECURSE files RELATIVE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${JSON_API_PATH}/vnet/*.api.json
|
||||
${JSON_API_PATH}/vpp/*.api.json
|
||||
)
|
||||
|
||||
java_api_binding (core core ${files})
|
||||
|
||||
############ Plugin Packages #######################
|
||||
unset (ACL_JSON_FILE)
|
||||
unset (NAT_JSON_FILE)
|
||||
unset (NSH_JSON_FILE)
|
||||
unset (GTPU_JSON_FILE)
|
||||
unset (PPPOE_JSON_FILE)
|
||||
unset (IOAM_TRACE_JSON_FILE)
|
||||
unset (IOAM_POT_JSON_FILE)
|
||||
unset (IOAM_EXPORT_JSON_FILE)
|
||||
|
||||
set (plugin_path ${CMAKE_BINARY_DIR}/../vpp/plugins)
|
||||
|
||||
find_file(ACL_JSON_FILE NAMES acl.api.json HINTS ${plugin_path} PATH_SUFFIXES acl)
|
||||
find_file(NAT_JSON_FILE NAMES nat.api.json HINTS ${plugin_path} PATH_SUFFIXES nat)
|
||||
find_file(NSH_JSON_FILE NAMES nsh.api.json HINTS ${plugin_path} PATH_SUFFIXES nsh)
|
||||
find_file(GTPU_JSON_FILE NAMES gtpu.api.json HINTS ${plugin_path} PATH_SUFFIXES gtpu)
|
||||
find_file(PPPOE_JSON_FILE NAMES pppoe.api.json HINTS ${plugin_path} PATH_SUFFIXES pppoe)
|
||||
find_file(IOAM_TRACE_JSON_FILE NAMES trace.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-trace)
|
||||
find_file(IOAM_POT_JSON_FILE NAMES pot.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-pot)
|
||||
find_file(IOAM_EXPORT_JSON_FILE NAMES ioam_export.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/export)
|
||||
|
||||
if(ACL_JSON_FILE)
|
||||
java_api_binding (acl acl ${ACL_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(NAT_JSON_FILE)
|
||||
java_api_binding (nat nat ${NAT_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(NSH_JSON_FILE)
|
||||
java_api_binding (nsh nsh ${NSH_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(GTPU_JSON_FILE)
|
||||
java_api_binding (gtpu gtpu ${GTPU_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(PPPOE_JSON_FILE)
|
||||
java_api_binding (pppoe pppoe ${PPPOE_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(IOAM_TRACE_JSON_FILE)
|
||||
java_api_binding (ioamtrace ioam_trace ${IOAM_TRACE_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(IOAM_POT_JSON_FILE)
|
||||
java_api_binding (ioampot ioam_pot ${IOAM_POT_JSON_FILE})
|
||||
endif()
|
||||
|
||||
if(IOAM_EXPORT_JSON_FILE)
|
||||
java_api_binding (ioamexport ioam_export ${IOAM_EXPORT_JSON_FILE})
|
||||
endif()
|
@ -1,236 +0,0 @@
|
||||
= JVpp
|
||||
|
||||
JVpp is JNI based Java API for VPP.
|
||||
|
||||
== Features
|
||||
It is:
|
||||
|
||||
* Asynchronous
|
||||
* Fully generated
|
||||
* Lightweight
|
||||
|
||||
== Architecture
|
||||
|
||||
=== Plugin support
|
||||
|
||||
/-------------\ /--------------\ /---------------\
|
||||
| JvppPlugin1 +<-------+ JVppRegistry +--------->+ VppConnection |
|
||||
\-------------/ inits \--+-----------/ uses \---------------/
|
||||
|
|
||||
/-------------\ |
|
||||
| JvppPlugin2 +<----------+ inits
|
||||
\-------------/ |
|
||||
|
|
||||
... |
|
||||
|
|
||||
/----------\ |
|
||||
| JVppCore +<-------------+
|
||||
\----------/
|
||||
|
||||
|
||||
VppRegistry opens connection to vpp (VppConnection) and manages jvpp plugins.
|
||||
Each plugin needs to be registered in the VppRegistry. Registration involves
|
||||
plugin initialization (providing JNI implementation with JVppCallback reference,
|
||||
vpp client identifier and vpp shared memory queue address).
|
||||
|
||||
API user sends message by calling a method of appropriate plugin interface.
|
||||
The call is delegated to JNI implementation provided by the particular plugin.
|
||||
When JNI code receives reply, it invokes callback method of JVppCallback
|
||||
that corresponds to the received message reply.
|
||||
|
||||
=== JVppCore as an example of JVpp plugin architecture
|
||||
|
||||
JVpp Java
|
||||
|
||||
/--------------\ /----------\ /------------\ /------\
|
||||
| JVppRegistry | | JVppCore | | Callbacks | | DTOs |
|
||||
\----+---------/ \----+-----/ \------+-----/ \------/
|
||||
^ ^ ^
|
||||
| implements | implements | implements
|
||||
/----+--------------\ /---+----------\ /-----+---------\
|
||||
| JVppRegistryImpl* +-------->+ JVppCoreImpl | | JVppCallback |
|
||||
\-------+-----------/ inits \---+----------/ \-------+-------/
|
||||
| | ^
|
||||
| | uses | calls back
|
||||
| | |
|
||||
----------|--------------------------|-----------------------|---------------------
|
||||
| | |
|
||||
C JNI | +-------------------+ | /-----------------\
|
||||
v | | +-->+ jvpp_core_gen.h |
|
||||
/--------+--------\ | | | \-----------------/
|
||||
| jpp_registry.c* +---+ /--------+----+----\ | | |
|
||||
\-----------------/ | | << shared lib >> | /-+--+---+------\
|
||||
+ ->+ jvpp_common* <--------+ jvpp_core.c* |
|
||||
uses \------------------/ uses \---------------/
|
||||
|
||||
|
||||
* Components marked with an asterisk contain manually crafted code, which in addition
|
||||
to generated classes form jvpp. Exception applies to Callbacks and DTOs, since there are
|
||||
manually crafted marker interfaces in callback and dto package (dto/JVppRequest, dto/JVppReply,
|
||||
dto/JVppDump, dto/JVppReplyDump, callback/JVppCallback)
|
||||
|
||||
Note: jvpp_core.c calls back the JVppCallback instance with every response. An instance of the
|
||||
JVppCallback is provided to jvpp_core.c by JVppRegistryImpl on JVppCoreImpl initialization.
|
||||
|
||||
Part of the JVpp is also Future facade. It is asynchronous API returning Future objects
|
||||
on top of low level JVpp. It wraps dump reply messages in one DTO using control_ping message
|
||||
(provided by JVppRegistry).
|
||||
|
||||
|
||||
Future facade
|
||||
|
||||
/----------------\ /---------------\
|
||||
| FutureJVppCore | +-->+ JVppRegistry* |
|
||||
\-----+----------/ | \---------------/
|
||||
^ |
|
||||
| implements | uses
|
||||
| |
|
||||
/--------+-------------\ | /------------------------------\
|
||||
| FutureJVppCoreFacade +---+--->+ FutureJVppCoreFacadeCallback |
|
||||
\---------+------------/ uses \-------+----------------------/
|
||||
| |
|
||||
---------------|-----------------------------|-------------------------------
|
||||
| uses | implements
|
||||
JVpp Java | |
|
||||
| |
|
||||
/----------\ | |
|
||||
| JVppCore +<-+ |
|
||||
\----+-----/ |
|
||||
^ |
|
||||
| implements v
|
||||
/----+---------\ /--------+---------------\
|
||||
| JVppCoreImpl | | JVppCoreGlobalCallback |
|
||||
\--------------/ \------------------------/
|
||||
|
||||
|
||||
|
||||
Another useful utility of the JVpp is Callback facade. It is asynchronous API
|
||||
capable of calling specific callback instance (provided when performing a call)
|
||||
per call.
|
||||
|
||||
|
||||
Callback facade
|
||||
|
||||
/------------------\ /---------------\
|
||||
| CallbackJVppCore | +-->+ JVppRegistry* |
|
||||
\-----+------------/ | \---------------/
|
||||
^ |
|
||||
| implements | uses
|
||||
| |
|
||||
/--------+---------------\ | /--------------------------\
|
||||
| CallbackJVppCoreFacade +---+--->+ CallbackJVppCoreCallback |
|
||||
\---------+--------------/ uses \-----+--------------------/
|
||||
| |
|
||||
---------------|-----------------------------|-------------------------------
|
||||
| uses | implements
|
||||
JVpp Java | |
|
||||
| |
|
||||
/----------\ | |
|
||||
| JVppCore +<-+ |
|
||||
\----+-----/ |
|
||||
^ |
|
||||
| implements v
|
||||
/----+---------\ /----------+-------------\
|
||||
| JVppCoreImpl | | JVppCoreGlobalCallback |
|
||||
\--------------/ \------------------------/
|
||||
|
||||
|
||||
== Package structure
|
||||
|
||||
* *io.fd.vpp.jvpp* - top level package for generated JVpp interface+ implementation and hand-crafted
|
||||
VppConnection interface + implementation - packaged as jvpp-registry-version.jar
|
||||
|
||||
* *io.fd.vpp.jvpp.[plugin]* - top level package for generated JVpp interface + implementation
|
||||
+ plugin's API tests - packaged as jvpp-[plugin]-version.jar
|
||||
|
||||
** *dto* - package for DTOs generated from VPP API structures + base/marker hand-crafted interfaces
|
||||
(in case of jvpp-registry)
|
||||
** *callback* - package for low-level JVpp callbacks and a global callback interface implementing each of
|
||||
the low-level JVppcallbacks
|
||||
** *future* - package for future based facade on top of JVpp and callbacks
|
||||
** *callfacade* - package for callback based facade on top of JVpp and callbacks. Allowing
|
||||
users to provide callback per request
|
||||
** *test* - package for JVpp standalone tests. Can also serve as samples for JVpp.
|
||||
|
||||
C code is structured into modules:
|
||||
|
||||
* *jvpp_common* - shared library that provides jvpp_main_t reference used by jvpp_registry and plugins.
|
||||
|
||||
* *jvpp_registry* - native library used by JVppRegistryImpl, responsible for:
|
||||
|
||||
** VPP connection open/close
|
||||
** Rx thread to java thread attach
|
||||
** control ping message handling
|
||||
|
||||
* *jvpp_core* - native library used by jvpp core plugin:
|
||||
** *jvpp_core.c* - contains hand crafted code for core plugin initialization
|
||||
** *jvpp_core_gen.h* - contains generated JNI compatible handlers for all requests and replies defined in vpe.api
|
||||
|
||||
== Code generators
|
||||
All of the required code except the base/marker interfaces is generated using
|
||||
simple python2 code generators. The generators use __defs_vpp_papi.py__ input
|
||||
file produced by __vppapigen__ from vpe.api file.
|
||||
|
||||
=== JNI compatible C code
|
||||
Produces __jvpp_[plugin]_gen.h__ file containing JNI compatible handlers for each VPP
|
||||
request and reply.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Source: jvpp_c_gen.py
|
||||
====
|
||||
|
||||
=== Request/Reply DTOs
|
||||
For all the structures in __defs_vpp_papi.py__ a POJO DTO is produced. Logically,
|
||||
there are 4 types of DTOs:
|
||||
|
||||
* Request - requests that can be sent to VPP and only a single response is expected
|
||||
* DumpRequest - requests that can be sent to VPP and a stream of responses is expected
|
||||
* Reply - reply to a simple request or a single response from dump triggered response stream
|
||||
* ReplyDump - collection of replies from a single dump request
|
||||
* Notifications/Events - Not implemented yet
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Source: dto_gen.py
|
||||
====
|
||||
|
||||
=== JVpp
|
||||
Produces __JVpp.java__ and __JVppImpl.java__. This is the layer right above JNI compatible C
|
||||
code.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Source: jvpp_impl_gen.py
|
||||
====
|
||||
|
||||
=== Callbacks
|
||||
Produces callback interface for each VPP reply + a global callback interface called
|
||||
__JVpp[plugin]GlobalCallback.java__ aggregating all of the callback interfaces. The JNI
|
||||
compatible C code expects only a single instance of this global callback and calls
|
||||
it with every reply.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Source: callback_gen.py
|
||||
====
|
||||
|
||||
=== Future facade
|
||||
Produces an asynchronous facade on top of JVpp and callbacks, which returns a Future that provides
|
||||
matching reply once VPP invocation finishes. Sources produced:
|
||||
__FutureJVpp[plugin].java, FutureJVpp[plugin]Facade.java and FutureJVpp[plugin]Callback.java__
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Source: jvpp_future_facade_gen.py
|
||||
====
|
||||
|
||||
=== Callback facade
|
||||
Similar to future facade, only this facade takes callback objects as part of the invocation
|
||||
and the callback is called with result once VPP invocation finishes. Sources produced:
|
||||
__CallbackJVpp[plugin].java, CallbackJVpp[plugin]Facade.java and CallbackJVpp[plugin]Callback.java__
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Source: jvpp_callback_facade_gen.py
|
||||
====
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.acl.examples;
|
||||
|
||||
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_ADDRESS_2_AS_ARRAY;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_ADDRESS_AS_ARRAY;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_DST_ICMP_TYPE_END;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_DST_ICMP_TYPE_START;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_MAC;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_MAC_MASK;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_PREFIX;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_PREFIX_2;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_SRC_ICMP_TYPE_END;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.FIRST_RULE_SRC_ICMP_TYPE_START;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.ICMP_PROTOCOL;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_ADDRESS_2_AS_ARRAY;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_ADDRESS_AS_ARRAY;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_DST_PORT_RANGE_END;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_DST_PORT_RANGE_START;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_MAC;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_MAC_MASK;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_PREFIX;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_PREFIX_2;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_SRC_PORT_RANGE_END;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.SECOND_RULE_SRC_PORT_RANGE_START;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.UDP_PROTOCOL;
|
||||
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDetails;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclDetails;
|
||||
import io.fd.vpp.jvpp.acl.types.AclRule;
|
||||
import io.fd.vpp.jvpp.acl.types.MacipAclRule;
|
||||
import java.util.Arrays;
|
||||
|
||||
class AclExpectedDumpData {
|
||||
|
||||
static void verifyMacIpDump(final MacipAclDetails macipAclDetails) {
|
||||
// asserting data create by previous call
|
||||
assertEquals(0, macipAclDetails.aclIndex);
|
||||
assertEquals(2, macipAclDetails.count);
|
||||
|
||||
final MacipAclRule currentIpv4Rule = macipAclDetails.r[0];
|
||||
final MacipAclRule currentIpv6Rule = macipAclDetails.r[1];
|
||||
|
||||
// Comparing one property at the time to better pointer if something is wrong
|
||||
//Ipv4 rule
|
||||
assertEquals(0, currentIpv4Rule.isIpv6);
|
||||
assertEquals(1, currentIpv4Rule.isPermit);
|
||||
|
||||
// cutting expected ipv4 to 4 bytes,vpp sends it as 16 always
|
||||
assertArrays(FIRST_RULE_ADDRESS_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.srcIpAddr, 0, 4));
|
||||
assertEquals(FIRST_RULE_PREFIX, currentIpv4Rule.srcIpPrefixLen);
|
||||
assertArrays(FIRST_RULE_MAC, currentIpv4Rule.srcMac);
|
||||
assertArrays(FIRST_RULE_MAC_MASK, currentIpv4Rule.srcMacMask);
|
||||
|
||||
//Ipv6 rule
|
||||
assertEquals(1, currentIpv6Rule.isIpv6);
|
||||
assertEquals(0, currentIpv6Rule.isPermit);
|
||||
assertArrays(SECOND_RULE_ADDRESS_AS_ARRAY, currentIpv6Rule.srcIpAddr);
|
||||
assertEquals(SECOND_RULE_PREFIX, currentIpv6Rule.srcIpPrefixLen);
|
||||
assertArrays(SECOND_RULE_MAC, currentIpv6Rule.srcMac);
|
||||
assertArrays(SECOND_RULE_MAC_MASK, currentIpv6Rule.srcMacMask);
|
||||
}
|
||||
|
||||
static void verifyAclDump(final AclDetails aclDetails) {
|
||||
assertEquals(0, aclDetails.aclIndex);
|
||||
assertEquals(2, aclDetails.count);
|
||||
|
||||
final AclRule currentIpv4Rule = aclDetails.r[0];
|
||||
final AclRule currentIpv6Rule = aclDetails.r[1];
|
||||
|
||||
// Comparing one property at the time to better pointer if something is wrong
|
||||
//Ipv4 rule
|
||||
assertEquals(0, currentIpv4Rule.isIpv6);
|
||||
assertEquals(1, currentIpv4Rule.isPermit);
|
||||
|
||||
// cutting expected ipv4 to 4 bytes,vpp sends it as 16 always
|
||||
assertArrays(FIRST_RULE_ADDRESS_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.srcIpAddr, 0, 4));
|
||||
assertEquals(FIRST_RULE_PREFIX, currentIpv4Rule.srcIpPrefixLen);
|
||||
assertArrays(FIRST_RULE_ADDRESS_2_AS_ARRAY, Arrays.copyOfRange(currentIpv4Rule.dstIpAddr, 0, 4));
|
||||
assertEquals(FIRST_RULE_PREFIX_2, currentIpv4Rule.dstIpPrefixLen);
|
||||
|
||||
assertEquals(ICMP_PROTOCOL, currentIpv4Rule.proto);
|
||||
assertEquals(FIRST_RULE_SRC_ICMP_TYPE_START, currentIpv4Rule.srcportOrIcmptypeFirst);
|
||||
assertEquals(FIRST_RULE_SRC_ICMP_TYPE_END, currentIpv4Rule.srcportOrIcmptypeLast);
|
||||
assertEquals(FIRST_RULE_DST_ICMP_TYPE_START, currentIpv4Rule.dstportOrIcmpcodeFirst);
|
||||
assertEquals(FIRST_RULE_DST_ICMP_TYPE_END, currentIpv4Rule.dstportOrIcmpcodeLast);
|
||||
|
||||
assertArrays(SECOND_RULE_ADDRESS_AS_ARRAY, currentIpv6Rule.srcIpAddr);
|
||||
assertEquals(SECOND_RULE_PREFIX, currentIpv6Rule.srcIpPrefixLen);
|
||||
assertArrays(SECOND_RULE_ADDRESS_2_AS_ARRAY, currentIpv6Rule.dstIpAddr);
|
||||
assertEquals(SECOND_RULE_PREFIX_2, currentIpv6Rule.dstIpPrefixLen);
|
||||
|
||||
assertEquals(UDP_PROTOCOL, currentIpv6Rule.proto);
|
||||
assertEquals(SECOND_RULE_SRC_PORT_RANGE_START, currentIpv6Rule.srcportOrIcmptypeFirst);
|
||||
assertEquals(SECOND_RULE_SRC_PORT_RANGE_END, currentIpv6Rule.srcportOrIcmptypeLast);
|
||||
assertEquals(SECOND_RULE_DST_PORT_RANGE_START, currentIpv6Rule.dstportOrIcmpcodeFirst);
|
||||
assertEquals(SECOND_RULE_DST_PORT_RANGE_END, currentIpv6Rule.dstportOrIcmpcodeLast);
|
||||
}
|
||||
|
||||
static void verifyAclInterfaceList(final AclInterfaceListDetails aclInterfaceListDetails) {
|
||||
assertEquals(1, aclInterfaceListDetails.count);
|
||||
assertEquals(1, aclInterfaceListDetails.acls[0]);
|
||||
assertEquals(0, aclInterfaceListDetails.nInput);
|
||||
assertEquals(0, aclInterfaceListDetails.swIfIndex);
|
||||
}
|
||||
|
||||
private static void assertArrays(final byte[] expected, final byte[] actual) {
|
||||
if (!Arrays.equals(expected, actual)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Expected[%s]/Actual[%s]", Arrays.toString(expected), Arrays.toString(actual)));
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertEquals(final int expected, final int actual) {
|
||||
if (expected != actual) {
|
||||
throw new IllegalArgumentException(String.format("Expected[%s]/Actual[%s]", expected, actual));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.acl.examples;
|
||||
|
||||
|
||||
import io.fd.vpp.jvpp.acl.types.AclRule;
|
||||
import io.fd.vpp.jvpp.acl.types.MacipAclRule;
|
||||
|
||||
class AclTestData {
|
||||
|
||||
static final byte[] FIRST_RULE_ADDRESS_AS_ARRAY = {-64, -88, 2, 1};
|
||||
static final byte[] FIRST_RULE_ADDRESS_2_AS_ARRAY = {-64, -88, 2, 3};
|
||||
static final byte[] SECOND_RULE_ADDRESS_AS_ARRAY =
|
||||
{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
|
||||
static final byte[] SECOND_RULE_ADDRESS_2_AS_ARRAY =
|
||||
{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
|
||||
static final byte[] FIRST_RULE_MAC = {11, 11, 11, 11, 11, 11};
|
||||
static final byte[] FIRST_RULE_MAC_MASK = {0, 0, 0, 0, 0, 0};
|
||||
static final byte[] SECOND_RULE_MAC = {11, 12, 11, 11, 12, 11};
|
||||
static final byte[] SECOND_RULE_MAC_MASK = {(byte) 170, 0, 0, 0, 0, 0};
|
||||
static final int FIRST_RULE_PREFIX = 32;
|
||||
static final int FIRST_RULE_PREFIX_2 = 24;
|
||||
static final int SECOND_RULE_PREFIX = 64;
|
||||
static final int SECOND_RULE_PREFIX_2 = 62;
|
||||
static final int FIRST_RULE_DST_ICMP_TYPE_START = 0;
|
||||
static final int FIRST_RULE_DST_ICMP_TYPE_END = 8;
|
||||
static final int FIRST_RULE_SRC_ICMP_TYPE_START = 1;
|
||||
static final int FIRST_RULE_SRC_ICMP_TYPE_END = 7;
|
||||
static final int ICMP_PROTOCOL = 1;
|
||||
static final int SECOND_RULE_DST_PORT_RANGE_START = 2000;
|
||||
static final int SECOND_RULE_DST_PORT_RANGE_END = 6000;
|
||||
static final int SECOND_RULE_SRC_PORT_RANGE_START = 400;
|
||||
static final int SECOND_RULE_SRC_PORT_RANGE_END = 2047;
|
||||
static final int UDP_PROTOCOL = 17;
|
||||
|
||||
|
||||
static MacipAclRule[] createMacipRules() {
|
||||
MacipAclRule ruleOne = new MacipAclRule();
|
||||
ruleOne.isIpv6 = 0;
|
||||
ruleOne.isPermit = 1;
|
||||
ruleOne.srcIpAddr = FIRST_RULE_ADDRESS_AS_ARRAY;
|
||||
ruleOne.srcIpPrefixLen = FIRST_RULE_PREFIX;
|
||||
ruleOne.srcMac = FIRST_RULE_MAC;
|
||||
ruleOne.srcMacMask = FIRST_RULE_MAC_MASK;// no mask
|
||||
|
||||
MacipAclRule ruleTwo = new MacipAclRule();
|
||||
ruleTwo.isIpv6 = 1;
|
||||
ruleTwo.isPermit = 0;
|
||||
ruleTwo.srcIpAddr = SECOND_RULE_ADDRESS_AS_ARRAY;
|
||||
ruleTwo.srcIpPrefixLen = SECOND_RULE_PREFIX;
|
||||
ruleTwo.srcMac = SECOND_RULE_MAC;
|
||||
ruleTwo.srcMacMask = SECOND_RULE_MAC_MASK;
|
||||
|
||||
return new MacipAclRule[]{ruleOne, ruleTwo};
|
||||
}
|
||||
|
||||
static AclRule[] createAclRules() {
|
||||
AclRule ruleOne = new AclRule();
|
||||
|
||||
ruleOne.isIpv6 = 0;
|
||||
ruleOne.isPermit = 1;
|
||||
ruleOne.srcIpAddr = FIRST_RULE_ADDRESS_AS_ARRAY;
|
||||
ruleOne.srcIpPrefixLen = FIRST_RULE_PREFIX;
|
||||
ruleOne.dstIpAddr = FIRST_RULE_ADDRESS_2_AS_ARRAY;
|
||||
ruleOne.dstIpPrefixLen = FIRST_RULE_PREFIX_2;
|
||||
ruleOne.dstportOrIcmpcodeFirst = FIRST_RULE_DST_ICMP_TYPE_START;
|
||||
ruleOne.dstportOrIcmpcodeLast = FIRST_RULE_DST_ICMP_TYPE_END;
|
||||
ruleOne.srcportOrIcmptypeFirst = FIRST_RULE_SRC_ICMP_TYPE_START;
|
||||
ruleOne.srcportOrIcmptypeLast = FIRST_RULE_SRC_ICMP_TYPE_END;
|
||||
ruleOne.proto = ICMP_PROTOCOL; //ICMP
|
||||
|
||||
AclRule ruleTwo = new AclRule();
|
||||
ruleTwo.isIpv6 = 1;
|
||||
ruleTwo.isPermit = 0;
|
||||
ruleTwo.srcIpAddr = SECOND_RULE_ADDRESS_AS_ARRAY;
|
||||
ruleTwo.srcIpPrefixLen = SECOND_RULE_PREFIX;
|
||||
ruleTwo.dstIpAddr = SECOND_RULE_ADDRESS_2_AS_ARRAY;
|
||||
ruleTwo.dstIpPrefixLen = SECOND_RULE_PREFIX_2;
|
||||
ruleTwo.dstportOrIcmpcodeFirst = SECOND_RULE_DST_PORT_RANGE_START;
|
||||
ruleTwo.dstportOrIcmpcodeLast = SECOND_RULE_DST_PORT_RANGE_END;
|
||||
ruleTwo.srcportOrIcmptypeFirst = SECOND_RULE_SRC_PORT_RANGE_START;
|
||||
ruleTwo.srcportOrIcmptypeLast = SECOND_RULE_SRC_PORT_RANGE_END;
|
||||
ruleTwo.proto = UDP_PROTOCOL; //UDP
|
||||
|
||||
return new AclRule[]{ruleOne, ruleTwo};
|
||||
}
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.acl.examples;
|
||||
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.createAclRules;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestData.createMacipRules;
|
||||
|
||||
import io.fd.vpp.jvpp.VppInvocationException;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclAddReplace;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclAddReplaceReply;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDel;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDelReply;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDump;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclList;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclListReply;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclAdd;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclAddReply;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclAddReplace;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclAddReplaceReply;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclDel;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclDelReply;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump;
|
||||
import io.fd.vpp.jvpp.acl.dto.MacipAclDump;
|
||||
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
class AclTestRequests {
|
||||
|
||||
static MacipAclDetailsReplyDump sendMacIpDumpRequest(final FutureJVppAclFacade jvpp)
|
||||
throws ExecutionException, InterruptedException {
|
||||
System.out.println("Sending MacipAclDump request...");
|
||||
MacipAclDetailsReplyDump dump = jvpp.macipAclDump(new MacipAclDump()).toCompletableFuture().get();
|
||||
System.out.println("MacipAclDump returned");
|
||||
return dump;
|
||||
}
|
||||
|
||||
static void sendMacIpAddRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException {
|
||||
final MacipAclAdd request = createMacIpAddRequest();
|
||||
System.out.printf("Sending MacipAclAdd request %s%n", request.toString());
|
||||
final MacipAclAddReply reply = jvpp.macipAclAdd(createMacIpAddRequest()).toCompletableFuture().get();
|
||||
System.out.printf("MacipAclAdd send result = %s%n", reply);
|
||||
}
|
||||
|
||||
static void sendMacIpAddReplaceRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException {
|
||||
final MacipAclAddReplace request = createMacIpAddReplaceRequest();
|
||||
System.out.printf("Sending MacipAclAddReplace request %s%n", request.toString());
|
||||
final MacipAclAddReplaceReply reply = jvpp.macipAclAddReplace(createMacIpAddReplaceRequest()).toCompletableFuture().get();
|
||||
System.out.printf("MacipAclAddReplace send result = %s%n", reply);
|
||||
}
|
||||
|
||||
static void sendMacIpDelRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException {
|
||||
final MacipAclDel request = new MacipAclDel();
|
||||
request.aclIndex = 0;
|
||||
System.out.printf("Sending MacipAclDel request %s%n", request.toString());
|
||||
final MacipAclDelReply reply = jvpp.macipAclDel(request).toCompletableFuture().get();
|
||||
System.out.printf("MacipAclDel send result = %s%n", reply);
|
||||
}
|
||||
|
||||
static void sendAclAddRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException {
|
||||
final AclAddReplace request = createAclAddRequest();
|
||||
System.out.printf("Sending AclAddReplace request %s%n", request.toString());
|
||||
final AclAddReplaceReply reply = jvpp.aclAddReplace(request).toCompletableFuture().get();
|
||||
System.out.printf("AclAddReplace send result = %s%n", reply);
|
||||
}
|
||||
|
||||
static AclDetailsReplyDump sendAclDumpRequest(final FutureJVppAclFacade jvpp)
|
||||
throws InterruptedException, VppInvocationException, ExecutionException {
|
||||
System.out.println("Sending AclDump request...");
|
||||
final AclDetailsReplyDump dump = jvpp.aclDump(new AclDump()).toCompletableFuture().get();
|
||||
System.out.printf("AclDump send result = %s%n", dump);
|
||||
return dump;
|
||||
}
|
||||
|
||||
static void sendAclDelRequest(final FutureJVppAclFacade jvpp) throws InterruptedException, ExecutionException {
|
||||
final AclDel request = new AclDel();
|
||||
request.aclIndex = 0;
|
||||
System.out.printf("Sending AclDel request %s%n", request.toString());
|
||||
final AclDelReply reply = jvpp.aclDel(request).toCompletableFuture().get();
|
||||
System.out.printf("AclDel send result = %s%n", reply);
|
||||
}
|
||||
|
||||
static AclInterfaceListDetailsReplyDump sendAclInterfaceListDumpRequest(final FutureJVppAclFacade jvpp)
|
||||
throws InterruptedException, ExecutionException {
|
||||
final AclInterfaceListDump request = new AclInterfaceListDump();
|
||||
request.swIfIndex = 0;
|
||||
System.out.printf("Sending AclInterfaceListDump request %s%n", request.toString());
|
||||
final AclInterfaceListDetailsReplyDump dump = jvpp.aclInterfaceListDump(request).toCompletableFuture().get();
|
||||
System.out.printf("AclInterfaceListDump send result = %s%n", dump);
|
||||
return dump;
|
||||
}
|
||||
|
||||
static void sendAclInterfaceSetAclList(final FutureJVppAclFacade jvpp)
|
||||
throws InterruptedException, ExecutionException {
|
||||
final AclInterfaceSetAclList request = new AclInterfaceSetAclList();
|
||||
request.count = 1;
|
||||
request.acls = new int[]{1};
|
||||
request.swIfIndex = 0;
|
||||
request.nInput = 0;
|
||||
System.out.printf("Sending AclInterfaceSetAclList request %s%n", request.toString());
|
||||
final AclInterfaceSetAclListReply reply = jvpp.aclInterfaceSetAclList(request).toCompletableFuture().get();
|
||||
System.out.printf("AclInterfaceSetAclList send result = %s%n", reply);
|
||||
}
|
||||
|
||||
static void sendAclInterfaceDeleteList(final FutureJVppAclFacade jvpp)
|
||||
throws InterruptedException, ExecutionException {
|
||||
// uses same api but sets list to empty
|
||||
final AclInterfaceSetAclList request = new AclInterfaceSetAclList();
|
||||
request.count = 0;
|
||||
request.acls = new int[]{};
|
||||
request.swIfIndex = 0;
|
||||
request.nInput = 0;
|
||||
System.out.printf("Sending AclInterfaceSetAclList(Delete) request %s%n", request.toString());
|
||||
final AclInterfaceSetAclListReply reply = jvpp.aclInterfaceSetAclList(request).toCompletableFuture().get();
|
||||
System.out.printf("AclInterfaceSetAclList(Delete) send result = %s%n", reply);
|
||||
}
|
||||
|
||||
private static MacipAclAdd createMacIpAddRequest() {
|
||||
MacipAclAdd request = new MacipAclAdd();
|
||||
|
||||
request.count = 2;
|
||||
request.r = createMacipRules();
|
||||
return request;
|
||||
}
|
||||
|
||||
private static MacipAclAddReplace createMacIpAddReplaceRequest() {
|
||||
MacipAclAddReplace request = new MacipAclAddReplace();
|
||||
|
||||
request.count = 2;
|
||||
request.aclIndex = 0;
|
||||
request.r = createMacipRules();
|
||||
return request;
|
||||
}
|
||||
|
||||
private static AclAddReplace createAclAddRequest() {
|
||||
AclAddReplace request = new AclAddReplace();
|
||||
|
||||
request.aclIndex = -1;// to define new one
|
||||
request.count = 2;
|
||||
request.r = createAclRules();
|
||||
return request;
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.acl.examples;
|
||||
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclExpectedDumpData.verifyAclDump;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclExpectedDumpData.verifyAclInterfaceList;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclExpectedDumpData.verifyMacIpDump;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclAddRequest;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclDelRequest;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclDumpRequest;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclInterfaceDeleteList;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclInterfaceListDumpRequest;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendAclInterfaceSetAclList;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendMacIpAddRequest;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendMacIpDelRequest;
|
||||
import static io.fd.vpp.jvpp.acl.examples.AclTestRequests.sendMacIpDumpRequest;
|
||||
|
||||
import io.fd.vpp.jvpp.JVppRegistry;
|
||||
import io.fd.vpp.jvpp.JVppRegistryImpl;
|
||||
import io.fd.vpp.jvpp.acl.JVppAclImpl;
|
||||
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
|
||||
|
||||
public class FutureApiExample {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testCallbackApi();
|
||||
}
|
||||
|
||||
private static void testCallbackApi() throws Exception {
|
||||
System.out.println("Testing Java callback API for acl plugin");
|
||||
try (final JVppRegistry registry = new JVppRegistryImpl("macipAclAddTest");
|
||||
final FutureJVppAclFacade jvpp = new FutureJVppAclFacade(registry, new JVppAclImpl())) {
|
||||
|
||||
// adds,dump and verifies Mac-Ip acl
|
||||
sendMacIpAddRequest(jvpp);
|
||||
verifyMacIpDump(sendMacIpDumpRequest(jvpp).macipAclDetails.get(0));
|
||||
|
||||
// adds,dumps and verifies Acl acl
|
||||
sendAclAddRequest(jvpp);
|
||||
verifyAclDump(sendAclDumpRequest(jvpp).aclDetails.get(0));
|
||||
|
||||
// adds,dumps and verifies Interface for acl
|
||||
sendAclInterfaceSetAclList(jvpp);
|
||||
verifyAclInterfaceList(sendAclInterfaceListDumpRequest(jvpp).aclInterfaceListDetails.get(0));
|
||||
|
||||
// deletes all created data
|
||||
sendAclInterfaceDeleteList(jvpp);
|
||||
sendAclDelRequest(jvpp);
|
||||
sendMacIpDelRequest(jvpp);
|
||||
|
||||
System.out.println("Disconnecting...");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
release version:
|
||||
sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.examples.FutureApiExample
|
||||
debug version:
|
||||
sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-debug-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.examples.FutureApiExample
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.acl.test;
|
||||
|
||||
import io.fd.vpp.jvpp.AbstractCallbackApiTest;
|
||||
import io.fd.vpp.jvpp.acl.JVppAclImpl;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class CallbackApiTest extends AbstractCallbackApiTest {
|
||||
|
||||
private static Logger LOG = Logger.getLogger(CallbackApiTest.class.getName());
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
LOG.info("Testing ControlPing using Java callback API for core plugin");
|
||||
testControlPing(args[0], new JVppAclImpl());
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.acl.test;
|
||||
|
||||
import io.fd.vpp.jvpp.Assertions;
|
||||
import io.fd.vpp.jvpp.JVppRegistry;
|
||||
import io.fd.vpp.jvpp.JVppRegistryImpl;
|
||||
import io.fd.vpp.jvpp.acl.JVppAclImpl;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump;
|
||||
import io.fd.vpp.jvpp.acl.dto.AclDump;
|
||||
import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class FutureApiTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(FutureApiTest.class.getName());
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testFutureApi(args);
|
||||
}
|
||||
|
||||
private static void testFutureApi(String[] args) throws Exception {
|
||||
LOG.info("Testing Java future API for core plugin");
|
||||
try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiTest", args[0]);
|
||||
final FutureJVppAclFacade jvppFacade = new FutureJVppAclFacade(registry, new JVppAclImpl())) {
|
||||
LOG.info("Successfully connected to VPP");
|
||||
|
||||
testAclDump(jvppFacade);
|
||||
|
||||
LOG.info("Disconnecting...");
|
||||
}
|
||||
}
|
||||
|
||||
private static void testAclDump(final FutureJVppAclFacade jvpp) throws Exception {
|
||||
LOG.info("Sending AclDump request...");
|
||||
final AclDump request = new AclDump();
|
||||
|
||||
final CompletableFuture<AclDetailsReplyDump>
|
||||
replyFuture = jvpp.aclDump(request).toCompletableFuture();
|
||||
final AclDetailsReplyDump reply = replyFuture.get();
|
||||
|
||||
Assertions.assertNotNull(reply);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
release version:
|
||||
sudo java -cp build-vpp-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.test.[test-name]
|
||||
debug version:
|
||||
sudo java -cp build-vpp_debug-native/vpp/vpp-api/java/jvpp-registry-17.10.jar:build-vpp_debug-native/vpp/vpp-api/java/jvpp-acl-17.10.jar io.fd.vpp.jvpp.acl.test.[test-name]
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <vnet/vnet.h>
|
||||
|
||||
#include <acl/acl_msg_enum.h>
|
||||
#define vl_typedefs /* define message structures */
|
||||
#include <acl/acl_all_api_h.h>
|
||||
#undef vl_typedefs
|
||||
|
||||
#include <vnet/api_errno.h>
|
||||
#include <vlibapi/api.h>
|
||||
#include <vlibmemory/api.h>
|
||||
|
||||
#if VPPJNI_DEBUG == 1
|
||||
#define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_LOG(...)
|
||||
#endif
|
||||
|
||||
#include <jvpp-common/jvpp_common.h>
|
||||
|
||||
#include "jvpp-acl/io_fd_vpp_jvpp_acl_JVppAclImpl.h"
|
||||
#include "jvpp_acl.h"
|
||||
#include "jvpp-acl/jvpp_acl_gen.h"
|
||||
|
||||
/*
|
||||
* Class: io_fd_vpp_jvpp_acl_JVppaclImpl
|
||||
* Method: init0
|
||||
* Signature: (JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_acl_JVppAclImpl_init0
|
||||
(JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
|
||||
acl_main_t * plugin_main = &acl_main;
|
||||
clib_warning ("Java_io_fd_vpp_jvpp_acl_JVppAclImpl_init0");
|
||||
|
||||
plugin_main->my_client_index = my_client_index;
|
||||
plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *);
|
||||
|
||||
plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
|
||||
plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
|
||||
|
||||
// verify API has not changed since jar generation
|
||||
#define _(N) \
|
||||
if (get_message_id(env, #N) == 0) return;
|
||||
foreach_supported_api_message;
|
||||
#undef _
|
||||
|
||||
#define _(N,n) \
|
||||
vl_msg_api_set_handlers(get_message_id(env, #N), #n, \
|
||||
vl_api_##n##_t_handler, \
|
||||
vl_noop_handler, \
|
||||
vl_noop_handler, \
|
||||
vl_noop_handler, \
|
||||
sizeof(vl_api_##n##_t), 1);
|
||||
foreach_api_reply_handler;
|
||||
#undef _
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_acl_JVppAclImpl_close0
|
||||
(JNIEnv *env, jclass clazz) {
|
||||
acl_main_t * plugin_main = &acl_main;
|
||||
|
||||
// cleanup:
|
||||
(*env)->DeleteGlobalRef(env, plugin_main->callbackClass);
|
||||
(*env)->DeleteGlobalRef(env, plugin_main->callbackObject);
|
||||
|
||||
plugin_main->callbackClass = NULL;
|
||||
plugin_main->callbackObject = NULL;
|
||||
}
|
||||
|
||||
/* Attach thread to JVM and cache class references when initiating JVPP ACL */
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
JNIEnv* env;
|
||||
|
||||
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
|
||||
return JNI_EVERSION;
|
||||
}
|
||||
|
||||
if (cache_class_references(env) != 0) {
|
||||
clib_warning ("Failed to cache class references\n");
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_8;
|
||||
}
|
||||
|
||||
/* Clean up cached references when disposing JVPP ACL */
|
||||
void JNI_OnUnload(JavaVM *vm, void *reserved) {
|
||||
JNIEnv* env;
|
||||
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
|
||||
return;
|
||||
}
|
||||
delete_class_references(env);
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __included_jvpp_acl_h__
|
||||
#define __included_jvpp_acl_h__
|
||||
|
||||
#include <vnet/vnet.h>
|
||||
#include <vnet/ip/ip.h>
|
||||
#include <vnet/api_errno.h>
|
||||
#include <vlibapi/api.h>
|
||||
#include <vlibmemory/api.h>
|
||||
#include <jni.h>
|
||||
|
||||
/* Global state for JVPP-acl */
|
||||
typedef struct {
|
||||
/* Pointer to shared memory queue */
|
||||
svm_queue_t * vl_input_queue;
|
||||
|
||||
/* VPP api client index */
|
||||
u32 my_client_index;
|
||||
|
||||
/* Callback object and class references enabling asynchronous Java calls */
|
||||
jobject callbackObject;
|
||||
jclass callbackClass;
|
||||
|
||||
} acl_main_t;
|
||||
|
||||
acl_main_t acl_main __attribute__((aligned (64)));
|
||||
|
||||
|
||||
#endif /* __included_jvpp_acl_h__ */
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
* 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.
|
||||
*/
|
||||
#define _GNU_SOURCE /* for strcasestr(3) */
|
||||
|
||||
#include <vnet/api_errno.h>
|
||||
#include "jvpp_common.h"
|
||||
|
||||
#ifndef JVPP_DEBUG
|
||||
#define JVPP_DEBUG 0
|
||||
#endif
|
||||
|
||||
#if JVPP_DEBUG == 1
|
||||
#define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_LOG(...)
|
||||
#endif
|
||||
|
||||
#define _(error,errorCode,msg) \
|
||||
if (errorCode == code) \
|
||||
message = msg; \
|
||||
else
|
||||
|
||||
#define get_error_message(errno) \
|
||||
int code = errno; \
|
||||
foreach_vnet_api_error \
|
||||
message = "Reason unknown";
|
||||
|
||||
/* shared jvpp main structure */
|
||||
jvpp_main_t jvpp_main __attribute__((aligned (64)));
|
||||
|
||||
void call_on_error(const char* callName, int contextId, int retval,
|
||||
jclass callbackClass, jobject callbackObject,
|
||||
jclass callbackExceptionClass) {
|
||||
DEBUG_LOG("\nCallOnError : callback=%s, retval=%d, context=%d\n", callName,
|
||||
clib_net_to_host_u32(retval), clib_net_to_host_u32(context));
|
||||
JNIEnv *env = jvpp_main.jenv;
|
||||
if (!callbackClass) {
|
||||
DEBUG_LOG("CallOnError : jm->callbackClass is null!\n");
|
||||
return;
|
||||
}
|
||||
jmethodID excConstructor = (*env)->GetMethodID(env, callbackExceptionClass,
|
||||
"<init>", "(Ljava/lang/String;Ljava/lang/String;II)V");
|
||||
if (!excConstructor) {
|
||||
DEBUG_LOG("CallOnError : excConstructor is null!\n");
|
||||
return;
|
||||
}
|
||||
jmethodID callbackExcMethod = (*env)->GetMethodID(env, callbackClass,
|
||||
"onError", "(Lio/fd/vpp/jvpp/VppCallbackException;)V");
|
||||
if (!callbackExcMethod) {
|
||||
DEBUG_LOG("CallOnError : callbackExcMethod is null!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char *message;
|
||||
get_error_message(clib_net_to_host_u32(retval));
|
||||
jobject excObject = (*env)->NewObject(env, callbackExceptionClass,
|
||||
excConstructor, (*env)->NewStringUTF(env, callName),
|
||||
(*env)->NewStringUTF(env, message),
|
||||
clib_net_to_host_u32(contextId), clib_net_to_host_u32(retval));
|
||||
if (!excObject) {
|
||||
DEBUG_LOG("CallOnError : excObject is null!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod(env, callbackObject, callbackExcMethod, excObject);
|
||||
DEBUG_LOG("CallOnError : Response sent\n");
|
||||
}
|
||||
#undef _
|
||||
|
||||
u32 get_message_id(JNIEnv *env, const char *key) {
|
||||
uword *p = hash_get(jvpp_main.messages_hash, key);
|
||||
if (!p) {
|
||||
jclass exClass = (*env)->FindClass(env, "java/lang/IllegalStateException");
|
||||
char *msgBuf = clib_mem_alloc(strlen(key) + 70);
|
||||
strcpy(msgBuf, "API mismatch detected: ");
|
||||
strcat(msgBuf, key);
|
||||
strcat(msgBuf, " is missing in global name_crc hash table.");
|
||||
DEBUG_LOG("%s", msgBuf);
|
||||
DEBUG_LOG("Possible reasons:");
|
||||
DEBUG_LOG("1) incompatible VPP version used");
|
||||
DEBUG_LOG("2) message present in JSON file but not in global name_crc table");
|
||||
(*env)->ThrowNew(env, exClass, msgBuf);
|
||||
clib_mem_free(msgBuf);
|
||||
return 0;
|
||||
}
|
||||
return (u32) p[0];
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __included_jvpp_common_h__
|
||||
#define __included_jvpp_common_h__
|
||||
//
|
||||
#include <vppinfra/types.h>
|
||||
#include <vlibapi/api.h>
|
||||
#include <vlibapi/api_types.h>
|
||||
#include <vlibmemory/api.h>
|
||||
#include <jni.h>
|
||||
|
||||
typedef struct {
|
||||
/* Unique identifier used for matching replays with requests */
|
||||
volatile u32 context_id;
|
||||
|
||||
/* Spinlock */
|
||||
volatile u32 lock;
|
||||
u32 tag;
|
||||
|
||||
/* JNI Native Method Interface pointer for message handlers */
|
||||
JNIEnv *jenv;
|
||||
|
||||
/* JNI Invoke Interface pointer for attachment of rx thread to java thread */
|
||||
JavaVM *jvm;
|
||||
|
||||
/* Convenience */
|
||||
svm_queue_t * vl_input_queue;
|
||||
u32 my_client_index;
|
||||
uword *messages_hash;
|
||||
} jvpp_main_t;
|
||||
|
||||
extern jvpp_main_t jvpp_main __attribute__((aligned (64)));
|
||||
|
||||
static_always_inline u32 vppjni_get_context_id(jvpp_main_t * jm) {
|
||||
return clib_atomic_add_fetch(&jm->context_id, 1);
|
||||
}
|
||||
|
||||
static_always_inline void vppjni_lock(jvpp_main_t * jm, u32 tag) {
|
||||
while (clib_atomic_test_and_set(&jm->lock))
|
||||
;
|
||||
jm->tag = tag;
|
||||
}
|
||||
|
||||
static_always_inline void vppjni_unlock(jvpp_main_t * jm) {
|
||||
jm->tag = 0;
|
||||
CLIB_MEMORY_BARRIER();
|
||||
jm->lock = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls onError callback on callbackObject reference. Passes instance of callbackExceptionClass as parameter.
|
||||
*/
|
||||
void call_on_error(const char* callName, int contextId, int retval,
|
||||
jclass callbackClass, jobject callbackObject,
|
||||
jclass callbackExceptionClass);
|
||||
|
||||
/**
|
||||
* Retrieves message id based on message name and crc (key format: name_crc).
|
||||
* Throws java/lang/IllegalStateException on failure.
|
||||
*/
|
||||
u32 get_message_id(JNIEnv *env, const char* key);
|
||||
|
||||
#endif /* __included_jvpp_common_h__ */
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.core.examples;
|
||||
|
||||
import io.fd.vpp.jvpp.JVpp;
|
||||
import io.fd.vpp.jvpp.JVppRegistry;
|
||||
import io.fd.vpp.jvpp.JVppRegistryImpl;
|
||||
import io.fd.vpp.jvpp.VppCallbackException;
|
||||
import io.fd.vpp.jvpp.core.JVppCoreImpl;
|
||||
import io.fd.vpp.jvpp.core.callback.GetNodeIndexReplyCallback;
|
||||
import io.fd.vpp.jvpp.core.callback.ShowVersionReplyCallback;
|
||||
import io.fd.vpp.jvpp.core.callback.SwInterfaceDetailsCallback;
|
||||
import io.fd.vpp.jvpp.core.dto.GetNodeIndex;
|
||||
import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply;
|
||||
import io.fd.vpp.jvpp.core.dto.ShowVersion;
|
||||
import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
|
||||
import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
|
||||
import io.fd.vpp.jvpp.core.dto.SwInterfaceDump;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class CallbackApiExample {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testCallbackApi();
|
||||
}
|
||||
|
||||
private static void testCallbackApi() throws Exception {
|
||||
System.out.println("Testing Java callback API with JVppRegistry");
|
||||
try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiExample");
|
||||
final JVpp jvpp = new JVppCoreImpl()) {
|
||||
registry.register(jvpp, new TestCallback());
|
||||
|
||||
System.out.println("Sending ShowVersion request...");
|
||||
final int result = jvpp.send(new ShowVersion());
|
||||
System.out.printf("ShowVersion send result = %d%n", result);
|
||||
|
||||
System.out.println("Sending GetNodeIndex request...");
|
||||
GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
|
||||
getNodeIndexRequest.nodeName = "non-existing-node".getBytes(StandardCharsets.UTF_8);
|
||||
jvpp.send(getNodeIndexRequest);
|
||||
|
||||
System.out.println("Sending SwInterfaceDump request...");
|
||||
SwInterfaceDump swInterfaceDumpRequest = new SwInterfaceDump();
|
||||
swInterfaceDumpRequest.nameFilterValid = 0;
|
||||
swInterfaceDumpRequest.nameFilter = "".getBytes(StandardCharsets.UTF_8);
|
||||
jvpp.send(swInterfaceDumpRequest);
|
||||
|
||||
Thread.sleep(1000);
|
||||
System.out.println("Disconnecting...");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
static class TestCallback implements GetNodeIndexReplyCallback, ShowVersionReplyCallback, SwInterfaceDetailsCallback {
|
||||
|
||||
@Override
|
||||
public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
|
||||
System.out.printf("Received GetNodeIndexReply: %s%n", msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowVersionReply(final ShowVersionReply msg) {
|
||||
System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, "
|
||||
+ "buildDate=%s, buildDirectory=%s%n",
|
||||
msg.context,
|
||||
msg.program,
|
||||
msg.version,
|
||||
msg.buildDate,
|
||||
msg.buildDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwInterfaceDetails(final SwInterfaceDetails msg) {
|
||||
System.out.printf("Received SwInterfaceDetails: interfaceName=%s, l2AddressLength=%d, adminUpDown=%d, "
|
||||
+ "linkUpDown=%d, linkSpeed=%d, linkMtu=%d%n",
|
||||
msg.interfaceName, msg.l2AddressLength, msg.adminUpDown,
|
||||
msg.linkUpDown, msg.linkSpeed, (int) msg.linkMtu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(VppCallbackException ex) {
|
||||
System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(),
|
||||
ex.getCtxId(), ex.getErrorCode());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Cisco and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.fd.vpp.jvpp.core.examples;
|
||||
|
||||
import io.fd.vpp.jvpp.JVpp;
|
||||
import io.fd.vpp.jvpp.JVppRegistry;
|
||||
import io.fd.vpp.jvpp.JVppRegistryImpl;
|
||||
import io.fd.vpp.jvpp.VppCallbackException;
|
||||
import io.fd.vpp.jvpp.core.JVppCoreImpl;
|
||||
import io.fd.vpp.jvpp.core.callback.ShowVersionReplyCallback;
|
||||
import io.fd.vpp.jvpp.core.dto.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class CallbackApiReadPerfTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CallbackApiReadPerfTest.class.getName());
|
||||
private static final ShowVersion REQUEST = new ShowVersion();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args - for running for one sec requires no parameter
|
||||
* - for running for set amount of requests requires one parameters, desired REQUEST amount
|
||||
* @throws Exception if arguments aren't String representations of numbers
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 0) {
|
||||
testInvokeCounter(true, Integer.parseUnsignedInt(args[0]));
|
||||
} else {
|
||||
testInvokeCounter(false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param setCount true = run with set amount of requests, false = run for 1 sec
|
||||
* @param count number of request with which test should be run
|
||||
* @throws Exception
|
||||
*/
|
||||
private static void testInvokeCounter(boolean setCount, int count) throws Exception {
|
||||
LOG.info("Testing callback API Invocation Counter");
|
||||
try (final JVppRegistry registry = new JVppRegistryImpl("CallbackApiReadPerfTest");
|
||||
final JVpp jvpp = new JVppCoreImpl()) {
|
||||
TestCallback callback = new TestCallback(count);
|
||||
registry.register(jvpp, callback);
|
||||
if (!setCount) {
|
||||
for(int i = 0; i < 5; i++) {
|
||||
callback.reset();
|
||||
LOG.info("Starting invocation for 1sec");
|
||||
long time = System.nanoTime();
|
||||
do {
|
||||
jvpp.send(REQUEST);
|
||||
} while (System.nanoTime() - time < 1000000000 || callback.stop());
|
||||
int replyCount = callback.getReplyCounter();
|
||||
LOG.info(String.format("Invocation count within 1 second: %d", replyCount));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
LOG.info("Starting invocations");
|
||||
callback.reset();
|
||||
long time = System.nanoTime();
|
||||
for (int x = 0; x < count; x++) {
|
||||
jvpp.send(REQUEST);
|
||||
}
|
||||
long timeAfter = callback.getTime();
|
||||
LOG.info(String.format("Invocations took %d ns (%f invocations/s)", timeAfter - time,
|
||||
count * (1000000000.0/(timeAfter - time))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Thread.sleep(1000);
|
||||
LOG.info("Disconnecting...");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
static class TestCallback implements ShowVersionReplyCallback {
|
||||
|
||||
private int replyCounter = 0;
|
||||
private int count;
|
||||
private long time = 0;
|
||||
private boolean stop = false;
|
||||
|
||||
public TestCallback(int count) throws Exception {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public int getReplyCounter() {
|
||||
return replyCounter;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
replyCounter = 0;
|
||||
time = 0;
|
||||
stop = false;
|
||||
}
|
||||
|
||||
public boolean stop() {
|
||||
this.stop = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* actual method called from VPP
|
||||
not thread safe but since there's only one VPP thread listening for requests and calling
|
||||
this method it's OK
|
||||
*/
|
||||
@Override
|
||||
public void onShowVersionReply(final ShowVersionReply msg) {
|
||||
if (stop) {
|
||||
return;
|
||||
}
|
||||
replyCounter++;
|
||||
if (replyCounter == count ) {
|
||||
time = System.nanoTime();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(VppCallbackException ex) {
|
||||
System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(),
|
||||
ex.getCtxId(), ex.getErrorCode());
|
||||
}
|
||||
|
||||
public long getTime() throws Exception {
|
||||
while(time == 0) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user