BUG-731 : removed critical sonar warnings
[bgpcep.git] / bgp / linkstate / src / main / java / org / opendaylight / protocol / bgp / linkstate / LinkstateAdjRIBsIn.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.bgp.linkstate;
9
10 import com.google.common.base.Objects.ToStringHelper;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Lists;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.List;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs;
18 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
19 import org.opendaylight.protocol.bgp.rib.spi.Peer;
20 import org.opendaylight.protocol.util.ByteArray;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateDestination;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.LinkstateRoutes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.LinkstateRoute;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.LinkstateRouteBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.LinkstateRouteKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.Attributes1Builder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.ObjectType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.AttributeType;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.link._case.LinkAttributesBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.node._case.NodeAttributesBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.prefix._case.PrefixAttributesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.LinkCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.LinkCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.NodeCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.NodeCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.PrefixCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.PrefixCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.link._case.LinkDescriptorsBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.link._case.LocalNodeDescriptorsBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.link._case.RemoteNodeDescriptorsBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.node._case.NodeDescriptorsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.object.type.prefix._case.AdvertisingNodeDescriptorsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttribute;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstate;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.unreach.nlri.WithdrawnRoutes;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.AttributesBuilder;
71 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
72 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
75
76 final class LinkstateAdjRIBsIn extends AbstractAdjRIBs<CLinkstateDestination, LinkstateRoute, LinkstateRouteKey> {
77
78     private abstract static class LinkstateRIBEntryData<A extends LinkStateAttribute> extends RIBEntryData<CLinkstateDestination, LinkstateRoute, LinkstateRouteKey> {
79         private final A lsattr;
80
81         protected LinkstateRIBEntryData(final Peer peer, final PathAttributes attributes, final A lsattr) {
82             super(peer, attributes);
83             this.lsattr = lsattr;
84         }
85
86         protected abstract AttributeType createAttributes(A lsattr);
87
88         protected abstract ObjectType createObject(CLinkstateDestination key);
89
90         @Override
91         protected final LinkstateRoute getDataObject(final CLinkstateDestination key, final LinkstateRouteKey id) {
92             final LinkstateRouteBuilder builder = new LinkstateRouteBuilder();
93
94             builder.setKey(id);
95             builder.setIdentifier(key.getIdentifier());
96             builder.setProtocolId(key.getProtocolId());
97             builder.setDistinguisher(key.getDistinguisher());
98             builder.setAttributes(new AttributesBuilder(getPathAttributes()).addAugmentation(Attributes1.class,
99                 new Attributes1Builder().setAttributeType(Preconditions.checkNotNull(createAttributes(this.lsattr))).build()).build());
100             builder.setObjectType(Preconditions.checkNotNull(createObject(key)));
101
102             return builder.build();
103         }
104
105         @Override
106         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
107             return toStringHelper.add("lsattr", this.lsattr);
108         }
109     }
110
111     private static final Logger LOG = LoggerFactory.getLogger(LinkstateAdjRIBsIn.class);
112
113     LinkstateAdjRIBsIn(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
114         super(basePath);
115     }
116
117     @Override
118     public KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> identifierForKey(final InstanceIdentifier<Tables> basePath, final CLinkstateDestination key) {
119         final ByteBuf keyBuf = Unpooled.buffer();
120         LinkstateNlriParser.serializeNlri(key, keyBuf);
121         return basePath.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class,
122             new LinkstateRouteKey(ByteArray.readAllBytes(keyBuf)));
123     }
124
125     @Override
126     public void addRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpReachNlri nlri,
127         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes attributes) {
128         LOG.debug("Passed nlri {}", nlri);
129         final LinkstateDestination keys = ((DestinationLinkstateCase) nlri.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate();
130         if (keys == null) {
131             LOG.debug("No destinations present in advertized routes");
132             return;
133         }
134
135         LOG.debug("Iterating over route destinations {}", keys);
136
137         for (final CLinkstateDestination key : keys.getCLinkstateDestination()) {
138             LOG.debug("Processing route key {}", key);
139
140             LinkStateAttribute lsattr = null;
141             final PathAttributes1 pa = attributes.getAugmentation(PathAttributes1.class);
142             if (pa != null) {
143                 final LinkstatePathAttribute lpa = pa.getLinkstatePathAttribute();
144                 if (lpa != null) {
145                     lsattr = lpa.getLinkStateAttribute();
146                 }
147             }
148
149             RIBEntryData<CLinkstateDestination, LinkstateRoute, LinkstateRouteKey> data = null;
150             switch (key.getNlriType()) {
151             case Ipv4Prefix:
152             case Ipv6Prefix:
153                 data = new LinkstateRIBEntryData<PrefixAttributesCase>(peer, attributes, (PrefixAttributesCase) lsattr) {
154                     @Override
155                     protected AttributeType createAttributes(final PrefixAttributesCase lsattr) {
156                         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.PrefixCaseBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.PrefixCaseBuilder();
157                         if (lsattr != null && lsattr.getPrefixAttributes() != null) {
158                             b.setPrefixAttributes(new PrefixAttributesBuilder(lsattr.getPrefixAttributes()).build());
159                         }
160                         return b.build();
161                     }
162
163                     @Override
164                     protected PrefixCase createObject(final CLinkstateDestination key) {
165                         final PrefixCaseBuilder b = new PrefixCaseBuilder(key.getPrefixDescriptors());
166                         b.setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder(key.getLocalNodeDescriptors()).build());
167                         return b.build();
168                     }
169                 };
170                 break;
171             case Link:
172                 data = new LinkstateRIBEntryData<LinkAttributesCase>(peer, attributes, (LinkAttributesCase) lsattr) {
173                     @Override
174                     protected AttributeType createAttributes(final LinkAttributesCase lsattr) {
175                         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.LinkCaseBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.LinkCaseBuilder();
176                         if (lsattr != null && lsattr.getLinkAttributes() != null) {
177                             b.setLinkAttributes(new LinkAttributesBuilder(lsattr.getLinkAttributes()).build());
178                         }
179                         return b.build();
180                     }
181
182                     @Override
183                     protected LinkCase createObject(final CLinkstateDestination key) {
184                         final LinkCaseBuilder b = new LinkCaseBuilder();
185                         b.setLinkDescriptors(new LinkDescriptorsBuilder(key.getLinkDescriptors()).build());
186                         b.setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder(key.getLocalNodeDescriptors()).build());
187                         b.setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder(key.getRemoteNodeDescriptors()).build());
188                         return b.build();
189                     }
190                 };
191                 break;
192             case Node:
193                 data = new LinkstateRIBEntryData<NodeAttributesCase>(peer, attributes, (NodeAttributesCase) lsattr) {
194                     @Override
195                     protected AttributeType createAttributes(final NodeAttributesCase lsattr) {
196                         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.NodeCaseBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.routes.linkstate.routes.linkstate.route.attributes.attribute.type.NodeCaseBuilder();
197                         if (lsattr != null && lsattr.getNodeAttributes() != null) {
198                             b.setNodeAttributes(new NodeAttributesBuilder(lsattr.getNodeAttributes()).build());
199                         }
200                         return b.build();
201                     }
202
203                     @Override
204                     protected NodeCase createObject(final CLinkstateDestination key) {
205                         return new NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder(key.getLocalNodeDescriptors()).build()).build();
206                     }
207                 };
208                 break;
209             }
210             super.add(trans, peer, key, data);
211         }
212     }
213
214     @Override
215     public void removeRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
216         final DestinationLinkstate keys = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) nlri.getWithdrawnRoutes().getDestinationType()).getDestinationLinkstate();
217
218         for (final CLinkstateDestination key : keys.getCLinkstateDestination()) {
219             super.remove(trans, peer, key);
220         }
221     }
222
223     @Override
224     public void addAdvertisement(final MpReachNlriBuilder builder, final LinkstateRoute data) {
225         final CLinkstateDestinationBuilder nlri = new CLinkstateDestinationBuilder();
226         nlri.setProtocolId(data.getProtocolId());
227         nlri.setIdentifier(data.getIdentifier());
228         final Attributes a = data.getAttributes();
229         if (a != null && a.getCNextHop() != null) {
230             builder.setCNextHop(a.getCNextHop());
231         }
232         final ObjectType type = data.getObjectType();
233         if (type instanceof PrefixCase) {
234             final PrefixCase prefix = (PrefixCase) type;
235             final IpPrefix ip = prefix.getIpReachabilityInformation();
236
237             if (ip.getIpv4Prefix() != null) {
238                 nlri.setNlriType(NlriType.Ipv4Prefix);
239             } else if (ip.getIpv6Prefix() != null) {
240                 nlri.setNlriType(NlriType.Ipv6Prefix);
241             } else {
242                 throw new IllegalArgumentException("Unsupported reachability type " + ip);
243             }
244             nlri.setLocalNodeDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder(prefix.getAdvertisingNodeDescriptors()).build());
245
246         } else if (type instanceof NodeCase) {
247             final NodeCase node = (NodeCase) type;
248
249             nlri.setNlriType(NlriType.Node);
250             nlri.setLocalNodeDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder(node.getNodeDescriptors()).build());
251         } else if (type instanceof LinkCase) {
252             final LinkCase link = (LinkCase) type;
253
254             nlri.setNlriType(NlriType.Link);
255             nlri.setLinkDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder(link.getLinkDescriptors()).build());
256             nlri.setLocalNodeDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder(link.getLocalNodeDescriptors()).build());
257             nlri.setRemoteNodeDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder(link.getRemoteNodeDescriptors()).build());
258         } else {
259             throw new IllegalArgumentException("Unhandled linkstate route type " + type);
260         }
261
262         final AdvertizedRoutes ar = builder.getAdvertizedRoutes();
263         if (ar == null) {
264             builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
265                 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder()
266                     .setCLinkstateDestination(Lists.newArrayList(nlri.build())).build()).build()).build());
267         } else {
268             ((DestinationLinkstateCase) ar.getDestinationType()).getDestinationLinkstate().getCLinkstateDestination().add(nlri.build());
269         }
270     }
271
272     @Override
273     public void addWithdrawal(final MpUnreachNlriBuilder builder, final CLinkstateDestination id) {
274         final WithdrawnRoutes wr = builder.getWithdrawnRoutes();
275         if (wr == null) {
276             builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
277                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
278                     new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder()
279                         .setCLinkstateDestination(Lists.newArrayList(id)).build()).build()).build());
280         } else {
281             ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) wr.getDestinationType())
282             .getDestinationLinkstate().getCLinkstateDestination().add(id);
283         }
284     }
285
286     @SuppressWarnings("unchecked")
287     @Override
288     public KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> routeIdentifier(final InstanceIdentifier<?> id) {
289         return (KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey>)id.firstIdentifierOf(LinkstateRoute.class);
290     }
291
292     @Override
293     public CLinkstateDestination keyForIdentifier(final KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> id) {
294         final LinkstateRouteKey route = id.getKey();
295         List<CLinkstateDestination> dests = null;
296         try {
297             dests = LinkstateNlriParser.parseNlri(Unpooled.wrappedBuffer(route.getRouteKey()), false);
298         } catch (final BGPParsingException e) {
299             LOG.warn("Unable to parse LinkstateRoute Key {}", route, e);
300         }
301         if (dests == null || dests.size() != 1) {
302             LOG.warn("Null or more than one LinkstateRoute Key was parsed");
303             return null;
304         }
305         return dests.get(0);
306     }
307 }