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 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.explicit.route.object.Ero;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
24 * Parser for {@link Ero}
26 public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
28 public static final int CLASS = 7;
30 public static final int TYPE = 1;
32 public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
37 public Ero parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
38 // Explicit approval of empty ERO
39 Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
40 final EroBuilder builder = new EroBuilder();
41 builder.setIgnore(header.isIgnore());
42 builder.setProcessingRule(header.isProcessingRule());
43 builder.setSubobject(parseSubobjects(buffer));
44 return builder.build();
48 public void serializeObject(final Object object, final ByteBuf buffer) {
49 Preconditions.checkArgument(object instanceof Ero, "Wrong instance of PCEPObject. Passed %s. Needed EroObject.", object.getClass());
50 final Ero ero = ((Ero) object);
51 final ByteBuf body = Unpooled.buffer();
52 serializeSubobject(ero.getSubobject(), body);
53 ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);