2 * Copyright (c) 2015 CableLabs and others. All rights reserved.
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
9 package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
11 import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
12 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.AbstractValidator;
13 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ClassifierValidator;
14 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ExtClassifierValidator;
15 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.Ipv6ClassifierValidator;
16 import org.opendaylight.yang.gen.v1.urn.packetcable.rev151026.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
21 public class GateValidator extends AbstractValidator<Gate> {
23 private static final String GATE_ID = "gate.gateId";
24 private static final String GATE_SPEC = "gate.gate-spec";
25 private static final String TRAFFIC_PROFILE = "gate.traffic-profile";
27 // private final GateSpecValidatator gateSpecValidatator = new GateSpecValidatator();
28 private final TrafficProfileValidator trafficProfileValidator = new TrafficProfileValidator();
29 private final ClassifierValidator classifierValidator = new ClassifierValidator();
30 private final ExtClassifierValidator extClassifierValidator = new ExtClassifierValidator();
31 private final Ipv6ClassifierValidator ipv6ClassifierValidator = new Ipv6ClassifierValidator();
34 public void validate(final Gate gate, final Extent extent) throws ValidationException {
36 throw new ValidationException("gate must exist");
39 mustExist(gate.getGateId(), GATE_ID);
41 // all leafs in GateSpec are optional
42 // mustExist(gate.getGateSpec(), GATE_SPEC);
44 mustExist(gate.getTrafficProfile(), TRAFFIC_PROFILE);
45 if (extent == Extent.NODE_AND_SUBTREE) {
46 // validateChild(gateSpecValidatator, gate.getGateSpec());
47 validateChild(trafficProfileValidator, gate.getTrafficProfile());
52 if (gate.getClassifier() != null) {
54 // classifer is not null, ext and ipv6 must be null
56 if (gate.getExtClassifier() != null || gate.getIpv6Classifier() != null) {
57 getErrorMessages().add("Only one type of classifier is allowed");
59 else if (extent == Extent.NODE_AND_SUBTREE) {
60 validateChild(classifierValidator, gate.getClassifier());
64 else if (gate.getExtClassifier() != null) {
66 // classifer is null; ext is not null and ipv6 must be null
68 if (gate.getIpv6Classifier() != null) {
69 getErrorMessages().add("Only one type of classifier is allowed");
71 else if (extent == Extent.NODE_AND_SUBTREE) {
72 validateChild(extClassifierValidator, gate.getExtClassifier());
76 else if (gate.getIpv6Classifier() != null) {
78 // classifer and ext are null; ipv6 is not
79 if (extent == Extent.NODE_AND_SUBTREE) {
80 validateChild(ipv6ClassifierValidator, gate.getIpv6Classifier());
85 getErrorMessages().add("a classifer is required");
88 throwErrorsIfNeeded();