// GateConSLAStats.bcpl

// Last modified April 28, 1982  10:32 AM by Taft

get "Pup0.decl"
get "PupAlComProc.decl"

external
[
// outgoing procedure
PrintSLAStats

// incoming procedures
Ws; PutTemplate; Puts; Error

// incoming statics
dsp
]

//----------------------------------------------------------------------------
let PrintSLAStats(pbi) be
//----------------------------------------------------------------------------
[
let stats = lv pbi>>PBI.pup.words
if stats>>SLAStats.statsVersion ne slaStatsVersion then
   [ Error("Incompatible format"); return ]

Ws("*NSLA Statistics:*N")
Ws("        ----Packets---     -----Bytes-----    ------Errors------*n")
Ws("Line    Sent  Received     Sent   Received    CRC   Sync Control   State*n")

let maxSLAHost = stats>>SLAStats.maxHost
let rt = lv stats>>SLAStats.rt
let maxSLALine = rt!(maxSLAHost*lenRTE)
let lineStats = rt + (maxSLAHost*lenRTE) +1

for line = 0 to maxSLALine do
   [
   let l = lineStats + line*lenLineStats
   if l>>LineStats.state eq slaLineMissing loop
   PutTemplate(dsp, "$3O$9UED$9UED$10UED$10UED  $6UD$6UD$6UD      $S*n", line,
    lv l>>LineStats.transmitPackets, lv l>>LineStats.receivePackets,
    lv l>>LineStats.transmitBytes, lv l>>LineStats.receiveBytes,
    l>>LineStats.badCRC, l>>LineStats.inputOverrun,
    l>>LineStats.lineControlError,
    selecton l>>LineStats.state into
      [
      case slaLineDown: "Down"
      case slaLineUp: "Up"
      case slaLineLoopedBack: "Looped"
      default: "?"
      ])
   ]

Ws("*nRouting table:*n")
for i = 1 to 4 do Ws("Host Line Hops    ")
let count = 0
for host = 1 to maxSLAHost do
   [
   let rte = rt + host-1
   if rte>>RTE.hopCnt ne 377b then
      [
      PutTemplate(dsp, "$S$3O  $3O  $3D", (count rem 4 eq 0? "*n", "     "),
       host, rte>>RTE.line, rte>>RTE.hopCnt)
      count = count +1
      ]
   ]

Puts(dsp, $*n)
]