#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/Parameter.hpp"
#include "RTC/SCTP/packet/parameters/ReconfigurationResponseParameter.hpp"
#include "RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
SCENARIO("Re-configuration Response Parameter (16)", "[serializable][sctp][parameter]")
{
sctpCommon::ResetBuffers();
SECTION("ReconfigurationResponseParameter::Parse() with Sender's and Receiver's Next TSN succeeds")
{
alignas(4) uint8_t buffer[] =
{
0x00, 0x10, 0x00, 0x14,
0x11, 0x22, 0x33, 0x44,
0x00, 0x00, 0x00, 0x01,
0x42, 0x3A, 0x35, 0xC7,
0x84, 0x74, 0x6B, 0x8E,
0xAA, 0xBB, 0xCC
};
auto* parameter = RTC::SCTP::ReconfigurationResponseParameter::Parse(buffer, sizeof(buffer));
CHECK_SCTP_PARAMETER(
parameter,
buffer,
sizeof(buffer),
20,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetReconfigurationResponseSequenceNumber() == 287454020);
REQUIRE(
parameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::SUCCESS_PERFORMED);
REQUIRE(parameter->HasNextTsns() == true);
REQUIRE(parameter->GetSenderNextTsn() == 1111111111);
REQUIRE(parameter->GetReceiverNextTsn() == 2222222222);
parameter->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
20,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetReconfigurationResponseSequenceNumber() == 287454020);
REQUIRE(
parameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::SUCCESS_PERFORMED);
REQUIRE(parameter->HasNextTsns() == true);
REQUIRE(parameter->GetSenderNextTsn() == 1111111111);
REQUIRE(parameter->GetReceiverNextTsn() == 2222222222);
auto* clonedParameter =
parameter->Clone(sctpCommon::CloneBuffer, sizeof(sctpCommon::CloneBuffer));
std::memset(sctpCommon::SerializeBuffer, 0x00, sizeof(sctpCommon::SerializeBuffer));
delete parameter;
CHECK_SCTP_PARAMETER(
clonedParameter,
sctpCommon::CloneBuffer,
sizeof(sctpCommon::CloneBuffer),
20,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(clonedParameter->GetReconfigurationResponseSequenceNumber() == 287454020);
REQUIRE(
clonedParameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::SUCCESS_PERFORMED);
REQUIRE(clonedParameter->HasNextTsns() == true);
REQUIRE(clonedParameter->GetSenderNextTsn() == 1111111111);
REQUIRE(clonedParameter->GetReceiverNextTsn() == 2222222222);
delete clonedParameter;
}
SECTION("ReconfigurationResponseParameter::Parse() without Sender's and Receiver's Next TSN succeeds")
{
alignas(4) uint8_t buffer[] =
{
0x00, 0x10, 0x00, 0x0C,
0xC6, 0xAE, 0xA1, 0x55,
0x00, 0x00, 0x00, 0x04,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC, 0xDD,
};
auto* parameter = RTC::SCTP::ReconfigurationResponseParameter::Parse(buffer, sizeof(buffer));
CHECK_SCTP_PARAMETER(
parameter,
buffer,
sizeof(buffer),
12,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetReconfigurationResponseSequenceNumber() == 3333333333);
REQUIRE(
parameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::ERROR_REQUEST_ALREADY_IN_PROGRESS);
REQUIRE(parameter->HasNextTsns() == false);
parameter->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
12,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetReconfigurationResponseSequenceNumber() == 3333333333);
REQUIRE(
parameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::ERROR_REQUEST_ALREADY_IN_PROGRESS);
REQUIRE(parameter->HasNextTsns() == false);
auto* clonedParameter =
parameter->Clone(sctpCommon::CloneBuffer, sizeof(sctpCommon::CloneBuffer));
std::memset(sctpCommon::SerializeBuffer, 0x00, sizeof(sctpCommon::SerializeBuffer));
delete parameter;
CHECK_SCTP_PARAMETER(
clonedParameter,
sctpCommon::CloneBuffer,
sizeof(sctpCommon::CloneBuffer),
12,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(clonedParameter->GetReconfigurationResponseSequenceNumber() == 3333333333);
REQUIRE(
clonedParameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::ERROR_REQUEST_ALREADY_IN_PROGRESS);
REQUIRE(clonedParameter->HasNextTsns() == false);
delete clonedParameter;
}
SECTION("ReconfigurationResponseParameter::Parse() fails")
{
alignas(4) uint8_t buffer1[] =
{
0x00, 0x10, 0x00, 0x10,
0x11, 0x22, 0x33, 0x44,
0x00, 0x00, 0x00, 0x01,
0x42, 0x3A, 0x35, 0xC7,
0x84, 0x74, 0x6B, 0x8E,
};
REQUIRE(!RTC::SCTP::ReconfigurationResponseParameter::Parse(buffer1, sizeof(buffer1)));
alignas(4) uint8_t buffer2[] =
{
0x00, 0x10, 0x00, 0x14,
0x11, 0x22, 0x33, 0x44,
0x00, 0x00, 0x00, 0x01,
0x42, 0x3A, 0x35, 0xC7,
};
REQUIRE(!RTC::SCTP::ReconfigurationResponseParameter::Parse(buffer2, sizeof(buffer2)));
}
SECTION("ReconfigurationResponseParameter::Factory() succeeds")
{
auto* parameter = RTC::SCTP::ReconfigurationResponseParameter::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
12,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetReconfigurationResponseSequenceNumber() == 0);
REQUIRE(
parameter->GetResult() == static_cast<RTC::SCTP::ReconfigurationResponseParameter::Result>(0));
REQUIRE(parameter->HasNextTsns() == false);
parameter->SetReconfigurationResponseSequenceNumber(111000);
parameter->SetResult(RTC::SCTP::ReconfigurationResponseParameter::Result::IN_PROGRESS);
parameter->SetNextTsns(100000000, 200000000);
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
20,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetReconfigurationResponseSequenceNumber() == 111000);
REQUIRE(
parameter->GetResult() == RTC::SCTP::ReconfigurationResponseParameter::Result::IN_PROGRESS);
REQUIRE(parameter->HasNextTsns() == true);
REQUIRE(parameter->GetSenderNextTsn() == 100000000);
REQUIRE(parameter->GetReceiverNextTsn() == 200000000);
auto* parsedParameter = RTC::SCTP::ReconfigurationResponseParameter::Parse(
parameter->GetBuffer(), parameter->GetLength());
delete parameter;
CHECK_SCTP_PARAMETER(
parsedParameter,
sctpCommon::FactoryBuffer,
20,
20,
RTC::SCTP::Parameter::ParameterType::RECONFIGURATION_RESPONSE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parsedParameter->GetReconfigurationResponseSequenceNumber() == 111000);
REQUIRE(
parsedParameter->GetResult() ==
RTC::SCTP::ReconfigurationResponseParameter::Result::IN_PROGRESS);
REQUIRE(parsedParameter->HasNextTsns() == true);
REQUIRE(parsedParameter->GetSenderNextTsn() == 100000000);
REQUIRE(parsedParameter->GetReceiverNextTsn() == 200000000);
delete parsedParameter;
}
}