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 org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
12 import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
13 import org.opendaylight.protocol.util.ByteArray;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject.Flags;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.XroBuilder;
20 import com.google.common.primitives.UnsignedBytes;
23 * Parser for {@link ExcludeRouteObject}
25 public final class PCEPExcludeRouteObjectParser extends AbstractXROWithSubobjectsParser {
27 public static final int CLASS = 7;
29 public static final int TYPE = 1;
31 private static final int FLAGS_OFFSET = 3;
33 public PCEPExcludeRouteObjectParser(final XROSubobjectHandlerRegistry registry) {
38 public ExcludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
39 PCEPDocumentedException {
40 if (bytes == null || bytes.length == 0) {
41 throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
43 final XroBuilder builder = new XroBuilder();
44 builder.setIgnore(header.isIgnore());
45 builder.setProcessingRule(header.isProcessingRule());
46 builder.setFlags(new Flags(UnsignedBytes.toInt(bytes[FLAGS_OFFSET]) != 0));
47 builder.setSubobjects(parseSubobjects(ByteArray.cutBytes(bytes, FLAGS_OFFSET + 1)));
48 return builder.build();
52 public byte[] serializeObject(final Object object) {
53 if (!(object instanceof ExcludeRouteObject)) {
54 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ExcludeRouteObject.");
56 final ExcludeRouteObject obj = (ExcludeRouteObject) object;
57 assert !(obj.getSubobjects().isEmpty()) : "Empty Excluded Route Object.";
58 final byte[] bytes = serializeSubobject(obj.getSubobjects());
59 final byte[] result = new byte[FLAGS_OFFSET + 1 + bytes.length];
60 if (obj.getFlags().isFail()) {
61 result[FLAGS_OFFSET] = 1;
63 ByteArray.copyWhole(bytes, result, FLAGS_OFFSET + 1);
68 public int getObjectType() {
73 public int getObjectClass() {