2 * Copyright (C) 2016, 2017 Red Hat 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.netvirt.elanmanager.tests;
10 import static java.util.Arrays.asList;
11 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
12 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
14 import java.util.List;
15 import java.util.Optional;
16 import javax.inject.Inject;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Ignore;
20 import org.junit.Rule;
21 import org.junit.Test;
22 import org.junit.rules.MethodRule;
23 import org.mockito.Mockito;
24 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
25 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule;
26 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
27 import org.opendaylight.genius.mdsalutil.MDSALUtil;
28 import org.opendaylight.genius.mdsalutil.NwConstants;
29 import org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache;
30 import org.opendaylight.genius.testutils.interfacemanager.TunnelInterfaceDetails;
31 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
32 import org.opendaylight.infrautils.caches.CacheProvider;
33 import org.opendaylight.infrautils.caches.testutils.CacheModule;
34 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
35 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
36 import org.opendaylight.infrautils.jobcoordinator.internal.JobCoordinatorImpl;
37 import org.opendaylight.infrautils.metrics.MetricProvider;
38 import org.opendaylight.infrautils.metrics.testimpl.TestMetricProviderImpl;
39 import org.opendaylight.infrautils.testutils.LogRule;
40 import org.opendaylight.mdsal.binding.testutils.AssertDataObjects;
41 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
42 import org.opendaylight.mdsal.common.api.ReadFailedException;
43 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
44 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
45 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
46 import org.opendaylight.netvirt.elan.cache.ElanInstanceDpnsCache;
47 import org.opendaylight.netvirt.elan.evpn.listeners.ElanMacEntryListener;
48 import org.opendaylight.netvirt.elan.evpn.listeners.EvpnElanInstanceListener;
49 import org.opendaylight.netvirt.elan.evpn.listeners.MacVrfEntryListener;
50 import org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils;
51 import org.opendaylight.netvirt.elan.internal.ElanDpnInterfaceClusteredListener;
52 import org.opendaylight.netvirt.elan.internal.ElanExtnTepConfigListener;
53 import org.opendaylight.netvirt.elan.internal.ElanExtnTepListener;
54 import org.opendaylight.netvirt.elan.internal.ElanInterfaceManager;
55 import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepPhysicalSwitchListener;
56 import org.opendaylight.netvirt.elan.l2gw.listeners.L2GatewayConnectionListener;
57 import org.opendaylight.netvirt.elan.l2gw.listeners.L2GatewayListener;
58 import org.opendaylight.netvirt.elan.l2gw.listeners.LocalUcastMacListener;
59 import org.opendaylight.netvirt.elan.l2gw.nodehandlertest.DataProvider;
60 //import org.opendaylight.netvirt.elan.l2gw.nodehandlertest.PhysicalSwitchHelper;
61 import org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayInstanceRecoveryHandler;
62 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
63 import org.opendaylight.netvirt.elan.utils.ElanUtils;
64 import org.opendaylight.netvirt.elanmanager.api.IElanService;
65 import org.opendaylight.netvirt.elanmanager.api.IL2gwService;
66 import org.opendaylight.netvirt.elanmanager.tests.utils.EvpnTestHelper;
67 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
68 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
69 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
70 import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
71 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp;
72 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksContainer;
73 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks;
74 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey;
75 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
85 //import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global
86 // .attributes.LocalUcastMacs;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
93 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
94 import org.slf4j.Logger;
95 import org.slf4j.LoggerFactory;
99 * End-to-end test of IElanService.
101 * @author Michael Vorburger
102 * @author Riyazahmed Talikoti
104 public class ElanServiceTest extends ElanServiceTestBase {
106 private static final Logger LOG = LoggerFactory.getLogger(ElanServiceTest.class);
108 // TODO as-is, this test is flaky; as uncommenting will show
109 // Uncomment this to keep running this test indefinitely
110 // This is very useful to detect concurrency issues (such as https://bugs.opendaylight.org/show_bug.cgi?id=7538)
111 // public static @ClassRule RunUntilFailureClassRule classRepeater = new RunUntilFailureClassRule();
112 // public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
114 public @Rule LogRule logRule = new LogRule();
115 public @Rule MethodRule guice = new GuiceRule(ElanServiceTestModule.class, JobCoordinatorTestModule.class,
117 // TODO re-enable after we can await completion of listeners and DJC:
118 // Otherwise this too frequently causes spurious test failures, e.g. due to error
119 // logs Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: Operation was interrupted
120 // public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule();
121 private @Inject IElanService elanService;
122 private @Inject IdManagerService idManager;
123 private @Inject EvpnElanInstanceListener evpnElanInstanceListener;
124 private @Inject ElanMacEntryListener elanMacEntryListener;
125 private @Inject MacVrfEntryListener macVrfEntryListener;
126 private @Inject EvpnUtils evpnUtils;
127 private @Inject IBgpManager bgpManager;
128 private @Inject IVpnManager vpnManager;
129 private @Inject EvpnTestHelper evpnTestHelper;
130 private @Inject OdlInterfaceRpcService odlInterfaceRpcService;
131 private @Inject ElanL2GatewayUtils elanL2GatewayUtils;
132 private @Inject ElanInterfaceManager elanInterfaceManager;
133 private @Inject HwvtepPhysicalSwitchListener hwvtepPhysicalSwitchListener;
134 private @Inject L2GatewayConnectionListener l2GatewayConnectionListener;
135 private @Inject LocalUcastMacListener localUcastMacListener;
136 private @Inject ElanDpnInterfaceClusteredListener elanDpnInterfaceClusteredListener;
137 private @Inject EntityOwnershipService mockedEntityOwnershipService;
138 private @Inject L2GatewayCache l2GatewayCache;
139 private @Inject ElanUtils elanUtils;
140 private @Inject ElanInstanceDpnsCache elanInstanceDpnsCache;
141 private @Inject ElanExtnTepConfigListener elanExtnTepConfigListener;
142 private @Inject ElanExtnTepListener elanExtnTepListener;
143 private @Inject CacheProvider cacheProvider;
144 private @Inject L2GatewayInstanceRecoveryHandler l2GatewayInstanceRecoveryHandler;
145 private @Inject ServiceRecoveryRegistry serviceRecoveryRegistry;
147 private L2GatewayListener l2gwListener;
148 private final MetricProvider metricProvider = new TestMetricProviderImpl();
150 private Verifications verifications;
151 private L2gwBuilders l2gwBuilders;
153 private SingleTransactionDataBroker singleTxdataBroker;
155 private InstanceIdDataObjectCache<LogicalSwitches> logicalSwitchCache;
157 @Before public void before() throws Exception {
158 singleTxdataBroker = new SingleTransactionDataBroker(dataBroker);
159 logicalSwitchCache = new InstanceIdDataObjectCache<LogicalSwitches>(
160 LogicalSwitches.class, dataBroker, CONFIGURATION,
161 InstanceIdentifier.builder(NetworkTopology.class)
162 .child(Topology.class, new TopologyKey(new TopologyId(new Uri("hwvtep:1"))))
163 .child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
164 .network.topology.rev131021.network.topology.topology.Node.class)
165 .augmentation(HwvtepGlobalAugmentation.class)
166 .child(LogicalSwitches.class).build(), cacheProvider) {
168 protected void added(InstanceIdentifier<LogicalSwitches> path, LogicalSwitches dataObject) {
171 singleTxdataBroker.syncWrite(OPERATIONAL, path, dataObject);
172 } catch (TransactionCommitFailedException e) {
173 LOG.error("Failed to write to oper ds");
178 verifications = new Verifications(singleTxdataBroker, odlInterfaceRpcService, EXTN_INTFS, getAwaiter());
179 l2gwBuilders = new L2gwBuilders(singleTxdataBroker);
180 JobCoordinator jobCoordinator = new JobCoordinatorImpl(metricProvider);
182 l2gwListener = new L2GatewayListener(dataBroker, mockedEntityOwnershipService,
183 Mockito.mock(ItmRpcService.class), Mockito.mock(IL2gwService.class), jobCoordinator, l2GatewayCache,
184 l2GatewayInstanceRecoveryHandler,serviceRecoveryRegistry);
187 l2gwBuilders.buildTorNode(TOR2_NODE_ID, PS2, TOR2_TEPIP);
188 l2gwBuilders.buildTorNode(TOR1_NODE_ID, PS1, TOR1_TEPIP);
191 @After public void after() throws Exception {
192 for (ResourceBatchingManager.ShardResource i : ResourceBatchingManager.ShardResource.values()) {
193 ResourceBatchingManager.getInstance().deregisterBatchableResource(i.name());
196 ElanL2GwCacheUtils.removeL2GatewayDeviceFromAllElanCache(TOR1_NODE_ID);
197 ElanL2GwCacheUtils.removeL2GatewayDeviceFromAllElanCache(TOR2_NODE_ID);
199 ElanL2GwCacheUtils.removeL2GatewayDeviceFromCache(ExpectedObjects.ELAN1, TOR1_NODE_ID);
200 ElanL2GwCacheUtils.removeL2GatewayDeviceFromCache(ExpectedObjects.ELAN1, TOR2_NODE_ID);
203 @Test public void elanServiceTestModule() {
204 // Intentionally empty; the goal is just to first test the ElanServiceTestModule
207 void createL2gwAndConnection(InstanceIdentifier<Node> nodePath,
211 String connectionName)
212 throws InterruptedException, TransactionCommitFailedException {
215 singleTxdataBroker.syncWrite(LogicalDatastoreType.CONFIGURATION,
216 l2gwBuilders.buildL2gwIid(l2gwName), l2gwBuilders.buildL2gw(l2gwName, deviceName, ports));
217 awaitForData(LogicalDatastoreType.CONFIGURATION, l2gwBuilders.buildL2gwIid(l2gwName));
220 SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
221 l2gwBuilders.buildConnectionIid(connectionName), l2gwBuilders.buildConnection(connectionName,
222 l2gwName, ExpectedObjects.ELAN1, 100));
223 awaitForData(LogicalDatastoreType.CONFIGURATION, l2gwBuilders.buildConnectionIid(connectionName));
227 public void checkSMAC() throws Exception {
228 // Create Elan instance
229 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
230 awaitForElanTag(ExpectedObjects.ELAN1);
232 // Add Elan interface
233 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
234 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
236 // Read Elan instance
237 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
238 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
239 ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
241 // Read and Compare SMAC flow
242 String flowId = new StringBuilder()
243 .append(actualElanInstances.getElanTag())
244 .append(interfaceInfo.getMacAddress())
246 InstanceIdentifier<Flow> flowInstanceIidSrc = getFlowIid(NwConstants.ELAN_SMAC_TABLE,
247 new FlowId(flowId), DPN1_ID);
248 awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidSrc);
250 Flow flowSrc = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidSrc);
251 flowSrc = getFlowWithoutCookie(flowSrc);
253 Flow expected = ExpectedObjects.checkSmac(flowId, interfaceInfo, actualElanInstances);
254 AssertDataObjects.assertEqualBeans(expected, flowSrc);
257 @Test public void checkDmacSameDPN() throws Exception {
258 // Create Elan instance
259 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
260 awaitForElanTag(ExpectedObjects.ELAN1);
262 // Add Elan interface in DPN1
263 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
264 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
266 // Read Elan instance
267 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
268 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
269 ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
271 // Read DMAC Flow in DPN1
272 String flowId = new StringBuilder()
273 .append(actualElanInstances.getElanTag())
274 .append(interfaceInfo.getMacAddress())
276 InstanceIdentifier<Flow> flowInstanceIidDst = getFlowIid(NwConstants.ELAN_DMAC_TABLE,
277 new FlowId(flowId), DPN1_ID);
278 awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidDst);
280 Flow flowDst = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidDst);
281 flowDst = getFlowWithoutCookie(flowDst);
283 Flow expected = ExpectedObjects.checkDmacOfSameDpn(flowId, interfaceInfo, actualElanInstances);
284 AssertDataObjects.assertEqualBeans(getSortedActions(expected), getSortedActions(flowDst));
287 @Test public void checkDmacOfOtherDPN() throws Exception {
288 // Create Elan instance
289 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
290 awaitForElanTag(ExpectedObjects.ELAN1);
292 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
293 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
295 // Read Elan instance
296 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
297 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
298 ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
300 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC1).getLeft();
301 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN2IP1);
303 // Read and Compare DMAC flow in DPN1 for MAC1 of DPN2
304 String flowId = ElanUtils.getKnownDynamicmacFlowRef(actualElanInstances.getElanTag(),
305 interfaceInfo.getMacAddress());
307 InstanceIdentifier<Flow> flowInstanceIidDst = getFlowIid(NwConstants.ELAN_DMAC_TABLE,
308 new FlowId(flowId), DPN1_ID);
309 awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidDst);
311 Flow flowDst = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidDst);
312 flowDst = getFlowWithoutCookie(flowDst);
314 TunnelInterfaceDetails tepDetails = EXTN_INTFS.get(DPN1_ID_STR + ":" + DPN2_ID_STR);
315 Flow expected = ExpectedObjects.checkDmacOfOtherDPN(flowId, interfaceInfo, tepDetails,
316 actualElanInstances);
317 AssertDataObjects.assertEqualBeans(getSortedActions(expected), getSortedActions(flowDst));
320 @Test public void checkEvpnAdvRT2() throws Exception {
321 createElanInstanceAndInterfaceAndAttachEvpn();
324 AssertDataObjects.assertEqualBeans(
325 ExpectedObjects.checkEvpnAdvertiseRoute(ELAN1_SEGMENT_ID, DPN1MAC1, DPN1_TEPIP, DPN1IP1, RD),
326 readBgpNetworkFromDS(DPN1IP1));
329 /* @Test public void checkEvpnAdvRT2NewInterface() throws Exception {
330 createElanInstanceAndInterfaceAndAttachEvpn();
332 // Add Elan interface
333 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
335 AssertDataObjects.assertEqualBeans(
336 ExpectedObjects.checkEvpnAdvertiseRoute(ELAN1_SEGMENT_ID, DPN1MAC2, DPN1_TEPIP, DPN1IP2, RD),
337 readBgpNetworkFromDS(DPN1IP2));
340 /* @Test public void checkEvpnWithdrawRT2DelIntf() throws Exception {
341 createElanInstanceAndInterfaceAndAttachEvpn();
343 InstanceIdentifier<Networks> iid = evpnTestHelper.buildBgpNetworkIid(DPN1IP1);
344 awaitForData(LogicalDatastoreType.CONFIGURATION, iid);
346 evpnTestHelper.deleteRdtoNetworks();
348 deleteElanInterface(ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft());
349 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, iid);
352 /* @Test public void checkEvpnWithdrawRouteDetachEvpn() throws Exception {
353 createElanInstanceAndInterfaceAndAttachEvpn();
354 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
356 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
357 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
359 evpnTestHelper.detachEvpnToNetwork(ExpectedObjects.ELAN1);
361 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
362 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
365 /* @Test public void checkEvpnInstalDmacFlow() throws Exception {
366 createElanInstanceAndInterfaceAndAttachEvpn();
367 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
369 // Verify advertise RT2 route success for both MAC's
370 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
371 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
373 // RT2 received from Peer
374 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC1, EVPNRECVIP1);
375 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC2, EVPNRECVIP2);
377 // verify successful installation of DMAC flow for recvd rt2
378 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC1));
379 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC2));
382 @Test public void checkEvpnUnInstalDmacFlow() throws Exception {
383 createElanInstanceAndInterfaceAndAttachEvpn();
384 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
386 // Verify advertise RT2 route success for both MAC's
387 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
388 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
390 // RT2 received from Peer
391 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC1, EVPNRECVIP1);
392 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC2, EVPNRECVIP2);
394 // verify successful installation of DMAC flow for recvd rt2
395 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC1));
396 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC2));
398 // withdraw RT2 received from Peer
399 evpnTestHelper.deleteMacVrfEntryToDS(RD, EVPNRECVMAC1);
400 evpnTestHelper.deleteMacVrfEntryToDS(RD, EVPNRECVMAC2);
402 // verify successful un-installation of DMAC flow for recvd rt2
403 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC1));
404 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC2));
407 public void createElanInstanceAndInterfaceAndAttachEvpn() throws ReadFailedException,
408 TransactionCommitFailedException {
409 // Create Elan instance
410 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
411 awaitForElanTag(ExpectedObjects.ELAN1);
413 // Read Elan Instance
414 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
415 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
416 ElanInstance elanInstance = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
418 // Add Elan interface
419 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft(), DPN1IP1);
421 // Attach EVPN to networks
422 evpnTestHelper.attachEvpnToNetwork(elanInstance);
425 public Networks readBgpNetworkFromDS(String prefix) throws ReadFailedException {
426 InstanceIdentifier<Networks> iid = InstanceIdentifier.builder(Bgp.class)
427 .child(NetworksContainer.class)
428 .child(Networks.class, new NetworksKey(prefix, RD))
430 awaitForData(LogicalDatastoreType.CONFIGURATION, iid);
432 return singleTxdataBroker.syncRead(CONFIGURATION, iid);
435 private void awaitForElanTag(String elanName) {
436 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
437 .child(ElanInstance.class, new ElanInstanceKey(elanName)).build();
438 getAwaiter().until(() -> {
439 Optional<ElanInstance> elanInstance = MDSALUtil.read(dataBroker, CONFIGURATION, elanInstanceIid);
440 return elanInstance.isPresent() && elanInstance.get().getElanTag() != null;
444 public void verifyL2gw1Connection() throws Exception {
447 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
448 awaitForElanTag(ExpectedObjects.ELAN1);
450 //Add Elan MAC1, MAC2 in DPN1
451 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
452 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
453 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft();
454 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP2);
456 //Add Elan MAC1, MAC2 in DPN2
457 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC1).getLeft();
458 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN2IP1);
459 verifications.verifyLocalBcGroup(DPN2_ID, 1);
461 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC2).getLeft();
462 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN2IP2);
463 verifications.verifyLocalBcGroup(DPN2_ID, 2);
465 createL2gwAndConnection(TOR1_NODE_IID, L2GW1, PS1, DataProvider.getPortNameListD1(), L2GW_CONN1);
467 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP));
468 verifications.verifyThatUcastCreated(TOR1_NODE_IID, asList(DPN1MAC1, DPN1MAC2, DPN2MAC1, DPN2MAC2));
469 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID), asList(TOR1_TEPIP));
470 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID), asList(TOR1_TEPIP));
474 public void verifyL2gwPreProvisioning() throws Exception {
476 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
477 awaitForElanTag(ExpectedObjects.ELAN1);
479 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft(), DPN1IP1);
481 singleTxdataBroker.syncDelete(OPERATIONAL, TOR1_NODE_IID);
482 singleTxdataBroker.syncDelete(OPERATIONAL,
483 PhysicalSwitchHelper.getPhysicalSwitchInstanceIdentifier(TOR1_NODE_IID, PS1));
485 createL2gwAndConnection(TOR1_NODE_IID, L2GW1, PS1, DataProvider.getPortNameListD1(), L2GW_CONN1);
487 l2gwBuilders.buildTorNode(TOR1_NODE_ID, PS1, TOR1_TEPIP);
489 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID, asList(DPN1_TEPIP));
490 verifications.verifyThatUcastCreated(TOR1_NODE_IID, asList(DPN1MAC1));
493 public void verifyL2gwMac1InDpns() throws Exception {
494 verifyL2gw1Connection();
495 l2gwBuilders.createLocalUcastMac(TOR1_NODE_IID, TOR1_MAC1, TOR1_IP1, TOR1_TEPIP);
496 verifications.verifyThatDmacFlowOfTORCreated(asList(DPN1_ID, DPN2_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
499 public void verifyL2gw2Connection() throws Exception {
500 verifyL2gwMac1InDpns();
501 // TOR Node 2 creation
502 createL2gwAndConnection(TOR2_NODE_IID, L2GW2, PS2, DataProvider.getPortNameListTor2(), L2GW_CONN2);
503 //check for remote mcast mac in tor2 against TEPs of dpn1, dpn2 and dpn3, tor1)
504 verifications.verifyThatMcastMacTepsCreated(TOR2_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP, TOR1_TEPIP));
505 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP, TOR2_TEPIP));
506 verifications.verifyThatUcastCreated(TOR2_NODE_IID, asList(DPN1MAC1, DPN2MAC1, DPN2MAC1, DPN2MAC2, TOR1_MAC1));
510 public void verifyL2gwMac2InTors() throws Exception {
511 verifyL2gw2Connection();
512 l2gwBuilders.createLocalUcastMac(TOR1_NODE_IID, TOR1_MAC2, TOR1_IP2, TOR1_TEPIP);
513 verifications.verifyThatUcastCreated(TOR2_NODE_IID, asList(TOR1_MAC2));
517 public void verifyL2gwMacDeleteInTors() throws Exception {
518 verifyL2gwMac2InTors();
519 LocalUcastMacs localUcastMacs1 = l2gwBuilders.createLocalUcastMac(
520 TOR1_NODE_IID, TOR1_MAC1, TOR1_IP1, TOR1_TEPIP);
521 singleTxdataBroker.syncDelete(LogicalDatastoreType.OPERATIONAL,
522 l2gwBuilders.buildMacIid(TOR1_NODE_IID, localUcastMacs1));
523 verifications.verifyThatDmacFlowOfTORDeleted(asList(DPN1_ID, DPN2_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
524 verifications.verifyThatUcastDeleted(TOR2_NODE_IID, asList(TOR1_MAC1));
528 public void verifyAddDpnAfterL2gwConnection() throws Exception {
529 verifyL2gwMac2InTors();
530 //Add Elan MAC1, MAC2 in DPN3
531 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN3MAC1).getLeft();
532 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN3IP1);
534 //bc group of this dpn created
535 verifications.verifyThatDpnGroupUpdated(DPN3_ID, asList(DPN1_ID, DPN2_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
536 //other tors macs be installed in this dpn
537 verifications.verifyThatDmacFlowOfTORCreated(asList(DPN3_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
538 verifications.verifyThatDmacOfOtherDpnCreated(DPN3_ID, DPN1_ID, asList(DPN1MAC1, DPN1MAC2));
539 verifications.verifyThatDmacOfOtherDpnCreated(DPN3_ID, DPN2_ID, asList(DPN2MAC1, DPN2MAC2));
541 //bc group of the other dpns be updated
542 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID, DPN3_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
543 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID, DPN3_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
545 //mcast of tor should be updated
546 verifications.verifyThatMcastMacTepsCreated(TOR2_NODE_IID,
547 asList(DPN1_TEPIP, DPN2_TEPIP, DPN3_TEPIP, TOR1_TEPIP));
548 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID,
549 asList(DPN1_TEPIP, DPN2_TEPIP, DPN3_TEPIP, TOR2_TEPIP));
551 //this dpn mac should get installed in other dpns and tors
552 verifications.verifyThatUcastCreated(TOR1_NODE_IID, asList(DPN3MAC1));
553 verifications.verifyThatUcastCreated(TOR2_NODE_IID, asList(DPN3MAC1));
554 verifications.verifyThatDmacOfOtherDpnCreated(DPN1_ID, DPN3_ID, asList(DPN3MAC1));
555 verifications.verifyThatDmacOfOtherDpnCreated(DPN2_ID, DPN3_ID, asList(DPN3MAC1));
559 @Ignore("Ignoring for Neon MRI")
560 public void verifyDeleteDpnAfterL2gwConnection() throws Exception {
561 //verifyAddDpnAfterL2gwConnection();
562 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN3MAC1).getLeft();
563 deleteElanInterface(interfaceInfo);
565 //clean up of group of this dpn3
566 verifications.verifyThatDpnGroupDeleted(DPN3_ID);
567 //clean up dmacs of this dpn3
568 verifications.verifyThatDmacFlowOfTORDeleted(asList(DPN3_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
569 verifications.verifyThatDmacOfOtherDPNDeleted(DPN3_ID, DPN1_ID, asList(DPN1MAC1, DPN1MAC2));
570 verifications.verifyThatDmacOfOtherDPNDeleted(DPN3_ID, DPN2_ID, asList(DPN2MAC1, DPN2MAC2));
572 //clean up of dmacs in the other dpns
573 verifications.verifyThatDmacOfOtherDPNDeleted(DPN1_ID, DPN3_ID, asList(DPN3MAC1));
574 verifications.verifyThatDmacOfOtherDPNDeleted(DPN2_ID, DPN3_ID, asList(DPN3MAC1));
576 //cleanup of bc group of other dpns
577 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
578 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
580 //dpn tep should be removed from tors
581 verifications.verifyThatMcastMacTepsDeleted(TOR2_NODE_IID, asList(DPN3_TEPIP));
582 verifications.verifyThatMcastMacTepsDeleted(TOR2_NODE_IID, asList(DPN3_TEPIP));
584 //dpn mac should be removed from tors
585 verifications.verifyThatUcastDeleted(TOR1_NODE_IID, asList(DPN3MAC1));
586 verifications.verifyThatUcastDeleted(TOR2_NODE_IID, asList(DPN3MAC1));
590 public void verifyDeleteL2gw1Connection() throws Exception {
591 verifyL2gw2Connection();
592 //delete tor1 l2gw connection
593 l2gwBuilders.deletel2GWConnection(L2GW_CONN1);
595 //deleted tors mcast & cast be cleared
596 verifications.verifyThatMcastMacTepsDeleted(TOR1_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP, TOR2_TEPIP));
597 verifications.verifyThatUcastDeleted(TOR1_NODE_IID, asList(DPN1MAC1, DPN1MAC2, DPN2MAC1, DPN2MAC2));
599 //mcast of other tor be updated
600 verifications.verifyThatMcastMacTepsDeleted(TOR2_NODE_IID, asList(TOR1_TEPIP));
602 //ucast of deleted to be deleted in other tor
603 verifications.verifyThatUcastDeleted(TOR2_NODE_IID, asList(TOR1_MAC1));
605 //group of dpns be udpated
606 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID), asList(TOR2_NODE_ID));
607 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID), asList(TOR2_NODE_ID));
609 //ucast of deleted tor be deleted in other dpns
610 verifications.verifyThatDmacFlowOfTORDeleted(asList(DPN1_ID, DPN2_ID), TOR1_NODE_IID, asList(TOR1_MAC1));