Cache Session Management Protocol (CAPR)

The Cache Session Management Protocol (CAPR) is an open protocol developed by Rai for defining the semantics of interaction between publishers and subscribers in a market data system. In the OSI model CAPR resides at the Session layer (level 5), above the transport layer and below the presentation layer.

The session management protocol provides the methods by which data is distributed to interested parties. This layer can be described as the protocol of the control plane for a virtual network of streams addressed by subject, much like IGMP is the protocol used by the Layer 3 control plane in switches for a virtual network of IPv4 addresses.

The function objectives for CAPR are:

  1. Impose no constraints with regard to physical topology or transport used.
  2. Define a format for addressing messages by subject.
  3. Define a basic framing of a message that allows applications to easily pack and unpack payloads; this allows the attachment of market data encoded in any number of existing wire formats.
  4. Define the message flow for

    1. Starting, Canceling, Synchronizing, and Recovery of Subscriptions
    2. Publishing Initial Values, Updates, Snapshots, and Drops
    3. Provide for Dictionaries
    4. QOS status notifications
  5. Define the meta-data messages which allow for monitoring of key system health metrics of

    1. Messaging Counters
    2. Messaging Latency
    3. Subscription Activity
    4. Publishing Activity

CAPR uses subjects (topics) for defining interest in a type of data. A subject is a hierarchical directory which is segmented much like a file system directory. The nature of this structure makes it easier to use wild-cards to select several streams of interest and perform complex actions on them. Most notably, wild-carding a stream of subjects is useful as a mechanism for routing and otherwise separating the domains of related streams for appropriate distribution. Like an IPv4 address, subjects often use the dotted notation when represented as strings, segmenting components with a dot.

On the wire, the binary encoding of a subject string is

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    N SEGS     |   SEG1 LEN    |  SEG1 string, null terminated |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    SEG2 LEN   |   SEG2 string, null terminated                |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The subject string "This.subject" would be represented in binary form as

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     0x02      |     0x05      |      'T'      |      'h'      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      'i'      |      's'      |      \0       |     0x08      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      's'      |      'u'      |      'b'      |      'j'      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      'e'      |      'c'      |      't'      |      \0       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

A CAPR session layer message contains the data needed for session semantics between publishers and subscribers on the market data network:

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 0 0 1 0 1 0|    MSG CODE   |    MSG ENC    |I|S|P|R|N|x|0 1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        DATA LENGTH                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        SUBJECT HASH                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    SUBJECT   ...                              .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.    [ INBOX ADDRESS ] -- optional 12 byte reply addr:    I set .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.    [ SESSION ID ]    -- optional 8 byte session id:     S set .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.    [ PUBTIME ]       -- optional 8 byte pub time:       P set .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.    [ ROUTETIME ]     -- optional 8 byte route time:     R set .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.    [ COUNTER ]       -- optional 4 byte update counter: N set .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.    [ MESSAGE DATA ]  -- the rest up to DATA LENGTH + 12 bytes .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+