38ad207c03dcb61d03f7a75a2e890e322a470e28
[bgpcep.git] / bgp / extensions / l3vpn / src / main / java / org / opendaylight / protocol / bgp / l3vpn / mcast / nlri / L3vpnMcastIpv6NlriHandler.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.l3vpn.mcast.nlri;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
12 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
13 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil;
14 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
15 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
16 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationL3vpnMcastIpv6AdvertizedCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationL3vpnMcastIpv6AdvertizedCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.l3vpn.mcast.ipv6.advertized._case.DestinationIpv6L3vpnMcastBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationL3vpnMcastIpv6WithdrawnCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationL3vpnMcastIpv6WithdrawnCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
31
32 /**
33  * https://tools.ietf.org/html/rfc6514#section-4.
34  *
35  * @author Claudio D. Gasparini
36  */
37 public final class L3vpnMcastIpv6NlriHandler implements NlriParser, NlriSerializer {
38     @Override
39     public void parseNlri(
40             final ByteBuf nlri,
41             final MpReachNlriBuilder builder,
42             final PeerSpecificParserConstraint constraint) throws BGPParsingException {
43         if (!nlri.isReadable()) {
44             return;
45         }
46         final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint,
47                 new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
48
49         builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
50                 new DestinationL3vpnMcastIpv6AdvertizedCaseBuilder().setDestinationIpv6L3vpnMcast(
51                         new DestinationIpv6L3vpnMcastBuilder().setL3vpnMcastDestination(
52                                 L3vpnMcastNlriSerializer.extractDest(nlri, mPathSupported)).build()).build()).build());
53     }
54
55
56     @Override
57     public void parseNlri(
58             final ByteBuf nlri,
59             final MpUnreachNlriBuilder builder,
60             final PeerSpecificParserConstraint constraint) throws BGPParsingException {
61         if (!nlri.isReadable()) {
62             return;
63         }
64         final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint,
65                 new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
66         builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder()
67                 .setDestinationType(new DestinationL3vpnMcastIpv6WithdrawnCaseBuilder().setDestinationIpv6L3vpnMcast(
68                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417
69                                 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.l3vpn
70                                 .mcast.ipv6.withdrawn._case.DestinationIpv6L3vpnMcastBuilder()
71                                 .setL3vpnMcastDestination(L3vpnMcastNlriSerializer.extractDest(nlri, mPathSupported))
72                                 .build()).build()).build());
73     }
74
75     @Override
76     public void serializeAttribute(final Attributes pathAttributes, final ByteBuf byteAggregator) {
77         final AttributesReach pathAttributes1 = pathAttributes.augmentation(AttributesReach.class);
78         final AttributesUnreach pathAttributes2 = pathAttributes.augmentation(AttributesUnreach.class);
79         if (pathAttributes1 != null) {
80             final AdvertizedRoutes routes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes();
81             if (routes != null && routes.getDestinationType() instanceof DestinationL3vpnMcastIpv6AdvertizedCase) {
82                 final DestinationL3vpnMcastIpv6AdvertizedCase reach
83                         = (DestinationL3vpnMcastIpv6AdvertizedCase) routes.getDestinationType();
84                 L3vpnMcastNlriSerializer.serializeNlri(reach.getDestinationIpv6L3vpnMcast().getL3vpnMcastDestination(),
85                         byteAggregator);
86             }
87         } else if (pathAttributes2 != null) {
88             final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes();
89             if (withdrawnRoutes != null
90                     && withdrawnRoutes.getDestinationType() instanceof DestinationL3vpnMcastIpv6WithdrawnCase) {
91                 final DestinationL3vpnMcastIpv6WithdrawnCase reach
92                         = (DestinationL3vpnMcastIpv6WithdrawnCase) withdrawnRoutes.getDestinationType();
93                 L3vpnMcastNlriSerializer.serializeNlri(reach.getDestinationIpv6L3vpnMcast().getL3vpnMcastDestination(),
94                         byteAggregator);
95             }
96         }
97     }
98 }