X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2Fmessage%2FPCCreateMessageValidator.java;h=92303b1ba0ec7d9e49aec3308819eb58d941db4c;hb=ce6991a8596c022555b003e128077a8f5468ec5e;hp=42fa0c0756c1268ce53b6e0263bff53345781680;hpb=18052efffd88d249dcb3131ff63da090980fa6d1;p=bgpcep.git diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java index 42fa0c0756..92303b1ba0 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java @@ -7,117 +7,99 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.protocol.pcep.PCEPObject; -import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; -import org.opendaylight.protocol.pcep.impl.object.UnknownObject; -import org.opendaylight.protocol.pcep.message.PCCreateMessage; -import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; -import org.opendaylight.protocol.pcep.object.CompositeInstantiationObject; -import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; -import org.opendaylight.protocol.pcep.object.PCEPErrorObject; -import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; -import org.opendaylight.protocol.pcep.object.PCEPLspaObject; -import org.opendaylight.protocol.pcep.object.PCEPMetricObject; -import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; /** * PCCCreateMessage validator. Validates message integrity. */ -public class PCCreateMessageValidator extends PCEPMessageValidator { - - @Override - public List validate(final List objects) throws PCEPDeserializerException { - if (objects == null) - throw new IllegalArgumentException("Passed list can't be null."); - - final List insts = new ArrayList(); - - CompositeInstantiationObject inst; - while (!objects.isEmpty()) { - try { - if ((inst = this.getValidInstantiationObject(objects)) == null) - break; - } catch (final PCEPDocumentedException e) { - return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); - } - - insts.add(inst); - } - - if (insts.isEmpty()) - throw new PCEPDeserializerException("At least one CompositeInstantiationObject is mandatory."); - - if (!objects.isEmpty()) - throw new PCEPDeserializerException("Unprocessed objects: " + objects); - - return Arrays.asList((Message) new PCCreateMessage(insts)); - } - - private CompositeInstantiationObject getValidInstantiationObject(final List objects) throws PCEPDocumentedException { - if (objects.get(0) instanceof UnknownObject) - throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); - if (!(objects.get(0) instanceof PCEPEndPointsObject)) - return null; - - final PCEPEndPointsObject endPoints = ((PCEPEndPointsObject) objects.get(0)); - objects.remove(0); - - if (objects.get(0) instanceof UnknownObject) - throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); - if (!(objects.get(0) instanceof PCEPLspaObject)) - throw new PCEPDocumentedException("LSPA Object must be second.", PCEPErrors.LSPA_MISSING); - final PCEPLspaObject lspa = (PCEPLspaObject) objects.get(0); - objects.remove(0); - - PCEPExplicitRouteObject ero = null; - PCEPRequestedPathBandwidthObject bandwidth = null; - final List metrics = new ArrayList(); - - PCEPObject obj; - int state = 1; - while (!objects.isEmpty()) { - obj = objects.get(0); - if (obj instanceof UnknownObject) { - throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); - } - - switch (state) { - case 1: - state = 2; - if (obj instanceof PCEPExplicitRouteObject) { - ero = (PCEPExplicitRouteObject) obj; - break; - } - case 2: - state = 3; - if (obj instanceof PCEPRequestedPathBandwidthObject) { - bandwidth = (PCEPRequestedPathBandwidthObject) obj; - break; - } - case 3: - state = 4; - if (obj instanceof PCEPMetricObject) { - metrics.add((PCEPMetricObject) obj); - state = 3; - break; - } - } - - if (state == 4) - break; - - objects.remove(0); - } - - return new CompositeInstantiationObject(endPoints, lspa, ero, bandwidth, metrics); - } +// FIXME: merge with parser +class PCCreateMessageValidator { + + // @Override + // public List validate(final List objects) throws PCEPDeserializerException { + // if (objects == null) + // throw new IllegalArgumentException("Passed list can't be null."); + // + // final List insts = new ArrayList(); + // + // CompositeInstantiationObject inst; + // while (!objects.isEmpty()) { + // try { + // if ((inst = this.getValidInstantiationObject(objects)) == null) + // break; + // } catch (final PCEPDocumentedException e) { + // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + // } + // + // insts.add(inst); + // } + // + // if (insts.isEmpty()) + // throw new PCEPDeserializerException("At least one CompositeInstantiationObject is mandatory."); + // + // if (!objects.isEmpty()) + // throw new PCEPDeserializerException("Unprocessed objects: " + objects); + // + // return Arrays.asList((Message) new PCCreateMessage(insts)); + // } + // + // private CompositeInstantiationObject getValidInstantiationObject(final List objects) throws + // PCEPDocumentedException { + // if (objects.get(0) instanceof UnknownObject) + // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); + // if (!(objects.get(0) instanceof EndpointsObject)) + // return null; + // + // final EndpointsObject endPoints = ((EndpointsObject) objects.get(0)); + // objects.remove(0); + // + // if (objects.get(0) instanceof UnknownObject) + // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); + // if (!(objects.get(0) instanceof LspaObject)) + // throw new PCEPDocumentedException("LSPA Object must be second.", PCEPErrors.LSPA_MISSING); + // final LspaObject lspa = (LspaObject) objects.get(0); + // objects.remove(0); + // + // ExplicitRouteObject ero = null; + // BandwidthObject bandwidth = null; + // final List metrics = Lists.newArrayList(); + // + // Object obj; + // int state = 1; + // while (!objects.isEmpty()) { + // obj = objects.get(0); + // if (obj instanceof UnknownObject) { + // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + // } + // + // switch (state) { + // case 1: + // state = 2; + // if (obj instanceof ExplicitRouteObject) { + // ero = (ExplicitRouteObject) obj; + // break; + // } + // case 2: + // state = 3; + // if (obj instanceof BandwidthObject) { + // bandwidth = (BandwidthObject) obj; + // break; + // } + // case 3: + // state = 4; + // if (obj instanceof MetricObject) { + // metrics.add((MetricObject) obj); + // state = 3; + // break; + // } + // } + // + // if (state == 4) + // break; + // + // objects.remove(0); + // } + // + // return new CompositeInstantiationObject(endPoints, lspa, ero, bandwidth, metrics); + // } }