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 com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
18 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.Iro;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.IroBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.Subobject;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder;
27 * Parser for {@link Iro}.
29 public final class PCEPIncludeRouteObjectParser extends AbstractEROWithSubobjectsParser {
31 private static final int CLASS = 10;
32 private static final int TYPE = 1;
34 public PCEPIncludeRouteObjectParser(final EROSubobjectRegistry subobjReg) {
35 super(subobjReg, CLASS, TYPE);
39 public Iro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
40 checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
41 final List<Subobject> subs = new ArrayList<>();
42 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
43 .route.object.ero.Subobject s : parseSubobjects(bytes)) {
44 subs.add(new SubobjectBuilder()
45 .setLoose(s.getLoose())
46 .setSubobjectType(s.getSubobjectType())
49 return new IroBuilder()
50 .setIgnore(header.getIgnore())
51 .setProcessingRule(header.getProcessingRule())
57 public void serializeObject(final Object object, final ByteBuf buffer) {
58 checkArgument(object instanceof Iro, "Wrong instance of PCEPObject. Passed %s. Needed IroObject.",
60 final Iro iro = (Iro) object;
61 final ByteBuf body = Unpooled.buffer();
62 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
63 .route.object.ero.Subobject> subs = new ArrayList<>();
64 for (final Subobject s : iro.nonnullSubobject()) {
66 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
67 .explicit.route.object.ero.SubobjectBuilder()
68 .setLoose(s.getLoose())
69 .setSubobjectType(s.getSubobjectType())
72 serializeSubobject(subs, body);
73 ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);