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.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
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.reported.route.object.Rro;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
18 * Parser for {@link Rro}
20 public class PCEPReportedRouteObjectParser extends AbstractRROWithSubobjectsParser {
22 public static final int CLASS = 8;
24 public static final int TYPE = 1;
26 public PCEPReportedRouteObjectParser(final RROSubobjectHandlerRegistry subobjReg) {
31 public Rro 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 RroBuilder builder = new RroBuilder();
37 builder.setIgnore(header.isIgnore());
38 builder.setProcessingRule(header.isProcessingRule());
39 builder.setSubobjects(parseSubobjects(bytes));
40 return builder.build();
44 public byte[] serializeObject(final Object object) {
45 if (!(object instanceof Rro)) {
46 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
47 + ". Needed ReportedRouteObject.");
49 final Rro obj = (Rro) object;
50 assert !(obj.getSubobjects().isEmpty()) : "Empty Reported Route Object.";
51 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(),
52 serializeSubobject(obj.getSubobjects()));
56 public int getObjectType() {
61 public int getObjectClass() {