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 java.util.List;
12 import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
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.Subobject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
24 import com.google.common.collect.Lists;
27 * Parser for {@link PathKey}
29 public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser {
31 public static final int CLASS = 16;
33 public static final int TYPE = 1;
35 public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
40 public PathKey parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
41 final PathKeyBuilder builder = new PathKeyBuilder();
42 builder.setIgnore(header.isIgnore());
43 builder.setProcessingRule(header.isProcessingRule());
44 final List<PathKeys> pk = Lists.newArrayList();
45 final List<Subobject> subs = parseSubobjects(bytes);
46 for (final Subobject s : subs) {
47 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCase k = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCase) s.getSubobjectType();
48 pk.add(new PathKeysBuilder().setLoose(s.isLoose()).setPceId(k.getPathKey().getPceId()).setPathKey(k.getPathKey().getPathKey()).build());
50 builder.setPathKeys(pk);
51 return builder.build();
55 public byte[] serializeObject(final Object object) {
56 if (!(object instanceof PathKey)) {
57 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject.");
59 final PathKey pkey = (PathKey) object;
60 final List<PathKeys> pk = pkey.getPathKeys();
61 final List<Subobject> subs = Lists.newArrayList();
62 for (final PathKeys p : pk) {
63 subs.add(new SubobjectBuilder().setLoose(p.isLoose()).setSubobjectType(
64 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCaseBuilder().setPathKey(
65 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKeyBuilder().setPathKey(
66 p.getPathKey()).setPceId(p.getPceId()).build()).build()).build());
68 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), serializeSubobject(subs));
72 public int getObjectType() {
77 public int getObjectClass() {