Remove check for empty lists, where not needed.
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing / 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 package org.opendaylight.protocol.pcep.segment.routing;
9
10 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrEroSubobject;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupType;
16
17 public final class SrEroUtil {
18
19     private static final int MPLS_LABEL_MIN_VALUE = 16;
20
21     private SrEroUtil() {
22         throw new UnsupportedOperationException();
23     }
24
25     protected static PCEPErrors validateSrEroSubobjects(final Ero ero) {
26         if (ero.getSubobject() != null) {
27             for (final Subobject subobject : ero.getSubobject()) {
28                 if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
29                     return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
30                 }
31                 final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
32                 if (srEroSubobject.isMFlag() != null && srEroSubobject.isMFlag() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
33                     return PCEPErrors.BAD_LABEL_VALUE;
34                 }
35             }
36         }
37         return null;
38     }
39
40     protected static boolean isSegmentRoutingPath(final Srp srp) {
41         if (srp != null && srp.getTlvs() != null && isSrTePst(srp.getTlvs().getPathSetupType())) {
42             return true;
43         }
44         return false;
45     }
46
47     private static boolean isSrTePst(final PathSetupType tlv) {
48         if (tlv != null && tlv.getPst() == 1) {
49             return true;
50         }
51         return false;
52     }
53
54 }