Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_executable(runUnitTestsEFP
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest21.cpp
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest22.cpp
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest23.cpp
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest24.cpp
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTestHelpers.cpp
)

Expand Down
10 changes: 9 additions & 1 deletion ElasticFrameProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ ElasticFrameProtocolReceiver::unpackType1(const uint8_t *pSubPacket, size_t lPac
pThisBucket->mActive = false;
return ElasticFrameMessages::memoryAllocationError;
}

if (pThisBucket->mOfFragmentNo < lType1Frame->hFragmentNo) {
EFP_LOGGER(true, LOGG_FATAL, "bufferOutOfBounds")
mBucketMap.erase(pThisBucket->mDeliveryOrder);
pThisBucket->mActive = false;
return ElasticFrameMessages::bufferOutOfBounds;
}

std::copy_n(pSubPacket + sizeof(ElasticFrameType1), lPacketSize - sizeof(ElasticFrameType1),
pThisBucket->mBucketData->pFrameData + lInsertDataPointer);
return ElasticFrameMessages::noError;
Expand Down Expand Up @@ -329,7 +337,7 @@ ElasticFrameProtocolReceiver::unpackType2(const uint8_t *pSubPacket, size_t lPac
return ElasticFrameMessages::noError;
}

// Unpack method for type3 packets. Type3 packets are the parts of frames where the reminder data does not fit a type2 packet. Then a type 3 is added
// Unpack method for type3 packets. Type3 packets are the parts of frames where the remainder data does not fit a type2 packet. Then a type 3 is added
// in front of a type2 packet to catch the data overshoot.
// Type 3 frames MUST be the same header size as type1 headers (FIXME part of the opportunistic data discussion)
ElasticFrameMessages
Expand Down
6 changes: 3 additions & 3 deletions efp_c_api/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void send_data_callback(const uint8_t *data, size_t size, uint8_t stream_id, voi
}

void receive_embedded_data_callback(uint8_t *data, size_t size, uint8_t data_type, uint64_t pts, void* ctx) {
printf("Got embedded data: %zu bytes size and of type %d pts: %lu\n", size, data_type, pts);
printf("Got embedded data: %zu bytes size and of type %d pts: %llu\n", size, data_type, pts);
//In this example we know it's a string, print it.
printf("Data: %s \n", data);
printf("Context: %d \n\n", *(int*)ctx);
Expand Down Expand Up @@ -72,8 +72,8 @@ void receive_data_callback(uint8_t *data,
printf("mFrameSize: %zu\n", size);
printf("mDataContent: %d\n", data_content);
printf("mBroken: %d\n", broken);
printf("mPts: %lu\n", pts);
printf("mDts: %lu\n", dts);
printf("mPts: %llu\n", pts);
printf("mDts: %llu\n", dts);
printf("mCode: %d\n", code);
printf("mStreamID: %d\n", stream_id);
printf("mSource: %d\n", source);
Expand Down
40 changes: 40 additions & 0 deletions unitTests/UnitTest24.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <gtest/gtest.h>

#include <memory>
#include <random>

#include "ElasticFrameProtocol.h"
#include "UnitTestHelpers.h"

// UnitTest24
// Test receiving corrupted packages
TEST(UnitTest24, SendPacketFrameType1AndFrameType2) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<unsigned int> dis(0, 255);

std::unique_ptr<ElasticFrameProtocolReceiver> myEFPReceiver =
std::make_unique<ElasticFrameProtocolReceiver>(50, 20);
std::unique_ptr<ElasticFrameProtocolSender> myEFPPacker =
std::make_unique<ElasticFrameProtocolSender>(MTU);

for (int i = 0; i < 10000; i++) {
myEFPPacker->sendCallback = [&](const std::vector<uint8_t> &subPacket,
uint8_t lStreamID,
ElasticFrameProtocolContext *pCTX) {
std::vector<uint8_t> garbage = subPacket;

std::generate(garbage.begin(), garbage.end(),
[&]() { return static_cast<uint8_t>(dis(gen)); });
};

std::vector<uint8_t> mydata;
size_t randSize = rand() % 10000 + 1;
mydata.resize(randSize);

uint8_t streamID = 4;
ElasticFrameMessages result = myEFPPacker->packAndSend(
mydata, ElasticFrameContent::adts, 1001, 1, 2, streamID, NO_FLAGS);
EXPECT_EQ(result, ElasticFrameMessages::noError);
}
}