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

Update URR report #139

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/genl_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ int gtp5g_genl_fill_ur(struct sk_buff *, struct usage_report *);
int gtp5g_genl_fill_usage_report(struct sk_buff *, u32, u32, u32, struct usage_report *);
int gtp5g_genl_fill_multi_usage_reports(struct sk_buff *, u32, u32, u32, struct usage_report **, u32);

void convert_urr_to_report(struct urr *, struct usage_report *);
void convert_urr_to_report(struct urr *, struct usage_report *, bool);
#endif // __GENL_URR_H__
5 changes: 3 additions & 2 deletions include/urr.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ struct urr {
struct Volume volumequota;

// For usage report volume measurement
struct VolumeMeasurement bytes;
struct VolumeMeasurement bytes2;
bool use_vol2;
struct VolumeMeasurement vol;
struct VolumeMeasurement vol2;
struct VolumeMeasurement consumed;

// for report time
Expand Down
32 changes: 18 additions & 14 deletions src/genl/genl_report.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ int gtp5g_genl_get_usage_report(struct sk_buff *skb, struct genl_info *info)
goto fail;
}

// set the use_vol2 flag to the opposite value
urr->use_vol2 = !urr->use_vol2;

report = kzalloc(sizeof(struct usage_report), GFP_KERNEL);
if (!report) {
err = -ENOMEM;
goto fail;
}

convert_urr_to_report(urr, report);
convert_urr_to_report(urr, report, !urr->use_vol2);

err = gtp5g_genl_fill_usage_report(skb_ack,
NETLINK_CB(skb).portid,
Expand Down Expand Up @@ -250,13 +252,15 @@ int gtp5g_genl_get_multi_usage_reports(struct sk_buff *skb, struct genl_info *in
goto fail;
}

// set the use_vol2 flag to the opposite value
urr->use_vol2 = !urr->use_vol2;

reports[i] = kzalloc(sizeof(struct usage_report), GFP_KERNEL);
if (!reports[i]) {
err = -ENOMEM;
goto fail;
}

convert_urr_to_report(urr, reports[report_num++]);
convert_urr_to_report(urr, reports[report_num++], !urr->use_vol2);
}

skb_ack = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
Expand Down Expand Up @@ -298,30 +302,30 @@ int gtp5g_genl_get_multi_usage_reports(struct sk_buff *skb, struct genl_info *in
return genlmsg_unicast(genl_info_net(info), skb_ack, info->snd_portid);
}

static int gtp5g_genl_fill_volume_measurement(struct sk_buff *skb, struct VolumeMeasurement bytes)
static int gtp5g_genl_fill_volume_measurement(struct sk_buff *skb, struct VolumeMeasurement vol)
{
struct nlattr *nest_volume_measurement;

nest_volume_measurement = nla_nest_start(skb, GTP5G_UR_VOLUME_MEASUREMENT);
if (!nest_volume_measurement)
return -EMSGSIZE;

if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_TOVOL, bytes.totalVolume , 0))
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_TOVOL, vol.totalVolume , 0))
return -EMSGSIZE;
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_UVOL, bytes.uplinkVolume, 0))
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_UVOL, vol.uplinkVolume, 0))
return -EMSGSIZE;
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_DVOL, bytes.downlinkVolume, 0))
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_DVOL, vol.downlinkVolume, 0))
return -EMSGSIZE;
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_TOPACKET, bytes.totalPktNum, 0))
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_TOPACKET, vol.totalPktNum, 0))
return -EMSGSIZE;
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_UPACKET, bytes.uplinkPktNum, 0))
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_UPACKET, vol.uplinkPktNum, 0))
return -EMSGSIZE;
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_DPACKET, bytes.downlinkPktNum, 0))
if (nla_put_u64_64bit(skb, GTP5G_UR_VOLUME_MEASUREMENT_DPACKET, vol.downlinkPktNum, 0))
return -EMSGSIZE;

nla_nest_end(skb, nest_volume_measurement);

memset(&bytes, 0, sizeof(struct VolumeMeasurement));
memset(&vol, 0, sizeof(struct VolumeMeasurement));

return 0;
}
Expand Down Expand Up @@ -423,10 +427,10 @@ int gtp5g_genl_fill_multi_usage_reports(struct sk_buff *skb, u32 snd_portid, u32
return -EMSGSIZE;
}

void convert_urr_to_report(struct urr *urr, struct usage_report *report)
void convert_urr_to_report(struct urr *urr, struct usage_report *report, bool use_vol2)
{
struct VolumeMeasurement *urr_counter
= get_usage_report_counter(urr, true);
= get_usage_report_counter(urr, use_vol2);

urr->end_time = ktime_get_real();
*report = (struct usage_report ) {
Expand Down
11 changes: 6 additions & 5 deletions src/genl/genl_urr.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ int gtp5g_genl_del_urr(struct sk_buff *skb, struct genl_info *info)
goto fail;
}

convert_urr_to_report(urr, report);
// return current counter
convert_urr_to_report(urr, report, urr->use_vol2);

err = gtp5g_genl_fill_usage_report(skb_ack,
NETLINK_CB(skb).portid,
Expand Down Expand Up @@ -332,10 +333,10 @@ static int urr_fill(struct urr *urr, struct gtp5g_dev *gtp, struct genl_info *in
if (info->attrs[GTP5G_URR_REPORTING_TRIGGER]) {
urr->trigger = nla_get_u32(info->attrs[GTP5G_URR_REPORTING_TRIGGER]);
if (urr->trigger == URR_RPT_TRIGGER_START) {
// Clean bytes to make sure the bytes are counted after the start of service data flow
// TODO: Should send the previous stroed bytes to CP first
memset(&urr->bytes, 0, sizeof(struct VolumeMeasurement));
memset(&urr->bytes2, 0, sizeof(struct VolumeMeasurement));
// Clean vol to make sure the vol are counted after the start of service data flow
// TODO: Should send the previous stroed vol to CP first
memset(&urr->vol, 0, sizeof(struct VolumeMeasurement));
memset(&urr->vol2, 0, sizeof(struct VolumeMeasurement));
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/gtpu/encap.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,16 @@ int update_urr_counter_and_send_report(struct pdr *pdr, struct far *far, u64 vol
} else {
volume = vol;
}

// Caculate Volume measurement for each trigger
urr_counter = get_usage_report_counter(urr, false);
urr_counter = get_usage_report_counter(urr, urr->use_vol2);
if (urr->trigger & URR_RPT_TRIGGER_VOLTH) {
if (increment_and_check_counter(urr_counter, &urr->volumethreshold, volume, uplink, mnop)) {
triggers[report_num] = USAR_TRIGGER_VOLTH;
urrs[report_num++] = urr;
}
} else {
// For other triggers, only increment bytes
// For other triggers, only increment vol
increment_and_check_counter(urr_counter, NULL, volume, uplink, mnop);
}
if (urr->trigger & URR_RPT_TRIGGER_VOLQU) {
Expand Down Expand Up @@ -708,7 +709,7 @@ int update_urr_counter_and_send_report(struct pdr *pdr, struct far *far, u64 vol
if (triggers[i] == USAR_TRIGGER_START){
ret = DONT_SEND_UL_PACKET;
}
convert_urr_to_report(urrs[i], &report[i]);
convert_urr_to_report(urrs[i], &report[i], !urrs[i]->use_vol2);

report[i].trigger = triggers[i];
}
Expand Down
28 changes: 9 additions & 19 deletions src/pfcp/urr.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,34 +257,24 @@ int urr_set_pdr(struct pdr *pdr, struct gtp5g_dev *gtp)
/*
`get_usage_report_counter` will return one of the two counters.

To avoid sending incorrect reports, there are two counters (bytes, bytes2) for each period.
To avoid sending incorrect reports, there are two counters (vol, vol2) for each period.
These counters will take turns recording the packet count.

For usage report => counter of the previous period
For packet counting => counter of the current period
*/
struct VolumeMeasurement *get_usage_report_counter(struct urr *urr, bool previous_counter)
struct VolumeMeasurement *get_usage_report_counter(struct urr *urr, bool use_vol2)
{
u32 now = ktime_get_real() / NSEC_PER_SEC;

// If the period is zero, always return the first counter.
if (urr->period == 0) {
return &urr->bytes;
return &urr->vol;
}

if ((now/urr->period)%2 == 1) {
if (previous_counter) {
return &urr->bytes;
} else{
return &urr->bytes2;
}
} else {
if (previous_counter) {
return &urr->bytes2;
} else{
return &urr->bytes;
}
}
if (use_vol2) {
return &urr->vol2;
} else{
return &urr->vol;
}

return &urr->bytes;
return &urr->vol;
}