test_qos.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)yahoo.fr>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_QOS_H_
  23. #define _TEST_QOS_H_
  24. char* test_qos_tostring(const tmedia_qos_tline_t* tline)
  25. {
  26. char* ret = tsk_null;
  27. tsdp_header_M_t* M;
  28. if(!tline) {
  29. TSK_DEBUG_ERROR("Invalid parameter");
  30. return tsk_null;
  31. }
  32. M = tsdp_header_M_create("audio", 20000, "RTP/AVP");
  33. tmedia_qos_tline_to_sdp(tline, M);
  34. ret = tsdp_header_tostring(TSDP_HEADER(M));
  35. TSK_OBJECT_SAFE_FREE(M);
  36. return ret;
  37. }
  38. void test_qos_parser()
  39. {
  40. tsdp_header_M_t* M;
  41. tmedia_qos_tline_e2e_t* e2e;
  42. tmedia_qos_tline_segmented_t* segmented;
  43. char* temp = tsk_null;
  44. tmedia_qos_stype_t type;
  45. tsk_bool_t canresume;
  46. /* test E2E */
  47. M = tsdp_header_M_create("audio", 20000, "RTP/AVP");
  48. e2e = tmedia_qos_tline_e2e_create(tmedia_qos_strength_mandatory);
  49. // to_sdp
  50. tmedia_qos_tline_e2e_to_sdp(e2e, M);
  51. if((type = tmedia_qos_get_type(M)) != tmedia_qos_stype_e2e) {
  52. TSK_DEBUG_ERROR("Invalid type");
  53. }
  54. if((temp = tsdp_header_tostring(TSDP_HEADER(M)))) {
  55. TSK_DEBUG_INFO("E2E to_sdp: %s", temp);
  56. TSK_FREE(temp);
  57. }
  58. // from_sdp
  59. TSK_OBJECT_SAFE_FREE(e2e);
  60. e2e = tmedia_qos_tline_e2e_from_sdp(M);
  61. canresume = tmedia_qos_tline_e2e_canresume(e2e);
  62. tmedia_qos_tline_e2e_to_sdp(e2e, M);
  63. if((temp = tsdp_header_tostring(TSDP_HEADER(M)))) {
  64. TSK_DEBUG_INFO("e2e from_sdp: %s", temp);
  65. TSK_FREE(temp);
  66. }
  67. TSK_OBJECT_SAFE_FREE(e2e);
  68. TSK_OBJECT_SAFE_FREE(M);
  69. /* test Segmented */
  70. M = tsdp_header_M_create("video", 20002, "RTP/AVP");
  71. segmented = tmedia_qos_tline_segmented_create(tmedia_qos_strength_none);
  72. segmented->remote_send.strength = tmedia_qos_strength_optional;
  73. // to_sdp
  74. tmedia_qos_tline_segmented_to_sdp(segmented, M);
  75. if((type = tmedia_qos_get_type(M)) != tmedia_qos_stype_segmented) {
  76. TSK_DEBUG_ERROR("Invalid type");
  77. }
  78. if((temp = tsdp_header_tostring(TSDP_HEADER(M)))) {
  79. TSK_DEBUG_INFO("Segmented to_sdp: %s", temp);
  80. TSK_FREE(temp);
  81. }
  82. // from_sdp
  83. TSK_OBJECT_SAFE_FREE(segmented);
  84. segmented = tmedia_qos_tline_segmented_from_sdp(M);
  85. canresume = tmedia_qos_tline_segmented_canresume(segmented);
  86. tmedia_qos_tline_segmented_to_sdp(segmented, M);
  87. if((temp = tsdp_header_tostring(TSDP_HEADER(M)))) {
  88. TSK_DEBUG_INFO("Segmented from_sdp: %s", temp);
  89. TSK_FREE(temp);
  90. }
  91. TSK_OBJECT_SAFE_FREE(segmented);
  92. TSK_OBJECT_SAFE_FREE(M);
  93. }
  94. void test_qos_e2e_neg()
  95. {
  96. tmedia_qos_tline_e2e_t *e2eA = tsk_null, *e2eB = tsk_null;
  97. char* temp = tsk_null;
  98. /* SDP1: A includes end-to-end quality of service preconditions in the
  99. initial offer.
  100. m=audio 20000 RTP/AVP 0
  101. c=IN IP4 192.0.2.1
  102. a=curr:qos e2e none
  103. a=des:qos mandatory e2e sendrecv
  104. */
  105. e2eA = tmedia_qos_tline_e2e_create(tmedia_qos_strength_mandatory);
  106. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)e2eA))) {
  107. TSK_DEBUG_INFO("SDP1=\n%s", temp);
  108. TSK_FREE(temp);
  109. }
  110. /* SDP2: Since B uses RSVP, it can know when resources in its "send"
  111. direction are available, because it will receive RESV messages from
  112. the network. However, it does not know the status of the
  113. reservations in the other direction. B requests confirmation for
  114. resource reservations in its "recv" direction to the peer user agent
  115. A in its answer.
  116. m=audio 30000 RTP/AVP 0
  117. c=IN IP4 192.0.2.4
  118. a=curr:qos e2e none
  119. a=des:qos mandatory e2e sendrecv
  120. a=conf:qos e2e recv
  121. */
  122. e2eB = tmedia_qos_tline_e2e_create(tmedia_qos_strength_mandatory);
  123. tmedia_qos_tline_e2e_set_ro(e2eB, e2eA);
  124. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)e2eB))) {
  125. TSK_DEBUG_INFO("SDP2=\n%s", temp);
  126. TSK_FREE(temp);
  127. }
  128. /* SDP3: When A receives RESV messages, it sends an updated offer (5) to B:
  129. m=audio 20000 RTP/AVP 0
  130. c=IN IP4 192.0.2.1
  131. a=curr:qos e2e send
  132. a=des:qos mandatory e2e sendrecv
  133. */
  134. tmedia_qos_tline_e2e_set_ro(e2eA, e2eB);
  135. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)e2eA))) {
  136. TSK_DEBUG_INFO("SDP3=\n%s", temp);
  137. TSK_FREE(temp);
  138. }
  139. /* SDP4: B responds with an answer (6) which contains the current status
  140. of the resource reservation (i.e., sendrecv):
  141. m=audio 30000 RTP/AVP 0
  142. c=IN IP4 192.0.2.4
  143. a=curr:qos e2e sendrecv
  144. a=des:qos mandatory e2e sendrecv
  145. */
  146. tmedia_qos_tline_e2e_set_ro(e2eB, e2eA);
  147. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)e2eB))) {
  148. TSK_DEBUG_INFO("SDP4=\n%s", temp);
  149. TSK_FREE(temp);
  150. }
  151. /* A receive B's response */
  152. tmedia_qos_tline_e2e_set_ro(e2eA, e2eB);
  153. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)e2eA))) {
  154. TSK_DEBUG_INFO("SDP5=\n%s", temp);
  155. TSK_FREE(temp);
  156. }
  157. if(tmedia_qos_tline_e2e_canresume(e2eA)) {
  158. TSK_DEBUG_INFO("A can resume");
  159. }
  160. else {
  161. TSK_DEBUG_ERROR("A can't resume");
  162. }
  163. if(tmedia_qos_tline_e2e_canresume(e2eB)) {
  164. TSK_DEBUG_INFO("B can resume");
  165. }
  166. else {
  167. TSK_DEBUG_ERROR("B can't resume");
  168. }
  169. TSK_OBJECT_SAFE_FREE(e2eB);
  170. TSK_OBJECT_SAFE_FREE(e2eA);
  171. }
  172. void test_qos_segmented_neg()
  173. {
  174. tmedia_qos_tline_segmented_t *segA = tsk_null, *segB = tsk_null;
  175. char* temp = tsk_null;
  176. /* INVITE
  177. a=curr:qos local none
  178. a=curr:qos remote none
  179. a=des:qos mandatory local sendrecv
  180. a=des:qos mandatory remote sendrecv
  181. */
  182. segA = tmedia_qos_tline_segmented_create(tmedia_qos_strength_mandatory);
  183. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)segA))) {
  184. TSK_DEBUG_INFO("INVITE=\n%s", temp);
  185. TSK_FREE(temp);
  186. }
  187. /* 183 Sesson progress
  188. a=curr:qos local none
  189. a=curr:qos remote none
  190. a=des:qos mandatory local sendrecv
  191. a=des:qos mandatory remote sendrecv
  192. a=conf:qos remote sendrecv
  193. */
  194. segB = tmedia_qos_tline_segmented_create(tmedia_qos_strength_mandatory);
  195. tmedia_qos_tline_segmented_set_ro(segB, segA);
  196. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)segB))) {
  197. TSK_DEBUG_INFO("183=\n%s", temp);
  198. TSK_FREE(temp);
  199. }
  200. /* UPDATE
  201. a=curr:qos local sendrecv
  202. a=curr:qos remote none
  203. a=des:qos mandatory local sendrecv
  204. a=des:qos mandatory remote sendrecv
  205. */
  206. tmedia_qos_tline_segmented_set_ro(segA, segB);
  207. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)segA))) {
  208. TSK_DEBUG_INFO("UPDATE=\n%s", temp);
  209. TSK_FREE(temp);
  210. }
  211. /* 200 OK
  212. a=curr:qos local sendrecv
  213. a=curr:qos remote sendrecv
  214. a=des:qos mandatory local sendrecv
  215. a=des:qos mandatory remote sendrecv
  216. */
  217. tmedia_qos_tline_segmented_set_ro(segB, segA);
  218. if((temp = test_qos_tostring((const tmedia_qos_tline_t*)segB))) {
  219. TSK_DEBUG_INFO("200OK=\n%s", temp);
  220. TSK_FREE(temp);
  221. }
  222. TSK_OBJECT_SAFE_FREE(segA);
  223. TSK_OBJECT_SAFE_FREE(segB);
  224. }
  225. void test_qos()
  226. {
  227. //test_qos_parser();
  228. //test_qos_e2e_neg();
  229. test_qos_segmented_neg();
  230. }
  231. #endif /* _TEST_QOS_H_ */