pal_usecs_t usec1 = pal_time_usecs();
DBG_TEST("show start time %d", usec1);
char timebuf[25];
char buf[INET_NTOP_BUFSIZ];
UINT32 out_ifx;
char pStr[NETIF_ID_STRLEN];
char cli_buf[1024] = {0}; /* TPIMI_PRINT_STR_LEN 256 */
int len = 0;
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, "MPLS Layer-2 Virtual Circuit: %s%s, id: %u, create time: %s\r\n",
vc->name, vc->fec_type_vc == PW_OWNER_MANUAL ? "(static)" : "", vc->id,
sec2wdhms_str(vc->create_time, timebuf, 25));
#if 0
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " up time: %s, last change time: %s\r\n",
sec2wdhms_str(vc->uptime, timebuf, 25), sec2wdhms_str(vc->last_change, timebuf, 25));
if (vc->tunnel_id > 0)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Tunnel-Id: %d\r\n", vc->tunnel_id);
else if (vc->tunnel_name)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Tunnel-Name: %s\r\n", vc->tunnel_name);
#endif
if (vc->pw_operation_mode == PW_OPERATING_MODE_RAW) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Operating mode : Raw\r\n");
} else if (vc->pw_operation_mode == PW_OPERATING_MODE_TAGGED) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Operating mode : Tagged\r\n");
}
if (vc->address.family == AF_INET) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint-Type : IPv4 Address\r\n");
pal_inet_ntop(AF_INET, &vc->address.u.prefix4, buf, INET_NTOP_BUFSIZ);
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint : %s\r\n", buf);
} else if (vc->address.family == AF_INET6) {
#ifdef HAVE_IPV6
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint-Type : IPv6 Address\r\n");
pal_inet_ntop(AF_INET6, &vc->address.u.prefix6, buf, INET_NTOP_BUFSIZ);
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint : %s\r\n", buf);
#endif
} else {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint: N/A\r\n");
}
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Remote vc label: %d\r\n", vc->in_label);
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Local vc label : %d\r\n", vc->out_label);
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Control Word : %s\r\n", vc->cw ? "Enabled" : "Disabled");
#if 1
tpImiPrintf(printEnv, "%s", cli_buf);
memset(cli_buf, 0, 255);
len = 0;
#endif
ipc_netIfKernelIfx2IfIndex(vc->vc_info.if_index, (long *)&out_ifx);
if (ipc_netIfIndex2Str(out_ifx, pStr, NETIF_ID_STRLEN) == ERR_NO_ERROR) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Bound to interface : %s\r\n", pStr);
} else {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Bound to interface : Unknown\r\n");
}
#ifdef HAVE_SUBINTERFACE
if (is_ifp_subinterface(vc->vc_info.mif->ifp))
nsm_subif_encap_dump(cli, vc->vc_info.mif->ifp);
#endif /* HAVE_SUBINTERFACE */
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit Type: %s\r\n", mpls_vc_type_to_str(vc->vc_info.vc_type));
if (vc->vc_info.vc_type == VC_TYPE_ETH_VLAN) {
if (vc->vc_info.vlan_id)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Vlan Id: %d\r\n", vc->vc_info.vlan_id);
if (vc->vc_info.inner_vlan)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Inner Vlan Id: %d\r\n", vc->vc_info.inner_vlan);
if (vc->vc_info.svlan_tpid)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Svlan Tpid: %x\r\n", vc->vc_info.svlan_tpid);
}
if (vc->vc_info.vc_type == VC_TYPE_ETHERNET) {
if (vc->vc_info.svlan_id)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Svlan Id: %d\r\n", vc->vc_info.svlan_id);
if (vc->vc_info.svlan_tpid)
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Svlan Tpid: %x\r\n", vc->vc_info.svlan_tpid);
}
if (vc->vc_info.egress_oper) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Action: %s\r\n", mpls_pw_egr_oper_to_str(vc->vc_info.egress_oper));
}
#if 0
if (!CHECK_FLAG(vc->vc_info.conf_flag, (1 << 4)))
pal_strcpy(vcstr, "Primary");
else
pal_strcpy(vcstr, "Secondary");
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is configured as %s\r\n", vcstr);
#endif
if (vc->install == TRUE) {
if (IS_NSM_CODE_PW_AC_FAULT(vc->pw_status)) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is inactive");
} else {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is active");
}
} else if (CHECK_FLAG(vc->vc_info.conf_flag, (1 << 1))) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is standby");
} else {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is inactive");
}
if (vc->state == 3 /* NSM_MPLS_L2_CIRCUIT_UP */) {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " (UpTime %s) ",
sec2wdhms_str(vc->vc_up_time, timebuf, 25));
} else {
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " (Reason: %s)",
vc_down_reason_str(vc->last_down_reason));
}
len += snprintf(cli_buf + len, sizeof(cli_buf) - len, "\r\n");
tpImiPrintf(printEnv, "%s\r\n", cli_buf);
#ifdef HAVE_VCCV
l2_circuit_vccv_dump (printEnv, vc);
#endif /* HAVE_VCCV */
usec1 = pal_time_usecs();
DBG_TEST("show end time %d", usec1);
#if 0
else if (vc->vpls)
{
struct nsm_vpls_spoke_vc *svc;
/* VPLS binding. */
tpImiPrintf(printEnv, " Bound to VPLS instance: %s\r\n",
(vc->vpls ? vc->vpls->vpls_name : "none"));
svc = nsm_vpls_spoke_vc_lookup_by_name (vc->vpls, vc->name, NSM_FALSE);
if (svc)
{
/* Circuit type is always ETHERNET VPLS. */
tpImiPrintf(printEnv, " Virtual Circuit Type: %s\r\n",
mpls_vc_type_to_str (svc->vc_type));
}
}
#endif /* HAVE_VPLS */
#if 0
AVL_TREE_LOOP (nm->svc_templ_table, svc_templ, avl_node)
{
if (vc->vc_info && ((pal_strncmp(vc->vc_info.svc_templ_name, svc_templ->name,
MAX_SVC_TEMPLATE_NAME)) == 0))
nsm_svc_templ_dump_detail (cli, svc_templ, PAL_TRUE);
}
#endif
减少上述代码中snprintf的调用次数
最新发布