<?xml version='1.0'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBk XML V4.1.2//EN"
               "/usr/share/sgml/docbook/dtd/xml/4.1.2/docbookx.dtd"
>
<book>
<chapter>
    <title>RTLinux UDP/IP (<emphasis
            role="bold">RTLUDP</emphasis>)</title> <!--
    ================================ Summary ============== -->
    <section>
      <title>Summary</title>

      <variablelist>
        <varlistentry>
          <term>Name</term>
          <listitem>
            <para>RTLinux UDP/IP
            </para>

          </listitem>
        </varlistentry>

        <varlistentry>
          <term>Description</term>
          <listitem>
            <para>
	      Hard real-time IP/DUP stack implementation.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Author/s</term>
          <listitem>
            <para>
	      Miguel Masmano
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>Reviewer</term>
          <listitem>
            <para>
	      Ismael Ripoll
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Layer</term>
          <listitem>
            <para>
              High level RTLinux.
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>Version</term>
          <listitem>
            <para>
              0.1
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Status</term>
          <listitem>
            <para>
	      Testing
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Dependencies</term>
          <listitem>
            <para>
	      None.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Release Date</term>
          <listitem>
            <para>
              M3
            </para>
          </listitem>
        </varlistentry>
      </variablelist>

    </section>

    <section>
      <title>Description</title>
      <para>
	Currently, standard RTLinux/GPL has two different IP stacks:
	RTSOCK and LwIP (LwIP was ported to RTLinux by a college from
        the UPVLC, in a project sopported by the national
	reseach department, MCYT).
      </para>
      <para>
	Rtsock is not a device driver for network cards. Instead,
	packets flow through the Linux kernel using the standard Linux
	drivers, up/down the standard layer 2 and layer 3 protocols,
	and then packets are diverted into an RTLinux task. Currently
	only UDP sockets are supported.
      </para>

      <para>
	LwIP is a complete and full featured TCP/IP stack designed to
	be ported to embedded systems easily. The current version of
	RTLinux provides support of a small number of network card
	drivers.
      </para>


      <para>
	This component is an <emphasis role="bold">implementation of
	the UDP/IP stack from scratch</emphasis> (not derived from BSD
	code as many other TCP/UDP/IP implementations). The main
	design criteria is efficiency, while features and
	compatibility are secondary. The stack will be prepared
	(interfaced) to work with the network device drivers developed
	in the project <emphasis role="bold">EtherBoot</emphasis>,
	which has a large base of supported drivers; and also be
	connected with the Linux networking stack (via a virtual
	network driver), providing a high level communication
	mechanism between RTLinux and Linux on the same machine.
      </para>

      <para>
	Next figure outlines the internal structure of the proposed
	component: the core of the component is the UDP/IP stack,
	which provides the socket interface to RTLinux threads; the
	component will implement the required API to use all the
	<emphasis role="bold">EtherBoot</emphasis> project network
	device drivers; and finally, a standard Linux network driver
	will be provided so that Linux user application can
	communicate via UDP/IP with RTLinux threads.
      </para>
      
      <figure>
	<title>RTLUDP component</title>
	<mediaobject>
	  <imageobject>
	    <imagedata align="center" scale="40"
	    fileref="img/rtludp.png"/>
	  </imageobject>
	</mediaobject>
      </figure>

    </section>
    <!--
    <section>
    <title>Author</title>
    <para>
    Miguel Masmano Tello
  </para>
  </section>
    -->
    <section>
      <title>Layer</title>
      <para>
	This is a Low Level RTLinux component. It also interacts with the Linux Kernel by means of
	a virtual network Linux driver since it allows to send ARP/IP
	packets via the kernel TCP/IP stack.
      </para>
    </section>
    
    <section>
      <title>API / Compatibility</title>
      <para>
	Standard BSD socket API: <function>send()</function> and
	<function>sendto()</function> for sending messages;
	<function>recv()</function> and
	<function>receivefrom()</function> to receive messages; and
	<function>connect()</function> to establish the connection.
      </para>
      <para>
	The Stack will be compatible with all the <emphasis
	role="bold">EtherBoot</emphasis> network drivers.
      </para>
    </section>
    
    <section>
      <title>Dependencies</title>
      <para>
	RTLUDP do not have dependencies with any external components.
      </para>
    </section>
    
    <section>
      <title>Status</title>
      <para>
	Alpha status
      </para>
    </section>
    
    <section>
      <title>Implementation issues</title>

      
      <!--
      <para>
      RTLUDP can be splitted in two halves: the first one, a Real Time
      UDP/IP stack to be used by the RTLinux applications, providing a
      Unix-like programming interface; and the second one, the drivers
      layer, this layer proporcionates a virtual Linux Kernel driver
      which allows to use the Linux Kernel TCP/IP stack in order to
      stablish non Real Time communications and it also provides a
      software layer which allows to use all the Etherboot Project
      drivers, an real time ethernet protocol will be implemented over
      this layer in order to override some non real time behaviour.
    </para>
      --> <!--
      <para>
      RTLUDP has been implemented in order to give real time
      comunications (using UDP/IP) with a cheap physical medium
      (Ethernet). Due to the CSMA/CD protocol used by Ethernet, it has
      not a real time behaviour.  Overrinding CSMA/CD by means of a
      new software protocol, a real time behavior can be achieved.  We
      have implemented one of this software protocolos, in concrete
      the proposed one by " A Multipoint Communication Protocol based
      on Ethermet for Analyzable Distributed Real-Time Applications",
      Jose Maria Martinez, Michael Gonzalez and Javier Gutierrez,
      Internal Report.  This protocol consists of the use of a token,
      It is a similar protocol to the Token Bus LAN.  RTLUDP can also
      be used to establish a non real time comunication by means of
      the Linux TCP/IP stack. In order to use Linux TCP/IP a optional
      virtual driver will be implemented.  RTLUDP also will
      incorporate a software layer which will make compatible all the
      Etherboot project drivers, allowing us to use them.  </para>
      (Ethernet Adder) -->
      <para>
	RTLUDP implements a light UDP stack with the following
	functionality: </para>
      <itemizedlist>
	<listitem>
	  <para>
	    ARP protocol: Complete.
	  </para>
	  <para>
	    The RTLUDP component implements the ARP protocol as is
	    described in the RFC 826, titled "Ethernet Address
	    Resolution Protocol".
	  </para>
	  <para>
	    Besides the ARP protocol, RTLUDP implements a little
	    software cache for storing Ethernet address and its IP
	    address translation.  All IP address are translated using
	    this cache table. If an IP address is not located in the
	    table, RTLUDP sends an ARP request only when the
	    appropiate translation is not in the table.
	  </para>
	  <para>
	    Since the ARP protocol is not an inherence real-time
	    protocol,  RTLUDP provides two non-standard functions:
	    <function>insert_arp_translation()</function> and
	    <function>flush_arp_table()</function>. The first one
	    allows user to insert into the arp cache table
	    translations during the initialisation time and the
	    last one allows to empty the whole arp cache table.
	  </para>
	  <para>
	  The use of the ARP protocol can be avoided if the physical
	  medium used is a point-to-point medium.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    IP protocol: Complete. But packet split and recombine are
	    not supported.
	  </para>
	<para>
	  Even using a deterministic physical medium, some IP
	  protocol features, like the packet split,
	  do not allow any kind of deterministic response
	  time. Therefore in this implementation these non-deterministic
	  features have been avoided.  This IP protocol does not
	  implement routing.
	</para>
	</listitem>
	<listitem>
	  <para>
	    UDP protocol: Complete.
	  </para>
	  <para>
	    Avoiding the ARP protocol, since it can be statically
	    initialised and supposing the previous described IP
	    protocol, this UDP protocol can be considered a real-time
	    protocol.  RTLUDP only has made one simplification of this
	    protocol: it does not calculate the UDP header
	  checksum. However this is not an important simplification because it is
	    covered by the RFC 768.
	  </para>
	  <para>
	    The sockets abstraction has not any kind of
	    simplification, allowing user to use any socket from 0 to
	    65535. RTLUDP does not reserve any port, from 0 to 1024,
	    as conventionally done.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    ICMP protocol: Only some parts have been implemented like
	    ECHO, DESTINATION UNREACHABLE, etc. Packages related with
	    host or router information and management will not be
	    implemented.
	  </para>
	  <para>
	    This protocol has been implemented for debbuging porpouses
	    so more error messages are not interesting.
	  </para>
	  <para>
	    An extensive list of implemented error messages are:
	  </para>
	  <itemizedlist>
	    <listitem>
	      <para>
		ICMP_ECHO_REQUEST: This is a very useful message
		because it can be used for checking the sending and
		also the reception of IP messages, since it guarantees
		the reception of other hosts ECHO_REPLY messages.
	      </para>
	    </listitem>
	    <listitem>
	      <para>
		ICMP_ECHO_REPLY: This message is used to response
		requests from other hosts.  It has no sense to
		implement previous ECHO_REQUEST message without 
		implementing this one.
	      </para>
	    </listitem>
	    <listitem>
	      <para>
		DESTINATION_UNREACHABLE: This message allows to
		indicate that a package can not arrive to the
		specified destination.
	      </para>
	    </listitem>
	  </itemizedlist>
	</listitem>
	<listitem>
	  <para>
	    TCP protocol: TCP protocol has not been implemeted since
	    it is not a real-time protocol.
	  </para>
	</listitem>
      </itemizedlist>
      <para>
	The RTLUDP componen has been designed in two
	well-differenciated layer: the light UDP stack layer,
	previously described, and the hardware layer, which implements
	the drivers.  RTLUDP supplies an interface layer, called
	hardware abstraction layer (HAL), for allowing the interaction
	between the UDP stack and drivers.
      </para>
      <para>
	HAL has been designed keeping in mind two important details:

	<!--   HAL ha sido diseñada teniendo en cuenta dos
	importantes consideraciones -->

	<itemizedlist>
	  <listitem>
	    <para>It has to be as simple as possible, because making
	      drivers must be an easy work. </para>
	  </listitem>
	  <listitem>
	    <para>
	      It must be compatible with the existing <emphasis
		role="bold">EtherBoot</emphasis> HAL, to allow to port easily
	      existing <emphasis role="bold">EtherBoot</emphasis> drivers.</para>
	  </listitem>
	</itemizedlist>
      </para>
      <para>
	This HAL has been designed to be simple and also <emphasis
	role="bold">EtherBoot</emphasis> drivers compatible, thus with
	<emphasis role="bold">EtherBoot</emphasis> drivers can be used
	directly by the RTLUDP component.
      </para>
      <para> Any implemented driver must satisfay the next interface:
      </para>
      <itemizedlist>
	<listitem>
	  <para>
	    <function>poll()</function>: This function has to return
	    "1" when a new package has arrived and "0" otherwhise.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <function>reset()</function>: This function will be used
	    by the stack to reset the physical device.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <function>transmit()</function>: This function will be
	    always called whenever some protocol wants to send a package.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <function>disable()</function>: This function will be
	    used by the stack to disable the physical device.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <function>node_addr</function>: This is an optional
	    variable which is used on the case that the physical
	    device had an MAC address like for example the Ethernet
	    protocol.  On the case there exist a MAC address, it has
	    to be initialised by the driver itself.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <function>packet</function>: When the
	    <function>poll()</function> function returns "1" means
	    that a new packet has arrived so <function>packet</function> will contain the
	    new packet.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <function>packet_len</function>: When the <function>poll
	    ()</function> function returns "1" means that a new packet
	    has arrived so the packet variable will contain the new
	    packet length.
	  </para>
	</listitem>
      </itemizedlist>
      <para>
	Another important feature of the RTLUDP component is that it
	accepts dynamic insertion and extraction of the drivers,
	showing available drivers in the <filename>/proc/rtl_udp</filename> file.
      </para>
      <para>
	Implementing drivers is a tedious task, so one solution is to
	use other project drivers, <emphasis
	role="bold">EtherBoot</emphasis> drivers have been choosen
	because it has drivers for almost all existing Ethernet cards.
	Due to the HAL interface is very similar to the <emphasis
	role="bold">EtherBoot</emphasis> drivers, in fact, it is the
	same.  <emphasis role="bold">EtherBoot</emphasis> drivers can
	be used with only replacing its time functions with RTLinux
	time functions. This replacing is done because existing
	<emphasis role="bold">EtherBoot</emphasis> time functions use
	directly the hardware PIT, reprogramming it.
      </para>
      <para>
	Besides the <emphasis role="bold">EtherBoot</emphasis> network
	driver, a new virtual Linux network driver has been
	implemented.  This new driver allows direct network
	communication between the RTLUDP stack and the Linux Kernel
	TCP/IP stack, and it also allows to send packages through the
	Linux Kernel stack.
      </para>
      <para>
	Although the first version of RTLUDP stack has been
	implemented using a one copy method, we will study the way to
	provide a real zero copy network on following versions (may be
	using the STREAMS interface).
      </para>
    </section>
    
    <section>
      <title>Validation criteria</title>
      <para>
	The validation criteria are:
	<itemizedlist>
	  <listitem>
	    <para>
	      A Real Time behaviour, when the real-time protocol is
	      used, must be achieved, being this point the main goal of
	      the RTLUDP.
	    </para>
	  </listitem>
	  <listitem>
	    <para>
	      RTLUDP stack must be completely compatible with existing
	      UDP/IP protocol.
	    </para>
	  </listitem>
	</itemizedlist>
      </para>
    </section>
    
    <section>
      <title>Tests</title>
      <para>
	As is described in the Validation criteria, there are two
	important features to check in this component: the
	deterministic behaviour and the compatibility with existing
	protocols. There is no problem in testing the second
	feature, however, currently the real-time behaviour can not
	be tested because we have not any real-time physical device to
	use.

	Following four tests check ARP and ICMP compatibility:
      </para>
      <itemizedlist>
	<listitem>
	  <para>
	    Test 1: The first test is a simple test with the ping
	    utility.  Using the virtual Linux kernel network driver,
	    the ping utility sends several ICMP ECHO_REQUEST packets,
	    and the RTLUDP component answers with the appropiate ICMP
	    ECHO_REPLY package.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    Test 2: This test is similar to the previous one but this
	    time the ICMP ECHO_REQUEST package is sent by the RTLUDP
	    component.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    Test 3: This test checks as well as the ARP and ICMP
	    protocol, it checks <emphasis
	    role="bold">EtherBoot</emphasis> drivers.  Using a
	    different computer connected through ETHERNET without
	    computer, it consists of sending several ICMP ECHO_REQUEST
	    using the ping utility and waiting a correct answer.
	  </para>
	</listitem>
	<listitem>
	  <para>
	    Test 4: This test is the same that the test 3 but this
	    time the ICMP ECHO_REQUEST package is sent by the RTLUDP
	    component.
	  </para>
	</listitem>
      </itemizedlist>
      <para>
	<emphasis role="bold">EtherBoot</emphasis> Drivers has the
	same well-behavior as the Virtual Linux Kernel network driver
	so for following will be executed using first <emphasis
	role="bold">EtherBoot</emphasis> drivers and later the Virtual
	one.

	The following tests check the ARP and IP/UDP compatibility,
	(Only UDP compatibility can be tested since in the current
	version raw IP packages have not been implemented):
      </para>
      <para>
	<itemizedlist>
	  <listitem>
	    <para>
	      Test 5: UDP sending and receiving compatibility.  This
	      test has been designed to prove UDP sending
	      compatibilities with a standard TCP/IP stack. The test
	      sends several packages, from several ports, to one open
	      Linux port, and waits confirmation.
	    </para>
	  </listitem>
	  <listitem>
	    <para>
	      Test 6: Previous tests have check if the implemented UDP
	      sends and receives correctly packages with open ports,
	      tests 6 checks the same but with close ports. This test
	      checks what it happens when nobody waits a package. A
	      Linux application sends several packages to RTLUDP
	      closed ports and waits a response.
	    </para>
	  </listitem>
	  <listitem>
	    <para>
	      Test 7: Stress test.  In this test, several external
	      applications send packages through different physical
	      mediums to the RTLUDP, trying to get a stack overload,
	       measuring the number of lost packages, times, and so
	      on.
	    </para>
	  </listitem>
	</itemizedlist>
      </para>
    </section>
</chapter>
</book>

