test-fullmode.c 40.7 KB
Newer Older
1
2
3
/*
 * This file is part of the Nice GLib ICE library.
 *
4
5
 * Unit test for ICE full-mode related features.
 *
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * (C) 2007 Nokia Corporation. All rights reserved.
 *  Contact: Kai Vehmanen
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Nice GLib ICE library.
 *
 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
 * Corporation. All Rights Reserved.
 *
 * Contributors:
 *   Kai Vehmanen, Nokia
 *
 * Alternatively, the contents of this file may be used under the terms of the
 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
 * case the provisions of LGPL are applicable instead of those above. If you
 * wish to allow use of your version of this file only under the terms of the
 * LGPL and not to allow others to use your version of this file under the
 * MPL, indicate your decision by deleting the provisions above and replace
 * them with the notice and other provisions required by the LGPL. If you do
 * not delete the provisions above, a recipient may use your version of this
 * file under either the MPL or the LGPL.
 */
37
38
39
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
40

Youness Alaoui's avatar
Youness Alaoui committed
41
42
#include "agent.h"

43
44
45
46
#include <stdlib.h>
#include <string.h>


47
48
#define USE_TURN 0
#define USE_LOOPBACK 1
49
#define TEST_GOOGLE 0
50

51
52
53
54
55
56
57
#define PROXY_IP "127.0.0.1"
#define PROXY_PORT 1080
#define PROXY_TYPE NICE_PROXY_TYPE_SOCKS5
#define PROXY_USERNAME NULL
#define PROXY_PASSWORD NULL


58
59
60
61
62
63
64
#if TEST_GOOGLE
#define NICE_COMPATIBILITY NICE_COMPATIBILITY_GOOGLE

#if USE_TURN
#undef USE_LOOPBACK
#define USE_LOOPBACK 0

65
#define TURN_IP "209.85.163.126"
66
#define TURN_PORT 443
67
68
69
70
#define TURN_USER "ih9ppiM0P6vN34DB"
#define TURN_PASS ""
#define TURN_USER2 TURN_USER
#define TURN_PASS2 TURN_PASS
71
#define TURN_TYPE NICE_RELAY_TYPE_TURN_TLS
72
73
74
75
76

#endif

#else
#define NICE_COMPATIBILITY NICE_COMPATIBILITY_DRAFT19
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#if USE_LOOPBACK
#define USE_TURN_SERVER_ORG 1
#else
#define USE_TURN_SERVER_ORG 0
#endif

#define NUMB_IP "64.251.22.149"
#define NUMB_PORT 3478
#define NUMB_USER "youness.alaoui@collabora.co.uk"
#define NUMB_PASS "badger"

#define TSORG_IP "127.0.0.1"
#define TSORG_PORT 3478
#define TSORG_USER "toto"
#define TSORG_PASS "password"


#if USE_TURN_SERVER_ORG
#define TURN_IP TSORG_IP
#define TURN_PORT TSORG_PORT
#define TURN_USER TSORG_USER
#define TURN_PASS TSORG_PASS
99
100
#define TURN_USER2 TSORG_USER
#define TURN_PASS2 TSORG_PASS
101
#define TURN_TYPE NICE_RELAY_TYPE_TURN_TCP
102
103
104
105
106
#else
#define TURN_IP NUMB_IP
#define TURN_PORT NUMB_PORT
#define TURN_USER NUMB_USER
#define TURN_PASS NUMB_PASS
107
108
#define TURN_USER2 NUMB_USER
#define TURN_PASS2 NUMB_PASS
109
#define TURN_TYPE NICE_RELAY_TYPE_TURN_UDP
110
111
#endif

112
113
#endif

114

115
116
static NiceComponentState global_lagent_state[2] = { NICE_COMPONENT_STATE_LAST, NICE_COMPONENT_STATE_LAST };
static NiceComponentState global_ragent_state[2] = { NICE_COMPONENT_STATE_LAST, NICE_COMPONENT_STATE_LAST };
117
118
119
120
static guint global_components_ready = 0;
static guint global_components_ready_exit = 0;
static guint global_components_failed = 0;
static guint global_components_failed_exit = 0;
121
static GMainLoop *global_mainloop = NULL;
122
123
static gboolean global_lagent_gathering_done = FALSE;
static gboolean global_ragent_gathering_done = FALSE;
124
125
126
127
static gboolean global_lagent_ibr_received = FALSE;
static gboolean global_ragent_ibr_received = FALSE;
static int global_lagent_cands = 0;
static int global_ragent_cands = 0;
128
static gint global_ragent_read = 0;
129
static guint global_exit_when_ibr_received = 0;
130

131
static void priv_print_global_status (void)
132
{
133
  g_debug ("\tgathering_done=%d", global_lagent_gathering_done && global_ragent_gathering_done);
134
135
  g_debug ("\tlstate[rtp]=%d [rtcp]=%d", global_lagent_state[0], global_lagent_state[1]);
  g_debug ("\trstate[rtp]=%d [rtcp]=%d", global_ragent_state[0], global_ragent_state[1]);
136
  g_debug ("\tL cands=%d R cands=%d", global_lagent_cands, global_ragent_cands);
137
138
139
140
}

static gboolean timer_cb (gpointer pointer)
{
141
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, pointer);
142
143
144
145

  /* signal status via a global variable */

  /* note: should not be reached, abort */
146
  g_error ("ERROR: test has got stuck, aborting...");
147
148
149
150
}

static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
{
151
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, user_data);
152
153

  /* XXX: dear compiler, these are for you: */
154
155
  (void)agent; (void)stream_id; (void)component_id; (void)buf;

156
157
158
159
160
161
162
163
  /*
   * Lets ignore stun packets that got through
   */
  if (len < 8)
    return;
  if (strncmp ("12345678", buf, 8))
    return;

164
  if (GPOINTER_TO_UINT (user_data) == 2) {
165
166
167
    global_ragent_read = len;
    g_main_loop_quit (global_mainloop);
  }
168
169
}

170
static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
171
{
172
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
173

174
  if (GPOINTER_TO_UINT (data) == 1)
175
    global_lagent_gathering_done = TRUE;
176
  else if (GPOINTER_TO_UINT (data) == 2)
177
178
179
180
181
    global_ragent_gathering_done = TRUE;

  if (global_lagent_gathering_done &&
      global_ragent_gathering_done)
    g_main_loop_quit (global_mainloop);
182
183
184
185
186

  /* XXX: dear compiler, these are for you: */
  (void)agent;
}

187
188
static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
{
189
  g_debug ("test-fullmode:%s: %p", __func__, data);
190

191
  if (GPOINTER_TO_UINT (data) == 1)
192
    global_lagent_state[component_id - 1] = state;
193
  else if (GPOINTER_TO_UINT (data) == 2)
194
    global_ragent_state[component_id - 1] = state;
195
196
197
198
199
200
  
  if (state == NICE_COMPONENT_STATE_READY)
    global_components_ready++;
  if (state == NICE_COMPONENT_STATE_FAILED)
    global_components_failed++;

201
202
  g_debug ("test-fullmode: checks READY/EXIT-AT %u/%u.", global_components_ready, global_components_ready_exit);
  g_debug ("test-fullmode: checks FAILED/EXIT-AT %u/%u.", global_components_failed, global_components_failed_exit);
203
204

  /* signal status via a global variable */
205
206
  if (global_components_ready == global_components_ready_exit &&
      global_components_failed == global_components_failed_exit) {
207
208
209
210
    g_main_loop_quit (global_mainloop); 
    return;
  }

211
#if 0
212
213
214
215
216
  /* signal status via a global variable */
  if (global_components_failed == global_components_failed_exit) {
    g_main_loop_quit (global_mainloop); 
    return;
  }
217
#endif
218
219
220
221

  /* XXX: dear compiler, these are for you: */
  (void)agent; (void)stream_id; (void)data; (void)component_id;
}
222
223
224
225

static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id, 
				 gchar *lfoundation, gchar* rfoundation, gpointer data)
{
226
  g_debug ("test-fullmode:%s: %p", __func__, data);
227

228
  if (GPOINTER_TO_UINT (data) == 1)
229
    ++global_lagent_cands;
230
  else if (GPOINTER_TO_UINT (data) == 2)
231
232
233
    ++global_ragent_cands;

  /* XXX: dear compiler, these are for you: */
234
  (void)agent; (void)stream_id; (void)component_id; (void)lfoundation; (void)rfoundation;
235
236
237
238
239
}

static void cb_new_candidate(NiceAgent *agent, guint stream_id, guint component_id, 
			     gchar *foundation, gpointer data)
{
240
  g_debug ("test-fullmode:%s: %p", __func__, data);
241

242
  /* XXX: dear compiler, these are for you: */
243
  (void)agent; (void)stream_id; (void)data; (void)component_id; (void)foundation;
244
245
246
247
}

static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_id, gpointer data)
{
248
  g_debug ("test-fullmode:%s: %p", __func__, data);
249

250
  if (GPOINTER_TO_UINT (data) == 1)
251
    global_lagent_ibr_received = TRUE;
252
  else if (GPOINTER_TO_UINT (data) == 2)
253
254
    global_ragent_ibr_received = TRUE;

255
256
257
  if (global_exit_when_ibr_received)
    g_main_loop_quit (global_mainloop);     

258
259
260
261
  /* XXX: dear compiler, these are for you: */
  (void)agent; (void)stream_id; (void)data;
}

262
263
264
265
266
267
268
269
270
271
272
static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint component_id, NiceAddress *dstaddr)
{
  GSList *cands, *i;
  cands = nice_agent_get_local_candidates(agent, stream_id, component_id);
  for (i = cands; i; i = i->next) {
    NiceCandidate *cand = i->data;
    if (cand) {
      g_assert (dstaddr);
      *dstaddr = cand->addr;
    }
  }
273
274
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
275
276
277
  g_slist_free (cands);
}

Olivier Crete's avatar
Olivier Crete committed
278

279
280
281
282
283
284
285
286
287
288
289
290
static GSList *priv_get_local_candidate (NiceAgent *agent, guint stream_id, guint component_id)
{
  GSList *cands, *i;
  GSList *result = NULL;
  NiceCandidate *out_cand = NULL;
  cands = nice_agent_get_local_candidates(agent, stream_id, component_id);
  for (i = cands; i; i = i->next) {
    NiceCandidate *cand = i->data;
    if (cand) {
      out_cand = cand;
    }
  }
291
292
293
294
  result = g_slist_append (result, nice_candidate_copy (out_cand));

  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
295
296
297
298
299
  g_slist_free (cands);
  return result;
}


Olivier Crete's avatar
Olivier Crete committed
300
301
302
303
304
305
306
307
308
309
310

static void init_candidate (NiceCandidate *cand)
{
  memset (cand, 0, sizeof(NiceCandidate));

  cand->priority = 10000;
  strcpy (cand->foundation, "1");
  cand->type = NICE_CANDIDATE_TYPE_HOST;
  cand->transport = NICE_CANDIDATE_TRANSPORT_UDP;
}

311
static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, guint ready, guint failed)
312
{
313
  //  NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;   
Olivier Crete's avatar
Olivier Crete committed
314
  NiceCandidate cdes;
315
  GSList *cands, *i;
316
317
  guint ls_id, rs_id;

Olivier Crete's avatar
Olivier Crete committed
318
319
  init_candidate (&cdes);

320
321
322
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

323
324
  /* step: initialize variables modified by the callbacks */
  global_components_ready = 0;
325
  global_components_ready_exit = ready;
326
  global_components_failed = 0;
327
  global_components_failed_exit = failed;
328
329
330
331
  global_lagent_gathering_done = FALSE;
  global_ragent_gathering_done = FALSE;
  global_lagent_ibr_received =
    global_ragent_ibr_received = FALSE;
332
  global_lagent_cands =
333
334
335
336
337
    global_ragent_cands = 0;

  g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);

338
339
  /* step: add one stream, with RTP+RTCP components, to each agent */
  ls_id = nice_agent_add_stream (lagent, 2);
340

341
  rs_id = nice_agent_add_stream (ragent, 2);
342
343
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
344
345
#if USE_TURN
  nice_agent_set_relay_info(lagent, ls_id, 1,
346
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
347
  nice_agent_set_relay_info(lagent, ls_id, 2,
348
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
349
  nice_agent_set_relay_info(ragent, rs_id, 1,
350
      TURN_IP, TURN_PORT, TURN_USER2, TURN_PASS2, TURN_TYPE);
351
  nice_agent_set_relay_info(ragent, rs_id, 2,
352
      TURN_IP, TURN_PORT, TURN_USER2, TURN_PASS2, TURN_TYPE);
353
354
#endif

355

356
357
358
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

359
360
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
361
362
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
363
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
364
365
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
366
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
367
368
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
369
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
370
371
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
372
373

  /* step: run mainloop until local candidates are ready
374
   *       (see timer_cb() above) */
375
376
377
378
379
380
381
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }
382
383
384

  /* step: find out the local candidates of each agent */

385
  /* priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
386
387
  g_debug ("test-fullmode: local RTP port R %u",
           nice_address_get_port (&raddr));
388
389

  priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
390
391
  g_debug ("test-fullmode: local RTP port L %u",
           nice_address_get_port (&laddr));
392
393

  priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
394
395
  g_debug ("test-fullmode: local RTCP port R %u",
           nice_address_get_port (&raddr_rtcp));
396
397

  priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
398
  g_debug ("test-fullmode: local RTCP port L %u",
399
  nice_address_get_port (&laddr_rtcp));*/
400

401
  /* step: pass the remote candidates to agents  */
402
  //cands = g_slist_append (NULL, &cdes);
403
  {
404
      gchar *ufrag = NULL, *password = NULL;
405
406
407
      nice_agent_get_local_credentials(lagent, ls_id, &ufrag, &password);
      nice_agent_set_remote_credentials (ragent,
					 rs_id, ufrag, password);
408
409
      g_free (ufrag);
      g_free (password);
410
411
412
      nice_agent_get_local_credentials(ragent, rs_id, &ufrag, &password);
      nice_agent_set_remote_credentials (lagent,
					 ls_id, ufrag, password);
413
414
      g_free (ufrag);
      g_free (password);
415
  }
416
  /*  cdes.component_id = NICE_COMPONENT_TYPE_RTP;
Olivier Crete's avatar
Olivier Crete committed
417
  cdes.addr = raddr;
418
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
Olivier Crete's avatar
Olivier Crete committed
419
  cdes.addr = laddr;
420
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
421
  cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
Olivier Crete's avatar
Olivier Crete committed
422
  cdes.addr = raddr_rtcp;
423
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);
Olivier Crete's avatar
Olivier Crete committed
424
  cdes.addr = laddr_rtcp;
425
426
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);

427
428
429
  g_slist_free (cands);*/
  cands = priv_get_local_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTP);
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
430
431
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
432
433
434
  g_slist_free (cands);
  cands = priv_get_local_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP);
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);
435
436
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
437
438
439
  g_slist_free (cands);
  cands = priv_get_local_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
440
441
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
442
443
444
  g_slist_free (cands);
  cands = priv_get_local_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP);
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);
445
446
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
447
448
449
450
  g_slist_free (cands);

  g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");

451
  /* step: run the mainloop until connectivity checks succeed
452
453
454
455
456
457
458
   *       (see timer_cb() above) */
  g_main_loop_run (global_mainloop);

  /* note: verify that STUN binding requests were sent */
  g_assert (global_lagent_ibr_received == TRUE);
  g_assert (global_ragent_ibr_received == TRUE);

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
  /* note: test payload send and receive */
  global_ragent_read = 0;
  g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
  g_main_loop_run (global_mainloop);
  g_assert (global_ragent_read == 16);

  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

475
476
477
478
479
480
481
482
/**
 * Simulate the case where answer to the offer is delayed and
 * some STUN connectivity checks reach the offering party
 * before it gets the remote SDP information.
 */
static int run_full_test_delayed_answer (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, guint ready, guint failed)
{
  NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;   
Olivier Crete's avatar
Olivier Crete committed
483
  NiceCandidate cdes;
484
485
486
  GSList *cands;
  guint ls_id, rs_id;

Olivier Crete's avatar
Olivier Crete committed
487
488
  init_candidate (&cdes);

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

  /* step: initialize variables modified by the callbacks */
  global_components_ready = 0;
  global_components_ready_exit = ready;
  global_components_failed = 0;
  global_components_failed_exit = failed;
  global_lagent_gathering_done = FALSE;
  global_ragent_gathering_done = FALSE;
  global_lagent_ibr_received =
    global_ragent_ibr_received = FALSE;
  global_exit_when_ibr_received = 1;
  global_lagent_cands = 
    global_ragent_cands = 0;

  g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);

  /* step: add one stream, with RTP+RTCP components, to each agent */
  ls_id = nice_agent_add_stream (lagent, 2);
510

511
512
513
  rs_id = nice_agent_add_stream (ragent, 2);
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
514

515
516
517
  /* We don't try this with TURN because as long as both agents don't
     have the remote candidates, they won't be able to create the
     permission on the TURN server, so the connchecks will never go through */
518

519
520
521
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

522
523
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
524
525
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
526
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
527
528
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
529
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
530
531
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
532
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
533
534
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
535

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
  /* step: run mainloop until local candidates are ready 
   *       (see timer_cb() above) */
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }

  /* step: find out the local candidates of each agent */

  priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
  g_debug ("test-fullmode: local RTP port R %u",
           nice_address_get_port (&raddr));

  priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
  g_debug ("test-fullmode: local RTP port L %u",
           nice_address_get_port (&laddr));

  priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
  g_debug ("test-fullmode: local RTCP port R %u",
           nice_address_get_port (&raddr_rtcp));

  priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
  g_debug ("test-fullmode: local RTCP port L %u",
           nice_address_get_port (&laddr_rtcp));

  /* step: pass the remote candidates to agent R (answering party)  */
  {
566
      gchar *ufrag = NULL, *password = NULL;
567
568
569
      nice_agent_get_local_credentials(lagent, ls_id, &ufrag, &password);
      nice_agent_set_remote_credentials (ragent,
					 rs_id, ufrag, password);
570
571
      g_free (ufrag);
      g_free (password);
572
573
574
      nice_agent_get_local_credentials(ragent, rs_id, &ufrag, &password);
      nice_agent_set_remote_credentials (lagent,
					 ls_id, ufrag, password);
575
576
      g_free (ufrag);
      g_free (password);
577
578
579
580
  }
  /* step: set remote candidates for agent R (answering party) */
  cands = g_slist_append (NULL, &cdes);
  cdes.component_id = NICE_COMPONENT_TYPE_RTP;
Olivier Crete's avatar
Olivier Crete committed
581
  cdes.addr = laddr;
582
583
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
  cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
Olivier Crete's avatar
Olivier Crete committed
584
  cdes.addr = laddr_rtcp;
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);

  g_debug ("test-fullmode: Set properties, next running mainloop until first check is received...");

  /* step: run the mainloop until first connectivity check receveid */
  g_main_loop_run (global_mainloop);
  global_exit_when_ibr_received = 0;

  /* note: verify that STUN binding requests were sent */
  g_assert (global_lagent_ibr_received == TRUE);

  g_debug ("test-fullmode: Delayed answer received, continuing processing..");

  /* step: pass the remote candidates to agent L (offering party)  */
  {
600
      gchar *ufrag = NULL, *password = NULL;
601
602
603
      nice_agent_get_local_credentials(ragent, rs_id, &ufrag, &password);
      nice_agent_set_remote_credentials (lagent,
					 ls_id, ufrag, password);
604
605
      g_free (ufrag);
      g_free (password);
606
607
608
      nice_agent_get_local_credentials(ragent, rs_id, &ufrag, &password);
      nice_agent_set_remote_credentials (lagent,
					 ls_id, ufrag, password);
609
610
      g_free (ufrag);
      g_free (password);
611
612
613
614
  }

  /* step: pass remove candidates to agent L (offering party) */
  cdes.component_id = NICE_COMPONENT_TYPE_RTP;
Olivier Crete's avatar
Olivier Crete committed
615
  cdes.addr = raddr;
616
617
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
  cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
Olivier Crete's avatar
Olivier Crete committed
618
  cdes.addr = raddr_rtcp;
619
620
621
622
623
624
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);

  g_debug ("test-fullmode: Running mainloop until connectivity checks succeeed.");

  g_main_loop_run (global_mainloop);
  g_assert (global_ragent_ibr_received == TRUE);
625
  g_assert (global_components_failed == 0);
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644

  /* note: test payload send and receive */
  global_ragent_read = 0;
  g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
  g_main_loop_run (global_mainloop);
  g_assert (global_ragent_read == 16);

  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  g_slist_free (cands);

  return 0;
}

645
646
647
static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
{
  NiceAddress laddr, raddr;   
Olivier Crete's avatar
Olivier Crete committed
648
  NiceCandidate cdes;
649
650
651
  GSList *cands, *i;
  guint ls_id, rs_id;

Olivier Crete's avatar
Olivier Crete committed
652
653
  init_candidate (&cdes);

654
655
656
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

657
  global_components_ready = 0;
658
  global_components_ready_exit = 0;
659
660
  global_components_failed = 0;
  global_components_failed_exit = 2;
661
662
663
  global_lagent_state[0] =   global_lagent_state[1] = 
    global_ragent_state[0] = global_ragent_state[1] 
    = NICE_COMPONENT_STATE_LAST;
664
665
666
667
668
669
670
671
672
673
  global_lagent_gathering_done = 
    global_ragent_gathering_done = FALSE;
  global_lagent_cands = 
    global_ragent_cands = 0;

  g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);

  /* step: add one stream, with one component, to each agent */
  ls_id = nice_agent_add_stream (lagent, 1);
674

675
676
677
  rs_id = nice_agent_add_stream (ragent, 1);
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
678
679
#if USE_TURN
  nice_agent_set_relay_info(lagent, ls_id, 1,
680
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
681
  nice_agent_set_relay_info(ragent, rs_id, 1,
682
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
683
#endif
684

685
686
687
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

688
689
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
690
691
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
692
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
693
694
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
695

696
697
698
699
700
701
702
703
704
705
706
707
  /* step: run mainloop until local candidates are ready 
   *       (see timer_cb() above) */
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }

  /* step: find out the local candidates of each agent */
  cands = nice_agent_get_local_candidates(lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
708
  
709
710
711
  for (i = cands; i; i = i->next) {
    NiceCandidate *cand = i->data;
    if (cand) {
712
713
      g_debug ("test-fullmode: local port L %u",
               nice_address_get_port (&cand->addr));
714
715
716
      laddr = cand->addr;
    }
  }
717
718
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
719
720
721
722
723
724
  g_slist_free (cands);

  cands = nice_agent_get_local_candidates(ragent, rs_id, NICE_COMPONENT_TYPE_RTP);
  for (i = cands; i; i = i->next) {
    NiceCandidate *cand = i->data;
    if (cand) {
725
726
      g_debug ("test-fullmode: local port R %u",
               nice_address_get_port (&cand->addr));
727
728
729
      raddr = cand->addr;
    }
  }
730
731
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
732
733
  g_slist_free (cands);
  g_debug ("test-fullmode: Got local candidates...");
734

735
736
737
  /* step: pass the remote candidates to agents  */
  cands = g_slist_append (NULL, &cdes);
  {
738
      gchar *ufrag = NULL, *password = NULL;
739
740
741
      nice_agent_get_local_credentials(lagent, ls_id, &ufrag, &password);
      nice_agent_set_remote_credentials (ragent,
					 rs_id, "wrong", password);
742
743
      g_free (ufrag);
      g_free (password);
744
745
746
      nice_agent_get_local_credentials(ragent, rs_id, &ufrag, &password);
      nice_agent_set_remote_credentials (lagent,
					 ls_id, ufrag, "wrong2");
747
748
      g_free (ufrag);
      g_free (password);
749
  }
Olivier Crete's avatar
Olivier Crete committed
750
  cdes.addr = raddr;
751
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
Olivier Crete's avatar
Olivier Crete committed
752
  cdes.addr = laddr;
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
  g_slist_free (cands);

  g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");

  /* step: run the mainloop until connectivity checks succeed 
   *       (see timer_cb() above) */
  g_main_loop_run (global_mainloop);

  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 0);
  g_assert (global_ragent_cands == 0);

  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, gboolean role)
{
  NiceAddress laddr, raddr;   
Olivier Crete's avatar
Olivier Crete committed
779
  NiceCandidate cdes;
780
781
782
  GSList *cands, *i;
  guint ls_id, rs_id;

Olivier Crete's avatar
Olivier Crete committed
783
784
  init_candidate (&cdes);

785
786
787
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

788
789
790
  global_components_ready = 0;
  global_components_ready_exit = 2;
  global_components_failed = 0;
791
  global_components_failed_exit = 0;
792
793
794
795
796
797
798
799
800
801
802
803
  global_lagent_gathering_done =
    global_ragent_gathering_done = FALSE;
  global_lagent_cands = 
    global_ragent_cands = 0;
  global_lagent_ibr_received =
    global_ragent_ibr_received = FALSE;

  g_object_set (G_OBJECT (lagent), "controlling-mode", role, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", role, NULL);

  /* step: add one stream, with one component, to each agent */
  ls_id = nice_agent_add_stream (lagent, 1);
804

805
806
807
  rs_id = nice_agent_add_stream (ragent, 1);
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
808
809
#if USE_TURN
  nice_agent_set_relay_info(lagent, ls_id, 1,
810
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
811
  nice_agent_set_relay_info(ragent, rs_id, 1,
812
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
813
#endif
814

815
816
817
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

818
819
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
820
821
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
822
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
823
824
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
825

826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  /* step: run mainloop until local candidates are ready 
   *       (see timer_cb() above) */
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }

  /* step: find out the local candidates of each agent */
  cands = nice_agent_get_local_candidates(lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
  for (i = cands; i; i = i->next) {
    NiceCandidate *cand = i->data;
    if (cand) {
841
842
      g_debug ("test-fullmode: local port L %u",
               nice_address_get_port (&cand->addr));
843
844
845
      laddr = cand->addr;
    }
  }
846
847
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
848
849
850
851
852
853
  g_slist_free (cands);

  cands = nice_agent_get_local_candidates(ragent, rs_id, NICE_COMPONENT_TYPE_RTP);
  for (i = cands; i; i = i->next) {
    NiceCandidate *cand = i->data;
    if (cand) {
854
855
      g_debug ("test-fullmode: local port R %u",
               nice_address_get_port (&cand->addr));
856
857
858
      raddr = cand->addr;
    }
  }
859
860
  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
861
862
863
864
865
866
  g_slist_free (cands);
  g_debug ("test-fullmode: Got local candidates...");
 
  /* step: pass the remote candidates to agents  */
  cands = g_slist_append (NULL, &cdes);
  {
867
      gchar *ufrag = NULL, *password = NULL;
868
869
870
      nice_agent_get_local_credentials(lagent, ls_id, &ufrag, &password);
      nice_agent_set_remote_credentials (ragent,
					 rs_id, ufrag, password);
871
872
      g_free (ufrag);
      g_free (password);
873
874
875
      nice_agent_get_local_credentials(ragent, rs_id, &ufrag, &password);
      nice_agent_set_remote_credentials (lagent,
					 ls_id, ufrag, password);
876
877
      g_free (ufrag);
      g_free (password);
878
  }
Olivier Crete's avatar
Olivier Crete committed
879
  cdes.addr = raddr;
880
  nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
Olivier Crete's avatar
Olivier Crete committed
881
  cdes.addr = laddr;
882
883
884
885
886
887
888
889
890
891
892
893
894
  nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
  g_slist_free (cands);

  g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");

  /* step: run the mainloop until connectivity checks succeed 
   *       (see timer_cb() above) */
  g_main_loop_run (global_mainloop);

  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 1);
  g_assert (global_ragent_cands == 1);

895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

int main (void)
{
  NiceAgent *lagent, *ragent;      /* agent's L and R */
  NiceAddress baseaddr;
  int result;
  guint timer_id;
911
  const char *stun_server = NULL, *stun_server_port = NULL;
912
913

  g_type_init ();
Youness Alaoui's avatar
Youness Alaoui committed
914
  g_thread_init (NULL);
915
916
917
918
919
920
921
922
  global_mainloop = g_main_loop_new (NULL, FALSE);

  /* Note: impl limits ...
   * - no multi-stream support
   * - no IPv6 support
   */

  /* step: create the agents L and R */
923
924
  lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY);
  ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY);
925
926

  /* step: add a timer to catch state changes triggered by signals */
927
928
929
930
931
#if USE_TURN
  timer_id = g_timeout_add (300000, timer_cb, NULL);
#else
  timer_id = g_timeout_add (30000, timer_cb, NULL);
#endif
932
933

  /* step: specify which local interface to use */
934
#if USE_LOOPBACK
935
  if (!nice_address_set_from_string (&baseaddr, "127.0.0.1"))
936
937
938
    g_assert_not_reached ();
  nice_agent_add_local_address (lagent, &baseaddr);
  nice_agent_add_local_address (ragent, &baseaddr);
939
#else
940
  if (!nice_address_set_from_string (&baseaddr, "192.168.1.110"))
941
942
    g_assert_not_reached ();
  nice_agent_add_local_address (lagent, &baseaddr);
943
944
  nice_agent_add_local_address (ragent, &baseaddr);
#endif
945

946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
  g_signal_connect (G_OBJECT (lagent), "candidate-gathering-done",
      G_CALLBACK (cb_candidate_gathering_done), GUINT_TO_POINTER(1));
  g_signal_connect (G_OBJECT (ragent), "candidate-gathering-done",
      G_CALLBACK (cb_candidate_gathering_done), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "component-state-changed",
      G_CALLBACK (cb_component_state_changed), GUINT_TO_POINTER (1));
  g_signal_connect (G_OBJECT (ragent), "component-state-changed",
      G_CALLBACK (cb_component_state_changed), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "new-selected-pair",
      G_CALLBACK (cb_new_selected_pair), GUINT_TO_POINTER(1));
  g_signal_connect (G_OBJECT (ragent), "new-selected-pair",
      G_CALLBACK (cb_new_selected_pair), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "new-candidate",
      G_CALLBACK (cb_new_candidate), GUINT_TO_POINTER (1));
  g_signal_connect (G_OBJECT (ragent), "new-candidate",
      G_CALLBACK (cb_new_candidate), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "initial-binding-request-received",
      G_CALLBACK (cb_initial_binding_request_received),
      GUINT_TO_POINTER (1));
  g_signal_connect (G_OBJECT (ragent), "initial-binding-request-received",
      G_CALLBACK (cb_initial_binding_request_received),
      GUINT_TO_POINTER (2));
968

969
970
971
972
973
974
975
976
977
  stun_server = getenv ("NICE_STUN_SERVER");
  stun_server_port = getenv ("NICE_STUN_SERVER_PORT");
  if (stun_server) {
    g_object_set (G_OBJECT (lagent), "stun-server", stun_server,  NULL);
    g_object_set (G_OBJECT (lagent), "stun-server-port", atoi (stun_server_port),  NULL);
    g_object_set (G_OBJECT (ragent), "stun-server", stun_server,  NULL);
    g_object_set (G_OBJECT (ragent), "stun-server-port", atoi (stun_server_port),  NULL);
  }

978
979
980
981
982
983
984
985
986
987
988
  g_object_set (G_OBJECT (lagent), "proxy-ip", PROXY_IP,  NULL);
  g_object_set (G_OBJECT (lagent), "proxy-port", PROXY_PORT, NULL);
  g_object_set (G_OBJECT (lagent), "proxy-type", PROXY_TYPE, NULL);
  g_object_set (G_OBJECT (lagent), "proxy-username", PROXY_USERNAME, NULL);
  g_object_set (G_OBJECT (lagent), "proxy-password", PROXY_PASSWORD, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-ip", PROXY_IP,  NULL);
  g_object_set (G_OBJECT (ragent), "proxy-port", PROXY_PORT, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-type", PROXY_TYPE, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-username", PROXY_USERNAME, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-password", PROXY_PASSWORD, NULL);

989
  /* step: test setter/getter functions for properties */
990
  {
991
    guint max_checks = 0;
992
993
994
995
996
    gchar *string = NULL;
    guint port = 0;
    gboolean mode = FALSE;
    g_object_get (G_OBJECT (lagent), "stun-server", &string, NULL);
    g_assert (stun_server == NULL || strcmp (string, stun_server) == 0);
997
    g_free (string);
998
999
    g_object_get (G_OBJECT (lagent), "stun-server-port", &port, NULL);
    g_assert (stun_server_port == NULL || port == (guint)atoi (stun_server_port));
1000
1001
1002
1003
1004
    g_object_get (G_OBJECT (lagent), "proxy-ip", &string, NULL);
    g_assert (strcmp (string, PROXY_IP) == 0);
    g_free (string);
    g_object_get (G_OBJECT (lagent), "proxy-port", &port, NULL);
    g_assert (port == PROXY_PORT);
1005
1006
    g_object_get (G_OBJECT (lagent), "controlling-mode", &mode, NULL);
    g_assert (mode == TRUE);
1007
1008
1009
    g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 300, NULL);
    g_object_get (G_OBJECT (lagent), "max-connectivity-checks", &max_checks, NULL);
    g_assert (max_checks == 300);
1010
  }
1011

1012
1013
  /* step: run test the first time */
  g_debug ("test-fullmode: TEST STARTS / running test for the 1st time");
1014
  result = run_full_test (lagent, ragent, &baseaddr, 4 ,0);
1015
  priv_print_global_status ();
1016
  g_assert (result == 0);
1017
1018
1019
1020
1021
1022
1023
1024
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 2);
  g_assert (global_ragent_cands == 2);

1025
1026

  /* step: run test again without unref'ing agents */
1027
  g_debug ("test-fullmode: TEST STARTS / running test for the 2nd time");
1028
  result = run_full_test (lagent, ragent, &baseaddr, 4, 0);
1029
1030
  priv_print_global_status ();
  g_assert (result == 0);
1031
1032
1033
1034
1035
1036
1037
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 2);
  g_assert (global_ragent_cands == 2);
1038

Youness Alaoui's avatar
Youness Alaoui committed
1039
#if TEST_GOOGLE
1040
1041
1042
  return result;
#endif

1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
  /* step: run test simulating delayed SDP answer */
  g_debug ("test-fullmode: TEST STARTS / delayed SDP answer");
  result = run_full_test_delayed_answer (lagent, ragent, &baseaddr, 4, 0);
  priv_print_global_status ();
  g_assert (result == 0);
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 2);
  g_assert (global_ragent_cands == 2);

1056

1057
1058
1059
1060
1061
  /* run test with incorrect credentials (make sure process fails) */
  g_debug ("test-fullmode: TEST STARTS / incorrect credentials");
  result = run_full_test_wrong_password (lagent, ragent, &baseaddr);
  priv_print_global_status ();
  g_assert (result == 0);
1062
1063
1064
1065
1066
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_FAILED);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_LAST);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_FAILED);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_LAST);

1067
1068
1069
1070
1071
  /* The max connectivity checks test can't be run with TURN because
     we'll have 3 local candidates instead of 1 and the checks will
     be random, so we can't predict how many will fail/succeed */
#if USE_TURN == 0

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
  /* step: run test with a hard limit for connecitivity checks */
  g_debug ("test-fullmode: TEST STARTS / max connectivity checks");
  g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 1, NULL);
  g_object_set (G_OBJECT (ragent), "max-connectivity-checks", 1, NULL);
  result = run_full_test (lagent, ragent, &baseaddr, 2, 2);
  priv_print_global_status ();
  g_assert (result == 0); 
  /* should FAIL as agent L can't send any checks: */
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_FAILED ||
	    global_lagent_state[1] == NICE_COMPONENT_STATE_FAILED);
1082
1083
1084
1085
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_FAILED ||
	    global_lagent_state[1] == NICE_COMPONENT_STATE_FAILED);
#endif

1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
  g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 100, NULL);
  g_object_set (G_OBJECT (ragent), "max-connectivity-checks", 100, NULL);
  result = run_full_test (lagent, ragent, &baseaddr, 4, 0);
  priv_print_global_status ();
  /* should SUCCEED as agent L can send the checks: */
  g_assert (result == 0); 
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
  g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 100, NULL);
1097

1098
1099
1100
1101
1102
  /* run test with a conflict in controlling mode: controlling-controlling */
  g_debug ("test-fullmode: TEST STARTS / controlling mode conflict case-1");
  result = run_full_test_control_conflict (lagent, ragent, &baseaddr, TRUE);
  priv_print_global_status ();
  g_assert (result == 0);
1103
1104
1105
1106
1107

  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
1108

1109
1110
1111
1112
1113
  /* run test with a conflict in controlling mode: controlled-controlled */
  g_debug ("test-fullmode: TEST STARTS / controlling mode conflict case-2");
  result = run_full_test_control_conflict (lagent, ragent, &baseaddr, FALSE);
  priv_print_global_status ();
  g_assert (result == 0);
1114
1115
1116
1117
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
1118
1119
1120
1121

  g_object_unref (lagent);
  g_object_unref (ragent);

1122
1123
  g_main_loop_unref (global_mainloop);
  global_mainloop = NULL;
1124
1125
1126
1127
1128

  g_source_remove (timer_id);

  return result;
}