[ Click here to show document header. ]
LicenseThis document is distributed under the terms of the GNU Free Documentation License, version 1.2. ScopeThis document is a specification of the EPICS Channel Access (CA) protocol. Structure of messages exchanged between communicating nodes is defined, as well as semantics of the exchange. The documentation is focused on version 4.11 of the CA protocol, which comes with EPICS 3.14. AudienceThe audience of this document are all developers who need to work with CA at the network layer, without the use of higher-level application programming interfaces. Table of Contents
[ Click here to show Table of Contents. ]
1. Introduction1.1. Implementation Requirements1.2. Basic Concepts1.2.1. Process Variables1.2.2. Channels1.2.3. Monitors1.2.4. Channel Access Client Library1.2.5. Repeater1.2.6. Server Beacons1.2.7. Virtual Circuit1.2.8. Message Buffering1.2.9. Version compatibility1.2.10. Exceptions1.3. Overall Operation2. Data Types3. Messages3.1. Message Structure3.1.1. Header3.1.2. Payload3.2. Message Identifiers3.2.1. CID - Client ID3.2.2. SID - Server ID3.2.3. Subscription ID3.2.4. IOID4. Commands (TCP and UDP)4.0. CA_PROTO_VERSION4.0.1. Request4.0.2. Response4.6. CA_PROTO_SEARCH4.6.1. Request4.6.2. Response4.14. CA_PROTO_NOT_FOUND4.14.1. Response4.23. CA_PROTO_ECHO4.23.1. Request4.23.2. Response5. Commands (UDP)5.13. CA_PROTO_RSRV_IS_UP5.13.1. Response5.17. CA_REPEATER_CONFIRM5.17.1. Response5.24. CA_REPEATER_REGISTER5.24.1. Request6. Commands (TCP)6.1. CA_PROTO_EVENT_ADD6.1.1. Request6.1.2. Response6.2. CA_PROTO_EVENT_CANCEL6.2.1. Request6.2.2. Response6.3. CA_PROTO_READ6.3.1. Request6.3.2. Response6.4. CA_PROTO_WRITE6.4.1. Request6.5. CA_PROTO_SNAPSHOT6.7. CA_PROTO_BUILD6.8. CA_PROTO_EVENTS_OFF6.8.1. Request6.9. CA_PROTO_EVENTS_ON6.9.1. Request6.10. CA_PROTO_READ_SYNC6.10.1. Request6.11. CA_PROTO_ERROR6.11.1. Response6.12. CA_PROTO_CLEAR_CHANNEL6.12.1. Request6.12.2. Response6.15. CA_PROTO_READ_NOTIFY6.15.1. Request6.15.2. Response6.16. CA_PROTO_READ_BUILD6.16.1. Request6.18. CA_PROTO_CREATE_CHAN6.18.1. Request6.18.2. Response6.19. CA_PROTO_WRITE_NOTIFY6.19.1. Request6.19.2. Response6.20. CA_PROTO_CLIENT_NAME6.20.1. Request6.21. CA_PROTO_HOST_NAME6.21.1. Request6.22. CA_PROTO_ACCESS_RIGHTS6.22.1. Response6.25. CA_PROTO_SIGNAL6.26. CA_PROTO_CREATE_CH_FAIL6.26.1. Response6.27. CA_PROTO_SERVER_DISCONN6.27.1. Response7. Payload Data Types7.7. DBR_STS_STRING7.8. DBR_STS_SHORT7.9. DBR_STS_FLOAT7.10. DBR_STS_ENUM7.11. DBR_STS_CHAR7.12. DBR_STS_LONG7.13. DBR_STS_DOUBLE7.14. DBR_TIME_STRING7.15. DBR_TIME_SHORT7.16. DBR_TIME_FLOAT7.17. DBR_TIME_ENUM7.18. DBR_TIME_CHAR7.19. DBR_TIME_LONG7.20. DBR_TIME_DOUBLE7.21. DBR_GR_STRING7.22. DBR_GR_SHORT7.22. DBR_GR_INT7.23. DBR_GR_FLOAT7.24. DBR_GR_ENUM7.25. DBR_GR_CHAR7.26. DBR_GR_LONG7.27. DBR_GR_DOUBLE7.28. DBR_CTRL_STRING7.29. DBR_CTRL_SHORT7.29. DBR_CTRL_INT7.30. DBR_CTRL_FLOAT7.31. DBR_CTRL_ENUM7.32. DBR_CTRL_CHAR7.33. DBR_CTRL_LONG7.34. DBR_CTRL_DOUBLE8. Constants8.1. Port numbers8.2. Representation of constants8.3. Monitor Mask8.4. Search Reply Flag8.5. Access Rights9. Example message10. Virtual Circuit Operation10.1. Establishing virtual circuit10.2. Basic mode of operation10.3. Detecting virtual circuit unresponsiveness10.4. Channel life-cycle10.5. Connecting a Channel10.6. Read and Write operations10.7. Subscriptions and Monitors10.8. Connection events10.9. Closing the channel11. Repeater Operation11.1. Role11.2. Startup11.3. Client detection11.4. Operation11.5. Shutdown12. Server Beacons13. Return Codes14. Example conversationGlossary of TermsReferencesDocument HistoryHow to Read This DocumentThis document's meta-information (authors, revision history, table of contents, ...) can be found above. What follows below is the body of the document. The body is composed of several sections, which may be further composed of subsections. Typographical styles are used to denote entities of different kinds. For a full list of entities and their respective typographic conventions, please refer to the Styles section of the XML Documentation document. 1. Introduction1.1. Implementation RequirementsThe key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", "OPTIONAL" in this document are to be interpreted as described in RFC 2119: Key words for use in RFCs to Indicate Requirement Levels[3]. An implementation is not compliant if it fails to satisfy one or more of the MUST or REQUIRED level requirements for the protocols it implements. An implementation that satisfies all the MUST or REQUIRED level and all the SHOULD level requirements for its protocols is said to be "unconditionally compliant"; one that satisfies all the MUST level requirements but not all the SHOULD level requirements for its protocols is said to be "conditionally compliant." This document is based on the original CA protocol implementation that accompanies EPICS. Wherever the MAY, OPTIONAL or RECOMMENDED is specified, it implies that experience has shown such behaviour to improve either performance, portability or memory consumption. A protocol implementation that is not unconditionally compliant MUST NOT be used in any production environment or used with EPICS databases controling physical devices. 1.2. Basic Concepts1.2.1. Process VariablesA Process Variable (PV) is representation of a single value within an EPICS host. 1.2.2. ChannelsA channel is created whenever a PV is connected using CA. From implementation point of view, a channel is a connection, established over virtual circuit, between server and client through which a single PV is accessed. Both the client and the server will provide a way of uniquely identifying channels. These identifiers are explained in section Message Identifiers (3.2.). 1.2.3. MonitorsA monitor is created on a channel as a means of registering for asynchronous change notifications. CA protocol defines the subscription mechanism through which clients register for notifications. These changes will then be provided through monitor object or callback, depending on implementation and environment. Monitors may be filtered to receive only a subset of events, such as value or alarm changes. Several different monitors may be created for each channel. 1.2.4. Channel Access Client LibraryA client library implements channel access protocol and exposes it through a programmer-friendly API. How the protocol and its mechanisms are implemented in the library depends on the programming language and no specific requirements are made with respect to this. 1.2.5. RepeaterRepeater is a standalone process that allows several clients on one machine to share a predefined UDP port for recieving broadcast messages. Broadcast messages are sent without prior knowledge of which port the CA clients and hosts are listening at, so predefined port numbers are used. Since most network stack implementations do not allow multiple clients to listen on the same port, repeater is installed to listen on a single port, used for broadcast notifications. Repeater will fan-out unmodified incoming datagram messages to all the clients on the same host, that have previously registered with the repeater. Typically, a client library will attempt to register with the repeater during startup. If repeater cannot be found or is not available, the library will attempt to spawn a new repeater process. Repeater and client communicate using a minimal set of messages over UDP. 1.2.6. Server BeaconsServer beacons are simple protocol messages that allow servers to broadcast their availability. These messages are sent out periodically to announce their presence. Additionally, these beacons are used to restore virtual circuits that have lost connections. 1.2.7. Virtual CircuitChannel Access protocol is designed to minimize resources used on both client and server. Virtual circuits minimize number of TCP connections used between clients and servers. Each client will have exactly one active and open TCP connection to an individual server, regardless of how many channels it accesses over it. This helps to ensure that servers do not get overwhelmed by too many connections. The life-cycle of a virtual circuit is defined in section Virtual Circuit Operation (10.). 1.2.8. Message BufferingWhen sending packets over network, channel access allows huge savings to be made by grouping individual messages in a single TCP packet. This is performed by maintaining per virtual circuit buffers that collect all outgoing messages. These buffers are flushed upon application's explicit request. This mechanism is independent of the TCP/IP stack, which maintains its own send queue and defines a maximum frame size. Messages sent over virtual circuit may be larger than this and will not always be aligned on frame boundary. Implementation should also be aware that messages received may not yet be available entirely or will be split over several TCP frames. 1.2.9. Version compatibilityCertain aspects of Channel Access protocol have changed between releases. In this document, Channel Access versions are identified using CA_VXYY, where X represents single-digit major version number and YY represents a single- or double-digit minor version number. Stating that a feature is available in CA_VXYY implies that any client supporting version XYY must support the feature. Implementation must be backward compatible with all versions up to and including its declared supported minor version number. Example: CA_V43, denotes version 4.3 (major version 4, minor version 3). Currently, all protocol definitions are assumed to have major version 4. Minor version ranges from 1 through 11. 1.2.10. ExceptionsThis document uses the concept of exceptions to refer to the mechanism of reporting errors that occur during command request execution. An exception defines reporting of error condition on the server. This can occur either due to client problem or due to some unexpected condition on the server (such as running out of resources). Exceptions are reported either within the command's response or using a specialized message. Actual form and method (response or asynhronously received message) depends on circumstances where the exception occurs. Individual commands and messages determine which method is used. 1.3. Overall OperationThis section is intended as a quick overview of channel access functionality and behaviour. For more information, please refer to Channel Access Reference Manual[1]. The goal of channel access (CA) is to provide remote access to records and fields managed by IOC, including search and discovery of hosts and minimal flow contol. Protocol itself is designed to provide minimal overhead and maximize network throughput for transfer of large number of small data packets. Additionaly, implementation overhead of the protocol can be kept very small, to allow operation with limited resources. All commands and events in CA are encapsulated in predefined messages, which can be sent in one of three forms:
Communication between server and client is performed by sending command messages over UDP and TCP. Client will use UDP to search for hosts and PVs, server will use them to notify its startup and shutdown. Once client requests a specific PV (by specifying its name), UDP message will be broadcast to either a subnet or a list of predefined addresses, and the server which hosts requested PV will respond. Data exchange between client and server is performed over TCP. After locating the PV, the client will establish a TCP connection to the server. If more that one PV is found to be on the same server, client will use existing TCP connection. Reusable TCP connection between client and server is called Virtual circuit. Once a virtual circuit is established or already available, channels can be created to PVs. Let's assume the following setup of PVs and hosts:
A typical scenario would be similar to this:
2. Data TypesThis section defines all primitive data types employed by the CA, as well as their C/C++ equivalents. These data types are referred to in the subsequent sections.
All values are transmitted over the network in big-endian (network) order. For example: UINT32 3145 (0x00000C49) would be sent over the network represented as 00 00 0C 49. 3. Messages3.1. Message StructureAll channel access messages are composed of a header, followed by the payload. Header is always present. Its structure is fixed, and contains predefined fields. At the very least, this will be command ID and payload size. Other header fields may carry command-specific meaning. If a field is not used within a certain message, its value must be 0 (0x00). Payload is a sequence of bytes, which are command and version dependent. Implementation is required to provide proper payload with respect to individual command specification. Total size of an individual message is limited. With CA versions older than CA_V49, the maximum message size is limited to 16384 (0x4000) bytes. Out of these, header has a fixed size of 16 (0x10) bytes, with the payload having a maximum size of 16368 (0x3ff0) bytes. Versions CA_V49 and higher may use the extended message form, which allows for larger payloads. The extended message form is indicated by the header fields Payload Size and Data Count being set to 0xffff and 0, respectively. Real payload size and data count are then given as UINT32 type values immediately following the header. Maximum message size is limited by 32-bit unsigned integer representation, 4294967295 (0xffffffff). Maximum payload size is limited to 4294967255 (0xffffffe7). Extended message form should only be used if payload size actualy exceeds the pre-CA_V49 message size limit of 16368 bytes. 3.1.1. HeaderNames of header fields are based on their most common use. Certain messages will use individual fields for purposes other than those described here. These variations are documented for each message individually. All of values in header are unsigned integers. The common header present in all messages is structured as follows:
The extended message header (CA_V49 and newer) has the following structure:
3.1.2. PayloadThe structure of the payload depends on the type of the message. The size of the payload matches the Payload Size header field.
3.2. Message IdentifiersSome fields in messages serve as identifiers, which must be properly handled by the implementation. These fields serve as identification tokens in asynchronous communication and must be unique within the context of the client library. Recommended scheme for allocating these values is to create them sequentially starting at 0. All IDs are represented with UINT32. Overflow must be anticipated! Although it is unlikely that an application will need more than 232 different channel IDs, such an overflow can occur with the IOID identifier (see below). 3.2.1. CID - Client IDCID identifies individual channel within client library context. When a message requires the CID, this value must be passed. CID for a given channel may not change within the lifetime of the channel. Recommended way of allocating CIDs is sequential 0-based indexing. First client library channel reference that is created has value of 0, second 1, etc. Duplicate CIDs within a single active instance of client library are not allowed. CID value is passed to the server when the channel is actually connected. Overflow should be potentially handled, since an application with expected long lifetime and frequent channel allocation and destruction might increase the index frequently. The best way to handle it is to ignore the problem until the first overflow. When that occurs, old CIDs should be no longer relevant, and CID value can be restarted from 0, but excluding any already used values. 3.2.2. SID - Server IDPerforms the same function as CID, but is provided by the server when the channel is connected. SID of channel will never change, unless the channel represented by particular SID is removed from the server during runtime. In that case, the channel will be no longer available. To handle overflows, the same method could be used as for the Client Channel ID. 3.2.3. Subscription IDWhen a subscription is created on a channel (monitor), a unique subscription ID must be provided. Client library will use this ID to identify different subscriptions on the same channel. This value will allow the client library to dispatch monitors appropriately. Any subscription ID is only valid during the subscription's lifespan. After that, IDs may be reused. 3.2.4. IOIDUnique ID is given to all read and write messages sent by the client library. ID passed with the request will be returned in the matching response. Properly handling the wrapping of identifiers is vital to IOID, since an individual ID is used each time a request is made. 4. Commands (TCP and UDP)The following commands are sent as either UDP datagrams or TCP messages. Some of the messages are also used within the context of a Virtual Circuit. 4.0. CA_PROTO_VERSIONCommand: CA_PROTO_VERSION ID: 0 (0x00) Description: Exchanges client and server protocol versions and desired circuit priority. This is the first message sent when a new TCP (Virtual Circuit) connection is established. Must be sent before any other exchange between client, server and repeater. The communication is not strictly request response, but will be perceived as such by the implementation. When a new TCP connection is established by the client, CA_PROTO_VERSION is sent. Likewise, the server will accept the connection and send the response form back. Sent over UDP or TCP. 4.0.1. RequestHeader
Compatibility
Comments
4.0.2. ResponseHeader
Compatibility
4.6. CA_PROTO_SEARCHCommand: CA_PROTO_SEARCH ID: 6 (0x06) Description: Searches for a given channel name. Sent over UDP or TCP. 4.6.1. RequestHeader
Payload
Comments
4.6.2. ResponseHeader
Payload
Comments
4.14. CA_PROTO_NOT_FOUNDCommand: CA_PROTO_NOT_FOUND ID: 14 (0x0E) Description: Indicates that a channel with requested name does not exist. Sent in response to CA_PROTO_SEARCH (4.6.), but only when its DO_REPLY flag was set. Sent over UDP. 4.14.1. ResponseHeader
Comments
4.23. CA_PROTO_ECHOCommand: CA_PROTO_ECHO ID: 23 (0x17) Description: Connection verify used by CA_V43. Sent over TCP. 4.23.1. RequestHeader
4.23.2. ResponseHeader
5. Commands (UDP)The following commands are sent as UDP datagrams. 5.13. CA_PROTO_RSRV_IS_UPCommand: CA_PROTO_RSRV_IS_UP ID: 13 (0x0D) Description: Beacon sent by a server when it becomes available. Beacons are also sent out periodically to announce the server is still alive. Another function of beacons is to allow detection of changes in network topology. Sent over UDP. 5.13.1. ResponseHeader
Comments
5.17. CA_REPEATER_CONFIRMCommand: CA_REPEATER_CONFIRM ID: 17 (0x11) Description: Confirms successful client registration with repeater. Sent over UDP. 5.17.1. ResponseHeader
Comments
5.24. CA_REPEATER_REGISTERCommand: CA_REPEATER_REGISTER ID: 24 (0x18) Description: Requests registration with the repeater. Repeater will confirm successful registration using CA_REPEATER_CONFIRM. Sent over TCP. 5.24.1. RequestHeader
6. Commands (TCP)The following commands are used within the context of Virtual Circuit and are sent using TCP. 6.1. CA_PROTO_EVENT_ADDCommand: CA_PROTO_EVENT_ADD ID: 1 (0x01) Description: Creates a subscription on a channel, allowing the client to be notified of changes in value. A request will produce at least one response. Sent over TCP. 6.1.1. RequestHeader
Payload
Comments
6.1.2. ResponseHeader
Payload
Comments
6.2. CA_PROTO_EVENT_CANCELCommand: CA_PROTO_EVENT_CANCEL ID: 2 (0x02) Description: Clears event subscription. This message will stop event updates for specified channel. Sent over TCP. 6.2.1. RequestHeader
Comments
6.2.2. ResponseHeader
Comments
6.3. CA_PROTO_READCommand: CA_PROTO_READ ID: 3 (0x03) Description: Read value of a channel. Sent over TCP. Deprecated since protocol version 3.13. 6.3.1. RequestHeader
Comments
6.3.2. ResponseHeader
Payload
6.4. CA_PROTO_WRITECommand: CA_PROTO_WRITE ID: 4 (0x04) Description: Writes new channel value. Sent over TCP. 6.4.1. RequestHeader
Payload
Comments
6.5. CA_PROTO_SNAPSHOTCommand: CA_PROTO_SNAPSHOT ID: 5 (0x05) Description: Obsolete. 6.7. CA_PROTO_BUILDCommand: CA_PROTO_BUILD ID: 7 (0x07) Description: Obsolete. 6.8. CA_PROTO_EVENTS_OFFCommand: CA_PROTO_EVENTS_OFF ID: 8 (0x08) Description: Disables a server from sending any subscription updates over this virtual circuit. Sent over TCP. This mechanism is used by clients with slow CPU to prevent congestion when they are unable to handle all updates recived. Effective automated handling of flow control is beyond the scope of this document. 6.8.1. RequestHeader
Comments
6.9. CA_PROTO_EVENTS_ONCommand: CA_PROTO_EVENTS_ON ID: 9 (0x09) Description: Enables the server to resume sending subscription updates for this virtual circuit. Sent over TCP. This mechanism is used by clients with slow CPU to prevent congestion when they are unable to handle all updates recived. Effective automated handling of flow control is beyond the scope of this document. 6.9.1. RequestHeader
Comments
6.10. CA_PROTO_READ_SYNCCommand: CA_PROTO_READ_SYNC ID: 10 (0x0A) Description: Deprecated since protocol version 3.13. 6.10.1. RequestHeader
6.11. CA_PROTO_ERRORCommand: CA_PROTO_ERROR ID: 11 (0x0B) Description: Sends error message and code. This message is only sent from server to client in response to any request that fails and does not include error code in response. This applies to all asynchronous commands. Error message will contain a copy of original request and textual description of the error. Sent over UDP. 6.11.1. ResponseHeader
Payload
Comments
6.12. CA_PROTO_CLEAR_CHANNELCommand: CA_PROTO_CLEAR_CHANNEL ID: 12 (0x0C) Description: Clears a channel. This command will cause server to release the associated channel resources and no longer accept any requests for this SID/CID. 6.12.1. RequestHeader
6.12.2. ResponseHeader
Comments
6.15. CA_PROTO_READ_NOTIFYCommand: CA_PROTO_READ_NOTIFY ID: 15 (0x0F) Description: Read value of a channel. Sent over TCP. 6.15.1. RequestHeader
Comments
6.15.2. ResponseHeader
Payload
6.16. CA_PROTO_READ_BUILDCommand: CA_PROTO_READ_BUILD ID: 16 (0x10) Description: Obsolete 6.16.1. Request6.18. CA_PROTO_CREATE_CHANCommand: CA_PROTO_CREATE_CHAN ID: 18 (0x12) Description: Requests creation of channel. Server will allocate required resources and return initialized SID. Sent over TCP. 6.18.1. RequestHeader
Payload
Comments
6.18.2. ResponseHeader
Comments
6.19. CA_PROTO_WRITE_NOTIFYCommand: CA_PROTO_WRITE_NOTIFY ID: 19 (0x13) Description: Writes new channel value. Sent over TCP. 6.19.1. RequestHeader
Payload
6.19.2. ResponseHeader
6.20. CA_PROTO_CLIENT_NAMECommand: CA_PROTO_CLIENT_NAME ID: 20 (0x14) Description: Sends local username to virtual circuit peer. This name identifies the user and affects access rights. 6.20.1. RequestHeader
Payload
Comments
6.21. CA_PROTO_HOST_NAMECommand: CA_PROTO_HOST_NAME ID: 21 (0x15) Description: Sends local host name to virtual circuit peer. This name will affect access rights. Sent over TCP. 6.21.1. RequestHeader
Payload
Comments
6.22. CA_PROTO_ACCESS_RIGHTSCommand: CA_PROTO_ACCESS_RIGHTS ID: 22 (0x16) Description: Notifies of access rights for a channel. This value is determined based on host and client name and may change during runtime. Client cannot change access rights nor can it explicitly query its value, so last received value must be stored. 6.22.1. ResponseHeader
Comments
6.25. CA_PROTO_SIGNALCommand: CA_PROTO_SIGNAL ID: 25 (0x19) Description: Obsolete. 6.26. CA_PROTO_CREATE_CH_FAILCommand: CA_PROTO_CREATE_CH_FAIL ID: 26 (0x1A) Description: Reports that channel creation failed. This response is sent to when channel creation in CA_PROTO_CREATE_CHAN fails. 6.26.1. ResponseHeader
Comments
6.27. CA_PROTO_SERVER_DISCONNCommand: CA_PROTO_SERVER_DISCONN ID: 27 (0x1B) Description: Notifies the client that server has disconnected the channel. This may be since the channel has been destroyed on server. Sent over TCP. 6.27.1. ResponseHeader
7. Payload Data TypesChannel access defines special structures to transferring data. Main reason is efficiency, since in many cases more than one value can be transferred. These types are organized in typed hierarchies with loose inheritance. There are seven basic data types: DBR_STRING, DBR_SHORT, DBR_INT, DBR_FLOAT, DBR_ENUM, DBR_CHAR, DBR_LONG and DBR_DOUBLE. Each of these types can be represented as an array, if the corresponding field in header indicates that. Additional to basic data types, structured types allow access to more than one value within the same record. These structures are status (STS), time stamp (TIME), graphic (GR) and control (CTRL). All these structures contain value as the last field. Status structure adds alarm severity. Time stamp structures extends the status structure by adding time stamp of the value. Graphic extends status structure by providing alarm limits, units and precision. Control structure extends graphic by adding control limits. Following is the list of all structures as transmitted over network. 7.7. DBR_STS_STRINGType: DBR_STS_STRING ID: 7 (0x07) Description: DBR_STS structure for string type. 7.8. DBR_STS_SHORTType: DBR_STS_SHORT ID: 8 (0x08) Description: DBR_STS structure for UINT16 type. May be referred to as DBR_STS_INT. 7.9. DBR_STS_FLOATType: DBR_STS_FLOAT ID: 9 (0x09) Description: DBR_STS structure for FLOAT type. 7.10. DBR_STS_ENUMType: DBR_STS_ENUM ID: 10 (0x0A) Description: DBR_STS structure for ENUM type. 7.11. DBR_STS_CHARType: DBR_STS_CHAR ID: 11 (0x0B) Description: DBR_STS structure for CHAR type. 7.12. DBR_STS_LONGType: DBR_STS_LONG ID: 12 (0x0C) Description: DBR_STS structure for LONG type. 7.13. DBR_STS_DOUBLEType: DBR_STS_DOUBLE ID: 13 (0x0D) Description: DBR_STS structure for LONG type. 7.14. DBR_TIME_STRINGType: DBR_TIME_STRING ID: 14 (0x0E) Description: DBR_TIME structure for string type. 7.15. DBR_TIME_SHORTType: DBR_TIME_SHORT ID: 15 (0x0F) Description: DBR_TIME structure for UINT16 type. May be referred to as DBR_TIME_INT. 7.16. DBR_TIME_FLOATType: DBR_TIME_FLOAT ID: 16 (0x10) Description: DBR_TIME structure for FLOAT type. 7.17. DBR_TIME_ENUMType: DBR_TIME_ENUM ID: 17 (0x11) Description: DBR_TIME structure for ENUM type. 7.18. DBR_TIME_CHARType: DBR_TIME_CHAR ID: 18 (0x12) Description: DBR_TIME structure for CHAR type. 7.19. DBR_TIME_LONGType: DBR_TIME_LONG ID: 19 (0x13) Description: DBR_TIME structure for LONG type. 7.20. DBR_TIME_DOUBLEType: DBR_TIME_DOUBLE ID: 20 (0x14) Description: DBR_TIME structure for DOUBLE type. 7.21. DBR_GR_STRINGType: DBR_GR_STRING ID: 21 (0x15) Description: DBR_GR structure for string type. 7.22. DBR_GR_SHORTType: DBR_GR_SHORT ID: 22 (0x16) Description: DBR_GR structure for short type. 7.22. DBR_GR_INTType: DBR_GR_INT ID: 22 (0x16) Description: DBR_GR structure for int type. 7.23. DBR_GR_FLOATType: DBR_GR_FLOAT ID: 23 (0x17) Description: DBR_GR structure for float type. 7.24. DBR_GR_ENUMType: DBR_GR_ENUM ID: 24 (0x18) Description: DBR_GR structure for ENUM type. 7.25. DBR_GR_CHARType: DBR_GR_CHAR ID: 25 (0x19) Description: DBR_GR structure for char type (UINT8 representation). 7.26. DBR_GR_LONGType: DBR_GR_LONG ID: 26 (0x1A) Description: DBR_GR structure for long type (INT32 representation). 7.27. DBR_GR_DOUBLEType: DBR_GR_DOUBLE ID: 27 (0x1B) Description: DBR_GR structure for double type. 7.28. DBR_CTRL_STRINGType: DBR_CTRL_STRING ID: 28 (0x1C) Description: DBR_CTRL structure for string type. 7.29. DBR_CTRL_SHORTType: DBR_CTRL_SHORT ID: 29 (0x1D) Description: DBR_CTRL structure for short type. 7.29. DBR_CTRL_INTType: DBR_CTRL_INT ID: 29 (0x1D) Description: DBR_CTRL structure for INT16 type. 7.30. DBR_CTRL_FLOATType: DBR_CTRL_FLOAT ID: 30 (0x1E) Description: DBR_CTRL structure for float type. 7.31. DBR_CTRL_ENUMType: DBR_CTRL_ENUM ID: 31 (0x1F) Description: DBR_CTRL structure for ENUM type. 7.32. DBR_CTRL_CHARType: DBR_CTRL_CHAR ID: 32 (0x20) Description: DBR_CTRL structure for char type (UINT8 representation). 7.33. DBR_CTRL_LONGType: DBR_CTRL_LONG ID: 33 (0x21) Description: DBR_CTRL structure for INT32 type. 7.34. DBR_CTRL_DOUBLEType: DBR_CTRL_DOUBLE ID: 34 (0x22) Description: DBR_CTRL structure for DOUBLE type. 8. Constants8.1. Port numbersAlthough there is no requirement as to which port numbers are used by either servers or clients, there are some standard values which must be used as defaults, unless overriden by application. Port numbers are dependant on protocol versions and are calculated using the folowing definitions: CA_PORT_BASE = 5056 CA_SERVER_PORT = CA_PORT_BASE + MAJOR_PROTOCOL_VERSION * 2 CA_REPEATER_PORT = CA_PORT_BASE + MAJOR_PROTOCOL_VERSION * 2 + 1 Based on protocol version described in this document (4.11), port numbers used are CA_SERVER_PORT = 5064 and CA_REPEATER_PORT = 5065. Since registration of port numbers with IANA and in the interest of compatibility, the version numbers are unlikely to change. Therefore, the port numbers described here (5064 and 5065) may be considered final. 8.2. Representation of constantsThis section lists various constants, their types and values used by protocol. Some constants can be combined using logical OR operation. Example: Monitor mask of DBE_VALUE and DBE_ALARM are combined using (DBE_VALUE or DBE_ALARM) resulting in (1 or 4 == 5). To query the whether certain value is present in such combined value, and operation is used. Example: to query whether DBE_ALARM of monitor mask is set, (DBE_VALUE and MASK > 0) will return 0 if DBE_VALUE is not present, otherwise DBE_ALARM is present. 8.3. Monitor MaskIndicates which changes to the value should be reported back to client library. Different values can be combined using logical OR operation. Type: not defined, depends on the field it is in (usually UINT16)
8.4. Search Reply FlagIndicates whether server should reply to failed search messages. If a server does not know about channel name, it has the option of replying to request or ignoring it. Usually, servers contacted through address list will receive request for reply. Type: not defined, depends on the field it is in (usually UINT16).
8.5. Access RightsDefines access rights for a given channel. Accss rights are defined as logicaly ORred value of allowed access. Type: not defined, depends on the field it is in (usually UINT16).
As a reference, the following values are valid.
9. Example messageThis example shows construction of messages. For details of individual structures, see message and data type reference (CA_PROTO_READ_NOTIFY and DBR_GR_INT16). A client will send CA_PROTO_READ_NOTIFY message with the following contents.
The messsage would be represented as follows:
Server would respond with success and return requested value with individual DBR_GR_INT16 fields having the following values.
10. Virtual Circuit Operation10.1. Establishing virtual circuitVirtual circuit is a TCP connection between a client and a server. Each virtual circuit has an associated priority, which can be used by server to prioritize requests depending on current load. An independent circuit for each priority level selected by the client might be used because it allows for preemptive prioritized dispatch scheduling in the server when the OS supports that, and also allows specifying the networks scheduling priority when the router and or LAN support that. Regardless of how many channels are handled by either client or server, each client-server pair will be connected with exactly one TCP connection for each priority level. This level is specified when creating a virtual circuit. When establishing a virtual circuit, a simple handshake will be performed. Client will open a TCP connection to the server. After that, it sends CA_PROTO_VERSION (4.0.), CA_PROTO_CLIENT_NAME (6.20.) and CA_PROTO_HOST_NAME (6.21.) messages. If server accepts all the supplied parameters and the client and host are permitted to connect, the server will respond with CA_PROTO_VERSION (4.0.). After that, client may start sending requests. Virtual circuit will remain active as long as there is at least one channel active. If the TCP connection is lost, all channels using this circuit must be notified. 10.2. Basic mode of operationIn most basic role, the client will send requests to the server and await one or more responses, or in some special cases, no response will be expected. For each type of request, one of three events will occur:
When a matching response is received, the operation has completed successfully. Any result returned will report any applicable return information. Client library will then notify the client about completion. If a request fails and server could handle this failure, CA_PROTO_ERROR (6.11.) response will be received or error code is received in response, depending on the request sent. This response contains original request header, error code and text description of error. Although servers are designed to always return a response, in some cases this will not occur. An unlikely case is that a server has failed or stopped responding. A more common case is broadcast search, where no replies are sent to search messages. The later case is designed to not overload the network by sending failure notifications. This however does not allow client library to determine, whether a search has failed, or the server load is simply too high and the response will arrive later. In this case, client library may assume that search yielded no results and notify on search failure. Regardless of this, should any such response arrive late, the client must be notified. In case of network failure, two situations should be anticipated. One is TCP connection loss for a virtual circuit. Virtual circuit has mechanisms for dealing with such case and should attempt to restore the connection itself. Repeater has no such mechanisms, since it depends on reliability of UDP protocol. There will be in most cases no way for repeater to determine, whether the packets sent actually arrive at destination. Repeater can however verify the clients registered with it, by attempting to bind to their port. If binding succeeds, the client no longer exists. Alternate way is using connected UDP sockets and checking ICMP destination unreachable error. 10.3. Detecting virtual circuit unresponsivenessDuring virtual circuit life-time, the circuit may become unresponsive. Since this is tightly related to network availability and server load, determining actual cause for unresponsiveness is difficult. Basic criteria on which unresponsiveness should be determined are:
Behaviour of virtual circuit implementation under such conditions is undefined. Experience has shown however, that virtual circuit should not be disconnected when it becomes unresponsive, since this negatively impacts network performance under load. 10.4. Channel life-cycleA channel discussed here is based on two levels. One is channel as seen from client application, the other is channel implementation in client library. This difference will be pointed out where applicable. When a channel is created by client application, it is initialized in NEVER_CONN state. This indicates that channel is currently being connected for the first time. If connection process fails, channel moves into FAILED state and is not usable. Connection proccess within the client library will attempt to connect the channel repeatedly. Intervals between consecutive attempts should be increased, before finally giving up and determining the channel cannot be connected and signaling FAILED state. A total number of attempts can be on the order of 100. When connection is established, the channel will signal to client with CONN_UP event and changing its state to connected. Should the virtual circuit connection be lost, CONN_DOWN event will change channel state to disconnected. Whenever virtual circuit is reconnected, the channel state is restored to connected. Note that reconnection process follows the same rules as initial process. It is also possible, that the PV will move between the servers, but client application should not be aware of such internal changes to channel. Once client application is done using the channel, it will be closed and its state moved changed to CLOSED. After that, this channel can no longer be used. Detailed description of channel operations is outlined below. 10.5. Connecting a ChannelConnection of a channel is a two phase process. First, server that hosts channel with a given name must be located. Second, client and server must both register a connection. Before connection, client library allocates CID identifier that will be used to reference new channel. Next it sends CA_PROTO_SEARCH (4.6.) with channel name request via broadcast and/or to address list. Each server that receives such message checks to see if it knows about this name. If it does, response to CA_PROTO_SEARCH (4.6.) is sent back to client. If not, the server checks if reply field of request is DO_REPLY and responds with CA_PROTO_NOT_FOUND (4.14.), otherwise does nothing. Client library may receive more than one response. In this case, first response should be used and others rejected. The cause of multiple responses is same PV hosted on multiple different hosts. Client or server has no method of knowing which PV is 'right'. Multiple responses should be reported by the client to the application or user. After extracting server address and port, client library checks to see if this server is already known and connected via virtual circuit. If not, virtual circuit is established. Any requests sent through this channel will use this circuit. For this it sends CA_PROTO_CREATE_CHAN (6.18.) request with channels CID and channel name. Server will respond with CA_PROTO_CREATE_CHAN (6.18.) response which will provide channel type, data count and server identifier SID. In case the channel could not be created, error message will be returned. Having initialized both CID and SID and registered the channel with the server, this channel is ready for use. Client library should store these values for further use. 10.6. Read and Write operationsRead and write operations require the channel to be properly initialized and connected and its virtual circuit to be active. These operations use CA_PROTO_READ_NOTIFY (6.15.) and CA_PROTO_WRITE_NOTIFY (6.19.) messages. To read a value from a channel client library will create a CA_PROTO_READ_NOTIFY (6.15.) request. This request will contain desired data type and data count parameters which may differ from channels native type as obtained during connect. Additionally, IOID is stored in request to provide unique identification. Channel that is used will be identified by SID that was obtained during channel creation. No payload is sent with request. After server processes the message reponse is either valid CA_PROTO_READ_NOTIFY (6.15.) response or CA_PROTO_ERROR (6.11.) to indicate error. In case of success, response contains same field values as request, but has additional payload. This payload is formatted as requested data type with desired number of elements. Write operation is performed identically with payload roles reversed. Here the request will contain payload with DBR formatted value to write and response will have no payload. 10.7. Subscriptions and MonitorsClient creates monitors by registering a subscription on a channel. This causes server to notify subscribers of value changes. Subscriptions are created by first allocating unique Subscription ID. This identifier is used to uniquely identify various subscriptions. Next, CA_PROTO_EVENT_ADD (6.1.) request is created using SID and Subscription ID. Data type and data count indicate desired value format in response. Additional information is provided in payload as specified in CA_PROTO_EVENT_ADD (6.1.) reference. First CA_PROTO_EVENT_ADD (6.1.) response is received immediatelly to confirm successful subscription. If error occurs, CA_PROTO_ERROR (6.11.) response is received. Responses arrive asynchronously until client cancels the subscription using CA_PROTO_EVENT_ADD (6.1.) response and payload containing DBR formatted value. If server is shutdown during this time, events will no longer arrive, but the subscription will not be cancelled. Once the server is restarted, client library will reestablish the subscription silently without notifying client application. Subscription is cancelled by sending CA_PROTO_EVENT_CANCEL (6.2.) request with relevant parameters identical to those in original CA_PROTO_EVENT_ADD (6.1.) request that created the subscription. Successful cancelation is confirmed by CA_PROTO_EVENT_ADD (6.1.) response without payload. Cancelling the subscription while the server is down should be handled by cancelling the subscription locally and not reestablishing it once the server is up again. 10.8. Connection eventsIf a virtual circuit is disconnected (server goes down or stops sending beacons), any connected channels that use this circuit should be notified. There is no direct way to reconnect the channel from client side, but this will be done by the library. Once the circuit is reestablished, client application is notified of status change for all channels. Even if a channel is reported to be disconnect as a result of virtual circuit failure, the channel is not closed. The only way a channel connection is actually closed is by explicitly closing it using CA_PROTO_CLEAR_CHANNEL (6.12.) thereby invalidating its resources. 10.9. Closing the channelChannel is closed by sending CA_PROTO_CLEAR_CHANNEL (6.12.) request. Regardless of whether response confirmes closing or reports an error, CID and SID associated with the channel are no longer valid. Any resources still available to the client application are considered invalid. A channel that was cleared may no longer be reconnected. 11. Repeater Operation11.1. RoleSimple demonstration of repeater operation. A repeater will be used both on client and server side to forward incoming UDP requests to multiple clients and/or server on same host. Each host or client will then respond on its own. Since role of the repeater is related to host, not the client, its implementation must be independant from individual client instance or process. Repeater must not stop operation until all clients depending on it registered with it have shut down. 11.2. StartupEach client must check for presence of repeater on startup, before any access to EPICS hosts is made. This check is made by attempting to bind to CA_REPEATER_PORT. If binding fails, the client may assume the repeater is already running and may attempt to register. This is done by sending CA_REPEATER_REGISTER datagram to CA_REPEATER_PORT. If repeater is already active, it will respond with CA_REPEATER_CONFIRM datagram back to client, otherwise the client can assume, the repeater is invalid, the process bound to the port is not even a repeater or that some unknown error occured. In this case, client will spawn new repeater and attempt registration again. Attempt to detect the repeater and register should be made several times with some reasonable delay to avoid any transient unresponsiveness that might occur. After the client has received registration confirmation from the repeater, it should keep listening for messages from the repeater. Any broadcasts sent by servers will be received by the repeater and forwarded to registered clients. 11.3. Client detectionThe repeater tests to see if its clients exist by periodically attempting to bind to their ports. If unsuccessful when attempting to bind to the client's port, then the repeater concludes that the client no longer exists. A technique using connected UDP sockets and ICMP destination unreachable can also used. If a client is determined to no longer be present then the repeater un-registers that client and no longer sends messages to it. 11.4. OperationEach message, the repeater receives, must be forwarded to local clients, to the address provided during registration. No assumption should be made about existence or state of clients. 11.5. ShutdownRepeater should not shutdown on its own, if it does, there should be no active clients registered with it. 12. Server BeaconsEach EPICS server will send beacons periodically to report it is still active. Beacon messages will contain server's IP and port, as well as sequential beacon ID. Beacons will be broadcast and sent to servers address list. When a server becomes active, it will immediately start sending beacons with an increasing delay. Time between beacons will start at 0.02 seconds. After each beacon is sent, this time is doubled. Maximum delay between beacons will be limited by server specified parameter, but is commonly 15 seconds. If a beacon is not received within expected time, virtual circuits connected to this server should be notified and virtual circuit must handle this situation. 13. Return CodesThis section covers return codes and exceptions that can occur during CA command processing. In general, exceptions will be used to report various events to the application. Return codes are predefined values for conditions that can occur, where as exceptions are actually reported. Apart from exceptions that occur on server or due to network transport, additional error conditions may be reported on the client side as local exceptions. Implementation is required to handle all return codes. Local exceptions should be thrown whenever implied, but only if such exception is reasonable within the scope of implementation. Certain local exceptions that deal with state dependent exception must always be provided. Naming convention: All return codes defined within the scope of CA are listed with all capitals, with underscore character (_) replacing spaces. Additionally, all exception names are prefixed with string ECA_. Return codes are represented as UINT16. First 3 least signifficant bits indicate severity, remaining 13 bits are return code ID. Return codes are communicated in the protocol by the CA_PROTO_READ_NOTIFY, CA_PROTO_WRITE_NOTIFY, monitor subscription responses, and the CA_PROTO_ERROR responses.
14. Example conversationThis is example conversation between client and server. Client first establishes TCP connection to the server and immediately requests creation of a channel. After server aknowledges channel creation, client reads the value of the channel twice. First as a single string value and second as a DBR_GR_INT16 type. After the response to both queries has been received, the channel is destroyed.
Glossary of Terms
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||