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.impl.object;
10 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
15 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
25 * Parser for {@link Xro}
27 public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobjectsParser {
29 public static final int CLASS = 7;
31 public static final int TYPE = 1;
33 private static final int FLAGS_OFFSET = 3;
35 public PCEPExcludeRouteObjectParser(final XROSubobjectRegistry registry) {
40 public Xro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
41 Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
42 final XroBuilder builder = new XroBuilder();
43 builder.setIgnore(header.isIgnore());
44 builder.setProcessingRule(header.isProcessingRule());
45 bytes.readerIndex(bytes.readerIndex() + FLAGS_OFFSET);
46 builder.setFlags(new Flags(bytes.readBoolean()));
47 builder.setSubobject(parseSubobjects(bytes.slice()));
48 return builder.build();
52 public void serializeObject(final Object object, final ByteBuf buffer) {
53 Preconditions.checkArgument(object instanceof Xro, "Wrong instance of PCEPObject. Passed %s. Needed XroObject.", object.getClass());
54 final Xro obj = (Xro) object;
55 final ByteBuf body = Unpooled.buffer();
56 body.writeZero(FLAGS_OFFSET);
57 if (obj.getFlags().isFail() != null) {
58 body.writeBoolean(obj.getFlags().isFail());
60 serializeSubobject(obj.getSubobject(), body);
61 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);