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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.util.ArrayList;
14 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.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.include.route.object.Iro;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.IroBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.Subobject;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder;
26 * Parser for {@link Iro}.
28 public final class PCEPIncludeRouteObjectParser extends AbstractEROWithSubobjectsParser {
30 private static final int CLASS = 10;
31 private static final int TYPE = 1;
33 public PCEPIncludeRouteObjectParser(final EROSubobjectRegistry subobjReg) {
34 super(subobjReg, CLASS, TYPE);
38 public Iro 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 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 Preconditions.checkArgument(object instanceof Iro,
59 "Wrong instance of PCEPObject. Passed %s. Needed IroObject.", object.getClass());
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);