Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Pcrf json dbi #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions configs/pcrf-no-mongodb/pcrf-default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH it looks a bit weird that being all the config files yaml this is done in JSON. I forsee this will be NACKed upon review. If I were you I'd move this to yaml, drop cJSON and even incorporate this as a node in pcrf.cfg

{
"id": 4660,
"qci": 8,
"priority": 5,
"pre_emption_capability": 0,
"pre_emption_vulnerability": 1,
"ambr": {
"up": 999,
"down": 1000
},
"gmbr": {
"up": 500,
"down": 500
}
}
]
32 changes: 32 additions & 0 deletions configs/pcrf-no-mongodb/pcrf-internet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"id": -1,
"qci": 5,
"priority": 5,
"pre_emption_capability": 0,
"pre_emption_vulnerability": 1,
"ambr": {
"up": 1000,
"down": 10000
},
"gmbr": {
"up": 500,
"down": 500
}
},
{
"id": 4660,
"qci": 5,
"priority": 5,
"pre_emption_capability": 0,
"pre_emption_vulnerability": 1,
"ambr": {
"up": 1000,
"down": 10000
},
"gmbr": {
"up": 500,
"down": 500
}
}
]
55 changes: 55 additions & 0 deletions configs/pcrf-no-mongodb/pcrf.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# db_json
# allow to use json templates for the policy
# a * will be used if the apn isn't defined. it can be omitted.
db_json:
internet: @sysconfdir@/open5gs/pcrf-internet.json
"*": @sysconfdir@/open5gs/pcrf-default.json

#
# logger:
#
# o Set OGS_LOG_INFO to all domain level
# - If `level` is omitted, the default level is OGS_LOG_INFO)
# - If `domain` is omitted, the all domain level is set from 'level'
# (Nothing is needed)
#
# o Set OGS_LOG_ERROR to all domain level
# - `level` can be set with none, fatal, error, warn, info, debug, trace
# level: error
#
# o Set OGS_LOG_DEBUG to mme/emm domain level
# level: debug
# domain: mme,emm
#
# o Set OGS_LOG_TRACE to all domain level
# level: trace
# domain: core,fd,pcrf,event,mem,sock
logger:
file: @localstatedir@/log/open5gs/pcrf.log

pcrf:
freeDiameter: @sysconfdir@/freeDiameter/pcrf.conf

#
# parameter:
#
# o Disable use of IPv4 addresses (only IPv6)
# no_ipv4: true
#
# o Disable use of IPv6 addresses (only IPv4)
# no_ipv6: true
#
# o Prefer IPv4 instead of IPv6 for estabishing new GTP connections.
# prefer_ipv4: true
#
parameter:

#
# max:
#
# o Maximum Number of UE
# ue: 1024
# o Maximum Number of Peer(S1AP/NGAP, DIAMETER, GTP, PFCP or SBI)
# peer: 64
#
max:
19 changes: 19 additions & 0 deletions lib/app/ogs-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ int ogs_app_context_parse_config(void)
ogs_assert(root_key);
if (!strcmp(root_key, "db_uri")) {
self.db_uri = ogs_yaml_iter_value(&root_iter);
} else if (!strcmp(root_key, "db_json")) {
ogs_yaml_iter_t dbjson_iter;
ogs_yaml_iter_recurse(&root_iter, &dbjson_iter);
int apns = 0;
while (ogs_yaml_iter_next(&dbjson_iter)) {
const char *apn = ogs_yaml_iter_key(&dbjson_iter);
const char *apn_filepath;

if (apns >= OGS_APP_DB_JSON_MAX_APNS) {
ogs_error("db_json: too many apns defined!");
return OGS_ERROR;
}
ogs_assert(apn);
apn_filepath = ogs_yaml_iter_value(&dbjson_iter);
ogs_assert(apn_filepath);
self.db_json[apns].apn = apn;
self.db_json[apns].filepath = apn_filepath;
apns++;
}
} else if (!strcmp(root_key, "logger")) {
ogs_yaml_iter_t logger_iter;
ogs_yaml_iter_recurse(&root_iter, &logger_iter);
Expand Down
7 changes: 7 additions & 0 deletions lib/app/ogs-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@
extern "C" {
#endif

#define OGS_APP_DB_JSON_MAX_APNS 16

typedef struct ogs_app_context_s {
const char *version;

const char *file;
void *document;

const char *db_uri;
struct {
const char *apn;
const char *filepath;
} db_json[OGS_APP_DB_JSON_MAX_APNS];

struct {
const char *file;
const char *level;
Expand Down
58 changes: 58 additions & 0 deletions lib/dbi/dbi-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <[email protected]>
* Author: Alexander Couzens <[email protected]>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#if !defined(OGS_DBI_INSIDE) && !defined(OGS_DBI_COMPILATION)
#error "This header cannot be included directly."
#endif

#ifndef OGS_DBI_PRIVATE_H
#define OGS_DBI_PRIVATE_H

#ifdef __cplusplus
extern "C" {
#endif

struct ogs_dbi_s {
const char *name;
void (*final)(void);
/* session */
int (*session_data)(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
int32_t charging_char, ogs_session_data_t *data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's more like a bitmask, maybe makes more sense to use uint32_t?

/* ims */
int (*msisdn_data)(char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data);
int (*ims_data)(char *supi, ogs_ims_data_t *ims_data);
/* subscription */
int (*auth_info)(char *supi, ogs_dbi_auth_info_t *auth_info);
int (*update_sqn)(char *supi, uint64_t sqn);
int (*increment_sqn)(char *supi);
int (*update_imeisv)(char *supi, char *imeisv);
int (*subscription_data)(char *supi,
ogs_subscription_data_t *subscription_data);
};
typedef struct ogs_dbi_s ogs_dbi_t;

int ogs_dbi_deselect_interface(void);
int ogs_dbi_select_interface(const char *dbi_name);

#ifdef __cplusplus
}
#endif

#endif /* OGS_DBI_PRIVATE_H */
144 changes: 144 additions & 0 deletions lib/dbi/dbi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <[email protected]>
* Author: Alexander Couzens <[email protected]>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "ogs-dbi.h"

#include "dbi-private.h"
#include "dbi-config-private.h"

#ifdef WITH_MONGOC
#include "mongo/mongo-private.h"
#endif
#include "json/json-private.h"

int __ogs_dbi_domain;

static ogs_dbi_t *dbi_interfaces[] = {
#ifdef WITH_MONGOC
&ogs_dbi_mongo_interface,
#endif
&ogs_dbi_json_interface,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how is one or the other selected for use? I don't recall seeing any explanation anywhere.

NULL,
};

static ogs_dbi_t *dbi_selected;

int ogs_dbi_deselect_interface()
{
dbi_selected = NULL;

return 0;
}

int ogs_dbi_select_interface(const char *dbi_name)
{
ogs_dbi_t *dbi;
int i;
ogs_assert(dbi_name);

for (i = 0; i < OGS_ARRAY_SIZE(dbi_interfaces); i++) {
dbi = dbi_interfaces[i];
if (!ogs_strcasecmp(dbi->name, dbi_name)) {
dbi_selected = dbi;
return 0;
}
}

ogs_error("Couldn't find dbi interface %s", dbi_name);
return -1;
}

void ogs_dbi_final(void)
{
if (!dbi_selected)
return;

dbi_selected->final();
}

/* ims */
int ogs_dbi_msisdn_data(
char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data)
{
ogs_assert(dbi_selected);
if (!dbi_selected->msisdn_data)
return OGS_ERROR;
return dbi_selected->msisdn_data(imsi_or_msisdn_bcd, msisdn_data);
}

int ogs_dbi_ims_data(char *supi, ogs_ims_data_t *ims_data)
{
ogs_assert(dbi_selected);
if (!dbi_selected->ims_data)
return OGS_ERROR;
return dbi_selected->ims_data(supi, ims_data);
}

/* session */
int ogs_dbi_session_data(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
int32_t charging_char, ogs_session_data_t *session_data)
{
ogs_assert(dbi_selected);
if (!dbi_selected->session_data)
return OGS_ERROR;
return dbi_selected->session_data(supi, s_nssai, dnn, charging_char, session_data);
}

/* subscription */
int ogs_dbi_auth_info(char *supi, ogs_dbi_auth_info_t *auth_info)
{
ogs_assert(dbi_selected);
if (!dbi_selected->auth_info)
return OGS_ERROR;
return dbi_selected->auth_info(supi, auth_info);
}

int ogs_dbi_update_sqn(char *supi, uint64_t sqn)
{
ogs_assert(dbi_selected);
if (!dbi_selected->update_sqn)
return OGS_ERROR;
return dbi_selected->update_sqn(supi, sqn);
}

int ogs_dbi_increment_sqn(char *supi)
{
ogs_assert(dbi_selected);
if (!dbi_selected->increment_sqn)
return OGS_ERROR;
return dbi_selected->increment_sqn(supi);
}

int ogs_dbi_update_imeisv(char *supi, char *imeisv)
{
ogs_assert(dbi_selected);
if (!dbi_selected->update_imeisv)
return OGS_ERROR;
return dbi_selected->update_imeisv(supi, imeisv);
}

int ogs_dbi_subscription_data(char *supi,
ogs_subscription_data_t *subscription_data)
{
ogs_assert(dbi_selected);
if (!dbi_selected->subscription_data)
return OGS_ERROR;
return dbi_selected->subscription_data(supi, subscription_data);
}
Loading