7 static bool do_ports_state (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
10 const struct swi_attr *sa;
11 unsigned char *ports=NULL;
15 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
16 printf("must be logged\n");
22 ports=malloc(sa->ports*sizeof(unsigned char));
23 if ( (i=ngadmin_getPortsStatus(nga, ports))<0 ) {
29 for (i=0; i<sa->ports; i++) {
30 printf("port %i: ", i+1);
32 case 0: printf("down"); break;
33 case SPEED_10: printf("up, 10M"); break;
34 case SPEED_100: printf("up, 100M"); break;
35 case SPEED_1000: printf("up, 1000M"); break;
36 default: printf("unknown (%i)", ports[i]);
51 static bool do_ports_stats_show (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
54 const struct swi_attr *sa;
56 struct port_stats *ps=NULL;
59 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
60 printf("must be logged\n");
65 ps=calloc(sa->ports, sizeof(struct port_stats));
66 if ( (i=ngadmin_getPortsStatistics(nga, ps))<0 ) {
72 printf("Port\tReceived\tSent\t\tCRC errors\n");
73 for (i=0; i<sa->ports; ++i) {
74 printf("%i\t%8llu\t%8llu\t%8llu\n", i+1, ps[i].recv, ps[i].sent, ps[i].crc);
87 static bool do_ports_stats_reset (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
92 if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
93 printf("must be logged\n");
97 i=ngadmin_resetPortsStatistics(nga);
107 static const struct TreeNode com_ports_state=COM("state", do_ports_state, false, NULL);
109 static const struct TreeNode com_ports_stats_show=COM("show", do_ports_stats_show, false, NULL);
110 static const struct TreeNode com_ports_stats_reset=COM("reset", do_ports_stats_reset, false, NULL);
111 static const struct TreeNode com_ports_stats=COM("stats", NULL, false, &com_ports_stats_reset, &com_ports_stats_show, NULL);
113 const struct TreeNode com_ports=COM("ports", NULL, false, &com_ports_state, &com_ports_stats, NULL);