2 * Copyright (c) 2013 Cisco Systems, Inc. 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
8 package org.opendaylight.protocol.pcep.parser.util;
10 import java.util.List;
11 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPceBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.object.Overload;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pce.id.object.PceId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime;
20 * Utilities used in pcep-base-parser.
22 public final class Util {
25 throw new UnsupportedOperationException();
28 private static State insertObject(final MetricPceBuilder metricPceBuilder, final State state, final Object obj) {
31 if (obj instanceof ProcTime) {
32 metricPceBuilder.setProcTime((ProcTime) obj);
33 return State.PROC_TIME;
37 if (obj instanceof Overload) {
38 metricPceBuilder.setOverload((Overload) obj);
39 return State.OVERLOAD;
50 public static MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
51 final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
52 if (!(objects.get(0) instanceof PceId)) {
53 throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
55 metricPceBuilder.setPceId((PceId) (objects.get(0)));
57 State state = State.START;
58 while (!objects.isEmpty() && !state.equals(State.END)) {
59 final Object obj = objects.get(0);
60 state = insertObject(metricPceBuilder, state, obj);
61 if (!state.equals(State.END)) {
65 return metricPceBuilder.build();
69 START, PROC_TIME, OVERLOAD, END