Provide Add Path support for all AFI/SAFI
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / l3vpn / ipv6 / FlowspecL3vpnIpv6NlriParser.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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.flowspec.l3vpn.ipv6;
9
10 import io.netty.buffer.ByteBuf;
11 import java.util.List;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry;
15 import org.opendaylight.protocol.bgp.flowspec.ipv6.FlowspecIpv6NlriParserHelper;
16 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnNlriParser;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.Flowspec;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.FlowspecBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.destination.DestinationType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
25 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
26
27 /**
28  * @author Kevin Wang
29  */
30 public final class FlowspecL3vpnIpv6NlriParser extends AbstractFlowspecL3vpnNlriParser {
31
32     public FlowspecL3vpnIpv6NlriParser(SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
33         super(flowspecTypeRegistry);
34     }
35
36     @Override
37     public DestinationType createWithdrawnDestinationType(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId) {
38         final RouteDistinguisher rd = (RouteDistinguisher) nlriFields[0];
39         final List<Flowspec> flowspecList = (List<Flowspec>) nlriFields[1];
40         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6CaseBuilder()
41             .setDestinationFlowspecL3vpnIpv6(
42                 new DestinationFlowspecL3vpnIpv6Builder()
43                     .setRouteDistinguisher(rd)
44                     .setFlowspec(flowspecList)
45                     .setPathId(pathId)
46                     .build()
47             ).build();
48     }
49
50     @Override
51     public DestinationType createAdvertizedRoutesDestinationType(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId) {
52         final RouteDistinguisher rd = (RouteDistinguisher) nlriFields[0];
53         final List<Flowspec> flowspecList = (List<Flowspec>) nlriFields[1];
54         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv6CaseBuilder()
55             .setDestinationFlowspecL3vpnIpv6(
56                 new DestinationFlowspecL3vpnIpv6Builder()
57                     .setRouteDistinguisher(rd)
58                     .setFlowspec(flowspecList)
59                     .setPathId(pathId)
60                     .build()
61             ).build();
62     }
63
64     @Override
65     public void extractSpecificFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
66         FlowspecIpv6NlriParserHelper.extractFlowspec(fsType, fsBuilder);
67     }
68
69     @Override
70     protected void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer) {
71         FlowspecIpv6NlriParserHelper.buildFlowspecString(value, buffer);
72     }
73
74     @Override
75     protected void serializeMpReachNlri(final DestinationType dstType, final ByteBuf byteAggregator) {
76         if (dstType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv6Case) {
77             final DestinationFlowspecL3vpnIpv6 destFlowspec = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv6Case) dstType)
78                 .getDestinationFlowspecL3vpnIpv6();
79             serializeNlri(
80                 new Object[] {
81                     destFlowspec.getRouteDistinguisher(),
82                     destFlowspec.getFlowspec()
83                 },
84                 destFlowspec.getPathId(),
85                 byteAggregator
86             );
87         }
88     }
89
90     @Override
91     protected void serializeMpUnreachNlri(final DestinationType dstType, final ByteBuf byteAggregator) {
92         if (dstType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6Case) {
93             final DestinationFlowspecL3vpnIpv6 destFlowspec = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6Case) dstType)
94                 .getDestinationFlowspecL3vpnIpv6();
95             serializeNlri(
96                 new Object[] {
97                     destFlowspec.getRouteDistinguisher(),
98                     destFlowspec.getFlowspec()
99                 },
100                 destFlowspec.getPathId(),
101                 byteAggregator
102             );
103         }
104     }
105 }