]> git.sur5r.net Git - ngadmin/blob - cli/src/com_ports.c
6cf0c813e492f25e3b91d2b4e0c3d406486bb292
[ngadmin] / cli / src / com_ports.c
1
2 #include "commands.h"
3
4
5 int do_ports_state (int argc, const char **argv UNUSED, struct ngadmin *nga)
6 {
7         int i, ret = 0;
8         const struct swi_attr *sa;
9         unsigned char *ports = NULL;
10         
11         
12         if (argc > 0) {
13                 printf("this command takes no argument\n");
14                 ret = 1;
15                 goto end;
16         }
17         
18         sa = ngadmin_getCurrentSwitch(nga);
19         if (sa == NULL) {
20                 printf("must be logged\n");
21                 ret = 1;
22                 goto end;
23         }
24         
25         ports = malloc(sa->ports * sizeof(unsigned char));
26         i = ngadmin_getPortsStatus(nga, ports);
27         if (i < 0) {
28                 printErrCode(i);
29                 ret = 1;
30                 goto end;
31         }
32         
33         for (i = 0; i < sa->ports; i++) {
34                 printf("port %i: ", i + 1);
35                 switch (ports[i]) {
36                 
37                 case 0:
38                         printf("down");
39                         break;
40                 
41                 case SPEED_10_HD:
42                         printf("up, 10M half-duplex");
43                         break;
44                 
45                 case SPEED_10_FD:
46                         printf("up, 10M full-duplex");
47                         break;
48                 
49                 case SPEED_100_HD:
50                         printf("up, 100M half-duplex");
51                         break;
52                 
53                 case SPEED_100_FD:
54                         printf("up, 100M full-duplex");
55                         break;
56                 
57                 case SPEED_1000_FD:
58                         printf("up, 1000M full-duplex");
59                         break;
60                 
61                 default:
62                         printf("unknown (%i)", ports[i]);
63                 }
64                 putchar('\n');
65         }
66         
67 end:
68         free(ports);
69         
70         
71         return ret;
72 }
73
74
75 int do_ports_statistics_reset (int argc, const char **argv UNUSED, struct ngadmin *nga)
76 {
77         int i;
78         
79         
80         if (argc > 0) {
81                 printf("this command takes no argument\n");
82                 return 1;
83         }
84         
85         if (ngadmin_getCurrentSwitch(nga) == NULL) {
86                 printf("must be logged\n");
87                 return 1;
88         }
89         
90         i = ngadmin_resetPortsStatistics(nga);
91         printErrCode(i);
92         
93         return 0;
94 }
95
96
97 int do_ports_statistics_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
98 {
99         int i, ret = 0;
100         const struct swi_attr *sa;
101         struct port_stats *ps = NULL;
102         
103         
104         if (argc > 0) {
105                 printf("this command takes no argument\n");
106                 ret = 1;
107                 goto end;
108         }
109         
110         sa = ngadmin_getCurrentSwitch(nga);
111         if (sa == NULL) {
112                 printf("must be logged\n");
113                 ret = 1;
114                 goto end;
115         }
116         
117         ps = calloc(sa->ports, sizeof(struct port_stats));
118         i = ngadmin_getPortsStatistics(nga, ps);
119         if (i < 0) {
120                 printErrCode(i);
121                 ret = 1;
122                 goto end;
123         }
124         
125         printf("Port\tReceived\tSent\tCRC errors\n");
126         for (i = 0; i < sa->ports; i++)
127                 printf("% 4i%12llu%12llu%14llu\n", i + 1, ps[i].recv, ps[i].sent, ps[i].crc);
128         
129 end:
130         free(ps);
131         
132         return ret;
133 }
134
135