IF Commons GitHub

logical/discovery

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-estate-logical FR-009

Discovery of devices on a network by what a machine already knows of it: the neighbor table (ip neigh) or the ARP table (arp -an) read as devices with an address and a hardware address, and the devices that no declaration expects. Nothing is scanned: a device that has not talked to this machine is not seen, and a discovered asset is only listed (0002-estate-governance FR-002).

import { parseNeighbors } from "./discovery.ts";
parseNeighbors("192.168.1.20 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE")[0]?.mac; // "aa:bb:cc:dd:ee:ff"

Source: commons/estate/src/logical/discovery.ts

3 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

SeenDevicetypeno test imports it
type SeenDevice = { readonly address: string; readonly mac: string; readonly interface: string };

A device seen: its address, its hardware address and the interface it was seen on.

parseNeighborsfunction
function parseNeighbors(text: string): readonly SeenDevice[]

The devices of a neighbor table, in the form of ip neigh show (<address> dev <if> lladdr <mac> <state>) or arp -an (? (<address>) at <mac> [ether] on <if>); an entry with no hardware address (FAILED, INCOMPLETE), a broadcast or a multicast address is not a device, and a device is once, by its hardware address.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

deviceIdOfconst
const deviceIdOf: (mac: string) => string

The identity a discovered device gets: device- and its hardware address without the colons.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

Declaredtypeno test imports it
type Declared = { readonly asset: string; readonly address?: string; readonly mac?: string };

What an estate declares of a device the network may show: the address or the hardware address of an asset.

unexpectedDevicesfunction
function unexpectedDevices(declared: readonly Declared[], seen: readonly SeenDevice[]): { readonly unexpected: readonly SeenDevice[]; readonly unseen: readonly string[]; }

The devices seen that no asset declares (by hardware address, or by address where no hardware address is declared), and the assets that declare an address or a hardware address and were not seen.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.