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 IroBuilder builder = new IroBuilder();
42 builder.setIgnore(header.isIgnore());
43 builder.setProcessingRule(header.isProcessingRule());
44 final List<Subobject> subs = new ArrayList<>();
45 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
46 .route.object.ero.Subobject s : parseSubobjects(bytes)) {
47 subs.add(new SubobjectBuilder().setLoose(s.isLoose()).setSubobjectType(s.getSubobjectType()).build());
49 builder.setSubobject(subs);
50 return builder.build();
54 public void serializeObject(final Object object, final ByteBuf buffer) {
55 Preconditions.checkArgument(object instanceof Iro,
56 "Wrong instance of PCEPObject. Passed %s. Needed IroObject.", object.getClass());
57 final Iro iro = ((Iro) object);
58 final ByteBuf body = Unpooled.buffer();
59 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
60 .route.object.ero.Subobject> subs = new ArrayList<>();
61 for (final Subobject s : iro.getSubobject()) {
62 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
63 .explicit.route.object.ero.SubobjectBuilder().setLoose(
64 s.isLoose()).setSubobjectType(s.getSubobjectType()).build());
66 serializeSubobject(subs, body);
67 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);