FIX: each test case should end with the server and client termination

Terminate the server and the client both in the case of a test file
failure and test file success

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Don't treat FIX test case scripts as binary

Signed-off-by: Pekka Enberg <penberg@kernel.org>
FIX: a new test case is added to the FIX testing suite

If an incoming message has MsgSeqNum higher than expected,
one should repond with Reset Request message. The added
2b_MsgSeqNumHigherThanExpected test file checks this logic.

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/test-fix-client: Remove 'protocol info' structure

The program only supports the FIX protocol so drop the unnecessary
'protocol info' indirection.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/test-fix-client: Fix program name in usage

Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/test-fix-client: Make SenderCompID and TargetCompID configurable

Signed-off-by: Pekka Enberg <penberg@kernel.org>
Update FIX known issues list

Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/test.py: Fix extra newlines for "-v" option

Signed-off-by: Pekka Enberg <penberg@kernel.org>
FIX: New Order Single and Execution Report support is added

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
fix: Rename fix_message_has_tag() to fix_get_field()

The helper function looks up a 'struct fix_field' from a 'struct
fix_message' so rename it appriopriately.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
fix: Introduce 'enum fix_msg_type' and use it

Introduce a libtrading internal 'fix_msg_type' enumeration and convert
the MsgType(35) string value to it in the parse_msg_type() function.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
fix: Use FIX_MSG_TYPE prefix for 'fix_msg_type' enumerations

Signed-off-by: Pekka Enberg <penberg@kernel.org>
fix: Fix formatting in lib/proto/fix_message.c

Signed-off-by: Pekka Enberg <penberg@kernel.org>
fix: Fix formatting in include/libtrading/proto/fix_message.h

Signed-off-by: Pekka Enberg <penberg@kernel.org>
FIX: test-fix-client cleanup

* Session level messages are to be handled by fix_session_process()
* If an incoming message has sequence number less than expected we
  have to check the PossDupFlag

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
FIX: test-fix-client a new testing mode is added

A small performance test is added to the test-fix-client.
When this test is invoked a client starts sending a number
of New Single Orders to the server. Once an Execution Report
arrives, a client calculates the round-trip latency.

The first timestamp is made just before the client sends
a New Single Order, the second timestamp is made just after
an Execution Report arrives. So, the round-trip latency is
the difference between the second and first timestamps
expressed in microseconds. From what has been said, it
is clear that this latency is made of four main parts:
encoding a New Order Single by the client, decoding a
FIX message by the server, encoding an Execution Report
by the server and decoding a FIX message by the client.

A new command line option is added to the test-fix-client.
So, if one would like to run a test she just need to specify
the -t option with the number of Execution Reports sent e.g
test-fix-client -t 10000 [hostname] [port] [version] [sender] [target]
would trigger a test with 10000 Orders sent.

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/test-fix-client: Use clock_gettime(CLOCK_MONOTONIC)

Use monotonic clock with nanosecond precision for FIX engine latency
measurements.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
fix: Fix buffer_find() for empty buffers

Marat explains:

  Consider the case: the buffer contains just

  8=FIX4.4\x01

  Then in first_three_fields() we successfully pass the function
  parse_begin_string() and reach the buffer's end.  Then the function
  parse_body_length() starts parsing the field which makes buffer_find()
  perform a "conditional jump or move depends on uninitialised value(s)".

  As far as I can understand the circumstances are rather rare
  to reproduce easily but not rare enough to be caught by Valgrind.

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
FIX: Introduce an explicit state of the message being parsed

When the FIX message that is stored in a buffer is being unparse
we should distinguish between two major cases: the message is
garbled and we should skip it when parsing the buffer's content
and the message is just partially delivered and we should wait
until it will be delivered completely.

Until now there was no reliable way to distinguish between these
two cases. The only thing we knew for sure is that if buffer's
size was greater than the maximum possible FIX message size we
shouldn't wait more data to come once we found out that some
part of the buffer contains a garbled field.

This patch suggests that we should explicitly track the FIX
message state while it is being parsed, namely every function
examining the incoming buffer's data explicitly returns the
value associated with the FIX message state.

For example, if the buffer's data are '8=FIX4.4\x019=-1\x01' we
know for sure that body length is corrupted because of the negative
value so we could skip this part of the message. But if the buffer's
data are '8=FIX4.4\x019=1' we should wait the next set of bytes
because the only thing we know is that body length begins with '1'.

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
FAST: Introduction

Two minor changes were made:
* Remove buffer_put(). This functions  is a part of transferring patch.
Not needed in decoding FAST messages.
* Remove FAST_FIELD_SET_STATE macro. This macro remains from previous
versions. At the moment fast messages do not have their states (undefined,
assigned or empty) because is_none field is enough to handle different states.

This patch implements a generic function to decode the incoming data.
In order to support FAST to the full extent a few additional steps
have to be done. At this moment these steps include the following
points:

* Reset support
* Encoding support
* Sequences / Groups support
* Decimal and Unicode support
* Delta operation for strings

Moreover, it would be nice to have a pair of test client and server
as the other part of libtrading have.

This patch is a skeleton and once it is admitted the other steps
should be based on it.

Signed-off-by: Marat Stanichenko <mstanichenko@gmail.com>
[ penberg@kernel.org: cleanups ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>