Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a source filtering management #453

Merged
merged 3 commits into from
Nov 22, 2023
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
2 changes: 2 additions & 0 deletions engine/IO/inc/_luos_phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void Phy_FiltersInit(void);
void Phy_AddLocalServices(uint16_t service_id, uint16_t service_number);
bool Phy_FilterType(uint16_t type_id);
void Phy_IndexSet(uint8_t *index, uint16_t id);
void Phy_NodeIndexRm(uint16_t id);
void Phy_ServiceIndexRm(uint16_t id);
void Phy_ResetAllNeeded(void);

#endif /* _PRIVATE_LUOS_PHY_H_ */
17 changes: 15 additions & 2 deletions engine/IO/src/luos_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ error_return_t LuosIO_ConsumeMsg(const msg_t *input)
switch (input->header.size)
{
case 2:
// generate local ID
// Generate local ID
RoutingTB_Erase();
memcpy(&base_id, &input->data[0], sizeof(uint16_t));
Service_GenerateId(base_id);
case 0:
// send back a local routing table
// Send back a local routing table
output_msg.header.cmd = RTB;
output_msg.header.target_mode = NODEIDACK;
output_msg.header.target = input->header.source;
Expand Down Expand Up @@ -582,10 +582,23 @@ error_return_t LuosIO_ConsumeMsg(const msg_t *input)
case DEADTARGET:
if (dead_target->node_id != 0)
{
// Get all services of this node and remove them from the indexes
search_result_t result;
RTFilter_Node(RTFilter_Reset(&result), dead_target->node_id);
for (size_t i = 0; i < result.result_nbr; i++)
{
Phy_ServiceIndexRm(result.result_table[i]->id);
}
// remove the node from the indexes
Phy_NodeIndexRm(dead_target->node_id);
// remove the node services from the routing table
RoutingTB_RemoveNode(dead_target->node_id);
}
if (dead_target->service_id != 0)
{
// Remove the service from the indexes
Phy_ServiceIndexRm(dead_target->service_id);
// Remove the service from the routing table
RoutingTB_RemoveService(dead_target->service_id);
}
// This assert information could be usefull for services, do not remove it.
Expand Down
72 changes: 62 additions & 10 deletions engine/IO/src/luos_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static int Phy_GetPhyId(luos_phy_t *phy_ptr);
static bool Phy_IndexFilter(uint8_t *index, uint16_t id);
static bool Phy_Need(luos_phy_t *phy_ptr, header_t *header);
static phy_target_t Phy_ComputeTargets(luos_phy_t *phy_ptr, header_t *header);
static void Phy_IndexRm(uint8_t *index, uint16_t id);

/*******************************************************************************
* Variables
Expand Down Expand Up @@ -527,7 +528,7 @@ bool Phy_Need(luos_phy_t *phy_ptr, header_t *header)
// To avoid to spend precious computing time, instead of checking all the phy we will only check if this concern only the receiving phy.
// We need to keep this message only if the message target is not only for the phy_ptr, except if it is Luos because Luos can do localhost.

// If this phy is Luos phy, we need to keep all the messages
// If this phy is Luos phy, we need to keep all the messages no matter what.
if (Phy_GetPhyId(phy_ptr) == 0)
{
return true;
Expand All @@ -543,19 +544,27 @@ bool Phy_Need(luos_phy_t *phy_ptr, header_t *header)
break;
case SERVICEIDACK:
case SERVICEID:
// If the target is not the phy_ptr, we need to keep this message
return !Phy_IndexFilter(phy_ptr->services, header->target);
// If the target is not the phy_ptr, and the source service is known, we need to keep this message
return (!Phy_IndexFilter(phy_ptr->services, header->target)) && (Phy_IndexFilter(phy_ptr->services, header->source));
break;
case NODEIDACK:
case NODEID:
if (header->target == 0)
{
return Node_DoWeWaitId() || (phy_ctx.PhyExeptSourceDone == false); // or we are waiting for child branches ((phy_ctx.topology_running == true) && (header->source == 1))
return Node_DoWeWaitId() || (phy_ctx.PhyExeptSourceDone == false);
}
else
{
// If the target is not for the receiving phy, we need to keep this message
return (!Phy_IndexFilter(phy_ptr->nodes, header->target) && (Node_Get()->node_id != 0));
if (Luos_IsDetected())
{
// If the target is not for the receiving phy, and the source service is known, we need to keep this message
return (!Phy_IndexFilter(phy_ptr->nodes, header->target) && (Node_Get()->node_id != 0) && (Phy_IndexFilter(phy_ptr->services, header->source)));
}
else
{
// If the target is not for the receiving phy, we need to keep this message
return (!Phy_IndexFilter(phy_ptr->nodes, header->target) && (Node_Get()->node_id != 0));
}
}
break;
default:
Expand Down Expand Up @@ -1199,8 +1208,8 @@ void Phy_AddLocalServices(uint16_t service_id, uint16_t service_number)

/******************************************************************************
* @brief check if the given id value concern this phy index
* @param index Pointer to the index of the node
* @param id id of the service concerned by this message
* @param index Pointer to the index of the node or service
* @param id id of the node or service concerned by this message
* @return phy concerned by this message
******************************************************************************/
inline bool Phy_IndexFilter(uint8_t *index, uint16_t id)
Expand All @@ -1212,8 +1221,8 @@ inline bool Phy_IndexFilter(uint8_t *index, uint16_t id)

/******************************************************************************
* @brief Set a given id value in the index
* @param index Pointer to the index of the node
* @param id id of the service concerned by this message
* @param index Pointer to the index of the node or service
* @param id id of the node or service concerned by this message
* @return phy concerned by this message
******************************************************************************/
inline void Phy_IndexSet(uint8_t *index, uint16_t id)
Expand All @@ -1223,6 +1232,49 @@ inline void Phy_IndexSet(uint8_t *index, uint16_t id)
index[bit_index / 8] |= 1 << (bit_index % 8);
}

/******************************************************************************
* @brief Remove a given id value in the index
* @param index Pointer to the index of the node or service
* @param id id of the service concerned by this message
* @return phy concerned by this message
******************************************************************************/
inline void Phy_IndexRm(uint8_t *index, uint16_t id)
{
LUOS_ASSERT((index != NULL) && (id <= 0x0FFF) && (id != 0));
uint8_t bit_index = id - 1; // Because 1 represent bit index 0.
index[bit_index / 8] &= ~(1 << (bit_index % 8));
}

/******************************************************************************
* @brief Remove a given service id value in the index of all phys
* @param id id of the service concerned by this message
* @return phy concerned by this message
******************************************************************************/
inline void Phy_ServiceIndexRm(uint16_t id)
{
LUOS_ASSERT((id <= 0x0FFF) && (id != 0));
// for all phy
for (int i = 0; i < phy_ctx.phy_nb; i++)
{
Phy_IndexRm(phy_ctx.phy[i].services, id);
}
}

/******************************************************************************
* @brief Remove a given node id value in the index of all phys
* @param id id of the node concerned by this message
* @return phy concerned by this message
******************************************************************************/
inline void Phy_NodeIndexRm(uint16_t id)
{
LUOS_ASSERT((id <= 0x0FFF) && (id != 0));
// for all phy
for (int i = 0; i < phy_ctx.phy_nb; i++)
{
Phy_IndexRm(phy_ctx.phy[i].nodes, id);
}
}

/******************************************************************************
* @brief Parse all services type to find if target exists
* @param type_id of message
Expand Down
4 changes: 2 additions & 2 deletions engine/core/src/routing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,12 @@ search_result_t *RTFilter_Node(search_result_t *result, uint16_t node_id)
uint8_t entry_nbr = 0;
// Check result pointer
LUOS_ASSERT(result != 0);
// if we the result is not initialized return 0
// If the result is not initialized return 0
if (RTFilter_InitCheck(result) == FAILED)
{
result->result_nbr = 0;
}
// search all the entries of the research table
// Search all the entries of the research table
while (entry_nbr < result->result_nbr)
{
// find a service with the wanted node_id
Expand Down
Loading