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 io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
13 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
14 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
20 import com.google.common.base.Preconditions;
23 * Parser for {@link Ero}
25 public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
27 public static final int CLASS = 7;
29 public static final int TYPE = 1;
31 public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
36 public Ero parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
37 Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
38 final EroBuilder builder = new EroBuilder();
39 builder.setIgnore(header.isIgnore());
40 builder.setProcessingRule(header.isProcessingRule());
41 builder.setSubobject(parseSubobjects(buffer));
42 return builder.build();
46 public byte[] serializeObject(final Object object) {
47 if (!(object instanceof Ero)) {
48 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
49 + ". Needed ExplicitRouteObject.");
51 final Ero ero = ((Ero) object);
53 assert !(ero.getSubobject().isEmpty()) : "Empty Explicit Route Object.";
55 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(),
56 serializeSubobject(ero.getSubobject()));