e0d0f6bfbb8fa950c753f51d8ea6f6719e46299a
[bgpcep.git] / bgp / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / EvpnRibSupportTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.evpn.impl;
9
10 /**
11  * TODO: Remove, instead use Common Rib Support test
12  */
13 public class EvpnRibSupportTest {
14 /*
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;
22     @Mock
23     private DOMDataWriteTransaction tx;
24
25     @Before
26     public void setUp() {
27         MockitoAnnotations.initMocks(this);
28         routes = new ArrayList<>();
29         Mockito.doAnswer(new Answer<Object>() {
30             @Override
31             public Object answer(final InvocationOnMock invocation) throws Throwable {
32                 final Object[] args = invocation.getArguments();
33                 EvpnRibSupportTest.this.routes.add((YangInstanceIdentifier) args[1]);
34                 return args[1];
35             }
36         }).when(this.tx).put(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
37
38         Mockito.doAnswer(new Answer<Object>() {
39             @Override
40             public Object answer(final InvocationOnMock invocation) throws Throwable {
41                 final Object[] args = invocation.getArguments();
42                 EvpnRibSupportTest.this.routes.remove(args[1]);
43                 return args[1];
44             }
45         }).when(this.tx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class));
46     }
47
48
49     @Test
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());
56     }
57
58     @Test
59     public void testBuildUnreach() {
60         final MpUnreachNlri result = evpnRibSupport.buildUnreach(evpnList);
61         assertEquals(L2vpnAddressFamily.class, result.getAfi());
62         assertEquals(EvpnSubsequentAddressFamily.class, result.getSafi());
63     }
64
65     @Test
66     public void testDestRoutesEthADRModel() {
67         ESIActivator.registerEsiTypeParsers(new ArrayList<>());
68         NlriActivator.registerNlriParsers(new ArrayList<>());
69
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());
74
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();
78
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());
82
83         evpnRibSupport.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID);
84         Assert.assertEquals(0, this.routes.size());
85     }
86
87     @Test
88     public void testDestRoutesMacIp() {
89         ESIActivator.registerEsiTypeParsers(new ArrayList<>());
90         NlriActivator.registerNlriParsers(new ArrayList<>());
91
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());
96
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();
100
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());
104
105         evpnRibSupport.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID);
106         Assert.assertEquals(0, this.routes.size());
107     }*/
108 }