X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2Fobject%2FPCEPPathKeyObjectParser.java;h=59a5327604d31a7290b555c21e06255db8f8d5f1;hb=b7985ae58fb4050cccbe361f11d195b9b37a0357;hp=570f054cfea6ba9c9363660e47924a7630821c85;hpb=e0a5b2c8695603825cb242906479cd6bc05adb06;p=bgpcep.git diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java index 570f054cfe..59a5327604 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java @@ -7,60 +7,65 @@ */ package org.opendaylight.protocol.pcep.impl.object; -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser; -import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; +import java.util.List; + +import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.ObjectUtil; +import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.path.key.expansion.PathKeyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder; + +import com.google.common.collect.Lists; /** - * Parser for {@link PathKeyObject} + * Parser for {@link PathKey} */ -public class PCEPPathKeyObjectParser extends AbstractObjectWithTlvsParser { +public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser { public static final int CLASS = 16; public static final int TYPE = 1; - public PCEPPathKeyObjectParser(final TlvHandlerRegistry tlvReg) { - super(tlvReg); + public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) { + super(subReg); } @Override - public PathKeyObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { - // FIXME : finish - + public PathKey parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException { final PathKeyBuilder builder = new PathKeyBuilder(); - builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); - + final List pk = Lists.newArrayList(); + final List subs = parseSubobjects(bytes); + for (final Subobject s : subs) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCase k = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCase) s.getSubobjectType(); + pk.add(new PathKeysBuilder().setLoose(s.isLoose()).setPceId(k.getPathKey().getPceId()).setPathKey(k.getPathKey().getPathKey()).build()); + } + builder.setPathKeys(pk); return builder.build(); } - @Override - public void addTlv(final PathKeyBuilder builder, final Tlv tlv) { - // No tlvs defined - } - @Override public byte[] serializeObject(final Object object) { - if (!(object instanceof PathKeyObject)) { + if (!(object instanceof PathKey)) { throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject."); } - - final PathKeyObject pkey = (PathKeyObject) object; - - // FIXME, but no Tlvs defined - // final byte[] tlvs = PCEPTlvParser.put(lspaObj.getTlvs()); - // final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length]; - // ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET); - return new byte[0]; + final PathKey pkey = (PathKey) object; + final List pk = pkey.getPathKeys(); + final List subs = Lists.newArrayList(); + for (final PathKeys p : pk) { + subs.add(new SubobjectBuilder().setLoose(p.isLoose()).setSubobjectType( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCaseBuilder().setPathKey( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKeyBuilder().setPathKey( + p.getPathKey()).setPceId(p.getPceId()).build()).build()).build()); + } + return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), serializeSubobject(subs)); } @Override