Ejemplo n.º 1
0
static int
show_history_res(dladm_usage_t *history, void *arg)
{
	show_history_state_t	*state = (show_history_state_t *)arg;
	char			buf[DLADM_STRSIZE];
	history_fields_buf_t	ubuf;
	dladm_flow_attr_t	attr;
	dladm_status_t		status;

	/*
	 * Only show historical information for existing flows unless '-a'
	 * is specified.
	 */
	if (!state->us_showall && ((status = dladm_flow_info(handle,
	    history->du_name, &attr)) != DLADM_STATUS_OK)) {
		return (status);
	}

	bzero(&ubuf, sizeof (ubuf));

	(void) snprintf(ubuf.history_flow, sizeof (ubuf.history_flow), "%s",
	    history->du_name);
	(void) snprintf(ubuf.history_duration, sizeof (ubuf.history_duration),
	    "%llu", history->du_duration);
	(void) snprintf(ubuf.history_ipackets, sizeof (ubuf.history_ipackets),
	    "%llu", history->du_ipackets);
	(void) snprintf(ubuf.history_rbytes, sizeof (ubuf.history_rbytes),
	    "%llu", history->du_rbytes);
	(void) snprintf(ubuf.history_opackets, sizeof (ubuf.history_opackets),
	    "%llu", history->du_opackets);
	(void) snprintf(ubuf.history_obytes, sizeof (ubuf.history_obytes),
	    "%llu", history->du_obytes);
	(void) snprintf(ubuf.history_bandwidth, sizeof (ubuf.history_bandwidth),
	    "%s Mbps", dladm_bw2str(history->du_bandwidth, buf));

	ofmt_print(state->us_ofmt, (void *)&ubuf);

	return (DLADM_STATUS_OK);
}
Ejemplo n.º 2
0
/* ARGSUSED */
static dladm_status_t
do_get_maxbw(dladm_handle_t handle, const char *flow, char **prop_val,
    uint_t *val_cnt)
{
	char 			buf[DLADM_STRSIZE];
	mac_resource_props_t	*mrp;
	dladm_flow_attr_t	fa;
	dladm_status_t		status;

	status = dladm_flow_info(handle, flow, &fa);
	if (status != DLADM_STATUS_OK)
		return (status);
	mrp = &(fa.fa_resource_props);

	*val_cnt = 1;
	if (mrp->mrp_mask & MRP_MAXBW) {
		(void) snprintf(prop_val[0], DLADM_STRSIZE, "%s",
		    dladm_bw2str(mrp->mrp_maxbw, buf));
	} else {
		return (DLADM_STATUS_NOTSUP);
	}
	return (DLADM_STATUS_OK);
}
Ejemplo n.º 3
0
static int
show_history_time(dladm_usage_t *history, void *arg)
{
	show_history_state_t	*state = (show_history_state_t *)arg;
	char			buf[DLADM_STRSIZE];
	history_l_fields_buf_t 	ubuf;
	time_t			time;
	double			bw;
	dladm_flow_attr_t	attr;
	dladm_status_t		status;

	/*
	 * Only show historical information for existing flows unless '-a'
	 * is specified.
	 */
	if (!state->us_showall && ((status = dladm_flow_info(handle,
	    history->du_name, &attr)) != DLADM_STATUS_OK)) {
		return (status);
	}

	if (state->us_plot) {
		if (!state->us_printheader) {
			if (state->us_first) {
				(void) printf("# Time");
				state->us_first = B_FALSE;
			}
			(void) printf(" %s", history->du_name);
			if (history->du_last) {
				(void) printf("\n");
				state->us_first = B_TRUE;
				state->us_printheader = B_TRUE;
			}
		} else {
			if (state->us_first) {
				time = history->du_etime;
				(void) strftime(buf, sizeof (buf), "%T",
				    localtime(&time));
				state->us_first = B_FALSE;
				(void) printf("%s", buf);
			}
			bw = (double)history->du_bandwidth/1000;
			(void) printf(" %.2f", bw);
			if (history->du_last) {
				(void) printf("\n");
				state->us_first = B_TRUE;
			}
		}
		return (DLADM_STATUS_OK);
	}

	bzero(&ubuf, sizeof (ubuf));

	(void) snprintf(ubuf.history_l_flow, sizeof (ubuf.history_l_flow), "%s",
	    history->du_name);
	time = history->du_stime;
	(void) strftime(buf, sizeof (buf), "%T", localtime(&time));
	(void) snprintf(ubuf.history_l_stime, sizeof (ubuf.history_l_stime),
	    "%s", buf);
	time = history->du_etime;
	(void) strftime(buf, sizeof (buf), "%T", localtime(&time));
	(void) snprintf(ubuf.history_l_etime, sizeof (ubuf.history_l_etime),
	    "%s", buf);
	(void) snprintf(ubuf.history_l_rbytes, sizeof (ubuf.history_l_rbytes),
	    "%llu", history->du_rbytes);
	(void) snprintf(ubuf.history_l_obytes, sizeof (ubuf.history_l_obytes),
	    "%llu", history->du_obytes);
	(void) snprintf(ubuf.history_l_bandwidth,
	    sizeof (ubuf.history_l_bandwidth), "%s Mbps",
	    dladm_bw2str(history->du_bandwidth, buf));

	ofmt_print(state->us_ofmt, (void *)&ubuf);
	return (DLADM_STATUS_OK);
}