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