Econet over IP

From BeebWiki
Jump to: navigation, search

Econet Packet

Econet packets can be ecapsulated in UDP (User Datagram Protocol) packets to be transmitted in IP (Internet protocol) packets to be transmitted over a network with IP protocol, such as Ethernet, as done by Acorn Universal Networking.

An Econet packet looks like this:

 +------+------+-----+-----+---------+------+-----------------------------+
 | Dest | Dest | Src | Src | Control | Port |         Data                |
 | Stn  | Net  | Stn | Net |  Byte   |      |                             |
 +------+------+-----+-----+---------+------+-----------------------------+
  <-------- - - Packet Header - - ---------> <--- - - Packet Data - - --->

The Econet system sends a packet in four frames using a four-way handshake which the 6854 ADLC puts on the wire as follows:

 Send:    Scout frame with packet header
 Receive: Scout fcknowledge frame
 Send:    Data frame with packet data
 Receive: Data acknowledge frame

See Econet packet.

An Econet packet is sent over IP with a two-way handshake, sending a UDP data packet and waiting for an acknowledge or a negative-acknowledge UDP packet.

UDP packet

The UDP data contains an eight-byte UDP header containing information from the Econet packet header, followed by the variable-length UDP data which contains eight bytes containing more information from the Econet packet header followed by the Econet packet data:

   +-----------------------+
   |UDP Header:            |
   |  Source Port          | 16-bit port
   |  Dest Port            | &8000 for Econet-Over-IP
   |  Length of UDP Data   | 16-bit UDP data packet length
   |  Checksum             | 16-bit UDC checksum
   +-----------------------+
   |UDP Data:              |
   |  Transaction Type     | &01 = Broadcast &02=Data packet, &03=ACK, &04=NAK,
   |                       | &05=Immediate, &06 Imm.Reply
   |  Econet Port          | From Econet packet header
   |  Econet Control Byte  | From Econet packet header with bit 7 cleared
   |  Padding &00          |     The Control Byte gets bit 7 set in the receive block
   |  Sequence Number      | This 32-bit number increments by 4 on each transaction
   |                       |  Acks and Naks quote back the sequence they relate to
   | --------------------- |
   |        Econet         |
   |        Packet         |
   |         Data          |
   +-----------------------+

IP Packet

The UDP packet is encapsulated in an IP packet as follows:

   IP packet:
   +-------------------+
   | IP Header:        |
   |  Version          |
   |  Header Length    |
   |  Type             |
   |  Total Length     |
   |  ID               |
   |  Fragment         |
   |  Protocol         |
   |  Header CRC       |
   |  Source Address   | - site.network.net.stn
   |  Dest Address     | - site.network.net.stn
   |  Options          |
   | ----------------- |
   | IP Data:          |
   |  UDP packet       |
   | +---------------+ |
   | | UDP Header:   | |
   | |  Source Port  | |
   | |  Dest Port    | | - &8000 for Econet-Over-IP
   | |  Length       | |
   | |  Checksum     | |
   | | ------------- | |
   | | UDP Data:     | |
   | | +-----------+ | |
   | | | Tr.Type   | | | &01=Broadcast, &02=Data packet, &03=ACK, &04=NAK,
   | | |           | | | &05=Immediate, &06=Imm.reply
   | | | Eco Port  | | | From Econet packet header
   | | | Eco Ctrl  | | | From Econet packet header
   | | | Padding   | | |
   | | | Sequence  | | |
   | | | --------- | | |
   | | |  Econet   | | |
   | | |  Packet   | | |
   | | |   Data    | | |
   | | +-----------+ | |
   | +---------------+ |
   +-------------------+

Broadcasts

Broadcasts just send a data block and do not wait for any acknowledgement.

Immediate Operations

The only immediate operation implemented in Acorn Universal Networking Econet over IP is MachinePeek to determine if a remote machine is present. However, immediate operations do fit into the protocol.

Coding

The Net_Tx() function in the Net library would essentially do something like the following:

 DEFFNNet_Tx(Stn%,Ctrl%,Port%,Addr%,Len%,RAddr%):try=10:delay=50
 
 REPEAT
                            /* Prepare to send */
   sock=socket(AF_INET, SOCK_DGRAM, 0);
 
   name.sin_family=AF_INET;  /* Internet socket */
   name.sin_port=&8000;      /* Port for Econet-Over-Ethernet */
   name.sin_addr.s_addr=Stn% /* Destination */
 
   header[0]=&02             /* Econet header */
   header[1]=Port%
   header[2]=Ctrl%
   header[3]=0
   header[4..7]=RAddr%
 
   iov[0].base=&header       /* Point to header to send */
   iov[0].len=8              /* Eight bytes in header   */
   iov[1].base=Addr%         /* Point to data to send   */
   iov[1].len=Len%           /* Specified bytes of data */
 
   socketwritev(sock, &iov, 1);
   socketclose(sock);
 
                            /* Now listen for an acknowledgement */
   sock=socket(AF_INET, SOCK_DGRAM, 0);
 
   name.sin_family=AF_INET;  /* Internet socket */
   name.sin_port=&8000       /* Port for Econet-Over-Ethernet */
   name.sin_addr.s_addr=Stn% /* Who we're expecting an Ack from */
   bind(sock, &name, sizeof(name));
 
   socketread(sock, buf, buflen)
   socketclose(sock)
 
   IF buf[0]<>3 THEN try=try-1:IF try>0 THEN PROCdelay(delaytime)
 UNTIL buf[0]=3 OR try<1
 IF buf[0]=3 THEN =0  :REM Ok
 IF buf[0]=4 THEN =&42:REM Not listening
 =&40:REM Network error

IP over Econet

An IP packet can be encapsulated in an Econet packet as follows:

 +------+------+-----+-----+------+------+---------------+
 | Dest | Dest | Src | Src | Ctrl | Port | +-----------+ |
 | Stn  | Net  | Stn | Net | Byte | &D2  | | IP Packet | |
 |      |      |     |     |      |      | +-----------+ |
 +------+------+-----+-----+------+------+---------------+

The Control byte determines the type of IP packet:

 &81 IP
 &A1 ARP_REQUEST
 &A2 ARP_REPLY
 &8F IPBCAST_REQUEST
 &8E IPBCAST_REPLY

Jgharston 22:21, 14 May 2009 (UTC) Jgharston (talk) 16:56, 9 December 2023 (CET)