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.flowspec.FlowspecTypeRegistries.SAFI;
22 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
23 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
24 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6Builder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRoute;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRouteBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRouteKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6Routes;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6RoutesBuilder;
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.DestinationFlowspecIpv6Case;
40 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;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
47 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
48 import org.opendaylight.yangtools.yang.common.QName;
49 import org.opendaylight.yangtools.yang.common.Uint32;
50 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
51 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
52 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
53 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
55 public class FlowspecIpv6RIBSupportTest extends AbstractRIBSupportTest<FlowspecIpv6RoutesCase, FlowspecIpv6Routes,
56 FlowspecRoute, FlowspecRouteKey> {
58 private static final PathId PATH_ID = new PathId(Uint32.ONE);
59 private static final DestinationIpv6PrefixCase DEST_PREFIX = new DestinationIpv6PrefixCaseBuilder()
60 .setDestinationPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build();
61 private static final List<Flowspec> FLOW_LIST = Collections.singletonList(new FlowspecBuilder()
62 .setFlowspecType(DEST_PREFIX).build());
63 private static final DestinationFlowspecIpv6 DEST_FLOW = new DestinationFlowspecIpv6Builder()
64 .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build();
65 private static final DestinationFlowspecIpv6Case REACH_NLRI = new DestinationFlowspecIpv6CaseBuilder()
66 .setDestinationFlowspecIpv6(DEST_FLOW).build();
67 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
68 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6Case UNREACH_NLRI
69 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
70 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder()
71 .setDestinationFlowspecIpv6(DEST_FLOW).build();
72 private FlowspecRoute route;
73 private FlowspecRouteKey routeKey;
74 private FlowspecIpv6Routes routes;
75 private FlowspecIpv6RIBSupport ribSupport;
78 public void setUp() throws Exception {
80 final BGPActivator act = new BGPActivator();
81 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
84 final SimpleFlowspecIpv6NlriParser parser = new SimpleFlowspecIpv6NlriParser(SAFI.FLOWSPEC);
85 this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST));
86 this.route = new FlowspecRouteBuilder().withKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
87 .setAttributes(new AttributesBuilder().build()).build();
88 this.routes = new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Map.of(this.route.key(), this.route)).build();
89 this.ribSupport = new FlowspecIpv6RIBSupport(this.adapter.currentSerializer());
90 setUpTestCustomizer(this.ribSupport);
94 public void testDeleteRoutes() {
95 this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
96 final InstanceIdentifier<FlowspecRoute> instanceIdentifier = this.deletedRoutes.get(0);
97 assertEquals(this.routeKey, instanceIdentifier.firstKeyOf(FlowspecRoute.class));
101 public void testPutRoutes() {
102 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
103 assertEquals(this.route, this.insertedRoutes.get(0).getValue());
107 public void testEmptyRoute() {
108 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
112 public void testBuildMpUnreachNlriUpdate() {
113 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(),
114 createRoutes(this.routes), ATTRIBUTES);
115 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
116 .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
117 assertNull(update.getAttributes().augmentation(Attributes1.class));
121 public void testBuildMpReachNlriUpdate() {
122 final Update update = this.ribSupport.buildUpdate(createRoutes(this.routes),
123 Collections.emptyList(), ATTRIBUTES);
124 assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
125 .getAdvertizedRoutes().getDestinationType());
126 assertNull(update.getAttributes().augmentation(Attributes2.class));
130 public void testCacheableNlriObjects() {
131 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
135 public void testCacheableAttributeObjects() {
136 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
140 public void testRouteIdAddPath() {
141 assertEquals(this.routeKey, this.ribSupport.createRouteListKey(routeKey.getPathId(), routeKey.getRouteKey()));
145 public void testRoutePath() {
146 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(this.routes);
147 assertEquals(getRoutePath().node(prefixNii),
148 this.ribSupport.routePath(getTablePath(), prefixNii));
152 public void testRouteAttributesIdentifier() {
153 assertEquals(new NodeIdentifier(QName.create(FlowspecIpv6Routes.QNAME,
154 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes
155 .QNAME.getLocalName().intern())),
156 this.ribSupport.routeAttributesIdentifier());
160 public void testRoutesCaseClass() {
161 assertEquals(FlowspecIpv6RoutesCase.class, this.ribSupport.routesCaseClass());
165 public void testRoutesContainerClass() {
166 assertEquals(FlowspecIpv6Routes.class, this.ribSupport.routesContainerClass());
170 public void testRoutesListClass() {
171 assertEquals(FlowspecRoute.class, this.ribSupport.routesListClass());
175 public void testChangedRoutes() {
176 final Routes emptyCase = new FlowspecIpv6RoutesCaseBuilder().build();
177 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
178 createRoutes(emptyCase)).getRootNode();
179 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
181 final Routes emptyRoutes = new FlowspecIpv6RoutesCaseBuilder()
182 .setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder().build()).build();
183 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
184 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
186 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(new FlowspecIpv6RoutesCaseBuilder()
187 .setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder()
188 .setFlowspecRoute(Map.of(this.route.key(), this.route)).build()).build())).getRootNode();
189 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
190 Assert.assertFalse(result.isEmpty());