Skip to contentSkip to conversation

lpm: skip table entries update if rules found

PATCH Superseded Yangchao Zhou 3 participants 8 messages Apr 17, 2020 – Apr 24, 2020 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

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
index 268756419..ee44fc4e5 100644
@@ -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
#1 lore raw

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

A message that is not in the archive (sent off-list or not yet received): CABLiTuxTNQYYSCwWRuqqSZy+0JhBqjcE2v5ha+OqWk+YH42+TA@mail.gmail.com

#3 lore raw

++ [email protected]

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 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 index renamed from lib/librte_lpm/rte_lpm.c +0 -0

268756419..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

#4 lore raw

PATCH v2 1/1 lpm: skip table entries update if rules found

In reply to Yangchao Zhou

Table 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
index 268756419..83db3cd34 100644
@@ -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
#5 lore raw

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
index 268756419..9085f935e 100644
@@ -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
#6 lore raw

PATCH v4 1/1 lpm: skip table entries update if rules found

In reply to Yangchao Zhou

Table 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
index 268756419..b8a90e385 100644
@@ -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
Acked-by on v4 1/1
#7 lore raw

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.

---
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
index 268756419..b8a90e385 100644

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
#8 lore raw

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 at rte_fib library, there are more optimizations compared to lpm library.

Apart from that,

[...]

Quoted 1 line
Quoted 1 line

/* If rule already exists update its next_hop and 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.