Provide codec Serializer via RibSupport
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / l3vpn / AbstractFlowspecL3vpnRIBSupport.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;
9
10 import com.google.common.collect.Iterables;
11 import java.util.Collection;
12 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
13 import org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecRIBSupport;
14 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.FlowspecL3vpnSubsequentAddressFamily;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.Identifier;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
26
27 public abstract class AbstractFlowspecL3vpnRIBSupport
28         <T extends AbstractFlowspecL3vpnNlriParser,
29                 C extends Routes & DataObject,
30                 S extends DataObject,
31                 R extends Route,
32                 I extends Identifier>
33         extends AbstractFlowspecRIBSupport<T, C, S, R, I> {
34
35     protected AbstractFlowspecL3vpnRIBSupport(
36             final BindingNormalizedNodeSerializer mappingService,
37             final Class<C> cazeClass,
38             final Class<S> containerClass,
39             final Class<R> listClass,
40             final QName dstContainerClassQName,
41             final Class<? extends AddressFamily> afiClass,
42             final T flowspecNlriParser
43     ) {
44         super(mappingService, cazeClass, containerClass, listClass, afiClass, FlowspecL3vpnSubsequentAddressFamily.class,
45                 dstContainerClassQName, flowspecNlriParser);
46     }
47
48     @Override
49     protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
50         final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
51         final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
52         final RouteDistinguisher rd = extractRouteDistinguisher(routesCont);
53         return this.nlriParser.createAdvertizedRoutesDestinationType(
54                 new Object[]{rd, this.nlriParser.extractFlowspec(routesCont)},
55                 pathId
56         );
57     }
58
59     @Override
60     protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
61         final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
62         final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
63         final RouteDistinguisher rd = extractRouteDistinguisher(routesCont);
64         return this.nlriParser.createWithdrawnDestinationType(
65                 new Object[]{rd, this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))},
66                 pathId
67         );
68     }
69 }