test_engine.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. #include "zrtp.h"
  10. /** libzrtp test elements identifier */
  11. typedef uint32_t zrtp_test_id_t;
  12. /** Defines constant for unknown test element identifier */
  13. #define ZRTP_TEST_UNKNOWN_ID 0
  14. /** Default lengths for libzrtp test string buffers */
  15. #define ZRTP_TEST_STR_LEN 128
  16. /** libzrtp test endpoint configuration */
  17. typedef struct {
  18. zrtp_config_t zrtp; /** libzrtp global configuration parameters */
  19. unsigned generate_traffic; /** switch On to emulate RTP/RTCP traffic generation. Off by default. */
  20. } zrtp_test_endpoint_cfg_t;
  21. /** ZRTP test session parameters*/
  22. typedef struct {
  23. zrtp_profile_t zrtp; /** libzrtp session parameters */
  24. unsigned streams_count; /** number of zrtp streams to be attached to the session */
  25. zrtp_signaling_role_t role; /** signaling role, default is ZRTP_SIGNALING_ROLE_UNKNOWN */
  26. unsigned is_enrollment; /** true if enrollment session should be created */
  27. } zrtp_test_session_cfg_t;
  28. /** ZRTP test stream info */
  29. typedef struct {
  30. zrtp_stream_info_t zrtp; /** libzrtp stream info */
  31. unsigned zrtp_events_queueu[128]; /** list of received zrtp events*/
  32. unsigned zrtp_events_count; /** number of received events */
  33. } zrtp_test_stream_info_t;
  34. /** ZRTP test session state snapshot */
  35. typedef struct {
  36. zrtp_session_info_t zrtp; /** libzrtp session info*/
  37. zrtp_test_stream_info_t streams[ZRTP_MAX_STREAMS_PER_SESSION]; /** array of attached streams info */
  38. unsigned streams_count; /** number streams attached to the session */
  39. } zrtp_test_session_info_t;
  40. /** *ZRTP test channel state */
  41. typedef struct {
  42. zrtp_test_stream_info_t left; /** one-leg zrtp stream */
  43. zrtp_test_stream_info_t right; /** second-leg zrtp stream */
  44. unsigned char is_secure; /** enabled when both streams in the channel are secure */
  45. } zrtp_test_channel_info_t;
  46. /**
  47. * Initialize zrtp test endpoint configuration with default values
  48. * @param cfg - endpoint config to initialize
  49. */
  50. void zrtp_test_endpoint_config_defaults(zrtp_test_endpoint_cfg_t *cfg);
  51. /**
  52. * ZRTP test endpoint constructor
  53. * One endpoint is created, it starts processing threads and ready to emulate ZRTP exchange.
  54. *
  55. * @param cfg - endpoint configuration
  56. * @param name - endpoint name for debug purposes and cache naming, e.h "Alice", "Bob".
  57. * @param id - just created endpoint identifier will be placed here
  58. *
  59. * @return zrtp_status_ok on success or some of zrtp_status_t error codes on failure
  60. */
  61. zrtp_status_t zrtp_test_endpoint_create(zrtp_test_endpoint_cfg_t *cfg,
  62. const char *name,
  63. zrtp_test_id_t *id);
  64. /**
  65. * ZRTP test endpoint destructor
  66. * zrtp_test_endpoint_destroy() stops processing threads and release all
  67. * recurses allocated in zrtp_test_endpoint_create().
  68. *
  69. * @param id - endpoint identifier
  70. * @return zrtp_status_ok on success or some of zrtp_status_t error codes on failure
  71. */
  72. zrtp_status_t zrtp_test_endpoint_destroy(zrtp_test_id_t id);
  73. /**
  74. * Enables test session config with default values
  75. * @param cfg - session config for initialization
  76. */
  77. void zrtp_test_session_config_defaults(zrtp_test_session_cfg_t *cfg);
  78. /**
  79. * Create zrtp test session
  80. *
  81. * @param endpoint - test endpoint creating endpoint should belong to
  82. * @param cfg - session parameters
  83. * @param id - created session identifier will be placed here
  84. * @return zrtp_status_ok on success or some of zrtp_status_t error codes on failure
  85. */
  86. zrtp_status_t zrtp_test_session_create(zrtp_test_id_t endpoint,
  87. zrtp_test_session_cfg_t *cfg,
  88. zrtp_test_id_t *id);
  89. zrtp_status_t zrtp_test_session_destroy(zrtp_test_id_t id);
  90. zrtp_status_t zrtp_test_session_get(zrtp_test_id_t id, zrtp_test_session_info_t *info);
  91. /**
  92. * Get stream Id by it's index in zrtp session
  93. *
  94. * @param session_id - zrtp test session id where needed stream should be taken
  95. * @param idx - stream index
  96. * @return found stream id, or ZRTP_TEST_UNKNOWN_ID if idex is out of stream array range
  97. */
  98. zrtp_test_id_t zrtp_test_session_get_stream_by_idx(zrtp_test_id_t session_id, unsigned idx);
  99. zrtp_status_t zrtp_test_stream_get(zrtp_test_id_t id, zrtp_test_stream_info_t *info);
  100. zrtp_status_t zrtp_test_channel_create(zrtp_test_id_t left_stream, zrtp_test_id_t right_stream, zrtp_test_id_t *id);
  101. zrtp_status_t zrtp_test_channel_create2(zrtp_test_id_t left_session, zrtp_test_id_t right_session, unsigned stream_idx, zrtp_test_id_t *id);
  102. zrtp_status_t zrtp_test_channel_destroy(zrtp_test_id_t id);
  103. zrtp_status_t zrtp_test_channel_start(zrtp_test_id_t id);
  104. zrtp_status_t zrtp_test_channel_get(zrtp_test_id_t id, zrtp_test_channel_info_t *info);
  105. zrtp_stream_t *zrtp_stream_for_test_stream(zrtp_test_id_t stream_id);
  106. unsigned zrtp_stream_did_event_receive(zrtp_test_id_t stream_id, unsigned event);