! Common formats for (Moose) INet process, GDMR, Jan. 1988

%include "Moose:Mouse.Inc"

! IP/ICMP/UDP/TCP/ether header formats and constants

%recordformat ether address fm(%bytearray x(0 : 5))

%recordformat IP header fm(%byte IHL,                { includes version }
                           %byte type of service,
                           %short total length,
                           %short identification,
                           %short fragment offset,   { includes flags }
                           %byte TTL,
                           %byte protocol,
                           %short checksum,
                           %integer source,
                           %integer destination,
                           %bytearray options(1 : 8))
%constinteger IP header size = 20;  ! Not including options

! Remove this next asap.
%constintegerarray new broadcast mask('@' : 'C') =
      16_00000000, 16_00FFFFFF, 16_0000FFFF, 16_000000FF

%constinteger IP ICMP protocol = 1
%constinteger IP TCP  protocol = 6
%constinteger IP UDP  protocol = 17

%recordformat TCP header fm(%short source, destination,
                            %integer seq,
                            %integer ack,
                            %byte data offset,
                            %byte flags,
                            %short window,
                            %short checksum,
                            %short urgent,
                            %integer options)
%constinteger TCP header size = 20;  ! Not including options

%constinteger FIN bit = 2_000001
%constinteger SYN bit = 2_000010
%constinteger RST bit = 2_000100
%constinteger PSH bit = 2_001000
%constinteger ACK bit = 2_010000
%constinteger URG bit = 2_100000

%constinteger TCP define max segment = 2

%recordformat UDP header fm(%short source,
                            %short destination,
                            %short length,
                            %short checksum)

%recordformat ICMP header fm(%byte type,
                             %byte code,
                             %short checksum,
                             ((%short identifier,
                               %short sequence number) %c
                          %or %integer gateway address),
                             (%integer originate timestamp,
                              %integer receive timestamp,
                              %integer transmit timestamp))


! TCP TCB format & constants

%constinteger max TCB table = 512;  ! Upper bound only
%ownstring(31) TCB table name = "INET__TCB_TABLE"

%constinteger time wait timeout = 12000;  ! msecs

%constinteger TCP initial receive window  = 2048
%constinteger TCP unspecified mrss        = 1024;  ! For compatibility
%constinteger TCP default mrss            = 1024

%recordformat TCB fm(%integer remote address, remote port, local port,
                     %integer slot,
                     %integer ISS, IRS, FIN seq,
                     %integer snd una, snd nxt, snd up,
                     %integer snd wnd, snd wl1, snd wl2,
                     %integer rcv nxt, rcv wnd, rcv up,
                     %integer state, previous state, state change stamp,
                     %integer ack pending, blocked send,
                     %record(queue fm) blocked send queue,
                     %record(queue fm) retransmit queue,
                     %record(queue fm) reordering queue,
                     %record(queue fm) state change queue,
                     %integer retransmit timer, retransmit timeout,
                     %integer rto, avg, mdev,
                     %integer mrss, mtss)
! retransmit timer    contains stamp when packet was sent
! retransmit timeout  contains offset for when retransmission is required
%constinteger TCB size = 12 + 4 + 4 + 12 + 24 + 12 + 12 + 8 + 4*16 + 8 + 12 + 8

%recordformat TCB table fm(%record(TCB fm)%array TCB(1 : max TCB table))

! TCP states (**NB order important**)
%constinteger TCP closed         = 0
%constinteger TCP listen         = 1
%constinteger TCP syn sent       = 2
%constinteger TCP syn received   = 3
%constinteger TCP established    = 4
%constinteger TCP fin wait 1     = 5
%constinteger TCP fin wait 2     = 6
%constinteger TCP close wait     = 7
! States from here on are ignored for (implied) ABORT requests
%constinteger TCP closing        = 8
%constinteger TCP last ack       = 9
%constinteger TCP time wait      = 10

%conststring(15)%array TCP state name(TCP closed : TCP time wait) =
   "closed",
   "listen",
   "syn sent",
   "syn received",
   "established",
   "fin wait 1",
   "fin wait 2",
   "close wait",
   "closing",
   "last ack",
   "time wait"

%constinteger TCP initial RTT =  600;  ! msecs

%constinteger TCP reTX lbound =  300;  ! msecs
%constinteger TCP reTX ubound = 8000;  ! msecs


! UDP tables: format and constants

%constinteger UDP table entries = 128;  ! Upper bound only

%ownstring(31) UDP table name = "INET__UDP_TABLES"

%recordformat UDP entry fm(%integer slot,
                           %integer remote address, remote port, local port)
%constinteger UDP entry size = 4 + 4 + 12

%recordformat UDP table fm(%c
   %record(UDP entry fm)%array UDP(1 : UDP table entries))
%constinteger UDP table size = UDP entry size * UDP table entries


! Internal buffer format and constants

%recordformat buffer fm(%record(queue fm) q,
                        %integer IP peer, IP target, protocol,
                        %integer ARP lives, seq, flags, interface,
                        %integer stamp, life, interval,
                        %integer privilege,
                        %record(queue fm)%name next queue,
                        (%record(TCB fm)%name TCB %c
                         %or %record(UDP entry fm)%name UDP entry),
                        %integer tag, IP tag, acceptable,
                        %integer code, bytes, IP bytes, data bytes,
                        %record(IP header fm)%name IP header,
                        (%record(*)%name header2 %or %c
                         %record(TCP header fm)%name TCP header %or %c
                         %record(UDP header fm)%name UDP header %or %c
                         %record(ICMP header fm)%name ICMP header),
                        %bytename data start,
                        %bytearray data(0 : 1539),
                        %bytearray message(0 : 127))  { Must be word aligned! }
%constinteger buffer size = 16 + 24 + 16 + 4 + 4 + 4 + 12 + %c
                            16 + 4 + 4 + 4 + 1540 + 128
%constinteger copy or clear = buffer size - 1540 + 128

%constinteger ignore seq      =  1
%constinteger ignore SYN      =  2
%constinteger ignore ACK      =  4
%constinteger requeue flag    =  8
%constinteger do first        = 16
%constinteger do sixth        = 32
%constinteger broadcast flag  = 64


! Lights bits

%constinteger ARP          light = 16_01000000
%constinteger ether        light = 16_02000000
%constinteger slow ether   light = 16_04000000
%constinteger IP           light = 16_08000000
%constinteger ICMP         light = 16_10000000
%constinteger TCP          light = 16_20000000
%constinteger UDP          light = 16_40000000
%constinteger routed       light = 16_80000000
 
%constinteger clear lights       = 16_FF000000

%end %of %file
