Commit 72eb1d7e authored by Franck Messaoudi's avatar Franck Messaoudi

Update: refactrongi and some changes in the code

parent 1be76e18
......@@ -214,6 +214,8 @@ smf:
upf:
support_features:
enable_bpf_datapath: yes # If "on": BPF is used as datapath else simpleswitch is used, DEFAULT= off
enable_qos: yes # Only supported for BPF datapath. If "on" we use qdiscs to manage the QoS
#qdisc_scheduler: "htb" # This value is used only in case QoS is enabled
enable_snat: no # If "on": Source natting is done for UE, DEFAULT= off
remote_n6_gw: oai-ext-dn
smfs:
......
......@@ -256,6 +256,13 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_MODULE_PATH "${SRC_TOP_DIR}/upf_app/cmake" "${CMAKE_MODULE_PATH}")
include(FindPkgConfig)
find_package (LibNL REQUIRED)
################################################################
# Add sub modules
################################################################
......@@ -311,12 +318,15 @@ IF(STATIC_LINKING)
SET(ASAN asan)
ENDIF(STATIC_LINKING)
## Common modules
include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger/logger.cmake)
include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config/config.cmake)
include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake)
include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/nrf/nrf_model.cmake)
include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/common_model/common_model.cmake)
include(${SRC_TOP_DIR}/upf_app/cmake/FindLibNL.cmake)
# folly glog dl double-conversion for FB folly library
target_link_libraries (upf
......@@ -335,7 +345,7 @@ qer_ebpf_tc
UPF_XDP
UPF_TC
gflags glog dl double-conversion folly fmt spdlog -Wl,--end-group
pthread m rt config++
pthread m rt config++
event boost_system curl yaml-cpp
)
......@@ -69,6 +69,13 @@ extern upf_nrf* upf_nrf_inst;
#define N6_IF_NAME upf_cfg.n6.if_name
#endif
#ifndef QDISC_HTB_SCHEDULER
#define QDISC_HTB_SCHEDULER "HTB"
#endif
std::unique_ptr<upf_config_yaml> upf_cfg_yaml = nullptr;
//------------------------------------------------------------------------------
......@@ -127,8 +134,9 @@ int my_check_redundant_process(char* exec_name) {
delete[] cmd;
return result;
}
//------------------------------------------------------------------------------
void setup_bpf() {
void setup_bpf(const char* qdisc_scheduler = nullptr) {
std::shared_ptr<RulesUtilities> mpRulesFactory;
mpRulesFactory = std::make_shared<RulesUtilitiesImpl>();
......@@ -136,9 +144,13 @@ void setup_bpf() {
string sUDPInterface = N6_IF_NAME;
Logger::upf_app().info("GTP interface: %s", sGTPInterface.c_str());
Logger::upf_app().info("UDP interface: %s", sUDPInterface.c_str());
UserPlaneComponent::getInstance().setup(
mpRulesFactory, sGTPInterface, sUDPInterface);
// spSessionManager = UserPlaneComponent::getInstance().getSessionManager();
if(qdisc_scheduler){
UserPlaneComponent::getInstance().setup(mpRulesFactory, sGTPInterface, sUDPInterface, qdisc_scheduler);
} else {
UserPlaneComponent::getInstance().setup(mpRulesFactory, sGTPInterface, sUDPInterface);
}
}
//------------------------------------------------------------------------------
int main(int argc, char** argv) {
......@@ -218,7 +230,15 @@ int main(int argc, char** argv) {
fflush(fp);
fclose(fp);
if (upf_cfg.enable_bpf_datapath) setup_bpf();
if (upf_cfg.enable_bpf_datapath){
const char *qdisc_scheduler = nullptr;
if (upf_cfg.enable_qos){
const char *qdisc_scheduler = QDISC_HTB_SCHEDULER;
}
setup_bpf(qdisc_scheduler);
}
// once all udp servers initialized
io_service.run();
......
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibNL.cmake)
add_subdirectory(bpf)
include_directories(${SRC_TOP_DIR}/upf_app/bpf/bpf_pfcp)
include_directories(${SRC_TOP_DIR}/upf_app/simpleswitch)
......@@ -23,6 +24,8 @@ include_directories(${SRC_TOP_DIR}/upf_app/bpf/rules/qer)
#include_directories(${SRC_TOP_DIR}/upf_app/bpf/rules/bar)
#include_directories(${SRC_TOP_DIR}/upf_app/bpf/rules/mar)
include_directories(${LibNL_INCLUDE_DIR})
include_directories(${SRC_TOP_DIR}/upf_app/app)
set(GTP_INTERFACE $ENV{GTP_INTERFACE})
......@@ -33,7 +36,7 @@ add_library(UPF_XDP STATIC
UserPlaneComponent.cpp
Configuration.cpp
SignalHandler.cpp
NextHopFinder.cpp
helpers/NextHopFinder.cpp
SessionProgramManager.cpp
SessionManager.cpp
SessionPrograms.cpp
......@@ -52,7 +55,7 @@ add_library(UPF_TC STATIC
UserPlaneComponent.cpp
Configuration.cpp
SignalHandler.cpp
NextHopFinder.cpp
helpers/NextHopFinder.cpp
SessionProgramManager.cpp
SessionManager.cpp
SessionPrograms.cpp
......
......@@ -17,13 +17,13 @@
using namespace oai::config;
extern upf_config upf_cfg;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
SessionManager::SessionManager() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
SessionManager::~SessionManager() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Helper function to extract PDI and source interface
bool SessionManager::extractPdiAndInterface(
std::shared_ptr<pfcp::pfcp_pdr> pdr, pfcp::pdi& pdi,
......@@ -32,7 +32,7 @@ bool SessionManager::extractPdiAndInterface(
return (pdr->get(pdi) && pdi.get(sourceInterface) && pdi.get(ueIpAddress));
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Helper function to extract FAR
bool SessionManager::extractFar(
std::shared_ptr<pfcp::pfcp_pdr> pdr,
......@@ -45,7 +45,7 @@ bool SessionManager::extractFar(
return false;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Helper function to extract Forwarding Parameters
bool SessionManager::extractForwardingParameters(
std::shared_ptr<pfcp::pfcp_far> far,
......@@ -53,7 +53,7 @@ bool SessionManager::extractForwardingParameters(
return far->get(forwardingParams);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Helper function to find the Uplink TEID to update
uint32_t SessionManager::findUplinkTeid(
uint32_t seid,
......@@ -84,14 +84,14 @@ uint32_t SessionManager::findUplinkTeid(
return teidToUpdate;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::createSession(std::shared_ptr<SessionBpf> pSession) {
SessionProgramManager::getInstance().create(pSession->getSeid());
Logger::upf_app().debug(
"Session %d Has Been Cretead Successfully", pSession->getSeid());
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::createBPFSession(
std::shared_ptr<pfcp::pfcp_session> pSession_establishment,
itti_n4_session_establishment_request* est_req,
......@@ -176,7 +176,7 @@ void SessionManager::createBPFSession(
mSeidToSession[pSession_establishment->get_up_seid()] =
pSession_establishment;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::createBPFSessionUL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceUl) {
......@@ -211,7 +211,7 @@ void SessionManager::createBPFSessionUL(
ueIpAddress.ipv4_address.s_addr, pFar, false, 0);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::createBPFSessionDL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceDl) {
......@@ -247,7 +247,7 @@ void SessionManager::createBPFSessionDL(
ueIpAddress.ipv4_address.s_addr, pFar, false, 0);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::updateBPFSession(
std::shared_ptr<pfcp::pfcp_session> pSession,
itti_n4_session_establishment_request* est_req,
......@@ -329,7 +329,7 @@ void SessionManager::updateBPFSession(
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::updateBPFSessionUL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceUl) {
......@@ -363,7 +363,7 @@ void SessionManager::updateBPFSessionUL(
Logger::upf_app().warn("TODO: update Uplink PDRs ...");
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Function to update the Downlink Direction of a session
void SessionManager::updateBPFSessionDL(
......@@ -420,7 +420,7 @@ void SessionManager::updateBPFSessionDL(
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::removeBPFSession(
std::shared_ptr<pfcp::pfcp_session> pSession,
itti_n4_session_establishment_request* est_req,
......@@ -438,7 +438,7 @@ void SessionManager::removeBPFSession(
Logger::upf_app().debug("Session 0x%x Has Been Removed Successfully", seid);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
bool SessionManager::comparePDR(
const std::shared_ptr<pfcp::pfcp_pdr>& pFirst,
const std::shared_ptr<pfcp::pfcp_pdr>& pSecond) {
......@@ -449,10 +449,10 @@ bool SessionManager::comparePDR(
return precedenceFirst.precedence < precedenceSecond.precedence;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void SessionManager::removeSession(uint64_t seid) {
SessionProgramManager::getInstance().remove(seid);
Logger::upf_app().debug("Session %d has been removed", seid);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
......@@ -43,7 +43,7 @@ class SessionManager {
// Set of PDRs.
using pdrs_t = std::vector<std::shared_ptr<PacketDetectionRules>>;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Construct a new Session Manager object.
......@@ -51,21 +51,21 @@ class SessionManager {
*/
SessionManager();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Destroy the Session Manager object.
*
*/
virtual ~SessionManager();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Create a Session object in BPF map.
*
* @param pSession The session object to be created.
*/
void createSession(std::shared_ptr<SessionBpf> pSession);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove a session object from BPF map.
......@@ -75,7 +75,7 @@ class SessionManager {
*/
void removeSession(uint64_t seid);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Creates BPF pipeline.
*
......@@ -87,7 +87,7 @@ class SessionManager {
itti_n4_session_establishment_request* est_req,
itti_n4_session_modification_request* mod_req,
itti_n4_session_deletion_request* del_req);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Update a Session object in BPF map.
......@@ -100,7 +100,7 @@ class SessionManager {
itti_n4_session_modification_request* mod_req,
itti_n4_session_deletion_request* del_req);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove BPF pipeline.
*
......@@ -113,56 +113,56 @@ class SessionManager {
itti_n4_session_modification_request* mod_req,
itti_n4_session_deletion_request* del_req);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void createBPFSessionUL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceUl);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void createBPFSessionDL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceDl);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void updateBPFSessionUL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceUl);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void updateBPFSessionDL(
std::shared_ptr<pfcp::pfcp_session> pSession,
std::shared_ptr<pfcp::pfcp_pdr> pdrHighPrecedenceDl);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
bool extractPdiAndInterface(
std::shared_ptr<pfcp::pfcp_pdr> pdr, pfcp::pdi& pdi,
pfcp::source_interface_t& sourceInterface,
pfcp::ue_ip_address_t& ueIpAddress);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
bool extractFar(
std::shared_ptr<pfcp::pfcp_pdr> pdr,
std::shared_ptr<pfcp::pfcp_session> session,
std::shared_ptr<pfcp::pfcp_far>& outFar);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
bool extractForwardingParameters(
std::shared_ptr<pfcp::pfcp_far> far,
pfcp::forwarding_parameters& forwardingParams);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t findUplinkTeid(
uint32_t seid,
const std::vector<std::shared_ptr<pfcp::pfcp_session>>& sessions);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static bool comparePDR(
const std::shared_ptr<pfcp::pfcp_pdr>& first,
const std::shared_ptr<pfcp::pfcp_pdr>& second);
std::vector<std::shared_ptr<pfcp::pfcp_session>> sessions;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::unordered_map<uint64_t, std::shared_ptr<pfcp::pfcp_session>>
mSeidToSession;
};
......
This diff is collapsed.
......@@ -36,7 +36,7 @@ class SessionProgramManager {
*/
virtual ~SessionProgramManager();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Instance object.
*
......@@ -44,7 +44,7 @@ class SessionProgramManager {
*/
static SessionProgramManager& getInstance();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Set the Programs Map object.
*
......@@ -52,7 +52,7 @@ class SessionProgramManager {
*/
void setTeidSessionMap(std::shared_ptr<BPFMap> pProgramsMaps);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Create a new program related to the SEID.
* The context will be empty.
......@@ -61,7 +61,7 @@ class SessionProgramManager {
*/
void create(uint32_t seid);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove program session context.
*
......@@ -69,14 +69,14 @@ class SessionProgramManager {
*/
void remove(uint32_t seid);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove all programs.
*
*/
void removeAll();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Set the On New Session Observer object.
*
......@@ -85,7 +85,7 @@ class SessionProgramManager {
*/
void setOnNewSessionObserver(OnStateChangeSessionProgramObserver* pObserver);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Find the Session Program object.
*
......@@ -96,80 +96,80 @@ class SessionProgramManager {
std::shared_ptr<PFCP_Session_PDR_LookupProgram> findSessionProgram(
uint32_t seid);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void addFarProgram(uint32_t seid, std::shared_ptr<FARProgram> pFARProgram);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void updateArpTableMap(
std::shared_ptr<FARProgram> pFARProgram, uint32_t upfIP,
uint32_t remoteIP);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t getRemoteIP(uint32_t upfIP, uint32_t remoteIP);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
pfcp_far_t_ createFar(std::shared_ptr<pfcp::pfcp_far> pFar);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void createPipeline(
uint32_t seid, uint32_t teid1, uint8_t sourceInterface,
uint32_t ueIpAddress, std::shared_ptr<pfcp::pfcp_far> pFar,
bool isModification, uint32_t teid2);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void initializeNextRuleProgIndexKey(
next_rule_prog_index_key& key, uint32_t teid, uint32_t ueIpAddress,
uint8_t sourceInterface);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void storeFarProgramIndexInNextProgRuleIndexMap(
std::shared_ptr<FARProgram> pFARProgram,
const next_rule_prog_index_key& key,
std::shared_ptr<PFCP_Session_LookupProgram> pPFCP_Session_LookupProgram);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void storeSessionMappingMap(
std::shared_ptr<PFCP_Session_LookupProgram> pPFCP_Session_LookupProgram,
uint32_t ue_ip_address, uint32_t teid_dl);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void storeFARInFARMap(
std::shared_ptr<FARProgram> pFARProgram,
std::shared_ptr<pfcp::pfcp_far> pFar);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void saveSeidWithinFARProgram(
uint32_t seid, std::shared_ptr<FARProgram> pFARProgram,
const next_rule_prog_index_key& key);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void updateARPTableForN6(
std::shared_ptr<FARProgram> pFARProgram, uint32_t dnIP, uint32_t upfn6IP);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void updateARPTableForN3(
std::shared_ptr<FARProgram> pFARProgram, uint32_t gNodeBIP,
uint32_t upfn3IP, uint32_t seid);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t getGnodebIp(std::shared_ptr<pfcp::pfcp_far> pFar);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void updatePipeline(
uint32_t seid, uint32_t teid, uint32_t gNBIpAddress, bool isModification);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// void storeUeQfiTeidMap(
// std::shared_ptr<PFCP_Session_LookupProgram>
// pPFCP_Session_LookupProgram, uint32_t ue_ip_address, uint8_t qfi,
// uint32_t teid_ul);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// void updateMap(std::shared_ptr<PFCP_Session_LookupProgram>
// pPFCP_Session_LookupProgram,
// uint32_t seid, uint32_t teid_ul, uint32_t src_ip, uint32_t teid_dl);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void removePipeline(uint32_t seid);
std::shared_ptr<SessionPrograms> findSessionPrograms(uint32_t seid);
......
......@@ -6,8 +6,19 @@
#include <SignalHandler.h>
#include <pfcp_session_lookup_ebpf_xdp_prgrm_user.h>
#include "logger.hpp"
#include <helpers/GetNicInformation.hpp>
/*****************************************************************************************************************/
#include <netlink/netlink.h>
#include <netlink/route/qdisc.h>
#include <netlink/route/link.h>
#include <netlink/route/qdisc/htb.h>
#ifndef QDISC_HTB_SCHEDULER
#define QDISC_HTB_SCHEDULER HTB
#endif
/*---------------------------------------------------------------------------------------------------------------*/
UserPlaneComponent::UserPlaneComponent() {
// Set new handlers for libbpf.
#ifdef DEBUG_LIBBPF
......@@ -15,64 +26,70 @@ UserPlaneComponent::UserPlaneComponent() {
#endif
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
UserPlaneComponent::~UserPlaneComponent() {
tearDown();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<SessionManager> UserPlaneComponent::getSessionManager() const {
return mpSessionManager;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<RulesUtilities> UserPlaneComponent::getRulesUtilities() const {
return mpRulesUtilities;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<PFCP_Session_LookupProgram>
UserPlaneComponent::getPFCP_Session_LookupProgram() const {
return mpPFCP_Session_LookupProgram;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::string UserPlaneComponent::getGTPInterface() const {
return mGTPInterface;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::string UserPlaneComponent::getUDPInterface() const {
return mUDPInterface;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
const char* UserPlaneComponent::getQdiscScheduler() const {
return mQdiscScheduler;
}
/*---------------------------------------------------------------------------------------------------------------*/
void UserPlaneComponent::onNewSessionProgram(
u_int32_t programId, u_int32_t fileDescriptor) {
mpPFCP_Session_LookupProgram->updateProgramMap(programId, fileDescriptor);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void UserPlaneComponent::onDestroySessionProgram(u_int32_t programId) {
mpPFCP_Session_LookupProgram->removeProgramMap(programId);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int UserPlaneComponent::printLibbpfLog(
enum libbpf_print_level lvl, const char* fmt, va_list args) {
return vfprintf(stderr, fmt, args);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
UserPlaneComponent& UserPlaneComponent::getInstance() {
static UserPlaneComponent sInstance;
return sInstance;
}
/*****************************************************************************************************************/
void UserPlaneComponent::setup(
std::shared_ptr<RulesUtilities> pRulesUtilities,
const std::string& gtpInterface, const std::string& udpInterface) {
/*---------------------------------------------------------------------------------------------------------------*/
void UserPlaneComponent::set_members(std::shared_ptr<RulesUtilities> pRulesUtilities,
const std::string& gtpInterface, const std::string& udpInterface){
mpRulesUtilities = pRulesUtilities;
mGTPInterface = gtpInterface;
mUDPInterface = udpInterface;
......@@ -84,14 +101,86 @@ void UserPlaneComponent::setup(
throw std::runtime_error("The eBPF Program is Not Initialized");
}
}
/*---------------------------------------------------------------------------------------------------------------*/
void UserPlaneComponent::setup(
std::shared_ptr<RulesUtilities> pRulesUtilities,
const std::string& gtpInterface, const std::string& udpInterface) {
set_members(pRulesUtilities, gtpInterface, udpInterface);
SignalHandler::getInstance().enable();
mpPFCP_Session_LookupProgram->setup();
// Pass maps to sessionManager.
mpSessionManager = std::make_shared<SessionManager>();
}
/*---------------------------------------------------------------------------------------------------------------*/
void UserPlaneComponent::setup(
std::shared_ptr<RulesUtilities> pRulesUtilities,
const std::string& gtpInterface, const std::string& udpInterface, const char* qdisc_scheduler) {
set_members(pRulesUtilities, gtpInterface, udpInterface);
mQdiscScheduler = qdisc_scheduler;
SignalHandler::getInstance().enable();
mpPFCP_Session_LookupProgram->setup();
// Pass maps to sessionManager.
mpSessionManager = std::make_shared<SessionManager>();
qdisc_att = new struct qdisc_params;
}
/*---------------------------------------------------------------------------------------------------------------*/
// Method to create the root qdisc
struct rtnl_qdisc* UserPlaneComponent::create_qdisc(struct nl_sock *sock){
// Allocate a new Qdisc object
struct rtnl_qdisc *qdisc = rtnl_qdisc_alloc();
if (!qdisc) {
perror("rtnl_qdisc_alloc");
nl_close(sock);
nl_socket_free(sock);
exit(EXIT_FAILURE);
}
return qdisc;
}
/*---------------------------------------------------------------------------------------------------------------*/
// Method definition to initialize qdisc_att
void UserPlaneComponent::initializeQdisc(std::string interface) {
NicInformationGetter nicInfoGet;
// Initialize qdisc_att members
qdisc_att->scheduler = getQdiscScheduler();
qdisc_att->rate = nicInfoGet.retrieveRate(interface);
qdisc_att->ceil = nicInfoGet.retrieveCeil(interface);
qdisc_att->rate_buffer = 0;
qdisc_att->ceil_buffer = 0;
qdisc_att->quantum = 0;
qdisc_att->level = 0;
}
/*---------------------------------------------------------------------------------------------------------------*/
struct rtnl_qdisc* UserPlaneComponent::configure_qdisc(struct rtnl_qdisc *qdisc, struct rtnl_class *htb_class){
// Set Qdisc attributes
rtnl_tc_set_kind(TC_CAST(qdisc), qdisc_att->scheduler);
if (strcmp(qdisc_att->scheduler, QDISC_HTB_SCHEDULER) == 0) {
rtnl_htb_set_rate(htb_class, qdisc_att->rate); // Set Physical capacity
rtnl_htb_set_rbuffer(htb_class, qdisc_att->rate_buffer);
rtnl_htb_set_cbuffer(htb_class, qdisc_att->ceil_buffer);
rtnl_htb_set_quantum(htb_class, qdisc_att->quantum);
rtnl_htb_set_level(htb_class, qdisc_att->level);
}
// Set additional Qdisc attributes as needed
return qdisc;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void UserPlaneComponent::tearDown() {
mpPFCP_Session_LookupProgram->tearDown();
SessionProgramManager::getInstance().removeAll();
......
This diff is collapsed.
......@@ -516,6 +516,13 @@ int upf_config::load(const string& config_file) {
enable_bpf_datapath = false;
}
support_features.lookupValue(UPF_CONFIG_STRING_ENABLE_QOS, opt);
if (boost::iequals(opt, "yes")) {
enable_qos = true;
} else {
enable_qos = false;
}
support_features.lookupValue(
UPF_CONFIG_STRING_5G_FEATURES_USE_FQDN_NRF, opt);
if (boost::iequals(opt, "yes")) {
......@@ -789,6 +796,12 @@ void upf_config::display() {
Logger::upf_app().info(" register_nrf: %s", (register_nrf) ? "yes" : "no");
Logger::upf_app().info(
" enable_bpf_datapath: %s", (enable_bpf_datapath) ? "yes" : "no");
if (enable_bpf_datapath){
Logger::upf_app().info(" enable_qos: %s", (enable_qos) ? "yes" : "no");
} else {
Logger::upf_app().info(" enable_qos: no");
}
Logger::upf_app().info(" use_fqdn_dns: %s", (use_fqdn_dns) ? "yes" : "no");
if (register_nrf) {
Logger::upf_app().info(" NRF:");
......
......@@ -50,6 +50,7 @@
constexpr auto UPF_CONFIG_OPTION_YES_STR = "Yes";
constexpr auto UPF_CONFIG_OPTION_NO_STR = "No";
const oai::model::common::Snssai DEFAULT_SNSSAI{1};
const std::vector<oai::model::nrf::DnnUpfInfoItem> DEFAULT_DNN_LIST = {
oai::model::nrf::DnnUpfInfoItem("default")};
......@@ -88,6 +89,7 @@ const std::vector<oai::model::nrf::DnnUpfInfoItem> DEFAULT_DNN_LIST = {
#define UPF_CONFIG_STRING_5G_FEATURES "SUPPORT_5G_FEATURES"
#define UPF_CONFIG_STRING_ENABLE_BPF_DATAPATH "ENABLE_BPF_DATAPATH"
#define UPF_CONFIG_STRING_ENABLE_QOS "ENABLE_QOS"
#define UPF_CONFIG_STRING_5G_FEATURES_REGISTER_NRF "REGISTER_NRF"
#define UPF_CONFIG_STRING_5G_FEATURES_UPF_FQDN "UPF_FQDN_5G"
#define UPF_CONFIG_STRING_5G_FEATURES_NRF "NRF"
......@@ -184,6 +186,7 @@ class upf_config {
bool enable_5g_features;
bool enable_bpf_datapath;
bool enable_qos;
bool register_nrf;
struct in_addr remote_n6;
upf_info_t upf_info;
......@@ -237,6 +240,7 @@ class upf_config {
enable_5g_features = true;
enable_bpf_datapath = false;
enable_qos = false;
register_nrf = false;
upf_info = {};
use_fqdn_dns = false;
......
......@@ -32,10 +32,15 @@ namespace oai::config {
//------------------------------------------------------------------------------
upf_support_features::upf_support_features(
bool enable_bpf_datapath, bool enable_snat) {
bool enable_bpf_datapath, bool enable_qos, bool enable_snat) {
m_config_name = "Supported Features";
m_enable_bpf_datapath = option_config_value(
UPF_CONFIG_SUPPORT_FEATURES_ENABLE_BPF_LABEL, enable_bpf_datapath);
m_enable_qos = option_config_value(
UPF_CONFIG_SUPPORT_FEATURES_ENABLE_QOS_LABEL, enable_qos);
m_enable_snat = option_config_value(
UPF_CONFIG_SUPPORT_FEATURES_ENABLE_SNAT_LABEL, enable_snat);
}
......@@ -46,6 +51,12 @@ void upf_support_features::from_yaml(const YAML::Node& node) {
m_enable_bpf_datapath.from_yaml(
node[UPF_CONFIG_SUPPORT_FEATURES_ENABLE_BPF]);
}
if (node[UPF_CONFIG_SUPPORT_FEATURES_ENABLE_QOS]) {
m_enable_qos.from_yaml(
node[UPF_CONFIG_SUPPORT_FEATURES_ENABLE_QOS]);
}
if (node[UPF_CONFIG_SUPPORT_FEATURES_ENABLE_SNAT]) {
m_enable_snat.from_yaml(node[UPF_CONFIG_SUPPORT_FEATURES_ENABLE_SNAT]);
}
......@@ -56,6 +67,7 @@ std::string upf_support_features::to_string(const std::string& indent) const {
std::string out;
unsigned int inner_width = get_inner_width(indent.length());
// Enable BPF
std::string enable_bpf_datapath = m_enable_bpf_datapath.get_value() ?
UPF_CONFIG_OPTION_YES_STR :
UPF_CONFIG_OPTION_NO_STR;
......@@ -63,7 +75,17 @@ std::string upf_support_features::to_string(const std::string& indent) const {
BASE_FORMATTER, INNER_LIST_ELEM,
UPF_CONFIG_SUPPORT_FEATURES_ENABLE_BPF_LABEL, inner_width,
enable_bpf_datapath));
// Enable QoS
std::string enable_qos = m_enable_qos.get_value() ?
UPF_CONFIG_OPTION_YES_STR :
UPF_CONFIG_OPTION_NO_STR;
out.append(indent).append(fmt::format(
BASE_FORMATTER, INNER_LIST_ELEM,
UPF_CONFIG_SUPPORT_FEATURES_ENABLE_QOS_LABEL, inner_width,
enable_qos));
// Enable SNAT
std::string enable_snat = m_enable_snat.get_value() ?
UPF_CONFIG_OPTION_YES_STR :
UPF_CONFIG_OPTION_NO_STR;
......@@ -78,7 +100,7 @@ upf::upf(
const std::string& name, const std::string& host, const sbi_interface& sbi,
const std::map<std::string, upf_interface_config>& interfaces)
: nf(name, host, sbi),
m_upf_support_features(false, false),
m_upf_support_features(false, false, false),
m_interfaces(interfaces) {
model::nrf::SnssaiUpfInfoItem item;
item.setSNssai(DEFAULT_SNSSAI);
......@@ -179,6 +201,11 @@ bool upf_support_features::get_option_enable_bpf_datapath() const {
return m_enable_bpf_datapath.get_value();
}
//------------------------------------------------------------------------------
bool upf_support_features::get_option_enable_qos() const {
return m_enable_qos.get_value();
}
//------------------------------------------------------------------------------
bool upf_support_features::get_option_enable_snat() const {
return m_enable_snat.get_value();
......@@ -364,9 +391,9 @@ void upf_config_yaml::to_upf_config(upf_config& cfg) {
cfg.sbi.addr4 = local().get_sbi().get_addr4();
cfg.sbi.if_name = local().get_sbi().get_if_name();
cfg.enable_bpf_datapath =
upf_local->get_support_features().get_option_enable_bpf_datapath();
cfg.enable_snat = upf_local->get_support_features().get_option_enable_snat();
cfg.enable_bpf_datapath = upf_local->get_support_features().get_option_enable_bpf_datapath();
cfg.enable_qos = upf_local->get_support_features().get_option_enable_qos();
cfg.enable_snat = upf_local->get_support_features().get_option_enable_snat();
auto snssai_upf_list = upf_local->get_upf_info().getSNssaiUpfInfoList();
for (const auto& snssai : snssai_upf_list) {
......
......@@ -39,6 +39,9 @@ constexpr auto UPF_CONFIG_SUPPORT_FEATURES_ENABLE_BPF_LABEL =
constexpr auto UPF_CONFIG_SUPPORT_FEATURES_ENABLE_SNAT = "enable_snat";
constexpr auto UPF_CONFIG_SUPPORT_FEATURES_ENABLE_SNAT_LABEL = "Enable SNAT";
constexpr auto UPF_CONFIG_SUPPORT_FEATURES_ENABLE_QOS = "enable_qos";
constexpr auto UPF_CONFIG_SUPPORT_FEATURES_ENABLE_QOS_LABEL = "Enable QoS";
constexpr auto UPF_CONFIG_REMOTE_N6_GW = "remote_n6_gw";
constexpr auto UPF_CONFIG_REMOTE_N6_GW_LABEL = "Remote N6 Gateway";
......@@ -52,15 +55,17 @@ namespace oai::config {
class upf_support_features : public config_type {
private:
option_config_value m_enable_bpf_datapath{};
option_config_value m_enable_qos{};
option_config_value m_enable_snat{};
public:
explicit upf_support_features(bool enable_bpf_datapath, bool enable_snat);
explicit upf_support_features(bool enable_bpf_datapath, bool enable_qos, bool enable_snat);
void from_yaml(const YAML::Node& node) override;
[[nodiscard]] std::string to_string(const std::string& indent) const override;
[[nodiscard]] bool get_option_enable_bpf_datapath() const;
[[nodiscard]] bool get_option_enable_qos() const;
[[nodiscard]] bool get_option_enable_snat() const;
};
......
......@@ -17,7 +17,7 @@
// INTERFACE_VALUE_5G_VN_INTERNAL = 4
// };
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
typedef struct source_interface {
ie_base_t_ base;
u8 interface_value;
......
......@@ -24,7 +24,7 @@
#include <string.h> //Needed for memcpy
#include "bpf_endian.h"
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// TODO: Put dummy in test folder.
/**
* WARNING: Redirect require an XDP bpf_prog loaded on the TX device.
......@@ -36,7 +36,7 @@ int xdp_redirect_gtpu(struct xdp_md* p_ctx) {
return XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Update MAC address
*
......@@ -60,7 +60,7 @@ static u32 update_dst_mac_address(u32 ip, struct ethhdr* p_eth) {
return 0;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static u32 get_ip_address_from_map(e_reference_point key) {
struct s_interface* map_element =
bpf_map_lookup_elem(&m_upf_interfaces, &key);
......@@ -76,7 +76,7 @@ static u32 get_ip_address_from_map(e_reference_point key) {
return XDP_DROP;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static u32 create_outer_header_gtpu_ipv4(
struct xdp_md* p_ctx, pfcp_far_t_* p_far) {
bpf_debug("Create Outer Header GTPU_IPv4");
......@@ -238,7 +238,7 @@ static u32 create_outer_header_gtpu_ipv4(
bpf_debug("GTPU header were pushed!");
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Apply forwarding action rules.
*
......@@ -333,7 +333,7 @@ static u32 pfcp_far_apply(struct xdp_md* p_ctx, pfcp_far_t_* p_far) {
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
SEC("xdp_far")
int far_entry_point(struct xdp_md* p_ctx) {
bpf_debug("==========< FAR CONTEXT >==========");
......@@ -352,4 +352,4 @@ int far_entry_point(struct xdp_md* p_ctx) {
}
char _license[] SEC("license") = "GPL";
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
......@@ -11,7 +11,7 @@
#define ARP_ENTRIES_MAX_SIZE 12
#define FAR_TAILS_MAX 1
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The unique FAR that will be consumed in this program.
struct bpf_map_def SEC("maps") m_far = {
......@@ -21,7 +21,7 @@ struct bpf_map_def SEC("maps") m_far = {
.max_entries = FAR_TAILS_MAX, // 1,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_redirect_interfaces = {
.type = BPF_MAP_TYPE_DEVMAP,
.key_size = sizeof(u32), // id
......@@ -29,7 +29,7 @@ struct bpf_map_def SEC("maps") m_redirect_interfaces = {
.max_entries = MAX_INTERFACES, // 10,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Static ARP Table. Used to get the MAC address of the next hop.
// TODO: Pin this maps. It does not depend on the session program
// struct bpf_map_def SEC("maps") m_arp_table = {
......@@ -46,7 +46,7 @@ struct bpf_map_def SEC("maps") m_arp_table = {
.max_entries = ARP_ENTRIES_MAX_SIZE, // 2,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// BPF_ANNOTATE_KV_PAIR(m_far, u8, pfcp_far_t_);
// BPF_ANNOTATE_KV_PAIR(m_redirect_interfaces, u32, u32);
// BPF_ANNOTATE_KV_PAIR(m_arp_table, u32, ??);
......
......@@ -8,7 +8,7 @@
#define INTERFACE_ENTRIES_MAX 12
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_upf_interfaces = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(e_reference_point),
......
......@@ -20,7 +20,7 @@
#define INTERFACE_ENTRIES_MAX 12
#define MAX_UEs 100000
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Maps TEID to PFCP_Session_PDR_LookupProgram
struct bpf_map_def SEC("maps") m_teid_session = {
......@@ -33,7 +33,7 @@ struct bpf_map_def SEC("maps") m_teid_session = {
.max_entries = MAX_LENGTH, // 10000, //!< TODO: Is it enought?
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Maps UE IPv4 address to PFCP_Session_PDR_LookupProgram
// FIXME: Select a primary key. We could use a hash value of the IP as a key.
......@@ -47,7 +47,7 @@ struct bpf_map_def SEC("maps") m_ueip_session = {
.max_entries = MAX_UEs, //!< TODO: Is it enought?
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_ue_ip_pdr = {
.type = BPF_MAP_TYPE_HASH,
......@@ -56,7 +56,7 @@ struct bpf_map_def SEC("maps") m_ue_ip_pdr = {
.max_entries = MAX_UEs,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_next_rule_prog_index = {
.type = BPF_MAP_TYPE_HASH,
......@@ -65,7 +65,7 @@ struct bpf_map_def SEC("maps") m_next_rule_prog_index = {
.max_entries = MAX_LENGTH, // 10,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_upf_interfaces = {
.type = BPF_MAP_TYPE_HASH,
......@@ -74,7 +74,7 @@ struct bpf_map_def SEC("maps") m_upf_interfaces = {
.max_entries = INTERFACE_ENTRIES_MAX, // 6,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// struct bpf_map_def SEC("maps") m_session_mapping = {
// .type = BPF_MAP_TYPE_HASH,
......@@ -91,7 +91,7 @@ struct bpf_map_def SEC("maps") m_session_mapping = {
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// struct bpf_map_def SEC("maps") m_traffic_classification = {
// .type = BPF_MAP_TYPE_HASH,
......@@ -100,7 +100,7 @@ struct bpf_map_def SEC("maps") m_session_mapping = {
// .max_entries = MAX_LENGTH,
// };
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// struct bpf_map_def SEC("maps") m_ue_qfi_teid = {
// .type = BPF_MAP_TYPE_HASH,
......@@ -109,7 +109,7 @@ struct bpf_map_def SEC("maps") m_session_mapping = {
// .max_entries = MAX_LENGTH,
// };
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// struct bpf_map_def SEC("maps") m_qos_flow_map = {
// .type = BPF_MAP_TYPE_HASH,
......
......@@ -13,7 +13,7 @@
#define FAR_ENTRIES_MAX_SIZE 5000 // 10
#define ARP_ENTRIES_MAX_SIZE 12
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_fars = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(u32), // teid
......@@ -21,7 +21,7 @@ struct bpf_map_def SEC("maps") m_fars = {
.max_entries = FAR_ENTRIES_MAX_SIZE,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_redirect_interfaces = {
.type = BPF_MAP_TYPE_DEVMAP,
.key_size = sizeof(u32), // id
......@@ -29,7 +29,7 @@ struct bpf_map_def SEC("maps") m_redirect_interfaces = {
.max_entries = MAX_LENGTH, // 10,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Uplink map.
// TODO: Store multiple PDR.
struct bpf_map_def SEC("maps") m_teid_pdr = {
......@@ -39,7 +39,7 @@ struct bpf_map_def SEC("maps") m_teid_pdr = {
.max_entries = PDR_ENTRIES_MAX_SIZE, // 10,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Downlink map.
// TODO: Store multiple PDR.
struct bpf_map_def SEC("maps") m_ueip_pdr = {
......@@ -49,7 +49,7 @@ struct bpf_map_def SEC("maps") m_ueip_pdr = {
.max_entries = PDR_ENTRIES_MAX_SIZE, // 10,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// Static ARP Table. Used to get the MAC address of the next hop.
// TODO: Pin this maps. It does not depend on the session program
struct bpf_map_def SEC("maps") m_arp_table = {
......
......@@ -31,7 +31,7 @@
#include "xdp_stats_kern.h"
#include "xdp_stats_kern_user.h"
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static u32 tail_call_next_prog(
struct xdp_md* p_ctx, teid_t_ teid, u8 source_value, u32 ipv4_address) {
......@@ -61,7 +61,7 @@ static u32 tail_call_next_prog(
return XDP_DROP;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static u32 handle_downlink_traffic(struct xdp_md* p_ctx, u32 ue_ip_address) {
struct session_id* session = NULL;
......@@ -80,7 +80,7 @@ static u32 handle_downlink_traffic(struct xdp_md* p_ctx, u32 ue_ip_address) {
return XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* Uplink SECTION.
*/
......@@ -146,7 +146,7 @@ static u32 handle_uplink_traffic(struct xdp_md* p_ctx, struct udphdr* udph) {
return XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* IP SECTION.
......@@ -187,7 +187,7 @@ static u32 ipv4_handle(struct xdp_md* p_ctx, struct iphdr* iph) {
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* ETHERNET SECTION.
*/
......@@ -248,7 +248,7 @@ static u32 eth_handle(struct xdp_md* p_ctx, struct ethhdr* ethh) {
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
SEC("xdp_entry_point")
int entry_point(struct xdp_md* p_ctx) {
bpf_debug("==========< PFCP Session Lookup >==========");
......@@ -265,4 +265,4 @@ int entry_point(struct xdp_md* p_ctx) {
char _license[] SEC("license") = "GPL";
/*****************************************************************************************************************/
\ No newline at end of file
/*---------------------------------------------------------------------------------------------------------------*/
\ No newline at end of file
......@@ -21,7 +21,7 @@
#include <pfcp_session_lookup_maps.h>
#include <string.h> //Needed for memcpy
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// TODO: Put dummy in test folder.
// /**
// * WARNING: Redirect require an XDP bpf_prog loaded on the TX device.
......@@ -33,7 +33,7 @@
// return XDP_PASS;
// }
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// /**
// * @brief Update MAC address
// *
......@@ -55,7 +55,7 @@
// return XDP_PASS;
// }
// /*****************************************************************************************************************/
// /*---------------------------------------------------------------------------------------------------------------*/
// static u32 create_outer_header_gtpu_ipv4(
// struct xdp_md* p_ctx, pfcp_far_t_* p_far) {
// bpf_debug("Create Outer Header GTPU_IPv4\n");
......@@ -216,7 +216,7 @@
// bpf_debug("GTPU header were pushed!\n");
// }
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// /**
// * @brief Apply forwarding action rules.
// *
......@@ -321,7 +321,7 @@
// return XDP_PASS;
// }
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Match the PDRs attribuites for UL data flow.
......@@ -365,7 +365,7 @@ static u32 pfcp_pdr_match_pdi_access(
return XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Match the PDRs attribuites for DL data flow.
* - Destination IP from IP header with source address stored in PDI.
......@@ -407,7 +407,7 @@ static u32 pfcp_pdr_match_pdi_downlink(
return XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static u32 tail_call_next_prog(
struct xdp_md* p_ctx, teid_t_ teid, u8 source_value, u32 ipv4_address) {
struct next_rule_prog_index_key map_key;
......@@ -440,7 +440,7 @@ static u32 tail_call_next_prog(
return 0;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Lookup all PDRs based on teid.
* After that, for each PDR, check the its attribuites with match with access
......@@ -510,7 +510,7 @@ static u32 pfcp_pdr_lookup_uplink(struct xdp_md* p_ctx) {
return XDP_DROP; // XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Lookup all PDRs based on IP.
* After that, for each PDR, check the its attribuites with match with access
......@@ -575,7 +575,7 @@ static u32 pfcp_pdr_lookup_downlink(struct xdp_md* p_ctx) {
bpf_debug("FAR was NOT Found\n");
return XDP_DROP; // XDP_PASS;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
SEC("xdp_uplink_entry_point")
int uplink_entry_point(struct xdp_md* p_ctx) {
......@@ -590,4 +590,4 @@ int downlink_entry_point(struct xdp_md* p_ctx) {
}
char _license[] SEC("license") = "GPL";
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
......@@ -167,7 +167,7 @@
// }
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Filter the Uplink traffic
*
......@@ -260,7 +260,7 @@ static __always_inline u32 uplink_sdf_filter(struct __sk_buff *skb, struct ethhd
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
static __always_inline u32 downlink_sdf_filter(struct __sk_buff *skb, struct ethhdr* ethh, struct iphdr* iph) {
void* data_end = (void*) (long) skb->data_end;
......@@ -336,7 +336,7 @@ static __always_inline u32 downlink_sdf_filter(struct __sk_buff *skb, struct eth
return TC_ACT_OK;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* IP SECTION.
*/
......@@ -374,7 +374,7 @@ static __always_inline u32 ipv4_sdf_filter(struct __sk_buff *skb, struct ethhdr*
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Filter traffic according to ETH_TYPE
......@@ -428,7 +428,7 @@ static __always_inline u32 sdf_filter(struct __sk_buff *skb, struct ethhdr* ethh
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief sections to be ran as eBPF tc code
......@@ -533,4 +533,4 @@ int egress_filter_entry_point(struct __sk_buff *skb) {
}
char _license[] SEC("license") = "GPL";
/*****************************************************************************************************************/
\ No newline at end of file
/*---------------------------------------------------------------------------------------------------------------*/
\ No newline at end of file
......@@ -10,7 +10,7 @@
#define QFI_MAX_ENTRIES 5000
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_gtp_u_tunnel = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(struct gtp_u_tunnel), // < teid_ul, teid_dl >
......@@ -18,16 +18,12 @@ struct bpf_map_def SEC("maps") m_gtp_u_tunnel = {
.max_entries = QFI_MAX_ENTRIES,
};
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
struct bpf_map_def SEC("maps") m_filter = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(struct filter_key),
.value_size = sizeof(e_qfi),
.key_size = sizeof(struct filter_key), // < src_ip, dst_ip, protocol, dst_port >
.value_size = sizeof(e_qfi), // QFI
.max_entries = QFI_MAX_ENTRIES,
};
#endif // __QER_MAPS_H__
\ No newline at end of file
message("Searching for Linux netlink library")
if (LibNL_FIND_REQUIRED)
message(" (required)")
else (LibNL_FIND_REQUIRED)
message(" (not required)")
endif (LibNL_FIND_REQUIRED)
find_path(LibNL_INCLUDE_DIR netlink/netlink.h
/usr/include
/usr/include/libnl3
/usr/local/include
/usr/local/include/libnl3
)
find_library(LibNL_LIBRARY NAMES nl nl-3)
find_library(LibNL_ROUTE_LIBRARY NAMES nl-route nl-route-3)
find_library(LibNL_NETFILTER_LIBRARY NAMES nl-nf nl-nf-3)
find_library(LibNL_GENL_LIBRARY NAMES nl-genl nl-genl-3)
if (LibNL_INCLUDE_DIR AND LibNL_LIBRARY)
set(LibNL_FOUND TRUE)
endif (LibNL_INCLUDE_DIR AND LibNL_LIBRARY)
if (LibNL_FOUND)
if (NOT LibNL_FIND_QUIETLY)
set(LibNL_LIBRARIES ${LibNL_LIBRARY} ${LibNL_ROUTE_LIBRARY} ${LibNL_NETFILTER_LIBRARY} ${LibNL_GENL_LIBRARY})
message("Found netlink libraries: ${LibNL_LIBRARIES}")
message("Found netlink includes: ${LibNL_INCLUDE_DIR}")
endif (NOT LibNL_FIND_QUIETLY)
ELSE (LibNL_FOUND)
if (LibNL_FIND_REQUIRED)
message("Netlink version 3 development packages cannot be found.")
message("In Debian/Ubuntu, they may be called:")
message("libnl-3-dev libnl-genl-3dev libnl-nf-3-dev libnl-route-3-dev")
message(FATAL_ERROR "Could not find netlink library.")
endif (LibNL_FIND_REQUIRED)
endif (LibNL_FOUND)
#include "GetNicInformation.hpp"
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <types.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <fstream>
#include <string>
#include <stdexcept>
#include <arpa/inet.h>
#define COMMAND_MAX_LENGTH 256
#define OUTPUT_MAX_LENGTH 256
/*---------------------------------------------------------------------------------------------------------------*/
// Function to read a value from a file
std::string readValueFromFile(const std::string& path) {
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "Error: Failed to open file " << path << std::endl;
return "";
}
std::string value;
file >> value;
file.close();
return value;
}
NicInfromationGetter::NicInfromationGetter() {}
/*---------------------------------------------------------------------------------------------------------------*/
// const char *NicInfromationGetter::setScheduler(const char*) {
// }
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t NicInfromationGetter::retrieveRate(std::string interface) {
// Paths to files containing interface information speed rate
std::string speedPath = INTERFACE_DIR + interface + "/speed";
// Read speed
std::string speed = readValueFromFile(speedPath);
uint32_t rate = 0;
std::istringstream iss(speed);
iss >> rate;
return rate;
}
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t NicInfromationGetter::retrieveCeil(std::string interface) {
// Paths to files containing interface information speed rate
std::string speedPath = INTERFACE_DIR + interface + "/speed";
// Read speed
std::string speed = readValueFromFile(speedPath);
uint32_t ceil = 0;
std::istringstream iss(speed);
iss >> ceil;
return ceil;
}
uint32_t NicInfromationGetter::retrieveCeil(std::string interface) {
return NicInfromationGetter::retrieveRate(interface);
}
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t NicInfromationGetter::retrieveRateBuffer(std::string interface) {
// char command[COMMAND_MAX_LENGTH];
// struct in_addr addr;
// addr.s_addr = next_hop_ip;
// char* ipAddress = inet_ntoa(addr);
// if (ipAddress == nullptr) {
// Logger::upf_app().error("The Next Hop IPv4 WAS NOT Retrieved");
// throw std::runtime_error("The Next Hop IPv4 WAS NOT Retrieved");
// }
// sprintf(command, "sudo arping -c 1 %s | awk '/from/ {print $4}'", ipAddress);
// // Logger::upf_app().debug("Next Hop SRC IP = %s", ipAddress);
// Logger::upf_app().debug(
// "Next Hop <SRC IP, MAC Address> = <%s, %s>", ipAddress,
// executeCommand(command).c_str());
// ether_addr* next_hop_mac = {};
// next_hop_mac = ether_aton(executeCommand(command).c_str());
// if (next_hop_mac == nullptr) {
// Logger::upf_app().error("The Next Hop MAC WAS NOT Retrieved");
// throw std::runtime_error("The Next Hop MAC WAS NOT Retrieved");
// }
// return next_hop_mac;
}
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t NicInfromationGetter::retrieveCeilBuffer(std::string interface) {
}
/*---------------------------------------------------------------------------------------------------------------*/
std::string NicInfromationGetter::executeCommand(const std::string& command) {
char output[OUTPUT_MAX_LENGTH];
FILE* fp = popen(command.c_str(), "r");
if (fp == nullptr) {
Logger::upf_app().error("Failed to Run the Command: %s\n", command.c_str());
return "";
}
fgets(output, OUTPUT_MAX_LENGTH, fp);
pclose(fp);
return output;
}
/*---------------------------------------------------------------------------------------------------------------*/
#ifndef __Get_NIC_INFORMATION_HPP__
#define __Get_NIC_INFORMATION_HPP__
#include <string>
#include <memory>
#include <netinet/ether.h>
#include "logger.hpp"
class NicInfromationGetter {
public:
/**
* @brief Construct a new Nic Information Getter object
*
*/
NicInformationGetter();
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Set the Scheduler object
*
* @return const char*
*/
//const char *setScheduler(const char*);
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Retrieve the Transmission Rate of NIC
*
* @return uint32_t rate
*/
uint32_t retrieveRate(std::string interface);
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Retrieve the Ceil transmission of NIC
*
* @return uint32_t ceil
*/
uint32_t retrieveCeil(std::string interface);
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Retrieve the Rate Buffer of the NIC
*
* @return uint32_t rate_buffer
*/
uint32_t retrieveRateBuffer(std::string interface);
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Retrieve the Ceil Buffer of the NIC
*
* @return uint32_t ceil_buffer
*/
uint32_t retrieveCeilBuffer(std::string interface);
/*---------------------------------------------------------------------------------------------------------------*/
private:
const std::string INTERFACE_DIR = "/sys/class/net/";
//std::string executeCommand(const std::string& command);
};
#endif //__Get_NIC_INFORMATION_HPP__
\ No newline at end of file
......@@ -19,10 +19,10 @@
#define COMMAND_MAX_LENGTH 256
#define OUTPUT_MAX_LENGTH 256
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
NextHopFinder::NextHopFinder() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int NextHopFinder::calculateSubnetMask(uint32_t ip) {
int mask = 0;
uint32_t temp = ip;
......@@ -35,7 +35,7 @@ int NextHopFinder::calculateSubnetMask(uint32_t ip) {
return mask;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int NextHopFinder::sameSubnet(uint32_t ip1, uint32_t ip2) {
int subnet_mask = calculateSubnetMask(ip1);
uint32_t mask = 0xFFFFFFFFU << (32 - subnet_mask);
......@@ -43,7 +43,7 @@ int NextHopFinder::sameSubnet(uint32_t ip1, uint32_t ip2) {
return (ip1 & mask) == (ip2 & mask);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
u_int32_t NextHopFinder::retrieveNextHopIP(uint32_t destination_ip) {
char command[COMMAND_MAX_LENGTH];
......@@ -67,7 +67,7 @@ u_int32_t NextHopFinder::retrieveNextHopIP(uint32_t destination_ip) {
return next_hop_ip;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
ether_addr* NextHopFinder::retrieveNextHopMAC(uint32_t next_hop_ip) {
char command[COMMAND_MAX_LENGTH];
......@@ -98,7 +98,7 @@ ether_addr* NextHopFinder::retrieveNextHopMAC(uint32_t next_hop_ip) {
return next_hop_mac;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::string NextHopFinder::executeCommand(const std::string& command) {
char output[OUTPUT_MAX_LENGTH];
FILE* fp = popen(command.c_str(), "r");
......@@ -113,4 +113,4 @@ std::string NextHopFinder::executeCommand(const std::string& command) {
return output;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
#ifndef __QDISC_PARAMETERS_H__
#define __QDISC_PARAMETERS_H__
#include <types.h>
struct qdisc_params {
const char *scheduler;
uint32_t rate;
uint32_t ceil;
uint32_t rate_buffer;
uint32_t ceil_buffer;
// uint32_t quantum;
// int level;
};
#endif //__QDISC_PARAMETERS_H__
\ No newline at end of file
#include "BPFProgram.h"
#include "logger.hpp"
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
u_int32_t BPFProgram::sIdCounter = 1;
BPFProgram::BPFProgram(/* args */) : mId(sIdCounter) {
sIdCounter++;
Logger::upf_app().info("BPFProgram %d is created!!!", mId);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
BPFProgram::~BPFProgram() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t BPFProgram::getId() const {
return mId;
}
/*****************************************************************************************************************/
\ No newline at end of file
/*---------------------------------------------------------------------------------------------------------------*/
\ No newline at end of file
......@@ -12,7 +12,7 @@
using namespace oai::config;
extern upf_config upf_cfg;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
FARProgram::FARProgram() : BPFProgram() {
mpLifeCycle = std::make_shared<FARProgramLifeCycle>(
far_ebpf_xdp_prgrm_kernel_c__open, far_ebpf_xdp_prgrm_kernel_c__load,
......@@ -20,10 +20,10 @@ FARProgram::FARProgram() : BPFProgram() {
far_ebpf_xdp_prgrm_kernel_c__destroy);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
FARProgram::~FARProgram() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void FARProgram::create_upf_interface_map_entry(e_reference_point s) {
struct s_interface iface;
__builtin_memset(&iface, 0, sizeof(s_interface));
......@@ -61,7 +61,7 @@ void FARProgram::create_upf_interface_map_entry(e_reference_point s) {
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void FARProgram::setup() {
spSkeleton = mpLifeCycle->open();
initializeMaps();
......@@ -84,44 +84,44 @@ void FARProgram::setup() {
create_upf_interface_map_entry(N4_INTERFACE);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMaps> FARProgram::getMaps() {
return mpMaps;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// TODO: Check when kill when running.
// It was noted the infinity loop.
void FARProgram::tearDown() {
mpLifeCycle->tearDown();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> FARProgram::getFARMap() const {
return mpFARMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> FARProgram::getEgressInterfaceMap() const {
return mpEgressInterfaceMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int FARProgram::getFd() const {
return bpf_program__fd(mpLifeCycle->getBPFSkeleton()->progs.far_entry_point);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> FARProgram::getArpTableMap() const {
return mpArpTableMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> FARProgram::getIfaceMap() const {
return mpUPFIfaceMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void FARProgram::initializeMaps() {
// Store all maps available in the program.
mpMaps = std::make_shared<BPFMaps>(mpLifeCycle->getBPFSkeleton()->skeleton);
......@@ -133,4 +133,4 @@ void FARProgram::initializeMaps() {
std::make_shared<BPFMap>(mpMaps->getMap("m_redirect_interfaces"));
mpUPFIfaceMap = std::make_shared<BPFMap>(mpMaps->getMap("m_upf_interfaces"));
}
/*****************************************************************************************************************/
\ No newline at end of file
/*---------------------------------------------------------------------------------------------------------------*/
\ No newline at end of file
......@@ -32,20 +32,20 @@ class FARProgram : public BPFProgram {
*/
explicit FARProgram();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Destroy the FARProgram object
*/
virtual ~FARProgram();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Insert one UPF reference point interface into a map.
*
*/
void create_upf_interface_map_entry(e_reference_point s);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Setup the BPF program.
......@@ -53,7 +53,7 @@ class FARProgram : public BPFProgram {
*/
void setup();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the BPFMaps object.
*
......@@ -61,13 +61,13 @@ class FARProgram : public BPFProgram {
*/
std::shared_ptr<BPFMaps> getMaps();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Tear downs the BPF program.
*
*/
void tearDown();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Update program int map.
......@@ -77,7 +77,7 @@ class FARProgram : public BPFProgram {
*/
void updateProgramMap(uint32_t key, uint32_t fd);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove program in map.
*
......@@ -85,7 +85,7 @@ class FARProgram : public BPFProgram {
*/
void removeProgramMap(uint32_t key);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the TEID to session Map object.
*
......@@ -93,7 +93,7 @@ class FARProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getFARMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Egress Interface Map object.
*
......@@ -101,7 +101,7 @@ class FARProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getEgressInterfaceMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Arp Table Map object.
*
......@@ -109,7 +109,7 @@ class FARProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getArpTableMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the iface Map object.
*
......@@ -117,7 +117,7 @@ class FARProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getIfaceMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the File Descriptor.
*
......@@ -125,7 +125,7 @@ class FARProgram : public BPFProgram {
*/
int getFd() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
private:
/**
* @brief Initialize BPF wrappers maps.
......@@ -133,35 +133,35 @@ class FARProgram : public BPFProgram {
*/
void initializeMaps();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The reference of the bpf maps.
std::shared_ptr<BPFMaps> mpMaps;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The skeleton of the UPF program generated by bpftool.
// ProgramLifeCycle is the owner of the pointer.
far_ebpf_xdp_prgrm_kernel_c* spSkeleton;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The program eBPF map.
std::shared_ptr<BPFMap> mpFARMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The egress interface map.
std::shared_ptr<BPFMap> mpEgressInterfaceMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The arp table map.
std::shared_ptr<BPFMap> mpArpTableMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The BPF lifecycle program.
std::shared_ptr<FARProgramLifeCycle> mpLifeCycle;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The iface map.
std::shared_ptr<BPFMap> mpUPFIfaceMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
};
#endif // __FAR_EBPF_XDP_PRGRM_USER_H__
......@@ -44,7 +44,7 @@
// //#define DSCP_8 8 // 001000
// #define DSCP_DEFAULT 0 // 000000
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int is_little_endian2() {
u32 value = 1;
......@@ -52,7 +52,7 @@ int is_little_endian2() {
return (*byte == 1);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
PFCP_Session_LookupProgram::PFCP_Session_LookupProgram(
const std::string& gtpInterface, const std::string& udpInterface)
: mGTPInterface(gtpInterface), mUDPInterface(udpInterface) {
......@@ -63,10 +63,10 @@ PFCP_Session_LookupProgram::PFCP_Session_LookupProgram(
pfcp_session_lookup_ebpf_xdp_prgrm_kernel_c__destroy);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
PFCP_Session_LookupProgram::~PFCP_Session_LookupProgram() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void PFCP_Session_LookupProgram::setup() {
spSkeleton = mpLifeCycle->open();
initializeMaps();
......@@ -100,24 +100,24 @@ void PFCP_Session_LookupProgram::setup() {
// NON_GBR, QOS_DEFAULT, QFI_DEFALUT, DSCP_DEFAULT);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMaps> PFCP_Session_LookupProgram::getMaps() {
return mpMaps;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// TODO: Check when kill when running.
// It was noted the infinity loop.
void PFCP_Session_LookupProgram::tearDown() {
mpLifeCycle->tearDown();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void PFCP_Session_LookupProgram::updateProgramMap(uint32_t key, uint32_t fd) {
mpTeidSessionMap->update(key, fd, BPF_ANY);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void PFCP_Session_LookupProgram::removeProgramMap(uint32_t key) {
s32 fd;
// Remove only if exists.
......@@ -126,52 +126,52 @@ void PFCP_Session_LookupProgram::removeProgramMap(uint32_t key) {
}
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getTeidSessionMap() const {
return mpTeidSessionMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getUeIpSessionMap() const {
return mpUeIpSessionMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getNextProgRuleMap() const {
return mpNextProgRuleMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getNextProgRuleIndexMap()
const {
return mpNextProgRuleIndexMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getSessionMappingMap()
const {
return mpSessionMappingMap;
}
// /*****************************************************************************************************************/
// /*---------------------------------------------------------------------------------------------------------------*/
// std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getTrafficMap() const {
// return mpTrafficMap;
// }
// /*****************************************************************************************************************/
// /*---------------------------------------------------------------------------------------------------------------*/
// std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getUeQfiTeidMap() const {
// return mpUeQfiTeidMap;
// }
// /*****************************************************************************************************************/
// /*---------------------------------------------------------------------------------------------------------------*/
// std::shared_ptr<BPFMap> PFCP_Session_LookupProgram::getQosFlowMap() const {
// return mpQosFlowMap;
// }
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void PFCP_Session_LookupProgram::initializeMaps() {
// Store all maps available in the program.
......@@ -193,7 +193,7 @@ void PFCP_Session_LookupProgram::initializeMaps() {
// std::make_shared<BPFMap>(mpMaps->getMap("m_qos_flow_map"));
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// void PFCP_Session_LookupProgram::instrementQfiFlowMappingTable(
// e_resource_type type, uint32_t qos, uint8_t qfi, uint8_t dscp) {
......
......@@ -31,20 +31,20 @@ class PFCP_Session_LookupProgram {
explicit PFCP_Session_LookupProgram(
const std::string& gtpInterface, const std::string& udpInterface);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Destroy the PFCP_Session_LookupProgram object
*/
virtual ~PFCP_Session_LookupProgram();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Setup the BPF program.
*
*/
void setup();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the BPFMaps object.
*
......@@ -52,14 +52,14 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMaps> getMaps();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Tear downs the BPF program.
*
*/
void tearDown();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Update program int map.
*
......@@ -68,7 +68,7 @@ class PFCP_Session_LookupProgram {
*/
void updateProgramMap(uint32_t key, uint32_t fd);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove program in map.
*
......@@ -76,7 +76,7 @@ class PFCP_Session_LookupProgram {
*/
void removeProgramMap(uint32_t key);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the TEID to session Map object.
*
......@@ -84,7 +84,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getTeidSessionMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the UE IP to session Map object.
*
......@@ -92,7 +92,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getUeIpSessionMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the NextProgRule Map object.
*
......@@ -100,7 +100,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getNextProgRuleMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the NextProgRuleIndex Map object.
*
......@@ -108,7 +108,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getNextProgRuleIndexMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Traffic Map object.
*
......@@ -116,7 +116,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getTrafficMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Session Mapping Map object.
*
......@@ -124,7 +124,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getSessionMappingMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the UE QFI TEID Map object.
*
......@@ -139,7 +139,7 @@ class PFCP_Session_LookupProgram {
*/
std::shared_ptr<BPFMap> getQosFlowMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
private:
/**
......@@ -151,61 +151,61 @@ class PFCP_Session_LookupProgram {
// void instrementQfiFlowMappingTable(
// e_resource_type type, uint32_t qos, uint8_t qfi, uint8_t dscp);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The reference of the bpf maps.
std::shared_ptr<BPFMaps> mpMaps;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The skeleton of the UPF program generated by bpftool.
// ProgramLifeCycle is the owner of the pointer.
pfcp_session_lookup_ebpf_xdp_prgrm_kernel_c* spSkeleton;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The program eBPF map.
std::shared_ptr<BPFMap> mpTeidSessionMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The program eBPF map.
std::shared_ptr<BPFMap> mpUeIpSessionMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The pdi key to program index map.
std::shared_ptr<BPFMap> mpNextProgRuleIndexMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The next prog rule map.
std::shared_ptr<BPFMap> mpNextProgRuleMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The traffic map.
// std::shared_ptr<BPFMap> mpTrafficMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The session mapping map.
std::shared_ptr<BPFMap> mpSessionMappingMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The UE-QFI-TEID map.
// std::shared_ptr<BPFMap> mpUeQfiTeidMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The QOS Flow map.
// std::shared_ptr<BPFMap> mpQosFlowMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The BPF lifecycle program.
std::shared_ptr<PFCP_Session_LookupProgramLifeCycle> mpLifeCycle;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The GTP interface.
std::string mGTPInterface;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The UDP interface.
std::string mUDPInterface;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
};
#endif // __PFCP_SESSION_LOOKUP_EBPF_XDP_PRGRM_USER_H__
......@@ -7,7 +7,7 @@
#include <wrappers/BPFMaps.h>
#include <wrappers/BPFMap.hpp>
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
PFCP_Session_PDR_LookupProgram::PFCP_Session_PDR_LookupProgram(
const std::string& gtpInterface, const std::string& udpInterface)
: mGTPInterface(gtpInterface), mUDPInterface(udpInterface) {
......@@ -18,10 +18,10 @@ PFCP_Session_PDR_LookupProgram::PFCP_Session_PDR_LookupProgram(
pfcp_session_pdr_lookup_ebpf_xdp_prgrm_kernel_c__destroy);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
PFCP_Session_PDR_LookupProgram::~PFCP_Session_PDR_LookupProgram() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// TODO: Pass configuration throught args.
void PFCP_Session_PDR_LookupProgram::setup() {
mpLifeCycle->open();
......@@ -30,57 +30,57 @@ void PFCP_Session_PDR_LookupProgram::setup() {
mpLifeCycle->attach();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void PFCP_Session_PDR_LookupProgram::tearDown() {
mpLifeCycle->tearDown();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int PFCP_Session_PDR_LookupProgram::getUplinkFileDescriptor() const {
return bpf_program__fd(
mpLifeCycle->getBPFSkeleton()->progs.uplink_entry_point);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
int PFCP_Session_PDR_LookupProgram::getDownlinkFileDescriptor() const {
return bpf_program__fd(
mpLifeCycle->getBPFSkeleton()->progs.downlink_entry_point);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_PDR_LookupProgram::getFARMap() const {
return mpFARMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_PDR_LookupProgram::getUplinkPDRsMap()
const {
return mpUplinkPDRsMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_PDR_LookupProgram::getDownlinkPDRsMap()
const {
return mpDownlinkPDRsMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_PDR_LookupProgram::getCounterMap() const {
return mpCounterMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_PDR_LookupProgram::getEgressInterfaceMap()
const {
return mpEgressInterfaceMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> PFCP_Session_PDR_LookupProgram::getArpTableMap() const {
return mpArpTableMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void PFCP_Session_PDR_LookupProgram::initializeMaps() {
// Store all maps available in the program.
mpMaps = std::make_shared<BPFMaps>(mpLifeCycle->getBPFSkeleton()->skeleton);
......@@ -95,4 +95,4 @@ void PFCP_Session_PDR_LookupProgram::initializeMaps() {
std::make_shared<BPFMap>(mpMaps->getMap("m_redirect_interfaces"));
mpArpTableMap = std::make_shared<BPFMap>(mpMaps->getMap("m_arp_table"));
}
/*****************************************************************************************************************/
\ No newline at end of file
/*---------------------------------------------------------------------------------------------------------------*/
\ No newline at end of file
......@@ -18,7 +18,7 @@ class BPFMap;
*/
class PFCP_Session_PDR_LookupProgram {
public:
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Construct a new Session Program object.
*
......@@ -26,28 +26,28 @@ class PFCP_Session_PDR_LookupProgram {
PFCP_Session_PDR_LookupProgram(
const std::string& gtpInterface, const std::string& udpInterface);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Destroy the Session Program object.
*
*/
virtual ~PFCP_Session_PDR_LookupProgram();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Setup the program.
*
*/
void setup();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Tear down the program.
*
*/
void tearDown();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Downlink File Descriptor (entry point) object.
*
......@@ -55,7 +55,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
int getUplinkFileDescriptor() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Uplink File Descriptor (entry point) object.
*
......@@ -63,7 +63,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
int getDownlinkFileDescriptor() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get PDR maps reference.
*
......@@ -71,7 +71,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getPDRMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the FAR Map object.
*
......@@ -79,7 +79,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getFARMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Uplink PDRs Map object.
*
......@@ -87,7 +87,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getUplinkPDRsMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Downlink PDRs Map object.
*
......@@ -95,7 +95,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getDownlinkPDRsMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Counter Map object.
*
......@@ -103,7 +103,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getCounterMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Egress Interface Map object.
*
......@@ -111,7 +111,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getEgressInterfaceMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Arp Table Map object.
*
......@@ -119,7 +119,7 @@ class PFCP_Session_PDR_LookupProgram {
*/
std::shared_ptr<BPFMap> getArpTableMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
private:
/**
* @brief Initialize BPF maps wrappers references.
......
......@@ -8,15 +8,16 @@
#include <wrappers/BPFMaps.h>
#include "interfaces.h"
#include "logger.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netlink/route/link.h>
#include <netlink/route/qdisc/htb.h>
/*****************************************************************************************************************/
int is_little_endian2() {
u32 value = 1;
u8* byte = (u8*) &value;
return (*byte == 1);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
QERProgram::QERProgram(
const std::string& gtpInterface, const std::string& udpInterface)
: mGTPInterface(gtpInterface), mUDPInterface(udpInterface) {
......@@ -27,10 +28,10 @@ QERProgram::QERProgram(
qer_ebpf_tc_prgrm_kernel_c__destroy);
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
QERProgram::~QERProgram() {}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void QERProgram::setup() {
spSkeleton = mpLifeCycle->open();
initializeMaps();
......@@ -38,29 +39,29 @@ void QERProgram::setup() {
mpLifeCycle->attach();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMaps> QERProgram::getMaps() {
return mpMaps;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// TODO: Check when kill when running.
// It was noted the infinity loop.
void QERProgram::tearDown() {
mpLifeCycle->tearDown();
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> QERProgram::geGtpUTunnelMap() const {
return mpGtpUTunnelMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
std::shared_ptr<BPFMap> QERProgram::getFilterMap() const {
return mpFilterMap;
}
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
void QERProgram::initializeMaps() {
// Store all maps available in the program.
......@@ -71,4 +72,171 @@ void QERProgram::initializeMaps() {
mpFilterMap = std::make_shared<BPFMap>(mpMaps->getMap("m_filter"));
}
/*****************************************************************************************************************/
\ No newline at end of file
/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/
struct nl_sock *create_socket(){
// Initialize Netlink socket
struct nl_sock *sock = nl_socket_alloc();
if (!sock) {
perror("nl_socket_alloc");
exit(EXIT_FAILURE);
}
// Connect to Netlink socket
if (nl_connect(sock, NETLINK_ROUTE) < 0) {
perror("nl_connect");
nl_socket_free(sock);
exit(EXIT_FAILURE);
}
return sock;
}
/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/
struct rtnl_tc *allocate_tc(struct rtnl_tc *tc, struct nl_sock *sock, struct rtnl_qdisc *qdisc){
// Allocate a new Traffic Control object
tc = rtnl_tc_alloc();
if (!tc) {
perror("rtnl_tc_alloc");
rtnl_qdisc_delete(sock, qdisc);
nl_close(sock);
nl_socket_free(sock);
exit(EXIT_FAILURE);
}
return tc;
}
/*---------------------------------------------------------------------------------------------------------------*/
void add_qdisc_to_interface(const char *interface, struct nl_sock *sock, struct rtnl_qdisc *qdisc, struct rtnl_tc *tc){
// Add the Qdisc to the interface (replace "eth0" with your interface name)
if (rtnl_tc_add(sock, tc, NLM_F_CREATE | NLM_F_EXCL, RTM_NEWQDISC, 0, interface) < 0) {
perror("rtnl_tc_add");
rtnl_tc_free(tc);
rtnl_qdisc_delete(sock, qdisc);
nl_close(sock);
nl_socket_free(sock);
exit(EXIT_FAILURE);
}
}
// /*---------------------------------------------------------------------------------------------------------------*/
// // Function to create and configure a Qdisc hierarchy
// void qer_tc::create_configure_hierarchy(struct rtnl_qdisc *root_qdisc, struct nl_sock *sock, qdisc_pdu_to_create, qdisc_qos_flows_to_create) {
// // Create and configure parent classes and their children as needed
// struct rtnl_qdisc *parent1 = create_parent_class(sock, seid);
// struct rtnl_qdisc *child1 = create_child_class(sock, parent1, qfi[i]);
// struct rtnl_qdisc *child2 = create_child_class(sock, parent1, qfi[j]);
// // Attach parent Qdisc to root Qdisc
// if (rtnl_qdisc_set_parent(parent1, root_qdisc) < 0) {
// perror("rtnl_qdisc_set_parent");
// exit(EXIT_FAILURE);
// }
// }
// /*---------------------------------------------------------------------------------------------------------------*/
// // Function to create and configure the Qdisc hierarchy
// void qer_tc::create_configure_hierarchy(struct nl_sock *sock, const char *interface, std::vector<std::vector<uint32_t>> child_ids) {
// // Create and configure parent classes
// for (size_t i = 0; i < child_ids.size(); ++i) {
// struct rtnl_qdisc *parent = create_parent_class(sock, interface, i + 1);
// parent_qdiscs.push_back(parent);
// // Create and attach child classes
// std::vector<struct rtnl_qdisc *> children;
// for (size_t j = 0; j < child_ids[i].size(); ++j) {
// struct rtnl_qdisc *child = create_child_class(sock, parent, child_ids[i][j]);
// children.push_back(child);
// }
// child_qdiscs.push_back(children);
// // Attach parent Qdisc to root Qdisc
// if (rtnl_qdisc_set_parent(parent, root_qdisc) < 0) {
// perror("rtnl_qdisc_set_parent");
// exit(EXIT_FAILURE);
// }
// }
// }
// /*---------------------------------------------------------------------------------------------------------------*/
// // Function to create a parent class
// struct rtnl_qdisc *qer_tc::create_parent_class(struct nl_sock *sock, const char *interface, uint32_t parent_id) {
// // Create parent Qdisc
// struct rtnl_qdisc *parent_qdisc = rtnl_qdisc_alloc();
// if (!parent_qdisc) {
// perror("rtnl_qdisc_alloc");
// exit(EXIT_FAILURE);
// }
// // Configure parent Qdisc as needed
// rtnl_htb_set_rate(parent_qdisc, rate);
// // Add parent Qdisc to the interface
// if (rtnl_tc_add(sock, parent_qdisc, NLM_F_CREATE | NLM_F_REPLACE, RTM_NEWQDISC, 0, interface) < 0) {
// perror("rtnl_tc_add");
// rtnl_qdisc_free(parent_qdisc);
// exit(EXIT_FAILURE);
// }
// return parent_qdisc;
// }
// /*---------------------------------------------------------------------------------------------------------------*/
// // Function to create a child class
// struct rtnl_qdisc *qer_tc::create_child_class(struct nl_sock *sock, struct rtnl_qdisc *parent, uint32_t child_id) {
// // Create child Qdisc
// struct rtnl_qdisc *child_qdisc = rtnl_qdisc_alloc();
// if (!child_qdisc) {
// perror("rtnl_qdisc_alloc");
// exit(EXIT_FAILURE);
// }
// // Configure child Qdisc as needed
// rtnl_htb_set_rate(child_qdisc, rate);
// // Add child Qdisc to the parent
// if (rtnl_qdisc_set_parent(child_qdisc, parent) < 0) {
// perror("rtnl_qdisc_set_parent");
// rtnl_qdisc_free(child_qdisc);
// exit(EXIT_FAILURE);
// }
// return child_qdisc;
// }
// #include "qer_tc.hpp"
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <netlink/route/link.h>
// // Constructor
// qer_tc::qer_tc(const char *kind, uint32_t rate) {
// params.kind = kind;
// params.rate = rate;
// // Initialize other parameters as needed
// }
......@@ -14,6 +14,11 @@
#include "interfaces.h"
#include <netlink/netlink.h>
#include <netlink/route/qdisc.h>
class BPFMaps;
class BPFMap;
class SessionManager;
......@@ -21,6 +26,7 @@ class RulesUtilities;
using QERProgramLifeCycle = ProgramLifeCycle<qer_ebpf_tc_prgrm_kernel_c>;
/**
* @brief Singleton class to abstract the UPF bpf tc program.
*/
......@@ -30,15 +36,15 @@ class QERProgram : public BPFProgram {
* @brief Construct a new QERProgram object.
*
*/
explicit QERProgram();
explicit QERProgram(const std::string& gtpInterface, const std::string& udpInterface);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Destroy the QERProgram object
*/
virtual ~QERProgram();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Setup the BPF program.
......@@ -46,7 +52,7 @@ class QERProgram : public BPFProgram {
*/
void setup();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the BPFMaps object.
*
......@@ -54,13 +60,13 @@ class QERProgram : public BPFProgram {
*/
std::shared_ptr<BPFMaps> getMaps();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Tear downs the BPF program.
*
*/
void tearDown();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Update program int map.
......@@ -70,15 +76,14 @@ class QERProgram : public BPFProgram {
*/
void updateProgramMap(uint32_t key, uint32_t fd);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Remove program in map.
*
* @param key The key which will be remove in the program map.
*/
void removeProgramMap(uint32_t key);
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the TEID to session Map object.
*
......@@ -86,7 +91,7 @@ class QERProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getQERMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Egress Interface Map object.
*
......@@ -94,7 +99,7 @@ class QERProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getEgressInterfaceMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the n3 GTP-U Tunnel Map object.
*
......@@ -103,7 +108,7 @@ class QERProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> geGtpUTunnelMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Get the Filter Map object.
*
......@@ -111,7 +116,46 @@ class QERProgram : public BPFProgram {
*/
std::shared_ptr<BPFMap> getFilterMap() const;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Create a configure hierarchy object
*
* @param sock
* @param interface
* @param child_ids
*/
void create_configure_hierarchy(struct nl_sock *sock, const char *interface, std::vector<std::vector<uint32_t>> child_ids);
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Create a parent parent class object
*
* @param sock
* @param interface
* @param parent_id
* @return * struct rtnl_qdisc*
*/
struct rtnl_qdisc *create_parent_class(struct nl_sock *sock, const char *interface, uint32_t parent_id);
/*---------------------------------------------------------------------------------------------------------------*/
/**
* @brief Create a child class object
*
* @param sock
* @param parent
* @param child_id
* @return struct rtnl_qdisc*
*/
struct rtnl_qdisc *create_child_class(struct nl_sock *sock, struct rtnl_qdisc *parent, uint32_t child_id);
/*---------------------------------------------------------------------------------------------------------------*/
private:
/**
* @brief Initialize BPF wrappers maps.
......@@ -119,24 +163,42 @@ class QERProgram : public BPFProgram {
*/
void initializeMaps();
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The reference of the bpf maps.
std::shared_ptr<BPFMaps> mpMaps;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The skeleton of the UPF program generated by bpftool.
// ProgramLifeCycle is the owner of the pointer.
qer_ebpf_tc_prgrm_kernel_c* spSkeleton;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The GTP-U Tunnel map.
std::shared_ptr<BPFMap> mpGtpUTunnelMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The BPF lifecycle program.
std::shared_ptr<QERProgramLifeCycle> mpLifeCycle;
/*---------------------------------------------------------------------------------------------------------------*/
// The Filter map.
std::shared_ptr<BPFMap> mpFilterMap;
/*****************************************************************************************************************/
/*---------------------------------------------------------------------------------------------------------------*/
// The GTP interface.
std::string mGTPInterface;
/*---------------------------------------------------------------------------------------------------------------*/
// The UDP interface.
std::string mUDPInterface;
/*---------------------------------------------------------------------------------------------------------------*/
std::vector<struct rtnl_qdisc *> parent_qdiscs;
std::vector<std::vector<struct rtnl_qdisc *>> child_qdiscs;
};
#endif // __QER_EBPF_TC_PRGRM_USER_H__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment