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.HandlerRegistry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.definition.ExplicitRouteBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
24 import com.google.common.collect.Maps;
27 * Parser for {@link ExplicitRouteObject}
29 public class PCEPExplicitRouteObjectParser extends AbstractObjectParser<ExplicitRouteBuilder> {
31 public static final int CLASS = 7;
33 public static final int TYPE = 1;
35 public PCEPExplicitRouteObjectParser(final HandlerRegistry registry) {
40 public ExplicitRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
41 PCEPDocumentedException {
42 if (bytes == null || bytes.length == 0)
43 throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
45 final ExplicitRouteBuilder builder = new ExplicitRouteBuilder();
47 builder.setIgnore(header.isIgnore());
48 builder.setProcessingRule(header.isProcessingRule());
50 parseSubobjects(builder, bytes);
51 return builder.build();
55 public void addTlv(final ExplicitRouteBuilder builder, final Tlv tlv) {
60 public byte[] serializeObject(final Object object) {
61 if (!(object instanceof ExplicitRouteObject))
62 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
63 + ". Needed ExplicitRouteObject.");
65 final ExplicitRouteObject ero = ((ExplicitRouteObject) object);
67 assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
69 final Map<CSubobject, Boolean> subs = Maps.newHashMap();
70 for (final Subobjects s : ero.getSubobjects()) {
71 subs.put((CSubobject) s, s.isLoose());
73 return serializeSubobject(subs);
77 // public void addSubobject(ExplicitRouteBuilder builder, Map<CSubobject, Boolean> subobjects) {
78 // List<Subobjects> subs = Lists.newArrayList();
79 // for (Entry<CSubobject, Boolean> entry : subobjects.entrySet()) {
80 // SubobjectsBuilder b = new SubobjectsBuilder();
81 // b.setLoose(entry.getValue());
82 // CSubobject sub = entry.getKey();
83 // if (sub instanceof IpPrefixSubobject) {
84 // b.setSubobjectType(new IpPrefixBuilder().setIpPrefix(((IpPrefix)sub).getIpPrefix()).build());
85 // subs.add(b.build());
86 // } else if (sub instanceof AsNumberSubobject) {
87 // b.setSubobjectType(new AsNumberBuilder().setAsNumber((AsNumber)sub).build());
88 // subs.add(b.build());
89 // } else if (sub instanceof LabelSubobject) {
90 // b.setSubobjectType(new LabelBuilder().setLabels(((Label)sub).getLabels()).build());
91 // subs.add(b.build());
92 // } else if (sub instanceof UnnumberedSubobject) {
93 // b.setSubobjectType(new
94 // UnnumberedBuilder().setInterfaceId(((Unnumbered)sub).getInterfaceId()).setRouterId(((Unnumbered)sub).getRouterId()).build());
95 // subs.add(b.build());
98 // builder.setSubobjects(subs);
102 public int getObjectType() {
107 public int getObjectClass() {