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.PCEPDeserializerException;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
23 import com.google.common.collect.Lists;
26 * Parser for {@link PathKey}
28 public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser {
30 public static final int CLASS = 16;
32 public static final int TYPE = 1;
34 public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
39 public PathKey parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
40 final PathKeyBuilder builder = new PathKeyBuilder();
41 builder.setIgnore(header.isIgnore());
42 builder.setProcessingRule(header.isProcessingRule());
43 final List<PathKeys> pk = Lists.newArrayList();
44 final List<Subobject> subs = parseSubobjects(bytes);
45 for (final Subobject s : subs) {
46 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();
47 pk.add(new PathKeysBuilder().setLoose(s.isLoose()).setPceId(k.getPathKey().getPceId()).setPathKey(k.getPathKey().getPathKey()).build());
49 builder.setPathKeys(pk);
50 return builder.build();
54 public byte[] serializeObject(final Object object) {
55 if (!(object instanceof PathKey)) {
56 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject.");
58 final PathKey pkey = (PathKey) object;
59 final List<PathKeys> pk = pkey.getPathKeys();
60 final List<Subobject> subs = Lists.newArrayList();
61 for (final PathKeys p : pk) {
62 subs.add(new SubobjectBuilder().setLoose(p.isLoose()).setSubobjectType(
63 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCaseBuilder().setPathKey(
64 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(
65 p.getPathKey()).setPceId(p.getPceId()).build()).build()).build());
67 return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), serializeSubobject(subs));
71 public int getObjectType() {
76 public int getObjectClass() {