lpm: skip table entries update if rules found
PATCH 1/1 lpm: skip table entries update if rules found
Table entries do not need to be updated if the same rules can be found.
--- lib/librte_lpm/rte_lpm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/librte_lpm/rte_lpm.c +5 -1
@@ -287,7 +287,7 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,if (lpm->rules_tbl[rule_index].ip == ip_masked) { lpm->rules_tbl[rule_index].next_hop = next_hop; -return rule_index; +return -EEXIST ; } }
@@ -674,6 +674,10 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if rule is found in rule table */ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;
Signature · 1 line
2.17.1
Hi Zhou,
NACK.
This patch makes lpm inconsistent.
From the programmers guide
"If a rule with the same prefix is already present in the table, the next hop of the rule is updated."
So, here in case of presence of a route, next hop will be updated only in rules_table which is helper data struct, but won't be updated in lpm data plane struct.
-----Original Message-----
From: Yangchao Zhou <[email protected]>
Sent: Friday, April 17, 2020 2:49 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Medvedkin, Vladimir <[email protected]>
Subject: [PATCH] lpm: skip table entries update if rules found
Table entries do not need to be updated if the same rules can be found.
--- lib/librte_lpm/rte_lpm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/librte_lpm/rte_lpm.c +5 -1
@@ -287,7 +287,7 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,if (lpm->rules_tbl[rule_index].ip == ip_masked) { lpm->rules_tbl[rule_index].next_hop = next_hop; -return rule_index; +return -EEXIST ; } }
@@ -674,6 +674,10 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if rule is found in rule table */ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;
--
2.17.1
Quoted 67 lines · Yangchao Zhou
Hi Vladimir,
Thanks, you are right. I saw that the next hop is also in lpm table entries.
On the basis of the same route, skiping the table entries update only if the next hop is also the same.Quoted 57 lines · Vladimir
Hi Zhou,
NACK.
This patch makes lpm inconsistent.
From the programmers guide
"If a rule with the same prefix is already present in the table, the next hop of the rule is updated."
So, here in case of presence of a route, next hop will be updated only inrules_tablewhich is helper data struct, but won't be updated in lpm data plane struct.-----Original Message-----
From: Yangchao Zhou <[email protected]>
Sent: Friday, April 17, 2020 2:49 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Medvedkin, Vladimir < [email protected]>
Subject: [PATCH] lpm: skip table entries update if rules foundTable entries do not need to be updated if the same rules can be found.
Signed-off-by Yangchao Zhou <[email protected]>--- lib/librte_lpm/rte_lpm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/librte_lpm/rte_lpm.c index renamed from lib/librte_lpm/rte_lpm.c +0
-0268756419..ee44fc4e5 100644
lib/librte_lpm/rte_lpm.c +1
-1@@ -287,7 +287,7 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth, if (lpm->rules_tbl[rule_index].ip == ip_masked) { lpm->rules_tbl[rule_index].next_hop = next_hop; -return rule_index; +return -EEXIST ; }}lib/librte_lpm/rte_lpm.c +4
-0@@ -674,6 +674,10 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip,uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if rule is found in rule table */ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;--
2.17.1
PATCH v2 1/1 lpm: skip table entries update if rules found
In reply to Yangchao ZhouTable entries do not need to be updated if the same rules can be found.
--- lib/librte_lpm/rte_lpm.c | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/librte_lpm/rte_lpm.c +8 -0
@@ -285,6 +285,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,/* If rule already exists update its next_hop and return. */ if (lpm->rules_tbl[rule_index].ip == ip_masked) { + +if (lpm->rules_tbl[rule_index].next_hop == next_hop) +return -EEXIST ; lpm->rules_tbl[rule_index].next_hop = next_hop;return rule_index;
@@ -674,6 +677,11 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if The rule is the same as +* the rule in the rules table */ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;
Signature · 1 line
2.17.1
PATCH v3 1/1 lpm: skip table entries update if rules found
Table entries do not need to be updated if the same rules can be found.
--- lib/librte_lpm/rte_lpm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/librte_lpm/rte_lpm.c +9 -0
@@ -285,6 +285,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,/* If rule already exists update its next_hop and return. */ if (lpm->rules_tbl[rule_index].ip == ip_masked) { + +if (lpm->rules_tbl[rule_index].next_hop == next_hop) +return -EEXIST ; lpm->rules_tbl[rule_index].next_hop = next_hop;return rule_index;
@@ -674,6 +677,12 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if The rule is the same as +* the rule in the rules table. +*/ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;
Signature · 1 line
2.17.1
PATCH v4 1/1 lpm: skip table entries update if rules found
In reply to Yangchao ZhouTable entries do not need to be updated if the same rules can be found.
---
v1-v2: Skip updating when the next hop is the same as the current one
v2-v4: Coding style fix
--- lib/librte_lpm/rte_lpm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/librte_lpm/rte_lpm.c +9 -0
@@ -285,6 +285,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,/* If rule already exists update its next_hop and return. */ if (lpm->rules_tbl[rule_index].ip == ip_masked) { + +if (lpm->rules_tbl[rule_index].next_hop == next_hop) +return -EEXIST ; lpm->rules_tbl[rule_index].next_hop = next_hop;return rule_index;
@@ -674,6 +677,12 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if The rule is the same as +* the rule in the rules table. +*/ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;
Signature · 1 line
2.17.1
Hi Yangchao,
Thanks for the patch.
This might be useful for control plane implementations that don't track inserted routes. I have just a one nit inlined below. Also, could you do the same for lpm6?
P.S. Please have a look at rte_fib library, there are more optimizations compared to lpm library.
Apart from that,
Quoted 15 lines · Yangchao Zhou
Table entries do not need to be updated if the same rules can be found.
Signed-off-by Yangchao Zhou <[email protected]>---
v1-v2: Skip updating when the next hop is the same as the current one
v2-v4: Coding style fix--- lib/librte_lpm/rte_lpm.c | 9 +++++++++ 1 file changed, 9 insertions(+)lib/librte_lpm/rte_lpm.c +0
-0
lib/librte_lpm/rte_lpm.c rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth, · line 289
Quoted 5 lines
lib/librte_lpm/rte_lpm.c +2
-0@@ -285,6 +285,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,/* If rule already exists update its next_hop and return. */ if (lpm->rules_tbl[rule_index].ip == ip_masked) { + +if (lpm->rules_tbl[rule_index].next_hop == next_hop)
Line over 80 characters, please split it by two.
Quoted 17 lines
lib/librte_lpm/rte_lpm.c +7
-0+return -EEXIST ; lpm->rules_tbl[rule_index].next_hop = next_hop;return rule_index;@@ -674,6 +677,12 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,/* Add the rule to the rule table. */ rule_index =rule_add (lpm, ip_masked, depth, next_hop); +/* Skip table entries update if The rule is the same as +* the rule in the rules table. +*/ +if (rule_index == -EEXIST ) +return 0 ; +/* If the is no space available for new rule return error. */ if (rule_index <0 ) {return rule_index;
Signature · 2 lines
Regards, Vladimir
21/04/2020 17:44, Medvedkin, Vladimir:
Quoted 12 lines
Hi Yangchao,
Thanks for the patch.
This might be useful for control plane implementations that don't track inserted routes.
I have just a one nit inlined below. Also, could you do the same for lpm6?
P.S. Please have a look atrte_fiblibrary, there are more optimizations compared to lpm library.Apart from that,
[...]
Quoted 1 line
Quoted 1 line
/* If rule already exists update its
next_hopand return. */
Reduced length of above comment,
Quoted 6 lines
lib/librte_lpm/rte_lpm.c rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth, · line 289
Quoted 3 lines
if (lpm->rules_tbl[rule_index].ip == ip_masked) {lib/librte_lpm/rte_lpm.c +2
-0+ +if (lpm->rules_tbl[rule_index].next_hop == next_hop)Line over 80 characters, please split it by two.
and split above line.
Applied with requested changes, thanks.