2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.genius.itm.tests;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
11 import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertEqualBeans;
13 import com.google.common.util.concurrent.FluentFuture;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.ArrayList;
16 import java.util.List;
18 import java.util.Optional;
19 import javax.inject.Inject;
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Ignore;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.MethodRule;
28 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
29 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorEventsWaiter;
30 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule;
31 import org.opendaylight.genius.datastoreutils.testutils.TestableDataTreeChangeListenerModule;
32 import org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner;
33 import org.opendaylight.genius.itm.globals.ITMConstants;
34 import org.opendaylight.genius.itm.impl.ItmProvider;
35 import org.opendaylight.genius.itm.impl.ItmUtils;
36 import org.opendaylight.genius.itm.tests.xtend.ExpectedDefTransportZoneObjects;
37 import org.opendaylight.genius.itm.tests.xtend.ExpectedTepNotHostedTransportZoneObjects;
38 import org.opendaylight.genius.itm.tests.xtend.ExpectedTransportZoneObjects;
39 import org.opendaylight.infrautils.caches.testutils.CacheModule;
40 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
41 import org.opendaylight.infrautils.testutils.LogRule;
42 import org.opendaylight.mdsal.binding.api.DataBroker;
43 import org.opendaylight.mdsal.common.api.CommitInfo;
44 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfigBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVtepsKey;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Vteps;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.VtepsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.VtepsKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
60 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
61 import org.opendaylight.yangtools.yang.common.Uint64;
64 * Component tests for ITM TEP Auto Config feature.
66 public class ItmTepAutoConfigTest {
68 public @Rule LogRule logRule = new LogRule();
69 // TODO public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule();
70 public @Rule MethodRule guice = new GuiceRule(ItmTestModule.class, TestableDataTreeChangeListenerModule.class,
71 JobCoordinatorTestModule.class, CacheModule.class);
73 TransportZone transportZone;
74 RetryingManagedNewTransactionRunner txRunner;
76 private @Inject DataBroker dataBroker;
77 private @Inject JobCoordinatorEventsWaiter coordinatorEventsWaiter;
78 private @Inject ItmProvider itmProvider;
81 public void start() throws InterruptedException {
82 transportZone = new TransportZoneBuilder().setZoneName(ItmTestConstants.TZ_NAME)
83 .setTunnelType(ItmTestConstants.TUNNEL_TYPE_VXLAN)
84 .withKey(new TransportZoneKey(ItmTestConstants.TZ_NAME))
86 this.txRunner = new RetryingManagedNewTransactionRunner(dataBroker);
89 // Common method created for code-reuse
90 private InstanceIdentifier<TransportZone> processDefTzOnItmConfig(boolean defTzEnabledFlag,
91 String defTzTunnelType) throws Exception {
93 ItmConfig itmConfigObj = null;
94 if (defTzTunnelType != null) {
95 // set def-tz-enabled flag and def-tz-tunnel-type
96 itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(defTzEnabledFlag)
97 .setDefTzTunnelType(defTzTunnelType).build();
99 // set def-tz-enabled flag only
100 itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(defTzEnabledFlag).build();
102 // creates/deletes default-TZ based on def-tz-enabled flag
103 itmProvider.createDefaultTransportZone(itmConfigObj);
104 coordinatorEventsWaiter.awaitEventsConsumption();
106 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
107 ITMConstants.DEFAULT_TRANSPORT_ZONE);
113 public void defTzEnabledFalseConfigTest() throws Exception {
114 InstanceIdentifier<ItmConfig> iid = InstanceIdentifier.create(ItmConfig.class);
116 // set def-tz-enabled flag to false
117 ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(false).build();
119 // write into config DS
121 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.merge(LogicalDatastoreType.CONFIGURATION,
123 coordinatorEventsWaiter.awaitEventsConsumption();
125 // read from config DS
126 boolean defTzEnabled = SingleTransactionDataBroker.syncReadOptional(
127 dataBroker, LogicalDatastoreType.CONFIGURATION, iid).get().isDefTzEnabled();
128 Assert.assertEquals(defTzEnabled, false);
132 public void defTzEnabledTrueConfigTest() throws Exception {
133 InstanceIdentifier<ItmConfig> iid = InstanceIdentifier.create(ItmConfig.class);
134 // set def-tz-enabled flag to true
135 ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(true).build();
137 // write into config DS
138 //txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
139 // tx -> tx.put(iid, itmConfigObj, true));
141 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.merge(LogicalDatastoreType.CONFIGURATION,
142 iid,itmConfigObj)).get();
144 coordinatorEventsWaiter.awaitEventsConsumption();
146 // read from config DS
147 boolean defTzEnabled = SingleTransactionDataBroker.syncReadOptional(
148 dataBroker, LogicalDatastoreType.CONFIGURATION, iid).get().isDefTzEnabled();
149 Assert.assertEquals(defTzEnabled, true);
153 public void defTzCreationTestWithDefTzEnabledTrueAndVxlanTunnelType() throws Exception {
154 // set def-tz-enabled flag to true
155 boolean defTzEnabledFlag = true;
156 // set def-tz-tunnel-type to VXLAN
157 String defTzTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
159 InstanceIdentifier<TransportZone> tzonePath = processDefTzOnItmConfig(defTzEnabledFlag,
161 Assert.assertNotNull(tzonePath);
163 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithVxlanTunnelType(),
164 dataBroker.newReadOnlyTransaction()
165 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
169 public void defTzCreationTestWithDefTzEnabledTrueAndGreTunnelType() throws Exception {
170 // set def-tz-enabled flag to true
171 boolean defTzEnabledFlag = true;
172 // set def-tz-tunnel-type to GRE
173 String defTzTunnelType = ITMConstants.TUNNEL_TYPE_GRE;
175 InstanceIdentifier<TransportZone> tzPath =
176 ItmUtils.getTZInstanceIdentifier(ITMConstants.DEFAULT_TRANSPORT_ZONE);
177 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
178 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
179 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
180 .setTunnelType(TunnelTypeGre.class)
181 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
185 InstanceIdentifier<TransportZone> tzonePath = processDefTzOnItmConfig(defTzEnabledFlag,
187 Assert.assertNotNull(tzonePath);
189 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithGreTunnelType(),
190 dataBroker.newReadOnlyTransaction()
191 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
195 public void defTzCreationFailedTestWithDefTzEnabledFalse() throws Exception {
196 // set def-tz-enabled flag to false
197 boolean defTzEnabledFlag = false;
198 // set def-tz-tunnel-type to GRE
199 String defTzTunnelType = null;
201 InstanceIdentifier<TransportZone> tzonePath = processDefTzOnItmConfig(defTzEnabledFlag,
203 Assert.assertNotNull(tzonePath);
205 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
206 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get());
210 public void defTzRecreationTestOnTunnelTypeChange() throws Exception {
211 // set def-tz-enabled flag to true
212 boolean defTzEnabledFlag = true;
213 // set def-tz-tunnel-type to VXLAN
214 String defTzTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
216 InstanceIdentifier<TransportZone> tzPath =
217 ItmUtils.getTZInstanceIdentifier(ITMConstants.DEFAULT_TRANSPORT_ZONE);
218 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
219 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
220 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
221 .setTunnelType(TunnelTypeVxlan.class)
222 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
225 InstanceIdentifier<TransportZone> tzonePath = processDefTzOnItmConfig(defTzEnabledFlag,
227 Assert.assertNotNull(tzonePath);
229 // check default-TZ is created with VXLAN tunnel type
230 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithVxlanTunnelType().getTunnelType(),
231 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, tzonePath)
232 .get().get().getTunnelType());
234 // now, change def-tz-tunnel-type to GRE
235 defTzTunnelType = ITMConstants.TUNNEL_TYPE_GRE;
238 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
239 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
240 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
241 .setTunnelType(TunnelTypeGre.class)
242 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
246 tzonePath = processDefTzOnItmConfig(defTzEnabledFlag, defTzTunnelType);
247 Assert.assertNotNull(tzonePath);
249 // check default-TZ is re-created with GRE tunnel type
250 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithGreTunnelType().getTunnelType(),
251 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, tzonePath)
252 .get().get().getTunnelType());
256 public void defTzDeletionTest() throws Exception {
257 // wait for start-up default-TZ creation task to get over
258 coordinatorEventsWaiter.awaitEventsConsumption();
260 // create default-TZ first by setting def-tz-enabled flag to true
261 ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(true)
262 .setDefTzTunnelType(ITMConstants.TUNNEL_TYPE_GRE).build();
264 // creates/deletes default-TZ based on def-tz-enabled flag
265 itmProvider.createDefaultTransportZone(itmConfigObj);
266 coordinatorEventsWaiter.awaitEventsConsumption();
268 InstanceIdentifier<TransportZone> tzPath =
269 ItmUtils.getTZInstanceIdentifier(ITMConstants.DEFAULT_TRANSPORT_ZONE);
270 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
271 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
272 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
273 .setTunnelType(TunnelTypeGre.class)
274 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
277 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
278 ITMConstants.DEFAULT_TRANSPORT_ZONE);
279 Assert.assertNotNull(tzonePath);
281 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithGreTunnelType(),
282 dataBroker.newReadOnlyTransaction()
283 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
285 // now delete default-TZ first by setting def-tz-enabled flag to false
286 itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(false).build();
288 // creates/deletes default-TZ based on def-tz-enabled flag
289 itmProvider.createDefaultTransportZone(itmConfigObj);
290 coordinatorEventsWaiter.awaitEventsConsumption();
292 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
293 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get());
297 public void testAddDeleteTepForDefTz() throws Exception {
298 // wait for start-up default-TZ creation task to get over
299 coordinatorEventsWaiter.awaitEventsConsumption();
301 InstanceIdentifier<TransportZone> tzPath =
302 ItmUtils.getTZInstanceIdentifier(ITMConstants.DEFAULT_TRANSPORT_ZONE);
303 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
304 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
305 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
306 .setTunnelType(TunnelTypeVxlan.class)
307 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
310 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
311 ITMConstants.DEFAULT_TRANSPORT_ZONE);
312 Assert.assertNotNull(tzonePath);
314 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
316 // add TEP into default-TZ
317 ListenableFuture<Void> futures =
318 ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.DEF_TZ_TEP_IP,
319 ItmTestConstants.DEF_BR_DPID,
320 ITMConstants.DEFAULT_TRANSPORT_ZONE, false, dataBroker, txRunner);
323 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
324 ITMConstants.DEFAULT_TRANSPORT_ZONE, ItmTestConstants.INT_DEF_BR_DPID,
325 ITMConstants.DUMMY_PORT);
326 Assert.assertNotNull(vtepPath);
328 // check TEP is added into default-TZ
329 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithTep(), dataBroker.newReadOnlyTransaction()
330 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
332 // remove tep from default-TZ
333 futures = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.DEF_TZ_TEP_IP, ItmTestConstants.DEF_BR_DPID,
334 ITMConstants.DEFAULT_TRANSPORT_ZONE, dataBroker, txRunner);
337 // check TEP is deleted from default-TZ
338 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
339 .read(LogicalDatastoreType.CONFIGURATION, vtepPath).get());
343 public void testAddDeleteTepForTz() throws Exception {
344 // wait for start-up default-TZ creation task to get over
345 coordinatorEventsWaiter.awaitEventsConsumption();
347 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
348 ItmTestConstants.TZ_NAME);
349 Assert.assertNotNull(tzonePath);
352 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
353 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
354 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
356 // check TZ is created with correct TZ name
357 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
358 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get().getZoneName());
361 ListenableFuture<Void> futures = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NB_TZ_TEP_IP,
362 ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, false, dataBroker, txRunner);
365 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
367 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
368 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_DEF_BR_DPID, ITMConstants.DUMMY_PORT);
369 Assert.assertNotNull(vtepPath);
371 // check TEP is added into TZ that is already created.
372 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(),
373 dataBroker.newReadOnlyTransaction()
374 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
377 futures = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.NB_TZ_TEP_IP, ItmTestConstants.DEF_BR_DPID,
378 ItmTestConstants.TZ_NAME, dataBroker, txRunner);
381 // check TEP is deleted
382 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
383 .read(LogicalDatastoreType.CONFIGURATION, vtepPath).get());
385 // for safe side, check TZ is present
386 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
387 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get().getZoneName());
391 public void tepAddDeleteFromDefTzViaSouthboundTest() throws Exception {
392 // wait for start-up default-TZ creation task to get over
393 coordinatorEventsWaiter.awaitEventsConsumption();
395 String tepIp = ItmTestConstants.DEF_TZ_TEP_IP;
396 // create Network topology node with tep-ip set into ExternalIds list
397 // OvsdbNodeListener would be automatically listen on Node to add TEP
398 ConnectionInfo connInfo = OvsdbTestUtil.getConnectionInfo(ItmTestConstants.OVSDB_CONN_PORT,
399 ItmTestConstants.LOCALHOST_IP);
400 FluentFuture<? extends @NonNull CommitInfo> future =
401 OvsdbTestUtil.createNode(connInfo,tepIp,ITMConstants.DEFAULT_TRANSPORT_ZONE,dataBroker);
404 InstanceIdentifier<TransportZone> tzPath =
405 ItmUtils.getTZInstanceIdentifier(ITMConstants.DEFAULT_TRANSPORT_ZONE);
406 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
407 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
408 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
409 .setTunnelType(ItmTestConstants.TUNNEL_TYPE_VXLAN)
410 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
414 // add bridge into node
415 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.DEF_BR_NAME,
416 ItmTestConstants.DEF_BR_DPID, dataBroker);
418 // wait for OvsdbNodeListener to perform config DS update through transaction
419 coordinatorEventsWaiter.awaitEventsConsumption();
421 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
422 ITMConstants.DEFAULT_TRANSPORT_ZONE);
423 Assert.assertNotNull(tzonePath);
425 // check TEP is added into default-TZ
426 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithTep(),
427 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, tzonePath)
430 // test TEP delete now,
431 // pass tep-ip with NULL value, tep-ip paramtere in external_ids will not be set.
433 future = OvsdbTestUtil.updateNode(connInfo, tepIp, ITMConstants.DEFAULT_TRANSPORT_ZONE,
436 // wait for OvsdbNodeListener to perform config DS update through transaction
437 coordinatorEventsWaiter.awaitEventsConsumption();
439 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
441 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
442 ITMConstants.DEFAULT_TRANSPORT_ZONE, ItmTestConstants.INT_DEF_BR_DPID,
443 ITMConstants.DUMMY_PORT);
444 Assert.assertNotNull(vtepPath);
446 // check TEP is deleted from default-TZ when TEP-Ip is removed from southbound
447 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
448 .read(LogicalDatastoreType.CONFIGURATION, vtepPath).get());
452 public void tepAddDeleteFromNbTzViaSouthboundTest() throws Exception {
453 String tepIp = ItmTestConstants.NB_TZ_TEP_IP;
454 // create Network topology node with tep-ip set into ExternalIds list
455 // OvsdbNodeListener would be automatically listen on Node to add TEP
456 ConnectionInfo connInfo = OvsdbTestUtil.getConnectionInfo(ItmTestConstants.OVSDB_CONN_PORT,
457 ItmTestConstants.LOCALHOST_IP);
458 FluentFuture<? extends @NonNull CommitInfo> future = OvsdbTestUtil.createNode(
459 connInfo, tepIp, ItmTestConstants.TZ_NAME, dataBroker);
462 // create Transport-zone in advance
463 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
464 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
465 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
467 // add bridge into node
468 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.DEF_BR_NAME,
469 ItmTestConstants.DEF_BR_DPID, dataBroker);
471 // wait for OvsdbNodeListener to perform config DS update through transaction
472 coordinatorEventsWaiter.awaitEventsConsumption();
474 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
475 ItmTestConstants.TZ_NAME);
476 Assert.assertNotNull(tzonePath);
478 // check TEP is added into NB configured TZ
479 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(),
480 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, tzonePath)
483 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
485 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
486 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_DEF_BR_DPID, ITMConstants.DUMMY_PORT);
487 Assert.assertNotNull(vtepPath);
489 // test TEP delete now,
490 // pass tep-ip with NULL value, tep-ip paramtere in external_ids will not be set.
492 future = OvsdbTestUtil.updateNode(connInfo, tepIp, ItmTestConstants.TZ_NAME, null, dataBroker);
494 // wait for OvsdbNodeListener to perform config DS update through transaction
495 coordinatorEventsWaiter.awaitEventsConsumption();
497 // check TEP is deleted from default-TZ when TEP-Ip is removed from southbound
498 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
499 .read(LogicalDatastoreType.CONFIGURATION, vtepPath).get());
503 public void tzAddDeleteToNotHostedViaSouthboundTest() throws Exception {
504 // create Network topology node
505 ConnectionInfo connInfo = OvsdbTestUtil.getConnectionInfo(ItmTestConstants.OVSDB_CONN_PORT,
506 ItmTestConstants.LOCALHOST_IP);
507 FluentFuture<? extends @NonNull CommitInfo> future = OvsdbTestUtil.createNode(
508 connInfo, ItmTestConstants.NOT_HOSTED_TZ_TEP_IP, ItmTestConstants.NOT_HOSTED_TZ_NAME,
512 // add bridge into node
513 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.DEF_BR_NAME,
514 ItmTestConstants.NOT_HOSTED_DEF_BR_DPID, dataBroker);
516 // wait for OvsdbNodeListener to perform config DS update through transaction
517 coordinatorEventsWaiter.awaitEventsConsumption();
519 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedtzPath = ItmTepAutoConfigTestUtil
520 .getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
521 Assert.assertNotNull(notHostedtzPath);
524 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects.newTepNotHostedTransportZone(),
525 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
526 notHostedtzPath).get().get());
528 future = OvsdbTestUtil.updateNode(connInfo, ItmTestConstants.NOT_HOSTED_TZ_TEP_IP, null,
529 ItmTestConstants.DEF_BR_NAME, dataBroker);
531 // wait for OvsdbNodeListener to perform config DS update through transaction
532 coordinatorEventsWaiter.awaitEventsConsumption();
534 Assert.assertEquals(Optional.empty(),dataBroker.newReadOnlyTransaction()
535 .read(LogicalDatastoreType.OPERATIONAL, notHostedtzPath).get());
539 public void tepUpdateForTepIpTest() throws Exception {
540 // wait for start-up default-TZ creation task to get over
541 coordinatorEventsWaiter.awaitEventsConsumption();
543 String tepIp = ItmTestConstants.DEF_TZ_TEP_IP;
544 // create Network topology node with tep-ip set into ExternalIds list
545 // OvsdbNodeListener would be automatically listen on Node to add TEP
546 ConnectionInfo connInfo = OvsdbTestUtil.getConnectionInfo(ItmTestConstants.OVSDB_CONN_PORT,
547 ItmTestConstants.LOCALHOST_IP);
548 FluentFuture<? extends @NonNull CommitInfo> future = OvsdbTestUtil.createNode(
549 connInfo, tepIp, ITMConstants.DEFAULT_TRANSPORT_ZONE, dataBroker);
552 InstanceIdentifier<TransportZone> tzPath =
553 ItmUtils.getTZInstanceIdentifier(ITMConstants.DEFAULT_TRANSPORT_ZONE);
554 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
555 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath,
556 new TransportZoneBuilder().setZoneName(ITMConstants.DEFAULT_TRANSPORT_ZONE)
557 .setTunnelType(ItmTestConstants.TUNNEL_TYPE_VXLAN)
558 .withKey(new TransportZoneKey(ITMConstants.DEFAULT_TRANSPORT_ZONE))
561 // add bridge into node
562 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.DEF_BR_NAME,
563 ItmTestConstants.DEF_BR_DPID, dataBroker);
565 // wait for OvsdbNodeListener to perform config DS update through transaction
566 coordinatorEventsWaiter.awaitEventsConsumption();
567 //Thread.sleep(5000);
569 // iid for default-TZ
570 InstanceIdentifier<TransportZone> defTzonePath = ItmTepAutoConfigTestUtil.getTzIid(
571 ITMConstants.DEFAULT_TRANSPORT_ZONE);
572 Assert.assertNotNull(defTzonePath);
575 // check TEP is added into default-TZ
577 /*if (dataBroker != null)
579 String errMsg = "present db :" + dataBroker.newReadOnlyTransaction()
580 .read(LogicalDatastoreType.CONFIGURATION, defTzonePath);
581 throw new NullPointerException(errMsg);
585 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithTep(),
586 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, defTzonePath)
589 // update OVSDB node with tep-ip in local_ip list
590 tepIp = ItmTestConstants.NB_TZ_TEP_IP;
591 future = OvsdbTestUtil.updateNode(connInfo, tepIp, ITMConstants.DEFAULT_TRANSPORT_ZONE, null, dataBroker);
593 // wait for OvsdbNodeListener to perform config DS update through transaction
594 coordinatorEventsWaiter.awaitEventsConsumption();
596 // check TEP is updated and now it is added with updated tep-ip
597 // when local_ip is updated from southbound
598 assertEqualBeans(ExpectedDefTransportZoneObjects.defTzWithUpdatedTepIp(),
599 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION,defTzonePath)
604 public void tepUpdateForTzTest() throws Exception {
605 // wait for start-up default-TZ creation task to get over
606 coordinatorEventsWaiter.awaitEventsConsumption();
608 String tepIp = ItmTestConstants.DEF_TZ_TEP_IP;
609 // create Network topology node with tep-ip set into ExternalIds list
610 // OvsdbNodeListener would be automatically listen on Node to add TEP
611 ConnectionInfo connInfo = OvsdbTestUtil.getConnectionInfo(ItmTestConstants.OVSDB_CONN_PORT,
612 ItmTestConstants.LOCALHOST_IP);
613 FluentFuture<? extends @NonNull CommitInfo> future = OvsdbTestUtil.createNode(
614 connInfo, tepIp, ITMConstants.DEFAULT_TRANSPORT_ZONE, dataBroker);
617 // add bridge into node
618 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.DEF_BR_NAME,
619 ItmTestConstants.DEF_BR_DPID, dataBroker);
621 // wait for OvsdbNodeListener to perform config DS update through transaction
622 coordinatorEventsWaiter.awaitEventsConsumption();
624 // iid for default-TZ
625 InstanceIdentifier<TransportZone> defTzonePath = ItmTepAutoConfigTestUtil.getTzIid(
626 ITMConstants.DEFAULT_TRANSPORT_ZONE);
627 Assert.assertNotNull(defTzonePath);
629 // check TEP is added into default-TZ
630 assertEqualBeans(ExpectedDefTransportZoneObjects.newDefTzWithTep(),
631 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, defTzonePath)
634 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
635 InstanceIdentifier<Vteps> oldVTepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
636 ITMConstants.DEFAULT_TRANSPORT_ZONE, ItmTestConstants.INT_DEF_BR_DPID,
637 ITMConstants.DUMMY_PORT);
638 Assert.assertNotNull(oldVTepPath);
640 // create Transport-zone TZA
641 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
642 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
643 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
644 // iid for TZA configured from NB
645 InstanceIdentifier<TransportZone> tzaTzonePath = ItmTepAutoConfigTestUtil.getTzIid(
646 ItmTestConstants.TZ_NAME);
647 Assert.assertNotNull(tzaTzonePath);
649 // update OVSDB node with tzname=TZA in ExternalIds list
650 String tzName = ItmTestConstants.TZ_NAME;
651 future = OvsdbTestUtil.updateNode(connInfo, tepIp, tzName, null, dataBroker);
653 // wait for OvsdbNodeListener to perform config DS update through transaction
654 coordinatorEventsWaiter.awaitEventsConsumption();
656 // check old TEP which was in default-TZ is deleted
657 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
658 .read(LogicalDatastoreType.CONFIGURATION, oldVTepPath).get());
660 // check TEP is updated and now it is added into TZA transport-zone when tzname is updated
661 // to TZA from southbound
662 assertEqualBeans(ExpectedTransportZoneObjects.updatedTransportZone(),
663 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION,tzaTzonePath)
668 public void tepUpdateForBrNameTest() throws Exception {
669 String tepIp = ItmTestConstants.NB_TZ_TEP_IP;
670 // prepare OVSDB node with tep-ip set into ExternalIds list
671 // OvsdbNodeListener would be automatically listen on Node to add TEP
672 ConnectionInfo connInfo = OvsdbTestUtil.getConnectionInfo(ItmTestConstants.OVSDB_CONN_PORT,
673 ItmTestConstants.LOCALHOST_IP);
674 FluentFuture<? extends @NonNull CommitInfo> future = OvsdbTestUtil.createNode(
675 connInfo, tepIp, ItmTestConstants.TZ_NAME, dataBroker);
678 // create Transport-zone in advance
679 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
680 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
681 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
683 // add bridge into node
684 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.DEF_BR_NAME,
685 ItmTestConstants.DEF_BR_DPID, dataBroker);
687 // wait for OvsdbNodeListener to perform config DS update through transaction
688 coordinatorEventsWaiter.awaitEventsConsumption();
690 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
691 ItmTestConstants.TZ_NAME);
692 Assert.assertNotNull(tzonePath);
694 /*if (dataBroker != null)
696 String errMsg = "present db :" + dataBroker.newReadOnlyTransaction().
697 read(LogicalDatastoreType.CONFIGURATION, tzonePath);
698 throw new NullPointerException(errMsg);
701 // check TEP is added into TZ
702 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(), dataBroker.newReadOnlyTransaction()
703 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
705 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
707 InstanceIdentifier<Vteps> oldVTepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
708 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_DEF_BR_DPID, ITMConstants.DUMMY_PORT);
709 Assert.assertNotNull(oldVTepPath);
711 // add new bridge br2
712 future = OvsdbTestUtil.addBridgeIntoNode(connInfo, ItmTestConstants.BR2_NAME,
713 ItmTestConstants.BR2_DPID, dataBroker);
715 // wait for OvsdbNodeListener to perform config DS update through transaction
716 coordinatorEventsWaiter.awaitEventsConsumption();
718 // update OVSDB node with br-name=br2 in ExternalIds column
719 String brName = ItmTestConstants.BR2_NAME;
720 future = OvsdbTestUtil.updateNode(connInfo, ItmTestConstants.NB_TZ_TEP_IP,
721 ItmTestConstants.TZ_NAME, brName, dataBroker);
723 // wait for OvsdbNodeListener to perform config DS update through transaction
724 coordinatorEventsWaiter.awaitEventsConsumption();
726 InstanceIdentifier<Vteps> newVTepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
727 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_BR2_DPID, ITMConstants.DUMMY_PORT);
728 Assert.assertNotNull(newVTepPath);
730 // check old TEP having default-bridge-DPID is deleted
731 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
732 .read(LogicalDatastoreType.CONFIGURATION, oldVTepPath).get());
734 // check TEP is updated with dpnId of br2 when br-name is updated to br2 from southbound
735 Assert.assertEquals(ItmTestConstants.INT_BR2_DPID, dataBroker.newReadOnlyTransaction()
736 .read(LogicalDatastoreType.CONFIGURATION, newVTepPath).get().get().getDpnId());
740 public void tepAddIntoTepsNotHostedListTest() throws Exception {
741 // add into not hosted list
742 ListenableFuture<Void> future = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
743 ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME,
744 false, dataBroker, txRunner);
746 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
747 ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
748 Assert.assertNotNull(notHostedPath);
750 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects.newTepNotHostedTransportZone(),
751 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, notHostedPath)
756 public void tepDeleteFromTepsNotHostedListTest() throws Exception {
757 // add into not hosted list
758 ListenableFuture<Void> future = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
759 ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME,
760 false, dataBroker, txRunner);
762 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
763 ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
764 Assert.assertNotNull(notHostedPath);
766 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects.newTepNotHostedTransportZone(),
767 dataBroker.newReadOnlyTransaction()
768 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get());
770 //delete from not hosted list
771 future = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
772 ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, dataBroker, txRunner);
775 Assert.assertEquals(Optional.empty(),
776 dataBroker.newReadOnlyTransaction()
777 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get());
781 public void tepMoveFromTepsNotHostedListToTzTest() throws Exception {
782 // add into not hosted list
783 ListenableFuture<Void> future = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
784 ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME,
785 false, dataBroker, txRunner);
787 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
788 ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
789 Assert.assertNotNull(notHostedPath);
791 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects.newTepNotHostedTransportZone(),
792 dataBroker.newReadOnlyTransaction()
793 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get());
795 // create the same TZ
796 TransportZone transportZoneNorth = new TransportZoneBuilder().setZoneName(ItmTestConstants.NOT_HOSTED_TZ_NAME)
797 .setTunnelType(ItmTestConstants.TUNNEL_TYPE_VXLAN)
798 .withKey(new TransportZoneKey(ItmTestConstants.NOT_HOSTED_TZ_NAME)).build();
799 Assert.assertNotNull(transportZoneNorth);
801 txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
802 tx -> tx.mergeParentStructurePut(ItmTepAutoConfigTestUtil.getTzIid(ItmTestConstants.NOT_HOSTED_TZ_NAME),
803 transportZoneNorth)).get();
805 // wait for TransportZoneListener to perform config DS update
806 // for TEP movement through transaction
807 coordinatorEventsWaiter.awaitEventsConsumption();
809 InstanceIdentifier<TransportZone> tzPath = ItmTepAutoConfigTestUtil.getTzIid(
810 ItmTestConstants.NOT_HOSTED_TZ_NAME);
811 Assert.assertNotNull(tzPath);
814 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects
815 .newTepNotHostedTransportZone().getUnknownVteps().values().iterator().next().getIpAddress()
816 .stringValue(), dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION,
817 tzPath).get().get().getVteps().values().iterator().next().getIpAddress().stringValue());
819 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects.newTepNotHostedTransportZone().getUnknownVteps()
820 .values().iterator().next().getDpnId(), dataBroker.newReadOnlyTransaction()
821 .read(LogicalDatastoreType.CONFIGURATION, tzPath).get()
822 .get().getVteps().values().iterator().next().getDpnId());
824 assertEqualBeans(ExpectedTepNotHostedTransportZoneObjects.newTepNotHostedTransportZone().getZoneName(),
825 dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, tzPath)
826 .get().get().getZoneName());
828 // check TZ is removed
829 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
830 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get());
834 public void tzDeletedAndReaddedTest() throws Exception {
836 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
837 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
838 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
840 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
841 ItmTestConstants.TZ_NAME);
842 Assert.assertNotNull(tzonePath);
844 // check TZ is created
845 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
846 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get().getZoneName());
849 ListenableFuture<Void> futures =
850 ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NB_TZ_TEP_IP,
851 ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, false, dataBroker, txRunner);
854 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
856 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
857 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_DEF_BR_DPID, ITMConstants.DUMMY_PORT);
858 Assert.assertNotNull(vtepPath);
860 // check TEP is added into TZ that is already created.
861 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(),
862 dataBroker.newReadOnlyTransaction()
863 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
865 // remove Transport Zone
866 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.delete(LogicalDatastoreType.CONFIGURATION,
869 // wait for TransportZoneListener to perform config DS update
870 // for TEP movement through transaction
871 coordinatorEventsWaiter.awaitEventsConsumption();
874 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
875 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get());
877 //check deleted tz moved to notHosted
878 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
879 ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.TZ_NAME);
880 Assert.assertNotNull(notHostedPath);
881 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
882 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get().getZoneName());
885 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
886 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
887 // wait for TransportZoneListener to perform config DS update
888 // for TEP movement through transaction
889 coordinatorEventsWaiter.awaitEventsConsumption();
891 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
892 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get());
894 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(),
895 dataBroker.newReadOnlyTransaction()
896 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
901 public void tzDeletedAndReaddedWithSameVtepsTest() throws Exception {
903 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
904 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
905 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
907 coordinatorEventsWaiter.awaitEventsConsumption();
909 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
910 ItmTestConstants.TZ_NAME);
911 Assert.assertNotNull(tzonePath);
913 // check TZ is created
914 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
915 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get().getZoneName());
918 ListenableFuture<Void> futures =
919 ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NB_TZ_TEP_IP,
920 ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, false, dataBroker, txRunner);
922 coordinatorEventsWaiter.awaitEventsConsumption();
924 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
926 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
927 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_DEF_BR_DPID, ITMConstants.DUMMY_PORT);
928 Assert.assertNotNull(vtepPath);
930 // check TEP is added into TZ that is already created.
931 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(),
932 dataBroker.newReadOnlyTransaction()
933 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
935 // remove Transport Zone
936 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.delete(LogicalDatastoreType.CONFIGURATION,
939 // wait for TransportZoneListener to perform config DS update
940 // for TEP movement through transaction
941 coordinatorEventsWaiter.awaitEventsConsumption();
944 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
945 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get());
947 //check deleted tz moved to notHosted
948 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
949 ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.TZ_NAME);
950 coordinatorEventsWaiter.awaitEventsConsumption();
951 Assert.assertNotNull(notHostedPath);
952 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
953 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get().getZoneName());
955 //create vtepList form unknownVtepList
956 List<Vteps> vtepsList = new ArrayList<>();
957 @Nullable Map<UnknownVtepsKey, UnknownVteps> unknownVtepsList = dataBroker.newReadOnlyTransaction()
958 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get().getUnknownVteps();
960 for (UnknownVteps unknownVtep:unknownVtepsList.values()) {
961 Vteps vteps = new VtepsBuilder().setDpnId(unknownVtep.getDpnId())
962 .setIpAddress(unknownVtep.getIpAddress())
963 .withKey(new VtepsKey(unknownVtep.getDpnId())).build();
964 vtepsList.add(vteps);
967 TransportZone recreatedTransportZone = new TransportZoneBuilder().setZoneName(ItmTestConstants.TZ_NAME)
968 .setTunnelType(ItmTestConstants.TUNNEL_TYPE_VXLAN).setVteps(vtepsList)
969 .withKey(new TransportZoneKey(ItmTestConstants.TZ_NAME)).build();
971 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
972 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, recreatedTransportZone)).get();
974 // wait for TransportZoneListener to perform config DS update
975 // for TEP movement through transaction
976 coordinatorEventsWaiter.awaitEventsConsumption();
978 // verify TZ is moved from notHosted to transport zone and their should be only one vtep in it.
980 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
981 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get());
983 assertEqualBeans(1, dataBroker.newReadOnlyTransaction()
984 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get()
989 public void tzReaddWithSameVtepsAndDiffDpnIDTest() throws Exception {
991 InstanceIdentifier<TransportZone> tzPath = ItmUtils.getTZInstanceIdentifier(ItmTestConstants.TZ_NAME);
992 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
993 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, transportZone)).get();
995 InstanceIdentifier<TransportZone> tzonePath = ItmTepAutoConfigTestUtil.getTzIid(
996 ItmTestConstants.TZ_NAME);
997 Assert.assertNotNull(tzonePath);
999 // check TZ is created
1000 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
1001 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get().getZoneName());
1004 ListenableFuture<Void> futures =
1005 ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NB_TZ_TEP_IP,
1006 ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, false, dataBroker, txRunner);
1009 IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
1011 InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
1012 ItmTestConstants.TZ_NAME, ItmTestConstants.INT_DEF_BR_DPID, ITMConstants.DUMMY_PORT);
1013 Assert.assertNotNull(vtepPath);
1015 // check TEP is added into TZ that is already created.
1016 assertEqualBeans(ExpectedTransportZoneObjects.newTransportZone(),
1017 dataBroker.newReadOnlyTransaction()
1018 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get());
1020 // remove Transport Zone
1021 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.delete(LogicalDatastoreType.CONFIGURATION,
1024 // wait for TransportZoneListener to perform config DS update
1025 // for TEP movement through transaction
1026 coordinatorEventsWaiter.awaitEventsConsumption();
1029 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
1030 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get());
1032 //check deleted tz moved to notHosted
1033 InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
1034 ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.TZ_NAME);
1036 Assert.assertNotNull(notHostedPath);
1037 Assert.assertEquals(ItmTestConstants.TZ_NAME, dataBroker.newReadOnlyTransaction()
1038 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get().getZoneName());
1040 //create vtepList form unknownVtepList
1041 List<Vteps> vtepsList = new ArrayList<>();
1042 @Nullable Map<UnknownVtepsKey, UnknownVteps> unknownVtepsList = dataBroker.newReadOnlyTransaction()
1043 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get().get().getUnknownVteps();
1044 //modifing the dpnid and keeping the ip same.
1045 for (UnknownVteps unknownVtep:unknownVtepsList.values()) {
1046 Vteps vteps = new VtepsBuilder().setDpnId(Uint64.valueOf(10))
1047 .setIpAddress(unknownVtep.getIpAddress())
1048 .withKey(new VtepsKey(Uint64.valueOf(10))).build();
1049 vtepsList.add(vteps);
1052 TransportZone recreatedTransportZone = new TransportZoneBuilder().setZoneName(ItmTestConstants.TZ_NAME)
1053 .setTunnelType(ItmTestConstants.TUNNEL_TYPE_VXLAN).setVteps(vtepsList)
1054 .withKey(new TransportZoneKey(ItmTestConstants.TZ_NAME)).build();
1056 txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
1057 tx.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, tzPath, recreatedTransportZone)).get();
1059 // wait for TransportZoneListener to perform config DS update
1060 // for TEP movement through transaction
1061 coordinatorEventsWaiter.awaitEventsConsumption();
1063 // verify TZ is moved from notHosted to transport zone and their should be only one vtep in it.
1065 Assert.assertEquals(Optional.empty(), dataBroker.newReadOnlyTransaction()
1066 .read(LogicalDatastoreType.OPERATIONAL, notHostedPath).get());
1068 assertEqualBeans(1, dataBroker.newReadOnlyTransaction()
1069 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).get().get()
1070 .getVteps().size());