d15e3f8188fff477881ba1cf3cba15ade18e70a7
[bgpcep.git] / bgp / extensions / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / SimpleFlowspecIpv6NlriParser.java
1 /*
2  * Copyright (c) 2015 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.flowspec;
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.ipv6.FlowspecIpv6NlriParserHelper;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.Flowspec;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.FlowspecBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.ipv6.DestinationFlowspecIpv6;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.ipv6.DestinationFlowspecIpv6Builder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
22 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
23
24 public final class SimpleFlowspecIpv6NlriParser extends AbstractFlowspecNlriParser {
25
26     public SimpleFlowspecIpv6NlriParser(final SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
27         super(flowspecTypeRegistry);
28     }
29
30     @Override
31     public DestinationType createWithdrawnDestinationType(@Nonnull final Object[] nlriFields,
32             @Nullable final PathId pathId) {
33         final List<Flowspec> flowspecList = (List<Flowspec>) nlriFields[0];
34         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update
35                 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder()
36             .setDestinationFlowspecIpv6(
37                 new DestinationFlowspecIpv6Builder()
38                     .setFlowspec(flowspecList)
39                     .setPathId(pathId)
40                     .build()
41             ).build();
42     }
43
44     @Override
45     public DestinationType createAdvertizedRoutesDestinationType(@Nonnull final Object[] nlriFields,
46             @Nullable final PathId pathId) {
47         final List<Flowspec> flowspecList = (List<Flowspec>) nlriFields[0];
48         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update
49                 .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6CaseBuilder()
50             .setDestinationFlowspecIpv6(
51                 new DestinationFlowspecIpv6Builder()
52                     .setFlowspec(flowspecList)
53                     .setPathId(pathId)
54                     .build()
55             ).build();
56     }
57
58     @Override
59     public void extractSpecificFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
60         FlowspecIpv6NlriParserHelper.extractFlowspec(fsType, fsBuilder);
61     }
62
63     @Override
64     protected void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer) {
65         FlowspecIpv6NlriParserHelper.buildFlowspecString(value, buffer);
66     }
67
68     @Override
69     protected void serializeMpReachNlri(final DestinationType dstType, final ByteBuf byteAggregator) {
70         if (dstType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329
71                 .update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case) {
72             final DestinationFlowspecIpv6 destFlowspec = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
73                     .yang.bgp.flowspec.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type
74                     .DestinationFlowspecIpv6Case) dstType).getDestinationFlowspecIpv6();
75             serializeNlri(new Object[] {destFlowspec.getFlowspec()}, destFlowspec.getPathId(), byteAggregator);
76         }
77     }
78
79     @Override
80     protected void serializeMpUnreachNlri(final DestinationType dstType, final ByteBuf byteAggregator) {
81         if (dstType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329
82                 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6Case) {
83             final DestinationFlowspecIpv6 destFlowspec = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
84                     .yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
85                     .DestinationFlowspecIpv6Case) dstType).getDestinationFlowspecIpv6();
86             serializeNlri(new Object[] {destFlowspec.getFlowspec()}, destFlowspec.getPathId(), byteAggregator);
87         }
88     }
89 }
90