home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pcrte224.zip / SRC.DOC < prev    next >
Text File  |  1992-06-09  |  17KB  |  348 lines

  1.  
  2.                         PCroute source code description
  3.                                 Vance Morrison
  4.  
  5.  
  6.     PCroute is distributed with source for essentially one reason, I would 
  7. like to involve many people in the design and debugging of PCroute, and for 
  8. them to do this, they need the source.   Since I will not be the only one
  9. fixing bugs and adding enhancements, PCroute will continue to develop as long
  10. as there are people who think it is a worthwhile program to support.  As
  11. creator of PCroute, however I request/demand the following
  12.  
  13.  
  14.         1) Please let me know about any bug fixes so that I can incorporate
  15.            them into the 'official' release.
  16.  
  17.         2) You may make local enhancements to PCroute and use them LOCALLY
  18.            (that is within the same organization) but you may NOT distribute
  19.            this code.  
  20.  
  21.     The reason for the second demand (it is in the copywrite) is very simple,
  22. I don't want PCroute to fragment into many versions.   That is my ONLY 
  23. concern.  Thus just tell me what you want to do, and I will give you
  24. an copy of the working source code, and you can be sure that the part that
  25. you are working on is not being worked on by anyone else, and when you are
  26. done it will be ready to integrate into the official release.   I do
  27. reserve the right NOT to integrate features that I regard as counterproductive
  28. and code that simply is too poorly written or buggy to risk, but I do not
  29. see myself exercising that option.  
  30.  
  31.     All of these conditions are simply to insure that PCroute has a long
  32. and productive life.   I have no monetary interest in PCroute.  
  33.  
  34.     I could like to thank David Johnson for his contribution of the 
  35. first generation SLIP code to PCroute.  Great work!  Thanks for the excellent 
  36. contribution.
  37.  
  38. ============================================================================
  39. DESIGN CRITERIA
  40.  
  41.     PCroute had to be designed to squeeze all the power it could out
  42. of an 8088 CPU.  As such I had to make some rather drastic measures.
  43. These include
  44.  
  45.         1) Programming the main packet routing loop in assembler
  46.         2) NO procedure call in the main packet routing loop
  47.  
  48.     Since assembler have very good macro expansion capabilities, the
  49. second decision is relatively painless.  Simply use macros instead
  50. of procedure calls.   This can make the code large, but memory has
  51. not been a problem yet.  
  52.  
  53.     Once we are out of the main packet loop, these optimizations are
  54. not really necessary anymore.  Thus if/when SNMP support is added
  55. to PCroute, it will be done in C, since all of this code is only 
  56. executed when SNMP operations are being done.
  57.  
  58. ===========================================================================
  59.  
  60. CONVENTIONS
  61.  
  62.     Despite the use use of assembler, I have tried to make the code 
  63. as modular as possible, and to adopt conventions that I have found quite
  64. useful in preventing common assembly code errors.   Some of these 
  65. conventions are
  66.  
  67.     1) function prefixing - Macros are groups into modules that provide
  68.           a set of related services.  All function in this group are 
  69.           prefixed by the same short string.  This improves readability
  70.           and prevents name conflicts
  71.  
  72.     2) Naming input, output and constant registers - The most common
  73.           error in assembly code is calling a macro that changes registers
  74.           that you believed where held constant.  To prevent this type
  75.           of error Macro names have the following form
  76.  
  77.                 <NAME>_in_<REG LIST>_out_<REG_LIST>_const_<REG_LIST>
  78.  
  79.           For example
  80.  
  81.               WD_IF_COPY_in_CX_SI_DI_ES_out_SI_DI_const_BX_BP_ES name
  82.  
  83.           It is quite clear from the name that this macro has its parameters
  84.           passed in CX,SI,DI,ES, it returns values in SI,DI and it holds
  85.           the registers BX,BP,ES constant.  While this may seem long-winded
  86.           (it is) it is VERY useful and has prevented many bugs and I
  87.           will DEMAND that any new assembly code follow these conventions.
  88.  
  89.           Note that since the CS,DS,SS registers are NEVER changed, you
  90.           may assume that EVERY macro preserves these registers. 
  91.  
  92.     3) file naming - There are two type of files in the source code at
  93.          present, INC files and ASM files.  INC files contain ONLY macro
  94.          definitions and admit NO code and are meant to be included in
  95.          ASM files.  INC file are thus the 'meat' of the code.  The ASM
  96.          files contain NO macro definitions, but do instantiate the macros
  97.          to generate the actual code.  Originally (an ideally), there was
  98.          only one ASM file (namely PCROUTE.ASM) and assembling this file
  99.          generated all code.  As PCroute grew, however, the assembler could
  100.          no longer compile it all in one piece, so I had to break the
  101.          program into into many parts that are assembled separately and
  102.          then linked together.  All of these ASM file are generally quite
  103.          boring because all they do is instantiate a few macros.  The
  104.          INC files is where the action is.
  105.  
  106. ===========================================================================
  107.  
  108. Overall structure
  109.  
  110.     The OSI model served as the basic 'backbone' of the PCroute structure,
  111. however, there were some problems with the model, and I had to make a few
  112. changes.  The basic layering is
  113.  
  114.  
  115.         1) IF.INC       (the interface (ethernet card) interface)
  116.         2) DL_IP.INC    (the data link interface for IP)
  117.         3) IP.INC       (the IP interface)
  118.         4) UDP.INC      (the User datagram protocol (UDP) interface)
  119.  
  120.     Notice this is ROUGHLY analogous to the first 4 layers of the OSI stack,
  121. but the major difference is the realization that a interface is a separator
  122. BETWEEN two layers and as such must explicitly KNOW what is on at least
  123. one of the sides.  For example there cannot be a generic interface for the DL 
  124. (data link) layer that will interface ANY data link level code with ANY network
  125. level code.  The interface must know about one layer or the other.  In this
  126. case the interface KNOWS that the network layer is IP (hence DL_IP), and 
  127. as long as the Data link layer below this conforms to this DL_IP interface
  128. IP can use it.  
  129.  
  130.     In the case of IF interface, the interface KNOWS that the code above it
  131. will treat it like an ethernet.  Conversely, the only thing the upper layer
  132. sees is the IF interface, thus any ethernet board board can be used as long 
  133. as there is code that conforms to the IF interface for it.  
  134.  
  135.     DL_IP.INC and IF.INC are also examples of an abstract interface.  These
  136. modules to no real useful work themselves.   Instead, they act as dispatchers,
  137. calling the proper code that will do the actual work.  The advantage doing
  138. this is that it allows multiple interface types (in the case of DL_IP) or
  139. multiple ethernet cards (in the case of IF) without having to change any
  140. code.
  141.  
  142.     In the case of Ethernet, there is an additional layer between the IF
  143. and DL_IP layer.  This layer (ETHER.INC) encapsulates the (old) Ethernet
  144. style of addressing (as opposed to 802.3).  This layer was added to add
  145. easy addition of the 802.3 type addressing and to support other networking
  146. protocols (Decnet, XNS) if desired (conceivably all on the same cable!).  
  147.  
  148.    The complete layering for ethernet is
  149.  
  150.         WD8003E.INC     IF interface specific to the WD8003E card
  151.  
  152.         WD8003.INC      A more generic IF interface that will work with
  153.                         WD8003E (ethernet) as well as WD8003S (starlan),
  154.                         the major difference is that this module has 
  155.                         output queuing which is needed for starlan but
  156.                         not for ethernet.  It is not recommended for ethernet
  157.                         since it will be slower than the WD8003E code.
  158.  
  159.         WD.INC          Constant declarations needed by the above two
  160.                         modules to manipulate the WD8003 card.
  161.  
  162.         IF.INC          Supplies a standard interface for all card specific
  163.                         code and dispatches the proper code when generic
  164.                         routines are called.
  165.  
  166.         ETHER.INC       Describes the Ethernet header and packet dispatching 
  167.                         on packet type. 
  168.         
  169.         ARP.INC         Provides a DL_IP interface for ethernet by using the
  170.                         standard Address Resolution Protocol (ARP)
  171.  
  172.         DL_IP.INC       Supplies a standard interface for data link specific
  173.                         code and dispatches the proper code when generic
  174.                         routines are called.
  175.  
  176.         IP.INC          Provides the routing service between the data link
  177.                         layers and a higher level interface for those packets
  178.                         directed to and from this program.  It also supports
  179.                         fragmentation if necessary.  This is the heart of the
  180.                         program.
  181.  
  182.         ICMP.INC        Uses the IP services to provide the ICMP control
  183.                         datagrams need to fully support the IP protocol.
  184.  
  185.         UDP.INC         Uses the IP services to provide the User datagram
  186.                         protocol needed for routing (RIP) and logging (syslogd).
  187.  
  188. ==========================================================================
  189.  
  190.     For the packet driver support, only one module is needed.  This module
  191. conforms to the IF interface.  The file associated with this module is
  192.  
  193.         PACKET.INC      An IF interface that then talks to the packet 
  194.                         driver software though a software interrupt.
  195.  
  196. ==========================================================================
  197.  
  198.     For the localtalk support, only one module is needed.  This module
  199. conforms to the DL_IP interface.  There are two files associated with this
  200. module.
  201.  
  202.         ATALK.INC       A DL_IP interface that then talks to the localtalk
  203.                         driver to encapsulate the IP packets in localtalk.
  204.  
  205.         AT.INC          A list of constant declarations needed to use the
  206.                         localtalk driver supplied with PC localtalk boards
  207.  
  208. ==========================================================================
  209.  
  210.     For SLIP support, four modules are needed.   They are
  211.  
  212.         I8250.INC       Does all the stuff needed to get a single character
  213.                         on and off the PC.  Interrupt code, and hardware 
  214.                         specific code is all in here.
  215.  
  216.         SLIP.INC        Defines the code that provides data transparency
  217.                         and packetizing.  This is the code that places
  218.                         packets into a read queue.
  219.  
  220.         QIF.INC         Implements the 'other side' of the read queue
  221.                         that SLIP.INC is filling.   It looks like an
  222.                         IF interface to calling code.
  223.  
  224.  
  225.         PP.INC          Implements a DL_IP interface for point to point
  226.                         links give an point to point IF link (like the
  227.                         one QIF provides).
  228.     
  229. ==========================================================================
  230.  
  231. Additional functionality
  232.  
  233.     In addition to the basic networking layers, there are a variety of
  234. support functions that are needed to have a complete, functioning router.
  235. These include
  236.  
  237.         RIP.INC         Provides a routing interface and implements the
  238.                         RIP protocol.  This module has complete control
  239.                         over the routing table and IP calls though this
  240.                         interface to determine how to route a packet 
  241.                         (thus another routing protocol could replace RIP
  242.                         by changing ONLY this module)
  243.  
  244.  
  245.         BOOTP.INC       Implements bootp forwarding by listening on the
  246.                         appropriate UDP port.
  247.  
  248.         LOG.INC         Implements logging functions and the syslogd code
  249.                         needed to get these messages to the logging host.
  250.                         These routines violate convention in that they
  251.                         preserve ALL registers but do not have a CONST
  252.                         part in their name (for the practical reason that
  253.                         it simply would not fit on a line anymore)
  254.  
  255.         DLOG.INC        Very similar to LOG, but the messages go to the
  256.                         disk instead of the syslogd host.  These routines
  257.                         and only be used at boot up since disk access is slow.
  258.                         These routines violate convention in that they
  259.                         preserve ALL registers but do not have a CONST
  260.                         part in their name.
  261.  
  262.         CONFIG.INC      This module is responsible for configuring all of
  263.                         other modules that need configuration time data.
  264.                         I am unhappy with this module, since it has to
  265.                         be change whenever ANY module needs different config
  266.                         info.  I think instead of its present structure it
  267.                         should simply provide a standard interface for getting
  268.                         configuration data and let each module manage its
  269.                         configuration data itself.
  270.  
  271.         DECLARE.INC     Contains actually hardware configuration of the router.
  272.                         It is this file that is changed (and ONLY this file)
  273.                         when new hardware is added to the router.
  274.  
  275. ===========================================================================
  276.  
  277. Support routines
  278.  
  279.     In addition to the major functional blocks, there are some modules that
  280. provide rather generic services that are used by the other functional blocks.
  281. These modules include
  282.  
  283.         DEBUG.INC       Provides simple routines that print to screen routines.
  284.                         They should not be in production code (use log routines)
  285.                         These routines violate convention in that they
  286.                         preserve ALL registers but do not have a CONST
  287.                         part in their name.
  288.  
  289.         ARPTAB.INC      Provides a simple table 'object' that is used to
  290.                         hold hardware-ip address translation data, used in
  291.                         ARP.INC and ATALK.INC.
  292.  
  293.         BUFFER.INC      Provides simple buffer allocation routines used in
  294.                         output (and possibly input) queuing.  Used in
  295.                         ATALK.INC and WD8003.INC
  296.  
  297.         QUEUE.INC       Provides simple queuing routines used for packet
  298.                         queues.  Used in ATALK.INC and WD8003.INC
  299.  
  300.         
  301.         TASKS.INC       Provides SIMPLE time slicing routines (they aren't
  302.                         even coroutines, but they are sufficient).
  303.  
  304.         
  305.         TIMER.INC       Provides the ability to schedule a routine to be
  306.                         executed some time in the future.  Used in RIP.INC
  307.                         and other places.
  308.  
  309. ==========================================================================
  310.  
  311. Experimental Routines
  312.  
  313.  
  314.         BRIDGE.INC      This takes several WDE interfaces and returns
  315.                         several IF interfaces, but it also provides ethernet
  316.                         bridging between the interfaces.  Incorporated into
  317.                         the rest of the code it implements a b-router.  
  318.                         Used by itself (in BRIDGE.ASM) it implements just
  319.                         a bridge.
  320.  
  321. ==============================================================================
  322.  
  323. ASM files
  324.  
  325. The ASM file frankly are not too interesting, nevertheless, for completeness
  326. their description follows.  The only reason for most of these (with the
  327. exceptions of bridge.asm and pcroute.asm) is simply to get around the macro 
  328. size limitation in TURBO ASSEMBLER.
  329.  
  330.         ATALK.ASM       appletalk code declarations 
  331.         DLOG.ASM        disk logging code declarations
  332.         LOG.ASM         syslog logging code declarations
  333.         ETHER.ASM       ethernet code declarations
  334.         IP.ASM          ip code declarations
  335.         IP_DL#.ASM      ip code associated with interface #
  336.         RIP.ASM         rip routing code declarations
  337.         SLIP.ASM        SLIP code declarations 
  338.         WD8003.ASM      wd8003 card code declarations
  339.         WD8003E.ASM     wd8003e card code declarations
  340.         I8250.ASM       Serial line code declarations
  341.         PP.ASM          declarations for the point-to-point DL_IP code
  342.         PACKET.ASM      packet driver code declarations
  343.         PCROUTE.ASM     the main program!!!!
  344.         BRIDGE.ASM      an independent program implementing a two interface
  345.                         ethernet bridge. (Three or more interface are possible,
  346.                         but you will want a fast machine for this use)
  347.  
  348.