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