]> git.sur5r.net Git - ngadmin/blob - lib/src/qos.c
553c87878503cfb12d5ca97df66f85f6e96d7b38
[ngadmin] / lib / src / qos.c
1
2 #include <ngadmin.h>
3
4 #include <nsdp/attr.h>
5 #include <nsdp/protocol.h>
6
7 #include "lib.h"
8 #include "network.h"
9
10
11 int ngadmin_getQOSMode (struct ngadmin *nga, int *s)
12 {
13         List *attr;
14         struct attr *at;
15         int ret = ERR_OK;
16         
17         
18         if (nga == NULL || s == NULL)
19                 return ERR_INVARG;
20         else if (nga->current == NULL)
21                 return ERR_NOTLOG;
22         
23         
24         attr = createEmptyList();
25         pushBackList(attr, newEmptyAttr(ATTR_QOS_TYPE));
26         ret = readRequest(nga, attr);
27         if (ret != ERR_OK)
28                 goto end;
29         
30         filterAttributes(attr, ATTR_QOS_TYPE, ATTR_END);
31         
32         *s = 0;
33         
34         if (attr->first != NULL) {
35                 at = attr->first->data;
36                 *s = *(char*)at->data;
37         }
38         
39         
40 end:
41         destroyList(attr, (void(*)(void*))freeAttr);
42         
43         
44         return ret;
45 }
46
47
48 int ngadmin_setQOSMode (struct ngadmin *nga, int s)
49 {
50         List *attr;
51         
52         
53         attr = createEmptyList();
54         pushBackList(attr, newByteAttr(ATTR_QOS_TYPE, s));
55         
56         
57         return writeRequest(nga, attr);
58 }
59
60
61 int ngadmin_getQOSValues (struct ngadmin *nga, char *ports)
62 {
63         List *attr;
64         ListNode *ln;
65         struct attr *at;
66         int ret = ERR_OK, port;
67         struct attr_qos *aq;
68         
69         
70         if (nga == NULL || ports == NULL)
71                 return ERR_INVARG;
72         else if (nga->current == NULL)
73                 return ERR_NOTLOG;
74         
75         
76         attr = createEmptyList();
77         pushBackList(attr, newEmptyAttr(ATTR_QOS_CONFIG));
78         ret = readRequest(nga, attr);
79         if (ret < 0)
80                 goto end;
81         
82         filterAttributes(attr, ATTR_QOS_CONFIG, ATTR_END);
83         
84         for (port = 0; port < nga->current->ports; port++)
85                 ports[port] = PRIO_UNSPEC;
86         
87         for (ln = attr->first; ln != NULL; ln = ln->next) {
88                 at = ln->data;
89                 aq = at->data;
90                 ports[aq->port - 1] = aq->prio;
91         }
92         
93         
94 end:
95         destroyList(attr, (void(*)(void*))freeAttr);
96         
97         
98         return ret;
99 }
100
101
102 int ngadmin_setQOSValues (struct ngadmin *nga, const char *ports)
103 {
104         List *attr;
105         int port;
106         struct attr_qos *aq;
107         
108         
109         if (nga == NULL || ports == NULL)
110                 return ERR_INVARG;
111         else if (nga->current == NULL)
112                 return ERR_NOTLOG;
113         
114         
115         attr = createEmptyList();
116         
117         for (port = 0; port < nga->current->ports; port++) {
118                 if (ports[port] >= PRIO_HIGH && ports[port] <= PRIO_LOW) {
119                         aq = malloc(sizeof(struct attr_qos));
120                         if (aq == NULL)
121                                 return ERR_MEM;
122                         aq->port = port + 1;
123                         aq->prio = ports[port];
124                         pushBackList(attr, newAttr(ATTR_QOS_CONFIG, sizeof(struct attr_qos), aq));
125                 }
126         }
127         
128         
129         return writeRequest(nga, attr);
130 }
131
132