lpm: skip table entries update if rules found

Message ID 20200417134830.13600-1-zhouyates@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series lpm: skip table entries update if rules found |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot warning Travis build: failed
ci/Intel-compilation success Compilation OK

Commit Message

Matt April 17, 2020, 1:48 p.m. UTC
  Table entries do not need to be updated if the same rules can be found.

Signed-off-by: Yangchao Zhou <zhouyates@gmail.com>
---
 lib/librte_lpm/rte_lpm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Vladimir Medvedkin April 17, 2020, 2:01 p.m. UTC | #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 <zhouyates@gmail.com> 
Sent: Friday, April 17, 2020 2:49 PM
To: dev@dpdk.org
Cc: Richardson, Bruce <bruce.richardson@intel.com>; Medvedkin, Vladimir <vladimir.medvedkin@intel.com>
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.

Signed-off-by: Yangchao Zhou <zhouyates@gmail.com>
---
 lib/librte_lpm/rte_lpm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index 268756419..ee44fc4e5 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -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
  
Matt April 17, 2020, 3:07 p.m. UTC | #2
++ dev@dpdk.org

On Fri, Apr 17, 2020 at 10:38 PM Yangchao Zhou <zhouyates@gmail.com> wrote:

> 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.
>
> On Fri, Apr 17, 2020 at 10:04 PM Medvedkin, Vladimir <
> vladimir.medvedkin@intel.com> wrote:
>
>> 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 <zhouyates@gmail.com>
>> Sent: Friday, April 17, 2020 2:49 PM
>> To: dev@dpdk.org
>> Cc: Richardson, Bruce <bruce.richardson@intel.com>; Medvedkin, Vladimir <
>> vladimir.medvedkin@intel.com>
>> 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.
>>
>> Signed-off-by: Yangchao Zhou <zhouyates@gmail.com>
>> ---
>>  lib/librte_lpm/rte_lpm.c | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index
>> 268756419..ee44fc4e5 100644
>> --- a/lib/librte_lpm/rte_lpm.c
>> +++ b/lib/librte_lpm/rte_lpm.c
>> @@ -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
>>
>>
  

Patch

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index 268756419..ee44fc4e5 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -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;