Commit f92c1a86 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Support PDU Session IPv4v6(IPv6 address allocation)

parent a44e42db
......@@ -94,13 +94,34 @@ void util::ipv4_to_bstring(struct in_addr ipv4_address, bstring str) {
bitstream_addr[2] = (uint8_t)(((ipv4_address.s_addr) & 0x00ff0000) >> 16);
bitstream_addr[3] = (uint8_t)(((ipv4_address.s_addr) & 0xff000000) >> 24);
// str = bfromcstralloc(4, "\0");
// str = bfromcstralloc(4, "\0");
str->slen = 4;
memcpy(str->data, bitstream_addr, sizeof(bitstream_addr));
}
void util::ipv6_to_bstring(struct in6_addr ipv6_address, bstring str) {
unsigned char bitstream_addr[8];
for (int i = 0; i <= 7; i++)
bitstream_addr[i] = (uint8_t)(ipv6_address.s6_addr16[i]);
str->slen = 8;
memcpy(str->data, bitstream_addr, sizeof(bitstream_addr));
}
void util::ipv4v6_to_bstring(
struct in_addr ipv4_address, struct in6_addr ipv6_address, bstring str) {
unsigned char bitstream_addr[12];
bitstream_addr[0] = (uint8_t)((ipv4_address.s_addr) & 0x000000ff);
bitstream_addr[1] = (uint8_t)(((ipv4_address.s_addr) & 0x0000ff00) >> 8);
bitstream_addr[2] = (uint8_t)(((ipv4_address.s_addr) & 0x00ff0000) >> 16);
bitstream_addr[3] = (uint8_t)(((ipv4_address.s_addr) & 0xff000000) >> 24);
for (int i = 0; i <= 7; i++)
bitstream_addr[i + 4] = (uint8_t)(ipv6_address.s6_addr16[i]);
str->slen = 12;
memcpy(str->data, bitstream_addr, sizeof(bitstream_addr));
}
void util::string_to_bstring(const std::string& str, bstring bstr) {
// bstr = bfromcstralloc(str.length(), "\0");
// bstr = bfromcstralloc(str.length(), "\0");
bstr->slen = str.length();
memcpy((void*) bstr->data, (void*) str.c_str(), str.length());
}
......@@ -46,6 +46,9 @@ std::string& rtrim(std::string& s);
std::string& trim(std::string& s);
void ipv4_to_bstring(struct in_addr ipv4_address, bstring str);
void ipv6_to_bstring(struct in6_addr ipv6_address, bstring str);
void ipv4v6_to_bstring(
struct in_addr ipv4_address, struct in6_addr ipv6_address, bstring str);
void string_to_bstring(const std::string& str, bstring bstr);
} // namespace util
......
......@@ -30,6 +30,7 @@
#include "smf_app.hpp"
#include <boost/uuid/random_generator.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <cstdlib>
#include <iostream>
......@@ -1642,21 +1643,20 @@ bool smf_app::get_session_management_subscription_data(
Logger::smf_app().debug(
"Default session type %s",
smf_cfg.session_management_subscription[i].session_type.c_str());
if (smf_cfg.session_management_subscription[i].session_type.compare(
"IPV4") == 0) {
std::string session_type =
smf_cfg.session_management_subscription[i].session_type;
if (boost::iequals(session_type, "IPv4")) {
pdu_session_type.pdu_session_type =
pdu_session_type_e::PDU_SESSION_TYPE_E_IPV4;
} else if (
smf_cfg.session_management_subscription[i].session_type.compare(
"IPV6") == 0) {
} else if (boost::iequals(session_type, "IPv6")) {
pdu_session_type.pdu_session_type =
pdu_session_type_e::PDU_SESSION_TYPE_E_IPV6;
} else if (
smf_cfg.session_management_subscription[i].session_type.compare(
"IPV4V6") == 0) {
} else if (boost::iequals(session_type, "IPv4v6")) {
pdu_session_type.pdu_session_type =
pdu_session_type_e::PDU_SESSION_TYPE_E_IPV4V6;
}
dnn_configuration->pdu_session_types.default_session_type =
pdu_session_type;
......
......@@ -1580,7 +1580,7 @@ void smf_context::handle_pdu_session_create_sm_context_request(
if (sm_context_resp->res.get_cause() !=
static_cast<uint8_t>(cause_value_5gsm_e::CAUSE_255_REQUEST_ACCEPTED)) {
// clear pco, ambr
// TODO:
// free paa
paa_t free_paa = {};
free_paa = sm_context_resp->res.get_paa();
......@@ -1588,10 +1588,12 @@ void smf_context::handle_pdu_session_create_sm_context_request(
switch (sp->pdu_session_type.pdu_session_type) {
case PDU_SESSION_TYPE_E_IPV4:
case PDU_SESSION_TYPE_E_IPV4V6:
paa_dynamic::get_instance().release_paa(
sd->dnn_in_use, free_paa.ipv4_address);
break;
// paa_dynamic::get_instance().release_paa(
// sd->dnn_in_use, free_paa.ipv4_address);
// break;
case PDU_SESSION_TYPE_E_IPV6:
paa_dynamic::get_instance().release_paa(sd->dnn_in_use, free_paa);
break;
case PDU_SESSION_TYPE_E_UNSTRUCTURED:
case PDU_SESSION_TYPE_E_ETHERNET:
case PDU_SESSION_TYPE_E_RESERVED:
......
......@@ -160,15 +160,36 @@ bool smf_n1::create_n1_pdu_session_establishment_accept(
// PDUAddress
paa_t paa = sm_context_res.get_paa();
sm_msg->pdu_session_establishment_accept.pduaddress.pdu_address_information =
bfromcstralloc(4, "\0");
util::ipv4_to_bstring(
paa.ipv4_address, sm_msg->pdu_session_establishment_accept.pduaddress
.pdu_address_information);
Logger::smf_n1().debug(
"PDU Session Type %s", paa.pdu_session_type.toString().c_str());
sm_msg->pdu_session_establishment_accept.pduaddress.pdu_session_type_value =
static_cast<uint8_t>(paa.pdu_session_type.pdu_session_type);
Logger::smf_n1().debug(
"UE Address %s", conv::toString(paa.ipv4_address).c_str());
if (paa.pdu_session_type.pdu_session_type == PDU_SESSION_TYPE_E_IPV4) {
sm_msg->pdu_session_establishment_accept.pduaddress
.pdu_address_information = bfromcstralloc(4, "\0");
util::ipv4_to_bstring(
paa.ipv4_address, sm_msg->pdu_session_establishment_accept.pduaddress
.pdu_address_information);
Logger::smf_n1().debug(
"UE IPv4 Address %s", conv::toString(paa.ipv4_address).c_str());
} else if (
paa.pdu_session_type.pdu_session_type == PDU_SESSION_TYPE_E_IPV4V6) {
sm_msg->pdu_session_establishment_accept.pduaddress
.pdu_address_information = bfromcstralloc(12, "\0");
util::ipv4v6_to_bstring(
paa.ipv4_address, paa.ipv6_address,
sm_msg->pdu_session_establishment_accept.pduaddress
.pdu_address_information);
Logger::smf_n1().debug(
"UE IPv4 Address %s", conv::toString(paa.ipv4_address).c_str());
char str_addr6[INET6_ADDRSTRLEN];
if (inet_ntop(AF_INET6, &paa.ipv6_address, str_addr6, sizeof(str_addr6))) {
Logger::smf_n1().debug("UE IPv6 Address: %s", str_addr6);
}
} else if (paa.pdu_session_type.pdu_session_type == PDU_SESSION_TYPE_E_IPV6) {
// TODO:
Logger::smf_n1().debug("IPv6 is not fully supported yet!");
}
// TODO: GPRSTimer
// sm_msg->pdu_session_establishment_accept.gprstimer.unit =
......
......@@ -290,6 +290,7 @@ class paa_dynamic {
return false;
} else if (
paa.pdu_session_type.pdu_session_type == PDU_SESSION_TYPE_E_IPV6) {
Logger::smf_app().debug("IPv6 is not fully supported yet!");
return true;
}
}
......
......@@ -408,7 +408,7 @@ void session_create_sm_context_procedure::handle_itti_msg(
// TODO: Support IPv4 only for now
if (n11_triggered_pending->res.get_pdu_session_type() ==
PDU_SESSION_TYPE_E_IPV4V6) {
PDU_SESSION_TYPE_E_IPV6) {
n11_triggered_pending->res.set_pdu_session_type(PDU_SESSION_TYPE_E_IPV4);
cause_n1 =
cause_value_5gsm_e::CAUSE_50_PDU_SESSION_TYPE_IPV4_ONLY_ALLOWED;
......
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