1d5f3a85665c9e04f866ed6eacb0f300e2f1b5f4
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / TrafficProfileValidator.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;
10
11 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.AbstractValidator;
12 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.TrafficProfile;
13 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.TrafficProfileChoice;
14 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.FlowSpecChoice;
15 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.ServiceClassNameChoice;
16 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.flow.spec.profile.FlowSpecProfile;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.serviceclass.name.profile.ServiceClassNameProfile;
18
19 /**
20  * @author rvail
21  */
22 public class TrafficProfileValidator extends AbstractValidator<TrafficProfile> {
23
24     private static final String FS = "flow-spec-profile";
25     private static final String SCN = "service-class-name";
26     private static final String SCP = "service-class-name-profile";
27
28     @Override
29     protected void doValidate(final TrafficProfile trafficProfile, final Extent extent) {
30         if (trafficProfile == null) {
31            getErrorMessages().add("traffic-profile must exist");
32            return;
33         }
34         if (trafficProfile.getTrafficProfileChoice() instanceof ServiceClassNameChoice) {
35             mustExist(((ServiceClassNameChoice)trafficProfile.getTrafficProfileChoice()).getServiceClassNameProfile(), SCP);
36             mustExist(((ServiceClassNameChoice)trafficProfile.getTrafficProfileChoice()).getServiceClassNameProfile().getServiceClassName(), SCN);
37         } else if (trafficProfile.getTrafficProfileChoice() instanceof FlowSpecChoice) {
38             mustExist(((FlowSpecChoice)trafficProfile.getTrafficProfileChoice()).getFlowSpecProfile(), SCP);
39         } else {
40            getErrorMessages().add("Unknown traffic profile");
41            return;
42         }
43     }
44
45 }