]> git.sur5r.net Git - ngadmin/blob - lib/src/qos.c
Merge remote-tracking branch 'upstream/master'
[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                 ret = ERR_BADREPLY;
36                 goto end;
37         }
38         at = attr->first->data;
39         if (at->size != 1) {
40                 ret = ERR_BADREPLY;
41                 goto end;
42         }
43         *s = *(char*)at->data;
44         
45         
46 end:
47         destroyList(attr, (void(*)(void*))freeAttr);
48         
49         
50         return ret;
51 }
52
53
54 int ngadmin_setQOSMode (struct ngadmin *nga, int s)
55 {
56         List *attr;
57         
58         
59         attr = createEmptyList();
60         pushBackList(attr, newByteAttr(ATTR_QOS_TYPE, s));
61         
62         
63         return writeRequest(nga, attr);
64 }
65
66
67 int ngadmin_getQOSValues (struct ngadmin *nga, char *ports)
68 {
69         List *attr;
70         ListNode *ln;
71         struct attr *at;
72         int ret = ERR_OK, port;
73         struct attr_qos *aq;
74         struct swi_attr *sa;
75         
76         
77         if (nga == NULL || ports == NULL)
78                 return ERR_INVARG;
79         
80         sa = nga->current;
81         if (sa == NULL)
82                 return ERR_NOTLOG;
83         
84         attr = createEmptyList();
85         pushBackList(attr, newEmptyAttr(ATTR_QOS_CONFIG));
86         ret = readRequest(nga, attr);
87         if (ret < 0)
88                 goto end;
89         
90         filterAttributes(attr, ATTR_QOS_CONFIG, ATTR_END);
91         
92         for (port = 0; port < sa->ports; port++)
93                 ports[port] = PRIO_UNSPEC;
94         
95         for (ln = attr->first; ln != NULL; ln = ln->next) {
96                 at = ln->data;
97                 aq = at->data;
98                 if (at->size == 0) {
99                         ret = ERR_BADREPLY;
100                         goto end;
101                 }
102                 if (aq->port <= sa->ports)
103                         ports[aq->port - 1] = aq->prio;
104         }
105         
106         
107 end:
108         destroyList(attr, (void(*)(void*))freeAttr);
109         
110         
111         return ret;
112 }
113
114
115 int ngadmin_setQOSValues (struct ngadmin *nga, const char *ports)
116 {
117         List *attr;
118         int port;
119         struct attr_qos *aq;
120         
121         
122         if (nga == NULL || ports == NULL)
123                 return ERR_INVARG;
124         else if (nga->current == NULL)
125                 return ERR_NOTLOG;
126         
127         
128         attr = createEmptyList();
129         
130         for (port = 0; port < nga->current->ports; port++) {
131                 if (ports[port] >= PRIO_HIGH && ports[port] <= PRIO_LOW) {
132                         aq = malloc(sizeof(struct attr_qos));
133                         if (aq == NULL)
134                                 return ERR_MEM;
135                         aq->port = port + 1;
136                         aq->prio = ports[port];
137                         pushBackList(attr, newAttr(ATTR_QOS_CONFIG, sizeof(struct attr_qos), aq));
138                 }
139         }
140         
141         
142         return writeRequest(nga, attr);
143 }
144
145