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 com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
19 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
20 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder;
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().setLoose(s.isLoose()).setSubobjectType(s.getSubobjectType()).build());
51 builder.setSubobject(subs);
52 return builder.build();
56 public void serializeObject(final Object object, final ByteBuf buffer) {
57 Preconditions.checkArgument(object instanceof Iro, "Wrong instance of PCEPObject. Passed %s. Needed IroObject.", object.getClass());
58 final Iro iro = ((Iro) object);
59 final ByteBuf body = Unpooled.buffer();
60 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.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.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
63 s.isLoose()).setSubobjectType(s.getSubobjectType()).build());
65 serializeSubobject(subs, body);
66 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);