int main(int argc, char *argv[]) { int dfd; int swtype = PRI_DEF_SWITCHTYPE; int node = PRI_DEF_NODETYPE; struct zt_params p; if (argc < 2) { fprintf(stderr, "Usage: pritest <dchannel> [swtypetype] [nodetype]\n"); exit(1); } dfd = open(argv[1], O_RDWR); if (dfd < 0) { fprintf(stderr, "Failed to open dchannel '%s': %s\n", argv[1], strerror(errno)); exit(1); } if (ioctl(dfd, ZT_GET_PARAMS, &p)) { fprintf(stderr, "Unable to get parameters on '%s': %s\n", argv[1], strerror(errno)); exit(1); } if ((p.sigtype != ZT_SIG_HDLCRAW) && (p.sigtype != ZT_SIG_HDLCFCS)) { fprintf(stderr, "%s is in %d signalling, not FCS HDLC or RAW HDLC mode\n", argv[1], p.sigtype); exit(1); } if (argc > 2) { swtype = str2switch(argv[2]); if (swtype < 0) { fprintf(stderr, "Valid switchtypes are: ni2, dms100, lucent5e, att4ess, and euroisdn\n"); exit(1); } } if (argc > 3) { node = str2node(argv[3]); if (node < 0) { fprintf(stderr, "Valid node types are: network and cpe\n"); exit(1); } } signal(SIGCHLD, chan_ended); if (run_pri(dfd, swtype, node)) exit(1); exit(0); return 0; }
/** * context: {} * tokens: {src-addr, src-iface-id, dst-addr, dst-iface-id} */ int cli_net_add_linkptp(cli_ctx_t * ctx, cli_cmd_t * cmd) { const char * arg_src = cli_get_arg_value(cmd, 0); const char * arg_src_if= cli_get_arg_value(cmd, 1); const char * arg_dst = cli_get_arg_value(cmd, 2); const char * arg_dst_if= cli_get_arg_value(cmd, 3); const char * opt; net_node_t * src_node; net_node_t * dst_node; net_iface_id_t src_if; net_iface_id_t dst_if; int result; net_iface_t * iface; net_link_delay_t delay= 0; net_link_load_t capacity= 0; // Get source node if (str2node(arg_src, &src_node)) { cli_set_user_error(cli_get(), "could not find node \"%s\"", arg_src); return CLI_ERROR_COMMAND_FAILED; } // Get source address if (net_iface_str2id(arg_src_if, &src_if)) { cli_set_user_error(cli_get(), "invalid interface id \"%\"", arg_src_if); return CLI_ERROR_COMMAND_FAILED; } // Get destination node if (str2node(arg_dst, &dst_node)) { cli_set_user_error(cli_get(), "could not find node \"%s\"", arg_dst); return CLI_ERROR_COMMAND_FAILED; } // get destination address if (net_iface_str2id(arg_dst_if, &dst_if)) { cli_set_user_error(cli_get(), "invalid interface id \"%\"", arg_dst_if); return CLI_ERROR_COMMAND_FAILED; } // Get optional link capacity opt= cli_get_opt_value(cmd, "bw"); if (opt != NULL) { if (str2capacity(opt, &capacity)) { cli_set_user_error(cli_get(), "invalid link capacity \"%s\"", opt); return CLI_ERROR_COMMAND_FAILED; } } // Get optional link delay opt= cli_get_opt_value(cmd, "delay"); if (opt != NULL) { if (str2delay(opt, &delay)) { cli_set_user_error(cli_get(), "invalid link delay \"%s\"", opt); return CLI_ERROR_CMD_FAILED; } } // Create link result= net_link_create_ptp(src_node, src_if, dst_node, dst_if, BIDIR, &iface); if (result != ESUCCESS) { cli_set_user_error(cli_get(), "could not create ptp link " "from %s (%s) to %s (%s) (%s)", arg_src, arg_src_if, arg_dst, arg_dst_if, network_strerror(result)); return CLI_ERROR_COMMAND_FAILED; } result= net_link_set_phys_attr(iface, delay, capacity, BIDIR); if (result != ESUCCESS) { cli_set_user_error(cli_get(), "could not set physical attributes (%s)", network_strerror(result)); return CLI_ERROR_COMMAND_FAILED; } return CLI_SUCCESS; }
/** * context: {} * tokens: {addr-src, prefix-dst} * options: [--depth=, --capacity=, delay=] */ int cli_net_add_link(cli_ctx_t * ctx, cli_cmd_t * cmd) { const char * arg_src= cli_get_arg_value(cmd, 0); const char * arg_dst= cli_get_arg_value(cmd, 1); const char * opt; net_node_t * src_node; net_node_t * dst_node; ip_dest_t dest; int result; uint8_t depth= 1; net_link_delay_t delay= 0; net_link_load_t capacity= 0; net_iface_dir_t dir; net_iface_t * iface; net_subnet_t * subnet; // Get optional link depth opt= cli_get_opt_value(cmd, "depth"); if (opt != NULL) { if (str2depth(opt, &depth)) { cli_set_user_error(cli_get(), "invalid link depth \"%s\"", opt); return CLI_ERROR_COMMAND_FAILED; } } // Get optional link capacity opt= cli_get_opt_value(cmd, "bw"); if (opt != NULL) { if (str2capacity(opt, &capacity)) { cli_set_user_error(cli_get(), "invalid link capacity \"%s\"", opt); return CLI_ERROR_COMMAND_FAILED; } } // Get optional link delay opt= cli_get_opt_value(cmd, "delay"); if (opt != NULL) { if (str2delay(opt, &delay)) { cli_set_user_error(cli_get(), "invalid link delay \"%s\"", opt); return CLI_ERROR_CMD_FAILED; } } // Get source node if (str2node(arg_src, &src_node)) { cli_set_user_error(cli_get(), "could not find node \"%s\"", arg_src); return CLI_ERROR_COMMAND_FAILED; } // Get destination: can be a node / a subnet if ((ip_string_to_dest(arg_dst, &dest) < 0) || (dest.type == NET_DEST_ANY)) { cli_set_user_error(cli_get(), "invalid destination \"%s\".", arg_dst); return CLI_ERROR_COMMAND_FAILED; } // Add link: RTR (to node) / PTMP (to subnet) if (dest.type == NET_DEST_ADDRESS) { dst_node= network_find_node(network_get_default(), dest.addr); if (dst_node == NULL) { cli_set_user_error(cli_get(), "tail-end \"%s\" does not exist.", arg_dst); return CLI_ERROR_COMMAND_FAILED; } dir= BIDIR; result= net_link_create_rtr(src_node, dst_node, dir, &iface); } else { subnet= network_find_subnet(network_get_default(), dest.prefix); if (subnet == NULL) { cli_set_user_error(cli_get(), "tail-end \"%s\" does not exist.", arg_dst); return CLI_ERROR_COMMAND_FAILED; } dir= UNIDIR; result= net_link_create_ptmp(src_node, subnet, dest.prefix.network, &iface); } if (result != ESUCCESS) { cli_set_user_error(cli_get(), "could not add link %s -> %s (%s)", arg_src, arg_dst, network_strerror(result)); return CLI_ERROR_COMMAND_FAILED; } result= net_link_set_phys_attr(iface, delay, capacity, dir); if (result != ESUCCESS) { cli_set_user_error(cli_get(), "could not set physical attributes (%s)", network_strerror(result)); return CLI_ERROR_COMMAND_FAILED; } return CLI_SUCCESS; }