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.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.Collection;
16 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4RIBSupport;
21 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4Builder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRoute;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4Routes;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4RoutesBuilder;
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.DestinationFlowspecL3vpnIpv4Case;
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.DestinationFlowspecL3vpnIpv4CaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdTwoOctetAs;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher;
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.tree.api.DataTreeCandidateNode;
53 import org.opendaylight.yangtools.yang.data.tree.spi.DataTreeCandidates;
55 public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest<FlowspecL3vpnIpv4RoutesCase,
56 FlowspecL3vpnIpv4Routes, FlowspecL3vpnRoute> {
58 private static final FlowspecL3vpnRoute ROUTE;
59 private static final FlowspecL3vpnRouteKey ROUTE_KEY;
60 private static final PathId PATH_ID = new PathId(Uint32.ONE);
61 private static final RouteDistinguisher RD = new RouteDistinguisher(new RdTwoOctetAs("0:5:3"));
62 private static final DestinationPrefixCase DEST_PREFIX = new DestinationPrefixCaseBuilder()
63 .setDestinationPrefix(new Ipv4Prefix("172.17.1.0/24")).build();
64 private static final List<Flowspec> FLOW_LIST = List.of(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build());
65 private static final DestinationFlowspecL3vpnIpv4 DEST_FLOW
66 = new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(RD)
67 .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build();
68 private static final DestinationFlowspecL3vpnIpv4Case REACH_NLRI
69 = new DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(DEST_FLOW).build();
70 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
71 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4Case UNREACH_NLRI
72 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
73 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder()
74 .setDestinationFlowspecL3vpnIpv4(DEST_FLOW).build();
75 private FlowspecL3vpnIpv4RIBSupport ribSupport;
78 ROUTE_KEY = new FlowspecL3vpnRouteKey(PATH_ID,
79 "[l3vpn with route-distinguisher 0:5:3] all packets to 172.17.1.0/24");
80 ROUTE = new FlowspecL3vpnRouteBuilder().withKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
81 .setAttributes(new AttributesBuilder().build()).setRouteDistinguisher(RD).build();
85 public void setUp() throws Exception {
87 ribSupport = new FlowspecL3vpnIpv4RIBSupport(adapter.currentSerializer());
88 setUpTestCustomizer(ribSupport);
92 public void testDeleteRoutes() {
93 ribSupport.deleteRoutes(tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
94 final InstanceIdentifier<FlowspecL3vpnRoute> instanceIdentifier = deletedRoutes.get(0);
95 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecL3vpnRoute.class));
99 public void testPutRoutes() {
100 ribSupport.putRoutes(tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
101 final FlowspecL3vpnRoute route = (FlowspecL3vpnRoute) insertedRoutes.get(0).getValue();
102 assertEquals(ROUTE, route);
106 public void testEmptyRoute() {
107 assertEquals(createEmptyTable(), ribSupport.emptyTable());
111 public void testBuildMpUnreachNlriUpdate() {
112 final Update update = ribSupport.buildUpdate(List.of(), createRoutes(
113 new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Map.of(ROUTE.key(), ROUTE)).build()),
115 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(AttributesUnreach.class)
116 .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
117 assertNull(update.getAttributes().augmentation(AttributesReach.class));
121 public void testBuildMpReachNlriUpdate() {
122 final Update update = ribSupport.buildUpdate(createRoutes(
123 new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Map.of(ROUTE.key(), ROUTE)).build()),
124 List.of(), ATTRIBUTES);
125 final AdvertizedRoutes advertised = update.getAttributes().augmentation(AttributesReach.class).getMpReachNlri()
126 .getAdvertizedRoutes();
127 assertEquals(REACH_NLRI, advertised.getDestinationType());
128 assertNull(update.getAttributes().augmentation(AttributesUnreach.class));
132 public void testCacheableNlriObjects() {
133 assertEquals(Set.of(), ribSupport.cacheableNlriObjects());
137 public void testCacheableAttributeObjects() {
138 assertEquals(Set.of(), ribSupport.cacheableAttributeObjects());
142 public void testRoutePath() {
143 final NodeIdentifierWithPredicates prefixNii
144 = createRouteNIWP(new FlowspecL3vpnIpv4RoutesBuilder()
145 .setFlowspecL3vpnRoute(Map.of(ROUTE.key(), ROUTE)).build());
146 assertEquals(getRoutePath().node(prefixNii),
147 ribSupport.routePath(getTablePath(), prefixNii));
151 public void testRouteAttributesIdentifier() {
152 assertEquals(new NodeIdentifier(QName.create(FlowspecL3vpnIpv4Routes.QNAME,
153 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables
154 .Attributes.QNAME.getLocalName().intern())),
155 ribSupport.routeAttributesIdentifier());
159 public void testRoutesCaseClass() {
160 assertEquals(FlowspecL3vpnIpv4RoutesCase.class, ribSupport.routesCaseClass());
164 public void testRoutesContainerClass() {
165 assertEquals(FlowspecL3vpnIpv4Routes.class, ribSupport.routesContainerClass());
169 public void testRoutesListClass() {
170 assertEquals(FlowspecL3vpnRoute.class, ribSupport.routesListClass());
174 public void testChangedRoutes() {
175 final Routes emptyCase = new FlowspecL3vpnIpv4RoutesCaseBuilder().build();
176 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
177 createRoutes(emptyCase)).getRootNode();
178 assertTrue(ribSupport.changedRoutes(tree).isEmpty());
180 final Routes emptyRoutes = new FlowspecL3vpnIpv4RoutesCaseBuilder()
181 .setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder().build()).build();
182 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
183 assertTrue(ribSupport.changedRoutes(tree).isEmpty());
185 final Routes routes = new FlowspecL3vpnIpv4RoutesCaseBuilder()
186 .setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder()
187 .setFlowspecL3vpnRoute(Map.of(ROUTE.key(), ROUTE)).build()).build();
188 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
189 final Collection<DataTreeCandidateNode> result = ribSupport.changedRoutes(tree);
190 assertFalse(result.isEmpty());