]> git.sur5r.net Git - ngadmin/blob - cli/com_qos.c
Remove Makefiles and use autotools
[ngadmin] / cli / com_qos.c
1
2 #include "commands.h"
3
4
5 int do_qos_mode (int argc, const char **argv, struct ngadmin *nga)
6 {
7         int i, s, ret = 0;
8         const struct swi_attr *sa;
9         
10         
11         if (argc == 0) {
12                 printf("usage: qos mode port|802.1p\n");
13                 goto end;
14         }
15         
16         sa = ngadmin_getCurrentSwitch(nga);
17         if (sa == NULL) {
18                 printf("must be logged\n");
19                 ret = 1;
20                 goto end;
21         }
22         
23         if (strcasecmp(argv[0], "port") == 0) {
24                 s = QOS_PORT;
25         } else if (strcasecmp(argv[0], "802.1p") == 0) {
26                 s = QOS_DOT;
27         } else {
28                 printf("Unknown QOS mode\n");
29                 ret = 1;
30                 goto end;
31         }
32         
33         i = ngadmin_setQOSMode(nga, s);
34         printErrCode(i);
35         
36 end:
37         
38         return ret;
39 }
40
41
42 int do_qos_set (int argc, const char **argv, struct ngadmin *nga)
43 {
44         int i, p, ret = 0;
45         const struct swi_attr *sa;
46         char d = PRIO_UNSPEC, *ports = NULL;
47         
48         
49         if (argc < 2) {
50                 printf("usage: qos set (all <prio0>)|(<port1> <prio1> [<port2> <prio2> ...])\n");
51                 ret = 1;
52                 goto end;
53         }
54         
55         sa = ngadmin_getCurrentSwitch(nga);
56         if (sa ==NULL) {
57                 printf("must be logged\n");
58                 ret = 1;
59                 goto end;
60         }
61         
62         ports = malloc(sa->ports * sizeof(char));
63         
64         /* read defaults */
65         if (strcmp(argv[0], "all") == 0) {
66                 d = parsePrio(argv[1]);
67                 argv += 2;
68                 argc -= 2;
69         }
70         
71         /* apply defaults */
72         for (i = 0; i < sa->ports; i++)
73                 ports[i] = d;
74         
75         /* read and apply port specifics */
76         for (i = 0; i < argc; i += 2) {
77                 p = strtol(argv[i], NULL, 0);
78                 if (p < 1 || p > sa->ports)
79                         continue;
80                 ports[p - 1] = parsePrio(argv[i + 1]);
81         }
82         
83         /* send the new configuration to the switch */
84         i = ngadmin_setQOSValues(nga, ports);
85         printErrCode(i);
86         
87 end:
88         free(ports);
89         
90         return ret;
91 }
92
93
94 int do_qos_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
95 {
96         int i, s = 0, ret = 0;
97         const struct swi_attr *sa;
98         char *ports = NULL;
99         
100         
101         if (argc > 0) {
102                 printf("this command takes no argument\n");
103                 ret = 1;
104                 goto end;
105         }
106         
107         sa = ngadmin_getCurrentSwitch(nga);
108         if (sa == NULL) {
109                 printf("must be logged\n");
110                 ret = 1;
111                 goto end;
112         }
113         
114         i = ngadmin_getQOSMode(nga, &s);
115         if (i != ERR_OK) {
116                 printErrCode(i);
117                 ret = 1;
118                 goto end;
119         }
120         
121         printf("QoS mode: ");
122         switch (s) {
123         
124         case QOS_DOT:
125                 printf("802.1p\n");
126                 goto end;
127         
128         case QOS_PORT:
129                 printf("port based\n");
130                 break;
131                 
132         default:
133                 printf("unknown (%i)\n", s);
134                 goto end;
135         }
136         
137         ports = malloc(sa->ports * sizeof(char));
138         i = ngadmin_getQOSValues(nga, ports);
139         if (i != ERR_OK) {
140                 printErrCode(i);
141                 ret = 1;
142                 goto end;
143         }
144         
145         for (i = 0; i < sa->ports; i++)
146                 printf("port %i: %s\n", i + 1, prio[(int)ports[i]]);
147         
148 end:
149         free(ports);
150         
151         return ret;
152 }
153
154