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;
36 if (obj instanceof Overload) {
37 metricPceBuilder.setOverload((Overload) obj);
38 return State.OVERLOAD;
48 public static MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
49 final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
50 if (!(objects.get(0) instanceof PceId)) {
51 throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
53 metricPceBuilder.setPceId((PceId) (objects.get(0)));
55 State state = State.START;
56 while (!objects.isEmpty() && !state.equals(State.END)) {
57 final Object obj = objects.get(0);
58 state = insertObject(metricPceBuilder, state, obj);
59 if (!state.equals(State.END)) {
63 return metricPceBuilder.build();
67 START, PROC_TIME, OVERLOAD, END