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;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
14 import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
15 import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry;
16 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.definition.ExplicitRouteBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
25 import com.google.common.collect.Maps;
28 * Parser for {@link ExplicitRouteObject}
30 public class PCEPExplicitRouteObjectParser extends AbstractObjectParser<ExplicitRouteBuilder> {
32 public static final int CLASS = 7;
34 public static final int TYPE = 1;
36 public PCEPExplicitRouteObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) {
37 super(subobjReg, tlvReg);
41 public ExplicitRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
42 PCEPDocumentedException {
43 if (bytes == null || bytes.length == 0) {
44 throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
47 final ExplicitRouteBuilder builder = new ExplicitRouteBuilder();
49 builder.setIgnore(header.isIgnore());
50 builder.setProcessingRule(header.isProcessingRule());
52 parseSubobjects(builder, bytes);
53 return builder.build();
57 public void addTlv(final ExplicitRouteBuilder builder, final Tlv tlv) {
62 public byte[] serializeObject(final Object object) {
63 if (!(object instanceof ExplicitRouteObject)) {
64 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
65 + ". Needed ExplicitRouteObject.");
68 final ExplicitRouteObject ero = ((ExplicitRouteObject) object);
70 assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
72 final Map<CSubobject, Boolean> subs = Maps.newHashMap();
73 for (final Subobjects s : ero.getSubobjects()) {
74 subs.put((CSubobject) s, s.isLoose());
76 return serializeSubobject(subs);
80 // public void addSubobject(ExplicitRouteBuilder builder, Map<CSubobject, Boolean> subobjects) {
81 // List<Subobjects> subs = Lists.newArrayList();
82 // for (Entry<CSubobject, Boolean> entry : subobjects.entrySet()) {
83 // SubobjectsBuilder b = new SubobjectsBuilder();
84 // b.setLoose(entry.getValue());
85 // CSubobject sub = entry.getKey();
86 // if (sub instanceof IpPrefixSubobject) {
87 // b.setSubobjectType(new IpPrefixBuilder().setIpPrefix(((IpPrefix)sub).getIpPrefix()).build());
88 // subs.add(b.build());
89 // } else if (sub instanceof AsNumberSubobject) {
90 // b.setSubobjectType(new AsNumberBuilder().setAsNumber((AsNumber)sub).build());
91 // subs.add(b.build());
92 // } else if (sub instanceof LabelSubobject) {
93 // b.setSubobjectType(new LabelBuilder().setLabels(((Label)sub).getLabels()).build());
94 // subs.add(b.build());
95 // } else if (sub instanceof UnnumberedSubobject) {
96 // b.setSubobjectType(new
97 // UnnumberedBuilder().setInterfaceId(((Unnumbered)sub).getInterfaceId()).setRouterId(((Unnumbered)sub).getRouterId()).build());
98 // subs.add(b.build());
101 // builder.setSubobjects(subs);
105 public int getObjectType() {
110 public int getObjectClass() {