Merge "BUG-113: split HandlerRegistry into per-class registries"
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPPathKeyObjectParser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.impl.object;
9
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
12 import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
13 import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry;
14 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
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.Tlv;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.path.key.expansion.PathKeyBuilder;
20
21 /**
22  * Parser for {@link PathKeyObject}
23  */
24 public class PCEPPathKeyObjectParser extends AbstractObjectParser<PathKeyBuilder> {
25
26         public static final int CLASS = 16;
27
28         public static final int TYPE = 1;
29
30         public PCEPPathKeyObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) {
31                 super(subobjReg, tlvReg);
32         }
33
34         @Override
35         public PathKeyObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
36         PCEPDocumentedException {
37                 // FIXME : finish
38
39                 final PathKeyBuilder builder = new PathKeyBuilder();
40
41                 builder.setIgnore(header.isIgnore());
42                 builder.setProcessingRule(header.isProcessingRule());
43
44                 return builder.build();
45         }
46
47         @Override
48         public void addTlv(final PathKeyBuilder builder, final Tlv tlv) {
49                 // No tlvs defined
50         }
51
52         @Override
53         public byte[] serializeObject(final Object object) {
54                 if (!(object instanceof PathKeyObject)) {
55                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject.");
56                 }
57
58                 final PathKeyObject pkey = (PathKeyObject) object;
59
60                 // FIXME, but no Tlvs defined
61                 // final byte[] tlvs = PCEPTlvParser.put(lspaObj.getTlvs());
62                 // final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length];
63                 // ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET);
64                 return new byte[0];
65         }
66
67         @Override
68         public int getObjectType() {
69                 return TYPE;
70         }
71
72         @Override
73         public int getObjectClass() {
74                 return CLASS;
75         }
76 }