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
8 package org.opendaylight.protocol.bgp.flowspec;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv6.FlowspecL3vpnIpv6RIBSupport;
20 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6Builder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRoute;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6RoutesBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv6Case;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv6CaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdTwoOctetAs;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher;
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;
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 FlowspecL3vpnIpv6RIBSupportTest extends AbstractRIBSupportTest<FlowspecL3vpnIpv6RoutesCase,
54 FlowspecL3vpnIpv6Routes, FlowspecL3vpnRoute, FlowspecL3vpnRouteKey> {
56 private static final FlowspecL3vpnRoute ROUTE;
57 private static final FlowspecL3vpnRouteKey ROUTE_KEY;
58 private static final PathId PATH_ID = new PathId(Uint32.ONE);
59 private static final RouteDistinguisher RD = new RouteDistinguisher(new RdTwoOctetAs("0:5:3"));
60 private static final DestinationIpv6PrefixCase DEST_PREFIX = new DestinationIpv6PrefixCaseBuilder()
61 .setDestinationPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build();
62 private static final List<Flowspec> FLOW_LIST
63 = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build());
64 private static final DestinationFlowspecL3vpnIpv6 DEST_FLOW
65 = new DestinationFlowspecL3vpnIpv6Builder().setRouteDistinguisher(RD)
66 .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build();
67 private static final DestinationFlowspecL3vpnIpv6Case REACH_NLRI
68 = new DestinationFlowspecL3vpnIpv6CaseBuilder().setDestinationFlowspecL3vpnIpv6(DEST_FLOW).build();
69 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
70 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6Case UNREACH_NLRI
71 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
72 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6CaseBuilder()
73 .setDestinationFlowspecL3vpnIpv6(DEST_FLOW).build();
76 ROUTE_KEY = new FlowspecL3vpnRouteKey(PATH_ID,
77 "[l3vpn with route-distinguisher 0:5:3] all packets to 2001:db8:1:2::/64");
78 ROUTE = new FlowspecL3vpnRouteBuilder().withKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
79 .setAttributes(new AttributesBuilder().build()).setRouteDistinguisher(RD).build();
82 private FlowspecL3vpnIpv6RIBSupport ribSupport;
85 public void setUp() throws Exception {
87 this.ribSupport = FlowspecL3vpnIpv6RIBSupport
88 .getInstance(new SimpleFlowspecExtensionProviderContext(), this.mappingService);
89 setUpTestCustomizer(this.ribSupport);
93 public void testDeleteRoutes() {
94 this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
95 final InstanceIdentifier<FlowspecL3vpnRoute> instanceIdentifier = this.deletedRoutes.get(0);
96 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecL3vpnRoute.class));
100 public void testPutRoutes() {
101 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
102 final FlowspecL3vpnRoute route = (FlowspecL3vpnRoute) this.insertedRoutes.get(0).getValue();
103 assertEquals(ROUTE, route);
107 public void testEmptyRoute() {
108 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
112 public void testBuildMpUnreachNlriUpdate() {
113 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(
114 new FlowspecL3vpnIpv6RoutesBuilder()
115 .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), ATTRIBUTES);
116 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
117 .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
118 assertNull(update.getAttributes().augmentation(Attributes1.class));
122 public void testBuildMpReachNlriUpdate() {
123 final Update update = this.ribSupport.buildUpdate(createRoutes(
124 new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()),
125 Collections.emptyList(), ATTRIBUTES);
126 final AdvertizedRoutes advertised
127 = update.getAttributes().augmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes();
128 assertEquals(REACH_NLRI, advertised.getDestinationType());
129 assertNull(update.getAttributes().augmentation(Attributes2.class));
133 public void testCacheableNlriObjects() {
134 Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
138 public void testCacheableAttributeObjects() {
139 Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
143 public void testRouteIdAddPath() {
144 Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId(),
145 ROUTE_KEY.getRouteKey()));
149 public void testRoutePath() {
150 final YangInstanceIdentifier.NodeIdentifierWithPredicates prefixNii
151 = createRouteNIWP(new FlowspecL3vpnIpv6RoutesBuilder()
152 .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build());
153 Assert.assertEquals(getRoutePath().node(prefixNii),
154 this.ribSupport.routePath(getTablePath(), prefixNii));
158 public void testRouteAttributesIdentifier() {
159 Assert.assertEquals(new YangInstanceIdentifier.NodeIdentifier(QName.create(FlowspecL3vpnIpv6Routes.QNAME,
160 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables
161 .Attributes.QNAME.getLocalName().intern())),
162 this.ribSupport.routeAttributesIdentifier());
166 public void testRoutesCaseClass() {
167 Assert.assertEquals(FlowspecL3vpnIpv6RoutesCase.class, this.ribSupport.routesCaseClass());
171 public void testRoutesContainerClass() {
172 Assert.assertEquals(FlowspecL3vpnIpv6Routes.class, this.ribSupport.routesContainerClass());
176 public void testRoutesListClass() {
177 Assert.assertEquals(FlowspecL3vpnRoute.class, this.ribSupport.routesListClass());
181 public void testChangedRoutes() {
182 final Routes emptyCase = new FlowspecL3vpnIpv6RoutesCaseBuilder().build();
183 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
184 createRoutes(emptyCase)).getRootNode();
185 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
187 final Routes emptyRoutes = new FlowspecL3vpnIpv6RoutesCaseBuilder()
188 .setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder().build()).build();
189 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
190 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
192 final Routes routes = new FlowspecL3vpnIpv6RoutesCaseBuilder()
193 .setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder()
194 .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()).build();
195 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
196 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
197 Assert.assertFalse(result.isEmpty());