Use uint types in itm-impl tests
[genius.git] / itm / itm-impl / src / test / java / org / opendaylight / genius / itm / impl / ItmExternalTunnelAddTest.java
1 /*
2  * Copyright (c) 2016 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.lenient;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Optional;
18 import java.util.concurrent.Future;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
27 import org.opendaylight.genius.itm.cache.UnprocessedNodeConnectorEndPointCache;
28 import org.opendaylight.genius.itm.confighelpers.HwVtep;
29 import org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelAddWorker;
30 import org.opendaylight.genius.itm.globals.ITMConstants;
31 import org.opendaylight.genius.itm.itmdirecttunnels.renderer.ovs.utilities.DirectTunnelUtils;
32 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
33 import org.opendaylight.infrautils.caches.baseimpl.internal.CacheManagersRegistryImpl;
34 import org.opendaylight.infrautils.caches.guava.internal.GuavaCacheProvider;
35 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
36 import org.opendaylight.mdsal.binding.api.DataBroker;
37 import org.opendaylight.mdsal.binding.api.ReadTransaction;
38 import org.opendaylight.mdsal.binding.api.WriteTransaction;
39 import org.opendaylight.mdsal.binding.util.Datastore;
40 import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
41 import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorInterval;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpoints;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpointsBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.DeviceVteps;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.DeviceVtepsBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.DeviceVtepsKey;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Vteps;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.VtepsBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.VtepsKey;
82 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
83 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
84 import org.opendaylight.yangtools.yang.common.RpcResult;
85 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
86 import org.opendaylight.yangtools.yang.common.Uint16;
87 import org.opendaylight.yangtools.yang.common.Uint32;
88 import org.opendaylight.yangtools.yang.common.Uint64;
89
90 @RunWith(MockitoJUnitRunner.class)
91 public class ItmExternalTunnelAddTest {
92
93     Uint64 dpId1 = Uint64.ONE;
94     int vlanId = 100 ;
95     Uint16 interval = Uint16.valueOf(1000);
96     String portName1 = "phy0";
97     String tepIp1 = "192.168.56.30";
98     String tepIp2 = "192.168.56.40";
99     String tepIp3 = "192.168.56.101";
100     String gwyIp1 = "0.0.0.0";
101     String gwyIp2 = "0.0.0.1";
102     String subnetIp = "10.1.1.24";
103     String parentInterfaceName = "1:phy0:100" ;
104     String transportZone1 = "TZA" ;
105     String source = "hwvtep://192.168.101.30:6640/physicalswitch/s3" ;
106     String destination = "hwvtep://192.168.101.40:6640/physicalswitch/s4" ;
107     String trunkInterfaceName = null;
108     TunnelEndPoints tunnelEndPointsVxlan = null;
109     IpAddress ipAddress1 = null;
110     IpAddress ipAddress2 = null;
111     IpAddress ipAddress3 = null;
112     IpAddress gtwyIp1 = null;
113     IpAddress gtwyIp2 = null;
114     IpPrefix ipPrefixTest = null;
115     DPNTEPsInfo dpntePsInfoVxlan = null;
116     ExternalTunnel externalTunnel = null;
117     DpnEndpoints dpnEndpointsVxlan = null;
118     AllocateIdInput getIdInput1 = null;
119     AllocateIdInput getIdInput2 = null;
120     AllocateIdInput getIdInput3 = null;
121     AllocateIdInput getIdInput4 = null;
122     AllocateIdInput getIdInput5 = null;
123     AllocateIdInput getIdInput6 = null;
124     HwVtep hwVtep1  = null;
125     Vteps vtepsTest = null;
126     DeviceVteps deviceVteps1 = null;
127     DeviceVteps deviceVteps2 = null;
128     TransportZone transportZone = null;
129     TunnelMonitorParams tunnelMonitorParams = null;
130     TunnelMonitorInterval tunnelMonitorInterval = null;
131     Class<? extends TunnelMonitoringTypeBase> monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
132     Interface iface = null;
133     List<DPNTEPsInfo> cfgdDpnListVxlan = new ArrayList<>() ;
134     List<TunnelEndPoints> tunnelEndPointsListVxlan = new ArrayList<>();
135     List<Uint64> bigIntegerList = new ArrayList<>();
136     List<HwVtep> cfgdHwVtepsList = new ArrayList<>();
137     List<DeviceVteps> deviceVtepsList = new ArrayList<>();
138     List<Vteps> vtepsList = new ArrayList<>();
139     java.lang.Class<? extends TunnelTypeBase> tunnelType1 = TunnelTypeVxlan.class;
140
141     InstanceIdentifier<Interface> interfaceIdentifier = null;
142     InstanceIdentifier<TunnelMonitorParams> tunnelMonitorParamsInstanceIdentifier =
143             InstanceIdentifier.create(TunnelMonitorParams.class);
144     InstanceIdentifier<TunnelMonitorInterval> tunnelMonitorIntervalIdentifier =
145             InstanceIdentifier.create(TunnelMonitorInterval.class);
146     InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier = null;
147     InstanceIdentifier<DpnEndpoints> dpnEndpointsIdentifier = InstanceIdentifier.builder(DpnEndpoints.class).build();
148     AllocateIdOutput expectedId1 = new AllocateIdOutputBuilder().setIdValue(Uint32.valueOf(100)).build();
149     Future<RpcResult<AllocateIdOutput>> idOutputOptional1 ;
150     AllocateIdOutput expectedId2 = new AllocateIdOutputBuilder().setIdValue(Uint32.valueOf(101)).build();
151     Future<RpcResult<AllocateIdOutput>> idOutputOptional2 ;
152     AllocateIdOutput expectedId3 = new AllocateIdOutputBuilder().setIdValue(Uint32.valueOf(102)).build();
153     Future<RpcResult<AllocateIdOutput>> idOutputOptional3 ;
154     AllocateIdOutput expectedId4 = new AllocateIdOutputBuilder().setIdValue(Uint32.valueOf(103)).build();
155     Future<RpcResult<AllocateIdOutput>> idOutputOptional4 ;
156     AllocateIdOutput expectedId5 = new AllocateIdOutputBuilder().setIdValue(Uint32.valueOf(104)).build();
157     Future<RpcResult<AllocateIdOutput>> idOutputOptional5 ;
158     AllocateIdOutput expectedId6 = new AllocateIdOutputBuilder().setIdValue(Uint32.valueOf(105)).build();
159     Future<RpcResult<AllocateIdOutput>> idOutputOptional6 ;
160     Optional<DpnEndpoints> optionalDpnEndPoints ;
161     Optional<TunnelMonitorParams> tunnelMonitorParamsOptional;
162     Optional<TunnelMonitorInterval> tunnelMonitorIntervalOptional ;
163
164     @Mock DataBroker dataBroker;
165     @Mock JobCoordinator jobCoordinator;
166     @Mock ReadTransaction mockReadTx;
167     @Mock WriteTransaction mockWriteTx;
168     @Mock TypedWriteTransaction<Datastore.Configuration> typedWriteTransaction;
169     @Mock TypedReadWriteTransaction<Datastore.Configuration> typedReadWriteTransaction;
170     @Mock IdManagerService idManagerService;
171     @Mock ItmConfig itmConfig;
172     @Mock EntityOwnershipUtils entityOwnershipUtils;
173
174     private ItmExternalTunnelAddWorker externalTunnelAddWorker;
175     DirectTunnelUtils directTunnelUtils;
176     UnprocessedNodeConnectorEndPointCache unprocessedNodeConnectorEndPointCache;
177
178     @Before
179     public void setUp() {
180         setupMocks();
181
182         optionalDpnEndPoints = Optional.of(dpnEndpointsVxlan);
183         tunnelMonitorParamsOptional = Optional.of(tunnelMonitorParams);
184         tunnelMonitorIntervalOptional = Optional.of(tunnelMonitorInterval);
185
186         externalTunnelAddWorker = new ItmExternalTunnelAddWorker(itmConfig,
187             new DPNTEPsInfoCache(dataBroker, new GuavaCacheProvider(new CacheManagersRegistryImpl()), directTunnelUtils,
188             jobCoordinator, unprocessedNodeConnectorEndPointCache));
189
190     }
191
192     @After
193     public void cleanUp() {
194     }
195
196     private void setupMocks() {
197
198         ipAddress1 = IpAddressBuilder.getDefaultInstance(tepIp1);
199         ipAddress2 = IpAddressBuilder.getDefaultInstance(tepIp2);
200         ipAddress3 = IpAddressBuilder.getDefaultInstance(tepIp3);
201         gtwyIp1 = IpAddressBuilder.getDefaultInstance(gwyIp1);
202         gtwyIp2 = IpAddressBuilder.getDefaultInstance(gwyIp2);
203         ipPrefixTest = IpPrefixBuilder.getDefaultInstance(subnetIp + "/24");
204         tunnelEndPointsVxlan = new TunnelEndPointsBuilder()
205                 .setIpAddress(ipAddress3).setInterfaceName(parentInterfaceName)
206                 .setTzMembership(ItmUtils.createTransportZoneMembership(transportZone1))
207                 .setTunnelType(tunnelType1).build();
208         tunnelEndPointsListVxlan.add(tunnelEndPointsVxlan);
209         dpntePsInfoVxlan = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).withKey(new DPNTEPsInfoKey(dpId1))
210                 .setTunnelEndPoints(tunnelEndPointsListVxlan).build();
211         deviceVteps1 = new DeviceVtepsBuilder().setIpAddress(ipAddress1).withKey(new DeviceVtepsKey(ipAddress1,
212                 source)).setNodeId(source).setTopologyId("hwvtep:1").build();
213         deviceVteps2 = new DeviceVtepsBuilder().setIpAddress(ipAddress2).withKey(new DeviceVtepsKey(ipAddress2,
214                 destination)).setNodeId(destination).setTopologyId("hwvtep:1").build();
215         hwVtep1 = new HwVtep();
216         hwVtep1.setTransportZone(transportZone1);
217         hwVtep1.setGatewayIP(gtwyIp1);
218         hwVtep1.setHwIp(ipAddress1);
219         hwVtep1.setTunnelType(tunnelType1);
220         hwVtep1.setVlanID(vlanId);
221         hwVtep1.setTopoId("hwvtep:1");
222         hwVtep1.setNodeId(source);
223         hwVtep1.setIpPrefix(ipPrefixTest);
224         cfgdDpnListVxlan.add(dpntePsInfoVxlan);
225         cfgdHwVtepsList.add(hwVtep1);
226         bigIntegerList.add(dpId1);
227         deviceVtepsList.add(deviceVteps1);
228         deviceVtepsList.add(deviceVteps2);
229         vtepsTest = new VtepsBuilder().setDpnId(dpId1).setIpAddress(ipAddress3).withKey(new
230                 VtepsKey(dpId1)).build();
231         vtepsList.add(vtepsTest);
232         dpnEndpointsVxlan = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListVxlan).build();
233         transportZone = new TransportZoneBuilder().setTunnelType(tunnelType1).setZoneName(transportZone1).withKey(new
234                 TransportZoneKey(transportZone1)).setVteps(vtepsList).setDeviceVteps(deviceVtepsList).build();
235         idOutputOptional1 = RpcResultBuilder.success(expectedId1).buildFuture();
236         getIdInput1 = new AllocateIdInputBuilder()
237                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
238                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.40:VXLAN").build();
239         lenient().doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
240         idOutputOptional2 = RpcResultBuilder.success(expectedId2).buildFuture();
241         getIdInput2 = new AllocateIdInputBuilder()
242                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
243                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.30:VXLAN").build();
244         lenient().doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
245         idOutputOptional3 = RpcResultBuilder.success(expectedId3).buildFuture();
246         getIdInput3 = new AllocateIdInputBuilder()
247                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
248                 .setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.101:VXLAN")
249                 .build();
250         lenient().doReturn(idOutputOptional3).when(idManagerService).allocateId(getIdInput3);
251         idOutputOptional4 = RpcResultBuilder.success(expectedId4).buildFuture();
252         getIdInput4 = new AllocateIdInputBuilder()
253                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
254                 .setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.101:VXLAN")
255                 .build();
256         lenient().doReturn(idOutputOptional4).when(idManagerService).allocateId(getIdInput4);
257         idOutputOptional5 = RpcResultBuilder.success(expectedId5).buildFuture();
258         getIdInput5 = new AllocateIdInputBuilder()
259                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
260                 .setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.40:VXLAN")
261                 .build();
262         lenient().doReturn(idOutputOptional5).when(idManagerService).allocateId(getIdInput5);
263         idOutputOptional6 = RpcResultBuilder.success(expectedId6).buildFuture();
264         getIdInput6 = new AllocateIdInputBuilder()
265                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
266                 .setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.30:VXLAN")
267                 .build();
268         lenient().doReturn(idOutputOptional6).when(idManagerService).allocateId(getIdInput6);
269         tunnelMonitorParams = new TunnelMonitorParamsBuilder().setEnabled(true).build();
270         tunnelMonitorInterval = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
271
272         trunkInterfaceName = ItmUtils.getTrunkInterfaceName(parentInterfaceName,
273                 tunnelEndPointsVxlan.getIpAddress().stringValue(), ipAddress2.stringValue(),tunnelType1.getName());
274         interfaceIdentifier = ItmUtils.buildId(trunkInterfaceName);
275         externalTunnelIdentifier = InstanceIdentifier.create(ExternalTunnelList.class)
276                 .child(ExternalTunnel.class, new ExternalTunnelKey(ipAddress2.stringValue(),
277                         dpId1.toString(), tunnelType1));
278         iface = ItmUtils.buildTunnelInterface(dpId1,trunkInterfaceName, String.format("%s %s",
279                 ItmUtils.convertTunnelTypetoString(tunnelType1), "Trunk Interface"), true, tunnelType1, ipAddress3,
280                 ipAddress2, false, false, monitorProtocol, null,  false,
281                 null);
282         externalTunnel = ItmUtils.buildExternalTunnel(dpId1.toString(), ipAddress2.stringValue(),
283                 tunnelType1, trunkInterfaceName);
284
285         lenient().doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
286         lenient().doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
287         lenient().doReturn(FluentFutures.immediateNullFluentFuture()).when(mockWriteTx).commit();
288         doReturn("phy0").when(itmConfig).getPortname();
289         doReturn(Uint16.valueOf(100)).when(itmConfig).getVlanId();
290     }
291
292     @Test
293     public void testBuildTunnelsToExternalEndPoint() {
294         externalTunnelAddWorker
295             .buildTunnelsToExternalEndPoint(cfgdDpnListVxlan, ipAddress2, tunnelType1, typedWriteTransaction);
296         verify(typedWriteTransaction).mergeParentStructureMerge(interfaceIdentifier, iface);
297         verify(typedWriteTransaction).mergeParentStructureMerge(externalTunnelIdentifier, externalTunnel);
298
299     }
300
301     @Ignore
302     @Test
303     public void testBuildTunnelsFromDpnToExternalEndPoint() {
304         externalTunnelAddWorker
305             .buildTunnelsFromDpnToExternalEndPoint(bigIntegerList, ipAddress2, tunnelType1, typedWriteTransaction);
306         verify(typedWriteTransaction).mergeParentStructureMerge(interfaceIdentifier, iface);
307         verify(typedWriteTransaction).mergeParentStructureMerge(externalTunnelIdentifier, externalTunnel);
308
309     }
310
311     @Test
312     public void testBuildHwVtepsTunnels() {
313
314         final Interface extTunnelIf1 = ItmUtils.buildTunnelInterface(dpId1, "tun030025bd04f",
315                 String.format("%s %s", tunnelType1.getName(), "Trunk Interface"), true, tunnelType1,
316                 tunnelEndPointsVxlan.getIpAddress(), ipAddress1, false,
317                 false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, false,
318                 null);
319         final Interface hwTunnelIf2 = ItmUtils.buildHwTunnelInterface("tun9a55a9c38f2",
320                 String.format("%s %s", tunnelType1.getName(), "Trunk Interface"), true, hwVtep1.getTopoId(),
321                 hwVtep1.getNodeId(), tunnelType1, ipAddress1, ipAddress3, gtwyIp1, false, monitorProtocol,
322                 ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
323         final Interface extTunnelIf3 = ItmUtils.buildTunnelInterface(dpId1, "tun17c6e20c283",
324                 String.format("%s %s", tunnelType1.getName(), "Trunk Interface"), true, tunnelType1,
325                 tunnelEndPointsVxlan.getIpAddress(), ipAddress2, false, false, monitorProtocol,
326                 ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, false, null);
327         final Interface hwTunnelIf4 = ItmUtils.buildHwTunnelInterface("tunaa109b6c8c5",
328                 String.format("%s %s", tunnelType1.getName(), "Trunk Interface"), true, hwVtep1.getTopoId(),
329                 destination, tunnelType1, ipAddress2, ipAddress3, gtwyIp1, false, monitorProtocol,
330                 ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
331         final Interface hwTunnelIf5 = ItmUtils.buildHwTunnelInterface("tund903ed434d5",
332                 String.format("%s %s", tunnelType1.getName(), "Trunk Interface"), true, hwVtep1.getTopoId(),
333                 hwVtep1.getNodeId(), tunnelType1, ipAddress1, ipAddress2, gtwyIp1, false, monitorProtocol,
334                 ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
335         final Interface hwTunnelIf6 = ItmUtils.buildHwTunnelInterface("tunc3315b110a6",
336                 String.format("%s %s", tunnelType1.getName(), "Trunk Interface"), true, hwVtep1.getTopoId(),
337                 destination, tunnelType1, ipAddress2, ipAddress1, gtwyIp1, false, monitorProtocol,
338                 ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
339         final ExternalTunnel externalTunnel1 = ItmUtils.buildExternalTunnel(getExternalTunnelKey(dpId1.toString()),
340                 getExternalTunnelKey(source), tunnelType1, "tun030025bd04f");
341         final ExternalTunnel externalTunnel2 = ItmUtils.buildExternalTunnel(getExternalTunnelKey(source),
342                 getExternalTunnelKey(dpId1.toString()), tunnelType1, "tun9a55a9c38f2");
343         final ExternalTunnel externalTunnel3 = ItmUtils.buildExternalTunnel(getExternalTunnelKey(dpId1.toString()),
344                 getExternalTunnelKey(destination), tunnelType1, "tun17c6e20c283");
345         final ExternalTunnel externalTunnel4 = ItmUtils.buildExternalTunnel(getExternalTunnelKey(destination),
346                 getExternalTunnelKey(dpId1.toString()), tunnelType1, "tunaa109b6c8c5");
347         final ExternalTunnel externalTunnel5 = ItmUtils.buildExternalTunnel(getExternalTunnelKey(source),
348                 getExternalTunnelKey(destination), tunnelType1, "tund903ed434d5");
349         final ExternalTunnel externalTunnel6 = ItmUtils.buildExternalTunnel(getExternalTunnelKey(destination),
350                 getExternalTunnelKey(source), tunnelType1, "tunc3315b110a6");
351
352         InstanceIdentifier<TransportZone> transportZoneIdentifier = InstanceIdentifier.builder(TransportZones.class)
353                 .child(TransportZone.class, new TransportZoneKey(transportZone1)).build();
354         final InstanceIdentifier<Interface> ifIID1 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
355                 new InterfaceKey("tun030025bd04f")).build();
356         final InstanceIdentifier<Interface> ifIID2 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
357                 new InterfaceKey("tun9a55a9c38f2")).build();
358         final InstanceIdentifier<Interface> ifIID3 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
359                 new InterfaceKey("tun17c6e20c283")).build();
360         final InstanceIdentifier<Interface> ifIID4 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
361                 new InterfaceKey("tunaa109b6c8c5")).build();
362         final InstanceIdentifier<Interface> ifIID5 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
363                 new InterfaceKey("tund903ed434d5")).build();
364         final InstanceIdentifier<Interface> ifIID6 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
365                 new InterfaceKey("tunc3315b110a6")).build();
366         final InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier1 = InstanceIdentifier
367                 .create(ExternalTunnelList.class).child(ExternalTunnel.class,
368                         new ExternalTunnelKey(getExternalTunnelKey(source),
369                                 getExternalTunnelKey(dpId1.toString()), tunnelType1));
370         final InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier2 = InstanceIdentifier
371                 .create(ExternalTunnelList.class).child(ExternalTunnel.class,
372                         new ExternalTunnelKey(getExternalTunnelKey(dpId1.toString()),
373                                 getExternalTunnelKey(source), tunnelType1));
374         final InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier3 = InstanceIdentifier
375                 .create(ExternalTunnelList.class).child(ExternalTunnel.class,
376                         new ExternalTunnelKey(getExternalTunnelKey(destination),
377                                 getExternalTunnelKey(dpId1.toString()), tunnelType1));
378         final InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier4 = InstanceIdentifier
379                 .create(ExternalTunnelList.class).child(ExternalTunnel.class,
380                         new ExternalTunnelKey(getExternalTunnelKey(dpId1.toString()),
381                                 getExternalTunnelKey(destination), tunnelType1));
382         final InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier5 = InstanceIdentifier
383                 .create(ExternalTunnelList.class).child(ExternalTunnel.class,
384                         new ExternalTunnelKey(getExternalTunnelKey(destination),
385                                 getExternalTunnelKey(source), tunnelType1));
386         final InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier6 = InstanceIdentifier
387                 .create(ExternalTunnelList.class).child(ExternalTunnel.class,
388                         new ExternalTunnelKey(getExternalTunnelKey(source),
389                                 getExternalTunnelKey(destination), tunnelType1));
390
391         doReturn(FluentFutures.immediateFluentFuture(Optional.of(transportZone))).when(typedReadWriteTransaction)
392             .read(transportZoneIdentifier);
393
394         externalTunnelAddWorker.buildHwVtepsTunnels(cfgdDpnListVxlan, null, typedReadWriteTransaction);
395         externalTunnelAddWorker.buildHwVtepsTunnels(null, cfgdHwVtepsList, typedReadWriteTransaction);
396
397         verify(typedReadWriteTransaction, times(2)).mergeParentStructureMerge(ifIID1, extTunnelIf1);
398         verify(typedReadWriteTransaction, times(2))
399                 .mergeParentStructureMerge(externalTunnelIdentifier1, externalTunnel1);
400         verify(typedReadWriteTransaction, times(2)).mergeParentStructureMerge(ifIID2, hwTunnelIf2);
401         verify(typedReadWriteTransaction, times(2))
402                 .mergeParentStructureMerge(externalTunnelIdentifier2, externalTunnel2);
403         verify(typedReadWriteTransaction).mergeParentStructureMerge(ifIID3,extTunnelIf3);
404         verify(typedReadWriteTransaction).mergeParentStructureMerge(externalTunnelIdentifier3, externalTunnel3);
405         verify(typedReadWriteTransaction).mergeParentStructureMerge(ifIID4, hwTunnelIf4);
406         verify(typedReadWriteTransaction).mergeParentStructureMerge(externalTunnelIdentifier4, externalTunnel4);
407         verify(typedReadWriteTransaction).mergeParentStructureMerge(ifIID5, hwTunnelIf5);
408         verify(typedReadWriteTransaction).mergeParentStructureMerge(externalTunnelIdentifier5, externalTunnel5);
409         verify(typedReadWriteTransaction).mergeParentStructureMerge(ifIID6, hwTunnelIf6);
410         verify(typedReadWriteTransaction).mergeParentStructureMerge(externalTunnelIdentifier6, externalTunnel6);
411
412     }
413
414     static String getExternalTunnelKey(String nodeid) {
415         if (nodeid.indexOf("physicalswitch") > 0) {
416             nodeid = nodeid.substring(0, nodeid.indexOf("physicalswitch") - 1);
417         }
418         return nodeid;
419     }
420 }