-- File: ForwarderCold.mesa - last edit:
-- AOF                  3-Feb-88 15:47:14
-- HGM                  6-Aug-85 21:00:37
-- Copyright (C) 1984, 1985, 1988 by Xerox Corporation. All rights reserved. 

DIRECTORY
  Event USING [aboutToSwap],
  EventTypes USING [aboutToBoot, aboutToBootPhysicalVolume],
  Supervisor USING [
    AddDependency, AgentProcedure, CreateSubsystem, SubsystemHandle],
  ForwarderDefs USING [PupForwarderOff],
  PupRouterDefs USING [NetworkContext],
  PupDefs USING [Body, PupBuffer, ReturnBuffer],
  PupTypes USING [gatewaySoc],
  Stats USING [StatCounterIndex, StatsStringToIndex],
  Trouble USING [Bug];

ForwarderCold: PROGRAM
  IMPORTS Event, Supervisor, ForwarderDefs, PupDefs, Stats, Trouble
  EXPORTS ForwarderDefs =
  BEGIN OPEN Stats;

  -- EXPORTed TYPEs

  broom: Supervisor.SubsystemHandle = Supervisor.CreateSubsystem[Broom];

  statPupGatewayPacketMs: PUBLIC StatCounterIndex;
  statGateInfoReplies: PUBLIC StatCounterIndex;
  statGateInfoBC: PUBLIC StatCounterIndex;
  statRoutingTableChanges: PUBLIC StatCounterIndex;
  statGateLowOnBuffers: PUBLIC StatCounterIndex;
  statGarbageSourceOrDest: PUBLIC StatCounterIndex;
  statNoRouteToNet: PUBLIC StatCounterIndex;
  statTooManyHops: PUBLIC StatCounterIndex;

  Broom: Supervisor.AgentProcedure =
    BEGIN
    SELECT event FROM
      EventTypes.aboutToBoot, EventTypes.aboutToBootPhysicalVolume =>
        ForwarderDefs.PupForwarderOff[];
      ENDCASE => NULL;
    END;

  SetupForwarderThings: PUBLIC PROCEDURE =
    BEGIN
    statPupGatewayPacketMs ← StatsStringToIndex["MS spent processing Pup Gateway Info Packets"];
    statGateInfoReplies ← StatsStringToIndex["Pup Gateway Info Replies"];
    statGateInfoBC ← StatsStringToIndex["Pup Gateway Info Broadcasts"];
    statRoutingTableChanges ← StatsStringToIndex["Pup Routing Table Changes"];
    statGateLowOnBuffers ← StatsStringToIndex[
      "Pups not forwarded: Gateway low on buffers"];
    statGarbageSourceOrDest ← StatsStringToIndex[
      "Pups not forwarded: Garbage source or dest"];
    statNoRouteToNet ← StatsStringToIndex[
      "Pups not forwarded: No route to that network"];
    statTooManyHops ← StatsStringToIndex[
      "Pups not forwarded: Hop count exceeded"];
    END;

  PeekAtRoutingPup: PUBLIC PROCEDURE [b: PupDefs.PupBuffer] =
    BEGIN
    body: PupDefs.Body = b.pup;
    net: CARDINAL ← body.source.net;
    context: PupRouterDefs.NetworkContext ← b.fo.context;
    <<
    Forwarder got a Pup before it was turned on.  See if it is the reply that
    would tell us that we have a buggy network number.
    >>
    IF body.pupType = gatewayInfo AND body.source.socket = PupTypes.gatewaySoc
      AND (net # context.pupNetNumber OR body.pupTransportControl # 0)
      AND context.pupNetNumber < 400B THEN Trouble.Bug["Wrong network number"L];
    PupDefs.ReturnBuffer[b];
    END;

  -- initialization
  SetupForwarderThings[];
  Supervisor.AddDependency[client: broom, implementor: Event.aboutToSwap];
  END.