algo: Fix NPE if ClassType is not specified 10/99410/1
authorOlivier Dugeon <olivier.dugeon@orange.com>
Tue, 23 Nov 2021 16:38:22 +0000 (17:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 20 Jan 2022 17:49:22 +0000 (18:49 +0100)
Path computation algorithms failed during edge pruning if ClassType
is not specified raising a NPE.

In addition, setting ClassType to 0 by default ito handle the NPE is
not conform to RFC5455.

This patch modify edge pruning when ClassType is not specified (set
to 0) and remove default setting to avoid problem when enforcing LSP
with a ClassType equal 0.

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Change-Id: I8930393359960dc9406fb9cc112bc194049cb35a
(cherry picked from commit 42282fe0eac1a45e0afdedd55c4984195ceddb8d)

algo/algo-impl/src/main/java/org/opendaylight/algo/impl/AbstractPathComputation.java
pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/MessagesUtil.java
pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/PathComputationImpl.java

index 297000cc6a3e535e9aeded6ec8b2f0198b249a68..1690e27cb395e2fd5fb2658d6517a060ef0ab0d8 100644 (file)
@@ -226,16 +226,20 @@ public abstract class AbstractPathComputation implements PathComputationAlgorith
         }
 
         /* Check that Edge meet Bandwidth constraint */
+        int cos = 0;
+        if (constraints.getClassType() != null) {
+            cos = constraints.getClassType().intValue();
+        }
         if (constraints.getBandwidth() != null) {
             if (attributes.getMaxLinkBandwidth() == null || attributes.getMaxResvLinkBandwidth() == null
                     || attributes.getUnreservedBandwidth() == null
-                    || attributes.getUnreservedBandwidth().get(constraints.getClassType().intValue()) == null) {
+                    || attributes.getUnreservedBandwidth().get(cos) == null) {
                 return true;
             } else {
                 Long bandwidth = constraints.getBandwidth().getValue().longValue();
                 Long unrsv = 0L;
                 for (UnreservedBandwidth unResBw : attributes.getUnreservedBandwidth()) {
-                    if (unResBw.getClassType().intValue() == constraints.getClassType().intValue()) {
+                    if (unResBw.getClassType().intValue() == cos) {
                         unrsv = unResBw.getBandwidth().getValue().longValue();
                         break;
                     }
index 66272b8ebd1a78da893f866e5f9a05d64837dcfc..b425c451d2130ddf843131510929f2952affdc71 100644 (file)
@@ -199,12 +199,12 @@ public final class MessagesUtil {
             bwBuilder.setBandwidth(new Bandwidth(new Float32(ByteBuffer.allocate(4)
                     .putFloat(cpath.getBandwidth().getValue().floatValue()).array())));
             pathBuilder.setBandwidth(bwBuilder.build());
-            if (cpath.getClassType() != null) {
-                pathBuilder.setClassType(new ClassTypeBuilder().setClassType(
-                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
-                                .ClassType(cpath.getClassType()))
-                        .build());
-            }
+        }
+        if (cpath.getClassType() != null && !cpath.getClassType().equals(Uint8.ZERO)) {
+            pathBuilder.setClassType(new ClassTypeBuilder().setClassType(
+                    new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
+                            .ClassType(cpath.getClassType()))
+                    .build());
         }
         return pathBuilder;
     }
index 42d64a077ae41c55432bda574ead67aaf44369ee..1cd71f7650881493905ceaa873383ed7a7d917ed 100644 (file)
@@ -40,7 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.segment.computation.P2p;
 import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -245,8 +244,6 @@ public class PathComputationImpl implements PathComputation {
                 ctsBuilder.setBandwidth(new DecimalBandwidth(BigDecimal.valueOf(value)));
                 if (classType != null) {
                     ctsBuilder.setClassType(classType.getClassType().getValue());
-                } else {
-                    ctsBuilder.setClassType(Uint8.ZERO);
                 }
             }
         }