Skip to content

Add Mobile Gateway modules #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ add_service(transparenthelloworld pcn-transparent-helloworld)
add_service(synflood pcn-synflood)
add_service(packetcapture pcn-packetcapture)
add_service(dynmon pcn-dynmon)
add_service(gtphandler pcn-gtphandler)
add_service(policer pcn-policer)
add_service(classifier pcn-classifier)

# save string to create code that load the services
SET_PROPERTY(GLOBAL PROPERTY LOAD_SERVICES_ ${LOAD_SERVICES})
Expand Down
17 changes: 17 additions & 0 deletions src/services/pcn-classifier/.swagger-codegen-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.

.swagger-codegen-ignore

src/*.c
src/*.cpp
src/*.h
src/modules/*.cpp
src/modules/*.h
src/CMakeLists.txt

!src/*Base.h
!src/*JsonObject.h
!src/*JsonObject.cpp
5 changes: 5 additions & 0 deletions src/services/pcn-classifier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required (VERSION 3.2)

set (CMAKE_CXX_STANDARD 11)

add_subdirectory(src)
52 changes: 52 additions & 0 deletions src/services/pcn-classifier/cmake/LoadFileAsVariable.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Loads the contents of a file into a std::string variable
#
# It creates a header file in ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
# that wrapps the contents of the file in a std::string using the raw
# string literal feature of C++11. The user needs to include that file
# into the source code in order to see the variable.
#
# parameters:
# target: target to add a dependency on file
# file: file to be loaded
# variable_name: name variable where the file is loaded
#
# example:
# load_file_as_variable(my-lib resource.c my_resource)
# Creates a resource.h in CMAKE_CURRENT_BINARY_DIR with a string variable
# my_resource with the contents of resource.c
# A dependency in resource.c is added to my-lib

function(load_file_as_variable target file variable_name)
get_filename_component(file_name ${file} NAME_WE)
get_filename_component(file_dir ${file} DIRECTORY)

set(new_path ${file_dir}/${file_name}.h)

add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/${new_path}
COMMAND
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${file_dir}
COMMAND
echo "#pragma once" > ${CMAKE_CURRENT_BINARY_DIR}/${new_path}
COMMAND
echo "#include <string>" >> ${CMAKE_CURRENT_BINARY_DIR}/${new_path}
COMMAND
echo "const std::string ${variable_name} = R\"POLYCUBE_DP(" >> ${CMAKE_CURRENT_BINARY_DIR}/${new_path}
COMMAND
cat ${CMAKE_CURRENT_SOURCE_DIR}/${file} >> ${CMAKE_CURRENT_BINARY_DIR}/${new_path}
COMMAND
cmake -E echo ")POLYCUBE_DP\";" >> ${CMAKE_CURRENT_BINARY_DIR}/${new_path}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
VERBATIM
)

string(REPLACE "/" "-" path_replaced ${new_path})

add_custom_target(
generate_${path_replaced}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${new_path}
)

add_dependencies(${target} generate_${path_replaced})
endfunction()
105 changes: 105 additions & 0 deletions src/services/pcn-classifier/datamodel/classifier.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
module classifier {
yang-version 1.1;
namespace "http://polycube.network/classifier";
prefix "classifier";

import polycube-base { prefix "polycube-base"; }
import polycube-transparent-base { prefix "polycube-transparent-base"; }

import ietf-yang-types { prefix "yang"; }
import ietf-inet-types { prefix "inet"; }

organization "Polycube Open Source Project";
description "YANG data model for the Polycube Traffic Classifier";

polycube-base:service-description "Traffic Classifier Service";
polycube-base:service-version "1.0";
polycube-base:service-name "classifier";
polycube-base:service-min-kernel-version "4.15.0";

uses "polycube-transparent-base:transparent-base-yang-module";

list traffic-class {
key id;
description "Traffic class identified by id";

leaf id {
type uint32;
mandatory true;
description "Id of the class, set in metadata of matching packets";
polycube-base:cli-example "100";
}

leaf priority {
type uint32;
mandatory true;
description "Packets matching multiple classes are assigned to the one with highest priority";
}

leaf direction {
type enumeration {
enum INGRESS;
enum EGRESS;
enum BOTH;
}
default BOTH;
description "Direction (INGRESS, EGRESS or BOTH) of the packet (default: BOTH)";
polycube-base:cli-example "INGRESS";
}

leaf smac {
type yang:mac-address;
description "Source MAC address of the packet";
polycube-base:cli-example "AC:00:00:00:00:01";
}

leaf dmac {
type yang:mac-address;
description "Destination MAC address of the packet";
polycube-base:cli-example "AC:00:00:00:00:02";
}

leaf ethtype {
type enumeration {
enum ARP;
enum IP;
}
description "Ethertype of the packet (ARP | IP)";
polycube-base:cli-example "IP";
}

leaf srcip {
type inet:ipv4-prefix;
description "Source IP address prefix of the packet";
polycube-base:cli-example "10.0.0.0/8";
}

leaf dstip {
type inet:ipv4-prefix;
description "Destination IP address prefix of the packet";
polycube-base:cli-example "192.168.0.0/24";
}

leaf l4proto {
type enumeration {
enum ICMP;
enum TCP;
enum UDP;
}
description "Level 4 protocol of the packet (ICMP | TCP | UDP)";
polycube-base:cli-example "TCP";
}

leaf sport {
type uint16;
description "Source port of the packet";
polycube-base:cli-example "80";
}

leaf dport {
type uint16;
description "Destination port of the packet";
polycube-base:cli-example "56000";
}
}
}
60 changes: 60 additions & 0 deletions src/services/pcn-classifier/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
include(${PROJECT_SOURCE_DIR}/cmake/LoadFileAsVariable.cmake)

aux_source_directory(serializer SERIALIZER_SOURCES)
aux_source_directory(api API_SOURCES)
aux_source_directory(base BASE_SOURCES)
aux_source_directory(modules MODULES)

include_directories(serializer)
include_directories(matcher)

if (NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(POLYCUBE libpolycube)
include_directories(${POLYCUBE_INCLUDE_DIRS})
endif(NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE)

# Needed to load files as variables
include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_library(pcn-classifier SHARED
${SERIALIZER_SOURCES}
${API_SOURCES}
${BASE_SOURCES}
${MODULES}
TrafficClass.cpp
Classifier.cpp
Classifier-lib.cpp
Utils.cpp)

# load ebpf datapath code a variable
load_file_as_variable(pcn-classifier
Classifier_dp.c
classifier_code)
load_file_as_variable(pcn-classifier
Selector_dp.c
selector_code)
load_file_as_variable(pcn-classifier
MatchingTable_dp.c
matching_table_code)
load_file_as_variable(pcn-classifier
Matcher_dp.c
matcher_code)

# load datamodel in a variable
load_file_as_variable(pcn-classifier
../datamodel/classifier.yang
classifier_datamodel)

target_link_libraries(pcn-classifier ${POLYCUBE_LIBRARIES})

# Specify shared library install directory

set(CMAKE_INSTALL_LIBDIR /usr/lib)

install(
TARGETS
pcn-classifier
DESTINATION
"${CMAKE_INSTALL_LIBDIR}"
)
21 changes: 21 additions & 0 deletions src/services/pcn-classifier/src/Classifier-lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* classifier API generated from classifier.yang
*
* NOTE: This file is auto generated by polycube-codegen
* https://github.com/polycube-network/polycube-codegen
*/


/* Do not edit this file manually */

#include "api/ClassifierApiImpl.h"
#include "../datamodel/classifier.h" // generated from datamodel

#define SERVICE_PYANG_GIT ""
#define SERVICE_SWAGGER_CODEGEN_GIT "master/f3b9193"

#include <polycube/services/shared_library.h>

extern "C" const char *data_model() {
return classifier_datamodel.c_str();
}
Loading