Skip to content

Commit

Permalink
dpdkmgmt: upgrade to node-memif 0.0.20230715
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jul 16, 2023
1 parent bf795e1 commit a120314
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 52 deletions.
3 changes: 2 additions & 1 deletion mk/check-dep.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async function* listImports(filename) {
}
}

const ignoredMissing = new Set(["memif"]);
const ignoredUnused = new Set(["@types/web-bluetooth", "graphql", "tslib"]);
const ignoredTypes = new Set(["yargs"]);

Expand All @@ -41,7 +42,7 @@ for (const [folder, { dependencies = {}, devDependencies = {} }] of Object.entri
for (const { path: filename } of jsFiles) {
for await (const dep of listImports(filename)) {
unusedP.delete(dep);
if (!dependencies[dep] && !isBuiltin(dep)) {
if (!dependencies[dep] && !isBuiltin(dep) && !ignoredMissing.has(dep)) {
process.stdout.write(`P+\t${filename}\t${dep}\n`);
++nWarnings;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dpdkmgmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"tslib": "^2.6.0"
},
"optionalDependencies": {
"memif": "0.0.20220425"
"memif": "0.0.20230715"
}
}
11 changes: 3 additions & 8 deletions packages/dpdkmgmt/src/face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { joinHostPort, splitHostPort, udp_helper, UdpTransport } from "@ndn/node
import type { NameLike } from "@ndn/packet";
import { gql, GraphQLClient } from "graphql-request";

import { Delete } from "./gql";
import { MemifTransport } from "./memif-transport";
import { NdndpdkPrefixReg } from "./prefix-reg";

Expand All @@ -28,7 +29,7 @@ async function detectLocalAddress(gqlServer: string): Promise<string> {

async function openFaceImpl(
{
gqlServer = "http://127.0.0.1:3030",
gqlServer = DefaultGqlServer,
fw = Forwarder.getDefault(),
addRoutes,
attributes = {},
Expand Down Expand Up @@ -56,13 +57,7 @@ async function openFaceImpl(
const prefixReg = new NdndpdkPrefixReg(client, id);
const cleanup = async () => {
prefixReg.disable();
await client.request(gql`
mutation delete($id: ID!) {
delete(id: $id)
}
`, {
id,
});
await client.request<Delete.Resp, Delete.Vars>(Delete, { id });
};

let transport: Transport;
Expand Down
37 changes: 37 additions & 0 deletions packages/dpdkmgmt/src/gql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { gql, type Variables } from "graphql-request";

export const Delete = gql`
mutation delete($id: ID!) {
delete(id: $id)
}
`;
export namespace Delete {
export interface Vars extends Variables {
id: string;
}

export interface Resp {
delete: boolean;
}
}

export const InsertFibEntry = gql`
mutation insertFibEntry($name: Name!, $nexthops: [ID!]!, $strategy: ID) {
insertFibEntry(name: $name, nexthops: $nexthops, strategy: $strategy) {
id
}
}
`;
export namespace InsertFibEntry {
export interface Vars extends Variables {
name: string;
nexthops: string[];
strategy?: string;
}

export interface Resp {
insertFibEntry: {
id: string;
};
}
}
6 changes: 1 addition & 5 deletions packages/dpdkmgmt/src/memif-transport.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { once } from "node:events";
import { createRequire } from "node:module";

import { L3Face, rxFromPacketIterable, Transport, txToStream } from "@ndn/l3face";
import type { Memif } from "memif";

// don't name this 'require' to avoid @typescript-eslint/no-require-imports
const cjsRequire = createRequire(import.meta.url);

/** Shared Memory Packet Interface (memif) transport. */
export class MemifTransport extends Transport {
public override readonly rx: Transport.Rx;
Expand Down Expand Up @@ -50,7 +46,7 @@ export namespace MemifTransport {
waitUp = true,
} = opts;

const MemifConstructor: typeof Memif = cjsRequire("memif").Memif;
const MemifConstructor: typeof Memif = (await import("memif")).Memif;
const transport = new MemifTransport(opts, new MemifConstructor(opts));

if (waitUp) {
Expand Down
48 changes: 11 additions & 37 deletions packages/dpdkmgmt/src/prefix-reg.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
import { ReadvertiseDestination } from "@ndn/fw";
import type { Name } from "@ndn/packet";
import { gql, type GraphQLClient, type Variables } from "graphql-request";
import type { GraphQLClient } from "graphql-request";

import { Delete, InsertFibEntry } from "./gql";

interface State {
fibEntryID?: string;
}

interface InsertFibEntryVars extends Variables {
name: string;
nexthops: string[];
}

interface InsertFibEntryResp {
insertFibEntry: {
id: string;
};
}

interface DeleteVars extends Variables {
id: string;
}

interface DeleteResp {
delete: boolean;
}

/** Enable prefix registration via NDN-DPDK GraphQL management API. */
export class NdndpdkPrefixReg extends ReadvertiseDestination<State> {
constructor(private readonly client: GraphQLClient, private readonly faceID: string) {
super();
}

protected override async doAdvertise(name: Name, state: State) {
const resp = await this.client.request<InsertFibEntryResp, InsertFibEntryVars>(gql`
mutation insertFibEntry($name: Name!, $nexthops: [ID!]!, $strategy: ID) {
insertFibEntry(name: $name, nexthops: $nexthops, strategy: $strategy) {
id
}
}
`, {
name: name.toString(),
nexthops: [this.faceID],
});
const resp = await this.client.request<InsertFibEntry.Resp, InsertFibEntry.Vars>(
InsertFibEntry,
{
name: name.toString(),
nexthops: [this.faceID],
},
);
state.fibEntryID = resp.insertFibEntry.id;
}

Expand All @@ -50,13 +30,7 @@ export class NdndpdkPrefixReg extends ReadvertiseDestination<State> {
if (!state.fibEntryID) {
return;
}
await this.client.request<DeleteResp, DeleteVars>(gql`
mutation delete($id: ID!) {
delete(id: $id)
}
`, {
id: state.fibEntryID,
});
await this.client.request<Delete.Resp, Delete.Vars>(Delete, { id: state.fibEntryID });
delete state.fibEntryID;
}
}

0 comments on commit a120314

Please sign in to comment.