test_UDPv4Transport.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _FASTDDS_TEST_UDPV4_TRANSPORT_H_
  15. #define _FASTDDS_TEST_UDPV4_TRANSPORT_H_
  16. #include <fastdds/rtps/transport/UDPv4Transport.h>
  17. #include <fastdds/rtps/messages/RTPS_messages.h>
  18. #include <fastdds/rtps/common/SequenceNumber.h>
  19. #include <fastdds/rtps/messages/CDRMessage.h>
  20. #include <vector>
  21. #include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
  22. namespace eprosima{
  23. namespace fastdds{
  24. namespace rtps{
  25. /*
  26. * This transport acts as a shim over UDPv4, allowing
  27. * packets to be dropped under certain criteria.
  28. */
  29. class test_UDPv4Transport : public UDPv4Transport
  30. {
  31. public:
  32. test_UDPv4Transport(const test_UDPv4TransportDescriptor& descriptor);
  33. virtual bool send(
  34. const fastrtps::rtps::octet* send_buffer,
  35. uint32_t send_buffer_size,
  36. eProsimaUDPSocket& socket,
  37. fastrtps::rtps::LocatorsIterator* destination_locators_begin,
  38. fastrtps::rtps::LocatorsIterator* destination_locators_end,
  39. bool only_multicast_purpose,
  40. const std::chrono::steady_clock::time_point& max_blocking_time_point) override;
  41. RTPS_DllAPI static bool test_UDPv4Transport_ShutdownAllNetwork;
  42. // Handle to a persistent log of dropped packets. Defaults to length 0 (no logging) to prevent wasted resources.
  43. RTPS_DllAPI static std::vector<std::vector<fastrtps::rtps::octet> > test_UDPv4Transport_DropLog;
  44. RTPS_DllAPI static uint32_t test_UDPv4Transport_DropLogLength;
  45. RTPS_DllAPI static bool always_drop_participant_builtin_topic_data;
  46. private:
  47. struct PercentageData
  48. {
  49. PercentageData(uint8_t percent)
  50. : percentage(percent)
  51. , accumulator(0)
  52. {
  53. }
  54. uint8_t percentage;
  55. uint8_t accumulator;
  56. };
  57. typedef std::function<bool(fastrtps::rtps::CDRMessage_t& msg)> filter;
  58. PercentageData drop_data_messages_percentage_;
  59. test_UDPv4TransportDescriptor::filter drop_data_messages_filter_;
  60. bool drop_participant_builtin_topic_data_;
  61. bool drop_publication_builtin_topic_data_;
  62. bool drop_subscription_builtin_topic_data_;
  63. PercentageData drop_data_frag_messages_percentage_;
  64. test_UDPv4TransportDescriptor::filter drop_data_frag_messages_filter_;
  65. PercentageData drop_heartbeat_messages_percentage_;
  66. test_UDPv4TransportDescriptor::filter drop_heartbeat_messages_filter_;
  67. PercentageData drop_ack_nack_messages_percentage_;
  68. test_UDPv4TransportDescriptor::filter drop_ack_nack_messages_filter_;
  69. PercentageData drop_gap_messages_percentage_;
  70. test_UDPv4TransportDescriptor::filter drop_gap_messages_filter_;
  71. PercentageData percentage_of_messages_to_drop_;
  72. test_UDPv4TransportDescriptor::filter messages_filter_;
  73. std::vector<fastrtps::rtps::SequenceNumber_t> sequence_number_data_messages_to_drop_;
  74. bool log_drop(const fastrtps::rtps::octet* buffer, uint32_t size);
  75. bool packet_should_drop(const fastrtps::rtps::octet* send_buffer, uint32_t send_buffer_size);
  76. bool random_chance_drop();
  77. bool should_be_dropped(PercentageData* percentage);
  78. bool send(
  79. const fastrtps::rtps::octet* send_buffer,
  80. uint32_t send_buffer_size,
  81. eProsimaUDPSocket& socket,
  82. const fastrtps::rtps::Locator_t& remote_locator,
  83. bool only_multicast_purpose,
  84. const std::chrono::microseconds& timeout);
  85. };
  86. } // namespace rtps
  87. } // namespace fastdds
  88. } // namespace eprosima
  89. #endif // _FASTDDS_TEST_UDPV4_TRANSPORT_H_