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.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
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.PathKeyObject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobjects;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobjects.subobject.type.PathKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeys;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeysBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.path.key.expansion.PathKeyBuilder;
25 import com.google.common.collect.Lists;
28 * Parser for {@link PathKeyObject}
30 public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser {
32 public static final int CLASS = 16;
34 public static final int TYPE = 1;
36 public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
41 public PathKeyObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
42 PCEPDocumentedException {
43 final PathKeyBuilder builder = new PathKeyBuilder();
44 builder.setIgnore(header.isIgnore());
45 builder.setProcessingRule(header.isProcessingRule());
46 final List<PathKeys> pk = Lists.newArrayList();
47 final List<Subobjects> subs = parseSubobjects(bytes);
48 for (final Subobjects s : subs) {
49 final PathKey k = (PathKey) s.getSubobjectType();
50 pk.add(new PathKeysBuilder().setLoose(s.isLoose()).setPceId(k.getPathKey().getPceId()).setPathKey(k.getPathKey().getPathKey()).build());
52 builder.setPathKeys(pk);
53 return builder.build();
57 public byte[] serializeObject(final Object object) {
58 if (!(object instanceof PathKeyObject)) {
59 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject.");
61 final PathKeyObject pkey = (PathKeyObject) object;
62 final List<PathKeys> pk = pkey.getPathKeys();
63 final List<Subobjects> subs = Lists.newArrayList();
64 for (final PathKeys p : pk) {
65 subs.add(new SubobjectsBuilder().setLoose(p.isLoose()).setSubobjectType(
66 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobjects.subobject.type.PathKeyBuilder().setPathKey(
67 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobjects.subobject.type.path.key.PathKeyBuilder().setPathKey(
68 p.getPathKey()).setPceId(p.getPceId()).build()).build()).build());
70 return serializeSubobject(subs);
74 public int getObjectType() {
79 public int getObjectClass() {