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

Feat/frontend mbr gbr foolproof mechanism #123

Merged
Merged
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
49 changes: 49 additions & 0 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
export function toHex(v: number | undefined): string {
return ("00" + v?.toString(16).toUpperCase()).substr(-2);
}

function parseDataRate(rate: string | undefined): number {
if (!rate) return 0;

const match = rate.match(/^(\d+)\s*(Gbps|Mbps|Kbps|bps)$/i);
if (!match) return 0;

const [, value, unit] = match;
const numValue = parseFloat(value);

switch (unit.toLowerCase()) {
case 'gbps':
return numValue * 1000000;
case 'mbps':
return numValue * 1000;
case 'kbps':
return numValue;
case 'bps':
return numValue / 1000;
default:
return 0;
}
}

export function validateMBRGreaterThanGBR(QosFlows: any[]): { isValid: boolean; error?: string } {
for (let i = 0; i < QosFlows.length; i++) {
const qosFlow = QosFlows[i];
const gbrDL = parseDataRate(qosFlow.gbrDL);
const mbrDL = parseDataRate(qosFlow.mbrDL);
const gbrUL = parseDataRate(qosFlow.gbrUL);
const mbrUL = parseDataRate(qosFlow.mbrUL);

if (gbrDL && mbrDL && gbrDL >= mbrDL) {
return {
isValid: false,
error: `In S-NSSAI ${qosFlow.snssai}'s Flow Rule ${i+1}\nDownlink MBR must be greater than Downlink GBR`
};
}

if (gbrUL && mbrUL && gbrUL >= mbrUL) {
return {
isValid: false,
error: `In S-NSSAI ${qosFlow.snssai}'s Flow Rule ${i+1}\nUplink MBR must be greater than Uplink GBR`
};
}
}

return { isValid: true };
}
14 changes: 14 additions & 0 deletions frontend/src/pages/ProfileCreate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import ProfileFormBasic from "./ProfileFormBasic";
import ProfileFormUeAmbr from "./ProfileFormUeAmbr";
import ProfileFormSessions from "./ProfileFormSessions";
import { ProfileMapperImpl, FlowsMapperImpl } from "../../lib/dtos/profile";
import { validateMBRGreaterThanGBR } from "../../lib/utils";

function FormHOC(Component: React.ComponentType<any>) {
return function (props: any) {
return (
Expand Down Expand Up @@ -66,6 +68,12 @@ function ProfileCreate() {
const profileMapper = new ProfileMapperImpl(new FlowsMapperImpl());
const profile = profileMapper.mapFromDto(data);

const validation = validateMBRGreaterThanGBR(profile.QosFlows);
if (!validation.isValid) {
alert(validation.error);
return;
}

axios
.post("/api/profile", profile)
.then(() => {
Expand Down Expand Up @@ -96,6 +104,12 @@ function ProfileCreate() {
const profileMapper = new ProfileMapperImpl(new FlowsMapperImpl());
const profile = profileMapper.mapFromDto(data);

const validation = validateMBRGreaterThanGBR(profile.QosFlows);
if (!validation.isValid) {
alert(validation.error);
return;
}

axios
.put("/api/profile/" + profile.profileName, profile)
.then(() => {
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/pages/SubscriberCreate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import SubscriberFormUeAmbr from "./SubscriberFormUeAmbr";
import SubscriberFormSessions from "./SubscriberFormSessions";
import { FlowsMapperImpl as SubscriptionFlowsMapperImpl, SubscriptionMapperImpl } from "../../lib/dtos/subscription";
import { FlowsMapperImpl as ProfileFlowsMapperImpl, ProfileMapperImpl } from "../../lib/dtos/profile";
import { validateMBRGreaterThanGBR } from "../../lib/utils";

function FormHOC(Component: React.ComponentType<any>) {
return function (props: any) {
return (
Expand Down Expand Up @@ -91,6 +93,12 @@ function SubscriberCreate() {
const subscriberMapper = new SubscriptionMapperImpl(new SubscriptionFlowsMapperImpl());
const subscription = subscriberMapper.mapFromDto(data);

const validation = validateMBRGreaterThanGBR(subscription.QosFlows);
if (!validation.isValid) {
alert(validation.error);
return;
}

// Iterate subscriber data number.
let supi = subscription.ueId;
for (let i = 0; i < subscription.userNumber!; i++) {
Expand Down Expand Up @@ -127,6 +135,12 @@ function SubscriberCreate() {
const subscriberMapper = new SubscriptionMapperImpl(new SubscriptionFlowsMapperImpl());
const subscription = subscriberMapper.mapFromDto(data);

const validation = validateMBRGreaterThanGBR(subscription.QosFlows);
if (!validation.isValid) {
alert(validation.error);
return;
}

axios
.put("/api/subscriber/" + subscription.ueId + "/" + subscription.plmnID, subscription)
.then(() => {
Expand Down
Loading