6 // helper function to analyse bitrate speed specifications
7 static int bitrate_analyse (int nb, const char **com, int *ports) {
13 s=parseBitrate(com[i+1]);
14 if ( strcmp(com[i], "inout")==0 ) {
17 } else if ( strcmp(com[i], "in")==0 ) {
19 } else if ( strcmp(com[i], "out")==0 ) {
34 bool do_bitrate_set (int nb, const char **com, struct ngadmin *nga) {
36 int i, k=0, defs[]={12, 12}, p, *ports=NULL;
37 const struct swi_attr *sa;
42 printf("Usage: bitrate set [all SPEEDSPEC] <port1> SPEEDSPEC [<port2> SPEEDSPEC ...]\n");
43 printf("SPEEDSPEC: [inout <speed>] [in <ispeed>] [out <ospeed>]\n");
48 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
49 printf("must be logged\n");
54 ports=malloc(2*sa->ports*sizeof(int));
56 // get defaults if present
57 if ( strcmp(com[k], "all")==0 ) {
59 k+=bitrate_analyse(nb-k, &com[k], defs);
63 for (i=0; i<sa->ports; ++i) {
64 memcpy(&ports[2*i], defs, sizeof(defs));
67 // get ports specifics
69 p=strtol(com[k++], NULL, 0)-1;
70 if ( p>=0 && p<sa->ports ) {
71 k+=bitrate_analyse(nb-k, &com[k], &ports[2*p]);
75 // send it to the switch
76 i=ngadmin_setBitrateLimits(nga, ports);
89 bool do_bitrate_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
91 int i, ret=true, *ports=NULL;
92 const struct swi_attr *sa;
95 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
96 printf("must be logged\n");
102 ports=malloc(2*sa->ports*sizeof(int));
103 if ( (i=ngadmin_getBitrateLimits(nga, ports))!=ERR_OK ) {
109 for (i=0; i<sa->ports; ++i) {
110 printf("port %i: in %s, out %s\n", i+1, bitrates[ports[2*i+0]], bitrates[ports[2*i+1]]);