Skip to content

Commit

Permalink
Bearer form (#223)
Browse files Browse the repository at this point in the history
* bearer types and converter

* add bearer-list basics

* fix evc attachment validation and converter

* add basic bearer table; add callbacks; add commit to bearers

* client to api bearer converter

* basic create/edit/delete bearer functionality

Co-authored-by: Paulooze <[email protected]>
  • Loading branch information
soson and Paulooze authored Oct 21, 2021
1 parent c650931 commit 61f61d1
Show file tree
Hide file tree
Showing 15 changed files with 623 additions and 50 deletions.
83 changes: 83 additions & 0 deletions packages/frinx-dashboard/src/api/unistore/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DefaultCVlanEnum,
EvcAttachment,
EvcAttachmentOutput,
EvcAttachmentInput,
IPConnection,
LanTag,
MaximumRoutes,
Expand All @@ -37,6 +38,7 @@ import {
SiteVpnFlavor,
ValidProviderIdentifiersOutput,
VpnBearerOutput,
VpnBearerInput,
VpnBearer,
VpnService,
VpnServicesOutput,
Expand Down Expand Up @@ -542,3 +544,84 @@ export function apiBearerToClientBearer(apiBearer: VpnBearerOutput): VpnBearer[]
};
});
}
function clientBearerStatusToApiBearerStatus(status: BearerStatus): BearerStatusOutput {
const adminStatus = status.adminStatus
? {
status: status.adminStatus.status || undefined,
'last-updated': status.adminStatus.lastUpdated || undefined,
}
: undefined;
const operStatus = status.operStatus
? {
status: status.operStatus.status || undefined,
'last-updated': status.operStatus.lastUpdated || undefined,
}
: undefined;
return {
'admin-status': adminStatus,
'oper-status': operStatus,
};
}

function clientCarrierToApiCarrier(carrier: Carrier): CarrierOutput {
return {
'carrier-name': carrier.carrierName || undefined,
'carrier-reference': carrier.carrierReference || undefined,
'service-status': carrier.serviceStatus || undefined,
'service-type': carrier.serviceType || undefined,
};
}

function clientConnectionToApiConnection(connection: Connection): ConnectionOutput {
return {
'encapsulation-type': connection.encapsulationType || undefined,
'remote-ne-id': connection.remoteNeId || undefined,
'remote-port-id': connection.remotePortId || undefined,
'svlan-assignment-type': connection.svlanAssignmentType || undefined,
mtu: connection.mtu,
tpid: connection.tpId || undefined,
};
}

function clientEvcAttachmentsToApiEvcAttachments(attachments: EvcAttachment[]): EvcAttachmentInput | undefined {
if (!attachments.length) {
return undefined;
}

const result = attachments.map((a: EvcAttachment): EvcAttachmentOutput => {
return {
'evc-type': a.evcType,
'customer-name': a.customerName || undefined,
'circuit-reference': a.circuitReference,
'carrier-reference': a.carrierReference || undefined,
'svlan-id': a.svlanId || undefined,
status: a.status ? clientBearerStatusToApiBearerStatus(a.status) : undefined,
'input-bandwidth': a.inputBandwidth,
'qos-input-profile': a.qosInputProfile || undefined,
'upstream-bearer': a.upstreamBearer || undefined,
};
});

return {
'evc-attachment': result,
};
}

export function clientBearerToApiBearer(bearer: VpnBearer): VpnBearerInput {
const output: VpnBearerInput = {
'vpn-bearer': [
{
'sp-bearer-reference': bearer.spBearerReference,
description: bearer.description || undefined,
'ne-id': bearer.neId,
'port-id': bearer.portId,
status: bearer.status ? clientBearerStatusToApiBearerStatus(bearer.status) : undefined,
carrier: bearer.carrier ? clientCarrierToApiCarrier(bearer.carrier) : undefined,
connection: bearer.connection ? clientConnectionToApiConnection(bearer.connection) : undefined,
'default-upstream-bearer': bearer.defaultUpstreamBearer || undefined,
'evc-attachments': clientEvcAttachmentsToApiEvcAttachments(bearer.evcAttachments),
},
],
};
return output;
}
41 changes: 25 additions & 16 deletions packages/frinx-dashboard/src/api/unistore/network-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,29 +611,38 @@ export function decodeConnectionOutput(value: unknown): ConnectionOutput {
return extractResult(ConnectionOutputValidator.decode(value));
}

const VpnBearerOutputValidator = t.type({
'vpn-bearers': optional(
const VpnBearerItemsOutputValidator = t.type({
'vpn-bearer': t.array(
t.type({
'vpn-bearer': t.array(
'sp-bearer-reference': t.string,
description: optional(t.string),
'ne-id': t.string,
'port-id': t.string,
status: optional(BearerStatusValidator),
carrier: optional(CarrierOutputValidator),
connection: optional(ConnectionOutputValidator),
'default-upstream-bearer': optional(t.string),
'evc-attachments': optional(
t.type({
'sp-bearer-reference': t.string,
description: optional(t.string),
'ne-id': t.string,
'port-id': t.string,
status: optional(BearerStatusValidator),
carrier: optional(CarrierOutputValidator),
connection: optional(ConnectionOutputValidator),
'default-upstream-bearer': optional(t.string),
'evc-attachments': optional(
t.type({
'evc-attachment': t.array(EvcAttachmentOutputValidator),
}),
),
'evc-attachment': t.array(EvcAttachmentOutputValidator),
}),
),
}),
),
});
export type VpnBearerItemsOutput = t.TypeOf<typeof VpnBearerItemsOutputValidator>;
export type VpnBearerInput = VpnBearerItemsOutput;
export function decodeVpnBearerItemsOutput(value: unknown): VpnBearerItemsOutput {
return extractResult(VpnBearerItemsOutputValidator.decode(value));
}

export type EvcAttachmentInput = {
'evc-attachment': EvcAttachmentOutput[];
};

const VpnBearerOutputValidator = t.type({
'vpn-bearers': optional(VpnBearerItemsOutputValidator),
});

export type VpnBearerOutput = t.TypeOf<typeof VpnBearerOutputValidator>;

Expand Down
26 changes: 25 additions & 1 deletion packages/frinx-dashboard/src/api/unistore/unistore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
VpnSite,
decodeVpnBearerOutput,
VpnBearerOutput,
VpnBearer,
} from './network-types';
import { clientVpnServiceToApiVpnService, clientVpnSiteToApiVpnSite } from './converters';
import { clientBearerToApiBearer, clientVpnServiceToApiVpnService, clientVpnSiteToApiVpnSite } from './converters';

// data/network-topology:network-topology/topology=uniconfig/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers
const UNICONFIG_SERVICE_URL =
Expand Down Expand Up @@ -80,3 +81,26 @@ export async function getVpnBearers(): Promise<VpnBearerOutput> {

return data;
}

export async function createVpnBearer(bearer: VpnBearer): Promise<void> {
const body = clientBearerToApiBearer(bearer);
await sendPostRequest(
'/data/network-topology:network-topology/topology=uniconfig/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers',
body,
);
}

export async function editVpnBearer(vpnBearer: VpnBearer): Promise<unknown> {
const body = clientBearerToApiBearer(vpnBearer);
const json = await sendPutRequest(
`/data/network-topology:network-topology/topology=uniconfig/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers/vpn-bearer=${vpnBearer.spBearerReference}`,
body,
);
return json;
}

export async function deleteVpnBearer(id: string): Promise<void> {
await sendDeleteRequest(
`/data/network-topology:network-topology/topology=uniconfig/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers/vpn-bearer=${id}`,
);
}
38 changes: 32 additions & 6 deletions packages/frinx-dashboard/src/gamma-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const GammaApp: VoidFunctionComponent = () => {
CreateDevice,
EditDevice,
VpnBearerList,
CreateBearer,
EditBearer,
getUnistoreApiProvider,
} = gammaImport;

Expand All @@ -53,6 +55,8 @@ const GammaApp: VoidFunctionComponent = () => {
CreateDevice,
EditDevice,
VpnBearerList,
CreateBearer,
EditBearer,
UnistoreApiProvider: getUnistoreApiProvider(callbacks),
});
});
Expand All @@ -77,6 +81,8 @@ const GammaApp: VoidFunctionComponent = () => {
SiteList,
SiteNetworkAccessList,
VpnBearerList,
CreateBearer,
EditBearer,
UnistoreApiProvider,
} = components;

Expand Down Expand Up @@ -237,15 +243,35 @@ const GammaApp: VoidFunctionComponent = () => {
}}
/>
</Route>
<Route path="/gamma/vpn-bearers">

{/* bearers */}
<Route path="/gamma/vpn-bearers" exact>
<VpnBearerList
onEditVpnBearerClick={() => {
// eslint-disable-next-line no-console
console.log('edit click');
onEditVpnBearerClick={(bearerId: string) => {
history.push(`/gamma/vpn-bearers/edit/${bearerId}`);
}}
onCreateVpnBearerClick={() => {
// eslint-disable-next-line no-console
console.log('create click');
history.push(`/gamma/vpn-bearers/add`);
}}
/>
</Route>
<Route path="/gamma/vpn-bearers/add" exact>
<CreateBearer
onSuccess={() => {
history.push(`/gamma/vpn-bearers`);
}}
onCancel={() => {
history.push(`/gamma/vpn-bearers`);
}}
/>
</Route>
<Route path="/gamma/vpn-bearers/edit/:bearerId" exact>
<EditBearer
onSuccess={() => {
history.push('/gamma/vpn-bearers');
}}
onCancel={() => {
history.push('/gamma/vpn-bearers');
}}
/>
</Route>
Expand Down
57 changes: 57 additions & 0 deletions packages/frinx-gamma/docs/gamma-bearer-svc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module: gamma-bearer-svc
+--rw bearer-svc
+--rw valid-provider-identifiers
| +--rw qos-profile-identifier* [id]
| +--rw id string
+--rw carriers
| +--rw carrier* [carrier-name]
| +--rw carrier-name string
| +--rw description? string
+--rw vpn-nodes
| +--rw vpn-node* [ne-id]
| +--rw ne-id string
| +--rw router-id inet:ip-address
| +--rw role? identityref
+--rw vpn-bearers
+--rw vpn-bearer* [sp-bearer-reference]
+--rw sp-bearer-reference svc-id
+--rw description? string
+--rw ne-id -> /bearer-svc/vpn-nodes/vpn-node/ne-id
+--rw port-id string
+--rw status
| +--rw admin-status
| | +--rw status? identityref
| | +--rw last-updated? yang:date-and-time
| +--ro oper-status
| +--ro status? identityref
| +--ro last-updated? yang:date-and-time
+--rw carrier
| +--rw carrier-name? -> /bearer-svc/carriers/carrier/carrier-name
| +--rw carrier-reference? string
| +--rw service-type? identityref
| +--rw service-status? identityref
+--rw connection
| +--rw encapsulation-type? identityref
| +--rw svlan-assignment-type? identityref
| +--rw tpid? identityref
| +--rw mtu uint16
| +--rw remote-ne-id? -> /bearer-svc/vpn-nodes/vpn-node/ne-id
| +--rw remote-port-id? string
+--rw default-upstream-bearer? -> /bearer-svc/vpn-bearers/vpn-bearer/sp-bearer-reference
+--rw evc-attachments
+--rw evc-attachment* [evc-type circuit-reference]
+--rw evc-type identityref
+--rw customer-name? string
+--rw circuit-reference svc-id
+--rw carrier-reference? svc-id
+--rw svlan-id? uint16
+--rw status
| +--rw admin-status
| | +--rw status? identityref
| | +--rw last-updated? yang:date-and-time
| +--ro oper-status
| +--ro status? identityref
| +--ro last-updated? yang:date-and-time
+--rw input-bandwidth uint64
+--rw qos-input-profile? -> /bearer-svc/valid-provider-identifiers/qos-profile-identifier/id
+--rw upstream-bearer? -> /bearer-svc/vpn-bearers/vpn-bearer/sp-bearer-reference
4 changes: 4 additions & 0 deletions packages/frinx-gamma/src/callback-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ValidProviderIdentifiersOutput, VpnBearerOutput, VpnServicesOutput, VpnSitesOutput } from './network-types';
import { VpnService } from './components/forms/service-types';
import { VpnSite } from './components/forms/site-types';
import { VpnBearer } from './components/forms/bearer-types';

export type WorkflowPayload = {
input: unknown;
Expand All @@ -25,6 +26,9 @@ export type Callbacks = {
executeWorkflow: (payload: WorkflowPayload) => Promise<WorkflowExecPayload>;
getWorkflowInstanceDetail: (workflowId: string, options?: RequestInit) => Promise<unknown>;
getVpnBearers: () => Promise<VpnBearerOutput>;
createVpnBearer: (bearer: VpnBearer) => Promise<void>;
editVpnBearer: (bearer: VpnBearer) => Promise<void>;
deleteVpnBearer: (id: string) => Promise<void>;
};
class CallbackUtils {
private callbacks: Callbacks | null = null;
Expand Down
Loading

0 comments on commit 61f61d1

Please sign in to comment.