#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/Chunk.hpp"
#include "RTC/SCTP/packet/Parameter.hpp"
#include "RTC/SCTP/packet/chunks/InitAckChunk.hpp"
#include "RTC/SCTP/packet/parameters/IPv4AddressParameter.hpp"
#include "RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
SCENARIO("SCTP Init Acknowledgement (2)", "[serializable][sctp][chunk]")
{
sctpCommon::ResetBuffers();
SECTION("InitAckChunk::Parse() succeeds")
{
alignas(4) uint8_t buffer[] =
{
0x02, 0b00000000, 0x00, 0x1C,
0x11, 0x22, 0x33, 0x44,
0xFF, 0x00, 0x66, 0x77,
0x12, 0x34, 0x56, 0x78,
0xAB, 0xCD, 0x01, 0x02,
0x00, 0x05, 0x00, 0x08,
0x02, 0x03, 0x04, 0x05,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC, 0xDD,
};
auto* chunk = RTC::SCTP::InitAckChunk::Parse(buffer, sizeof(buffer));
CHECK_SCTP_CHUNK(
chunk,
buffer,
sizeof(buffer),
28,
RTC::SCTP::Chunk::ChunkType::INIT_ACK,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000000,
true,
1,
false,
0);
REQUIRE(chunk->GetInitiateTag() == 287454020);
REQUIRE(chunk->GetAdvertisedReceiverWindowCredit() == 4278216311);
REQUIRE(chunk->GetNumberOfOutboundStreams() == 4660);
REQUIRE(chunk->GetNumberOfInboundStreams() == 22136);
REQUIRE(chunk->GetInitialTsn() == 2882339074);
auto* parameter1 =
reinterpret_cast<const RTC::SCTP::IPv4AddressParameter*>(chunk->GetParameterAt(0));
CHECK_SCTP_PARAMETER(
parameter1,
nullptr,
8,
8,
RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter1->GetIPv4Address()[0] == 0x02);
REQUIRE(parameter1->GetIPv4Address()[1] == 0x03);
REQUIRE(parameter1->GetIPv4Address()[2] == 0x04);
REQUIRE(parameter1->GetIPv4Address()[3] == 0x05);
delete chunk;
}
SECTION("InitAckChunk::Factory() succeeds")
{
auto* chunk =
RTC::SCTP::InitAckChunk::Factory(sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
20,
RTC::SCTP::Chunk::ChunkType::INIT_ACK,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000000,
true,
0,
false,
0);
REQUIRE(chunk->GetInitiateTag() == 0);
REQUIRE(chunk->GetAdvertisedReceiverWindowCredit() == 0);
REQUIRE(chunk->GetNumberOfOutboundStreams() == 0);
REQUIRE(chunk->GetNumberOfInboundStreams() == 0);
REQUIRE(chunk->GetInitialTsn() == 0);
chunk->SetInitiateTag(1111111110);
chunk->SetAdvertisedReceiverWindowCredit(2222222220);
chunk->SetNumberOfOutboundStreams(1234);
chunk->SetNumberOfInboundStreams(5678);
chunk->SetInitialTsn(3333333330);
auto* parameter1 = chunk->BuildParameterInPlace<RTC::SCTP::IPv4AddressParameter>();
uint8_t ipBuffer1[] = { 0x0B, 0x16, 0x21, 0x2C };
parameter1->SetIPv4Address(ipBuffer1);
parameter1->Consolidate();
CHECK_SCTP_CHUNK(
chunk,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
28,
RTC::SCTP::Chunk::ChunkType::INIT_ACK,
false,
RTC::SCTP::Chunk::ActionForUnknownChunkType::STOP,
0b00000000,
true,
1,
false,
0);
REQUIRE(chunk->GetInitiateTag() == 1111111110);
REQUIRE(chunk->GetAdvertisedReceiverWindowCredit() == 2222222220);
REQUIRE(chunk->GetNumberOfOutboundStreams() == 1234);
REQUIRE(chunk->GetNumberOfInboundStreams() == 5678);
REQUIRE(chunk->GetInitialTsn() == 3333333330);
const auto* addedParameter1 =
reinterpret_cast<const RTC::SCTP::IPv4AddressParameter*>(chunk->GetParameterAt(0));
CHECK_SCTP_PARAMETER(
addedParameter1,
nullptr,
8,
8,
RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(addedParameter1->GetIPv4Address()[0] == 0x0B);
REQUIRE(addedParameter1->GetIPv4Address()[1] == 0x16);
REQUIRE(addedParameter1->GetIPv4Address()[2] == 0x21);
REQUIRE(addedParameter1->GetIPv4Address()[3] == 0x2C);
delete chunk;
}
}