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 org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
11 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
18 * Parser for {@link Ero}
20 public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
22 public static final int CLASS = 7;
24 public static final int TYPE = 1;
26 public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
31 public Ero parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
32 if (bytes == null || bytes.length == 0) {
33 throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
35 final EroBuilder builder = new EroBuilder();
36 builder.setIgnore(header.isIgnore());
37 builder.setProcessingRule(header.isProcessingRule());
38 builder.setSubobjects(parseSubobjects(bytes));
39 return builder.build();
43 public byte[] serializeObject(final Object object) {
44 if (!(object instanceof Ero)) {
45 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
46 + ". Needed ExplicitRouteObject.");
48 final Ero ero = ((Ero) object);
50 assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
52 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(),
53 serializeSubobject(ero.getSubobjects()));
57 public int getObjectType() {
62 public int getObjectClass() {