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 java.util.List;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
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.include.route.object.Subobjects;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.SubobjectsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.IncludeRouteBuilder;
22 import com.google.common.collect.Lists;
25 * Parser for {@link IncludeRouteObject}
27 public class PCEPIncludeRouteObjectParser extends AbstractEROWithSubobjectsParser {
29 public static final int CLASS = 10;
31 public static final int TYPE = 1;
33 public PCEPIncludeRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
38 public IncludeRouteObject 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.");
44 final IncludeRouteBuilder builder = new IncludeRouteBuilder();
46 builder.setIgnore(header.isIgnore());
47 builder.setProcessingRule(header.isProcessingRule());
49 final List<Subobjects> subs = Lists.newArrayList();
50 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects s : parseSubobjects(bytes)) {
51 subs.add(new SubobjectsBuilder().setSubobjectType(s.getSubobjectType()).build());
53 builder.setSubobjects(subs);
54 return builder.build();
58 public byte[] serializeObject(final Object object) {
59 if (!(object instanceof IncludeRouteObject)) {
60 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed IncludeRouteObject.");
62 final IncludeRouteObject iro = ((IncludeRouteObject) object);
64 assert !(iro.getSubobjects().isEmpty()) : "Empty Include Route Object.";
66 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects> subs = Lists.newArrayList();
68 for (final Subobjects s : iro.getSubobjects()) {
69 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
70 false).setSubobjectType(s.getSubobjectType()).build());
73 return serializeSubobject(subs);
77 public int getObjectType() {
82 public int getObjectClass() {