Skip to content

Commit b1b445b

Browse files
Merge pull request #453 from Luos-io/fix/source_filter
Add a source filtering management
2 parents c54f009 + 86288ff commit b1b445b

File tree

5 files changed

+345
-16
lines changed

5 files changed

+345
-16
lines changed

engine/IO/inc/_luos_phy.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void Phy_FiltersInit(void);
2727
void Phy_AddLocalServices(uint16_t service_id, uint16_t service_number);
2828
bool Phy_FilterType(uint16_t type_id);
2929
void Phy_IndexSet(uint8_t *index, uint16_t id);
30+
void Phy_NodeIndexRm(uint16_t id);
31+
void Phy_ServiceIndexRm(uint16_t id);
3032
void Phy_ResetAllNeeded(void);
3133

3234
#endif /* _PRIVATE_LUOS_PHY_H_ */

engine/IO/src/luos_io.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,12 @@ error_return_t LuosIO_ConsumeMsg(const msg_t *input)
476476
switch (input->header.size)
477477
{
478478
case 2:
479-
// generate local ID
479+
// Generate local ID
480480
RoutingTB_Erase();
481481
memcpy(&base_id, &input->data[0], sizeof(uint16_t));
482482
Service_GenerateId(base_id);
483483
case 0:
484-
// send back a local routing table
484+
// Send back a local routing table
485485
output_msg.header.cmd = RTB;
486486
output_msg.header.target_mode = NODEIDACK;
487487
output_msg.header.target = input->header.source;
@@ -582,10 +582,23 @@ error_return_t LuosIO_ConsumeMsg(const msg_t *input)
582582
case DEADTARGET:
583583
if (dead_target->node_id != 0)
584584
{
585+
// Get all services of this node and remove them from the indexes
586+
search_result_t result;
587+
RTFilter_Node(RTFilter_Reset(&result), dead_target->node_id);
588+
for (size_t i = 0; i < result.result_nbr; i++)
589+
{
590+
Phy_ServiceIndexRm(result.result_table[i]->id);
591+
}
592+
// remove the node from the indexes
593+
Phy_NodeIndexRm(dead_target->node_id);
594+
// remove the node services from the routing table
585595
RoutingTB_RemoveNode(dead_target->node_id);
586596
}
587597
if (dead_target->service_id != 0)
588598
{
599+
// Remove the service from the indexes
600+
Phy_ServiceIndexRm(dead_target->service_id);
601+
// Remove the service from the routing table
589602
RoutingTB_RemoveService(dead_target->service_id);
590603
}
591604
// This assert information could be usefull for services, do not remove it.

engine/IO/src/luos_phy.c

+62-10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static int Phy_GetPhyId(luos_phy_t *phy_ptr);
100100
static bool Phy_IndexFilter(uint8_t *index, uint16_t id);
101101
static bool Phy_Need(luos_phy_t *phy_ptr, header_t *header);
102102
static phy_target_t Phy_ComputeTargets(luos_phy_t *phy_ptr, header_t *header);
103+
static void Phy_IndexRm(uint8_t *index, uint16_t id);
103104

104105
/*******************************************************************************
105106
* Variables
@@ -527,7 +528,7 @@ bool Phy_Need(luos_phy_t *phy_ptr, header_t *header)
527528
// To avoid to spend precious computing time, instead of checking all the phy we will only check if this concern only the receiving phy.
528529
// 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.
529530

530-
// If this phy is Luos phy, we need to keep all the messages
531+
// If this phy is Luos phy, we need to keep all the messages no matter what.
531532
if (Phy_GetPhyId(phy_ptr) == 0)
532533
{
533534
return true;
@@ -543,19 +544,27 @@ bool Phy_Need(luos_phy_t *phy_ptr, header_t *header)
543544
break;
544545
case SERVICEIDACK:
545546
case SERVICEID:
546-
// If the target is not the phy_ptr, we need to keep this message
547-
return !Phy_IndexFilter(phy_ptr->services, header->target);
547+
// If the target is not the phy_ptr, and the source service is known, we need to keep this message
548+
return (!Phy_IndexFilter(phy_ptr->services, header->target)) && (Phy_IndexFilter(phy_ptr->services, header->source));
548549
break;
549550
case NODEIDACK:
550551
case NODEID:
551552
if (header->target == 0)
552553
{
553-
return Node_DoWeWaitId() || (phy_ctx.PhyExeptSourceDone == false); // or we are waiting for child branches ((phy_ctx.topology_running == true) && (header->source == 1))
554+
return Node_DoWeWaitId() || (phy_ctx.PhyExeptSourceDone == false);
554555
}
555556
else
556557
{
557-
// If the target is not for the receiving phy, we need to keep this message
558-
return (!Phy_IndexFilter(phy_ptr->nodes, header->target) && (Node_Get()->node_id != 0));
558+
if (Luos_IsDetected())
559+
{
560+
// If the target is not for the receiving phy, and the source service is known, we need to keep this message
561+
return (!Phy_IndexFilter(phy_ptr->nodes, header->target) && (Node_Get()->node_id != 0) && (Phy_IndexFilter(phy_ptr->services, header->source)));
562+
}
563+
else
564+
{
565+
// If the target is not for the receiving phy, we need to keep this message
566+
return (!Phy_IndexFilter(phy_ptr->nodes, header->target) && (Node_Get()->node_id != 0));
567+
}
559568
}
560569
break;
561570
default:
@@ -1199,8 +1208,8 @@ void Phy_AddLocalServices(uint16_t service_id, uint16_t service_number)
11991208

12001209
/******************************************************************************
12011210
* @brief check if the given id value concern this phy index
1202-
* @param index Pointer to the index of the node
1203-
* @param id id of the service concerned by this message
1211+
* @param index Pointer to the index of the node or service
1212+
* @param id id of the node or service concerned by this message
12041213
* @return phy concerned by this message
12051214
******************************************************************************/
12061215
inline bool Phy_IndexFilter(uint8_t *index, uint16_t id)
@@ -1212,8 +1221,8 @@ inline bool Phy_IndexFilter(uint8_t *index, uint16_t id)
12121221

12131222
/******************************************************************************
12141223
* @brief Set a given id value in the index
1215-
* @param index Pointer to the index of the node
1216-
* @param id id of the service concerned by this message
1224+
* @param index Pointer to the index of the node or service
1225+
* @param id id of the node or service concerned by this message
12171226
* @return phy concerned by this message
12181227
******************************************************************************/
12191228
inline void Phy_IndexSet(uint8_t *index, uint16_t id)
@@ -1223,6 +1232,49 @@ inline void Phy_IndexSet(uint8_t *index, uint16_t id)
12231232
index[bit_index / 8] |= 1 << (bit_index % 8);
12241233
}
12251234

1235+
/******************************************************************************
1236+
* @brief Remove a given id value in the index
1237+
* @param index Pointer to the index of the node or service
1238+
* @param id id of the service concerned by this message
1239+
* @return phy concerned by this message
1240+
******************************************************************************/
1241+
inline void Phy_IndexRm(uint8_t *index, uint16_t id)
1242+
{
1243+
LUOS_ASSERT((index != NULL) && (id <= 0x0FFF) && (id != 0));
1244+
uint8_t bit_index = id - 1; // Because 1 represent bit index 0.
1245+
index[bit_index / 8] &= ~(1 << (bit_index % 8));
1246+
}
1247+
1248+
/******************************************************************************
1249+
* @brief Remove a given service id value in the index of all phys
1250+
* @param id id of the service concerned by this message
1251+
* @return phy concerned by this message
1252+
******************************************************************************/
1253+
inline void Phy_ServiceIndexRm(uint16_t id)
1254+
{
1255+
LUOS_ASSERT((id <= 0x0FFF) && (id != 0));
1256+
// for all phy
1257+
for (int i = 0; i < phy_ctx.phy_nb; i++)
1258+
{
1259+
Phy_IndexRm(phy_ctx.phy[i].services, id);
1260+
}
1261+
}
1262+
1263+
/******************************************************************************
1264+
* @brief Remove a given node id value in the index of all phys
1265+
* @param id id of the node concerned by this message
1266+
* @return phy concerned by this message
1267+
******************************************************************************/
1268+
inline void Phy_NodeIndexRm(uint16_t id)
1269+
{
1270+
LUOS_ASSERT((id <= 0x0FFF) && (id != 0));
1271+
// for all phy
1272+
for (int i = 0; i < phy_ctx.phy_nb; i++)
1273+
{
1274+
Phy_IndexRm(phy_ctx.phy[i].nodes, id);
1275+
}
1276+
}
1277+
12261278
/******************************************************************************
12271279
* @brief Parse all services type to find if target exists
12281280
* @param type_id of message

engine/core/src/routing_table.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,12 @@ search_result_t *RTFilter_Node(search_result_t *result, uint16_t node_id)
10301030
uint8_t entry_nbr = 0;
10311031
// Check result pointer
10321032
LUOS_ASSERT(result != 0);
1033-
// if we the result is not initialized return 0
1033+
// If the result is not initialized return 0
10341034
if (RTFilter_InitCheck(result) == FAILED)
10351035
{
10361036
result->result_nbr = 0;
10371037
}
1038-
// search all the entries of the research table
1038+
// Search all the entries of the research table
10391039
while (entry_nbr < result->result_nbr)
10401040
{
10411041
// find a service with the wanted node_id

0 commit comments

Comments
 (0)