test-protocol Plugin Spec
Overview
test-protocol is a plugin to test the following categories of APIs:
Net Processor API
Protocol API
Logging API
It basically simulates the the server side in a client/server connection. We'll have a separate synthetic client which keeps sending requests to this server. The server receives the request, sends back the response to the client and logs the client's requests in a log file. During the process, it calls all the APIs listed above with different parameters and in different scenarios.
Feature Description
Client Description
Before the plugin features are described, we need to first specify what requests the synthetic client sends to the plugin and what responses it expects to get back from the plugin.
The client sends requests in the following format:
pattern number
pattern
is a character string. number
is the number
of times the pattern
is being repeated.
The plugin gets pattern
and number
, repeats the pattern
in number
of times and sends it back to the client.
The usage of the client is:
java ClientTest -P <proxy> -p <proxy_port> -a <pattern> -n <number> -l <loop>
<loop>
is the number of requests the client sends to the
proxy. If it's -1
, the client will send requests in an infinite
loop.
Plugin Description
The plugin will be configured in plugin.config as:
test_protocol.so <accept_port>
accept_port
is the port that the plugin listens and accepts the
client's requests.
The following are the steps the plugin performs:
1) Create a text log object
Create a text log object with INKTextLogObjectCreate, set its header with INKTextLogObjectHeaderSet, and set the rolling parameters with INKTextLogObjectRollingEnabledSet, INKTextLogObjectRollingIntervalSecSet and INKTextLogObjectRollingOffsetHrSet.
2) Listen for and accept client requests
It calls INKNetAccept to listen on a specific port and accepts the requests from the client. The handler function of the callback continuation for INKNetAccept checks if the connection has been established successfully (by checking if it's called back with the event INK_EVENT_NET_ACCEPT). The caller also checks the return value of INKNetAccept to see if it makes sense.
3) Get the remote IP and port of the net vconnection.
The callback function of INKNetAccept calls INKNetVConnRemoteIPGet and INKNetVConnRemotePortGet to get the remote IP and port of the net vconnection. It then schedules another continuation call to handle the following work.
4) Read the client request content into a buffer
Call INKVConnRead to read the client's request into an IOBuffer. Set the watermark of the client request IOBuffer with INKIOBufferWaterMarkSet. The IOBuffer calls back the continuation only when watermark amount of data is available. Use INKIOBufferWaterMarkGet to check if the watermark is set correctly.
5) Parse the client's request
Get the pattern and number from the client request and check if they exceed the length limits.
6) Log the client's request
Write the client request into the log with INKTextLogObjectWrite, flush the log with INKTextLogObjectFlush and destroy the log object with INKTextLogObjectDestroy.
7) Create the response being sent to the client
Repeat the pattern for number of times and saves it in a buffer. This will be the response sent back to the client.
8) Send the response to the client
Create an IOBuffer for client response with INKIOBufferSizedCreate, write the response to the IOBuffer with INKIOBufferWrite, then call INKVConnWrite to send the response to the client.
Plugin Structure