]> git.sur5r.net Git - ngadmin/blob - cli/com_ports.c
baa8c8f3a6fe3dcca1c36deae8902e46195553af
[ngadmin] / cli / com_ports.c
1
2 #include "commands.h"
3
4
5
6 bool do_ports_state (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
7  
8  int i;
9  const struct swi_attr *sa;
10  unsigned char *ports=NULL;
11  bool ret=true;
12  
13  
14  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
15   printf("must be logged\n");
16   ret=false;
17   goto end;
18  }
19  
20  
21  ports=malloc(sa->ports*sizeof(unsigned char));
22  if ( (i=ngadmin_getPortsStatus(nga, ports))<0 ) {
23   printErrCode(i);
24   ret=false;
25   goto end;
26  }
27  
28  for (i=0; i<sa->ports; i++) {
29   printf("port %i: ", i+1);
30   switch ( ports[i] ) {
31    case 0: printf("down"); break;
32    case SPEED_10: printf("up, 10M"); break;
33    case SPEED_100: printf("up, 100M"); break;
34    case SPEED_1000: printf("up, 1000M"); break;
35    default: printf("unknown (%i)", ports[i]);
36   }
37   putchar('\n');
38  }
39  
40  end:
41  free(ports);
42  
43  
44  return ret;
45  
46 }
47
48
49
50 bool do_ports_statistics_reset (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
51  
52  int i;
53  
54  
55  if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
56   printf("must be logged\n");
57   return false;
58  }
59  
60  i=ngadmin_resetPortsStatistics(nga);
61  printErrCode(i);
62  
63  
64  return true;
65  
66 }
67
68
69
70 bool do_ports_statistics_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
71  
72  int i;
73  const struct swi_attr *sa;
74  bool ret=true;
75  struct port_stats *ps=NULL;
76  
77  
78  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
79   printf("must be logged\n");
80   ret=false;
81   goto end;
82  }
83  
84  ps=calloc(sa->ports, sizeof(struct port_stats));
85  if ( (i=ngadmin_getPortsStatistics(nga, ps))<0 ) {
86   printErrCode(i);
87   ret=false;
88   goto end;
89  }
90  
91  printf("Port\tReceived\tSent\tCRC errors\n");
92  for (i=0; i<sa->ports; ++i) {
93   printf("% 4i%12llu%12llu%14llu\n", i+1, ps[i].recv, ps[i].sent, ps[i].crc);
94  }
95  
96  end:
97  free(ps);
98  
99  
100  return ret;
101  
102 }
103
104
105