MRI version bump for Aluminium
[genius.git] / itm / itm-impl / src / test / java / org / opendaylight / genius / itm / impl / ItmInternalTunnelAddTest.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.genius.itm.impl;
9
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.verify;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Optional;
16 import java.util.concurrent.ExecutionException;
17 import java.util.concurrent.Future;
18 import org.junit.After;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.Mock;
23 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
24 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
25 import org.opendaylight.genius.itm.cache.OfEndPointCache;
26 import org.opendaylight.genius.itm.cache.OvsBridgeRefEntryCache;
27 import org.opendaylight.genius.itm.confighelpers.ItmInternalTunnelAddWorker;
28 import org.opendaylight.genius.itm.globals.ITMConstants;
29 import org.opendaylight.genius.itm.itmdirecttunnels.renderer.ovs.utilities.DirectTunnelUtils;
30 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
31 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
32 import org.opendaylight.infrautils.caches.baseimpl.internal.CacheManagersRegistryImpl;
33 import org.opendaylight.infrautils.caches.guava.internal.GuavaCacheProvider;
34 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
35 import org.opendaylight.mdsal.binding.api.DataBroker;
36 import org.opendaylight.mdsal.binding.api.ReadTransaction;
37 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
38 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBfd;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorInterval;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpoints;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpointsBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelList;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnel.list.InternalTunnel;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnel.list.InternalTunnelKey;
68 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
69 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
70 import org.opendaylight.yangtools.yang.common.OperationFailedException;
71 import org.opendaylight.yangtools.yang.common.RpcResult;
72 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
73 import org.opendaylight.yangtools.yang.common.Uint64;
74 import org.powermock.api.mockito.PowerMockito;
75 import org.powermock.core.classloader.annotations.PrepareForTest;
76 import org.powermock.modules.junit4.PowerMockRunner;
77
78 //@RunWith(MockitoJUnitRunner.class)
79 @RunWith(PowerMockRunner.class)
80 @PrepareForTest(ITMBatchingUtils.class)
81 public class ItmInternalTunnelAddTest {
82
83     Uint64 dpId1 = Uint64.ONE;
84     Uint64 dpId2 = Uint64.valueOf(2);
85     String portName1 = "phy0";
86     String portName2 = "phy1" ;
87     int vlanId = 100 ;
88     int interval = 1000;
89     String tepIp1 = "192.168.56.101";
90     String tepIp2 = "192.168.56.102";
91     String gwyIp1 = "0.0.0.0";
92     String gwyIp2 = "0.0.0.1";
93     String subnetIp = "10.1.1.24";
94     String transportZone1 = "TZA" ;
95     String parentInterfaceName = "1:phy0:100" ;
96     String trunkInterfaceName1 = null;
97     String trunkInterfaceName2 = null;
98     IpAddress ipAddress1 = null;
99     IpAddress ipAddress2 = null;
100     IpAddress gtwyIp1 = null;
101     IpAddress gtwyIp2 = null;
102     IpPrefix ipPrefixTest = null;
103     DPNTEPsInfo dpntePsInfoVxlan = null;
104     DPNTEPsInfo dpntePsInfoVxlanNew = null;
105     DPNTEPsInfo dpntePsInfoGre = null;
106     DPNTEPsInfo dpntePsInfoGreNew = null;
107     TunnelEndPoints tunnelEndPointsVxlan = null;
108     TunnelEndPoints tunnelEndPointsVxlanNew = null;
109     TunnelEndPoints tunnelEndPointsGre = null;
110     TunnelEndPoints tunnelEndPointsGreNew = null;
111     TunnelMonitorParams tunnelMonitorParams = null;
112     TunnelMonitorInterval tunnelMonitorInterval = null;
113     InternalTunnel internalTunnel1 = null;
114     InternalTunnel internalTunnel2 = null;
115     DpnEndpoints dpnEndpointsVxlan = null;
116     DpnEndpoints dpnEndpointsGre = null;
117     List<TunnelEndPoints> tunnelEndPointsListVxlan = new ArrayList<>();
118     List<TunnelEndPoints> tunnelEndPointsListVxlanNew = new ArrayList<>();
119     List<TunnelEndPoints> tunnelEndPointsListGre = new ArrayList<>();
120     List<TunnelEndPoints> tunnelEndPointsListGreNew = new ArrayList<>();
121     List<DPNTEPsInfo> meshDpnListVxlan = new ArrayList<>() ;
122     List<DPNTEPsInfo> cfgdDpnListVxlan = new ArrayList<>() ;
123     List<DPNTEPsInfo> meshDpnListGre = new ArrayList<>() ;
124     List<DPNTEPsInfo> cfgdDpnListGre = new ArrayList<>() ;
125     java.lang.Class<? extends TunnelTypeBase> tunnelType1 = TunnelTypeVxlan.class;
126     java.lang.Class<? extends TunnelTypeBase> tunnelType2 = TunnelTypeGre.class;
127     Class<? extends TunnelMonitoringTypeBase> monitorProtocol = TunnelMonitoringTypeBfd.class;
128
129     InstanceIdentifier<TunnelMonitorParams> tunnelMonitorParamsInstanceIdentifier =
130             InstanceIdentifier.create(TunnelMonitorParams.class);
131     InstanceIdentifier<TunnelMonitorInterval> tunnelMonitorIntervalIdentifier =
132             InstanceIdentifier.create(TunnelMonitorInterval.class);
133     InstanceIdentifier<DpnEndpoints> dpnEndpointsIdentifier = InstanceIdentifier.builder(DpnEndpoints.class).build() ;
134     InstanceIdentifier<InternalTunnel> internalTunnelIdentifierVxlan1 = InstanceIdentifier.create(
135             TunnelList.class).child(InternalTunnel.class, new InternalTunnelKey(dpId2, dpId1, tunnelType1));
136     InstanceIdentifier<InternalTunnel> internalTunnelIdentifierVxlan2 = InstanceIdentifier.create(
137             TunnelList.class).child(InternalTunnel.class, new InternalTunnelKey(dpId1, dpId2, tunnelType1));
138     InstanceIdentifier<InternalTunnel> internalTunnelIdentifierGre1 = InstanceIdentifier.create(
139             TunnelList.class).child(InternalTunnel.class, new InternalTunnelKey(dpId2, dpId1, tunnelType2));
140     InstanceIdentifier<InternalTunnel> internalTunnelIdentifierGre2 = InstanceIdentifier.create(
141             TunnelList.class).child(InternalTunnel.class, new InternalTunnelKey(dpId1, dpId2, tunnelType2));
142
143     AllocateIdOutput expectedId1 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("100")).build();
144     AllocateIdOutput expectedId2 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("200")).build();
145     AllocateIdOutput expectedDstID1 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("1")).build();
146     AllocateIdOutput expectedDstID2 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("2")).build();
147
148     Future<RpcResult<AllocateIdOutput>> idOutputOptional1;
149     Future<RpcResult<AllocateIdOutput>> idOutputOptional2;
150     Future<RpcResult<AllocateIdOutput>> dstId1Output;
151     Future<RpcResult<AllocateIdOutput>> dstId2Output;
152
153     @Mock DataBroker dataBroker;
154     @Mock ReadTransaction mockReadTx;
155     @Mock ReadWriteTransaction mockReadWriteTx;
156     @Mock IMdsalApiManager mdsalApiManager;
157     @Mock IdManagerService idManagerService;
158     @Mock ITMBatchingUtils batchingUtils;
159     @Mock ItmConfig itmConfig;
160     @Mock JobCoordinator jobCoordinator;
161     @Mock IInterfaceManager interfaceManager;
162     @Mock EntityOwnershipUtils entityOwnershipUtils;
163     ItmInternalTunnelAddWorker itmInternalTunnelAddWorker;
164     DirectTunnelUtils directTunnelUtils;
165     DataTreeEventCallbackRegistrar eventCallbacks;
166
167     Optional<TunnelMonitorParams> tunnelMonitorParamsOptional;
168     Optional<TunnelMonitorInterval> tunnelMonitorIntervalOptional;
169
170     @Before
171     public void setUp() {
172         PowerMockito.mockStatic(ITMBatchingUtils.class);
173         setupMocks();
174
175         tunnelMonitorParamsOptional = Optional.of(tunnelMonitorParams);
176         tunnelMonitorIntervalOptional = Optional.of(tunnelMonitorInterval);
177
178         idOutputOptional1 = RpcResultBuilder.success(expectedId1).buildFuture();
179         idOutputOptional2 = RpcResultBuilder.success(expectedId2).buildFuture();
180         dstId1Output = RpcResultBuilder.success(expectedDstID1).buildFuture();
181         dstId2Output = RpcResultBuilder.success(expectedDstID2).buildFuture();
182
183         doReturn(FluentFutures.immediateFluentFuture(tunnelMonitorParamsOptional)).when(mockReadTx)
184                 .read(LogicalDatastoreType.CONFIGURATION, tunnelMonitorParamsInstanceIdentifier);
185         doReturn(FluentFutures.immediateFluentFuture(tunnelMonitorIntervalOptional)).when(mockReadTx)
186                 .read(LogicalDatastoreType.CONFIGURATION, tunnelMonitorIntervalIdentifier);
187         doReturn(FluentFutures.immediateFluentFuture(tunnelMonitorParamsOptional)).when(mockReadWriteTx)
188                 .read(LogicalDatastoreType.CONFIGURATION, tunnelMonitorParamsInstanceIdentifier);
189         doReturn(FluentFutures.immediateFluentFuture(tunnelMonitorIntervalOptional)).when(mockReadWriteTx)
190                 .read(LogicalDatastoreType.CONFIGURATION, tunnelMonitorIntervalIdentifier);
191
192         directTunnelUtils = new DirectTunnelUtils(idManagerService, mdsalApiManager, entityOwnershipUtils, itmConfig);
193         itmInternalTunnelAddWorker = new ItmInternalTunnelAddWorker(dataBroker, jobCoordinator,
194                 new TunnelMonitoringConfig(dataBroker, new GuavaCacheProvider(new CacheManagersRegistryImpl())),
195                 itmConfig, directTunnelUtils, interfaceManager,
196                 new OvsBridgeRefEntryCache(dataBroker, new GuavaCacheProvider(new CacheManagersRegistryImpl())),
197                 new OfEndPointCache(), eventCallbacks);
198     }
199
200     @After
201     public void cleanUp() {
202     }
203
204     private void setupMocks() {
205
206         ipAddress1 = IpAddressBuilder.getDefaultInstance(tepIp1);
207         ipAddress2 = IpAddressBuilder.getDefaultInstance(tepIp2);
208         ipPrefixTest = IpPrefixBuilder.getDefaultInstance(subnetIp + "/24");
209         gtwyIp1 = IpAddressBuilder.getDefaultInstance(gwyIp1);
210         gtwyIp2 = IpAddressBuilder.getDefaultInstance(gwyIp2);
211         tunnelEndPointsVxlan = new TunnelEndPointsBuilder()
212                 .setIpAddress(ipAddress1).setInterfaceName(parentInterfaceName)
213                 .setTzMembership(ItmUtils.createTransportZoneMembership(transportZone1)).setTunnelType(tunnelType1)
214                 .build();
215         tunnelEndPointsVxlanNew = new TunnelEndPointsBuilder()
216                 .setIpAddress(ipAddress2).setInterfaceName(parentInterfaceName)
217                 .setTzMembership(ItmUtils.createTransportZoneMembership(transportZone1)).setTunnelType(tunnelType1)
218                 .build();
219         tunnelEndPointsGre = new TunnelEndPointsBuilder()
220                 .setIpAddress(ipAddress1).setInterfaceName(parentInterfaceName)
221                 .setTzMembership(ItmUtils.createTransportZoneMembership(transportZone1)).setTunnelType(tunnelType2)
222                 .build();
223         tunnelEndPointsGreNew = new TunnelEndPointsBuilder()
224                 .setIpAddress(ipAddress2).setInterfaceName(parentInterfaceName)
225                 .setTzMembership(ItmUtils.createTransportZoneMembership(transportZone1)).setTunnelType(tunnelType2)
226                 .build();
227         tunnelEndPointsListVxlan.add(tunnelEndPointsVxlan);
228         tunnelEndPointsListVxlanNew.add(tunnelEndPointsVxlanNew);
229         tunnelEndPointsListGre.add(tunnelEndPointsGre);
230         tunnelEndPointsListGreNew.add(tunnelEndPointsGreNew);
231         dpntePsInfoVxlan = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).withKey(new DPNTEPsInfoKey(dpId1))
232                 .setTunnelEndPoints(tunnelEndPointsListVxlan).setDstId(dpId1.intValue()).build();
233         dpntePsInfoVxlanNew = new DPNTEPsInfoBuilder().setDPNID(dpId2).withKey(new DPNTEPsInfoKey(dpId2)).setUp(true)
234                 .setTunnelEndPoints(tunnelEndPointsListVxlanNew).setDstId(dpId2.intValue()).build();
235         dpntePsInfoGre = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).withKey(new DPNTEPsInfoKey(dpId1))
236                 .setTunnelEndPoints(tunnelEndPointsListGre).setDstId(dpId1.intValue()).build();
237         dpntePsInfoGreNew = new DPNTEPsInfoBuilder().setDPNID(dpId2).withKey(new DPNTEPsInfoKey(dpId2)).setUp(true)
238                 .setTunnelEndPoints(tunnelEndPointsListGreNew).setDstId(dpId2.intValue()).build();
239         tunnelMonitorParams = new TunnelMonitorParamsBuilder().setEnabled(true)
240                 .setMonitorProtocol(monitorProtocol).build();
241         tunnelMonitorInterval = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
242         cfgdDpnListVxlan.add(dpntePsInfoVxlan);
243         meshDpnListVxlan.add(dpntePsInfoVxlanNew);
244         cfgdDpnListGre.add(dpntePsInfoGre);
245         meshDpnListGre.add(dpntePsInfoGreNew);
246         dpnEndpointsVxlan = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListVxlan).build();
247         dpnEndpointsGre = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListGre).build();
248
249         doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
250         doReturn(mockReadWriteTx).when(dataBroker).newReadWriteTransaction();
251         doReturn(FluentFutures.immediateNullFluentFuture()).when(mockReadWriteTx).commit();
252         doReturn(true).when(mockReadWriteTx).cancel();
253
254     }
255
256     @Test
257     public void testBuild_all_tunnels_VXLANtype() throws ExecutionException, InterruptedException,
258         OperationFailedException {
259
260         AllocateIdInput getIdInput1 = new AllocateIdInputBuilder()
261                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
262                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.102:VXLAN").build();
263         AllocateIdInput getIdInput2 = new AllocateIdInputBuilder()
264                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
265                 .setIdKey("1:phy0:100:192.168.56.102:192.168.56.101:VXLAN").build();
266         AllocateIdInput dstDpID1 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME)
267                 .setIdKey(dpId1.toString()).build();
268         AllocateIdInput dstDpID2 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME)
269                 .setIdKey(dpId2.toString()).build();
270
271         doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
272         doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
273         doReturn(dstId1Output).when(idManagerService).allocateId(dstDpID1);
274         doReturn(dstId2Output).when(idManagerService).allocateId(dstDpID2);
275
276         trunkInterfaceName1 = ItmUtils.getTrunkInterfaceName(parentInterfaceName,tepIp1,tepIp2,
277                 tunnelType1.getName());
278         trunkInterfaceName2 = ItmUtils.getTrunkInterfaceName(parentInterfaceName,tepIp2,tepIp1,
279                 tunnelType1.getName());
280         internalTunnel1 = ItmUtils.buildInternalTunnel(dpId1,dpId2,tunnelType1,trunkInterfaceName1);
281         internalTunnel2 = ItmUtils.buildInternalTunnel(dpId2,dpId1,tunnelType1,trunkInterfaceName2);
282
283         itmInternalTunnelAddWorker.buildAllTunnels(mdsalApiManager, cfgdDpnListVxlan, meshDpnListVxlan);
284
285         //Add some verifications
286         verify(mockReadWriteTx).mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
287                 internalTunnelIdentifierVxlan1, internalTunnel1);
288         verify(mockReadWriteTx).mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
289                 internalTunnelIdentifierVxlan2, internalTunnel2);
290         verify(mockReadWriteTx).merge(LogicalDatastoreType.CONFIGURATION, dpnEndpointsIdentifier,
291                 dpnEndpointsVxlan);
292     }
293
294     @Test
295     public void testBuild_all_tunnels_GREtype() throws ExecutionException, InterruptedException,
296             OperationFailedException {
297
298         AllocateIdInput getIdInput1 = new AllocateIdInputBuilder()
299                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
300                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.102:GRE").build();
301         AllocateIdInput getIdInput2 = new AllocateIdInputBuilder()
302                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
303                 .setIdKey("1:phy0:100:192.168.56.102:192.168.56.101:GRE").build();
304         AllocateIdInput dstDpID1 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME)
305                 .setIdKey(dpId1.toString()).build();
306         AllocateIdInput dstDpID2 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME)
307                 .setIdKey(dpId2.toString()).build();
308         doReturn(dstId1Output).when(idManagerService).allocateId(dstDpID1);
309         doReturn(dstId2Output).when(idManagerService).allocateId(dstDpID2);
310
311         doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
312         doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
313
314         trunkInterfaceName1 = ItmUtils.getTrunkInterfaceName(parentInterfaceName,tepIp1,tepIp2,
315                 tunnelType2.getName());
316         trunkInterfaceName2 = ItmUtils.getTrunkInterfaceName(parentInterfaceName,tepIp2,tepIp1,
317                 tunnelType2.getName());
318         internalTunnel1 = ItmUtils.buildInternalTunnel(dpId1,dpId2,tunnelType2,trunkInterfaceName1);
319         internalTunnel2 = ItmUtils.buildInternalTunnel(dpId2,dpId1,tunnelType2,trunkInterfaceName2);
320
321         itmInternalTunnelAddWorker.buildAllTunnels(mdsalApiManager, cfgdDpnListGre, meshDpnListGre);
322
323         verify(mockReadWriteTx).mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
324                 internalTunnelIdentifierGre1, internalTunnel1);
325         verify(mockReadWriteTx).mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
326                 internalTunnelIdentifierGre2, internalTunnel2);
327         verify(mockReadWriteTx).merge(LogicalDatastoreType.CONFIGURATION, dpnEndpointsIdentifier,
328                 dpnEndpointsGre);
329     }
330
331     @Test
332     public void testBuild_all_tunnels_Boyhtype() throws ExecutionException, InterruptedException,
333             OperationFailedException {
334
335         AllocateIdInput getIdInput1 = new AllocateIdInputBuilder()
336                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
337                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.102:VXLAN").build();
338         AllocateIdInput getIdInput2 = new AllocateIdInputBuilder()
339                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
340                 .setIdKey("1:phy0:100:192.168.56.102:192.168.56.101:GRE").build();
341         AllocateIdInput dstDpID1 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME)
342                 .setIdKey(dpId1.toString()).build();
343         AllocateIdInput dstDpID2 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME)
344                 .setIdKey(dpId2.toString()).build();
345
346         doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
347         doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
348         doReturn(dstId1Output).when(idManagerService).allocateId(dstDpID1);
349         doReturn(dstId2Output).when(idManagerService).allocateId(dstDpID2);
350
351
352         trunkInterfaceName1 = ItmUtils.getTrunkInterfaceName(parentInterfaceName,tepIp1,tepIp2,
353                 tunnelType1.getName());
354         trunkInterfaceName2 = ItmUtils.getTrunkInterfaceName(parentInterfaceName,tepIp2,tepIp1,
355                 tunnelType2.getName());
356         internalTunnel1 = ItmUtils.buildInternalTunnel(dpId1,dpId2,tunnelType1,trunkInterfaceName1);
357         internalTunnel2 = ItmUtils.buildInternalTunnel(dpId2,dpId1,tunnelType2,trunkInterfaceName2);
358
359         itmInternalTunnelAddWorker.buildAllTunnels(mdsalApiManager, cfgdDpnListVxlan, meshDpnListGre);
360
361         verify(mockReadWriteTx).mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
362                 internalTunnelIdentifierVxlan1, internalTunnel1);
363         verify(mockReadWriteTx).mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION,
364                 internalTunnelIdentifierGre2, internalTunnel2);
365         verify(mockReadWriteTx).merge(LogicalDatastoreType.CONFIGURATION, dpnEndpointsIdentifier,
366                 dpnEndpointsVxlan);
367     }
368 }