-- File: PtPrint.mesa, Last Edit:
-- MAS April 21, 1980 6:55 PM
-- HGM November 19, 1979 12:03 PM

DIRECTORY
IODefs
: FROM "IODefs" USING [
CR, ReadChar, WriteChar, WriteString, WriteLine, WriteNumber],
PupRouterDefs: FROM "PupRouterDefs" USING [
PupRoutingTableEntry, GetPupRoutingTable, PupGateInfo],
DriverDefs: FROM "DriverDefs" USING [Network],
PupDefs: FROM "PupDefs",
PupTypes: FROM "PupTypes" USING [fillInSocketID, gatewaySoc],
PtDefs: FROM "PtDefs" USING [
PtInterface];

PtPrint: PROGRAM [
pt: PtDefs.PtInterface]
IMPORTS IODefs, PupRouterDefs, PupDefs
EXPORTS PtDefs =
BEGIN OPEN IODefs, PupDefs;

PtPrintThings: PUBLIC PROCEDURE =
BEGIN
WriteString["Print "L];
SELECT ReadChar[] FROM
’L, ’l =>
BEGIN
WriteLine["Local routing table."L];
LocalRoutingTable[];
END;
’R, ’r =>
BEGIN
WriteString["Remote routing table from: "L];
RemoteRoutingTable[];
END;
’? => WriteLine["L(ocal routing table), or R(emote routing table)."L];
ENDCASE => WriteLine["???"L];
END;

LocalRoutingTable: PROCEDURE =
BEGIN
pupRt:
DESCRIPTOR FOR ARRAY OF PupRouterDefs.PupRoutingTableEntry;
pupRte:
POINTER TO PupRouterDefs.PupRoutingTableEntry;
network: DriverDefs.Network;
i, k: CARDINAL;
pupRt ← PupRouterDefs.GetPupRoutingTable[];
WriteChar[CR];
WriteLine["Local Routing Table:"L];
WriteLine["| Net Via Hops | Net Via Hops | Net Via Hops |"L];
WriteLine["|-------------------|-------------------|-------------------|"L];
k ← 0;
FOR i IN [0..LENGTH[pupRt]) DO
pupRte ← @pupRt[i];
network ← pupRte.network;
IF network=NIL THEN LOOP;
IF k=0 THEN WriteChar[’|];
O4[i];
O4[network.netNumber];
WriteChar[’#];
IF pupRte.hop#0 THEN O3Z[pupRte.route] ELSE O3Z[network.hostNumber];
WriteChar[’#];
O4[pupRte.hop];
WriteString[" |"L];
IF (k←k+1)=3 THEN BEGIN WriteChar[CR]; k←0; END;
ENDLOOP;
IF k#0 THEN WriteChar[CR];
END;

RemoteRoutingTable: PROCEDURE =
BEGIN
soc: PupSocket;
b: PupBuffer;
address: PupAddress ← [pt.pullHim.net, pt.pullHim.host, PupTypes.gatewaySoc];
PrintPupAddress[address];
WriteChar[CR];
soc ← PupSocketMake[PupTypes.fillInSocketID,address,SecondsToTocks[2]];
THROUGH [0..10) DO -- try a few times
b ← GetFreePupBuffer[];
b.pupType ← gatewayRequest;
SetPupContentsBytes[b,0];
b.pupID ← [0,0];
soc.put[b];
b ← soc.get[]; -- 2 sec wait
IF b#NIL THEN
BEGIN
WriteString["Reply from: "L];
PrintPupAddress[b.source];
WriteChar[CR];
SELECT b.pupType FROM
gatewayInfo =>
BEGIN
length: CARDINAL = GetPupContentsBytes[b];
data: POINTER TO PupRouterDefs.PupGateInfo ← LOOPHOLE[@b.pupWords];
i, k, n: CARDINAL;
n ← length/(2*SIZE[PupRouterDefs.PupGateInfo]);
IF (length MOD (2*SIZE[PupRouterDefs.PupGateInfo]))#0 THEN
WriteLine["***** Funny Length *****"L];
WriteLine["| Net Via Hops | Net Via Hops | Net Via Hops |"L];
WriteLine["|-------------------|-------------------|-------------------|"L];
k ← 0;
FOR i IN [0..n) DO
IF k=0 THEN WriteChar[’|];
O4[data.net];
O4[data.viaNet];
WriteChar[’#];
O3Z[data.viaHost];
WriteChar[’#];
O4[data.hop];
WriteString[" |"L];
IF (k←k+1)=3 THEN BEGIN WriteChar[CR]; k←0; END;
data ← data+SIZE[PupRouterDefs.PupGateInfo];
ENDLOOP;
IF k#0 THEN WriteChar[CR];
END;
ENDCASE => PrintErrorPup[b];
ReturnFreePupBuffer[b];
EXIT;
END
ELSE WriteLine["No Response that try."L];
ENDLOOP;
PupSocketDestroy[soc];
END;


O3: PROCEDURE [n: CARDINAL] =
BEGIN
WriteNumber[n,[8,FALSE,TRUE,4]];
END;

O3Z: PROCEDURE [n: CARDINAL] =
BEGIN
WriteNumber[n,[8,TRUE,TRUE,3]];
END;

O4: PROCEDURE [n: CARDINAL] =
BEGIN
WriteNumber[n,[8,FALSE,TRUE,4]];
END;

O6: PROCEDURE [n: CARDINAL] =
BEGIN
WriteNumber[n,[8,FALSE,TRUE,7]];
END;

-- initialization
END.