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