80d8816a25d04f0f017dbf4ed1124dd514e2d175
[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.rev170125.pcmm.qos.traffic.profile.TrafficProfile;
13 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.qos.traffic.profile.traffic.profile.TrafficProfileChoice;
14 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.FlowSpecChoice;
15 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.ServiceClassNameChoice;
16 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.RtpChoice;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.UgsChoice;
18 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.flow.spec.profile.FlowSpecProfile;
19 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.pcmm.serviceclass.name.profile.ServiceClassNameProfile;
20
21 /**
22  * @author rvail
23  */
24 public class TrafficProfileValidator extends AbstractValidator<TrafficProfile> {
25
26     private static final String FS = "flow-spec-profile";
27     private static final String SCN = "service-class-name";
28     private static final String SCP = "service-class-name-profile";
29     private static final String UGS = "ugs-profile";
30     private static final String RTP = "rtp-profile";
31
32     @Override
33     protected void doValidate(final TrafficProfile trafficProfile, final Extent extent) {
34         if (trafficProfile == null) {
35            getErrorMessages().add("traffic-profile must exist");
36            return;
37         }
38         if (trafficProfile.getTrafficProfileChoice() instanceof ServiceClassNameChoice) {
39             mustExist(((ServiceClassNameChoice)trafficProfile.getTrafficProfileChoice()).getServiceClassNameProfile(), SCP);
40             mustExist(((ServiceClassNameChoice)trafficProfile.getTrafficProfileChoice()).getServiceClassNameProfile().getServiceClassName(), SCN);
41         } else if (trafficProfile.getTrafficProfileChoice() instanceof FlowSpecChoice) {
42             mustExist(((FlowSpecChoice)trafficProfile.getTrafficProfileChoice()).getFlowSpecProfile(), SCP);
43         } else if (trafficProfile.getTrafficProfileChoice() instanceof RtpChoice) {
44             mustExist(((RtpChoice)trafficProfile.getTrafficProfileChoice()).getRtpProfile(), RTP);
45         } else if (trafficProfile.getTrafficProfileChoice() instanceof UgsChoice) {
46             mustExist(((UgsChoice)trafficProfile.getTrafficProfileChoice()).getUgsProfile(), UGS);
47         } else {
48            getErrorMessages().add("Unknown traffic profile");
49            return;
50         }
51     }
52
53 }