IPv4

Overview

Copyright (C) 2004-2022 OKTET Labs Ltd. More…

// typedefs

typedef struct tapi_ip4_packet_t tapi_ip4_packet_t;

typedef void (*ip4_callback)(
    const tapi_ip4_packet_t *pkt,
    void *userdata
    );

// structs

struct tapi_ip4_packet_t;

// global functions

te_errno tapi_ip4_add_csap_layer(asn_value** csap_spec, in_addr_t local_addr, in_addr_t remote_addr, int ip_proto, int ttl, int tos);
te_errno tapi_ip4_add_pdu(asn_value** tmpl_or_ptrn, asn_value** pdu, bool is_pattern, in_addr_t src_addr, in_addr_t dst_addr, int ip_proto, int ttl, int tos);
te_errno tapi_ip4_pdu_tmpl_fragments(asn_value** tmpl, asn_value** pdu, tapi_ip_frag_spec* fragments, unsigned int num_frags);
te_errno tapi_ip4_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac_addr, const uint8_t* rem_mac_addr, in_addr_t loc_ip4_addr, in_addr_t rem_ip4_addr, int ip_proto, csap_handle_t* ip4_csap);
te_errno tapi_ip4_csap_create(const char* ta_name, int sid, in_addr_t loc_ip4_addr, in_addr_t rem_ip4_addr, int ip_proto, csap_handle_t* ip4_csap);
tapi_tad_trrecv_cb_data* tapi_ip4_eth_trrecv_cb_data(ip4_callback callback, void* user_data);
te_errno tapi_ip4_template(tapi_ip_frag_spec* fragments, unsigned int num_frags, int ttl, int protocol, const uint8_t* payload, size_t pld_len, asn_value** result_value);
te_errno tapi_ip4_get_payload_len(asn_value* pdu, size_t* len);

Detailed Documentation

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

Typedefs

typedef void (*ip4_callback)(
    const tapi_ip4_packet_t *pkt,
    void *userdata
    )

Callback function for the receiving IP datagrams.

Neither pkt, nor pkt->payload MAY NOT be stored for future use by this callback: they are freed just after callback return.

Parameters:

pkt

Received IP packet.

userdata

Parameter, provided by the caller.

Global Functions

te_errno tapi_ip4_add_csap_layer(asn_value** csap_spec, in_addr_t local_addr, in_addr_t remote_addr, int ip_proto, int ttl, int tos)

Add IPv4 layer in CSAP specification.

Parameters:

csap_spec

Location of CSAP specification pointer.

local_addr

Default local IPv4 address in network byte order or htonl(INADDR_ANY)

remote_addr

Default remote IPv4 address in network byte order or htonl(INADDR_ANY)

ip_proto

Protocol or negative to keep unspecified.

ttl

Time-to-live or negative to keep unspecified.

tos

Type-of-service or negative to keep unspecified.

Status

code.

te_errno tapi_ip4_add_pdu(asn_value** tmpl_or_ptrn, asn_value** pdu, bool is_pattern, in_addr_t src_addr, in_addr_t dst_addr, int ip_proto, int ttl, int tos)

Add IPv4 PDU as the last PDU to the last unit of the traffic template or pattern.

Parameters:

tmpl_or_ptrn

Location of ASN.1 value with traffic template or pattern

pdu

Location for ASN.1 value pointer with added PDU

is_pattern

Is the first argument template or pattern

src_addr

Source IPv4 address in network byte order or htonl(INADDR_ANY). If htonl(INADDR_ANY), default value is specified during CSAP creation (as local address for sending, as remote address for receiving).

dst_addr

Destination IPv4 address in network byte order or htonl(INADDR_ANY). If htonl(INADDR_ANY), default value is specified during CSAP creation (as remote address for sending, as local address for receiving).

ip_proto

Protocol or negative to keep unspecified.

ttl

Time-to-live or negative to keep unspecified.

tos

Type-of-service or negative to keep unspecified.

Returns:

Status code.

te_errno tapi_ip4_pdu_tmpl_fragments(asn_value** tmpl, asn_value** pdu, tapi_ip_frag_spec* fragments, unsigned int num_frags)

Add fragments specification to IPv4 PDU.

Parameters:

tmpl

NULL or location of ASN.1 value with traffic template where IPv4 PDU should be added

pdu

If tmpl is NULL, this parameter must point to IPv4 PDU where to add fragments specification; on return, if this parameter is not NULL, pointer to IPv4 PDU will be saved in it

fragments

Array with IP fragments specifictaions

num_frags

Number of IP fragments (if 0, nothing is done)

Returns:

Status code.

te_errno tapi_ip4_eth_csap_create(const char* ta_name, int sid, const char* eth_dev, unsigned int receive_mode, const uint8_t* loc_mac_addr, const uint8_t* rem_mac_addr, in_addr_t loc_ip4_addr, in_addr_t rem_ip4_addr, int ip_proto, csap_handle_t* ip4_csap)

Create ‘ip4.eth’ CSAP

Parameters:

ta_name

Test Agent name

sid

RCF SID

eth_dev

Name of Ethernet interface

receive_mode

Receive mode for Ethernet Layer on the Interface

loc_mac_addr

Local MAC address (or NULL)

rem_mac_addr

Remote MAC address (or NULL)

loc_ip4_addr

Local IPv4 address in network order or htonl(INADDR_ANY)

rem_ip4_addr

Remote IPv4 address in network order or htonl(INADDR_ANY)

proto

Protocol over IPv4 or negative number

ip4_csap

Location for the IPv4 CSAP handle (OUT)

Returns:

Status code.

te_errno tapi_ip4_csap_create(const char* ta_name, int sid, in_addr_t loc_ip4_addr, in_addr_t rem_ip4_addr, int ip_proto, csap_handle_t* ip4_csap)

Creates ‘ip4’ CSAP

Parameters:

ta_name

Test Agent name

sid

RCF SID

loc_ip4_addr

Local IPv4 address in network order or htonl(INADDR_ANY)

rem_ip4_addr

Remote IPv4 address in network order or htonl(INADDR_ANY)

proto

Protocol over IPv4 or negative number

ip4_csap

Location for the IPv4 CSAP handle (OUT)

Returns:

Status code.

te_errno tapi_ip4_template(tapi_ip_frag_spec* fragments, unsigned int num_frags, int ttl, int protocol, const uint8_t* payload, size_t pld_len, asn_value** result_value)

Prepare ASN Traffic-Template value for CSAP with ‘ip4’ layer.

Deprecated Avoid usage of this function, since it should be removed in the future.

Parameters:

fragments

array with IP fragments specifictaions, or NULL;

num_frags

number of IP fragments;

ttl

time-to-live field, or negative for CSAP default;

protocol

protocol field, or negative for CSAP default;

payload

payload of IPv4 packet, or NULL;

pld_len

length of payload;

result_value

location for pointer to new ASN value (OUT);

Returns:

status code

te_errno tapi_ip4_get_payload_len(asn_value* pdu, size_t* len)

Compute IPv4 packet payload length from IP header length fields.

Parameters:

pdu

IPv4 PDU.

len

Where to save computed length.

Returns:

Status code.