home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / rfc / rfc2123 < prev    next >
Text File  |  1997-03-28  |  82KB  |  1,908 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                       N. Brownlee
  8. Request for Comments: 2123                   The University of Auckland
  9. Category: Informational                                      March 1997
  10.  
  11.  
  12.           Traffic Flow Measurement:  Experiences with NeTraMet
  13.  
  14. Status of this Memo
  15.  
  16.    This memo provides information for the Internet community.  This memo
  17.    does not specify an Internet standard of any kind.  Distribution of
  18.    this memo is unlimited.
  19.  
  20. Abstract
  21.  
  22.    This memo records experiences in implementing and using the Traffic
  23.    Flow Measurement Architecture and Meter MIB. It discusses the
  24.    implementation of NeTraMet (a traffic meter) and NeMaC (a combined
  25.    manager and meter reader), considers the writing of meter rule sets
  26.    and gives some guidance on setting up a traffic flow measurement
  27.    system using NeTraMet.
  28.  
  29. Table of Contents
  30.  
  31.  1 Introduction                                                        2
  32.    1.1 NeTraMet structure and development . . . . . . . . . . . . . .  3
  33.    1.2 Scope of this document . . . . . . . . . . . . . . . . . . . .  4
  34.  2 Implementation                                                      4
  35.    2.1 Choice of meter platform . . . . . . . . . . . . . . . . . . .  4
  36.    2.2 Programming support requirements . . . . . . . . . . . . . . .  5
  37.      2.2.1 DOS environment  . . . . . . . . . . . . . . . . . . . . .  6
  38.      2.2.2 Unix environment . . . . . . . . . . . . . . . . . . . . .  7
  39.    2.3 Implementing the meter . . . . . . . . . . . . . . . . . . . .  7
  40.      2.3.1 Data structures  . . . . . . . . . . . . . . . . . . . . .  7
  41.      2.3.2 Packet matching  . . . . . . . . . . . . . . . . . . . . .  8
  42.      2.3.3 Testing groups of rule addresses . . . . . . . . . . . . .  8
  43.      2.3.4 Compression of address masks . . . . . . . . . . . . . . .  9
  44.      2.3.5 Ignoring unwanted flow data  . . . . . . . . . . . . . . . 10
  45.      2.3.6 Observing meter reader activity  . . . . . . . . . . . . . 11
  46.      2.3.7 Meter memory management  . . . . . . . . . . . . . . . . . 12
  47.    2.4 Data collection  . . . . . . . . . . . . . . . . . . . . . . . 14
  48.    2.5 Restarting a meter . . . . . . . . . . . . . . . . . . . . . . 15
  49.    2.6 Performance  . . . . . . . . . . . . . . . . . . . . . . . . . 16
  50.  3 Writing rule sets                                                  16
  51.    3.1 Rule set to observe all flows  . . . . . . . . . . . . . . . . 17
  52.    3.2 Specifying flow direction, using computed attributes . . . . . 18
  53.    3.3 Subroutines  . . . . . . . . . . . . . . . . . . . . . . . . . 21
  54.    3.4 More complicated rule sets . . . . . . . . . . . . . . . . . . 23
  55.  
  56.  
  57.  
  58. Brownlee                     Informational                      [Page 1]
  59.  
  60. RFC 2123                Traffic Flow Measurement              March 1997
  61.  
  62.  
  63.  4 Flow data files                                                    26
  64.    4.1 Sample flow data file  . . . . . . . . . . . . . . . . . . . . 27
  65.    4.2 Flow data file features  . . . . . . . . . . . . . . . . . . . 28
  66.    4.3 Terminating and restarting meter reading . . . . . . . . . . . 29
  67.  5 Analysis applications                                              30
  68.  6 Using NeTraMet in a measurement system                             31
  69.    6.1 Examples of NeTraMet in production use . . . . . . . . . . . . 31
  70.  7 Acknowledgments                                                    33
  71.  8 References                                                         33
  72.  9 Security Considerations                                            34
  73. 10 Author's Address                                                   34
  74.  
  75. 1 Introduction
  76.  
  77.    Early in 1992 my University needed to develop a system for recovering
  78.    the costs of its Internet traffic.  In March of that year I attended
  79.    the Internet Accounting Working Group's session at the San Diego
  80.    IETF, where I was delighted to find that the Group had produced a
  81.    detailed architecture for measuring network traffic and were waiting
  82.    for someone to try implementing it.
  83.  
  84.    During 1992 I produced a prototype measurement system, using balanced
  85.    binary trees to store information about traffic flows.  This work was
  86.    reported at the Washington IETF in November 1992.  The prototype
  87.    performed well, but it made no attempt to recover memory from old
  88.    flows, and the overheads in managing the balanced trees proved to be
  89.    unacceptably high.  I moved on to develop a production-quality
  90.    system, this time using hash tables to index the flow information.
  91.  
  92.    This version was called NeTraMet (the Network Traffic Meter), and was
  93.    released as free software in October 1993.  Since then I have
  94.    continued working on NeTraMet, producing new releases two or three
  95.    times each year.  NeTraMet is now in production use at many sites
  96.    around the world.  It is difficult to estimate the number of sites,
  97.    but there is an active NeTraMet mailing list, which had about 130
  98.    subscribers in March 1996.
  99.  
  100.    Early in 1996 the Realtime Traffic Flow Measurement Working Group
  101.    (RTFM) was chartered to move the Traffic Flow Measurement
  102.    Architecture on to the IETF standards track.  This document records
  103.    traffic flow measurement experience gained through three years
  104.    experience with NeTraMet.
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. Brownlee                     Informational                      [Page 2]
  115.  
  116. RFC 2123                Traffic Flow Measurement              March 1997
  117.  
  118.  
  119. 1.1 NeTraMet structure and development
  120.  
  121.    The Traffic Flow Architecture document [1] describes four components:
  122.  
  123.      - METERS, which are attached to the network at the points where
  124.        it is desired to measure the traffic,
  125.  
  126.      - METER READERS, which read data from meters and store it for later
  127.        use,
  128.  
  129.      - MANAGERS, which configure meters and control meter readers, and
  130.  
  131.      - ANALYSIS APPLICATIONS, which process the data from meter readers
  132.        so as to produce whatever reports are required.
  133.  
  134.    NeTraMet is a computer program which implements the Traffic Meter,
  135.    stores the measured flow data in memory, and provides an SNMP agent
  136.    so as to make it available to Meter Readers.  The NeTraMet
  137.    distribution files include NeMaC, which is a combined Manager and
  138.    Meter Reader capable of managing an arbitrary number of meters, each
  139.    of which may be using its own rule set, and having its flow data
  140.    collected at its own specified intervals.  The NeTraMet distribution
  141.    also includes several rudimentary Analysis Applications, allowing
  142.    users to produce simple plots from NeMaC's flow data files (fd_filter
  143.    and fd_extract) and to monitor - in real time - the flows at a remote
  144.    meter (nm_rc and nifty).
  145.  
  146.    Since the first release the Traffic Meter MIB [2] has been both
  147.    improved and simplified.  Significant changes have included better
  148.    ways to specify traffic flows (i.e. more actions and better control
  149.    structures for the Packet Matching Engine), and computed attributes
  150.    (class and kind).  These changes have been prompted by operational
  151.    requirements at sites using NeTraMet, and have been tested
  152.    extensively in successive versions of NeTraMet.
  153.  
  154.    NeTraMet is widely used to collect usage data for Internet Service
  155.    Providers.  This is especially so in Australia and New Zealand, but
  156.    there are also active users at sites around the world, for example in
  157.    Canada, France, Germany and Poland.
  158.  
  159.    NeTraMet is very useful as a tool for understanding exactly where
  160.    traffic is flowing in large networks.  Since the Traffic Meters
  161.    perform considerable data reduction (as specified by their rule sets)
  162.    they significantly reduce the volume of data to be read by Meter
  163.    Readers.  This characteristic makes NeTraMet particularly effective
  164.    for networks with many remote sites.  An example of this (the
  165.    Kawaihiko network) is briefly described below.
  166.  
  167.  
  168.  
  169.  
  170. Brownlee                     Informational                      [Page 3]
  171.  
  172. RFC 2123                Traffic Flow Measurement              March 1997
  173.  
  174.  
  175.    As well as providing data for post-observation analysis, NeTraMet can
  176.    be used for real-time network monitoring and trouble-shooting.  The
  177.    NeTraMet distribution includes 'nifty,' an X/Motif application which
  178.    monitors traffic flows and attempts to highlight those which are
  179.    'interesting.'
  180.  
  181. 1.2 Scope of this document
  182.  
  183.    This document presents the experience gained from three years work
  184.    with the Traffic Flow Measurement Architecture.  Its contents are
  185.    grouped as follows
  186.  
  187.      - Implementation issues for NeTraMet and NeMaC,
  188.  
  189.      - How rule files work, and how to write them for particular
  190.        purposes, and
  191.  
  192.      - How to use NeTraMet and NeMaC for short-term and long-term flow
  193.        measurement.
  194.  
  195. 2 Implementation
  196.  
  197. 2.1 Choice of meter platform
  198.  
  199.    As pointed out in the Architecture document [1], the goal of the
  200.    Realtime Traffic Flow Measurement Working Group is to develop a
  201.    standard for the Traffic Meter, with the goal of seeing it
  202.    implemented in network devices such as hubs, switches and routers.
  203.    Until the Architecture is well enough developed to allow this, it has
  204.    sufficed to implement the meter as a program running on a general-
  205.    purpose computer system.
  206.  
  207.    The choice of computer system for NeTraMet was driven by the need to
  208.    choose one which would be widely available within the Internet
  209.    community.  One strong possibility was a Unix system, since these are
  210.    commonly used for a variety of network support and management tasks.
  211.    For the initial implementation, however, Unix would have had some
  212.    disadvantages:
  213.  
  214.      - The wide variety of different Unix systems can increase the
  215.        difficulties of software support.
  216.  
  217.      - The cost of a Unix system as a meter is too high to allow users
  218.        to run meters simultaneously at many points within their
  219.        networks.
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. Brownlee                     Informational                      [Page 4]
  227.  
  228. RFC 2123                Traffic Flow Measurement              March 1997
  229.  
  230.  
  231.    Another factor in choosing the platform was system performance.  When
  232.    I first started implementing NeTraMet it was impossible to predict
  233.    how much processing workload was needed for a viable meter.
  234.    Similarly, I had no idea how much memory would be required for code
  235.    or data.  I therefore chose to implement NeTraMet on a DOS PC. This
  236.    was because:
  237.  
  238.      - It is a minimum system in all respects.  If the meter works
  239.        well on such a system, it can be implemented on almost any
  240.        hardware (including routers, switches, etc.)
  241.  
  242.      - It is an inexpensive system.  Sites can easily afford to have
  243.        many meters around their networks.
  244.  
  245.      - It is a simple system, and one which I had complete control over.
  246.        This allowed me to implement effective instrumentation to monitor
  247.        the meter's performance, and to include a wide variety of
  248.        performance optimisations in the code.
  249.  
  250.    Once the meter was running I needed a manager to download rule files
  251.    to it.  Since a single manager and meter reader can effectively
  252.    support a large number of meters, a Unix environment for NeMaC was a
  253.    natural choice.  There are fewer software support problems for NeMaC
  254.    than for NeTraMet since NeMaC has minimal support needs - it only
  255.    needs to open a UDP socket to the SNMP port on each controlled meter.
  256.  
  257.    Early NeTraMet distributions contained only the PC meter and Unix
  258.    manager.  In later releases I ported NeTraMet (the meter) to Unix,
  259.    and extended the control features of NeMaC (the combined manager and
  260.    meter reader).  I have also experimented with porting NeMaC to the
  261.    DOS system.  This is not difficult, but doesn't seem to be worth
  262.    pursuing.
  263.  
  264.    The current version of NeTraMet is a production-quality traffic
  265.    measurement system which has been in continuous use at the University
  266.    of Auckland for nearly two years.
  267.  
  268. 2.2 Programming support requirements
  269.  
  270.    To implement the Traffic Flow Meter I needed a programming
  271.    environment providing good support for the following:
  272.  
  273.      - observation of packet headers on the network;
  274.  
  275.      - system timer with better than 10 ms resolution;
  276.  
  277.      - IP (Internet Protocol), for communications with manager and meter
  278.        reader;
  279.  
  280.  
  281.  
  282. Brownlee                     Informational                      [Page 5]
  283.  
  284. RFC 2123                Traffic Flow Measurement              March 1997
  285.  
  286.  
  287.      - SNMP, for the agent implementing the Meter MIB.
  288.  
  289. 2.2.1 DOS environment
  290.  
  291.    For the PC I chose to use Ethernet as the physical network medium.
  292.    This is simply an initial choice, being the medium used within the
  293.    University of Auckland's data network.  Interfaces for other media
  294.    could easily be added as they are needed.
  295.  
  296.    In the PC environment a variety of 'generalised' network interfaces
  297.    are available.  I considered those available from companies such as
  298.    Novell, DEC and Microsoft and decided against them, partly because
  299.    they are proprietary, and partly because they did not appear to be
  300.    particularly easy to use.  Instead I chose the CRYNWR Packet Drivers
  301.    [3] .  These are available for a wide variety of interface cards and
  302.    are simple and clearly documented.  They support Ethernet's
  303.    promiscuous mode, allowing one to observe headers for every passing
  304.    packet in a straightforward manner.  One disadvantage of the Packet
  305.    Drivers is that it is harder to use them with newer user shells (such
  306.    as Microsoft Windows), but this was irrelevant since I intended to
  307.    run the meter as the only program on a dedicated machine.
  308.  
  309.    Timing on the PC presented a challenge since the BIOS timer routines
  310.    only provide a clock tick about 18 times each second, which limits
  311.    the available time resolution.  Initially I made do with a timing
  312.    resolution of one second for packets, since I believed that most
  313.    flows existed for many seconds.  In recent years it has become
  314.    apparent that many flows have lifetimes well under a second.  To
  315.    measure them properly with the Traffic Flow Meter one needs times
  316.    resolved to 10 millisecond intervals, this being the size of
  317.    TimeTicks, the most common time unit within SNMP [4].  Since all the
  318.    details of the original PC are readily available [5], it was not
  319.    difficult to understand the underlying hardware.  I have written PC
  320.    timer routines for NeTraMet which read the hardware timer with 256
  321.    times the resolution of the DOS clock ticks, i.e. about 5 ticks per
  322.    millisecond.
  323.  
  324.    There are many TCP/IP implementations available for DOS, but most of
  325.    them are commercial software.  Instead I chose Waterloo TCP [6],
  326.    since this was available (including full source code) as public
  327.    domain software.  This was necessary since I needed to modify it to
  328.    allow me to save incoming packet headers at the same time as
  329.    forwarding packets destined for the meter to the IP handler routines.
  330.    For SNMP I chose CMU SNMP [7], since again this was available (with
  331.    full source code) as public domain software.  This made it fairly
  332.    simple to port it from Unix to the PC.
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Brownlee                     Informational                      [Page 6]
  339.  
  340. RFC 2123                Traffic Flow Measurement              March 1997
  341.  
  342.  
  343.    Finally, for the NeTraMet development I used Borland's Turbo C and
  344.    Turbo Assembler.  Although many newer C programming environments are
  345.    now available, I have been perfectly happy with Turbo C version 2 for
  346.    the NeTraMet project!
  347.  
  348. 2.2.2 Unix environment
  349.  
  350.    In implementing the Unix meter, the one obvious problem was 'how do I
  351.    get access to packet headers?'  Early versions of the Unix meter were
  352.    implemented using various system-specific interfaces on a SunOS 4.2
  353.    system.  Later versions use libpcap [8], which provides a portable
  354.    method of obtaining access to packet headers on a wide range of Unix
  355.    systems.  I have verified that this works very well for ethernet
  356.    interfaces on Solaris, SunOS, Irix, DEC Unix and Linux, and for FDDI
  357.    interfaces on Solaris.  libpcap provides timestamps for each packet
  358.    header with resolution determined by the system clock, which is
  359.    certainly better than 10 ms!
  360.  
  361.    All Unix systems provide TCP/IP capabilities, so that was not an
  362.    issue.  For SNMP I used CMU SNMP, exactly as on the PC.
  363.  
  364. 2.3 Implementing the meter
  365.  
  366.    This section briefly discusses the data structures used by the meter,
  367.    and the packet matching process.  One very strong concern during the
  368.    evolution of NeTraMet has been the need for the highest possible
  369.    level of meter performance.  A variety of interesting optimisations
  370.    have been developed to achieve this; as discussed below.  Another
  371.    particular concern was the need for efficient and effective memory
  372.    managent; this is discussed in detail below.
  373.  
  374. 2.3.1 Data structures
  375.  
  376.    All the programs in NeTraMet, NeMaC and their supporting utility
  377.    programs are written in C, partly because C and its run-time
  378.    libraries provides good access to the underlying hardware, and partly
  379.    because I have found it to be a highly portable language.
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Brownlee                     Informational                      [Page 7]
  395.  
  396. RFC 2123                Traffic Flow Measurement              March 1997
  397.  
  398.  
  399.    The data for each flow is stored in a C structure.  The structure
  400.    includes all the flow's attribute values (including packet and byte
  401.    counts), together with a link field which can be used to link flows
  402.    into lists.  NeTraMet assumes that Adjacent addresses are 802 MAC
  403.    Addresses, which are all six bytes long.  Similarly, Transport
  404.    addresses are assumes to be two bytes long, which is the case for
  405.    port numbers in IP.  Peer addresses are normally four bytes or less
  406.    in length.  They may, however, be as long as 20 bytes (for CLNS). I
  407.    have chosen to use a fixed Peer address size, defined at compile
  408.    time, so as to avoid the complexity of having variable-sized flow
  409.    structures.
  410.  
  411.    The flow table itself is an array of pointers to flow data
  412.    structures, which allows indexed access to flows via their flow
  413.    numbers.  There is also a single large hash table, referred to in the
  414.    Architecture document [1] as the flow table's 'search index'.  Each
  415.    hash value in the table points to a circular chain of flows.  To find
  416.    a flow one computes its hash value then searches that value's flow
  417.    chain.
  418.  
  419.    The meter stores each rule in a C structure.  All the rule components
  420.    have fixed sizes, but address fields must be wide enough to hold any
  421.    type of address - Adjacent, Peer or Transport.  The rule address
  422.    width is defined at compile time, in the same way as flow Peer
  423.    addresses.  Each rule set is implemented as an array of pointers to
  424.    rule data structures, and the rule table is an array of pointers to
  425.    the rule sets.  The size of each rule set is specified by NeMaC
  426.    (before it begins downloading the rule set), but the maximum number
  427.    of rule sets is defined at compile time.
  428.  
  429. 2.3.2 Packet matching
  430.  
  431.    Packet matching is carried out in NeTraMet exactly as described in
  432.    the Architecture document [1].  Each incoming packet header is
  433.    analysed so as to determine its attribute values.  These values are
  434.    stored in a structure which is passed to the Packet Matching Engine.
  435.    To facilitate matching with source and destination reversed this
  436.    structure contains two substructures, one containing the source
  437.    Adjacent, Peer and Transport address values, the other containing the
  438.    destination address values.
  439.  
  440. 2.3.3 Testing groups of rule addresses
  441.  
  442.    As described in the Architecture [1] each rule's address will usually
  443.    be tested, i.e. ANDed with the rule's mask and compared with the
  444.    rule's value.  If the comparison fails, the next rule in sequence is
  445.    executed.  This allows one to write rule sets which use a group of
  446.    rules to test an incoming packet to see whether one of its addresses
  447.  
  448.  
  449.  
  450. Brownlee                     Informational                      [Page 8]
  451.  
  452. RFC 2123                Traffic Flow Measurement              March 1997
  453.  
  454.  
  455.    - e.g. its SourcePeerAddress - is one of a set of specified IP
  456.    addresses.  Such groups of related rules can grow quite large,
  457.    containing hundreds of rules.  It was clear that sequential execution
  458.    of such groups of rules would be slow, and that something better was
  459.    essential.
  460.  
  461.    The optimisation implemented in NeTraMet is to find groups of rules
  462.    which test the same attribute with the same mask, and convert them
  463.    into a single hashed search of their values.  The overhead of setting
  464.    up hash tables (one for each group) is incurred once, just before the
  465.    meter starts running a new rule set.  When a 'group' test is to be
  466.    performed, the meter ANDs the incoming attribute value, computes a
  467.    hash value from it, and uses this to search the group's hash table.
  468.    Early tests showed that the rule hash chains were usually very short,
  469.    usually having only one or two members.  The effect is to reduce
  470.    large sequences of tests to a hash computation and lookup, with a
  471.    very small number of compares; in short this is an essential
  472.    optimisation for any traffic meter!
  473.  
  474.    There is, of course, overhead associated with performing the hashed
  475.    compare.  NeTraMet handles this by having a minimum group size
  476.    defined at compile time.  If the group is too small it is not
  477.    combined into a hashed group.
  478.  
  479.    In early versions of NeTraMet I did not allow Gotos into a hashed
  480.    group of rules, which proved to be an unnecessarily conservative
  481.    position.  NeTraMet stores each group's hash table in a separate
  482.    memory area, and keeps a pointer to the hash table in the first rule
  483.    of the group.  (The rules data structure has an extra component to
  484.    hold this hash table pointer).  Rules within the group don't have
  485.    hash table pointers; when they are executed as the target of a Goto
  486.    rule they behave as ordinary rules, i.e. their tests are performed
  487.    normally.
  488.  
  489. 2.3.4 Compression of address masks
  490.  
  491.    When the Packet Matching Engine has decided that an incoming packet
  492.    belongs to a flow which is to be measured, it searches the flow table
  493.    to determine whether or not the flow is already present.  It does
  494.    this by computing a hash from the packet and using it for access to
  495.    the flow table's search index.
  496.  
  497.    When designing a hash table, one normally assumes that the objects in
  498.    the table have a constant size.  For NeTraMet's flow table this would
  499.    mean that each flow would contain a value for every attribute.  This,
  500.    however, is not the case, since only those attribute values 'pushed'
  501.    by rules during packet matching are stored for a flow.
  502.  
  503.  
  504.  
  505.  
  506. Brownlee                     Informational                      [Page 9]
  507.  
  508. RFC 2123                Traffic Flow Measurement              March 1997
  509.  
  510.  
  511.    To demonstrate this problem , let us assume that every flow in the
  512.    table contains a value for only one attribute, SourcePeerAddress, and
  513.    that the rule set decides whether flows belong to a specified list of
  514.    IP networks, in which case only their network numbers are pushed.
  515.    The rules perform this test using a variety of masks, since the
  516.    network number allocations range from 16 to 24 bits in width.  In
  517.    searching the flow table, the meter must distinguish between zeroes
  518.    in the address and 'don't care' bits which had been ANDed out.  To
  519.    achieve this it must store SourcePeerMask values in the flow table as
  520.    well as the ANDed SourcePeerAddress values.
  521.  
  522.    In early versions of NeTraMet this problem was side-stepped by using
  523.    multiple hash tables and relying on the user to write rules which
  524.    used the same set of attributes and masks for all the flows in each
  525.    table.  This was effective, but clumsy and difficult to explain.
  526.    Later versions changed to using a single hash table, and storing the
  527.    mask values for all the address attributes in each flow.
  528.  
  529.    The current version of the meter stores the address masks in
  530.    compressed form.  After examining a large number of rule sets I
  531.    realised that although a rule set may have many rules, it usually has
  532.    a very small number of address masks.  It is a simple matter to build
  533.    a table of address masks, and store an index to this 'mask table'
  534.    instead of a complete mask.  NeTraMet's maximum number of masks is
  535.    defined at compile time, up to a maximum of 256.  This allows me to
  536.    use a single byte for each mask in the flow data structure,
  537.    significantly reducing the structure's size.  As well as this size
  538.    reduction, two masks can be compared by comparing their indices in
  539.    the mask table, i.e. it reduces to a single-byte comparison.
  540.    Overall, using a mask table seems to provide useful improvements in
  541.    storage efficiency and execution speed.
  542.  
  543. 2.3.5 Ignoring unwanted flow data
  544.  
  545.    As described in the Architecture document [1], every incoming packet
  546.    is tested against the current rule set by the Packet Matching Engine.
  547.    This section explains my efforts to improve NeTraMet performance on
  548.    the PC by reducing the amount of processing required by each incoming
  549.    packet.
  550.  
  551.    On the PC each incoming packet causes an interrupt, which NeTraMet
  552.    must process so as to collect information about the packet.  In early
  553.    versions I used a ring buffer with 512 slots for packet headers, and
  554.    simply copied each packet's first 64 bytes into the next free slot.
  555.    The packet headers were later taken from the buffer, attribute values
  556.    were extracted from them, and the resulting 'incoming attribute
  557.    values' records were passed to the Packet Matching Engine.
  558.  
  559.  
  560.  
  561.  
  562. Brownlee                     Informational                     [Page 10]
  563.  
  564. RFC 2123                Traffic Flow Measurement              March 1997
  565.  
  566.  
  567.    I modified the interrupt handling code to extract the attribute
  568.    values and store them in a 'buffer slot.'  This reduced the amount of
  569.    storage required in each slot, allowing more space for storing flows.
  570.    It did increase slightly the amount of processing done for each
  571.    packet interrupt, but this has not caused any problems.
  572.  
  573.    In later versions I realised that if one is only interested in
  574.    measuring IP packets, there is no point in storing (and later
  575.    processing) Novell or EtherTalk packets!  It is a simple matter for
  576.    the meter to inspect a rule set and determine which Peer types are of
  577.    interest.  If there are PushRule rules which test SourcePeerType (or
  578.    DestPeerType), they specify which types are of interest.  If there
  579.    are no such rules, every packet type is of interest.  The PC NeTraMet
  580.    has a set of Boolean variables, one for each protocol it can handle.
  581.    The values of these 'protocol' variables are determined when the
  582.    meter begins running a new rule set.  For each incoming packet, the
  583.    interrupt handler determines the Peer type.  If the protocol is not
  584.    of interest, no further processing is done - the packet is simply
  585.    ignored.  In a similar manner, if Adjacent addresses are never tested
  586.    there is no point in copying them into the packet buffer slot.
  587.  
  588.    The overall effect of these optimisations is most noticeable for rule
  589.    files which measure IP flows on a network segment which also carries
  590.    a lot of traffic for other network protocols; this situation is
  591.    common on multiprotocol Local Area networks.  On the Unix version of
  592.    NeTraMet the Operating System does all the packet interrupt
  593.    processing, and libpcap [8] delivers packet headers directly to
  594.    NeTraMet.  The 'protocol' and 'adjacent address' optimisations are
  595.    still performed, at the point when NeTraMet receives the packet
  596.    headers from libpcap.
  597.  
  598. 2.3.6 Observing meter reader activity
  599.  
  600.    The Architecture document [1] explains that a flow data record must
  601.    be held in the meter until its data has been read by a meter reader.
  602.    A meter must therefore have a reliable way of deciding when flow data
  603.    has been read.  The problem is complicated by the fact that there may
  604.    be more than one meter reader, and that meter readers collect their
  605.    data asynchronously.
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618. Brownlee                     Informational                     [Page 11]
  619.  
  620. RFC 2123                Traffic Flow Measurement              March 1997
  621.  
  622.  
  623.    Early versions of NeTraMet solved this problem by having a single MIB
  624.    variable which a meter reader could set to indicate that it was
  625.    beginning a data collection.  In response to such an SNMP SET
  626.    request, NeTraMet would update its 'collectors' table.  This had an
  627.    entry for each meter reader, and variables recording the start time
  628.    for the last two collections.  The most recent collection might still
  629.    be in progress, but its start time provides a safe estimate of the
  630.    time when the one before it actually finished.  Space used for flows
  631.    which have been idle since the penultimate collection started can be
  632.    recovered by the meter's garbage collector, as described below.
  633.  
  634.    The Meter MIB [2] specifies a more general table of meter reader
  635.    information.  A meter reader wishing to collect data from a meter
  636.    must inform the meter of its intention by creating a row in the
  637.    table, then setting a LastTime variable in that row to indicate the
  638.    start of a collection.  The meter handles such a SET request exactly
  639.    as described above.  If there are multiple meter readers the meter
  640.    can easily find the earliest time any of them started its penultimate
  641.    collection, and may recover flows idle since then.  Should a meter
  642.    reader fail, NeTraMet will eventually time out its entry in the meter
  643.    reader info table, and delete it.  This avoids a situation where the
  644.    meter can't recover flows until they have been collected by several
  645.    meter readers, one of which has failed.
  646.  
  647. 2.3.7 Meter memory management
  648.  
  649.    In principle, the size of the flow table (i.e. the maximum number of
  650.    flows) could be changed dynamically.  This would involve allocating
  651.    space for the flow table's new pointer array and copying the old
  652.    pointers into it.  NeTraMet does not implement this.  Instead the
  653.    maximum number of flows is set from the command line when it starts
  654.    execution.  If no maximum is specified, a compile-time default number
  655.    is used.
  656.  
  657.    Memory for flow data structures (i.e. 'flows') is allocated
  658.    dynamically.  NeTraMet requests the C run-time system for blocks of
  659.    several hundred flows, and links them into a free list.  When a new
  660.    flow is needed NeTraMet gets memory space from the free list, then
  661.    searches the flow table's pointer array for an unused flow pointer.
  662.    In practice a 'last-allocated' index is used to point to the flow
  663.    table, so a simple linear search suffices.  The flow index is saved
  664.    in the flow's data record, and its other attribute values are set to
  665.    zero.
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674. Brownlee                     Informational                     [Page 12]
  675.  
  676. RFC 2123                Traffic Flow Measurement              March 1997
  677.  
  678.  
  679.    To release a flow data record it must first be removed from any hash
  680.    list it is part of - this is straightforward since those lists are
  681.    circular.  The flow's entry in the flow table pointer array is then
  682.    set to zero (NULL pointer), and its space is returned to the free
  683.    list.
  684.  
  685.    Once a flow data record is created it could continue to exist
  686.    indefinitely.  In time, however, the meter would run out of space.
  687.    To deal with this problem NeTraMet uses an incremental garbage
  688.    collector to reclaim memory.
  689.  
  690.    At regular intervals specified by a 'GarbageCollectInterval' variable
  691.    the garbage collector procedure is invoked.  This searches through
  692.    the flow table looking for flows which might be recovered.  To
  693.    control the resources consumed by garbage collection there are limits
  694.    on the number of in-use and idle flows which the garbage collector
  695.    may inspect  these are set either when NeTraMet is started (as
  696.    options on the command line) or dynamically by NeMaC (using variables
  697.    in an Enterprise MIB for NeTraMet)
  698.  
  699.    To decide whether a flow can be recovered, the garbage collector
  700.    considers how long it has been idle (no packets in either direction),
  701.    and when its data was last collected.  If it has been collected by
  702.    all known meter readers since its LastTime, its memory may be
  703.    recovered.  This alogrithm is implemented using a variable called
  704.    'GarbageCollectTime,' which normally contains the meter's UpTime when
  705.    the penultimate collection (i.e. the one before last) was started.
  706.    See the section on observing meter reader activity (above) for more
  707.    details.
  708.  
  709.    Should flows not be collected often enough the meter could run out of
  710.    space.  NeTraMet attempts to prevent this by having a low-priority
  711.    background process check the percentage of flows active and compare
  712.    it with the HighWaterMark MIB variable.  If the percentage of active
  713.    flows is greater than the high-water mark, 'GarbageCollectTime' is
  714.    incremented by the current value of the InactivityTimeout MIB
  715.    variable.
  716.  
  717.    The Meter MIB [2] specifies that a meter should switch to using a
  718.    'standby' rule set if the percentage of active flows rises above
  719.    HighWaterMark.  In using NeTraMet to measure traffic flows to and
  720.    from the University of Auckland it has not been difficult to create
  721.    standby rules which are very similar to the 'production' rule file,
  722.    differing only in that they push much less information about flows.
  723.    This has, on several occasions, allowed the meter to continue running
  724.    for one or two days after the meter reader failed.  When the meter
  725.    reader restarted, it was able to collect all the accumulated flow
  726.    data!
  727.  
  728.  
  729.  
  730. Brownlee                     Informational                     [Page 13]
  731.  
  732. RFC 2123                Traffic Flow Measurement              March 1997
  733.  
  734.  
  735.    The MIB also specifies that the meter should take some action when
  736.    the active flow percentage rises above its FloodMark value.  If this
  737.    were not done, the meter could spend a rapidly increasing proportion
  738.    of its time garbage collecting, to the point where its ability to
  739.    respond to requests from its manager would be compromised.  NeTraMet
  740.    switches to the default rule set when its FloodMark is reached.
  741.  
  742.    A potentially large number of new flows may be created when the meter
  743.    switches to a standby rule set.  It is important to set a
  744.    HighWaterMark so as to allow enough flow table space for this.  In
  745.    practice, a HighWaterMark of 65% and a FloodMark of 95% seem to work
  746.    well.
  747.  
  748. 2.4 Data collection
  749.  
  750.    As explained above, a meter reader wishing to collect flows begins
  751.    each collection by setting the LastTime variable in its
  752.    ReaderInfoTable row, then works its way through the flow table
  753.    collecting data.  A number of algorithms can be used to examine the
  754.    flow table; these are presented below.
  755.  
  756.    The simplest approach is a linear scan of the table, reading the
  757.    LastTime variable for each row.  If the read fails the row is
  758.    inactive.  If it succeeds, it is of interest if its LastTime value is
  759.    greater than the time of the last collection.  Although this method
  760.    is simple it is also rather slow, requiring an SNMP GET request for
  761.    every possible flow; this renders it impractical.
  762.  
  763.    Early versions of NeTraMet used two 'windows' into the flow table to
  764.    find flows which were of interest.  Both windows were SNMP tables,
  765.    indexed by a variable which specified a time.  A succession of
  766.    GETNEXT requests on one of these windows allowed NeMaC (the meter
  767.    reader) to find the flow indices for all flows which had been active
  768.    since the specified time.  The two windows were the ActivityTime
  769.    window (which located active flows), and the CreateTime window (which
  770.    located new flows).  Knowing the index of an active flow, the meter
  771.    reader can GET the values for all the attributes of interest.  NeMaC
  772.    allows the user to specify which these are, rather than simply read
  773.    all the attributes.
  774.  
  775.    Having the two windows allowed NeMaC to read attributes which remain
  776.    constant - such as the flow's address attributes - when the flow is
  777.    created, but to only read attributes which change with time - such as
  778.    its packet and byte counts - during later collections.  Experience
  779.    has shown, however, that many flows have rather short lifetimes; one
  780.    effect of this is that the improved efficiency of using two windows
  781.    does not result in any worthwhile improvement in collection
  782.    performance.
  783.  
  784.  
  785.  
  786. Brownlee                     Informational                     [Page 14]
  787.  
  788. RFC 2123                Traffic Flow Measurement              March 1997
  789.  
  790.  
  791.    The current version of the Meter MIB [2] uses a TimeFilter variable
  792.    in the flow table entries.  This can be used with GETNEXT requests to
  793.    find all flows which have been active since a specified time
  794.    directly, without requiring the extra 'window' SNMP variables.  It
  795.    can be combined with SNMPv2's GETBULK request to further reduce the
  796.    number of SNMP packets needed for each collection; I have yet to
  797.    implement this in NeTraMet.
  798.  
  799.    A disadvantage of using SNMP to collect data from the meter is that
  800.    SNMP packets impose a high overhead.  For example, if we wish to read
  801.    an Integer32 variable (four bytes of data), it will be returned with
  802.    its object identifier, type and length, i.e. at least ten bytes of
  803.    superfluous data.  One way to reduce this overhead is to use an
  804.    Opaque object to return a collection of data.  NeTraMet uses this
  805.    approach to retrieve 'column activity data' from the meter, as
  806.    follows.
  807.  
  808.    Each packet of column activity data contains data values for a
  809.    specified attribute, and each value is preceded by its flow number.
  810.    The flow table can be regarded as a two-dimensional array, with a
  811.    column for each flow attribute.  Column activity data objects allow
  812.    the meter reader to read columns of the flow table, so as to collect
  813.    only those attributes specified by the user.  The actual
  814.    implementation is complicated by the fact that since the flow table
  815.    is read column by column, rows can become active after the first
  816.    column has been read.  NeMaC reads the widest columns (those with
  817.    greatest size in bytes, e.g. PeerAddress) first, and ignores any rows
  818.    which appear in later columns.  Newly active rows will, of course, be
  819.    read in the next collection.
  820.  
  821.    Using Opaque objects in this way dramatically reduces the number of
  822.    SNMP packets required to read a meter.  This has proved worthwhile in
  823.    situations where the number of flows is large (for example on busy
  824.    LANs), and where the meter(s) are physically dispersed over slow WAN
  825.    links.  It has the disadvantage that general-purpose MIB browsers
  826.    cannot understand the column activity variables, but this seems a
  827.    small price to pay for the improved data collection performance.
  828.  
  829. 2.5 Restarting a meter
  830.  
  831.    If a meter fails, for example because of a power failure, it will
  832.    restart and begin running rule set 1, the default rule set which is
  833.    built into the meter.  Its manager must recognise that this has
  834.    happened, and respond with some suitable action.
  835.  
  836.    NeMaC allows the user to specify a 'keepalive' interval.  After every
  837.    such interval NeMaC reads the meter's sysUptime and compares it with
  838.    the last sysUptime.  If the new sysUptime is less than the last one,
  839.  
  840.  
  841.  
  842. Brownlee                     Informational                     [Page 15]
  843.  
  844. RFC 2123                Traffic Flow Measurement              March 1997
  845.  
  846.  
  847.    NeMaC decides that the meter has restarted.  It downloads the meter's
  848.    backup rule set and production rule set, then requests the meter to
  849.    start running the production rule set.  In normal use we use a
  850.    keepalive interval of five minutes and a collection interval of 15
  851.    minutes.  If a meter restarts, we lose up to five minutes data before
  852.    the rules sets are downloaded.
  853.  
  854.    Having the meter run the default rule set on startup is part of the
  855.    Traffic Flow Measurement Architecture [1], in keeping with the notion
  856.    that meters are very simple devices which do not have disk storage.
  857.    Since disks are now very cheap, it may be worth considering whether
  858.    the architecture should allow a meter to save its configuration
  859.    (including rule sets) on disk.
  860.  
  861. 2.6 Performance
  862.  
  863.    The PC version of the meter, NeTraMet, continually measures how much
  864.    processor time is being used.  Whenever there is no incoming packet
  865.    data to process, 'dummy' packets are generated and placed in the
  866.    input buffer.  These packets are processed normally by the Packet
  867.    Matching Engine; they have a PeerType of 'dummy.'  The numbers of
  868.    dummy and normal packets are counted by the meter; their ratio is
  869.    used as an estimate of the processor time which is 'idle,' i.e. not
  870.    being used to process incoming packets.  The Unix version is intended
  871.    to run as a process in a multiprocessing system, so it cannot busy-
  872.    wait in this way.
  873.  
  874.    The meter also collects several other performance measures; these can
  875.    be displayed on the meter console in response to keyboard requests.
  876.  
  877.    The PC meter can be used with a 10 MHz 286 machine, on which it can
  878.    handle a steady load of about 750 packets per second.  On a 25 MHz
  879.    386SX it will handle about 1250 packets per second.  Users have
  880.    reported that a 40 MHz 486 can handle peaks of about 3,000 packets
  881.    per second without packet loss.  The Unix meter has been tested
  882.    metering traffic on a (lightly loaded) FDDI interface; it uses about
  883.    one percent of the processor time on a SPARC 10 system running
  884.    Solaris.
  885.  
  886. 3 Writing rule sets
  887.  
  888.    The Traffic Meter provides a versatile device for measuring a user-
  889.    specified set of traffic flows, and performing useful data reduction
  890.    on them.  This data reduction capability not only minimises the
  891.    volume of data to be collected by meter readers, but also simplifies
  892.    the later processing of traffic flow data.
  893.  
  894.  
  895.  
  896.  
  897.  
  898. Brownlee                     Informational                     [Page 16]
  899.  
  900. RFC 2123                Traffic Flow Measurement              March 1997
  901.  
  902.  
  903.    The flows of interest, and the processing to be performed, are
  904.    specified in a 'rule set' which is downloaded to the meter (NeTraMet)
  905.    by the manager (NeMaC). This section explains what is involved in
  906.    writing rule sets.
  907.  
  908.    NeTraMet is limited to metering packets observed on a network
  909.    segment.  This means that for all the observed flows, Source and Dest
  910.    Type attributes (e.g. SourcePeerType and DestPeerType) have the same
  911.    value.
  912.  
  913.    The NeTraMet implementation uses single variables in its flow data
  914.    structure for AdjacentType, SourceType and TransType.  Nonetheless,
  915.    the rule sets discussed below push values for both Source and Dest
  916.    Type attributes; this make sure that packet matching works properly
  917.    with the directions reversed, even for a meter which allows Source
  918.    and Dest Type values to be different.
  919.  
  920. 3.1 Rule set to observe all flows
  921.  
  922.    NeMaC reads rule sets from text files which contain the rules, the
  923.    set number which the meter (and meter reader) will identify them by,
  924.    and a 'format,' i.e. a list specifying which attributes the meter
  925.    reader should collect and write to the flow data file.  The #
  926.    character indicates the start of a comment; NeMaC ignores the rest of
  927.    the line.
  928.  
  929.      SET 2
  930.      #
  931.      RULES
  932.      #
  933.        SourcePeerType & 255 = Dummy:   Ignore, 0;
  934.        Null & 0 = 0:  GotoAct, Next;
  935.      #
  936.        SourcePeerType     & 255             = 0: PushPkttoAct, Next;
  937.        DestPeerType       & 255             = 0: PushPkttoAct, Next;
  938.        SourcePeerAddress  & 255.255.255.255 = 0: PushPkttoAct, Next;
  939.        DestPeerAddress    & 255.255.255.255 = 0: PushPkttoAct, Next;
  940.        SourceTransType    & 255             = 0: PushPkttoAct, Next;
  941.        DestTransType      & 255             = 0: PushPkttoAct, Next;
  942.        SourceTransAddress & 255.255         = 0: PushPkttoAct, Next;
  943.        DestTransAddress   & 255.255         = 0: CountPkt, 0;
  944.      #
  945.      FORMAT FlowRuleSet FlowIndex FirstTime "  "
  946.         SourcePeerType SourcePeerAddress DestPeerAddress "  "
  947.         SourceTransType SourceTransAddress DestTransAddress "  "
  948.         ToPDUs FromPDUs "  " ToOctets FromOctets;
  949.  
  950.  
  951.  
  952.  
  953.  
  954. Brownlee                     Informational                     [Page 17]
  955.  
  956. RFC 2123                Traffic Flow Measurement              March 1997
  957.  
  958.  
  959.    The first rule tests the incoming packet's SourcePeerType to see
  960.    whether it is 'dummy.'  If it is, the packet is ignored, otherwise
  961.    the next rule is executed.
  962.  
  963.    The second rule tests the Null attribute.  Such a test always
  964.    succeeds, so the rule simply jumps to the action of the next rule.
  965.    (The keyword 'next' is converted by NeMaC into the number of the
  966.    following rule.)
  967.  
  968.    The third rule pushes the packet's SourcePeerType value, then jumps
  969.    to the action of the next rule.  The user does not know in advance
  970.    what the value of PushPkt rules will be, which is why the value
  971.    appearing in them is always zero.  The user must take care not to
  972.    write rule sets which try to perform the test in a PushPkt rule.
  973.    This is a very common error in a rule set, so NeMaC tests for it and
  974.    displays an error message.
  975.  
  976.    The following rules push a series of attribute values from the
  977.    packet, and the last rule also Counts the packet, i.e. it tells the
  978.    Packet Matching Engine (PME) that the packet has been successfully
  979.    matched.  The PME responds by searching the flow table to see whether
  980.    the flow is already current (i.e. in the table), creating a new flow
  981.    data record for it should this be necessary, and incrementing its
  982.    packet and byte counters.
  983.  
  984.    Overall this rule set simply classifies the packet (i.e. decides
  985.    whether or not it is to be counted), then pushes all the Peer and
  986.    Transport attribute values for it.  It makes no attempt to specify a
  987.    direction for the flow - this is left to the PME, as described in
  988.    [1].  The resulting flow data file will have each flow's source and
  989.    destination addresses in the order of the first packet the meter
  990.    observed for the flow.
  991.  
  992. 3.2 Specifying flow direction, using computed attributes
  993.  
  994.    As indicated above, the Packet Matching Engine will reliably
  995.    determine the flow, and the direction within that flow, for every
  996.    packet seen by a meter.  If the rule set does not specify a direction
  997.    for the flow, the PME simply assumes that the first packet observed
  998.    for a flow is travelling forward, i.e. from source to destination.
  999.    In later analysis of the flow data, however, one is usually
  1000.    interested in traffic to or from a particular source.
  1001.  
  1002.    One can achieve this in a simple manner by writing a rule set to
  1003.    specify the source for flows.  All that is required is to have rules
  1004.    which succeed if the packet is travelling in the required direction,
  1005.    and which execute a 'Fail' action otherwise.  This is demonstrated in
  1006.    the following two examples.
  1007.  
  1008.  
  1009.  
  1010. Brownlee                     Informational                     [Page 18]
  1011.  
  1012. RFC 2123                Traffic Flow Measurement              March 1997
  1013.  
  1014.  
  1015.    (Note that early versions of NeMaC allowed 'Retry' as a synonym for
  1016.    'Fail.'  The current version also allows 'NoMatch,' which seems a
  1017.    better way to imply "fail, allowing PME to try a second match with
  1018.    directions reversed.")
  1019.  
  1020.      #  Count IP packets from network 130.216.0.0
  1021.      #
  1022.      SourcePeerType & 255 = IP: Pushto, ip_pkt;
  1023.      Null & 0 = 0: Ignore, 0;
  1024.      #
  1025.      ip_pkt:
  1026.        SourcePeerAddress & 255.255.0.0 = 130.216.0.0: Goto c_pkt;
  1027.        Null & 0 = 0: NoMatch, 0;
  1028.      #
  1029.      c_pkt:
  1030.        SourcePeerAddress & 255.255.255.255 = 0: PushPkttoAct, Next;
  1031.        DestPeerAddress & 255.255.255.255 = 0: CountPkt, 0;
  1032.  
  1033.    The rule labelled ip_pkt tests whether the packet came from network
  1034.    130.216.  If it did not, the test fails and the following rule
  1035.    executes a NoMatch action, causing the PME to retry the match with
  1036.    the directions reversed.  If the second match fails the packet did
  1037.    not have 130.216 as an end-point, and is ignored.
  1038.  
  1039.    The next rule set meters IP traffic on a network segment which
  1040.    connects two routers, g1 and g2.  It classifies flows into three
  1041.    groups - those travelling from g1 to g2, those whose source is g1 and
  1042.    those whose source is g2.
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066. Brownlee                     Informational                     [Page 19]
  1067.  
  1068. RFC 2123                Traffic Flow Measurement              March 1997
  1069.  
  1070.  
  1071.      #  Count IP packets between two gateways
  1072.      #
  1073.      #     -------+-------------------+------------------+-------
  1074.      #            |                   |                  |
  1075.      #       +----+-----+        +----+-----+        +---+---+
  1076.      #       |   g1     |        |    g2    |        | meter |
  1077.      #       +-+-+-+-+--+        +-+-+-+-+--+        +-------+
  1078.      #
  1079.      SourcePeerType & 255 = IP: Pushto, ip_pkt;
  1080.      Null & 0 = 0: Ignore, 0;
  1081.      #
  1082.      ip_pkt:
  1083.        SourceAdjacentAddress & FF-FF-FF-FF-FF-FF = 00-80-48-81-0E-7C:
  1084.            Goto, s1;
  1085.        Null & 0 = 0: Goto, s2;
  1086.      s1:
  1087.        DestAdjacentAddress & FF-FF-FF-FF-FF-FF = 02-07-01-04-ED-4A
  1088.            GotoAct, g3;
  1089.        Null & 0 = 0: GotoAct, g1;
  1090.      s2:
  1091.        SourceAdjacentAddress & FF-FF-FF-FF-FF-FF = 02-07-01-04-ED-4A:
  1092.            Goto, s3;
  1093.        Null & 0 = 0: NoMatch, 0;
  1094.      s3:
  1095.        DestAdjacentAddress & FF-FF-FF-FF-FF-FF = 00-80-48-81-0E-7C:
  1096.            NoMatch, 0;
  1097.        Null & 0 = 0: GotoAct, g2;
  1098.      #
  1099.      g1: FlowClass & 255 = 1:  PushtoAct, c_pkt;  # From g1
  1100.      g2: FlowClass & 255 = 2:  PushtoAct, c_pkt;  # From g2
  1101.      g3: FlowClass & 255 = 3:  PushtoAct, c_pkt;  # g1 to g2
  1102.      #
  1103.      c_pkt:
  1104.        SourceAdjacentAddress & FF-FF-FF-FF-FF-FF = 0:
  1105.            PushPkttoAct, Next;
  1106.        DestAdjacentAddress & FF-FF-FF-FF-FF-FF = 0: PushPkttoAct, Next;
  1107.        SourcePeerAddress & 255.255.255.255 = 0: PushPkttoAct, Next;
  1108.        DestPeerAddress & 255.255.255.255 = 0: PushPkttoAct, Next;
  1109.        Null & 0 = 0:  Count, 0
  1110.  
  1111.    The first two rules ignore non-IP packets.  The next two rules Goto
  1112.    s1 if the packet's source was g1, or to s2 otherwise.  The rule
  1113.    labelled s2 tests whether the packet's source was g2; if not a
  1114.    NoMatch action is executed, allowing the PME to try the match with
  1115.    the packet's direction reversed.  If the match fails on the second
  1116.    try the packet didn't come from (or go to) g1 or g2, and is ignored.
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122. Brownlee                     Informational                     [Page 20]
  1123.  
  1124. RFC 2123                Traffic Flow Measurement              March 1997
  1125.  
  1126.  
  1127.    Packets which come from g1 are tested by the rule labelled s1, and
  1128.    the PME will Goto either g3 or g1.
  1129.  
  1130.    Packets which came from g2 are tested by the rule labelled s3.  If
  1131.    they are not going to g1 the PME will Goto g2.  If they are going to
  1132.    g1 a NoMatch action is executed - we want them counted as backward-
  1133.    travelling packets for the g1-g2 flow.
  1134.  
  1135.    The rules at g1, g2 and g3 push the value 1, 2 or 3 from their rule
  1136.    into the flow's FlowClass attribute.  This value can be used by an
  1137.    Analysis Application to separate the flows into the three groups of
  1138.    interest.  FlowClass is an example of a 'computed' attribute, i.e.
  1139.    one whose value is Pushed by the PME during rule matching.
  1140.  
  1141.    The remaining rules Push the values of other attributes required for
  1142.    later analysis, then Count the flow.
  1143.  
  1144. 3.3 Subroutines
  1145.  
  1146.    Subroutines are implemented in the PME in much the same way as in
  1147.    BASIC.  A subroutine body is just a sequence of statements, supported
  1148.    by the GoSub and Return actions.  'GoSub' saves the PME's running
  1149.    environment and jumps to the first rule of the subroutine body.
  1150.    Subroutine calls may be nested as required - NeTraMet defines the
  1151.    maximum nesting at compile time.  'Return n' restores the environment
  1152.    and jumps to the action part of the nth rule after the Gosub, where n
  1153.    is the index value from the Return rule.
  1154.  
  1155.    The Return action provides a way of influencing the flow of control
  1156.    in a rule set, rather like a FORTRAN Computed Goto.  This is one way
  1157.    in which a subroutine can return a result.  The other way is by
  1158.    Pushing a value in either a computed attribute (as demonstrated in
  1159.    the preceding section), or in a flow attribute.
  1160.  
  1161.    One common use for a subroutine is to test whether a packet attribute
  1162.    matches one of a set of values.  Such a subroutine becomes much more
  1163.    useful if it can be used to test one of several attributes.  The PME
  1164.    architecture provides for this by using 'meter variables' to hold the
  1165.    names of the attributes to be tested.  The meter variables are called
  1166.    V1, V2, V3, V4 and V5, and the Assign action is provided to set their
  1167.    values.  If, for example, we need a subroutine to test either
  1168.    SourcePeerAddress or DestPeerAddress, we write its rules to test V1
  1169.    instead.  Before calling the subroutine we Assign SourcePeerAddress
  1170.    to V1; later tests of V1 are converted by the PME into tests on
  1171.    SourcePeerAddress.  Note that since meter variables may be reassigned
  1172.    in a subroutine, their values are part of the environment which must
  1173.    be saved by a Gosub action.
  1174.  
  1175.  
  1176.  
  1177.  
  1178. Brownlee                     Informational                     [Page 21]
  1179.  
  1180. RFC 2123                Traffic Flow Measurement              March 1997
  1181.  
  1182.  
  1183.    The following rule set demonstrates the use of a subroutine ..
  1184.  
  1185.      #  Rule specification file to tally IP packets in three groups:
  1186.      #     UA to AIT, UA to elsewhere, AIT to elsewhere
  1187.      #
  1188.      #     -------+-------------------+-----------------+--------
  1189.      #            |                   |                 |
  1190.      #       +----+-----+        +----+-----+        +---+---+
  1191.      #       |   UA     |        |   AIT    |        | meter |
  1192.      #       +-+-+-+-+--+        +-+-+-+-+--+        +-------+
  1193.      #
  1194.        SourcePeerType & 255 = IP:      PushtoAct, ip_pkt;
  1195.        Null & 0 = 0:                   Ignore, 0;
  1196.      #
  1197.      ip_pkt:
  1198.        v1 & 0 = SourcePeerAddress:  AssignAct, Next;
  1199.        Null & 0 = 0:  Gosub, classify;
  1200.          Null & 0 = 0:  GotoAct, from_ua;    # 1 ua
  1201.          Null & 0 = 0:  GotoAct, from_ait;   # 2 ait
  1202.          Null & 0 = 0:  NoMatch, 0;          # 3 other
  1203.      #
  1204.      from_ua:
  1205.        v1 & 0 = DestPeerAddress:  AssignAct, Next;
  1206.        Null & 0 = 0:  Gosub, classify;
  1207.          Null & 0 = 0:  Ignore, 0;            # 1 ua-ua
  1208.          Null & 0 = 0:  GotoAct, ok_pkt;      # 2 ua-ait
  1209.          Null & 0 = 0:  Gotoact, ok_pkt;      # 3 ua-other
  1210.      #
  1211.      from_ait:
  1212.        v1 & 0 = DestPeerAddress:  AssignAct, Next;
  1213.        Null & 0 = 0:  Gosub, classify;
  1214.          Null & 0 = 0:  NoMatch, 0;           # 1 ait-ua
  1215.          Null & 0 = 0:  Ignore, 0;            # 2 ait-ait
  1216.          Null & 0 = 0:  GotoAct, ok_pkt;      # 3 ait-other
  1217.      #
  1218.      ok_pkt:
  1219.        Null & 0 = 0:                   Count, 0;
  1220.  
  1221.    The subroutine begins at the rule labelled classify (shown below).
  1222.    It returns to the first, second or third rule after the invoking
  1223.    Gosub rule, depending on whether the tested PeerAddress is in the UA,
  1224.    AIT, or 'other' group of networks.  In the listing below only one
  1225.    network is tested in each of the groups - it is trivial to add more
  1226.    rules (one per network) into either of the first two groups.  In this
  1227.    example the subroutine Pushes the network number from the packet into
  1228.    the tested attribute before returning.
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234. Brownlee                     Informational                     [Page 22]
  1235.  
  1236. RFC 2123                Traffic Flow Measurement              March 1997
  1237.  
  1238.  
  1239.    The first invocation of classify (above) begins at the rule labelled
  1240.    ip_pkt.  It Assigns SourcePeerAddress to V1 then executes a Gosub
  1241.    action.  Classify returns to one of the three following rules.  They
  1242.    will Goto from_ua or from_ait if the packet came from the UA or AIT
  1243.    groups, otherwise the PME will retry the match.  This means that
  1244.    matched flows will have a UA or AIT network as their source, and
  1245.    flows between other networks will be ignored.
  1246.  
  1247.    The next two invocations of 'classify' test the packet's
  1248.    DestPeerAddress.  Packets from AIT to UA are Retried, forcing them to
  1249.    be counted as AU to AIT flows.  Packets from UA to UA are ignored, as
  1250.    are packets from AIT to AIT.
  1251.  
  1252.      classify:
  1253.        v1 & 255.255.0.0 = 130.216.0.0:  GotoAct, ua;   # ua
  1254.        v1 & 255.255.0.0 = 156.62.0.0:   GotoAct, ait;  # ait
  1255.        Null & 0 = 0:                    Return, 3;     # other
  1256.      ua:
  1257.        v1 & 255.255.0.0 = 0:            PushPkttoAct, Next;
  1258.        Null & 0 = 0:                    Return, 1;
  1259.      ait:
  1260.        v1 & 255.255.0.0 = 0:            PushPkttoAct, Next;
  1261.        Null & 0 = 0:                    Return, 2;
  1262.  
  1263. 3.4 More complicated rule sets
  1264.  
  1265.    The next example demonstrates a way of grouping IP flows together
  1266.    depending on their Transport Address, i.e. their IP port number.
  1267.    Simply Pushing every flow's SourceTransAddress and DestTransAddress
  1268.    would produce a large number of flows, most of which differ only in
  1269.    one of their transport addresses (the one which is not a well-known
  1270.    port).
  1271.  
  1272.    Instead we Push the well-known port number into each flow's
  1273.    SourceTransAddress; its DestTransAddress will be zero by default.
  1274.  
  1275.      SourcePeerType & 255 = dummy:      Ignore, 0;
  1276.      SourcePeerType & 255 = IP:         Pushto, IP_pkt;
  1277.      Null & 0 = 0:   GotoAct, Next;
  1278.      SourcePeerType & 255 = 0:      PushPkttoAct, Next;
  1279.      Null & 0 = 0:  Count, 0;  # Count others by protocol type
  1280.   #
  1281.   IP_pkt:
  1282.     SourceTransType & 255 = tcp:    Pushto, tcp_udp;
  1283.     SourceTransType & 255 = udp:    Pushto, tcp_udp;
  1284.     SourceTransType & 255 = icmp:   CountPkt, 0;
  1285.     SourceTransType & 255 = ospf:   CountPkt, 0;
  1286.     Null & 0 = 0:  GotoAct, c_unknown;  #  Unknown transport type
  1287.  
  1288.  
  1289.  
  1290. Brownlee                     Informational                     [Page 23]
  1291.  
  1292. RFC 2123                Traffic Flow Measurement              March 1997
  1293.  
  1294.  
  1295.   #
  1296.   tcp_udp:
  1297.   s_domain:
  1298.     SourceTransAddress & 255.255 = domain:  PushtoAct, c_well_known;
  1299.   s_ftp:
  1300.     SourceTransAddress & 255.255 = ftp:     PushtoAct, c_well_known;
  1301.   s_imap:
  1302.     SourceTransAddress & 255.255 = 113:     PushtoAct, c_well_known;
  1303.   s_nfs
  1304.     SourceTransAddress & 255.255 = 2049:    PushtoAct, c_well_known;
  1305.   s_pop:
  1306.     SourceTransAddress & 255.255 = 110:     PushtoAct, c_well_known;
  1307.   s_smtp:
  1308.     SourceTransAddress & 255.255 = smtp:    PushtoAct, c_well_known;
  1309.   s_telnet:
  1310.     SourceTransAddress & 255.255 = telnet:  PushtoAct, c_well_known;
  1311.   s_www:
  1312.     SourceTransAddress & 255.255 = www:     PushtoAct, c_well_known;
  1313.   s_xwin
  1314.     SourceTransAddress & 255.255 = 6000:    PushtoAct, c_well_known;
  1315.   #
  1316.     DestTransAddress & 255.255 = domain:    GotoAct, s_domain;
  1317.     DestTransAddress & 255.255 = ftp:       GotoAct, s_ftp;
  1318.     DestTransAddress & 255.255 = 113:       GotoAct, s_imap;
  1319.     DestTransAddress & 255.255 = 2049:      GotoAct, s_nfs;
  1320.     DestTransAddress & 255.255 = 110:       GotoAct, s_pop;
  1321.     DestTransAddress & 255.255 = smtp:      GotoAct, s_smtp;
  1322.     DestTransAddress & 255.255 = telnet:    GotoAct, s_telnet;
  1323.     DestTransAddress & 255.255 = www:       GotoAct, s_www;
  1324.     DestTransAddress & 255.255 = 6000:      GotoAct, s_xwin;
  1325.   #
  1326.     Null & 0 = 0:  GotoAct, c_unknown;  #  'Unusual' port
  1327.   #
  1328.   c_unknown:
  1329.     SourceTransType    & 255 = 0:     PushPkttoAct, Next;
  1330.     DestTransType      & 255 = 0:     PushPkttoAct, Next;
  1331.     SourceTransAddress & 255.255 = 0: PushPkttoAct, Next;
  1332.     DestTransAddress   & 255.255 = 0: CountPkt, 0;
  1333.   #
  1334.   c_well_known:
  1335.     Null & 0 = 0:  Count, 0
  1336.   #
  1337.  
  1338.    The first few rules ignore dummy packets, select IP packets for
  1339.    further processing, and count packets for other protocols in a single
  1340.    flow for each PeerType.  TCP and UDP packets cause the PME to Push
  1341.    their TransType and Goto tcp_udp.  ICMP and OSPF packets are counted
  1342.    in flows which have only their TransType Pushed.
  1343.  
  1344.  
  1345.  
  1346. Brownlee                     Informational                     [Page 24]
  1347.  
  1348. RFC 2123                Traffic Flow Measurement              March 1997
  1349.  
  1350.  
  1351.    At tcp_udp the packets' SourceTransAddress is tested to see whether
  1352.    it is included in a set of 'interesting' port numbers.  If it is, the
  1353.    port number is pushed from the rule into the SourceTransAddress
  1354.    attribute, and the packet is counted at c_well_known.  (NeMaC accepts
  1355.    Pushto as a synonym for PushRuleto).
  1356.  
  1357.    This testing is repeated for the packet's DestTransAddress; if one of
  1358.    these tests succeeds the PME Goes to the corresponding rule above and
  1359.    Pushes the port number into the flow's SourceTransAddress.  If these
  1360.    tests fail the packet is counted at c_unknown, where all the flow's
  1361.    Trans attributes are pushed.  For production use more well-known
  1362.    ports would need to be included in the tests above - c_unknown is
  1363.    intended only for little-used exception flows!
  1364.  
  1365.    Note that these rules only Push a value into a flow's
  1366.    SourceTransAddress, and they don't contain any NoMatch actions.  They
  1367.    therefore don't specify a packet's direction, and they could be used
  1368.    in other rule sets to group together flows for well-known ports.
  1369.  
  1370.    The last example (below) meters flows from a remote router, and
  1371.    demonstrates another approach to grouping well-known ports.
  1372.  
  1373.     SourceAdjacentAddress & FF-FF-FF-FF-FF-FF =
  1374.         00-60-3E-10-E0-A1:  Goto, gateway;  # tmkr2 router
  1375.     DestAdjacentAddress & FF-FF-FF-FF-FF-FF = 00-60-3E-10-E0-A1:
  1376.         Goto, gateway;  # Source is tmkr2
  1377.     Null & 0 = 0:  Ignore, 0;
  1378.   #
  1379.   gateway:
  1380.     SourcePeerType & 255 = IP:  GotoAct, IP_pkt;
  1381.     Null & 0 = 0:  GotoAct, Next;
  1382.     SourcePeerType & 255 = 0:  CountPkt, 0;
  1383.   #
  1384.   IP_pkt:
  1385.     SourceTransType & 255 = tcp:    PushRuleto, tcp_udp;
  1386.     SourceTransType & 255 = udp:    PushRuleto, tcp_udp;
  1387.     Null & 0 = 0:  GotoAct, not_wkp;  #  Unknown transport type
  1388.   #
  1389.   tcp_udp:
  1390.     SourceTransAddress & FC-00 = 0:  GotoAct, well_known_port;
  1391.     DestTransAddress & FC-00 = 0:  NoMatch, 0;
  1392.     Null & 0 = 0:  GotoAct, not_wkp;
  1393.   #
  1394.   not_wkp:
  1395.     DestTransAddress   & 255.255       = 0: PushPkttoAct, Next;
  1396.   well_known_port:
  1397.     SourcePeerType     & 255           = 0: PushPkttoAct, Next;
  1398.     DestPeerType       & 255           = 0: PushPkttoAct, Next;
  1399.  
  1400.  
  1401.  
  1402. Brownlee                     Informational                     [Page 25]
  1403.  
  1404. RFC 2123                Traffic Flow Measurement              March 1997
  1405.  
  1406.  
  1407.     SourcePeerAddress  & 255.255.255.0 = 0: PushPkttoAct, Next;
  1408.     DestPeerAddress    & 255.255.255.0 = 0: PushPkttoAct, Next;
  1409.     SourceTransType    & 255           = 0: PushPkttoAct, Next;
  1410.     DestTransType      & 255           = 0: PushPkttoAct, Next;
  1411.     SourceTransAddress & 255.255       = 0: CountPkt, 0;
  1412.  
  1413.    The first group of rules test incoming packet's AdjacentAddresses to
  1414.    see whether they belong to a flow with an end point at the specified
  1415.    router.  Any which don't are ignored.  Non-IP packets are counted in
  1416.    flows which only have their PeerType Pushed; these will produce one
  1417.    flow for each non-IP protocol.  IP packets with TransTypes other than
  1418.    UDP and TCP are counted at not_wkp, where all their address
  1419.    attributes are pushed.
  1420.  
  1421.    The high-order six bits of SourceTransAddress for UDP and TCP packets
  1422.    are compared with zero.  If this succeeds their source port number is
  1423.    less than 1024, so they are from a well-known port.  The port number
  1424.    is pushed from the rule into the flow's SourceTransAddress attribute,
  1425.    and the packet is counted at well_known_port.  If the test fails, it
  1426.    is repeated on the packet's DestTransAddress.  If the destination is
  1427.    a well-known port the match is Retried, and will succeed with the
  1428.    well-known port as the flow's source.
  1429.  
  1430.    If later analysis were to show that a high proportion of the observed
  1431.    flows were from non-well-known ports, further pairs of rules could be
  1432.    added to perform a test in each direction for other heavily-used
  1433.    ports.
  1434.  
  1435. 4 Flow data files
  1436.  
  1437.    Although the Architecture document [1] specifies - in great detail -
  1438.    how the Traffic Flow Meter works, and how a meter reader should
  1439.    collect flow data from a meter, it does not say anything about how
  1440.    the collected data should be stored.  NeMaC uses a simple, self-
  1441.    documenting file format, which has proved to be very effective in
  1442.    use.
  1443.  
  1444.    There are two kinds of records in a flow data file:  flow records and
  1445.    information records.  Each flow record is simply a sequence of
  1446.    attribute values with separators (these can be specified in a NeMaC
  1447.    rule file) or spaces between them, terminated by a newline.
  1448.  
  1449.    Information records all start with a cross-hatch.  The file's first
  1450.    record begins with ##, and identifies the file as being a file of
  1451.    data from NeTraMet.  It records NeMaC's parameters and the time this
  1452.    collection was started.  The file's second record begins with
  1453.    #Format: and is a copy of the Format statement used by NeMaC to
  1454.    collect the data.
  1455.  
  1456.  
  1457.  
  1458. Brownlee                     Informational                     [Page 26]
  1459.  
  1460. RFC 2123                Traffic Flow Measurement              March 1997
  1461.  
  1462.  
  1463.    The rest of the file is a sequence of collected data sets.  Each of
  1464.    these starts with a #Time:  record, giving the time-of-day the
  1465.    collection was started, the meter name, and the range of meter times
  1466.    this collection represents.  These from and to times are meter
  1467.    UpTimes, i.e. they are times in hundredths of seconds since the meter
  1468.    commenced operation.  Most analysis applications have simply used the
  1469.    collection start times (which are ASCII time-of-day values), but the
  1470.    from and to times could be used to convert Uptime values to time-of-
  1471.    day.  The flow records which comprise a data set follow the #Time
  1472.    record.
  1473.  
  1474. 4.1 Sample flow data file
  1475.  
  1476.    A sample flow data file appears below.  Most of the flow records have
  1477.    been deleted, but lines of dots show where they were.
  1478.  
  1479.   ##NeTraMet v3.2.  -c300 -r rules.lan -e rules.default
  1480.     test_meter -i eth0  4000 flows  starting at 12:31:27 Wed 1 Feb 95
  1481.   #Format: flowruleset flowindex firsttime  sourcepeertype
  1482.     sourcepeeraddress destpeeraddress  topdus frompdus
  1483.     tooctets fromoctets
  1484.   #Time: 12:31:27 Wed  1 Feb 95 130.216.14.251 Flows
  1485.     from 1 to 3642
  1486.   1 2 13  5 31.32.0.0 33.34.0.0  1138 0  121824 0
  1487.   1 3 13  2 11.12.0.0 13.14.0.0  4215 0  689711 0
  1488.   1 4 13  7 41.42.0.0 43.34.0.0  1432 0  411712 0
  1489.   1 5 13  6 21.22.0.0 23.24.0.0  8243 0  4338744 0
  1490.   3 6 3560  2 130.216.14.0 130.216.3.0  0 10  0 1053
  1491.   3 7 3560  2 130.216.14.0 130.216.76.0  59 65  4286 3796
  1492.   3 8 3560  7 0.0.255.0 1.144.200.0  0 4  0 222
  1493.   3 9 3560  2 130.216.14.0 130.216.14.0  118 1  32060 60
  1494.   3 10 3560  6 130.216.0.28 130.216.0.192  782 1  344620 66
  1495.   3 11 3560  7 0.0.255.0 0.128.113.0  0 1  0 73
  1496.   3 12 3560  5 59.3.13.0 4.1.152.0  1 1  60 60
  1497.   3 13 3560  7 0.128.94.0 0.129.27.0  2 2  120 158
  1498.   3 14 3560  5 59.3.40.0 4.1.153.0  2 2  120 120
  1499.   3 15 3560  5 0.0.0.0 4.1.153.0  0 1  0 60
  1500.   3 16 3560  5 4.1.152.0 59.2.189.0  2 2  120 120
  1501.        .  .  .  .  .  .  .  .  .
  1502.   3 42 3560  7 0.128.42.0 0.129.34.0  0 1  0 60
  1503.   3 43 3560  7 0.128.42.0 0.128.43.0  0 1  0 60
  1504.   3 44 3560  7 0.128.42.0 0.128.41.0  0 1  0 60
  1505.   3 45 3560  7 0.128.42.0 0.129.2.0  0 1  0 60
  1506.   3 46 3560  5 4.1.152.0 59.2.208.0  2 2  120 120
  1507.   3 47 3560  5 59.3.46.0 4.1.150.0  2 2  120 120
  1508.   3 48 3560  5 4.1.152.0 59.2.198.0  2 2  120 120
  1509.   3 49 3560  5 0.0.0.0 59.2.120.0  0 1  0 60
  1510.   3 50 3664  5 4.1.152.0 59.2.214.0  0 1  0 60
  1511.  
  1512.  
  1513.  
  1514. Brownlee                     Informational                     [Page 27]
  1515.  
  1516. RFC 2123                Traffic Flow Measurement              March 1997
  1517.  
  1518.  
  1519.   3 51 3664  5 0.0.0.0 4.2.142.0  0 1  0 60
  1520.   3 52 3664  5 4.1.153.0 59.3.45.0  4 4  240 240
  1521.   #Time: 12:36:25 Wed  1 Feb 95 130.216.14.251 Flows
  1522.     from 3641 to 33420
  1523.   3 6 3560  2 130.216.14.0 130.216.3.0  0 21  0 2378
  1524.   3 7 3560  2 130.216.14.0 130.216.76.0  9586 7148  1111118 565274
  1525.   3 8 3560  7 0.0.255.0 1.144.200.0  0 26  0 1983
  1526.   3 9 3560  2 130.216.14.0 130.216.14.0  10596 1  2792846 60
  1527.   3 10 3560  6 130.216.0.28 130.216.0.192  16589 1  7878902 66
  1528.   3 11 3560  7 0.0.255.0 0.128.113.0  0 87  0 16848
  1529.   3 12 3560  5 59.3.13.0 4.1.152.0  20 20  1200 1200
  1530.   3 13 3560  7 0.128.94.0 0.129.27.0  15 14  900 1144
  1531.   3 14 3560  5 59.3.40.0 4.1.153.0  38 38  2280 2280
  1532.   3 15 3560  5 0.0.0.0 4.1.153.0  0 30  0 1800
  1533.   3 16 3560  5 4.1.152.0 59.2.189.0  20 20  1200 1200
  1534.   3 17 3560  5 0.0.0.0 59.2.141.0  0 11  0 660
  1535.       .  .  .  .  .  .  .  .  .
  1536.   3 476 26162  7 0.129.113.0 0.128.37.0  0 1  0 82
  1537.   3 477 27628  7 0.128.41.0 0.128.46.0  1 1  543 543
  1538.   3 478 27732  7 0.128.211.0 0.128.46.0  1 1  543 543
  1539.   3 479 31048  7 0.128.47.0 2.38.221.0  1 1  60 60
  1540.   3 480 32717  2 202.14.100.0 130.216.76.0  0 4  0 240
  1541.   3 481 32717  2 130.216.76.0 130.216.3.0  0 232  0 16240
  1542.   #Time: 12:41:25 Wed  1 Feb 95 130.216.14.251 Flows
  1543.     from 33419 to 63384
  1544.   3 6 3560  2 130.216.14.0 130.216.3.0  51 180  3079 138195
  1545.   3 7 3560  2 130.216.14.0 130.216.76.0  21842 18428  2467693 1356570
  1546.   3 8 3560  7 0.0.255.0 1.144.200.0  0 30  0 2282
  1547.   3 9 3560  2 130.216.14.0 130.216.14.0  24980 1  5051834 60
  1548.   3 10 3560  6 130.216.0.28 130.216.0.192  20087 1  8800070 66
  1549.   3 11 3560  7 0.0.255.0 0.128.113.0  0 164  0 32608
  1550.   3 12 3560  5 59.3.13.0 4.1.152.0  41 41  2460 2460
  1551.   3 14 3560  5 59.3.40.0 4.1.153.0  82 82  4920 4920
  1552.   3 15 3560  5 0.0.0.0 4.1.153.0  0 60  0 3600
  1553.       .  .  .  .  .  .  .  .  .
  1554.  
  1555. 4.2 Flow data file features
  1556.  
  1557.    Several features of NeMaC's flow data files (as indicated above) are
  1558.    worthy of note:
  1559.  
  1560.   - Collection times overlap slightly between samples.  This allows for
  1561.     flows which were created after the collection started, and makes
  1562.     sure that flows are not missed from a collection.
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570. Brownlee                     Informational                     [Page 28]
  1571.  
  1572. RFC 2123                Traffic Flow Measurement              March 1997
  1573.  
  1574.  
  1575.   - The rule set may change during a run.  The above shows flows from
  1576.     rule set 1 - the default set - in the first collection, followed by
  1577.     the first flows created by rule set 3 (which has just been
  1578.     downloaded by NeMaC).
  1579.  
  1580.   - FlowIndexes may be reused by the meter once their flows have been
  1581.     recovered by the garbage collector.  The combination of
  1582.     FlowRuleSet, FlowIndex and StartTime are needed to identify a flow
  1583.     uniquely.
  1584.  
  1585.   - Packet and Byte counters are 32-bit unsigned integers, and are
  1586.     never reset by the meter.  Computing the counts occurring within a
  1587.     collection interval requires taking the difference between the
  1588.     collected count and its value when the flow was last collected.
  1589.     Note that counter wrap-around can be allowed for by simply
  1590.     performing an unsigned subtraction and ignoring any carry.
  1591.  
  1592.   - In the sample flow data file above I have used double spaces as
  1593.     separators between the flow identifiers, peer addresses, pdu counts
  1594.     and packet counts.
  1595.  
  1596.   - The format of addresses in the flow data file depends on the type
  1597.     of address.  NeMaC always displays Adjacent addresses as six hex
  1598.     bytes separated by hyphens, and Transport addresses as (16-bit)
  1599.     integers.  The format of a Peer address depends on its PeerType,
  1600.     e.g. dotted decimal for IP. To facilitate this NeMaC needs to know
  1601.     the PeerType for each flow; the user must request NeMaC to collect
  1602.     it.
  1603.  
  1604. 4.3 Terminating and restarting meter reading
  1605.  
  1606.    When NeMaC first starts collecting from a meter, it reads the flow
  1607.    data for all active flows.  This provides a starting point for
  1608.    analysis applications to compute the counts between successive
  1609.    collections.
  1610.  
  1611.    From time to time the user needs to terminate a flow data file and
  1612.    begin a new one.  For example, a user might need to generate a
  1613.    separate file for each day of metering.  NeMaC provides for this by
  1614.    closing the file after each collection, then opening it and appending
  1615.    the data from the next collection.  To terminate a file the user
  1616.    simply renames it.  The Unix system will effect the name change
  1617.    either immediately (if the file was closed) or as soon as the current
  1618.    collection is complete (and the file is closed).
  1619.  
  1620.    When NeMaC begins its next collection it observes that the file has
  1621.    disappeared, so it creates a new one and writes the # header records
  1622.    before writing the collected data.
  1623.  
  1624.  
  1625.  
  1626. Brownlee                     Informational                     [Page 29]
  1627.  
  1628. RFC 2123                Traffic Flow Measurement              March 1997
  1629.  
  1630.  
  1631.    There is one aspect of the above which requires some care on the
  1632.    user's part.  The last data set in a file is not duplicated as the
  1633.    first data set of the next file.  In other words, analysis
  1634.    applications must either look ahead at the first data set of the next
  1635.    file, or begin by reading the last data set of the previous file.  If
  1636.    they fail to do this they will loose one collection's worth of flow
  1637.    data at each change of file.
  1638.  
  1639. 5 Analysis applications
  1640.  
  1641.    Most analysis applications will be unique, taking data produced by a
  1642.    locally-developed rule set and producing reports to satisfy specific
  1643.    local requirements.  The NeTraMet distribution files include three
  1644.    applications which are of general use, as follows:
  1645.  
  1646.   - fd_filter computes data rates, i.e. the differences between
  1647.     successive data sets in a flow data file.  It also allows the user
  1648.     to assign a 'tag' number to each flow; these are 'computed'
  1649.     attributes similar to FlowClass and FlowKind - the only difference
  1650.     is that they are computed from the collected data sets.
  1651.  
  1652.   - fd_extract takes 'tagged' files from fd_filter and produces simple
  1653.     'column list' files for use by other programs.  One common use for
  1654.     fd_extract is to produce time-series data files which can be plotted
  1655.     by utilities like GNUPlot.
  1656.  
  1657.   - nm_rc is a 'remote console' for a NeTraMet meter.  It is a slightly
  1658.     simplified version of NeMaC combined with fd_filter.  It can be used
  1659.     to monitor any meter, and will display (as lines of text
  1660.     characters) information about the n busiest flows observed during
  1661.     each collection interval.
  1662.  
  1663.   - nifty is a traffic flow analyser, which (like nm_rc) displays data
  1664.     from a NeTraMet meter.  nifty is an X/Motif application, which
  1665.     produces displays like 'Packet rate (pps) vs Flow lifetime
  1666.     (minutes),' so as to highlight those flows which are 'interesting.'
  1667.  
  1668.    These applications are useful in themselves, and they provide a good
  1669.    starting point for users who wish to write their own analysis
  1670.    applications.
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682. Brownlee                     Informational                     [Page 30]
  1683.  
  1684. RFC 2123                Traffic Flow Measurement              March 1997
  1685.  
  1686.  
  1687. 6 Using NeTraMet in a measurement system
  1688.  
  1689.    This section gives a brief summary of the steps involved in setting
  1690.    up a traffic measurement system using NeTraMet.  These are:
  1691.  
  1692.   - Decide what is to be measured.  One good way to approach this is to
  1693.     specify exactly which flows are to be measured, and what reports
  1694.     will be required.  Specifying the flows should make it obvious
  1695.     where meters will have to be placed so that the flows can be
  1696.     observed, whether PCs will be adequate for the task, etc..
  1697.  
  1698.   - Install meters.  As well as actually placing the meter hosts this
  1699.     includes making sure that they are configured correctly, with
  1700.     appropriate IP addresses, SNMP community strings, etc.
  1701.  
  1702.   - Develop the rule set (and a standby rule set).  The degree of
  1703.     difficulty here depends on how much is known in advance about the
  1704.     traffic.  One possible approach is to start with the meter default
  1705.     rule set and measure how much traffic there is for each PeerType.
  1706.     (This is a good way to verify that NeTraMet and NeMaC are working
  1707.     properly).  You can now add rules so as to increase the granularity
  1708.     of the flows; this will of course increase the number of flows to
  1709.     be collected, and force the meter's garbage collector to work
  1710.     harder.  Another approach is to try a rule set with very fine
  1711.     granularity (i.e. one which Pushes all the address attributes),
  1712.     then observing how many flows are collected every few minutes.
  1713.  
  1714.   - Develop a strategy for controlling meter reader.  This means
  1715.     setting the meter's maximum number of flows, the collection
  1716.     interval, how breaks between flow data files will be handled, how
  1717.     often NeMaC should check that the meter is running, etc.
  1718.  
  1719.   - Develop application(s) to process the collected flow data and
  1720.     produce the required files and reports.
  1721.  
  1722.   - Test run.  Monitor the system, then refine the rule sets and meter
  1723.     reading strategy until the overall system performance is
  1724.     satisfactory.
  1725.  
  1726.    This process can take quite a long time, but the overall result is
  1727.    well worth the effort.
  1728.  
  1729. 6.1 Examples of NeTraMet in production use
  1730.  
  1731.    At the University of Auckland we run two sets of meters.  One of
  1732.    these measures the traffic entering and leaving our University
  1733.    network, and generates usage reports for all our Internet users.
  1734.    This has been in production since early 1994.
  1735.  
  1736.  
  1737.  
  1738. Brownlee                     Informational                     [Page 31]
  1739.  
  1740. RFC 2123                Traffic Flow Measurement              March 1997
  1741.  
  1742.  
  1743.    The other set consists of meters which are distributed at
  1744.    Universities throughout New Zealand.  They provide continuous traffic
  1745.    flow measurements at five-minute intervals for all the links making
  1746.    up the Universities' network (Kawaihiko); this system has been in
  1747.    production since January 1996, and has already proved very useful in
  1748.    planning the network's development.
  1749.  
  1750.    The Kawaihiko Network provides IP connectivity for the New Zealand
  1751.    Universities.  They are linked via a Frame Relay cloud, using a
  1752.    partial mesh of permanent virtual circuits.  There is a NeTraMet
  1753.    meter at each site, metering inward and outward traffic.  All the
  1754.    meters are managed from Auckland, and they all run copies of the same
  1755.    rule set.
  1756.  
  1757.    The rule set has about 650 rules, most of which are in a single
  1758.    subroutine which classifies PeerAddresses into three categories -
  1759.    'Kawaihiko network,' 'other New Zealand network' and 'non-New Zealand
  1760.    network.'  Inside New Zealand IP addresses lie within six CIDR
  1761.    blocks, and there are about four hundred older networks which have
  1762.    addresses outside those blocks.  The rules are arranged in groups by
  1763.    subnet size, i.e. all the /24 networks are tested first, then the /23
  1764.    networks, etc, finishing with the /16 networks.  This means that
  1765.    although there are about 600 networks, any PeerAddress can be
  1766.    classified with only nine tests.
  1767.  
  1768.    The Kawaihiko rule set classifies flows, using computed attributes to
  1769.    indicate the network 'kind' (Kawaihiko / New Zealand / international)
  1770.    for each flow's SourcePeerAddress and DestPeerAddress, and to
  1771.    indicate whether the flow is a 'network news' flow or not.
  1772.  
  1773.    Flow data is collected from all of the meters every five minutes, and
  1774.    is used to produce weekly reports, as follows:
  1775.  
  1776.   - Traffic Plots.  Plots of the 5-minute traffic rates for each site,
  1777.     showing international traffic in and out, news traffic in and out,
  1778.     and total traffic in and out of the site.
  1779.  
  1780.   - Traffic Matrices.  Two of these are produced, one for news traffic,
  1781.     the other for total traffic.  They show the traffic rates from
  1782.     every site (including 'other New Zealand' and 'international') to
  1783.     every other site.  The mean, third quartile and maximum are printed
  1784.     for every cell in the matrices.
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794. Brownlee                     Informational                     [Page 32]
  1795.  
  1796. RFC 2123                Traffic Flow Measurement              March 1997
  1797.  
  1798.  
  1799. 7 Acknowledgments
  1800.  
  1801.    This memo documents the implementation work on traffic flow
  1802.    measurement here at the University of Auckland.  Many of my
  1803.    University colleagues have contributed significantly to this work,
  1804.    especially Russell Fulton (who developed the rules sets, Perl scripts
  1805.    and Cron jobs which produce our traffic usage reports automatically
  1806.    week after week) and John White (for his patient help in documenting
  1807.    the project).
  1808.  
  1809. 8 References
  1810.  
  1811.     [1] Brownlee, N., Mills, C., and G. Ruth, "Traffic Flow
  1812.     Measurement: Architecture", RFC 2063, The University of Auckland,
  1813.     Bolt Beranek and Newman Inc., GTE Laboratories, Inc, January 1997.
  1814.  
  1815.     [2] Brownlee, N., "Traffic Flow Measurement:  Meter MIB",
  1816.     RFC 2064, The University of Auckland, January 1997.
  1817.  
  1818.     [3] CRYNWR Packer Drivers distribution site:
  1819.     http://www.crynwr.com/
  1820.  
  1821.     [4] Case J., McCloghrie K., Rose M., and Waldbusser S.,
  1822.     "Structure of Management Information for version 2 of the
  1823.     Simple Network Managemenet Protocol", RFC 1902, SNMP Research
  1824.     Inc., Hughes LAN Systems, Dover Beach Consulting, Carnegie
  1825.     Mellon University, April 1993.
  1826.  
  1827.     [5] IBM Corporation, "IBM PC Technical Reference Manual," 1984.
  1828.  
  1829.     [6] Waterloo TCP distribution site:
  1830.     http://mvmpc9.ciw.uni-karlsruhe.de:80/d:/public/tcp_ip/wattcp
  1831.  
  1832.     [7] CMU SNMP distribution site:
  1833.     ftp://lancaster.andrew.cmu.edu/pub/snmp-dist
  1834.  
  1835.     [8] libpcap distribution site:
  1836.     ftp://ftp.ee.lbl.gov/libpcap-*.tar.gz
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850. Brownlee                     Informational                     [Page 33]
  1851.  
  1852. RFC 2123                Traffic Flow Measurement              March 1997
  1853.  
  1854.  
  1855. 9 Security Considerations
  1856.  
  1857.    Security issues are not discussed in detail in this document.  The
  1858.    meter's management and collection protocols are responsible for
  1859.    providing sufficient data integrity and confidentiality.
  1860.  
  1861. 10 Author's Address
  1862.  
  1863.    Nevil Brownlee
  1864.    The University of Auckland
  1865.  
  1866.    Phone: +64 9 373 7599 x8941
  1867.    Email: n.brownlee@auckland.ac.nz
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906. Brownlee                     Informational                     [Page 34]
  1907.  
  1908.