TSG-13355 Steering Service搭建Project框架

This commit is contained in:
luwenpeng
2023-01-09 19:01:08 +08:00
commit 364e5ccaf9
20 changed files with 3062 additions and 0 deletions

111
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,111 @@
image: "git.mesalab.cn:7443/mesa_platform/build-env:master"
variables:
GIT_STRATEGY: "clone"
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
INSTALL_PREFIX: "/opt/tsg/traffic-steering-service"
TESTING_VERSION_BUILD: 0
stages:
- build
.build_by_travis:
before_script:
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
- ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
- chmod +x ./ci/travis.sh
script:
- yum makecache
- ./ci/travis.sh
tags:
- share
branch_build_debug:
stage: build
extends: .build_by_travis
variables:
BUILD_TYPE: Debug
except:
- /^develop-.*$/i
- /^release-.*$/i
- tags
branch_build_release:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis
except:
- /^develop-.*$/i
- /^release-.*$/i
- tags
develop_build_debug:
stage: build
extends: .build_by_travis
variables:
TESTING_VERSION_BUILD: 1
UPLOAD_SYMBOL_FILES: 1
BUILD_TYPE: Debug
ASAN_OPTION: ADDRESS
PACKAGE: 1
PULP3_REPO_NAME: tsg-testing-x86_64.el7
PULP3_DIST_NAME: tsg-testing-x86_64.el7
artifacts:
name: "traffic-steering-service-develop-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- /^develop-.*$/i
- /^release-.*$/i
develop_build_release:
stage: build
extends: .build_by_travis
variables:
TESTING_VERSION_BUILD: 1
UPLOAD_SYMBOL_FILES: 1
# ASAN_OPTION: ADDRESS
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
PULP3_REPO_NAME: tsg-testing-x86_64.el7
PULP3_DIST_NAME: tsg-testing-x86_64.el7
artifacts:
name: "traffic-steering-service-develop-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- /^develop-.*$/i
- /^release-.*$/i
release_build_debug:
stage: build
variables:
UPLOAD_SYMBOL_FILES: 1
BUILD_TYPE: Debug
PACKAGE: 1
PULP3_REPO_NAME: tsg-stable-x86_64.el7
PULP3_DIST_NAME: tsg-stable-x86_64.el7
extends: .build_by_travis
artifacts:
name: "traffic-steering-service-install-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- tags
release_build_release:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
UPLOAD_SYMBOL_FILES: 1
PACKAGE: 1
PULP3_REPO_NAME: tsg-stable-x86_64.el7
PULP3_DIST_NAME: tsg-stable-x86_64.el7
extends: .build_by_travis
artifacts:
name: "traffic-steering-service-install-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- tags

62
CMakeLists.txt Normal file
View File

@@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.5)
project(tslb)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(Version)
include(Package)
add_definitions(-D_GNU_SOURCE)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "/opt/tsg/tslb" CACHE PATH "default install path" FORCE)
endif()
# Global Compile Options
option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE)
option(ENABLE_WARNING_ALL "Enable all optional warnings which are desirable for normal code" TRUE)
if(NOT ASAN_OPTION)
option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE)
else()
option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" TRUE)
endif()
option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE)
if(ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE 1)
endif()
if(ENABLE_WARNING_ALL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
if(ENABLE_SANITIZE_ADDRESS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
elseif(ENABLE_SANITIZE_THREAD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
endif()
if(ENABLE_SANITIZE_ADDRESS AND ENABLE_SANITIZE_THREAD)
message(WARNING "Both ENABLE_SANITIZE_ADDRESS and ENABLE_SANITIZE_THREAD set, only ENABLE_SANITIZE_ADDRESS effected.")
endif()
add_custom_target("install-program" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Program -P cmake_install.cmake)
add_custom_target("install-profile" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Profile -P cmake_install.cmake)
enable_testing()
#add_subdirectory(vendor)
add_subdirectory(common)
#add_subdirectory(platform)
#add_subdirectory(script)

1260
autorevision.sh Normal file

File diff suppressed because it is too large Load Diff

48
ci/get-nprocessors.sh Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Copyright 2017 Google Inc.
# All Rights Reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This file is typically sourced by another script.
# if possible, ask for the precise number of processors,
# otherwise take 2 processors as reasonable default; see
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
if [ -x /usr/bin/getconf ]; then
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
else
NPROCESSORS=2
fi
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
# crashes if parallelized too much (maybe memory consumption problem),
# so limit to 4 processors for the time being.
if [ $NPROCESSORS -gt 4 ]; then
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
NPROCESSORS=4
fi

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
set -evx
echo "machine ${PULP3_SERVER_URL}\nlogin ${PULP3_SERVER_LOGIN}\npassword ${PULP3_SERVER_PASSWORD}\n" >~/.netrc

63
ci/travis.sh Normal file
View File

@@ -0,0 +1,63 @@
#!/usr/bin/env sh
set -evx
chmod +x ci/get-nprocessors.sh
. ci/get-nprocessors.sh
# If possible, ask for the precise number of processors,
# otherwise take 2 processors as reasonable default; see
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
if [ -x /usr/bin/getconf ]; then
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
else
NPROCESSORS=2
fi
# As of 2017-09-04 Travis CI reports 32 processors, but GCC build
# crashes if parallelized too much (maybe memory consumption problem),
# so limit to 4 processors for the time being.
if [ $NPROCESSORS -gt 4 ]; then
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
NPROCESSORS=4
fi
# Tell make to use the processors. No preceding '-' required.
MAKEFLAGS="j${NPROCESSORS}"
export MAKEFLAGS
env | sort
# Set default values to OFF for these variables if not specified.
: "${NO_EXCEPTION:=OFF}"
: "${NO_RTTI:=OFF}"
: "${COMPILER_IS_GNUCXX:=OFF}"
# Install dependency from YUM
yum install -y libasan
if [ $ASAN_OPTION ]; then
source /opt/rh/devtoolset-7/enable
fi
mkdir build || true
cd build
cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DASAN_OPTION=$ASAN_OPTION \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \
..
make
if [ -n "${PACKAGE}" ]; then
make package
cp ~/rpm_upload_tools.py ./
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
fi
if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
rpm -i traffic-steering-service*debuginfo*.rpm
cp /usr/lib/debug/opt/tsg/traffic-steering-service/bin/traffic-steering-service.debug /tmp/traffic-steering-service.debuginfo.${CI_COMMIT_SHORT_SHA}
sentry-cli upload-dif -t elf /tmp/traffic-steering-service.debuginfo.${CI_COMMIT_SHORT_SHA}
fi

33
cmake/Package.cmake Normal file
View File

@@ -0,0 +1,33 @@
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_PACKAGE_NAME "traffic-steering-service-debug")
else()
set(CPACK_PACKAGE_NAME "traffic-steering-service")
endif()
message(STATUS "Package: ${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_VENDOR "MESASOFT")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${DESCRIBE}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
# RPM Build
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
set(CPACK_RPM_PACKAGE_RELEASE_DIST on)
set(CPACK_RPM_DEBUGINFO_PACKAGE on)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in)
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostUninstall.in)
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PreUninstall.in)
# Must uninstall the debug package before install release package
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_RPM_PACKAGE_CONFLICTS "traffic-steering-service")
else()
set(CPACK_RPM_PACKAGE_CONFLICTS "traffic-steering-service-debug")
endif()
include(CPack)

2
cmake/PostInstall.in Normal file
View File

@@ -0,0 +1,2 @@
%systemd_post traffic-steering-service.service
/sbin/ldconfig

2
cmake/PostUninstall.in Normal file
View File

@@ -0,0 +1,2 @@
%systemd_postun_with_restart traffic-steering-service.service
/sbin/ldconfig

1
cmake/PreUninstall.in Normal file
View File

@@ -0,0 +1 @@
%systemd_preun traffic-steering-service.service

46
cmake/Version.cmake Normal file
View File

@@ -0,0 +1,46 @@
# Using autorevision.sh to generate version information
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
set(__VERSION_CACHE ${CMAKE_SOURCE_DIR}/version.txt)
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
# Execute autorevision.sh to generate version information
execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE} OUTPUT_FILE ${__VERSION_CONFIG})
include(${__VERSION_CONFIG})
# Extract major, minor, patch version from git tag
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}")
string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}")
if(NOT VERSION_MAJOR)
set(VERSION_MAJOR 1)
endif()
if(NOT VERSION_MINOR)
set(VERSION_MINOR 0)
endif()
if(NOT VERSION_PATCH)
set(VERSION_PATCH 0)
endif()
if(VERSION_DAILY_BUILD)
set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE})
endif()
set(DESCRIBE "${VCS_SHORT_HASH}")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(GIT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${DESCRIBE}")
# Replace .- with _
string(REGEX REPLACE "[\\.\\-]" "_" VAR_VERSION "${GIT_VERSION}")
# Print information
message(STATUS "Welcome to Traffic Steering Service, Version: ${GIT_VERSION}")
add_definitions(-DGIT_VERSION=\"${GIT_VERSION}\")
add_definitions(-DVAR_VERSION=${VAR_VERSION})

3
common/CMakeLists.txt Normal file
View File

@@ -0,0 +1,3 @@
add_library(common src/conntable.cpp src/bfd.cpp)
target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)

15
common/include/bfd.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef _BFD_H
#define _BFD_H
#ifdef __cpluscplus
extern "C"
{
#endif
// TODO
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -0,0 +1,30 @@
#ifndef _CONNTABLE_H
#define _CONNTABLE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
struct tuple4
{
/* data */
};
struct conntable;
struct conntable *conntable_create();
void conntable_destory(struct conntable *table);
void conntable_add(struct conntable *table, uint64_t streamid, void *val);
void conntable_del(struct conntable *table, uint64_t streamid);
void *conntable_search_by_streamid(struct conntable *table, uint64_t streamid);
void *conntable_search_by_tuple4(struct conntable *table, struct tuple4 *tuplekey);
#ifdef __cpluscplus
}
#endif
#endif

27
common/include/log.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef _LOG_H
#define _LOG_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdio.h>
#define LOG_DEBUG(format, ...) \
{ \
fprintf(stdout, format "\n", ##__VA_ARGS__); \
fflush(stdout); \
}
#define LOG_ERROR(format, ...) \
{ \
fprintf(stderr, format "\n", ##__VA_ARGS__); \
fflush(stderr); \
}
#ifdef __cpluscplus
}
#endif
#endif

1316
common/include/uthash.h Normal file

File diff suppressed because it is too large Load Diff

3
common/src/bfd.cpp Normal file
View File

@@ -0,0 +1,3 @@
#include "bfd.h"
// TODO

30
common/src/conntable.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include "conntable.h"
#include "uthash.h"
#include "log.h"
struct conntable *conntable_create()
{
return NULL;
}
void conntable_destory(struct conntable *table)
{
}
void conntable_add(struct conntable *table, uint64_t streamid, void *val)
{
}
void conntable_del(struct conntable *table, uint64_t streamid)
{
}
void *conntable_search_by_streamid(struct conntable *table, uint64_t streamid)
{
return NULL;
}
void *conntable_search_by_tuple4(struct conntable *table, struct tuple4 *tuplekey)
{
return NULL;
}

1
script/CMakeLists.txt Normal file
View File

@@ -0,0 +1 @@
install(FILES service/traffic-steering-service.service DESTINATION /usr/lib/systemd/system/ COMPONENT Program)

View File

@@ -0,0 +1,6 @@
[Unit]
Description=Traffic Steering Service
After=network.target
[Service]
ExecStart=/opt/tsg/traffic-steering-service/bin/traffic-steering-service