Skip to content
Snippets Groups Projects
Commit 3cfb0ada authored by Stefan Spettel's avatar Stefan Spettel
Browse files

feat(pcf): Implemented basic policy control procedures and reply with...

feat(pcf): Implemented basic policy control procedures and reply with hardcoded decision based on Snssai

Signed-off-by: Stefan Spettel's avatarStefan Spettel <stefan.spettel@eurecom.fr>
parent 827a657f
No related branches found
No related tags found
1 merge request!2Implement feature to create a policy via the SMPolicyControl API
......@@ -12,6 +12,9 @@
*/
#include "SMPoliciesCollectionApiImpl.h"
#include "sm_policy/pcf_sm_policy_control_errors.hpp"
#include "3gpp_29.500.h"
#include "logger.hpp"
namespace oai {
namespace pcf {
......@@ -20,6 +23,7 @@ namespace api {
using namespace oai::pcf::helpers;
using namespace oai::pcf::model;
using namespace oai::pcf::app;
using namespace oai::pcf::app::sm_policy;
SMPoliciesCollectionApiImpl::SMPoliciesCollectionApiImpl(
const std::shared_ptr<Pistache::Rest::Router>& rtr,
......@@ -32,7 +36,51 @@ SMPoliciesCollectionApiImpl::SMPoliciesCollectionApiImpl(
void SMPoliciesCollectionApiImpl::create_sm_policy(
const SmPolicyContextData& smPolicyContextData,
Pistache::Http::ResponseWriter& response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
int http_code = 500;
std::string cause;
ProblemDetails problem_details;
SmPolicyDecision decision;
std::string details_string = "";
pcf_smpc_error_code res = smpc_service->create_sm_policy_handler(
smPolicyContextData, decision, details_string);
nlohmann::json json_data;
switch (res) {
case pcf_smpc_error_code::Created:
http_code = HTTP_STATUS_CODE_201_CREATED;
break;
case pcf_smpc_error_code::UserUnknown:
problem_details.setCause("USER_UNKOWN");
problem_details.setDetail(details_string);
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
break;
case pcf_smpc_error_code::InvalidParameters:
problem_details.setCause("ERROR_INITIAL_PARAMETERS");
problem_details.setDetail(details_string);
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
break;
case pcf_smpc_error_code::ContextDenied:
problem_details.setCause("POLICY_CONTEXT_DENIED");
problem_details.setDetail(details_string);
http_code = HTTP_STATUS_CODE_403_FORBIDDEN;
break;
default:
Logger::pcf_app().error("Unknown error code");
http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
problem_details.setCause("INTERNAL_ERROR");
problem_details.setDetail("Internal Service Error: Unknown return code.");
}
if (http_code != HTTP_STATUS_CODE_201_CREATED) {
to_json(json_data, problem_details);
} else {
to_json(json_data, decision);
}
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
}
} // namespace api
......
......@@ -28,6 +28,7 @@ include_directories(${SRC_TOP_DIR}/api-server/api)
include_directories(${SRC_TOP_DIR}/api-server/impl)
include_directories(${SRC_TOP_DIR}/api-server/model)
include_directories(${SRC_TOP_DIR}/api-server/)
include_directories(${SRC_TOP_DIR}/pcf_app/sm_policy/)
add_library (PCF STATIC
pcf_app.cpp
......@@ -38,4 +39,6 @@ add_library (PCF STATIC
pcf_event.cpp
pcf_sm_policy_control.cpp
task_manager.cpp
#sm_policy/individual_sm_association.cpp
sm_policy/slice_policy_decision.cpp
)
\ No newline at end of file
......@@ -34,12 +34,17 @@
#include "pcf_config.hpp"
#include "pcf_client.hpp"
#include "Snssai.h"
//#include "individual_sm_association.hpp"
#include "slice_policy_decision.hpp"
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <stdexcept>
#include <unordered_map>
#include <map>
using namespace oai::pcf::app;
using namespace oai::pcf::app::sm_policy;
using namespace oai::pcf::config;
using namespace oai::pcf::model;
......@@ -49,10 +54,71 @@ extern pcf_smpc* pcf_smpc_inst;
extern pcf_config pcf_cfg;
//------------------------------------------------------------------------------
pcf_smpc::pcf_smpc() {}
pcf_smpc::pcf_smpc() {
// TODO currently hardcode the policy decisions, should come from UDR or file
SmPolicyDecision decision;
PccRule rule;
FlowInformation flow;
flow.setFlowDescription("permit out ip from any to assigned");
std::vector<FlowInformation> flow_information;
flow_information.push_back(flow);
rule.setPccRuleId("default");
rule.setFlowInfos(flow_information);
std::map<std::string, PccRule> pcc_rule_map;
pcc_rule_map["default"] = rule;
decision.setPccRules(pcc_rule_map);
Snssai snssai;
snssai.setSd("123");
snssai.setSst(222);
slice_policy_decision slice_desc(snssai, decision);
m_slice_policy_decisions.insert(std::make_pair(snssai, slice_desc));
}
//------------------------------------------------------------------------------
void pcf_smpc::create_sm_policy_handler() {}
pcf_smpc_error_code pcf_smpc::create_sm_policy_handler(
const SmPolicyContextData& context, SmPolicyDecision& decision,
std::string& problem_details) {
Snssai slice = context.getSliceInfo();
std::unordered_map<
Snssai, slice_policy_decision, snssai_hasher>::const_iterator got =
m_slice_policy_decisions.find(slice);
// TODO the plan here is to have: user based decisions, then dnn based
// decisions, then slice based decision and a default decision and reply with
// the policy decision in that order
if (got == m_slice_policy_decisions.end()) {
std::string description = fmt::format(
"SM Policy request from SUPI {}: Did not find policy based on slice: "
"{}-{}",
context.getSupi(), slice.getSd(), slice.getSst());
Logger::pcf_app().info(description);
problem_details = description;
return pcf_smpc_error_code::ContextDenied;
} else {
pcf_smpc_error_code res = got->second.decide(context, decision);
if (res != pcf_smpc_error_code::Created) {
std::string description = fmt::format(
"SM Policy request from SUPI {}: Could not create policy based on "
"slice: {}-{}",
context.getSupi(), slice.getSd(), slice.getSst());
problem_details = description;
return res;
}
Logger::pcf_app().info(fmt::format(
"SM Policy request from SUPI {}: CREATED", context.getSupi()));
return res;
}
}
//------------------------------------------------------------------------------
pcf_smpc::~pcf_smpc() {
......
......@@ -33,6 +33,7 @@
#include "common_root_types.h"
#include <boost/atomic.hpp>
#include <string>
#include <unordered_map>
#include "3gpp_29.500.h"
#include "pcf.h"
......@@ -45,9 +46,17 @@
#include "SmPolicyDecision.h"
#include "SmPolicyDeleteData.h"
#include "SmPolicyUpdateContextData.h"
#include "sm_policy/pcf_sm_policy_control_errors.hpp"
// #include "sm_policy/individual_sm_association.hpp"
#include "sm_policy/slice_policy_decision.hpp"
#include "sm_policy/snssai_hasher.hpp"
namespace oai::pcf::app {
/**
* @brief Service class to handle Session Management Policies
*
*/
class pcf_smpc {
public:
explicit pcf_smpc();
......@@ -56,20 +65,27 @@ class pcf_smpc {
virtual ~pcf_smpc();
/*
* Start event nf heartbeat procedure
* @param [void]
* @return void
/**
* @brief Handler for receiving create sm policy requests
*
* @param context input: context from the request
* @param decision output: policy decision based on context and local
* provisioning
* @return sm_policy::pcf_smpc_error_code
*/
void create_sm_policy_handler();
// void delete_sm_policy(const std::string &smPolicyId, const
// SmPolicyDeleteData &smPolicyDeleteData);
void get_sm_policy(const std::string& smPolicyId);
// void update_sm_policy(const std::string &smPolicyId, const
// SmPolicyUpdateContextData &smPolicyUpdateContextData);
sm_policy::pcf_smpc_error_code create_sm_policy_handler(
const oai::pcf::model::SmPolicyContextData& context,
oai::pcf::model::SmPolicyDecision& decision,
std::string& problem_details);
private:
// std::unordered_map<
// std::string, oai::pcf::app::sm_policy::individual_sm_association>
// m_associations;
std::unordered_map<
oai::pcf::model::Snssai, oai::pcf::app::sm_policy::slice_policy_decision,
oai::pcf::app::sm_policy::snssai_hasher>
m_slice_policy_decisions;
};
} // namespace oai::pcf::app
#endif /* FILE_PCF_SM_POLICY_CONTROL_SEEN */
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file pcf_sm_policy_control_errors.hpp
\brief
\author Stefan Spettel
\company Openairinterface Software Allianse
\date 2022
\email: rohan.kharade@openairinterface.org
*/
#ifndef FILE_PCF_SM_POLICY_CONTROL_ERRORS_H_SEEN
#define FILE_PCF_SM_POLICY_CONTROL_ERRORS_H_SEEN
namespace oai::pcf::app::sm_policy {
enum class pcf_smpc_error_code {
Created,
UserUnknown,
InvalidParameters,
ContextDenied,
};
} // namespace oai::pcf::app::sm_policy
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file individual_sm_association.hpp
\brief
\author Stefan Spettel
\company Openairinterface Software Allianse
\date 2022
\email: stefan.spettel@eurecom.fr
*/
#ifndef FILE_POLICY_DECISION_SEEN
#define FILE_POLICY_DECISION_SEEN
#include "SmPolicyContextData.h"
#include "SmPolicyDecision.h"
#include "pcf_sm_policy_control_errors.hpp"
namespace oai::pcf::app::sm_policy {
/**
* @brief Abstract base class for policy decisions. All sub classes need to
* implement the decide function
*
*/
class policy_decision {
public:
/**
* @brief Decides based on context on a policy. In case the return code is !=
* CREATED, the decision reference may be undefined
*
* @param context input: The context of the individual sm policy association
* @param decision output: The decision based on the context
* @return oai::pcf::app::sm_policy::pcf_smpc_error_code CREATED in case of
* success
*/
virtual oai::pcf::app::sm_policy::pcf_smpc_error_code decide(
const oai::pcf::model::SmPolicyContextData& context,
oai::pcf::model::SmPolicyDecision& decision) const = 0;
};
} // namespace oai::pcf::app::sm_policy
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file slice_policy_decision.cpp
\brief
\author Stefan Spettel
\company Openairinterface Software Allianse
\date 2022
\email: stefan.spettel@eurecom.fr
*/
#include "slice_policy_decision.hpp"
using namespace oai::pcf::model;
using namespace oai::pcf::app::sm_policy;
using namespace oai::pcf::app;
pcf_smpc_error_code slice_policy_decision::decide(
const SmPolicyContextData& context, SmPolicyDecision& decision) const {
if (context.getSliceInfo() != m_snssai) {
return pcf_smpc_error_code::ContextDenied;
}
decision = m_decision;
return pcf_smpc_error_code::Created;
}
Snssai slice_policy_decision::get_snssai() const {
return m_snssai;
}
slice_policy_decision::~slice_policy_decision() {}
\ No newline at end of file
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file slice_policy_decision.hpp
\brief
\author Stefan Spettel
\company Openairinterface Software Allianse
\date 2022
\email: stefan.spettel@eurecom.fr
*/
#ifndef FILE_SLICE_POLICY_DECISION_SEEN
#define FILE_SLICE_POLICY_DECISION_SEEN
#include "policy_decision.hpp"
#include "SmPolicyContextData.h"
#include "SmPolicyDecision.h"
#include "pcf_sm_policy_control_errors.hpp"
#include "Snssai.h"
namespace oai::pcf::app::sm_policy {
/**
* @brief Policy Decision based on slice.
*
*/
class slice_policy_decision : public oai::pcf::app::sm_policy::policy_decision {
public:
explicit slice_policy_decision(
oai::pcf::model::Snssai snssai,
oai::pcf::model::SmPolicyDecision decision) {
m_snssai = snssai;
m_decision = decision;
}
virtual ~slice_policy_decision();
/**
* @brief Decides based on context on a policy and the snssai information. In
* case the return code is != CREATED, the decision reference may be undefined
*
* @param context input: The context of the individual sm policy association
* @param decision output: The decision based on the context
* @return oai::pcf::app::sm_policy::pcf_smpc_error_code CREATED in case of
* success
*/
oai::pcf::app::sm_policy::pcf_smpc_error_code decide(
const oai::pcf::model::SmPolicyContextData& context,
oai::pcf::model::SmPolicyDecision& decision) const;
/**
* @brief Get the snssai object
*
* @return oai::pcf::model::Snssai
*/
oai::pcf::model::Snssai get_snssai() const;
private:
oai::pcf::model::SmPolicyDecision m_decision;
oai::pcf::model::Snssai m_snssai;
};
} // namespace oai::pcf::app::sm_policy
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file snssai_hasher.hpp
\brief
\author Stefan Spettel
\company Openairinterface Software Allianse
\date 2022
\email: stefan.spettel@eurecom.fr
*/
#ifndef FILE_SNSSAI_HASHER_SEEN
#define FILE_SNSSAI_HASHER_SEEN
#include "Snssai.h"
/**
* @brief Hash function to use Snssai objects as keys in (unordered) maps
*
*/
namespace oai::pcf::app::sm_policy {
class snssai_hasher {
public:
/**
* @brief Calculates the hash for a snssai
*
* @param snssai calculate hash based on this value
* @return size_t hash value
*/
size_t operator()(const oai::pcf::model::Snssai& snssai) const {
size_t res = 17;
res = res * 31 + std::hash<std::string>()(snssai.getSd());
res = res * 31 + std::hash<int>()(snssai.getSst());
}
};
} // namespace oai::pcf::app::sm_policy
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment