Bug-731: fixed segment-routing sonar issues.
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing02 / SrEroUtil.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.protocol.pcep.segment.routing02;
10
11 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.PathSetupTypeTlv;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.SrEroSubobject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
16
17 public final class SrEroUtil {
18
19     private static final int MPLS_LABEL_MIN_VALUE = 16;
20
21     private SrEroUtil() {
22     }
23
24     protected static PCEPErrors validateSrEroSubobjects(final Ero ero) {
25         if (ero.getSubobject() == null || ero.getSubobject().isEmpty()) {
26             return null;
27         }
28         for (final Subobject subobject : ero.getSubobject()) {
29             if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
30                 return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
31             }
32             final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
33             if (srEroSubobject.getFlags().isM() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
34                 return PCEPErrors.BAD_LABEL_VALUE;
35             }
36         }
37         return null;
38     }
39
40     protected static boolean isPst(final PathSetupTypeTlv tlv) {
41         if (tlv != null && tlv.getPathSetupType() != null && tlv.getPathSetupType().isPst()) {
42             return true;
43         }
44         return false;
45     }
46
47 }