Show pub.c syntax highlighted
/*
* Copyright (c) 2003 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>
int main(int argc, char **argv)
{
int num;
int count = 3;
flow_id_t fid = {
src: my_node_id,
dst: LINK_BROADCAST,
max_hops: 10
};
char *key = misc_parse_out_option(&argc, argv, "key", 0);
char *value = misc_parse_out_option(&argc, argv, "value", 0);
char *prefix = misc_parse_out_option(&argc, argv, "prefix", 0);
char *dst = misc_parse_out_option(&argc, argv, "dst", 0);
if (dst) {
if (parse_if_id(dst, &(fid.dst)) < 0) {
elog(LOG_WARNING, "Can't parse if id %s!", dst);
exit(1);
}
}
char *src = misc_parse_out_option(&argc, argv, "src", 0);
if (src) {
if (parse_if_id(src, &(fid.src)) < 0) {
elog(LOG_WARNING, "Can't parse if id %s!", src);
exit(1);
}
}
misc_parse_option_as_uint(&argc, argv, "src", 0, &(fid.src));
misc_parse_option_as_uint8(&argc, argv, "flow_index", 0, &(fid.flow_index));
if (misc_parse_option_as_uint8(&argc, argv, "iface", 0, &(fid.src_if)) == 0) {
fid.dst_if = fid.src_if;
}
misc_parse_option_as_uint8(&argc, argv, "hops", 0, &(fid.max_hops));
/* generic init */
misc_init(&argc, argv, CVSTAG);
num = random();
misc_parse_option_as_int(&argc, argv, "seq", 0, &num);
misc_parse_option_as_int(&argc, argv, "count", 0, &count);
if (key == NULL || value == NULL) {
printf("usage: [--prefix=<dev-prefix>] --key=<2char> --value=<atmost11char> "
"[--count=<count>] [--seq=<seq>]\n"
"[--dst=<addr>] [--src=<addr>] [--iface=<index>] [--hops=<max-hops>] "
"[--flow_index=<index>]\n"
" Default prefix is %s\n"
" Default count is %d\n"
" Default hops is 10\n"
" Default flow_index is 0\n"
" Default seqno will be selected randomly\n",
SSYNC_DEFAULT_PREFIX, count);
exit(1);
}
{
workload_table_t table[count];
int i;
memset(table, 0, sizeof(table));
for (i=0; i<count; i++) {
strncpy(table[i].workload.key, key, 2);
strncpy(table[i].workload.data, value, sizeof(table[i].workload.data));
table[i].workload.app_seq = num+i;
}
if (workload_pub(prefix, table, count, &fid) < 0) {
elog(LOG_WARNING, "Unable to publish?");
}
}
return 0;
}
See more files for this project here