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.evpn.impl;
11 * TODO: Remove, instead use Common Rib Support test
13 public class EvpnRibSupportTest {
15 private static final NodeIdentifier RD_NID = NodeIdentifier.create(QName.create(EvpnChoice.QNAME, "route-distinguisher").intern());
16 private static final NodeIdentifier ROUTES_NODE_ID = new NodeIdentifier(Routes.QNAME);
17 private static final Ipv4Address ipv4 = new Ipv4Address("42.42.42.42");
18 private static final NodeIdentifier DESTINATION_NID = NodeIdentifier.create(EvpnDestination.QNAME);
19 private final EvpnRibSupport evpnRibSupport = EvpnRibSupport.getInstance();
20 private final List<MapEntryNode> evpnList = new ArrayList<>();
21 private List<YangInstanceIdentifier> routes;
23 private DOMDataWriteTransaction tx;
27 MockitoAnnotations.initMocks(this);
28 routes = new ArrayList<>();
29 Mockito.doAnswer(new Answer<Object>() {
31 public Object answer(final InvocationOnMock invocation) throws Throwable {
32 final Object[] args = invocation.getArguments();
33 EvpnRibSupportTest.this.routes.add((YangInstanceIdentifier) args[1]);
36 }).when(this.tx).put(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
38 Mockito.doAnswer(new Answer<Object>() {
40 public Object answer(final InvocationOnMock invocation) throws Throwable {
41 final Object[] args = invocation.getArguments();
42 EvpnRibSupportTest.this.routes.remove(args[1]);
45 }).when(this.tx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class));
50 public void testbuildReach() throws BGPParsingException {
51 final CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(ipv4).build()).build();
52 final MpReachNlri result = evpnRibSupport.buildReach(evpnList, hop);
53 assertEquals(L2vpnAddressFamily.class, result.getAfi());
54 assertEquals(EvpnSubsequentAddressFamily.class, result.getSafi());
55 assertEquals(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("42.42.42.42")).build()).build(), result.getCNextHop());
59 public void testBuildUnreach() {
60 final MpUnreachNlri result = evpnRibSupport.buildUnreach(evpnList);
61 assertEquals(L2vpnAddressFamily.class, result.getAfi());
62 assertEquals(EvpnSubsequentAddressFamily.class, result.getSafi());
66 public void testDestRoutesEthADRModel() {
67 ESIActivator.registerEsiTypeParsers(new ArrayList<>());
68 NlriActivator.registerNlriParsers(new ArrayList<>());
70 final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create();
71 evpnBI.withNodeIdentifier(EVPN_NID);
72 evpnBI.withChild(EthADRParserTest.createEthADRModel());
73 evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build());
75 final UnkeyedListNode routes = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(DESTINATION_NID).addChild(evpnBI.build()).build();
76 final ContainerNode destination = ImmutableContainerNodeBuilder.create().addChild(routes).withNodeIdentifier(DESTINATION_NID).build();
77 final ContainerNode attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Attributes.QNAME)).build();
79 final YangInstanceIdentifier yangIdentifier = YangInstanceIdentifier.of(Routes.QNAME);
80 evpnRibSupport.putDestinationRoutes(tx, yangIdentifier, destination, attributes, ROUTES_NODE_ID);
81 Assert.assertEquals(1, this.routes.size());
83 evpnRibSupport.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID);
84 Assert.assertEquals(0, this.routes.size());
88 public void testDestRoutesMacIp() {
89 ESIActivator.registerEsiTypeParsers(new ArrayList<>());
90 NlriActivator.registerNlriParsers(new ArrayList<>());
92 final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create();
93 evpnBI.withNodeIdentifier(EVPN_NID);
94 evpnBI.withChild(createMACIpAdvChoice());
95 evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build());
97 final UnkeyedListNode routes = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(DESTINATION_NID).addChild(evpnBI.build()).build();
98 final ContainerNode destination = ImmutableContainerNodeBuilder.create().addChild(routes).withNodeIdentifier(DESTINATION_NID).build();
99 final ContainerNode attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Attributes.QNAME)).build();
101 final YangInstanceIdentifier yangIdentifier = YangInstanceIdentifier.of(Routes.QNAME);
102 evpnRibSupport.putDestinationRoutes(tx, yangIdentifier, destination, attributes, ROUTES_NODE_ID);
103 Assert.assertEquals(1, this.routes.size());
105 evpnRibSupport.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID);
106 Assert.assertEquals(0, this.routes.size());