check_session.c 76.8 KB
Newer Older
1 2 3
/*
 * This file is part of the Sofia-SIP package
 *
4
 * Copyright (C) 2008 Nokia Corporation.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

25
/**@CFILE check_session.c
26
 *
Pekka Pessi's avatar
Pekka Pessi committed
27
 * @brief NUA module tests for SIP session handling
28 29 30
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
31
 * @copyright (C) 2008 Nokia Corporation.
32 33 34 35
 */

#include "config.h"

36
#include "check_nua.h"
37

Pekka Pessi's avatar
Pekka Pessi committed
38
#include "test_s2.h"
39 40 41 42 43

#include <sofia-sip/sip_status.h>
#include <sofia-sip/sip_header.h>
#include <sofia-sip/soa.h>
#include <sofia-sip/su_tagarg.h>
44
#include <sofia-sip/su_tag_io.h>
45 46 47 48 49

#include <stdlib.h>
#include <string.h>
#include <assert.h>

50 51 52
/* define XXX as 1 in order to see all failing test cases */
#define XXX (0)

53 54 55
/* ====================================================================== */
/* Call cases */

Pekka Pessi's avatar
Pekka Pessi committed
56
static nua_t *nua;
57 58 59
static soa_session_t *soa = NULL;
static struct dialog *dialog = NULL;

60 61 62
#define CRLF "\r\n"

static void call_setup(void)
63
{
64 65
  s2_case("0.1.1", "Setup for Call Tests", "");

66
  nua = s2_nua_setup(SIPTAG_ORGANIZATION_STR("Pussy Galore's Flying Circus"),
67
                     NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
68
		     TAG_END());
69

70
  soa = soa_create(NULL, s2->root, NULL);
71 72 73 74

  fail_if(!soa);

  soa_set_params(soa,
75 76
		 SOATAG_USER_SDP_STR("m=audio 5008 RTP/AVP 8 0" CRLF
				     "m=video 5010 RTP/AVP 34" CRLF),
77 78 79 80 81 82 83
		 TAG_END());

  dialog = su_home_new(sizeof *dialog); fail_if(!dialog);

  s2_register_setup();
}

84
static void call_teardown(void)
85
{
86 87
  s2_case("0.1.2", "Teardown Call Test Setup", "");

88 89 90 91 92 93
  mark_point();

  s2_register_teardown();

  nua_shutdown(nua);
  fail_unless(s2_check_event(nua_r_shutdown, 200));
94 95

  s2_nua_teardown();
96 97
}

98
static void save_sdp_to_soa(struct message *message)
99 100 101 102 103 104 105 106 107 108
{
  sip_payload_t *pl;
  char const *body;
  isize_t bodylen;

  fail_if(!message);

  fail_if(!message->sip->sip_content_length);
  fail_if(!message->sip->sip_content_type);
  fail_if(strcmp(message->sip->sip_content_type->c_type,
109
		 "application/sdp"));
110 111 112 113 114

  fail_if(!message->sip->sip_payload);
  pl = message->sip->sip_payload;
  body = pl->pl_data, bodylen = pl->pl_len;

115
  fail_if(soa_set_remote_sdp(soa, NULL, body, (issize_t)bodylen) < 0);
116 117
}

118
static void process_offer(struct message *message)
119
{
120
  save_sdp_to_soa(message);
121 122 123
  fail_if(soa_generate_answer(soa, NULL) < 0);
}

124
static void process_answer(struct message *message)
125
{
126
  save_sdp_to_soa(message);
127 128 129
  fail_if(soa_process_answer(soa, NULL) < 0);
}

130 131 132 133 134
static void
respond_with_sdp(struct message *request,
		 struct dialog *dialog,
		 int status, char const *phrase,
		 tag_type_t tag, tag_value_t value, ...)
135 136 137 138 139 140 141 142 143
{
  ta_list ta;

  char const *body;
  isize_t bodylen;

  fail_if(soa_get_local_sdp(soa, NULL, &body, &bodylen) != 1);

  ta_start(ta, tag, value);
144
  s2_respond_to(request, dialog, status, phrase,
145 146
		SIPTAG_CONTENT_TYPE_STR("application/sdp"),
		SIPTAG_PAYLOAD_STR(body),
147
		SIPTAG_CONTENT_DISPOSITION_STR("session"),
148 149 150 151
		ta_tags(ta));
  ta_end(ta);
}

152 153 154 155 156
static void
request_with_sdp(struct dialog *dialog,
		 sip_method_t method, char const *name,
		 tport_t *tport,
		 tag_type_t tag, tag_value_t value, ...)
157 158 159 160 161 162 163 164 165 166
{
  ta_list ta;

  char const *body;
  isize_t bodylen;

  fail_if(soa_get_local_sdp(soa, NULL, &body, &bodylen) != 1);

  ta_start(ta, tag, value);
  fail_if(
167
    s2_request_to(dialog, method, name, tport,
168 169 170 171 172 173
		  SIPTAG_CONTENT_TYPE_STR("application/sdp"),
		  SIPTAG_PAYLOAD_STR(body),
		  ta_tags(ta)));
  ta_end(ta);
}

174 175 176
static struct message *
invite_sent_by_nua(nua_handle_t *nh,
		   tag_type_t tag, tag_value_t value, ...)
177 178 179 180 181 182 183 184 185
{
  ta_list ta;
  ta_start(ta, tag, value);
  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	     ta_tags(ta));
  ta_end(ta);

  fail_unless(s2_check_callstate(nua_callstate_calling));

186 187
  return s2_wait_for_request(SIP_METHOD_INVITE);
}
188

189 190
static uint32_t s2_rseq;

191 192 193
static struct message *
respond_with_100rel(struct message *invite,
		    struct dialog *d,
194
		    int with_sdp,
195 196 197 198 199 200 201 202 203
		    int status, char const *phrase,
		    tag_type_t tag, tag_value_t value, ...)
{
  ta_list ta;
  sip_rseq_t rs[1];

  assert(100 < status && status < 200);

  sip_rseq_init(rs);
204
  rs->rs_response = ++s2_rseq;
205 206 207

  ta_start(ta, tag, value);

208
  if (with_sdp) {
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    respond_with_sdp(
      invite, dialog, status, phrase,
      SIPTAG_REQUIRE_STR("100rel"),
      SIPTAG_RSEQ(rs),
      ta_tags(ta));
  }
  else {
    s2_respond_to(
      invite, dialog, status, phrase,
      SIPTAG_REQUIRE_STR("100rel"),
      SIPTAG_RSEQ(rs),
      ta_tags(ta));
  }
  ta_end(ta);

  fail_unless(s2_check_event(nua_r_invite, status));

226
  return s2_wait_for_request(SIP_METHOD_PRACK);
227 228 229 230 231 232 233 234 235 236
}

static void
invite_by_nua(nua_handle_t *nh,
	      tag_type_t tag, tag_value_t value, ...)
{
  struct message *invite;
  ta_list ta;

  ta_start(ta, tag, value);
237
  invite = invite_sent_by_nua(nh, ta_tags(ta));
238 239 240 241 242
  ta_end(ta);

  process_offer(invite);
  respond_with_sdp(
    invite, dialog, SIP_180_RINGING,
243 244
    SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
    TAG_END());
245

246 247 248
  fail_unless(s2_check_event(nua_r_invite, 180));
  fail_unless(s2_check_callstate(nua_callstate_proceeding));

249
  respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
250 251 252 253 254 255
  s2_free_message(invite);
  fail_unless(s2_check_event(nua_r_invite, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));
  fail_unless(s2_check_request(SIP_METHOD_ACK));
}

256 257
static nua_handle_t *
invite_to_nua(tag_type_t tag, tag_value_t value, ...)
258
{
259
  ta_list ta;
260 261 262 263 264 265
  struct event *invite;
  struct message *response;
  nua_handle_t *nh;

  soa_generate_offer(soa, 1, NULL);

266
  ta_start(ta, tag, value);
267
  request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, ta_tags(ta));
268
  ta_end(ta);
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

  invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  fail_unless(s2_check_callstate(nua_callstate_received));

  nh = invite->nh;
  fail_if(!nh);

  s2_free_event(invite);

  response = s2_wait_for_response(100, SIP_METHOD_INVITE);
  fail_if(!response);

  nua_respond(nh, SIP_180_RINGING,
	      SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	      TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_early));

  response = s2_wait_for_response(180, SIP_METHOD_INVITE);
  fail_if(!response);
  s2_update_dialog(dialog, response);
289
  process_answer(response);
290 291 292 293 294 295 296 297 298 299 300 301
  s2_free_message(response);

  nua_respond(nh, SIP_200_OK, TAG_END());

  fail_unless(s2_check_callstate(nua_callstate_completed));

  response = s2_wait_for_response(200, SIP_METHOD_INVITE);

  fail_if(!response);
  s2_update_dialog(dialog, response);
  s2_free_message(response);

302
  fail_if(s2_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
303 304 305 306 307 308 309

  fail_unless(s2_check_event(nua_i_ack, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));

  return nh;
}

310 311 312
static void
bye_by_nua(nua_handle_t *nh,
	   tag_type_t tag, tag_value_t value, ...)
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
{
  ta_list ta;
  struct message *bye;

  ta_start(ta, tag, value);
  nua_bye(nh, ta_tags(ta));
  ta_end(ta);

  bye = s2_wait_for_request(SIP_METHOD_BYE);
  fail_if(!bye);
  s2_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  s2_free_message(bye);
  fail_unless(s2_check_event(nua_r_bye, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));
}

329
static void
330 331
bye_by_nua_challenged(nua_handle_t *nh,
		      tag_type_t tag, tag_value_t value, ...)
332 333 334 335 336 337 338 339 340 341 342 343 344
{
  ta_list ta;
  struct message *bye;

  s2_flush_events();

  ta_start(ta, tag, value);
  nua_bye(nh, ta_tags(ta));
  ta_end(ta);

  bye = s2_wait_for_request(SIP_METHOD_BYE);
  fail_if(!bye);
  s2_respond_to(bye, dialog, SIP_407_PROXY_AUTH_REQUIRED,
345
		SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
346 347 348 349 350 351 352 353 354 355 356
		TAG_END());
  s2_free_message(bye);
  fail_unless(s2_check_event(nua_r_bye, 407));

  nua_authenticate(nh, NUTAG_AUTH("Digest:\"s2test\":abc:abc"), TAG_END());
  bye = s2_wait_for_request(SIP_METHOD_BYE);
  fail_if(!bye);
  s2_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  s2_free_message(bye);
  fail_unless(s2_check_event(nua_r_bye, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));
357
  fail_if(s2->events);
358 359 360
}


361
static void
362 363 364 365
cancel_by_nua(nua_handle_t *nh,
	      struct message *invite,
	      struct dialog *dialog,
	      tag_type_t tag, tag_value_t value, ...)
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
{
  ta_list ta;
  struct message *cancel;

  ta_start(ta, tag, value);
  nua_cancel(nh, ta_tags(ta));
  ta_end(ta);

  cancel = s2_wait_for_request(SIP_METHOD_CANCEL);
  fail_if(!cancel);
  s2_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  s2_free_message(cancel);
  fail_unless(s2_check_event(nua_r_cancel, 200));

  s2_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  fail_unless(s2_check_request(SIP_METHOD_ACK));

  fail_unless(s2_check_event(nua_r_invite, 487));
}

386
static void
387 388
bye_to_nua(nua_handle_t *nh,
	   tag_type_t tag, tag_value_t value, ...)
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
{
  ta_list ta;

  ta_start(ta, tag, value);
  fail_if(s2_request_to(dialog, SIP_METHOD_BYE, NULL, ta_tags(ta)));
  ta_end(ta);

  fail_unless(s2_check_event(nua_i_bye, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));
  fail_unless(s2_check_response(200, SIP_METHOD_BYE));
}

/* ====================================================================== */
/* 2 - Call cases */

/* 2.1 - Basic call cases */
405

Pekka Pessi's avatar
Pekka Pessi committed
406
START_TEST(call_2_1_1)
407 408 409 410
{
  nua_handle_t *nh;

  s2_case("2.1.1", "Basic call",
411
	  "NUA sends INVITE, NUA sends BYE");
412

413
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());
414

415
  invite_by_nua(nh, TAG_END());
416

417
  bye_by_nua(nh, TAG_END());
418 419 420 421 422 423

  nua_handle_destroy(nh);
}
END_TEST


424
START_TEST(call_2_1_2_1)
425 426 427
{
  nua_handle_t *nh;

428
  s2_case("2.1.2.1", "Basic call",
429
	  "NUA sends INVITE, NUA receives BYE");
430

431
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());
432

433
  invite_by_nua(nh, TAG_END());
434

435
  bye_to_nua(nh, TAG_END());
436 437 438 439 440

  nua_handle_destroy(nh);
}
END_TEST

441 442 443 444 445 446
START_TEST(call_2_1_2_2)
{
  nua_handle_t *nh;

  s2_case("2.1.2.2", "Basic call over TCP",
	  "NUA sends INVITE, NUA receives BYE");
447

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local),
		  TAG_END());

  invite_by_nua(nh,
		NUTAG_PROXY(s2->tcp.contact->m_url),
		TAG_END());

  bye_to_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST


START_TEST(call_2_1_3_1)
463 464 465
{
  nua_handle_t *nh;

466
  s2_case("2.1.3.1", "Incoming call",
467
	  "NUA receives INVITE and BYE");
468

469
  nh = invite_to_nua(TAG_END());
470

471
  bye_to_nua(nh, TAG_END());
472 473 474 475 476 477

  nua_handle_destroy(nh);
}
END_TEST


478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
START_TEST(call_2_1_3_2)
{
  nua_handle_t *nh;

  s2_case("2.1.3.2", "Incoming call over TCP",
	  "NUA receives INVITE and BYE");

  dialog->tport = s2->tcp.tport;

  nh = invite_to_nua(TAG_END());

  bye_to_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST


Pekka Pessi's avatar
Pekka Pessi committed
496
START_TEST(call_2_1_4)
497 498 499 500
{
  nua_handle_t *nh;

  s2_case("2.1.4", "Incoming call",
501
	  "NUA receives INVITE and sends BYE");
502

503
  nh = invite_to_nua(TAG_END());
504

505
  bye_by_nua(nh, TAG_END());
506 507 508 509 510 511

  nua_handle_destroy(nh);
}
END_TEST


Pekka Pessi's avatar
Pekka Pessi committed
512
START_TEST(call_2_1_5)
513 514 515 516
{
  nua_handle_t *nh;

  s2_case("2.1.5", "Incoming call",
517
	  "NUA receives INVITE and sends BYE, BYE is challenged");
518

519
  nh = invite_to_nua(TAG_END());
520

521
  bye_by_nua_challenged(nh, TAG_END());
522 523 524 525 526 527

  nua_handle_destroy(nh);
}
END_TEST


Pekka Pessi's avatar
Pekka Pessi committed
528 529 530 531 532 533 534 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 566 567 568 569 570 571 572 573 574 575 576 577
START_TEST(call_2_1_6)
{
  nua_handle_t *nh;
  struct message *bye;
  struct event *invite;
  struct message *response;

  s2_case("2.1.6", "Basic call",
	  "NUA received INVITE, "
	  "NUA responds (and saves proxy for dialog), "
	  "NUA sends BYE");

  soa_generate_offer(soa, 1, NULL);

  request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());

  invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  fail_unless(s2_check_callstate(nua_callstate_received));

  nh = invite->nh;
  fail_if(!nh);

  s2_free_event(invite);

  response = s2_wait_for_response(100, SIP_METHOD_INVITE);
  fail_if(!response);

  nua_respond(nh, SIP_180_RINGING,
	      /* Dialog-specific proxy is saved */
	      NUTAG_PROXY(s2->tcp.contact->m_url),
	      SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	      TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_early));

  response = s2_wait_for_response(180, SIP_METHOD_INVITE);
  fail_if(!response);
  s2_update_dialog(dialog, response);
  process_answer(response);
  s2_free_message(response);

  nua_respond(nh, SIP_200_OK, TAG_END());

  fail_unless(s2_check_callstate(nua_callstate_completed));

  response = s2_wait_for_response(200, SIP_METHOD_INVITE);

  fail_if(!response);
  s2_update_dialog(dialog, response);
  s2_free_message(response);

578
  fail_if(s2_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
Pekka Pessi's avatar
Pekka Pessi committed
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597

  fail_unless(s2_check_event(nua_i_ack, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));

  nua_bye(nh, TAG_END());
  bye = s2_wait_for_request(SIP_METHOD_BYE);
  fail_if(!bye);
  /* Check that NUA used dialog-specific proxy with BYE */
  fail_unless(tport_is_tcp(bye->tport));
  s2_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  s2_free_message(bye);
  fail_unless(s2_check_event(nua_r_bye, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));

  nua_handle_destroy(nh);
}
END_TEST


Pekka Pessi's avatar
Pekka Pessi committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
START_TEST(call_2_1_7)
{
  nua_handle_t *nh, *nh2;
  sip_replaces_t *replaces;

  s2_case("2.1.7", "Call lookup",
	  "Test dialog and call-id lookup");

  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());

  invite_by_nua(nh, TAG_END());

  nh2 = nua_handle_by_call_id(nua, dialog->call_id->i_id);
  fail_if(!nh2); fail_if(nh != nh2); nua_handle_unref(nh2);

  replaces = sip_replaces_format(NULL, "%s;from-tag=%s;to-tag=%s",
				 dialog->call_id->i_id,
				 dialog->local->a_tag,
				 dialog->remote->a_tag);
  fail_if(!replaces);

  nh2 = nua_handle_by_replaces(nua, replaces);
  fail_if(!nh2); fail_if(nh != nh2); nua_handle_unref(nh2);

  msg_header_free_all(NULL, (msg_header_t *)replaces);

  bye_by_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST


631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
START_TEST(call_2_1_8)
{
  nua_handle_t *nh;
  struct message *invite, *ack;

  s2_case("2.1.8", "Call using NUTAG_PROXY()",
	  "Test handle-specific NUTAG_PROXY().");

  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());

  invite = invite_sent_by_nua(
    nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
    NUTAG_PROXY(s2->tcp.contact->m_url), TAG_END());

  process_offer(invite);
  respond_with_sdp(
    invite, dialog, SIP_180_RINGING,
    SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
    TAG_END());

  fail_unless(s2_check_event(nua_r_invite, 180));
  fail_unless(s2_check_callstate(nua_callstate_proceeding));

  respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  s2_free_message(invite);
  fail_unless(s2_check_event(nua_r_invite, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));
  ack = s2_wait_for_request(SIP_METHOD_ACK);
  fail_unless(ack && tport_is_tcp(ack->tport));

  bye_by_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST


668 669
TCase *invite_tcase(void)
{
670 671
  TCase *tc = tcase_create("2.1 - Basic INVITE");
  tcase_add_checked_fixture(tc, call_setup, call_teardown);
672
  {
Pekka Pessi's avatar
Pekka Pessi committed
673
    tcase_add_test(tc, call_2_1_1);
674 675 676 677
    tcase_add_test(tc, call_2_1_2_1);
    tcase_add_test(tc, call_2_1_2_2);
    tcase_add_test(tc, call_2_1_3_1);
    tcase_add_test(tc, call_2_1_3_2);
Pekka Pessi's avatar
Pekka Pessi committed
678 679
    tcase_add_test(tc, call_2_1_4);
    tcase_add_test(tc, call_2_1_5);
Pekka Pessi's avatar
Pekka Pessi committed
680
    tcase_add_test(tc, call_2_1_6);
Pekka Pessi's avatar
Pekka Pessi committed
681
    tcase_add_test(tc, call_2_1_7);
682
    tcase_add_test(tc, call_2_1_8);
683 684 685 686 687
  }
  return tc;
}

/* ---------------------------------------------------------------------- */
688 689
/* 2.2 - Call CANCEL cases */

690
START_TEST(cancel_2_2_1)
691 692 693 694 695
{
  nua_handle_t *nh;
  struct message *invite, *cancel;

  s2_case("2.2.1", "Cancel call",
696
	  "NUA is caller, NUA sends CANCEL immediately");
697

698
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());
699 700 701 702 703 704 705 706

  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	     TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_calling));
  nua_cancel(nh, TAG_END());

  invite = s2_wait_for_request(SIP_METHOD_INVITE);
  fail_if(!invite);
707
  fail_if(s2->received != NULL);
708 709 710 711 712 713 714 715 716 717 718
  s2_respond_to(invite, dialog, SIP_100_TRYING, TAG_END());
  cancel = s2_wait_for_request(SIP_METHOD_CANCEL);
  fail_if(!cancel);
  s2_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  s2_respond_to(cancel, dialog, SIP_200_OK, TAG_END());

  fail_unless(s2_check_request(SIP_METHOD_ACK));

  fail_unless(s2_check_event(nua_r_invite, 487));
  fail_unless(s2_check_callstate(nua_callstate_terminated));
  fail_unless(s2_check_event(nua_r_cancel, 200));
719
  fail_if(s2->events != NULL);
720 721 722 723 724 725

  nua_handle_destroy(nh);
}
END_TEST


726
START_TEST(cancel_2_2_2)
727 728 729 730
{
  nua_handle_t *nh;
  struct message *invite;

731
  s2_case("2.2.2", "Canceled call",
732
	  "NUA is caller, NUA sends CANCEL after receiving 100");
733

734
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());
735 736 737 738 739 740

  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	     TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_calling));

  invite = s2_wait_for_request(SIP_METHOD_INVITE);
741
  process_offer(invite);
742 743
  s2_respond_to(invite, dialog, SIP_100_TRYING, TAG_END());

744
  cancel_by_nua(nh, invite, dialog, TAG_END());
745 746 747 748 749 750 751 752

  fail_unless(s2_check_callstate(nua_callstate_terminated));

  nua_handle_destroy(nh);
}
END_TEST


753
START_TEST(cancel_2_2_3)
754 755 756 757 758
{
  nua_handle_t *nh;
  struct message *invite;

  s2_case("2.2.3", "Canceled call",
759
	  "NUA is caller, NUA sends CANCEL after receiving 180");
760

761
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());
762 763 764 765

  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	     TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_calling));
766

767
  invite = s2_wait_for_request(SIP_METHOD_INVITE);
768 769 770
  process_offer(invite);
  respond_with_sdp(
    invite, dialog, SIP_180_RINGING,
771 772 773 774 775
    SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
    TAG_END());
  fail_unless(s2_check_event(nua_r_invite, 180));
  fail_unless(s2_check_callstate(nua_callstate_proceeding));

776
  cancel_by_nua(nh, invite, dialog, TAG_END());
777 778 779 780 781 782 783
  fail_unless(s2_check_callstate(nua_callstate_terminated));

  nua_handle_destroy(nh);
}
END_TEST


784
START_TEST(cancel_2_2_4)
785 786 787 788 789
{
  nua_handle_t *nh;
  struct message *invite, *cancel;

  s2_case("2.2.4", "Cancel and 200 OK glare",
790
	  "NUA is caller, NUA sends CANCEL after receiving 180 "
791 792
	  "but UAS already sent 200 OK.");

793
  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());
794 795 796 797 798 799

  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	     TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_calling));

  invite = s2_wait_for_request(SIP_METHOD_INVITE);
800 801
  process_offer(invite);
  respond_with_sdp(
802 803 804 805 806 807 808 809 810 811
    invite, dialog, SIP_180_RINGING,
    SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
    TAG_END());
  fail_unless(s2_check_event(nua_r_invite, 180));
  fail_unless(s2_check_callstate(nua_callstate_proceeding));

  nua_cancel(nh, TAG_END());
  cancel = s2_wait_for_request(SIP_METHOD_CANCEL);
  fail_if(!cancel);

812
  respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
813 814 815 816 817 818 819 820 821

  s2_respond_to(cancel, dialog, SIP_481_NO_TRANSACTION, TAG_END());
  s2_free_message(cancel);
  fail_unless(s2_check_event(nua_r_cancel, 481));

  fail_unless(s2_check_request(SIP_METHOD_ACK));

  fail_unless(s2_check_callstate(nua_callstate_ready));

822
  bye_by_nua(nh, TAG_END());
823 824 825 826 827 828

  nua_handle_destroy(nh);
}
END_TEST


829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
START_TEST(cancel_2_2_5)
{
  nua_handle_t *nh;
  struct message *invite, *cancel, *bye;

  s2_case(
    "2.2.5", "Cancel and 200 OK glare",
    "NUA is caller, "
    "NUA uses nua_bye() to send CANCEL after receiving 180\n"
    "but UAS already sent 200 OK.\n"
    "Test case checks that NUA really sends BYE after nua_bye() is called\n");

  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());

  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	     NUTAG_AUTOACK(0),
	     TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_calling));

  invite = s2_wait_for_request(SIP_METHOD_INVITE);
  process_offer(invite);
  respond_with_sdp(
    invite, dialog, SIP_180_RINGING,
    SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
    TAG_END());
  fail_unless(s2_check_event(nua_r_invite, 180));
  fail_unless(s2_check_callstate(nua_callstate_proceeding));

  nua_bye(nh, TAG_END());
  cancel = s2_wait_for_request(SIP_METHOD_CANCEL);
  fail_if(!cancel);

  respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());

  s2_respond_to(cancel, dialog, SIP_481_NO_TRANSACTION, TAG_END());
  s2_free_message(cancel);
  fail_unless(s2_check_event(nua_r_cancel, 481));

  fail_unless(s2_check_request(SIP_METHOD_ACK));

  fail_unless(s2_check_callstate(nua_callstate_terminating));

  bye = s2_wait_for_request(SIP_METHOD_BYE);
  fail_if(!bye);
  s2_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  s2_free_message(bye);
  fail_unless(s2_check_event(nua_r_bye, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));

  nua_handle_destroy(nh);
}
END_TEST


START_TEST(cancel_2_2_6)
{
  nua_handle_t *nh;
  struct event *invite;
  struct message *response;

  s2_case("2.2.6", "Cancel call",
	  "NUA is callee, sends 100, 180, INVITE gets canceled");

  soa_generate_offer(soa, 1, NULL);
  request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());

  invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  fail_unless(s2_check_callstate(nua_callstate_received));

  nh = invite->nh; fail_if(!nh);

  s2_free_event(invite);

  response = s2_wait_for_response(100, SIP_METHOD_INVITE);
  fail_if(!response);

  nua_respond(nh, SIP_180_RINGING,
	      SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	      TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_early));

  response = s2_wait_for_response(180, SIP_METHOD_INVITE);
  fail_if(!response);
  s2_update_dialog(dialog, response);
  process_answer(response);
  s2_free_message(response);

  fail_if(s2_request_to(dialog, SIP_METHOD_CANCEL, NULL, TAG_END()));
  fail_unless(s2_check_event(nua_i_cancel, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));

  response = s2_wait_for_response(200, SIP_METHOD_CANCEL);
  fail_if(!response);
  s2_free_message(response);

  response = s2_wait_for_response(487, SIP_METHOD_INVITE);
  fail_if(s2_request_to(dialog, SIP_METHOD_ACK, NULL,
			SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
			TAG_END()));

  nua_handle_destroy(nh);
}
END_TEST


START_TEST(cancel_2_2_7)
{
  nua_handle_t *nh;
  struct event *invite;
  struct message *response;
  char const *via = "SIP/2.0/UDP host.in.invalid;rport";

  s2_case("2.2.7", "Call gets canceled",
	  "NUA is callee, sends 100, 180, INVITE gets canceled. "
	  "Using RFC 2543 dialog and transaction matching.");

  soa_generate_offer(soa, 1, NULL);
  request_with_sdp(dialog, SIP_METHOD_INVITE, NULL,
		   SIPTAG_VIA_STR(via),
		   TAG_END());

  invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  fail_unless(s2_check_callstate(nua_callstate_received));

  nh = invite->nh; fail_if(!nh);

  s2_free_event(invite);

  response = s2_wait_for_response(100, SIP_METHOD_INVITE);
  fail_if(!response);

  nua_respond(nh, SIP_180_RINGING,
	      SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
	      TAG_END());
  fail_unless(s2_check_callstate(nua_callstate_early));

  response = s2_wait_for_response(180, SIP_METHOD_INVITE);
  fail_if(!response);
  s2_update_dialog(dialog, response);
  process_answer(response);
  s2_free_message(response);

  fail_if(s2_request_to(dialog, SIP_METHOD_CANCEL, NULL, TAG_END()));
  fail_unless(s2_check_event(nua_i_cancel, 200));
  fail_unless(s2_check_callstate(nua_callstate_terminated));

  response = s2_wait_for_response(200, SIP_METHOD_CANCEL);
  fail_if(!response);
  s2_free_message(response);

  response = s2_wait_for_response(487, SIP_METHOD_INVITE);
  fail_if(s2_request_to(dialog, SIP_METHOD_ACK, NULL,
			SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
			TAG_END()));

  nua_handle_destroy(nh);
}
END_TEST

988 989
TCase *cancel_tcase(void)
{
990 991
  TCase *tc = tcase_create("2.2 - CANCEL");
  tcase_add_checked_fixture(tc, call_setup, call_teardown);
992

993 994 995 996 997 998 999
  tcase_add_test(tc, cancel_2_2_1);
  tcase_add_test(tc, cancel_2_2_2);
  tcase_add_test(tc, cancel_2_2_3);
  tcase_add_test(tc, cancel_2_2_4);
  if (XXX) tcase_add_test(tc, cancel_2_2_5);
  tcase_add_test(tc, cancel_2_2_6);
  tcase_add_test(tc, cancel_2_2_7);
1000 1001 1002 1003 1004 1005 1006 1007

  return tc;
}


/* ---------------------------------------------------------------------- */
/* 2.3 - Session timers */

1008 1009
static void invite_timer_round(nua_handle_t *nh,
			       char const *session_expires)
1010 1011 1012 1013 1014
{
  struct message *invite, *ack;

  fail_unless(s2_check_callstate(nua_callstate_calling));
  invite = s2_wait_for_request(SIP_METHOD_INVITE);
1015 1016
  process_offer(invite);
  respond_with_sdp(
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
    invite, dialog, SIP_200_OK,
    SIPTAG_SESSION_EXPIRES_STR(session_expires),
    SIPTAG_REQUIRE_STR("timer"),
    TAG_END());
  s2_free_message(invite);
  fail_unless(s2_check_event(nua_r_invite, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));
  ack = s2_wait_for_request(SIP_METHOD_ACK);
  s2_free_message(ack);
}

1028
START_TEST(call_2_3_1)
1029 1030 1031 1032 1033 1034 1035 1036 1037
{
  nua_handle_t *nh;

  s2_case("2.3.1", "Incoming call with call timers",
	  "NUA receives INVITE, "
	  "activates call timers, "
	  "sends re-INVITE twice, "
	  "sends BYE.");

1038
  nh = invite_to_nua(
1039 1040 1041 1042 1043
    SIPTAG_SESSION_EXPIRES_STR("300;refresher=uas"),
    SIPTAG_REQUIRE_STR("timer"),
    TAG_END());

  s2_fast_forward(300);
1044
  invite_timer_round(nh, "300;refresher=uac");
1045
  s2_fast_forward(300);
1046
  invite_timer_round(nh, "300;refresher=uac");
1047

1048
  bye_by_nua(nh, TAG_END());
1049 1050 1051 1052 1053

  nua_handle_destroy(nh);
}
END_TEST

1054
START_TEST(call_2_3_2)
1055 1056 1057 1058 1059 1060 1061 1062 1063
{
  nua_handle_t *nh;

  s2_case("2.3.2", "Incoming call with call timers",
	  "NUA receives INVITE, "
	  "activates call timers, "
	  "sends re-INVITE, "
	  "sends BYE.");

1064
  nh = invite_to_nua(
1065 1066 1067 1068 1069
    SIPTAG_SESSION_EXPIRES_STR("300;refresher=uas"),
    SIPTAG_REQUIRE_STR("timer"),
    TAG_END());

  s2_fast_forward(300);
1070
  invite_timer_round(nh, "300");
1071
  s2_fast_forward(300);
1072
  invite_timer_round(nh, "300");
1073

1074
  bye_by_nua(nh, TAG_END());
1075 1076 1077 1078 1079

  nua_handle_destroy(nh);
}
END_TEST

1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
START_TEST(call_2_3_3)
{
  nua_handle_t *nh;
  struct message *response;

  s2_case("2.3.3", "Handling re-INVITE without SDP gracefully",
	  "NUA receives INVITE, "
	  "re-INVITE without SDP (w/o NUTAG_REFRESH_WITHOUT_SDP(), "
	  "re-INVITE without SDP (using NUTAG_REFRESH_WITHOUT_SDP(), "
	  "sends BYE.");

  nh = invite_to_nua(
    TAG_END());

  s2_request_to(dialog, SIP_METHOD_INVITE, NULL,
		SIPTAG_USER_AGENT_STR("evil (evil) evil"),
		TAG_END());
1097

1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
  nua_respond(nh, SIP_200_OK, TAG_END());

  fail_unless(s2_check_callstate(nua_callstate_completed));

  response = s2_wait_for_response(200, SIP_METHOD_INVITE);

  fail_if(!response);
  s2_update_dialog(dialog, response);
  fail_if(!response->sip->sip_content_type);
  s2_free_message(response);

  fail_if(s2_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));

  fail_unless(s2_check_event(nua_i_ack, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));

  s2_fast_forward(10);

  nua_set_hparams(nh, NUTAG_REFRESH_WITHOUT_SDP(1), TAG_END());
  fail_unless(s2_check_event(nua_r_set_params, 200));

  s2_request_to(dialog, SIP_METHOD_INVITE, NULL,
		SIPTAG_USER_AGENT_STR("evil (evil) evil"),
		TAG_END());
1122

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
  nua_respond(nh, SIP_200_OK, TAG_END());

  fail_unless(s2_check_callstate(nua_callstate_completed));

  response = s2_wait_for_response(200, SIP_METHOD_INVITE);

  fail_if(!response);
  s2_update_dialog(dialog, response);
  fail_if(response->sip->sip_content_type);
  s2_free_message(response);

  fail_if(s2_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));

  fail_unless(s2_check_event(nua_i_ack, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));

  bye_by_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST

1145 1146 1147

TCase *session_timer_tcase(void)
{
1148 1149
  TCase *tc = tcase_create("2.3 - Session timers");
  tcase_add_checked_fixture(tc, call_setup, call_teardown);
1150
  {
1151 1152
    tcase_add_test(tc, call_2_3_1);
    tcase_add_test(tc, call_2_3_2);
1153
    tcase_add_test(tc, call_2_3_3);
1154 1155 1156 1157
  }
  return tc;
}

1158
/* ====================================================================== */
1159 1160
/* 2.4 - 100rel */

1161
START_TEST(call_2_4_1)
1162 1163 1164
{
  nua_handle_t *nh;
  struct message *invite, *prack;
1165
  int with_sdp;
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179

  s2_case("2.4.1", "Call with 100rel",
	  "NUA sends INVITE, "
	  "receives 183, sends PRACK, receives 200 for it, "
	  "receives 180, sends PRACK, receives 200 for it, "
          "receives 200, send ACK.");

  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());

  invite = invite_sent_by_nua(
    nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
    TAG_END());
  process_offer(invite);

1180
  prack = respond_with_100rel(invite, dialog, with_sdp = 1,
1181 1182
			      SIP_183_SESSION_PROGRESS,
			      TAG_END());
1183
  s2_respond_to(prack, dialog, SIP_200_OK, TAG_END());
1184 1185 1186 1187
  s2_free_message(prack), prack = NULL;
  fail_unless(s2_check_callstate(nua_callstate_proceeding));
  fail_unless(s2_check_event(nua_r_prack, 200));

1188
  prack = respond_with_100rel(invite, dialog, with_sdp = 0,
1189 1190
			      SIP_180_RINGING,
			      TAG_END());
1191
  s2_respond_to(prack, dialog, SIP_200_OK, TAG_END());
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
  s2_free_message(prack), prack = NULL;
  fail_unless(s2_check_callstate(nua_callstate_proceeding));
  fail_unless(s2_check_event(nua_r_prack, 200));

  s2_respond_to(invite, dialog, SIP_200_OK, TAG_END());
  s2_free_message(invite);
  fail_unless(s2_check_event(nua_r_invite, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));
  fail_unless(s2_check_request(SIP_METHOD_ACK));

  bye_to_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST

1208
START_TEST(call_2_4_2)
1209 1210 1211
{
  nua_handle_t *nh;
  struct message *invite, *prack;
1212
  int with_sdp;
1213

1214
  s2_case("2.4.2", "Call with 100rel",
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
	  "NUA sends INVITE, "
	  "receives 183, sends PRACK, receives 200 for it, "
	  "receives 180, sends PRACK, receives 200 for it, "
          "receives 200, send ACK.");

  nh = nua_handle(nua, NULL, SIPTAG_TO(s2->local), TAG_END());

  invite = invite_sent_by_nua(
    nh,
    NUTAG_MEDIA_ENABLE(0),
    SIPTAG_CONTENT_TYPE_STR("application/sdp"),
    SIPTAG_PAYLOAD_STR(
      "v=0" CRLF
      "o=- 6805647540234172778 5821668777690722690 IN IP4 127.0.0.1" CRLF
      "s=-" CRLF
      "c=IN IP4 127.0.0.1" CRLF
      "m=audio 5004 RTP/AVP 0 8" CRLF),
    TAG_END());

1234
  prack = respond_with_100rel(invite, dialog, with_sdp = 0,
1235 1236
			      SIP_183_SESSION_PROGRESS,
			      TAG_END());
1237
  s2_respond_to(prack, dialog, SIP_200_OK, TAG_END());
1238 1239 1240
  s2_free_message(prack), prack = NULL;
  fail_unless(s2_check_callstate(nua_callstate_proceeding));
  fail_unless(s2_check_event(nua_r_prack, 200));
1241

1242
  prack = respond_with_100rel(invite, dialog, with_sdp = 0,
1243 1244
			      SIP_180_RINGING,
			      TAG_END());
1245
  s2_respond_to(prack, dialog, SIP_200_OK, TAG_END());
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
  s2_free_message(prack), prack = NULL;
  fail_unless(s2_check_callstate(nua_callstate_proceeding));
  fail_unless(s2_check_event(nua_r_prack, 200));

  s2_respond_to(invite, dialog, SIP_200_OK, TAG_END());
  s2_free_message(invite);
  fail_unless(s2_check_event(nua_r_invite, 200));
  fail_unless(s2_check_callstate(nua_callstate_ready));
  fail_unless(s2_check_request(SIP_METHOD_ACK));

  bye_to_nua(nh, TAG_END());

  nua_handle_destroy(nh);
}
END_TEST

TCase *invite_100rel_tcase(void)
{
  TCase *tc = tcase_create("2.4 - INVITE with 100rel");
  tcase_add_checked_fixture(tc, call_setup, call_teardown);
  {
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351