Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
include(UseGTest)
|
||||
configure_gtest_directory(LINK_LIBRARIES btp)
|
||||
|
||||
add_gtest(BtpDataIndication data_indication.cpp)
|
||||
add_gtest(BtpHeader header.cpp)
|
||||
add_gtest(BtpPortDispatcher port_dispatcher.cpp)
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/btp/data_indication.hpp>
|
||||
#include <vanetza/btp/header.hpp>
|
||||
#include <vanetza/geonet/data_indication.hpp>
|
||||
#include <boost/optional/optional_io.hpp>
|
||||
|
||||
using namespace vanetza;
|
||||
|
||||
TEST(BtpDataIndication, construct_from_header_b) {
|
||||
geonet::DataIndication gn_ind;
|
||||
gn_ind.transport_type = geonet::TransportType::GUC;
|
||||
gn_ind.destination = geonet::Address { MacAddress { 1, 2, 3, 4, 5, 6 }};
|
||||
gn_ind.traffic_class.store_carry_forward(true);
|
||||
gn_ind.source_position.longitude =
|
||||
static_cast<geonet::geo_angle_i32t>(43.8 * units::degree);
|
||||
gn_ind.remaining_packet_lifetime =
|
||||
geonet::Lifetime(geonet::Lifetime::Base::Ten_Seconds, 3);
|
||||
|
||||
btp::HeaderB hdr;
|
||||
hdr.destination_port = host_cast<uint16_t>(0x1816);
|
||||
hdr.destination_port_info = host_cast<uint16_t>(0x4711);;
|
||||
|
||||
btp::DataIndication btp_ind(gn_ind, hdr);
|
||||
EXPECT_FALSE(btp_ind.source_port);
|
||||
EXPECT_EQ(hdr.destination_port, btp_ind.destination_port);
|
||||
EXPECT_EQ(hdr.destination_port_info, btp_ind.destination_port_info);
|
||||
EXPECT_EQ(boost::get<geonet::Address>(gn_ind.destination),
|
||||
boost::get<geonet::Address>(btp_ind.destination));
|
||||
EXPECT_EQ(gn_ind.source_position, btp_ind.source_position);
|
||||
EXPECT_EQ(gn_ind.traffic_class.raw(), btp_ind.traffic_class.raw());
|
||||
ASSERT_TRUE(!!btp_ind.remaining_packet_lifetime);
|
||||
EXPECT_EQ(gn_ind.remaining_packet_lifetime->raw(),
|
||||
btp_ind.remaining_packet_lifetime->raw());
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/btp/header.hpp>
|
||||
#include <vanetza/common/serialization_buffer.hpp>
|
||||
|
||||
using namespace vanetza;
|
||||
|
||||
const ByteBuffer ref = { 0x38, 0x84, 0x01, 0x40 };
|
||||
|
||||
TEST(BtpHeaderA, serialize) {
|
||||
btp::HeaderA header;
|
||||
header.destination_port = host_cast<uint16_t>(0x3884);
|
||||
header.source_port = host_cast<uint16_t>(0x0140);
|
||||
ByteBuffer buf;
|
||||
serialize_into_buffer(header, buf);
|
||||
EXPECT_EQ(ref, buf);
|
||||
}
|
||||
|
||||
TEST(BtpHeaderA, deserialize) {
|
||||
btp::HeaderA header;
|
||||
deserialize_from_buffer(header, ref);
|
||||
EXPECT_EQ(host_cast<uint16_t>(0x3884), header.destination_port);
|
||||
EXPECT_EQ(host_cast<uint16_t>(0x0140), header.source_port);
|
||||
}
|
||||
|
||||
TEST(BtpHeaderB, serialize) {
|
||||
btp::HeaderB header;
|
||||
header.destination_port = host_cast<uint16_t>(0x3884);
|
||||
header.destination_port_info = host_cast<uint16_t>(0x0140);
|
||||
ByteBuffer buf;
|
||||
serialize_into_buffer(header, buf);
|
||||
EXPECT_EQ(ref, buf);
|
||||
}
|
||||
|
||||
TEST(BtpHeaderB, deserialize) {
|
||||
btp::HeaderB header;
|
||||
deserialize_from_buffer(header, ref);
|
||||
EXPECT_EQ(host_cast<uint16_t>(0x3884), header.destination_port);
|
||||
EXPECT_EQ(host_cast<uint16_t>(0x0140), header.destination_port_info);
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vanetza/btp/header_conversion.hpp>
|
||||
#include <vanetza/btp/port_dispatcher.hpp>
|
||||
#include <vanetza/btp/ports.hpp>
|
||||
#include <vanetza/geonet/data_indication.hpp>
|
||||
#include <vanetza/net/osi_layer.hpp>
|
||||
#include <vanetza/net/packet.hpp>
|
||||
|
||||
using namespace vanetza;
|
||||
using namespace vanetza::btp;
|
||||
using vanetza::geonet::UpperProtocol;
|
||||
|
||||
class CounterIndicationInterface : public IndicationInterface
|
||||
{
|
||||
public:
|
||||
void indicate(const DataIndication&, std::unique_ptr<UpPacket>) override
|
||||
{
|
||||
++counter;
|
||||
}
|
||||
|
||||
unsigned counter = 0;
|
||||
};
|
||||
|
||||
class CounterPromiscuousHook : public PortDispatcher::PromiscuousHook
|
||||
{
|
||||
public:
|
||||
void tap_packet(const DataIndication&, const UpPacket&) override
|
||||
{
|
||||
++counter;
|
||||
}
|
||||
|
||||
unsigned counter = 0;
|
||||
};
|
||||
|
||||
class BtpPortDispatcherTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
undispatched_counter = 0;
|
||||
dispatcher.hook_undispatched =
|
||||
[this](const geonet::DataIndication&, const DataIndication*)
|
||||
{
|
||||
++undispatched_counter;
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<UpPacket> create_btp_packet(port_type destination);
|
||||
std::unique_ptr<UpPacket> create_btp_packet(port_type destination, port_type source);
|
||||
geonet::DataIndication create_gn_indication(UpperProtocol protocol);
|
||||
|
||||
using port_native = port_type::value_type;
|
||||
const port_native port_min = std::numeric_limits<port_native>::min();
|
||||
const port_native port_max = std::numeric_limits<port_native>::max();
|
||||
|
||||
PortDispatcher dispatcher;
|
||||
std::size_t undispatched_counter;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(BtpPortDispatcherTest, empty) {
|
||||
std::size_t indication_counter = 0;
|
||||
const auto port_range = port_max - port_min;
|
||||
|
||||
// create list of port numbers to test
|
||||
std::list<port_native> ports;
|
||||
ports.push_back(port_min - 1);
|
||||
ports.push_back(port_min);
|
||||
ports.push_back(port_min + 1);
|
||||
ports.push_back(port_min + 0.2 * port_range);
|
||||
ports.push_back(port_min + 0.3 * port_range);
|
||||
ports.push_back(port_min + 0.5 * port_range);
|
||||
ports.push_back(port_min + 0.9 * port_range);
|
||||
ports.push_back(port_max - 1);
|
||||
ports.push_back(port_max);
|
||||
ports.push_back(port_max + 1);
|
||||
|
||||
for (port_native p : ports) {
|
||||
dispatcher.indicate(
|
||||
create_gn_indication(UpperProtocol::BTP_B),
|
||||
create_btp_packet(host_cast(p))
|
||||
);
|
||||
EXPECT_EQ(undispatched_counter, ++indication_counter);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(BtpPortDispatcherTest, interactive) {
|
||||
ASSERT_EQ(undispatched_counter, 0);
|
||||
CounterIndicationInterface handler;
|
||||
const port_type dst_port { host_cast<uint16_t>(0x1234) };
|
||||
const port_type src_port { host_cast<uint16_t>(0x1337) };
|
||||
dispatcher.set_interactive_handler(dst_port, &handler);
|
||||
dispatcher.indicate(create_gn_indication(UpperProtocol::BTP_A), create_btp_packet(dst_port, src_port));
|
||||
EXPECT_EQ(1, handler.counter);
|
||||
dispatcher.indicate(create_gn_indication(UpperProtocol::BTP_B), create_btp_packet(dst_port));
|
||||
EXPECT_EQ(1, handler.counter);
|
||||
}
|
||||
|
||||
TEST_F(BtpPortDispatcherTest, non_interactive) {
|
||||
ASSERT_EQ(undispatched_counter, 0);
|
||||
CounterIndicationInterface cam;
|
||||
CounterIndicationInterface denm;
|
||||
dispatcher.set_non_interactive_handler(ports::CAM, &cam);
|
||||
dispatcher.set_non_interactive_handler(ports::DENM, &denm);
|
||||
|
||||
const geonet::DataIndication indication_this = create_gn_indication(UpperProtocol::BTP_B);
|
||||
const geonet::DataIndication indication_other = create_gn_indication(UpperProtocol::BTP_A);
|
||||
dispatcher.indicate(indication_other, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, undispatched_counter);
|
||||
EXPECT_EQ(0, cam.counter);
|
||||
EXPECT_EQ(0, denm.counter);
|
||||
|
||||
dispatcher.indicate(indication_this, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, undispatched_counter);
|
||||
EXPECT_EQ(1, cam.counter);
|
||||
EXPECT_EQ(0, denm.counter);
|
||||
|
||||
dispatcher.indicate(indication_this, create_btp_packet(ports::DENM));
|
||||
EXPECT_EQ(1, undispatched_counter);
|
||||
EXPECT_EQ(1, cam.counter);
|
||||
EXPECT_EQ(1, denm.counter);
|
||||
|
||||
dispatcher.indicate(indication_this, create_btp_packet(ports::SPAT));
|
||||
EXPECT_EQ(2, undispatched_counter);
|
||||
EXPECT_EQ(1, cam.counter);
|
||||
EXPECT_EQ(1, denm.counter);
|
||||
}
|
||||
|
||||
TEST_F(BtpPortDispatcherTest, non_interactive_overwrite) {
|
||||
ASSERT_EQ(undispatched_counter, 0);
|
||||
CounterIndicationInterface cam1_interface;
|
||||
CounterIndicationInterface cam2_interface;
|
||||
|
||||
const auto indication = create_gn_indication(UpperProtocol::BTP_B);
|
||||
dispatcher.set_non_interactive_handler(ports::CAM, &cam1_interface);
|
||||
dispatcher.indicate(indication, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, cam1_interface.counter);
|
||||
EXPECT_EQ(0, cam2_interface.counter);
|
||||
|
||||
dispatcher.set_non_interactive_handler(ports::CAM, &cam2_interface);
|
||||
dispatcher.indicate(indication, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, cam1_interface.counter);
|
||||
EXPECT_EQ(1, cam2_interface.counter);
|
||||
|
||||
dispatcher.set_non_interactive_handler(ports::CAM, nullptr);
|
||||
dispatcher.indicate(indication, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, cam2_interface.counter);
|
||||
EXPECT_EQ(1, undispatched_counter);
|
||||
}
|
||||
|
||||
TEST_F(BtpPortDispatcherTest, promiscuous_hook) {
|
||||
CounterPromiscuousHook hook;
|
||||
const auto ind = create_gn_indication(UpperProtocol::BTP_B);
|
||||
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(0, hook.counter);
|
||||
|
||||
dispatcher.add_promiscuous_hook(&hook);
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, hook.counter);
|
||||
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::DENM));
|
||||
EXPECT_EQ(2, hook.counter);
|
||||
|
||||
CounterIndicationInterface cam;
|
||||
dispatcher.set_non_interactive_handler(ports::CAM, &cam);
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, cam.counter);
|
||||
EXPECT_EQ(3, hook.counter);
|
||||
|
||||
dispatcher.add_promiscuous_hook(&hook);
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::TOPO));
|
||||
EXPECT_EQ(4, hook.counter);
|
||||
}
|
||||
|
||||
TEST_F(BtpPortDispatcherTest, remove_promiscuous_hook) {
|
||||
CounterPromiscuousHook hook;
|
||||
const auto ind = create_gn_indication(UpperProtocol::BTP_B);
|
||||
|
||||
dispatcher.add_promiscuous_hook(&hook);
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, hook.counter);
|
||||
|
||||
dispatcher.remove_promiscuous_hook(&hook);
|
||||
dispatcher.indicate(ind, create_btp_packet(ports::CAM));
|
||||
EXPECT_EQ(1, hook.counter);
|
||||
}
|
||||
|
||||
std::unique_ptr<UpPacket> BtpPortDispatcherTest::create_btp_packet(port_type destination)
|
||||
{
|
||||
ChunkPacket packet;
|
||||
HeaderB header;
|
||||
header.destination_port = destination;
|
||||
packet[OsiLayer::Transport] = header;
|
||||
return std::unique_ptr<UpPacket> { new UpPacket(packet) };
|
||||
}
|
||||
|
||||
std::unique_ptr<UpPacket> BtpPortDispatcherTest::create_btp_packet(port_type destination, port_type source)
|
||||
{
|
||||
ChunkPacket packet;
|
||||
HeaderA header;
|
||||
header.destination_port = destination;
|
||||
header.source_port = source;
|
||||
packet[OsiLayer::Transport] = header;
|
||||
return std::unique_ptr<UpPacket> { new UpPacket(packet) };
|
||||
}
|
||||
|
||||
geonet::DataIndication BtpPortDispatcherTest::create_gn_indication(UpperProtocol protocol)
|
||||
{
|
||||
geonet::DataIndication indication;
|
||||
indication.upper_protocol = protocol;
|
||||
return indication;
|
||||
}
|
||||
Reference in New Issue
Block a user