retx_proto_test.c from EmStar at Krugle
Show retx_proto_test.c syntax highlighted
/*
*
* Copyright (c) 2004 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <devel/state/ssync.h>
#include <link/link.h>
#define P(s) printf("%s, %d delta, %d bytes total\n", s, \
iter->grow_pkt->len - last, iter->grow_pkt->len); \
elog_raw(LOG_DEBUG(0), iter->grow_pkt->buf + last, iter->grow_pkt->len - last); \
last = iter->grow_pkt->len
int main(int argc, char **argv)
{
cl_index_t target = {};
int last = 0;
misc_init(&argc, argv, CVSTAG);
printf("sizeof ctrl = %d\n", sizeof(ssync_retx2_ctrl_t));
printf("sizeof nack_ctrl = %d\n", sizeof(ssync_retx2_nack_ctrl_t));
printf("sizeof header = %d\n", sizeof(ssync_hdr_t));
printf("sizeof target = %d\n", sizeof(cl_index_t));
/* create a packet */
ssync_msg_iter_t *iter = ssync_msg_iter_new(NULL, 0, 200);
ssync_msg_iter_init_msg(iter, 0, NULL);
P("start [1]");
target.byte = 3;
ssync_msg_iter_append_msg(iter, SSYNC_LOG_INIT, 12, target,
45, 0, 0, 0, "12345678", 8);
P("init, new target, new flow, new list/seqno [16]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 12, target,
45, 35, 0, 0, "12345678", 8);
P("add 8, new seqno [12]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 12, target,
45, 36, 0, 0, "123", 3);
P("add 3 [5]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 12, target,
45, 37, 0, 0, "456", 3);
P("add 3, [4]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 12, target,
45, 39, 0, 0, "789", 3);
P("add 3, new seqno [7]");
target.byte = 4;
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 13, target,
45, 40, 0, 0, "4560987", 7);
P("add 7, new flow, new target [11]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 13, target,
45, 40, 0, 0, "abcd", 4);
P("add 4, new seqno [9]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 13, target,
47, 41, 0, 0, "efgh", 4);
P("add 4, new list [9]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 13, target,
47, 42, 0, 0, "ijklm", 5);
P("add 5 [7]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_TERM, 13, target,
47, 43, 0, 0, NULL, 0);
P("term [1]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 13, target,
47, 67, 0, 4, NULL, 0);
P("nack, new nack_list [5]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 13, target,
47, 90, 0, 32, NULL, 0);
P("nack len [5]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 13, target,
47, 1011, 0, 31, NULL, 0);
P("nack [3]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 13, target,
47, 0, 1, 0, NULL, 0);
P("nack init [3]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 13, target,
47, 0, 2, 0, NULL, 0);
P("nack full init [3]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 13, target,
47, 1089, 0, 16, NULL, 0);
P("nack [3]");
target.byte = 5;
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 14, target,
48, 178, 0, 16, NULL, 0);
P("nack, new list, new target, new flow [7]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 14, target,
49, 17990, 0, 50, NULL, 0);
P("nack len, new list [6]");
target.byte = 7;
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 14, target,
49, 10, 0, 500, NULL, 0);
P("nack len, new target (implies new flow) [8]");
target.byte = 4;
ssync_msg_iter_append_msg(iter, SSYNC_LOG_TERM, 13, target,
47, 44, 0, 0, NULL, 0);
P("term, new target, new flow [3]");
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NOP, 13, target,
47, 45, 0, 0, "test22", 6);
P("NOP, 6 bytes data [8]");
flow_id_t fid = {
src: 1,
src_if: 2,
dst: 3,
dst_if: 4,
max_hops: 5,
flow_index: 6
};
uint8_t flow_index = 13;
ssync_msg_iter_maybe_flow_map(iter, &flow_index,
&fid, 10);
P("flow, [14]");
ssync_msg_iter_maybe_addr_map(iter, &target, 0xFB);
P("addr, [5]");
target.byte = 0;
ssync_msg_iter_maybe_addr_map(iter, &target, 0xFB);
P("addr, [0]");
target.byte = 0;
ssync_msg_iter_maybe_addr_map(iter, &target, 0xFC);
P("addr, new target, [7]");
ssync_msg_iter_append_msg(iter, SSYNC_LOG_ADD, 13, target,
47, 45, 0, 0, "opop", 4);
P("add 4 [6]");
target.byte = 7;
ssync_msg_iter_append_msg(iter, RETX2_CTRL_NACK, 14, target,
49, 10, 0, 500, NULL, 0);
P("nack len, new target, new flow [8]");
buf_t *buf = ssync_msg_iter_finalize_msg(iter);
ssync_msg_iter_destroy(iter);
buf_t *output = buf_new();
misc_hexdump_to_buf(output, buf->buf, buf->len, "");
link_pkt_t pkt = {};
dump_ssync(output, &pkt, buf->buf, buf->len, " ", NULL);
printf("%s", output->buf);
return 0;
}
See more files for this project here