X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fbase-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fparser%2Fsubobject%2FXROIpv6PrefixSubobjectParser.java;fp=pcep%2Fbase-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fparser%2Fsubobject%2FXROIpv6PrefixSubobjectParser.java;h=e1692a77568dff141b2c0ee88a0c04ddc4e9b85a;hb=59bd8a58570b93fef65340808e37cab3c6fced8c;hp=513d70083467a921231bfaec181a7170aa58f21f;hpb=3b658310b793d4882ce59198a6d2563ce6ba114d;p=bgpcep.git diff --git a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java index 513d700834..e1692a7756 100644 --- a/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java +++ b/pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/subobject/XROIpv6PrefixSubobjectParser.java @@ -7,10 +7,9 @@ */ package org.opendaylight.protocol.pcep.parser.subobject; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix; -import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; @@ -20,6 +19,7 @@ import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.protocol.util.Ipv6Util; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute; @@ -27,25 +27,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder; -import org.opendaylight.yangtools.yang.common.Uint8; /** * Parser for {@link IpPrefixCase}. */ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer { - public static final int TYPE = 2; private static final int PREFIX_F_LENGTH = 1; - private static final int PREFIX6_F_OFFSET = Ipv6Util.IPV6_LENGTH; - private static final int CONTENT6_LENGTH = PREFIX6_F_OFFSET + PREFIX_F_LENGTH + 1; @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { - Preconditions.checkArgument(buffer != null && buffer.isReadable(), - "Array of bytes is mandatory. Can't be null or empty."); + checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT6_LENGTH) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); @@ -63,15 +58,20 @@ public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubo @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { - Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, + checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); - final IpPrefix prefix = specObj.getIpPrefix(); + final Ipv6Prefix ipv6Prefix = specObj.getIpPrefix().getIpv6Prefix(); + checkArgument(ipv6Prefix != null, "Ipv6Prefix is mandatory."); + serializeSubobject(buffer, subobject, ipv6Prefix); + } + + static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6Prefix) { final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH); - Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory."); - writeIpv6Prefix(prefix.getIpv6Prefix(), body); - Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); - writeUnsignedByte(Uint8.valueOf(subobject.getAttribute().getIntValue()), body); + writeIpv6Prefix(ipv6Prefix, body); + final Attribute attribute = subobject.getAttribute(); + checkArgument(attribute != null, "Attribute is mandatory."); + body.writeByte(attribute.getIntValue()); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } }