-- File: AltoPRDefs.mesa
-- Last Edit: L. Stewart  February 20, 1980  4:24 PM
-- Last Edit: HGM  September 14, 1980  12:17 AM

DIRECTORY
  DriverTypes USING [PRPacketType],
  StatsDefs USING [StatCounterIndex];

AltoPRDefs: DEFINITIONS =
  BEGIN

  -- Useful Types

  Byte: TYPE = [0..377B];

  --Packet Radio Stuff

  PRLengthWord: TYPE = MACHINE DEPENDENT RECORD [
    blank: INTEGER [0..15], header: INTEGER [0..15], packet: INTEGER [0..377B]];

  PRAddress: TYPE = WORD;
  PRSequence: TYPE = MACHINE DEPENDENT RECORD [
    number: INTEGER [0..8191], spp: INTEGER [0..7]];

  PRControlWord: TYPE = RECORD [WORD];
  PRStatisticsWord: TYPE = RECORD [WORD];
  PRRouteIndex: TYPE = INTEGER [1..8];
  PRRoute: TYPE = ARRAY PRRouteIndex OF PRAddress;

  PRLeader: TYPE = MACHINE DEPENDENT RECORD [
    length: PRLengthWord,
    source: PRAddress,
    destination: PRAddress,
    sequence: PRSequence,
    control: PRControlWord,
    stats: PRStatisticsWord,
    route: PRRoute];

  PRTOP: TYPE = MACHINE DEPENDENT RECORD [
    leader: PRLeader, startID, endID: PRAddress];

  PRPupHeader: TYPE = MACHINE DEPENDENT RECORD [
    leader: PRLeader,
    magic: Byte,
    fragmentation: RECORD [
      thisFrag: INTEGER [0..3],
      numFrags: INTEGER [0..3],
      packetType: DriverTypes.PRPacketType],
    packetNumber: INTEGER];

  PRBuffer: TYPE = MACHINE DEPENDENT RECORD [
    h: PRPupHeader,
    body: ARRAY [1..127 - SIZE[PRPupHeader] + 3] OF WORD --one longer than needed
    ];

  -- Particular values
  prInvalidAddress: PRAddress = 177777B;
  prInitialSequenceNumber: PRSequence = [0, 0];
  prNoStats: PRStatisticsWord = [0];
  prNullRoute: PRRoute = [0, 0, 0, 0, 0, 0, 0, 0];

  prTOPControlWord: PRControlWord = [000000B];
  prRegularControlWord: PRControlWord = [064001B];

  prTOPLeader: PRLeader =
    [length: [0, SIZE[PRLeader], SIZE[PRTOP]], source: 0B, destination: 0B,
      sequence: prInitialSequenceNumber, control: prTOPControlWord,
      stats: prNoStats, route: prNullRoute];

  prPupLeader: PRLeader =
    [length: [0, SIZE[PRLeader], 0], source: 0B, destination: 0B,
      sequence: prInitialSequenceNumber, control: prRegularControlWord,
      stats: prNoStats, route: prNullRoute];

  prSecretNumber: Byte = 303B;

  -- Types for driver

  WatchMode: TYPE = {normal, flappingRelay, justFlapped};
  InputMode: TYPE = {discard, normal};
  OutputMode: TYPE = {idle, sendTop, normal};
  PRRouteSet: TYPE = ARRAY [1..maxPRPupAddress] OF PRRoute;

  PRAliveTable: TYPE = ARRAY [1..maxPRPupAddress] OF BOOLEAN;

  PRImAliveEntry: TYPE = MACHINE DEPENDENT RECORD [
    source: CARDINAL, iHeardYou: PRAliveTable];

  --  Special record for poking driver from outside

  GetPRDriverVars: PROCEDURE RETURNS [POINTER TO PRDriverVars];
  PRDriverVars: TYPE = RECORD [
    outBufp: POINTER TO PRBuffer, --outputHeader
    inBufp: POINTER TO PRBuffer, --inputHeader
    topp: POINTER TO PRTOP, --TOP
    cbp: POINTER,
    prRouteSetp: POINTER TO PRRouteSet,
    prTOPInterval: CARDINAL, -- these are Alto ticks
    outputTimeoutInterval: CARDINAL,
    assemblyTimeoutInterval: CARDINAL,
    imAliveInterval: CARDINAL,
    prHostAliveTimeoutInterval: CARDINAL,
    maxOutputQueueLength: CARDINAL,
    maxAssemblyQueueLength: CARDINAL,
    hiQ, loQ: POINTER, --outputQueues
    aQ: POINTER, --assemblyQueue
    youAreOK: PRAliveTable,
    iHearYou: ARRAY [1..maxPRPupAddress] OF CARDINAL];

  --  Things that are not provided anywhere
  maxFragSize: CARDINAL = 127 - SIZE[PRPupHeader]; -- = 111 these days
  maxOneFragSize: CARDINAL = maxFragSize;
  maxTwoFragSize: CARDINAL = 2*maxFragSize;
  maxThreeFragSize: CARDINAL = 3*maxFragSize;
  maxPRPupAddress: CARDINAL = 5;
  prAddressBase: CARDINAL = 10220B;

  -- Procedures, etc.

  AltoPRInit: PROGRAM;


  SetupPRThings: PROCEDURE;

  statPRPacketsReceived: StatsDefs.StatCounterIndex;
  statPRImAliveReceived: StatsDefs.StatCounterIndex;
  statPROneFragRcvd: StatsDefs.StatCounterIndex;
  statPRTwoFragsRcvd: StatsDefs.StatCounterIndex;
  statPRThreeFragsRcvd: StatsDefs.StatCounterIndex;
  statPRWordsReceived: StatsDefs.StatCounterIndex;

  statPRPacketsSent: StatsDefs.StatCounterIndex;
  statPRImAliveSent: StatsDefs.StatCounterIndex;
  statPROneFragSent: StatsDefs.StatCounterIndex;
  statPRTwoFragsSent: StatsDefs.StatCounterIndex;
  statPRThreeFragsSent: StatsDefs.StatCounterIndex;
  statPRWordsSent: StatsDefs.StatCounterIndex;

  statPRDuplicateFragment: StatsDefs.StatCounterIndex;
  statPRAssemblyTimeout: StatsDefs.StatCounterIndex;
  statPRAssemblyQOvf: StatsDefs.StatCounterIndex;
  statPRInputBufferOvf: StatsDefs.StatCounterIndex;

  statPRBadMagic: StatsDefs.StatCounterIndex;
  statPRNotForMe: StatsDefs.StatCounterIndex;
  statPRTooManyFragments: StatsDefs.StatCounterIndex;
  statPRTotalTooBig: StatsDefs.StatCounterIndex;
  statPREmptyFreeQueue: StatsDefs.StatCounterIndex;

  statPROldPackets: StatsDefs.StatCounterIndex;
  statPRPacketsSkipped: StatsDefs.StatCounterIndex;
  statPRSequenceReset: StatsDefs.StatCounterIndex;

  statPRLengthOvf: StatsDefs.StatCounterIndex;
  statPRInvalidAddress: StatsDefs.StatCounterIndex;
  statPRDestinationDown: StatsDefs.StatCounterIndex;
  statPROutputQOvf: StatsDefs.StatCounterIndex;
  statPRConnectionLimit: StatsDefs.StatCounterIndex;
  statPROutPacketsDiscarded: StatsDefs.StatCounterIndex;

  stat1822MissingInterrupt: StatsDefs.StatCounterIndex;
  statPRTransferTimeout: StatsDefs.StatCounterIndex;
  statPRROPsReceived: StatsDefs.StatCounterIndex;
  statPRTOPsSent: StatsDefs.StatCounterIndex;
  statPRImpWasDown: StatsDefs.StatCounterIndex;

  -- GateControl Things

  prStatsReply: WORD = 5;

  PRStatsEntry: TYPE = RECORD [
    version: WORD,
    packetsReceived, imAliveReceived, oneFragPupRcvd, twoFragPupRcvd,
      threeFragPupRcvd, wordsReceived, packetsSent, imAliveSent, oneFragPupSent,
      twoFragPupSent, threeFragPupSent, wordsSent, topsSent, assemblyTimeout,
      assemblyOverflow, destinationDown, inputFilter, oldPackets, skippedPackets,
      sequencerResets, outputPacketsDiscarded, transferTimeout: LONG INTEGER,
    maxHosts: CARDINAL,
    hostsUp: ARRAY [0..0) OF BOOLEAN];
  prVersion: WORD = 1;

  END.  -- AltoPRDefs