-- File: GCPrint.mesa, HGM August 19, 1978 7:10 PM
-- Last Modified by Ly September 20, 1978 11:44 AM
DIRECTORY
GCDefs: FROM "GCDefs" USING [GCInterface],
IODefs: FROM "<Mesa>IODefs" USING [
CR, ReadChar, WriteChar, WriteString, WriteLine, WriteOctal, WriteNumber],
PupRouterDefs: FROM "PupRouterDefs" USING [
PupRoutingTableEntry, GetPupRoutingTable, PupGateInfo],
DriverDefs: FROM "DriverDefs" USING [Network],
PupDefs: FROM "PupDefs",
PupTypes: FROM "PupTypes" USING [fillInSocketID, gatewaySoc];
GCPrint: PROGRAM [gc: GCDefs.GCInterface]
IMPORTS GCDefs, IODefs, PupRouterDefs, PupDefs
EXPORTS GCDefs =
BEGIN OPEN gc, GCDefs, IODefs, PupDefs;
GCPrintThings: 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 ← [gc.remHost.net, gc.remHost.host, PupTypes.gatewaySoc];
PrintPupAddress[@address];
WriteChar[CR];
soc ← PupSocketMake[PupTypes.fillInSocketID,address,SecondsToTocks[2]];
THROUGH [0..2) 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];
EXITS
Error => NULL;
Reject => WriteLine["xxx"L];
END;
PrintErrorPup: PUBLIC PROCEDURE [b: PupBuffer] =
BEGIN
i, len: CARDINAL;
WriteChar[CR];
IF b.pupType=error THEN
BEGIN
WriteString["[Error Pup, code="L];
WriteOctal[b.errorCode];
WriteString["] "L];
len ← GetPupContentsBytes[b];
FOR i IN [0..len-2*(10+1+1)) DO WriteChar[b.errorText[i]]; ENDLOOP;
END
ELSE
BEGIN
WriteString["***** Funny PupType = "L];
WriteOctal[b.pupType];
WriteString[" *****"L];
END;
WriteChar[CR];
END;
PrintPupAddress: PUBLIC PROCEDURE [a: POINTER TO PupAddress] =
BEGIN
buffer: STRING ← [50];
AppendPupAddress[buffer,a];
WriteString[buffer];
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.