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 io.netty.buffer.ByteBuf;
12 import java.util.ArrayList;
13 import java.util.List;
15 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
16 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
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.include.route.object.Iro;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder;
25 import com.google.common.base.Preconditions;
26 import com.google.common.collect.Lists;
29 * Parser for {@link Iro}
31 public class PCEPIncludeRouteObjectParser extends AbstractEROWithSubobjectsParser {
33 public static final int CLASS = 10;
35 public static final int TYPE = 1;
37 public PCEPIncludeRouteObjectParser(final EROSubobjectRegistry subobjReg) {
42 public Iro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
43 Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
44 final IroBuilder builder = new IroBuilder();
45 builder.setIgnore(header.isIgnore());
46 builder.setProcessingRule(header.isProcessingRule());
47 final List<Subobject> subs = new ArrayList<>();
48 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject s : parseSubobjects(bytes)) {
49 subs.add(new SubobjectBuilder().setSubobjectType(s.getSubobjectType()).build());
51 builder.setSubobject(subs);
52 return builder.build();
56 public byte[] serializeObject(final Object object) {
57 if (!(object instanceof Iro)) {
58 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed IncludeRouteObject.");
60 final Iro iro = ((Iro) object);
62 assert !(iro.getSubobject().isEmpty()) : "Empty Include Route Object.";
64 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
66 for (final Subobject s : iro.getSubobject()) {
67 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
68 false).setSubobjectType(s.getSubobjectType()).build());
70 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), serializeSubobject(subs));