TCP

Overview

Declarations of TAPI methods for raw-TCP CSAP. More…

// typedefs

typedef uint32_t tapi_tcp_pos_t;
typedef struct tcp_message_t tcp_message_t;
typedef struct tcp4_message tcp4_message;

typedef void (*tcp_callback)(
    const tcp_message_t *pkt,
    void *userdata
    );

typedef void (*tcp4_callback)(
    const tcp4_message *pkt,
    void *userdata
    );

typedef int tapi_tcp_handler_t;

// enums

enum tapi_tcp_mode_t;
enum tapi_tcp_protocol_mode_t;

// structs

struct tapi_tcp_reset_hack_t;
struct tcp4_message;
struct tcp_message_t;

// global functions

te_errno tapi_tcp_add_csap_layer(asn_value** csap_spec, int local_port, int remote_port);
te_errno tapi_tcp_ip4_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac, const uint8_t* rem_mac, in_addr_t loc_addr, in_addr_t rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap);
te_errno tapi_tcp_ip4_csap_create(const char* ta_name, int sid, const char* ifname, in_addr_t loc_addr, in_addr_t rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap);
te_errno tapi_tcp_ip4_eth_recv_start(const char* ta_name, int sid, csap_handle_t csap, in_addr_t src_addr, in_addr_t dst_addr, int src_port, int dst_port, unsigned int timeout, unsigned int num, rcf_trrecv_mode mode);
te_errno tapi_tcp_ip4_pattern_unit(in_addr_t src_addr, in_addr_t dst_addr, int src_port, int dst_port, asn_value** result_value);
int ndn_tcp4_message_to_plain(asn_value* pkt, struct tcp4_message** tcp_msg);
tapi_tad_trrecv_cb_data* tapi_tcp_ip4_eth_trrecv_cb_data(tcp4_callback callback, void* user_data);
te_errno ndn_tcp_message_to_plain(asn_value* pkt, struct tcp_message_t** tcp_msg);
tapi_tad_trrecv_cb_data* tapi_tcp_ip_eth_trrecv_cb_data(tcp_callback callback, void* user_data);
te_errno tapi_tcp_make_msg(uint16_t src_port, uint16_t dst_port, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* msg);
te_errno tapi_tcp_pdu(int src_port, int dst_port, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pdu);
int tapi_tcp_template_gen(te_bool is_eth_pdu, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* data, size_t pld_len, asn_value** tmpl);
int tapi_tcp_template(te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* data, size_t pld_len, asn_value** tmpl);
int tapi_tcp_pattern_gen(te_bool is_eth_pdu, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pattern);
int tapi_tcp_pattern(tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pattern);
int tapi_tcp_ip_segment_pattern_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pattern);
int tapi_tcp_ip_pattern_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pattern);
int tapi_tcp_segment_pattern(tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pattern);
int tapi_tcp_ip_segment_pattern(te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pattern);
int tapi_tcp_segment_pdu(int src_port, int dst_port, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pdu);
int tapi_tcp_ip_segment_template_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, uint8_t* data, size_t pld_len, asn_value** tmpl);
int tapi_tcp_ip_template_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* data, size_t pld_len, asn_value** tmpl);
int tapi_tcp_segment_template(tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, uint8_t* data, size_t pld_len, asn_value** tmpl);
int tapi_tcp_ip_segment_template(te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, uint8_t* data, size_t pld_len, asn_value** tmpl);
te_errno tapi_tcp_create_conn(const char* agt, const struct sockaddr* local_addr, const struct sockaddr* remote_addr, const char* local_iface, const uint8_t* local_mac, const uint8_t* remote_mac, int window, tapi_tcp_handler_t* handler);
te_errno tapi_tcp_start_conn(tapi_tcp_handler_t handler, tapi_tcp_mode_t mode);
te_errno tapi_tcp_init_connection(const char* agt, tapi_tcp_mode_t mode, const struct sockaddr* local_addr, const struct sockaddr* remote_addr, const char* local_iface, const uint8_t* local_mac, const uint8_t* remote_mac, int window, tapi_tcp_handler_t* handler);
int tapi_tcp_init_connection_enc(const char* agt, tapi_tcp_mode_t mode, const struct sockaddr* local_addr, const struct sockaddr* remote_addr, const char* local_iface, const uint8_t* local_mac, const uint8_t* remote_mac, int window, te_bool enc_vlan, te_bool enc_snap, tapi_tcp_handler_t* handler);
int tapi_tcp_destroy_connection(tapi_tcp_handler_t handler);
int tapi_tcp_wait_open(tapi_tcp_handler_t handler, int timeout);
int tapi_tcp_wait_msg(tapi_tcp_handler_t handler, int timeout);
int tapi_tcp_send_fin(tapi_tcp_handler_t handler, int timeout);
int tapi_tcp_send_fin_ack(tapi_tcp_handler_t handler, int timeout);
int tapi_tcp_send_rst(tapi_tcp_handler_t handler);
int tapi_tcp_send_msg(tapi_tcp_handler_t handler, uint8_t* payload, size_t len, tapi_tcp_protocol_mode_t seq_mode, tapi_tcp_pos_t seqn, tapi_tcp_protocol_mode_t ack_mode, tapi_tcp_pos_t ackn, tapi_ip_frag_spec* frags, size_t frag_num);
int tapi_tcp_conn_template(tapi_tcp_handler_t handler, uint8_t* payload, size_t len, asn_value** tmpl);
int tapi_tcp_send_template(tapi_tcp_handler_t handler, const asn_value* template, rcf_call_mode_t blk_mode);
int tapi_tcp_recv_msg_gen(tapi_tcp_handler_t handler, int timeout, tapi_tcp_protocol_mode_t ack_mode, uint8_t* buffer, size_t* len, tapi_tcp_pos_t* seqn_got, tapi_tcp_pos_t* ackn_got, uint8_t* flags, te_bool no_unexp_seqn);
int tapi_tcp_recv_msg(tapi_tcp_handler_t handler, int timeout, tapi_tcp_protocol_mode_t ack_mode, uint8_t* buffer, size_t* len, tapi_tcp_pos_t* seqn_got, tapi_tcp_pos_t* ackn_got, uint8_t* flags);
int tapi_tcp_recv_data(tapi_tcp_handler_t handler, int time2wait, tapi_tcp_protocol_mode_t ack_mode, te_dbuf* data);
int tapi_tcp_send_ack(tapi_tcp_handler_t handler, tapi_tcp_pos_t ackn);
int tapi_tcp_ack_all(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_first_seqn_got(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_last_seqn_got(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_last_ackn_got(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_first_seqn_sent(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_last_seqn_sent(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_last_ackn_sent(tapi_tcp_handler_t handler);
size_t tapi_tcp_last_win_got(tapi_tcp_handler_t handler);
te_bool tapi_tcp_fin_got(tapi_tcp_handler_t handler);
te_bool tapi_tcp_rst_got(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_next_seqn(tapi_tcp_handler_t handler);
tapi_tcp_pos_t tapi_tcp_next_ackn(tapi_tcp_handler_t handler);
int tapi_tcp_update_sent_seq(tapi_tcp_handler_t handler, size_t new_sent_len);
int tapi_tcp_get_window(tapi_tcp_handler_t handler);
te_errno tapi_tcp_set_window(tapi_tcp_handler_t handler, int window);
int tapi_tcp_reset_hack_init(const char* ta_name, int session, const char* iface, te_bool dir_out, tapi_tcp_reset_hack_t* context);
int tapi_tcp_reset_hack_catch(const char* ta_name, int session, tapi_tcp_reset_hack_t* context);
int tapi_tcp_reset_hack_send(const char* ta_name, int session, tapi_tcp_reset_hack_t* context, size_t received, size_t sent);
int tapi_tcp_reset_hack_clear(const char* ta_name, int session, tapi_tcp_reset_hack_t* context);
te_errno tapi_tcp_ip6_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac, const uint8_t* rem_mac, const uint8_t* loc_addr, const uint8_t* rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap);
csap_handle_t tapi_tcp_conn_snd_csap(tapi_tcp_handler_t handler);
csap_handle_t tapi_tcp_conn_rcv_csap(tapi_tcp_handler_t handler);
int tapi_tcp_update_sent_ack(tapi_tcp_handler_t handler, size_t ack);
int tapi_tcp_wait_packet(tapi_tcp_handler_t handler, int timeout);
int tapi_tcp_get_packets(tapi_tcp_handler_t handler);
te_errno tapi_tcp_conn_enable_ts(tapi_tcp_handler_t handler, te_bool enable, uint32_t start_value);
te_errno tapi_tcp_conn_get_ts(tapi_tcp_handler_t handler, te_bool* enabled, te_bool* dst_enabled, uint32_t* ts_value, uint32_t* last_ts_sent, uint32_t* last_ts_got, uint32_t* ts_to_echo, uint32_t* last_ts_echo_sent, uint32_t* last_ts_echo_got);
te_errno tapi_tcp_get_ts_opt(const asn_value* val, uint32_t* ts_value, uint32_t* ts_echo);
te_errno tapi_tcp_set_ts_opt(asn_value* val, uint32_t ts_value, uint32_t ts_echo);
int tapi_tcp_compare_seqn(uint32_t seqn1, uint32_t seqn2);
te_errno tapi_tcp_ip_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac, const uint8_t* rem_mac, int ip_family, const void* loc_addr, const void* rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap);
te_errno tapi_tcp_get_hdrs_payload_len(asn_value* pkt, unsigned int* hdrs_len, unsigned int* pld_len);

// macros

#define TAPI_TCP_DEF_WINDOW
#define TAPI_TCP_ZERO_WINDOW
#define TCP_ACK_FLAG
#define TCP_CWR_FLAG
#define TCP_ECE_FLAG
#define TCP_FIN_FLAG
#define TCP_PSH_FLAG
#define TCP_RST_FLAG
#define TCP_SYN_FLAG
#define TCP_URG_FLAG

Detailed Documentation

Declarations of TAPI methods for raw-TCP CSAP.

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef uint32_t tapi_tcp_pos_t

Type for SEQ and ACK numbers (host byte order).

typedef void (*tcp_callback)(
    const tcp_message_t *pkt,
    void *userdata
    )

Callback types for receiving data in TCP connection.

Parameters:

pkt

Received TCP datagram. After return from this callback memory block under this datagram will be freed.

userdata

Parameter, provided by the caller.

Global Functions

te_errno tapi_tcp_add_csap_layer(asn_value** csap_spec, int local_port, int remote_port)

Add TCP layer in CSAP specification.

Parameters:

csap_spec

Location of CSAP specification pointer.

local_port

Default local port in network byte order or -1 to keep unspecified

remote_port

Default remote port in network byte order or -1 to keep unspecified

Status

code.

te_errno tapi_tcp_ip4_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac, const uint8_t* rem_mac, in_addr_t loc_addr, in_addr_t rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap)

Creates ‘tcp.ip4.eth’ CSAP.

Parameters:

ta_name

Test Agent name

sid

RCF SID

eth_dev

Name of Ethernet interface

receive_mode

Bitmask with receive mode, see ‘enum tad_eth_recv_mode’ in tad_common.h. Use TAD_ETH_RECV_DEF by default.

loc_mac

Local MAC address (or NULL)

rem_mac

Remote MAC address (or NULL)

loc_addr

Local IP address in network order or htonl(INADDR_ANY)

rem_addr

Remote IP address in network order or htonl(INADDR_ANY)

loc_port

Local TCP port in network byte order or -1

rem_port

Remote TCP port in network byte order or -1

tcp_csap

Location for the IPv4 CSAP handle (OUT)

Returns:

Status of the operation

te_errno tapi_tcp_ip4_csap_create(const char* ta_name, int sid, const char* ifname, in_addr_t loc_addr, in_addr_t rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap)

Creates ‘tcp.ip4’ CSAP.

Parameters:

ta_name

Test Agent name

sid

RCF SID

ifname

Interface name

loc_addr

Local IP address in network order or htonl(INADDR_ANY)

rem_addr

Remote IP address in network order or htonl(INADDR_ANY)

loc_port

Local TCP port in network byte order or -1

rem_port

Remote TCP port in network byte order or -1

tcp_csap

Location for the IPv4 CSAP handle (OUT)

Returns:

Status of the operation

te_errno tapi_tcp_ip4_eth_recv_start(const char* ta_name, int sid, csap_handle_t csap, in_addr_t src_addr, in_addr_t dst_addr, int src_port, int dst_port, unsigned int timeout, unsigned int num, rcf_trrecv_mode mode)

Start receiving of IPv4 packets ‘tcp.ip4.eth’ CSAP, non-block method.

Started receiving process may be controlled by rcf_ta_trrecv_get, rcf_ta_trrecv_wait, and rcf_ta_trrecv_stop methods.

Parameters:

ta_name

Test Agent name

sid

RCF SID

csap

Identifier of CSAP

src_addr

Source IP address in network order or htonl(INADDR_ANY)

dst_addr

Destination IP address in network order or htonl(INADDR_ANY)

src_port

Source TCP port in network byte order or -1

dst_port

Destination TCP port in network byte order or -1

timeout

Timeout of operation (in milliseconds, zero for infinitive)

num

nubmer of packets to be caugth

mode

Count received packets only or store packets to get to the test side later

Returns:

Zero on success or error code.

te_errno tapi_tcp_ip4_pattern_unit(in_addr_t src_addr, in_addr_t dst_addr, int src_port, int dst_port, asn_value** result_value)

Prepare ASN Pattern-Unit value for ‘tcp.ip4.eth’ CSAP.

Parameters:

src_addr

Source IP address in network order or htonl(INADDR_ANY)

dst_addr

Destination IP address in network order or htonl(INADDR_ANY)

src_port

Source TCP port in network byte order or -1

dst_port

Destination TCP port in network byte order or -1

result_value

Location for pointer to new ASN value

Returns:

Zero on success or error code.

int ndn_tcp4_message_to_plain(asn_value* pkt, struct tcp4_message** tcp_msg)

Convert TCP.IPv4 datagram ASN.1 value to plain C structure.

Function allocates memory under dhcp_message data structure, which should be freed with dhcpv4_message_destroy

Parameters:

pkt

ASN.1 value of type Raw-Packet.

tcp_message

converted structure (OUT).

Returns:

zero on success or error code.

tapi_tad_trrecv_cb_data* tapi_tcp_ip4_eth_trrecv_cb_data(tcp4_callback callback, void* user_data)

Prepare callback data to be passed in tapi_tad_trrecv_{wait,stop,get} to process received TCP packet.

Parameters:

callback

Callback for TCP packets handling

user_data

User-supplied data to be passed to callback

Returns:

Pointer to allocated callback data or NULL.

te_errno ndn_tcp_message_to_plain(asn_value* pkt, struct tcp_message_t** tcp_msg)

Convert TCP.IPv4 or TCP.IPv6 datagram ASN.1 value to plain C structure.

Function allocates memory for tcp payload data. It should be freed with tcp_message_t structure

Parameters:

pkt

ASN.1 value of type Raw-Packet.

tcp_msg

converted structure (OUT).

Returns:

zero on success or error code.

tapi_tad_trrecv_cb_data* tapi_tcp_ip_eth_trrecv_cb_data(tcp_callback callback, void* user_data)

Prepare callback data to be passed in tapi_tad_trrecv_{wait,stop,get} to process received TCP packet.

Parameters:

callback

Callback for TCP packets handling

user_data

User-supplied data to be passed to callback

Returns:

Pointer to allocated callback data or NULL.

te_errno tapi_tcp_make_msg(uint16_t src_port, uint16_t dst_port, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* msg)

Correct fill TCP header by specified parameter values.

Parameters:

src_port

source port in network byte order

dst_port

destination port in network byte order

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

syn_flag

syn flag

ack_flag

ack flag

msg

location where TCP header should be placed (OUT)

Returns:

Status code.

te_errno tapi_tcp_pdu(int src_port, int dst_port, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pdu)

Prepare TCP header PDU by specified parameter values.

Parameters:

src_port

source TCP port in network byte order

dst_port

destination TCP port in network byte order

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

syn_flag

syn flag

ack_flag

ack flag

pdu

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_template_gen(te_bool is_eth_pdu, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* data, size_t pld_len, asn_value** tmpl)

Prepare Traffic-Template ASN value for ‘tcp.ip(4|6).eth’ or ‘tcp.ip(4|6)’ CSAP. It is assumed that all connection parameters (src/dst MACs, IP, and ports) are already set in CSAP. If it is not, fill there parameters in obtained traffic template explicitely.

Parameters:

is_eth_pdu

if TRUE include eth header PDU

force_ip6

TRUE for IPv6 PDU FALSE for IPv4 PDU

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

syn_flag

syn flag

ack_flag

ack flag

data

pointer to data with payload or NULL

pld_len

length of payload

tmpl

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_template(te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* data, size_t pld_len, asn_value** tmpl)

The same function as tapi_tcp_template_gen() with is_eth_pdu parameter set to TRUE, so it prepares value for ‘tcp.ip(4|6).eth’ CSAP.

int tapi_tcp_pattern_gen(te_bool is_eth_pdu, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pattern)

Prepare Traffic-Pattern ASN value for ‘tcp.ip4.eth’ or ‘tcp.ip4’ CSAP. It is assumed that all connection parameters (src/dst MACs, IP, and ports) are already set in CSAP. If it is not, fill there parameters in obtained traffic template explicitely.

Parameters:

is_eth_pdu

if TRUE include eth header PDU

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

syn_flag

syn flag

ack_flag

ack flag

pattern

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_pattern(tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pattern)

The same function as tapi_tcp_template_gen() with is_eth_pdu parameter set to TRUE, so it prepares value for ‘tcp.ip4.eth’ CSAP.

int tapi_tcp_ip_segment_pattern_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pattern)

Prepare pattern for TCP segment to receive via tcp.[ip4|ip6].eth and tcp.[ip4|ip6] CSAPs

Parameters:

is_eth_layer

TRUE for tcp.[ip4|ip6].eth CSAPs FALSE for tcp.[ip4|ip6] CSAPs

force_ip6

TRUE for tcp.ip6.eth and tcp.ip6 CSAPs FALSE for tcp.ip4.eth and tcp.ip4 CSAPs

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

urg_flag

URG flag

ack_flag

ACK flag

psh_flag

PSH flag

rst_flag

RST flag

syn_flag

SYN flag

fin_flag

FIN flag

pattern

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_ip_pattern_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, asn_value** pattern)

Prepare pattern for TCP segment to receive via tcp.[ip4|ip6].eth and tcp.[ip4|ip6] CSAPs

Parameters:

is_eth_layer

TRUE for tcp.[ip4|ip6].eth CSAPs FALSE for tcp.[ip4|ip6] CSAPs

force_ip6

TRUE for tcp.ip6.eth and tcp.ip6 CSAPs FALSE for tcp.ip4.eth and tcp.ip4 CSAPs

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

syn_flag

SYN flag

ack_flag

ACK flag

pattern

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_segment_pattern(tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pattern)

The same function as tapi_tcp_segment_pattern_gen() with force_ip6 parameter set to FALSE and is_eth_pdu parameter set to TRUE to prepare pattern for ‘tcp.ip4.eth’ CSAP.

int tapi_tcp_ip_segment_pattern(te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pattern)

The same function as tapi_tcp_segment_pattern() with force_ip6 boolean parameter to create pattern for tcp.ip6.eth or tcp.ip4.eth CSAP

int tapi_tcp_segment_pdu(int src_port, int dst_port, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, asn_value** pdu)

Prepare TCP header PDU by specified parameter values. Modified version of tapi_tcp_pdu.

Parameters:

src_port

source TCP port in network byte order

dst_port

destination TCP port in network byte order

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

urg_flag

URG flag

ack_flag

ACK flag

psh_flag

PSH flag

rst_flag

RST flag

syn_flag

SYN flag

fin_flag

FIN flag

pdu

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_ip_segment_template_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, uint8_t* data, size_t pld_len, asn_value** tmpl)

Prepare template for TCP segment to send via tcp.[ip4|ip6].eth and tcp.[ip4|ip6] CSAPs

Parameters:

is_eth_layer

TRUE for tcp.[ip4|ip6].eth CSAPs FALSE for tcp.[ip4|ip6] CSAPs

force_ip6

TRUE for tcp.ip6.eth and tcp.ip6 CSAPs FALSE for tcp.ip4.eth and tcp.ip4 CSAPs

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

urg_flag

URG flag

ack_flag

ACK flag

psh_flag

PSH flag

rst_flag

RST flag

syn_flag

SYN flag

fin_flag

FIN flag

data

pointer to buffer with payload octets

pld_len

payload length

tmpl

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_ip_template_gen(te_bool is_eth_layer, te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool syn_flag, te_bool ack_flag, uint8_t* data, size_t pld_len, asn_value** tmpl)

Prepare template for TCP segment to send via tcp.[ip4|ip6].eth and tcp.[ip4|ip6] CSAPs

Parameters:

is_eth_layer

TRUE for tcp.[ip4|ip6].eth CSAPs FALSE for tcp.[ip4|ip6] CSAPs

force_ip6

TRUE for tcp.ip6.eth and tcp.ip6 CSAPs FALSE for tcp.ip4.eth and tcp.ip4 CSAPs

seqn

sequence number in host byte order

ackn

acknowledge number in host byte order

syn_flag

SYN flag

ack_flag

ACK flag

data

pointer to buffer with payload octets

pld_len

payload length

tmpl

location for pointer to ASN value (OUT)

Returns:

Status code.

int tapi_tcp_segment_template(tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, uint8_t* data, size_t pld_len, asn_value** tmpl)

The same function as tapi_tcp_ip_segment_template_gen() with force_ip6 parameter set to FALSE and is_eth_pdu parameter set to TRUE to prepare template for ‘tcp.ip4.eth’ CSAP.

int tapi_tcp_ip_segment_template(te_bool force_ip6, tapi_tcp_pos_t seqn, tapi_tcp_pos_t ackn, te_bool urg_flag, te_bool ack_flag, te_bool psh_flag, te_bool rst_flag, te_bool syn_flag, te_bool fin_flag, uint8_t* data, size_t pld_len, asn_value** tmpl)

The same function as tapi_tcp_segment_template() with force_ip6 parameter to create template for tcp.ip6.eth or tcp.ip4.eth CSAP

te_errno tapi_tcp_create_conn(const char* agt, const struct sockaddr* local_addr, const struct sockaddr* remote_addr, const char* local_iface, const uint8_t* local_mac, const uint8_t* remote_mac, int window, tapi_tcp_handler_t* handler)

Initialize TCP connection internal state. This method does not start connection establishing. Use tapi_tcp_start_conn() and tapi_tcp_wait_open() for establishing connection.

Local IP address should be fake, not registered on host with TA, because otherwise OS will respond to TCP packets too. Local MAC address may be fake, and it is better to use fake one, because OS sometimes may respond with ICMP messages to IP packets which are received on its Ethernet device but have foreign IP destination address.

If local MAC address is fake, Ethernet device will be turned to promiscuous mode.

Parameters:

agt

TA name.

local_addr

Local socket address.

remote_addr

Remote socket address.

local_iface

Local interface name.

local_mac

Local MAC address.

remote_mac

Remote MAC address.

window

Window size, or zero (TAPI_TCP_DEF_WINDOW) to use default window size. To specify zero window size, pass TAPI_TCP_ZERO_WINDOW.

handler

Where to save TAPI handler of created TCP connection.

Returns:

Status code.

te_errno tapi_tcp_start_conn(tapi_tcp_handler_t handler, tapi_tcp_mode_t mode)

Start TCP connection establishing.

Parameters:

handler

TAPI handler of TCP connection.

mode

Connection establishment mode. If TAPI_TCP_CLIENT, SYN will be sent.

Returns:

Status code.

te_errno tapi_tcp_init_connection(const char* agt, tapi_tcp_mode_t mode, const struct sockaddr* local_addr, const struct sockaddr* remote_addr, const char* local_iface, const uint8_t* local_mac, const uint8_t* remote_mac, int window, tapi_tcp_handler_t* handler)

Initialize process for open TCP connection. This method does not blocks, only sends SYN (in client mode) or SYN-ACK (in server mode). Use ‘tapi_tcp_wait_open’ for wait complete open of TCP connection. Local IP address should be fake, not retistered on host with TA, because running OS will respond to TCP messages also, and it will make side effects on IUT. Local MAC address may be fake, and it is desired to use fake, because running OS sometimes may respond with ICMP messages to IP packets which is got in its Ethernet device and have foreign IP dst address.

If local MAC address is fake, Ethernet device will be turned to promiscuous mode.

Parameters:

agt

name of TA;

mode

TCP mode: server or client, really, this means choice “wait for SYN” or “send SYN first”;

local_addr

local socket address, unspecified values are zeroes, (IN/OUT);

remote_addr

remote socket address, unspecified values are zeroes, (IN/OUT);

local_iface

name of Ethernet interface on ‘agt’ host;

local_mac

local MAC address, may be fake;

remote_mac

remote MAC address, must be real address of peer device;

window

Window size, or zero (TAPI_TCP_DEF_WINDOW) to use default window size. To specify zero window size, pass TAPI_TCP_ZERO_WINDOW.

handler

TAPI handler of created TCP connection (OUT);

Returns:

Status code

int tapi_tcp_init_connection_enc(const char* agt, tapi_tcp_mode_t mode, const struct sockaddr* local_addr, const struct sockaddr* remote_addr, const char* local_iface, const uint8_t* local_mac, const uint8_t* remote_mac, int window, te_bool enc_vlan, te_bool enc_snap, tapi_tcp_handler_t* handler)

Modification of tapi_tcp_init_connection() that supports Layer2 encapsulation.

Parameters are same as above plus:

Parameters:

enc_vlan

Use VLAN encapsulation

enc_llc

Use LLC/SNAP encapsulation

int tapi_tcp_destroy_connection(tapi_tcp_handler_t handler)

Destroy TAPI TCP connection handler: stop receive process on CSAPs, etc.

This method DOES NOT close TCP connection!

Parameters:

handler

TAPI handler of TCP connection;

Returns:

Status code

int tapi_tcp_wait_open(tapi_tcp_handler_t handler, int timeout)

Wait for complete process of opening TCP connection: blocks until SYN and ACKs from peer will be received. If timed out, TAPI connection handler will be destroyed.

Parameters:

handler

TAPI handler of TCP connection;

timeout

time in milliseconds, while TA should wait for SYN or ACK for his SYN;

Returns:

Status code

int tapi_tcp_wait_msg(tapi_tcp_handler_t handler, int timeout)

Wait for some incoming message in emulated TCP connection. If message was got, all internal state fields will be updated in accordance. If it was PUSH, it will be stored in internal buffer, and may be got with tapi_tcp_recv_msg().

Parameters:

handler

TAPI handler of TCP connection;

timeout

time in milliseconds, while TA should wait for SYN or ACK for his SYN;

Returns:

Status code

int tapi_tcp_send_fin(tapi_tcp_handler_t handler, int timeout)

Send FIN in TCP connection, and wait ACK for it. This is either part of close process, or shutdown for writing. This method blocks until ACK will be received.

Parameters:

handler

TAPI handler of TCP connection;

timeout

time in milliseconds, while TA should wait for answer for FIN;

Returns:

Status code

int tapi_tcp_send_fin_ack(tapi_tcp_handler_t handler, int timeout)

Send FIN in TCP connection with ACK (possibly to FIN sent by peer), and wait ACK for it. This is either part of close process, or shutdown for writing. This method blocks until ACK will be received.

Parameters:

handler

TAPI handler of TCP connection;

timeout

time in milliseconds, while TA should wait for answer for FIN;

Returns:

Status code

int tapi_tcp_send_rst(tapi_tcp_handler_t handler)

Send RST in TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

timeout

time in milliseconds, while TA should wait for answer for FIN;

Returns:

Status code

int tapi_tcp_send_msg(tapi_tcp_handler_t handler, uint8_t* payload, size_t len, tapi_tcp_protocol_mode_t seq_mode, tapi_tcp_pos_t seqn, tapi_tcp_protocol_mode_t ack_mode, tapi_tcp_pos_t ackn, tapi_ip_frag_spec* frags, size_t frag_num)

Send TCP message via established connection. With seq_mode = TAPI_TCP_AUTO it should be used ONLY for sending subsequent flow of data. If user need to send some strange sequence numbers, he have to use TAPI_TCP_EXPLICIT. First seqn for ‘explicit’ data block should be get with method ‘tapi_tcp_next_seqn’. To send some more data in automatic mode after explicit mode user have to store total length of all data, sent in explicit mode, by method ‘tapi_tcp_set_next_sent’

Parameters:

handler

TAPI handler of TCP connection;

payload

data for message payload;

len

length of payload;

seq_mode

mode of insertion SEQ number into message;

seqn

explicit SEQ number for message, used only if ‘seq_mode’ passed is TAPI_TCP_EXPLICIT;

ack_mode

mode of insertion ACK number into message;

ackn

explicit ACK number for message, used only if ‘ack_mode’ passed is TAPI_TCP_EXPLICIT;

Returns:

Status code

int tapi_tcp_conn_template(tapi_tcp_handler_t handler, uint8_t* payload, size_t len, asn_value** tmpl)

Prepare template for TCP message via established connection. Fields SEQN and ACKN are filled by default, if user want to set them explicitly , one can do it via ASN lib API.

Parameters:

handler

TAPI handler of TCP connection;

payload

data for message payload;

len

length of payload;

tmpl

location for new ASN value with traffic template(OUT);

Returns:

Status code

int tapi_tcp_send_template(tapi_tcp_handler_t handler, const asn_value* template, rcf_call_mode_t blk_mode)

Send explicitely formed traffic template. Note, that template should be prepareed accurately, if you want to send valid TCP message in connection. IP addresses and TCP pors should NOT be mentioned in template.

Parameters:

handler

TAPI handler of TCP connection;

template

ASN value of type Traffic-Template;

blk_mode

mode of the operation: in blocking mode it suspends the caller until sending of all the traffic finishes

Returns:

Status code

int tapi_tcp_recv_msg_gen(tapi_tcp_handler_t handler, int timeout, tapi_tcp_protocol_mode_t ack_mode, uint8_t* buffer, size_t* len, tapi_tcp_pos_t* seqn_got, tapi_tcp_pos_t* ackn_got, uint8_t* flags, te_bool no_unexp_seqn)

Wait for next incoming TCP message in connection, if buffer is empty, or get oldest received message in buffer queue. Ignore packets having unexpected SEQN (such as retransmits) if requested.

Parameters:

handler

TAPI handler of TCP connection.

timeout

Timeout in milliseconds.

ack_mode

Mode of sending ACK to the message, for this method valid values are TAPI_TCP_AUTO or TAPI_TCP_QUIET only.

payload

Pointer to message payload buffer (OUT).

len

Length of buffer / got payload (IN/OUT).

seqn_got

Place for received SEQ number or NULL (OUT).

ackn_got

Place for received ACK number or NULL (OUT).

flags

Location for TCP flags or NULL (OUT).

no_unexp_seqn

If TRUE, ignore packets with unexpected TCP SEQN.

Returns:

Status code

int tapi_tcp_recv_msg(tapi_tcp_handler_t handler, int timeout, tapi_tcp_protocol_mode_t ack_mode, uint8_t* buffer, size_t* len, tapi_tcp_pos_t* seqn_got, tapi_tcp_pos_t* ackn_got, uint8_t* flags)

Wait for next incoming TCP message in connection, if buffer is empty, or get oldest received message in buffer queue.

Parameters:

handler

TAPI handler of TCP connection;

timeout

timeout in milliseconds;

ack_mode

mode of sending ACK to the message, for this method valid values are ‘AUTO’ or ‘QUIET’ only;

payload

pointer to message payload buffer (OUT);

len

length of buffer / got payload (IN/OUT);

seqn_got

place for received SEQ number or NULL (OUT);

ackn_got

place for received ACK number or NULL (OUT);

flags

location for TCP flags or NULL (OUT).

Returns:

Status code

int tapi_tcp_recv_data(tapi_tcp_handler_t handler, int time2wait, tapi_tcp_protocol_mode_t ack_mode, te_dbuf* data)

Read all received data from TCP connection.

Parameters:

handler

TAPI handler of TCP connection.

time2wait

How long to wait for the next message, milliseconds.

ack_mode

Mode of sending ACKs, for this method valid values are TAPI_TCP_AUTO or TAPI_TCP_QUIET only.

data

Dynamic buffer to which received data should be appended.

Returns:

Status code.

int tapi_tcp_send_ack(tapi_tcp_handler_t handler, tapi_tcp_pos_t ackn)

Send ACK via established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

ackn

ACK number

Returns:

Status code

int tapi_tcp_ack_all(tapi_tcp_handler_t handler)

Send ACK to all data received from established TCP connection.

Parameters:

handler

TAPI handler of TCP connection.

Returns:

Status code.

tapi_tcp_pos_t tapi_tcp_first_seqn_got(tapi_tcp_handler_t handler)

Return the first received SEQ number in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection.

Returns:

SEQ number or zero if handler is not valid.

tapi_tcp_pos_t tapi_tcp_last_seqn_got(tapi_tcp_handler_t handler)

Return last received SEQ number in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

SEQ number of zero if ‘handler’ not valid.

tapi_tcp_pos_t tapi_tcp_last_ackn_got(tapi_tcp_handler_t handler)

Return last received ACK number in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

ACK number of zero if ‘handler’ not valid.

tapi_tcp_pos_t tapi_tcp_first_seqn_sent(tapi_tcp_handler_t handler)

Return the first sent SEQ number in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection.

Returns:

SEQ number or zero if handler is not valid.

tapi_tcp_pos_t tapi_tcp_last_seqn_sent(tapi_tcp_handler_t handler)

Return last sent SEQ number in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

SEQ number of zero if ‘handler’ not valid.

tapi_tcp_pos_t tapi_tcp_last_ackn_sent(tapi_tcp_handler_t handler)

Return last sent ACK number in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

ACK number of zero if ‘handler’ not valid.

size_t tapi_tcp_last_win_got(tapi_tcp_handler_t handler)

Return last received window in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

SEQ number of zero if ‘handler’ not valid.

te_bool tapi_tcp_fin_got(tapi_tcp_handler_t handler)

Check that a message with FIN flag set was got.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

TRUE if a message with FIN flag set was got, FALSE otherwise.

te_bool tapi_tcp_rst_got(tapi_tcp_handler_t handler)

Check that a message with RST flag set was got.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

TRUE if a message with RST flag set was got, FALSE otherwise.

tapi_tcp_pos_t tapi_tcp_next_seqn(tapi_tcp_handler_t handler)

Return next SEQ number to be sent in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

SEQ number of zero if ‘handler’ not valid.

tapi_tcp_pos_t tapi_tcp_next_ackn(tapi_tcp_handler_t handler)

Return next ACK number to be sent in established TCP connection.

Parameters:

handler

TAPI handler of TCP connection;

Returns:

ACK number of zero if ‘handler’ not valid.

int tapi_tcp_update_sent_seq(tapi_tcp_handler_t handler, size_t new_sent_len)

Update internal TAPI TCP connection fields according with next sent data in connection. This is necessary ONLY after sending data in ‘explicit’ mode.

Parameters:

handler

TAPI handler of TCP connection

new_sent_len

length of sent data

Returns:

status code

int tapi_tcp_get_window(tapi_tcp_handler_t handler)

Get TCP window size currently advertised by TCP connection.

Parameters:

handler

TAPI handler of TCP connection.

Returns:

TCP window size on success, negative value in case of failure.

te_errno tapi_tcp_set_window(tapi_tcp_handler_t handler, int window)

Set TCP window size to be advertised by TCP connection.

Parameters:

handler

TAPI handler of TCP connection.

window

Window size.

Returns:

Status code.

int tapi_tcp_reset_hack_init(const char* ta_name, int session, const char* iface, te_bool dir_out, tapi_tcp_reset_hack_t* context)

Initialize RST sending hack framework: create CSAP, start listening of SYN-ACK. Note, that it will catch FIRST SYN-ACK, matching passed filtering parameters, which user fill in ‘context’ structure. All unset fields have to be zero.

Parameters:

ta_name

TA name

sid

RCF session id

iface

Ethernet interface

dir_out

boolean flag wheather SYN-ACK will be outgoing; TRUE if it is.

context

pointer to structure with context data, IN/OUT

Returns:

status code

int tapi_tcp_reset_hack_catch(const char* ta_name, int session, tapi_tcp_reset_hack_t* context)

Catch SYN-ACK in RST sending hack framework. Note, that it will catch FIRST SYN-ACK, matching passed filtering parameters, which user fill in ‘context’ structure before call ‘init’.

Parameters:

ta_name

TA name

sid

RCF session id

context

pointer to structure with context data, IN/OUT

Returns:

status code

int tapi_tcp_reset_hack_send(const char* ta_name, int session, tapi_tcp_reset_hack_t* context, size_t received, size_t sent)

Send TCP RST.

Parameters:

ta_name

TA name

sid

RCF session id

context

pointer to structure with context data

received

received bytes during TCP connection life

sent

sent bytes during TCP connection life

Returns:

status code

int tapi_tcp_reset_hack_clear(const char* ta_name, int session, tapi_tcp_reset_hack_t* context)

Clear TCP reset hack context

Parameters:

ta_name

TA name

sid

RCF session id

context

pointer to structure with context data, IN/OUT

Returns:

status code

te_errno tapi_tcp_ip6_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac, const uint8_t* rem_mac, const uint8_t* loc_addr, const uint8_t* rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap)

Creates ‘tcp.ip6.eth’ CSAP.

Parameters:

ta_name

Test Agent name

sid

RCF SID

eth_dev

Name of Ethernet interface

receive_mode

Bitmask with receive mode, see ‘enum tad_eth_recv_mode’ in tad_common.h. Use TAD_ETH_RECV_DEF by default.

loc_mac

Local MAC address (or NULL)

rem_mac

Remote MAC address (or NULL)

loc_addr

Local IPv6 address

rem_addr

Remote IPv6 address

loc_port

Local TCP port in network byte order or -1

rem_port

Remote TCP port in network byte order or -1

tcp_csap

Location for the IPv4 CSAP handle (OUT)

Returns:

Status of the operation

csap_handle_t tapi_tcp_conn_snd_csap(tapi_tcp_handler_t handler)

Get sender CSAP from TCP connection context.

Parameters:

handler

TAPI handler of the TCP connection

Returns:

CSAP id

csap_handle_t tapi_tcp_conn_rcv_csap(tapi_tcp_handler_t handler)

Get receiver CSAP from TCP connection context.

Parameters:

handler

TAPI handler of the TCP connection

Returns:

CSAP id

int tapi_tcp_update_sent_ack(tapi_tcp_handler_t handler, size_t ack)

Set last sent ACK number of the sender CSAP in TCP connection context.

Parameters:

handler

TAPI handler of the TCP connection

ack

ACK number to set

Returns:

Status code

int tapi_tcp_wait_packet(tapi_tcp_handler_t handler, int timeout)

Wait for any packet in this connection while timeout expired.

Parameters:

handler

TAPI handler of the TCP connection

timeout

Timeout in milliseconds

Returns:

zero on success (one or more messages got), errno otherwise

int tapi_tcp_get_packets(tapi_tcp_handler_t handler)

Pull received packets.

Parameters:

handler

TAPI handler of the TCP connection

Returns:

Packets number or -1 in case of error

te_errno tapi_tcp_conn_enable_ts(tapi_tcp_handler_t handler, te_bool enable, uint32_t start_value)

Enable or disable TCP timestamp option for emulated TCP connection.

Parameters:

handler

TAPI TCP connection handler.

enable

Whether to enable or disable timestamp.

start_time

If enable is TRUE, this is the start value for TCP timestamp. Each new TCP timestamp will be computed as this value + number of milliseconds since the moment of time when the first packet was sent (for which this value will be used as TCP timestamp).

Returns:

Status code.

te_errno tapi_tcp_conn_get_ts(tapi_tcp_handler_t handler, te_bool* enabled, te_bool* dst_enabled, uint32_t* ts_value, uint32_t* last_ts_sent, uint32_t* last_ts_got, uint32_t* ts_to_echo, uint32_t* last_ts_echo_sent, uint32_t* last_ts_echo_got)

Get current status of TCP timestamp option in a given TCP connection emulation.

Parameters:

handler

TAPI TCP connection handler.

enabled

Whether TCP timestamp is enabled. Other parameters are filled only if this is TRUE.

dst_enabled

Whether peer sends TCP timestamp. If peer did not sent TCP timestamp in its first packet, we will not send it too.

ts_value

Current TCP timestamp value (such that would be used if a packet is sent now).

last_ts_sent

Last timestamp sent to peer.

last_ts_got

Last timestamp received from peer.

ts_to_echo

Value to be sent in echo-reply field in the next ACK.

last_ts_echo_sent

Timestamp echo-reply sent in the last packet.

last_ts_echo_got

Last timestamp echo-reply received from peer.

Returns:

Status code.

te_errno tapi_tcp_get_ts_opt(const asn_value* val, uint32_t* ts_value, uint32_t* ts_echo)

Get TCP timestamp option parameters.

Parameters:

val

Pointer to ASN value which stores either whole network packet or TCP PDU.

ts_value

Where to save timestamp value.

ts_echo

Where to save timestamp echo reply.

Returns:

Status code.

te_errno tapi_tcp_set_ts_opt(asn_value* val, uint32_t ts_value, uint32_t ts_echo)

Set TCP timestamp option parameters.

Parameters:

val

Pointer to ASN value which stores either whole network packet or TCP PDU.

ts_value

Timestamp value.

ts_echo

Timestamp echo reply.

Returns:

Status code.

int tapi_tcp_compare_seqn(uint32_t seqn1, uint32_t seqn2)

Compare two TCP sequence numbers.

Parameters:

seqn1

The first SEQN.

seqn2

The second SEQN.

Returns:

-1 if the first SEQN is smaller than the second SEQN, 1 if the first SEQN is greater than the second SEQN, 0 if they are equal.

te_errno tapi_tcp_ip_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac, const uint8_t* rem_mac, int ip_family, const void* loc_addr, const void* rem_addr, int loc_port, int rem_port, csap_handle_t* tcp_csap)

Create TCP CSAP for given IP address family on Ethernet.

Parameters:

ta_name

Test Agent name

sid

RCF SID

eth_dev

Name of Ethernet interface

receive_mode

Receive mode bitmask, see tad_eth_recv_mode in tad_common.h. Use TAD_ETH_RECV_DEF by default.

loc_mac

Local MAC address (or NULL)

rem_mac

Remote MAC address (or NULL)

ip_family

Address family of created CSAP (AF_INET or AF_INET6)

loc_addr

Local IP address in network byte order (or NULL)

rem_addr

Remote IP address in network byte order (or NULL)

loc_port

Local TCP port in network byte order or -1

rem_port

Remote TCP port in network byte order or -1

tcp_csap

Location for the TCP CSAP handle

Returns:

Status code.

te_errno tapi_tcp_get_hdrs_payload_len(asn_value* pkt, unsigned int* hdrs_len, unsigned int* pld_len)

Get length of TCP/IP headers and length of TCP payload from a packet captured by TCP/IP/Eth CSAP.

This function is used because CSAP sometimes reports extra zero bytes in payload, so payload.len may be not reliable.

This function does not take into account IPv6 extension headers and will probably work incorrectly in their presence.

Parameters:

pkt

Packet captured by CSAP.

hrds_len

Where to save headers length (may be NULL).

pld_len

Where to save payload length (may be NULL).

Returns:

Status code.

Macros

#define TAPI_TCP_DEF_WINDOW

Pass this as window parameter to tapi_tcp_init_connection() to use default window size.

#define TAPI_TCP_ZERO_WINDOW

Pass this as window parameter to tapi_tcp_init_connection() to use zero window size.