Skip to content

Commit

Permalink
preserve ip connection in site network access (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
soson authored Oct 19, 2021
1 parent 1e54184 commit b0982cb
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 33 deletions.
35 changes: 35 additions & 0 deletions packages/frinx-dashboard/src/api/unistore/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
AccessPriority,
ApiQosProfileInput,
CountryCode,
CreateIPConnectionInput,
CreateNetworkAccessInput,
CreateRoutingProtocolItem,
CreateRoutingProtocolsInput,
CreateVpnAttachment,
CreateVpnServiceInput,
CreateVpnSiteInput,
DefaultCVlanEnum,
IPConnection,
LanTag,
MaximumRoutes,
ProviderIdentifiers,
Expand Down Expand Up @@ -298,12 +300,45 @@ function clientVpnAttachmentToApiVpnAttachment(vpnAttachment: string): CreateVpn
};
}

function clientIPConnectionToApiIPConnection(ipConnection: IPConnection): CreateIPConnectionInput {
const output: CreateIPConnectionInput = {};

if (ipConnection.oam) {
output.oam = {};

if (ipConnection.oam.bfd) {
const { bfd } = ipConnection.oam;
output.oam.bfd = {
enabled: bfd?.enabled,
'profile-name': bfd?.profileName,
};
}
}
if (ipConnection.ipv4) {
output.ipv4 = {
'address-allocation-type': ipConnection.ipv4?.addressAllocationType,
};

if (ipConnection.ipv4.addresses) {
const { addresses } = ipConnection.ipv4;
output.ipv4.addresses = {
'customer-address': addresses.customerAddress,
'prefix-length': addresses.prefixLength,
'provider-address': addresses.providerAddress,
};
}
}

return output;
}

function clientNetworkAccessToApiNetworkAccess(networkAccesses: SiteNetworkAccess[]): CreateNetworkAccessInput {
return {
'site-network-access': networkAccesses.map((access) => {
return {
'site-network-access-id': access.siteNetworkAccessId,
'site-network-access-type': access.siteNetworkAccessType,
'ip-connection': access.ipConnection ? clientIPConnectionToApiIPConnection(access.ipConnection) : undefined,
availability: {
'access-priority': Number(access.accessPriority),
},
Expand Down
85 changes: 69 additions & 16 deletions packages/frinx-dashboard/src/api/unistore/network-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,42 @@ export function decodeRoutingProtocolsOutput(value: unknown): RoutingProtocolsOu
return extractResult(RoutingProtocolsValidator.decode(value));
}

const IPConnectionValidator = t.type({
oam: t.type({
bfd: optional(
t.type({
enabled: optional(t.boolean),
'profile-name': optional(t.string),
}),
),
}),
ipv4: optional(
t.type({
'address-allocation-type': optional(t.string),
addresses: optional(
t.type({
'customer-address': optional(t.string),
'prefix-length': optional(t.number),
'provider-address': optional(t.string),
}),
),
}),
),
});

export type IPConnectionOutput = t.TypeOf<typeof IPConnectionValidator>;
export function decodeIPConnectionOutput(value: unknown): IPConnectionOutput {
return extractResult(IPConnectionValidator.decode(value));
}

const SiteNetworkAccessValidator = t.type({
'site-network-access': t.array(
t.type({
'site-network-access-id': t.string,
'site-network-access-type': t.string,
// 'ip-connection': t.type({
// oam: t.type({
// bfd: t.type({
// enabled: t.boolean,
// 'profile-name': t.string,
// }),
// }),
// ipv4: t.type({
// 'address-allocation-type': t.string,
// addresses: t.type({
// 'customer-address': t.string,
// 'prefix-length': t.number,
// 'provider-address': t.string,
// }),
// }),
// }),
// this property is part of the form inputs, but it was reported,
// that they dont want to lose it when we edit form
'ip-connection': optional(IPConnectionValidator),
'maximum-routes': MaximumRoutesValidator,
'location-reference': optional(t.string),
'device-reference': optional(t.string),
Expand Down Expand Up @@ -345,10 +360,30 @@ export type CreateVpnAttachment = {
'site-role'?: string;
};

export type CreateIPConnectionInput = {
oam?: {
bfd?: {
enabled?: boolean;
'profile-name'?: string;
};
};
ipv4?: {
'address-allocation-type'?: string;
addresses?: {
'customer-address'?: string;
'prefix-length'?: number;
'provider-address'?: string;
};
};
};

export type CreateNetworkAccessInput = {
'site-network-access': {
'site-network-access-id': string;
'site-network-access-type': string;
// it is part of create/edit input even we dont use this value in the form,
// but we need to preserve it in the structure
'ip-connection'?: CreateIPConnectionInput;
availability: {
'access-priority': number;
};
Expand Down Expand Up @@ -599,9 +634,27 @@ export type Service = {
qosProfiles: [string];
};

export type IPConnection = {
oam?: {
bfd?: {
enabled?: boolean;
profileName?: string;
};
};
ipv4?: {
addressAllocationType?: string;
addresses?: {
customerAddress?: string;
prefixLength?: number;
providerAddress?: string;
};
};
};

export type SiteNetworkAccess = {
siteNetworkAccessId: string;
siteNetworkAccessType: SiteNetworkAccessType;
ipConnection?: IPConnection;
accessPriority: AccessPriority;
maximumRoutes: MaximumRoutes;
routingProtocols: RoutingProtocol[];
Expand Down
66 changes: 65 additions & 1 deletion packages/frinx-gamma/src/components/forms/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
RoutingProtocolType,
LanTag,
RequestedCVlan,
// StaticRoutingProtocol,
IPConnection,
} from './site-types';
import {
ApiQosProfileInput,
Expand All @@ -30,6 +30,8 @@ import {
CreateRoutingProtocolItem,
CreateRoutingProtocolsInput,
SiteServiceOutput,
IPConnectionOutput,
CreateIPConnectionInput,
} from '../../network-types';
import unwrap from '../../helpers/unwrap';

Expand Down Expand Up @@ -125,6 +127,34 @@ export function apiRoutingProtocolToClientRoutingProtocol(routingProtocol: Routi
};
}

export function apiIPConnectionToClientIPConnection(ipConnection: IPConnectionOutput): IPConnection {
const output: IPConnection = {};
if (ipConnection.oam) {
output.oam = {};
if (ipConnection.oam.bfd) {
output.oam.bfd = {
enabled: ipConnection.oam.bfd.enabled || undefined,
profileName: ipConnection.oam.bfd['profile-name'] || undefined,
};
}
}
if (ipConnection.ipv4) {
output.ipv4 = {
addressAllocationType: ipConnection.ipv4['address-allocation-type'] || undefined,
};
if (ipConnection.ipv4.addresses) {
const { addresses } = ipConnection.ipv4;
output.ipv4.addresses = {
customerAddress: addresses['customer-address'] || undefined,
prefixLength: addresses['prefix-length'] || undefined,
providerAddress: addresses['provider-address'] || undefined,
};
}
}

return output;
}

export function apiSiteNetworkAccessToClientSiteNetworkAccess(
networkAccess: SiteNetworkAccessOutput | void,
): SiteNetworkAccess[] {
Expand All @@ -142,6 +172,7 @@ export function apiSiteNetworkAccessToClientSiteNetworkAccess(
return {
siteNetworkAccessId: access['site-network-access-id'],
siteNetworkAccessType: access['site-network-access-type'] as SiteNetworkAccessType,
ipConnection: access['ip-connection'] ? apiIPConnectionToClientIPConnection(access['ip-connection']) : undefined,
accessPriority: String(access.availability['access-priority']) as AccessPriority,
maximumRoutes: access['maximum-routes']['address-family'][0]['maximum-routes'] as MaximumRoutes,
locationReference: access['location-reference'] || null,
Expand Down Expand Up @@ -291,12 +322,45 @@ function clientRoutingProtocolsToApiRoutingProtocols(routingProtocols: RoutingPr
};
}

function clientIPConnectionToApiIPConnection(ipConnection: IPConnection): CreateIPConnectionInput {
const output: CreateIPConnectionInput = {};

if (ipConnection.oam) {
output.oam = {};

if (ipConnection.oam.bfd) {
const { bfd } = ipConnection.oam;
output.oam.bfd = {
enabled: bfd?.enabled,
'profile-name': bfd?.profileName,
};
}
}
if (ipConnection.ipv4) {
output.ipv4 = {
'address-allocation-type': ipConnection.ipv4?.addressAllocationType,
};

if (ipConnection.ipv4.addresses) {
const { addresses } = ipConnection.ipv4;
output.ipv4.addresses = {
'customer-address': addresses.customerAddress,
'prefix-length': addresses.prefixLength,
'provider-address': addresses.providerAddress,
};
}
}

return output;
}

function clientNetworkAccessToApiNetworkAccess(networkAccesses: SiteNetworkAccess[]): CreateNetworkAccessInput {
return {
'site-network-access': networkAccesses.map((access) => {
return {
'site-network-access-id': access.siteNetworkAccessId,
'site-network-access-type': access.siteNetworkAccessType,
'ip-connection': access.ipConnection ? clientIPConnectionToApiIPConnection(access.ipConnection) : undefined,
availability: {
'access-priority': Number(access.accessPriority),
},
Expand Down
18 changes: 18 additions & 0 deletions packages/frinx-gamma/src/components/forms/site-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,27 @@ export type Service = {
qosProfiles: [string];
};

export type IPConnection = {
oam?: {
bfd?: {
enabled?: boolean;
profileName?: string;
};
};
ipv4?: {
addressAllocationType?: string;
addresses?: {
customerAddress?: string;
prefixLength?: number;
providerAddress?: string;
};
};
};

export type SiteNetworkAccess = {
siteNetworkAccessId: string;
siteNetworkAccessType: SiteNetworkAccessType;
ipConnection?: IPConnection;
accessPriority: AccessPriority;
maximumRoutes: MaximumRoutes;
routingProtocols: RoutingProtocol[];
Expand Down
Loading

0 comments on commit b0982cb

Please sign in to comment.