-- File: AltoSlaStats.mesa,  Last Edit: HGM  October 19, 1980  2:08 AM

DIRECTORY
  InlineDefs USING [MesaToBcplLongNumber],
  AltoSlaDefs USING [
    maxSlaHost, SlaHost, RoutingTableEntry, Line, LineInfoBlock, LIB,
    GetSlaRoutingTable, GetSlaInfoBlocks, SlaStatsEntry, slaStatsReply,
    slaVersion],
  PupDefs USING [PupBuffer],
  DriverDefs USING [Network];

AltoSlaStats: PROGRAM IMPORTS InlineDefs, AltoSlaDefs EXPORTS DriverDefs =
  BEGIN OPEN PupDefs;


  SlaStats: PUBLIC PROCEDURE [b: PupBuffer, network: DriverDefs.Network]
    RETURNS [BOOLEAN] =
    BEGIN OPEN AltoSlaDefs;
    sizeOfRoutingTable: CARDINAL = maxSlaHost*SIZE[RoutingTableEntry];
    routingTable: POINTER TO ARRAY SlaHost OF RoutingTableEntry;
    lineInfo: DESCRIPTOR FOR ARRAY OF LineInfoBlock;
    activeLines: Line;
    line: Line;
    host: SlaHost;
    lib: LIB;
    rte: LONG POINTER TO RoutingTableEntry;
    sse: LONG POINTER TO SlaStatsEntry;
    routingTable ← GetSlaRoutingTable[];
    lineInfo ← GetSlaInfoBlocks[];
    activeLines ← LENGTH[lineInfo];
    b.pupWords[0] ← slaStatsReply;
    b.pupWords[1] ← slaVersion;
    b.pupWords[2] ← maxSlaHost;
    rte ← LOOPHOLE[@b.pupWords[3]];
    FOR host IN SlaHost DO
      rte↑ ← routingTable[host]; rte ← rte + SIZE[RoutingTableEntry]; ENDLOOP;
    b.pupWords[3 + sizeOfRoutingTable] ← activeLines - 1;
    sse ← LOOPHOLE[@b.pupWords[4 + sizeOfRoutingTable]];
    FOR line IN [0..activeLines) DO
      lib ← @lineInfo[line];
      sse↑ ←
	[packetsSent: InlineDefs.MesaToBcplLongNumber[lib.packetsSent],
	  packetsRecv: InlineDefs.MesaToBcplLongNumber[lib.packetsRecv],
	  bytesSent: InlineDefs.MesaToBcplLongNumber[lib.bytesSent],
	  bytesRecv: InlineDefs.MesaToBcplLongNumber[lib.bytesRecv],
	  syncErrors: lib.syncErrors, badCrc: lib.crcErrors,
	  controlError: lib.controlErrors, state: LOOPHOLE[lib.state]];
      sse ← sse + SIZE[SlaStatsEntry];
      ENDLOOP;
    b.pupLength ←
      22 + 2*(4 + sizeOfRoutingTable + activeLines*SIZE[SlaStatsEntry]);
    RETURN[TRUE];
    END;

  -- initialization

  END.