2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.flowspec;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
14 import com.google.common.collect.ImmutableSet;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.List;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
22 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
23 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6Builder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRoute;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRouteBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRouteKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6Routes;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6RoutesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6CaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 import org.opendaylight.yangtools.yang.common.QName;
48 import org.opendaylight.yangtools.yang.common.Uint32;
49 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
50 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
51 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
52 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
54 public class FlowspecIpv6RIBSupportTest extends AbstractRIBSupportTest<FlowspecIpv6RoutesCase, FlowspecIpv6Routes,
55 FlowspecRoute, FlowspecRouteKey> {
57 private static final PathId PATH_ID = new PathId(Uint32.ONE);
58 private static final DestinationIpv6PrefixCase DEST_PREFIX = new DestinationIpv6PrefixCaseBuilder()
59 .setDestinationPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build();
60 private static final List<Flowspec> FLOW_LIST = Collections.singletonList(new FlowspecBuilder()
61 .setFlowspecType(DEST_PREFIX).build());
62 private static final DestinationFlowspecIpv6 DEST_FLOW = new DestinationFlowspecIpv6Builder()
63 .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build();
64 private static final DestinationFlowspecIpv6Case REACH_NLRI = new DestinationFlowspecIpv6CaseBuilder()
65 .setDestinationFlowspecIpv6(DEST_FLOW).build();
66 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
67 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6Case UNREACH_NLRI
68 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
69 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder()
70 .setDestinationFlowspecIpv6(DEST_FLOW).build();
71 private FlowspecRoute route;
72 private FlowspecRouteKey routeKey;
73 private FlowspecIpv6Routes routes;
74 private FlowspecIpv6RIBSupport ribSupport;
77 public void setUp() throws Exception {
79 final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
80 final FlowspecActivator activator = new FlowspecActivator(fsContext);
81 final BGPActivator act = new BGPActivator(activator);
82 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
85 final SimpleFlowspecIpv6NlriParser parser = new SimpleFlowspecIpv6NlriParser(
86 fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
87 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
88 this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST));
89 this.route = new FlowspecRouteBuilder().withKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
90 .setAttributes(new AttributesBuilder().build()).build();
91 this.routes = new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Map.of(this.route.key(), this.route)).build();
92 this.ribSupport = FlowspecIpv6RIBSupport.getInstance(fsContext, this.adapter.currentSerializer());
93 setUpTestCustomizer(this.ribSupport);
97 public void testDeleteRoutes() {
98 this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
99 final InstanceIdentifier<FlowspecRoute> instanceIdentifier = this.deletedRoutes.get(0);
100 assertEquals(this.routeKey, instanceIdentifier.firstKeyOf(FlowspecRoute.class));
104 public void testPutRoutes() {
105 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
106 assertEquals(this.route, this.insertedRoutes.get(0).getValue());
110 public void testEmptyRoute() {
111 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
115 public void testBuildMpUnreachNlriUpdate() {
116 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(),
117 createRoutes(this.routes), ATTRIBUTES);
118 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
119 .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
120 assertNull(update.getAttributes().augmentation(Attributes1.class));
124 public void testBuildMpReachNlriUpdate() {
125 final Update update = this.ribSupport.buildUpdate(createRoutes(this.routes),
126 Collections.emptyList(), ATTRIBUTES);
127 assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
128 .getAdvertizedRoutes().getDestinationType());
129 assertNull(update.getAttributes().augmentation(Attributes2.class));
133 public void testCacheableNlriObjects() {
134 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
138 public void testCacheableAttributeObjects() {
139 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
143 public void testRouteIdAddPath() {
144 assertEquals(this.routeKey, this.ribSupport.createRouteListKey(routeKey.getPathId(), routeKey.getRouteKey()));
148 public void testRoutePath() {
149 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(this.routes);
150 assertEquals(getRoutePath().node(prefixNii),
151 this.ribSupport.routePath(getTablePath(), prefixNii));
155 public void testRouteAttributesIdentifier() {
156 assertEquals(new NodeIdentifier(QName.create(FlowspecIpv6Routes.QNAME,
157 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes
158 .QNAME.getLocalName().intern())),
159 this.ribSupport.routeAttributesIdentifier());
163 public void testRoutesCaseClass() {
164 assertEquals(FlowspecIpv6RoutesCase.class, this.ribSupport.routesCaseClass());
168 public void testRoutesContainerClass() {
169 assertEquals(FlowspecIpv6Routes.class, this.ribSupport.routesContainerClass());
173 public void testRoutesListClass() {
174 assertEquals(FlowspecRoute.class, this.ribSupport.routesListClass());
178 public void testChangedRoutes() {
179 final Routes emptyCase = new FlowspecIpv6RoutesCaseBuilder().build();
180 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
181 createRoutes(emptyCase)).getRootNode();
182 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
184 final Routes emptyRoutes = new FlowspecIpv6RoutesCaseBuilder()
185 .setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder().build()).build();
186 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
187 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
189 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(new FlowspecIpv6RoutesCaseBuilder()
190 .setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder()
191 .setFlowspecRoute(Map.of(this.route.key(), this.route)).build()).build())).getRootNode();
192 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
193 Assert.assertFalse(result.isEmpty());