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.EvpnElanInstanceListener;
48 import org.opendaylight.netvirt.elan.evpn.listeners.EvpnElanMacEntryListener;
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.ha.listeners.HAOpClusteredListener;
56 import org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpNodeListener;
57 import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepPhysicalSwitchListener;
58 import org.opendaylight.netvirt.elan.l2gw.listeners.L2GatewayConnectionListener;
59 import org.opendaylight.netvirt.elan.l2gw.listeners.L2GatewayListener;
60 import org.opendaylight.netvirt.elan.l2gw.listeners.L2GwTransportZoneListener;
61 import org.opendaylight.netvirt.elan.l2gw.listeners.LocalUcastMacListener;
62 import org.opendaylight.netvirt.elan.l2gw.nodehandlertest.DataProvider;
63 //import org.opendaylight.netvirt.elan.l2gw.nodehandlertest.PhysicalSwitchHelper;
64 import org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayInstanceRecoveryHandler;
65 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
66 import org.opendaylight.netvirt.elan.l2gw.utils.L2gwZeroDayConfigUtil;
67 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
68 import org.opendaylight.netvirt.elan.utils.ElanUtils;
69 import org.opendaylight.netvirt.elanmanager.api.IElanService;
70 import org.opendaylight.netvirt.elanmanager.api.IL2gwService;
71 import org.opendaylight.netvirt.elanmanager.tests.utils.EvpnTestHelper;
72 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
73 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
74 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
75 import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
76 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp;
77 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksContainer;
78 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks;
79 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey;
80 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
90 //import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global
91 // .attributes.LocalUcastMacs;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
98 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
99 import org.slf4j.Logger;
100 import org.slf4j.LoggerFactory;
104 * End-to-end test of IElanService.
106 * @author Michael Vorburger
107 * @author Riyazahmed Talikoti
109 public class ElanServiceTest extends ElanServiceTestBase {
111 private static final Logger LOG = LoggerFactory.getLogger(ElanServiceTest.class);
113 // TODO as-is, this test is flaky; as uncommenting will show
114 // Uncomment this to keep running this test indefinitely
115 // This is very useful to detect concurrency issues (such as https://bugs.opendaylight.org/show_bug.cgi?id=7538)
116 // public static @ClassRule RunUntilFailureClassRule classRepeater = new RunUntilFailureClassRule();
117 // public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
119 public @Rule LogRule logRule = new LogRule();
120 public @Rule MethodRule guice = new GuiceRule(ElanServiceTestModule.class, JobCoordinatorTestModule.class,
122 // TODO re-enable after we can await completion of listeners and DJC:
123 // Otherwise this too frequently causes spurious test failures, e.g. due to error
124 // logs Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: Operation was interrupted
125 // public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule();
126 private @Inject IElanService elanService;
127 private @Inject IdManagerService idManager;
128 private @Inject EvpnElanInstanceListener evpnElanInstanceListener;
129 private @Inject EvpnElanMacEntryListener elanMacEntryListener;
130 private @Inject MacVrfEntryListener macVrfEntryListener;
131 private @Inject EvpnUtils evpnUtils;
132 private @Inject IBgpManager bgpManager;
133 private @Inject IVpnManager vpnManager;
134 private @Inject EvpnTestHelper evpnTestHelper;
135 private @Inject OdlInterfaceRpcService odlInterfaceRpcService;
136 private @Inject ElanL2GatewayUtils elanL2GatewayUtils;
137 private @Inject ElanInterfaceManager elanInterfaceManager;
138 private @Inject HwvtepPhysicalSwitchListener hwvtepPhysicalSwitchListener;
139 private @Inject L2GatewayConnectionListener l2GatewayConnectionListener;
140 private @Inject LocalUcastMacListener localUcastMacListener;
141 private @Inject ElanDpnInterfaceClusteredListener elanDpnInterfaceClusteredListener;
142 private @Inject EntityOwnershipService mockedEntityOwnershipService;
143 private @Inject L2GatewayCache l2GatewayCache;
144 private @Inject ElanUtils elanUtils;
145 private @Inject ElanInstanceDpnsCache elanInstanceDpnsCache;
146 private @Inject ElanExtnTepConfigListener elanExtnTepConfigListener;
147 private @Inject ElanExtnTepListener elanExtnTepListener;
148 private @Inject CacheProvider cacheProvider;
149 private @Inject L2GatewayInstanceRecoveryHandler l2GatewayInstanceRecoveryHandler;
150 private @Inject ServiceRecoveryRegistry serviceRecoveryRegistry;
151 private @Inject HAOpNodeListener haOpNodeListener;
152 private @Inject HAOpClusteredListener haOpClusteredListener;
153 private @Inject ElanClusterUtils elanClusterUtils;
154 private @Inject ItmRpcService itmRpcService;
157 private L2GatewayListener l2gwListener;
158 private final MetricProvider metricProvider = new TestMetricProviderImpl();
160 private Verifications verifications;
161 private L2gwBuilders l2gwBuilders;
163 private SingleTransactionDataBroker singleTxdataBroker;
165 private InstanceIdDataObjectCache<LogicalSwitches> logicalSwitchCache;
167 @Before public void before() throws Exception {
168 singleTxdataBroker = new SingleTransactionDataBroker(dataBroker);
169 logicalSwitchCache = new InstanceIdDataObjectCache<LogicalSwitches>(
170 LogicalSwitches.class, dataBroker, CONFIGURATION,
171 InstanceIdentifier.builder(NetworkTopology.class)
172 .child(Topology.class, new TopologyKey(new TopologyId(new Uri("hwvtep:1"))))
173 .child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
174 .network.topology.rev131021.network.topology.topology.Node.class)
175 .augmentation(HwvtepGlobalAugmentation.class)
176 .child(LogicalSwitches.class).build(), cacheProvider) {
178 protected void added(InstanceIdentifier<LogicalSwitches> path, LogicalSwitches dataObject) {
181 singleTxdataBroker.syncWrite(OPERATIONAL, path, dataObject);
182 } catch (TransactionCommitFailedException e) {
183 LOG.error("Failed to write to oper ds");
188 verifications = new Verifications(singleTxdataBroker, odlInterfaceRpcService, EXTN_INTFS, getAwaiter());
189 l2gwBuilders = new L2gwBuilders(singleTxdataBroker);
190 JobCoordinator jobCoordinator = new JobCoordinatorImpl(metricProvider);
192 l2gwListener = new L2GatewayListener(dataBroker,
193 Mockito.mock(IL2gwService.class), l2GatewayCache,
194 haOpNodeListener, haOpClusteredListener, itmRpcService,
195 l2GatewayInstanceRecoveryHandler,
196 serviceRecoveryRegistry,
197 Mockito.mock(L2gwZeroDayConfigUtil.class),
198 Mockito.mock(L2GwTransportZoneListener.class),
202 l2gwBuilders.buildTorNode(TOR2_NODE_ID, PS2, TOR2_TEPIP);
203 l2gwBuilders.buildTorNode(TOR1_NODE_ID, PS1, TOR1_TEPIP);
206 @After public void after() throws Exception {
207 for (ResourceBatchingManager.ShardResource i : ResourceBatchingManager.ShardResource.values()) {
208 ResourceBatchingManager.getInstance().deregisterBatchableResource(i.name());
211 ElanL2GwCacheUtils.removeL2GatewayDeviceFromAllElanCache(TOR1_NODE_ID);
212 ElanL2GwCacheUtils.removeL2GatewayDeviceFromAllElanCache(TOR2_NODE_ID);
214 ElanL2GwCacheUtils.removeL2GatewayDeviceFromCache(ExpectedObjects.ELAN1, TOR1_NODE_ID);
215 ElanL2GwCacheUtils.removeL2GatewayDeviceFromCache(ExpectedObjects.ELAN1, TOR2_NODE_ID);
218 @Test public void elanServiceTestModule() {
219 // Intentionally empty; the goal is just to first test the ElanServiceTestModule
222 void createL2gwAndConnection(InstanceIdentifier<Node> nodePath,
226 String connectionName)
227 throws InterruptedException, TransactionCommitFailedException {
230 singleTxdataBroker.syncWrite(LogicalDatastoreType.CONFIGURATION,
231 l2gwBuilders.buildL2gwIid(l2gwName), l2gwBuilders.buildL2gw(l2gwName, deviceName, ports));
232 awaitForData(LogicalDatastoreType.CONFIGURATION, l2gwBuilders.buildL2gwIid(l2gwName));
235 SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
236 l2gwBuilders.buildConnectionIid(connectionName), l2gwBuilders.buildConnection(connectionName,
237 l2gwName, ExpectedObjects.ELAN1, 100));
238 awaitForData(LogicalDatastoreType.CONFIGURATION, l2gwBuilders.buildConnectionIid(connectionName));
242 public void checkSMAC() throws Exception {
243 // Create Elan instance
244 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
245 awaitForElanTag(ExpectedObjects.ELAN1);
247 // Add Elan interface
248 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
249 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
251 // Read Elan instance
252 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
253 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
254 ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
256 // Read and Compare SMAC flow
257 String flowId = new StringBuilder()
258 .append(actualElanInstances.getElanTag())
259 .append(interfaceInfo.getMacAddress())
261 InstanceIdentifier<Flow> flowInstanceIidSrc = getFlowIid(NwConstants.ELAN_SMAC_TABLE,
262 new FlowId(flowId), DPN1_ID);
263 awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidSrc);
265 Flow flowSrc = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidSrc);
266 flowSrc = getFlowWithoutCookie(flowSrc);
268 Flow expected = ExpectedObjects.checkSmac(flowId, interfaceInfo, actualElanInstances);
269 AssertDataObjects.assertEqualBeans(expected, flowSrc);
272 @Test public void checkDmacSameDPN() throws Exception {
273 // Create Elan instance
274 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
275 awaitForElanTag(ExpectedObjects.ELAN1);
277 // Add Elan interface in DPN1
278 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
279 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
281 // Read Elan instance
282 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
283 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
284 ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
286 // Read DMAC Flow in DPN1
287 String flowId = new StringBuilder()
288 .append(actualElanInstances.getElanTag())
289 .append(interfaceInfo.getMacAddress())
291 InstanceIdentifier<Flow> flowInstanceIidDst = getFlowIid(NwConstants.ELAN_DMAC_TABLE,
292 new FlowId(flowId), DPN1_ID);
293 awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidDst);
295 Flow flowDst = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidDst);
296 flowDst = getFlowWithoutCookie(flowDst);
298 Flow expected = ExpectedObjects.checkDmacOfSameDpn(flowId, interfaceInfo, actualElanInstances);
299 AssertDataObjects.assertEqualBeans(getSortedActions(expected), getSortedActions(flowDst));
302 @Test public void checkDmacOfOtherDPN() throws Exception {
303 // Create Elan instance
304 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
305 awaitForElanTag(ExpectedObjects.ELAN1);
307 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
308 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
310 // Read Elan instance
311 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
312 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
313 ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
315 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC1).getLeft();
316 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN2IP1);
318 // Read and Compare DMAC flow in DPN1 for MAC1 of DPN2
319 String flowId = ElanUtils.getKnownDynamicmacFlowRef(actualElanInstances.getElanTag(),
320 interfaceInfo.getMacAddress());
322 InstanceIdentifier<Flow> flowInstanceIidDst = getFlowIid(NwConstants.ELAN_DMAC_TABLE,
323 new FlowId(flowId), DPN1_ID);
324 awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidDst);
326 Flow flowDst = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidDst);
327 flowDst = getFlowWithoutCookie(flowDst);
329 TunnelInterfaceDetails tepDetails = EXTN_INTFS.get(DPN1_ID_STR + ":" + DPN2_ID_STR);
330 Flow expected = ExpectedObjects.checkDmacOfOtherDPN(flowId, interfaceInfo, tepDetails,
331 actualElanInstances);
332 AssertDataObjects.assertEqualBeans(getSortedActions(expected), getSortedActions(flowDst));
335 @Test public void checkEvpnAdvRT2() throws Exception {
336 createElanInstanceAndInterfaceAndAttachEvpn();
339 AssertDataObjects.assertEqualBeans(
340 ExpectedObjects.checkEvpnAdvertiseRoute(ELAN1_SEGMENT_ID, DPN1MAC1, DPN1_TEPIP, DPN1IP1, RD),
341 readBgpNetworkFromDS(DPN1IP1));
344 @Test public void checkEvpnAdvRT2NewInterface() throws Exception {
345 createElanInstanceAndInterfaceAndAttachEvpn();
347 // Add Elan interface
348 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
350 AssertDataObjects.assertEqualBeans(
351 ExpectedObjects.checkEvpnAdvertiseRoute(ELAN1_SEGMENT_ID, DPN1MAC2, DPN1_TEPIP, DPN1IP2, RD),
352 readBgpNetworkFromDS(DPN1IP2));
355 @Test public void checkEvpnWithdrawRT2DelIntf() throws Exception {
356 createElanInstanceAndInterfaceAndAttachEvpn();
358 InstanceIdentifier<Networks> iid = evpnTestHelper.buildBgpNetworkIid(DPN1IP1);
359 awaitForData(LogicalDatastoreType.CONFIGURATION, iid);
361 evpnTestHelper.deleteRdtoNetworks();
363 deleteElanInterface(ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft());
364 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, iid);
367 /* @Test public void checkEvpnWithdrawRouteDetachEvpn() throws Exception {
368 createElanInstanceAndInterfaceAndAttachEvpn();
369 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
371 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
372 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
374 evpnTestHelper.detachEvpnToNetwork(ExpectedObjects.ELAN1);
376 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
377 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
380 @Test public void checkEvpnInstalDmacFlow() throws Exception {
381 createElanInstanceAndInterfaceAndAttachEvpn();
382 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
384 // Verify advertise RT2 route success for both MAC's
385 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
386 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
388 // RT2 received from Peer
389 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC1, EVPNRECVIP1);
390 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC2, EVPNRECVIP2);
392 // verify successful installation of DMAC flow for recvd rt2
393 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC1));
394 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC2));
399 public void checkEvpnUnInstalDmacFlow() throws Exception {
400 createElanInstanceAndInterfaceAndAttachEvpn();
401 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft(), DPN1IP2);
403 // Verify advertise RT2 route success for both MAC's
404 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP1));
405 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildBgpNetworkIid(DPN1IP2));
407 // RT2 received from Peer
408 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC1, EVPNRECVIP1);
409 evpnTestHelper.handleEvpnRt2Recvd(EVPNRECVMAC2, EVPNRECVIP2);
411 // verify successful installation of DMAC flow for recvd rt2
412 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC1));
413 awaitForData(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC2));
415 // withdraw RT2 received from Peer
416 evpnTestHelper.deleteMacVrfEntryToDS(RD, EVPNRECVMAC1);
417 evpnTestHelper.deleteMacVrfEntryToDS(RD, EVPNRECVMAC2);
419 // verify successful un-installation of DMAC flow for recvd rt2
420 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC1));
421 awaitForDataDelete(LogicalDatastoreType.CONFIGURATION, evpnTestHelper.buildMacVrfEntryIid(EVPNRECVMAC2));
424 public void createElanInstanceAndInterfaceAndAttachEvpn() throws ReadFailedException,
425 TransactionCommitFailedException {
426 // Create Elan instance
427 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
428 awaitForElanTag(ExpectedObjects.ELAN1);
430 // Read Elan Instance
431 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
432 .child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
433 ElanInstance elanInstance = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
435 // Add Elan interface
436 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft(), DPN1IP1);
438 // Attach EVPN to networks
439 evpnTestHelper.attachEvpnToNetwork(elanInstance);
442 public Networks readBgpNetworkFromDS(String prefix) throws ReadFailedException {
443 InstanceIdentifier<Networks> iid = InstanceIdentifier.create(Bgp.class)
444 .child(NetworksContainer.class)
445 .child(Networks.class, new NetworksKey(prefix, RD));
446 awaitForData(LogicalDatastoreType.CONFIGURATION, iid);
448 return singleTxdataBroker.syncRead(CONFIGURATION, iid);
451 private void awaitForElanTag(String elanName) {
452 InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class)
453 .child(ElanInstance.class, new ElanInstanceKey(elanName)).build();
454 getAwaiter().until(() -> {
455 Optional<ElanInstance> elanInstance = MDSALUtil.read(dataBroker, CONFIGURATION, elanInstanceIid);
456 return elanInstance.isPresent() && elanInstance.get().getElanTag() != null;
460 public void verifyL2gw1Connection() throws Exception {
463 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
464 awaitForElanTag(ExpectedObjects.ELAN1);
466 //Add Elan MAC1, MAC2 in DPN1
467 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
468 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
469 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft();
470 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP2);
472 //Add Elan MAC1, MAC2 in DPN2
473 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC1).getLeft();
474 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN2IP1);
475 verifications.verifyLocalBcGroup(DPN2_ID, 1);
477 interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC2).getLeft();
478 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN2IP2);
479 verifications.verifyLocalBcGroup(DPN2_ID, 2);
481 createL2gwAndConnection(TOR1_NODE_IID, L2GW1, PS1, DataProvider.getPortNameListD1(), L2GW_CONN1);
483 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP));
484 verifications.verifyThatUcastCreated(TOR1_NODE_IID, asList(DPN1MAC1, DPN1MAC2, DPN2MAC1, DPN2MAC2));
485 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID), asList(TOR1_TEPIP));
486 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID), asList(TOR1_TEPIP));
490 public void verifyL2gwPreProvisioning() throws Exception {
492 createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
493 awaitForElanTag(ExpectedObjects.ELAN1);
495 addElanInterface(ExpectedObjects.ELAN1, ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft(), DPN1IP1);
497 singleTxdataBroker.syncDelete(OPERATIONAL, TOR1_NODE_IID);
498 singleTxdataBroker.syncDelete(OPERATIONAL,
499 PhysicalSwitchHelper.getPhysicalSwitchInstanceIdentifier(TOR1_NODE_IID, PS1));
501 createL2gwAndConnection(TOR1_NODE_IID, L2GW1, PS1, DataProvider.getPortNameListD1(), L2GW_CONN1);
503 l2gwBuilders.buildTorNode(TOR1_NODE_ID, PS1, TOR1_TEPIP);
505 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID, asList(DPN1_TEPIP));
506 verifications.verifyThatUcastCreated(TOR1_NODE_IID, asList(DPN1MAC1));
509 public void verifyL2gwMac1InDpns() throws Exception {
510 verifyL2gw1Connection();
511 l2gwBuilders.createLocalUcastMac(TOR1_NODE_IID, TOR1_MAC1, TOR1_IP1, TOR1_TEPIP);
512 verifications.verifyThatDmacFlowOfTORCreated(asList(DPN1_ID, DPN2_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
515 public void verifyL2gw2Connection() throws Exception {
516 verifyL2gwMac1InDpns();
517 // TOR Node 2 creation
518 createL2gwAndConnection(TOR2_NODE_IID, L2GW2, PS2, DataProvider.getPortNameListTor2(), L2GW_CONN2);
519 //check for remote mcast mac in tor2 against TEPs of dpn1, dpn2 and dpn3, tor1)
520 verifications.verifyThatMcastMacTepsCreated(TOR2_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP, TOR1_TEPIP));
521 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP, TOR2_TEPIP));
522 verifications.verifyThatUcastCreated(TOR2_NODE_IID, asList(DPN1MAC1, DPN2MAC1, DPN2MAC1, DPN2MAC2, TOR1_MAC1));
526 public void verifyL2gwMac2InTors() throws Exception {
527 verifyL2gw2Connection();
528 l2gwBuilders.createLocalUcastMac(TOR1_NODE_IID, TOR1_MAC2, TOR1_IP2, TOR1_TEPIP);
529 verifications.verifyThatUcastCreated(TOR2_NODE_IID, asList(TOR1_MAC2));
533 public void verifyL2gwMacDeleteInTors() throws Exception {
534 verifyL2gwMac2InTors();
535 LocalUcastMacs localUcastMacs1 = l2gwBuilders.createLocalUcastMac(
536 TOR1_NODE_IID, TOR1_MAC1, TOR1_IP1, TOR1_TEPIP);
537 singleTxdataBroker.syncDelete(LogicalDatastoreType.OPERATIONAL,
538 l2gwBuilders.buildMacIid(TOR1_NODE_IID, localUcastMacs1));
539 verifications.verifyThatDmacFlowOfTORDeleted(asList(DPN1_ID, DPN2_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
540 verifications.verifyThatUcastDeleted(TOR2_NODE_IID, asList(TOR1_MAC1));
544 public void verifyAddDpnAfterL2gwConnection() throws Exception {
545 verifyL2gwMac2InTors();
546 //Add Elan MAC1, MAC2 in DPN3
547 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN3MAC1).getLeft();
548 addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN3IP1);
550 //bc group of this dpn created
551 verifications.verifyThatDpnGroupUpdated(DPN3_ID, asList(DPN1_ID, DPN2_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
552 //other tors macs be installed in this dpn
553 verifications.verifyThatDmacFlowOfTORCreated(asList(DPN3_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
554 verifications.verifyThatDmacOfOtherDpnCreated(DPN3_ID, DPN1_ID, asList(DPN1MAC1, DPN1MAC2));
555 verifications.verifyThatDmacOfOtherDpnCreated(DPN3_ID, DPN2_ID, asList(DPN2MAC1, DPN2MAC2));
557 //bc group of the other dpns be updated
558 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID, DPN3_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
559 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID, DPN3_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
561 //mcast of tor should be updated
562 verifications.verifyThatMcastMacTepsCreated(TOR2_NODE_IID,
563 asList(DPN1_TEPIP, DPN2_TEPIP, DPN3_TEPIP, TOR1_TEPIP));
564 verifications.verifyThatMcastMacTepsCreated(TOR1_NODE_IID,
565 asList(DPN1_TEPIP, DPN2_TEPIP, DPN3_TEPIP, TOR2_TEPIP));
567 //this dpn mac should get installed in other dpns and tors
568 verifications.verifyThatUcastCreated(TOR1_NODE_IID, asList(DPN3MAC1));
569 verifications.verifyThatUcastCreated(TOR2_NODE_IID, asList(DPN3MAC1));
570 verifications.verifyThatDmacOfOtherDpnCreated(DPN1_ID, DPN3_ID, asList(DPN3MAC1));
571 verifications.verifyThatDmacOfOtherDpnCreated(DPN2_ID, DPN3_ID, asList(DPN3MAC1));
575 @Ignore("Ignoring for Neon MRI")
576 public void verifyDeleteDpnAfterL2gwConnection() throws Exception {
577 //verifyAddDpnAfterL2gwConnection();
578 InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN3MAC1).getLeft();
579 deleteElanInterface(interfaceInfo);
581 //clean up of group of this dpn3
582 verifications.verifyThatDpnGroupDeleted(DPN3_ID);
583 //clean up dmacs of this dpn3
584 verifications.verifyThatDmacFlowOfTORDeleted(asList(DPN3_ID), TOR1_NODE_IID, asList(TOR1_MAC1));
585 verifications.verifyThatDmacOfOtherDPNDeleted(DPN3_ID, DPN1_ID, asList(DPN1MAC1, DPN1MAC2));
586 verifications.verifyThatDmacOfOtherDPNDeleted(DPN3_ID, DPN2_ID, asList(DPN2MAC1, DPN2MAC2));
588 //clean up of dmacs in the other dpns
589 verifications.verifyThatDmacOfOtherDPNDeleted(DPN1_ID, DPN3_ID, asList(DPN3MAC1));
590 verifications.verifyThatDmacOfOtherDPNDeleted(DPN2_ID, DPN3_ID, asList(DPN3MAC1));
592 //cleanup of bc group of other dpns
593 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
594 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID), asList(TOR1_NODE_ID, TOR2_NODE_ID));
596 //dpn tep should be removed from tors
597 verifications.verifyThatMcastMacTepsDeleted(TOR2_NODE_IID, asList(DPN3_TEPIP));
598 verifications.verifyThatMcastMacTepsDeleted(TOR2_NODE_IID, asList(DPN3_TEPIP));
600 //dpn mac should be removed from tors
601 verifications.verifyThatUcastDeleted(TOR1_NODE_IID, asList(DPN3MAC1));
602 verifications.verifyThatUcastDeleted(TOR2_NODE_IID, asList(DPN3MAC1));
606 public void verifyDeleteL2gw1Connection() throws Exception {
607 verifyL2gw2Connection();
608 //delete tor1 l2gw connection
609 l2gwBuilders.deletel2GWConnection(L2GW_CONN1);
611 //deleted tors mcast & cast be cleared
612 verifications.verifyThatMcastMacTepsDeleted(TOR1_NODE_IID, asList(DPN1_TEPIP, DPN2_TEPIP, TOR2_TEPIP));
613 verifications.verifyThatUcastDeleted(TOR1_NODE_IID, asList(DPN1MAC1, DPN1MAC2, DPN2MAC1, DPN2MAC2));
615 //mcast of other tor be updated
616 verifications.verifyThatMcastMacTepsDeleted(TOR2_NODE_IID, asList(TOR1_TEPIP));
618 //ucast of deleted to be deleted in other tor
619 verifications.verifyThatUcastDeleted(TOR2_NODE_IID, asList(TOR1_MAC1));
621 //group of dpns be udpated
622 verifications.verifyThatDpnGroupUpdated(DPN1_ID, asList(DPN2_ID), asList(TOR2_NODE_ID));
623 verifications.verifyThatDpnGroupUpdated(DPN2_ID, asList(DPN1_ID), asList(TOR2_NODE_ID));
625 //ucast of deleted tor be deleted in other dpns
626 verifications.verifyThatDmacFlowOfTORDeleted(asList(DPN1_ID, DPN2_ID), TOR1_NODE_IID, asList(TOR1_MAC1));