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.object;
10 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
12 import com.google.common.base.Preconditions;
13 import io.netty.buffer.ByteBuf;
14 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.rev181109.Object;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro.Flags;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.XroBuilder;
25 * Parser for {@link Xro}
27 public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobjectsParser {
29 private static final int CLASS = 17;
30 private static final int TYPE = 1;
31 private static final int FLAGS_OFFSET = 3;
33 public PCEPExcludeRouteObjectParser(final XROSubobjectRegistry registry) {
34 super(registry, CLASS, TYPE);
38 public Xro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
39 Preconditions.checkArgument(bytes != null && bytes.isReadable(),
40 "Array of bytes is mandatory. Can't be null or empty.");
41 final XroBuilder builder = new XroBuilder();
42 builder.setIgnore(header.isIgnore());
43 builder.setProcessingRule(header.isProcessingRule());
44 bytes.skipBytes(FLAGS_OFFSET);
45 builder.setFlags(new Flags(bytes.readBoolean()));
46 builder.setSubobject(parseSubobjects(bytes.slice()));
47 return builder.build();
51 public void serializeObject(final Object object, final ByteBuf buffer) {
52 Preconditions.checkArgument(object instanceof Xro,
53 "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 writeBoolean(obj.getFlags() != null ? obj.getFlags().isFail() : null, body);
58 serializeSubobject(obj.getSubobject(), body);
59 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);