Adding support for multiple classifiers per gate
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / classifier / ClassifiersValidator.java
1 /*
2  * Copyright (c) 2015 CableLabs 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.controller.packetcable.provider.validation.impl.validators.qos.classifier;
10
11 import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
12 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.AbstractValidator;
13 import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.Classifiers;
14 import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainer;
15 import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.QosClassifierChoice;
16
17 /**
18  * @author rvail
19  */
20 public class ClassifiersValidator extends AbstractValidator<Classifiers> {
21
22     private static final String CLASSIFER_CONTAINER = "classifers.classifer-container";
23
24     private ClassifierContainerValidator classifierContainerValidator = new ClassifierContainerValidator();
25
26     @Override
27     public void validate(final Classifiers classifiers, final Extent extent) throws ValidationException {
28         if (classifiers == null) {
29             throw new ValidationException("classifiers must exist");
30         }
31
32         mustExistAndNotBeEmpty(classifiers.getClassifierContainer(), CLASSIFER_CONTAINER);
33
34         boolean hasBasic = false;
35         boolean hasExtOrIpv6 = false;
36         for (ClassifierContainer classifier : classifiers.getClassifierContainer()) {
37             if (classifier.getClassifierChoice() instanceof QosClassifierChoice) {
38                 hasBasic = true;
39             } else {
40                 hasExtOrIpv6 = true;
41             }
42         }
43         if (hasBasic && hasExtOrIpv6) {
44             getErrorMessages().add("Legacy classifiers cannot be used in conjunction with Extended or Ipv6 Classifiers");
45         }
46
47         if (extent == Extent.NODE_AND_SUBTREE) {
48             for (ClassifierContainer classifier : classifiers.getClassifierContainer()) {
49                 validateChild(classifierContainerValidator, classifier);
50             }
51         }
52
53         throwErrorsIfNeeded();
54     }
55
56 }