Merge "Add utility apis"
[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
9 package org.opendaylight.genius.itm.impl;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
16
17 import com.google.common.base.Optional;
18 import com.google.common.util.concurrent.Futures;
19 import java.math.BigInteger;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.concurrent.Future;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.runners.MockitoJUnitRunner;
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
30 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
31 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
32 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
33 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
34 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
35 import org.opendaylight.genius.itm.confighelpers.HwVtep;
36 import org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelAddWorker;
37 import org.opendaylight.genius.itm.globals.ITMConstants;
38 import org.opendaylight.genius.utils.cache.DataStoreCache;
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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
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.ExternalTunnelList;
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
65         .TunnelEndPoints;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info
67         .TunnelEndPointsBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone
76         .SubnetsBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey;
84 import org.opendaylight.yangtools.concepts.ListenerRegistration;
85 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
86 import org.opendaylight.yangtools.yang.common.RpcResult;
87 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
88
89 @RunWith(MockitoJUnitRunner.class)
90 public class ItmExternalTunnelAddTest {
91
92     BigInteger dpId1 = BigInteger.valueOf(1);
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     Subnets subnets = 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<BigInteger> bigIntegerList = new ArrayList<>();
136     List<HwVtep> cfgdHwVtepsList = new ArrayList<>();
137     List<Subnets> subnetsList = new ArrayList<>();
138     List<DeviceVteps> deviceVtepsList = new ArrayList<>();
139     List<Vteps> vtepsList = new ArrayList<>();
140     java.lang.Class<? extends TunnelTypeBase> tunnelType1 = TunnelTypeVxlan.class;
141
142     InstanceIdentifier<Interface> interfaceIdentifier = null;
143     InstanceIdentifier<TunnelMonitorParams> TunnelMonitorParamsIdentifier = InstanceIdentifier.create(TunnelMonitorParams.class);
144     InstanceIdentifier<TunnelMonitorInterval> tunnelMonitorIntervalIdentifier = 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 ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
165     @Mock ReadOnlyTransaction mockReadTx;
166     @Mock WriteTransaction mockWriteTx;
167     @Mock IdManagerService idManagerService;
168
169     ItmExternalTunnelAddWorker externalTunnelAddWorker = new ItmExternalTunnelAddWorker();
170
171     @Before
172     public void setUp() throws Exception {
173         when(dataBroker.registerDataChangeListener(
174                 any(LogicalDatastoreType.class),
175                 any(InstanceIdentifier.class),
176                 any(DataChangeListener.class),
177                 any(AsyncDataBroker.DataChangeScope.class)))
178                 .thenReturn(dataChangeListenerRegistration);
179         setupMocks();
180         DataStoreCache.create(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME);
181
182         optionalDpnEndPoints = Optional.of(dpnEndpointsVxlan);
183         TunnelMonitorParamsOptional = Optional.of(TunnelMonitorParams);
184         tunnelMonitorIntervalOptional = Optional.of(tunnelMonitorInterval);
185
186         doReturn(Futures.immediateCheckedFuture(optionalDpnEndPoints)).when(mockReadTx).read(LogicalDatastoreType
187                 .CONFIGURATION,dpnEndpointsIdentifier);
188         doReturn(Futures.immediateCheckedFuture(TunnelMonitorParamsOptional)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
189                 TunnelMonitorParamsIdentifier);
190         doReturn(Futures.immediateCheckedFuture(tunnelMonitorIntervalOptional)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
191                 tunnelMonitorIntervalIdentifier);
192
193     }
194
195     @After
196     public void cleanUp() {
197     }
198
199     private void setupMocks(){
200
201         ipAddress1 = IpAddressBuilder.getDefaultInstance(tepIp1);
202         ipAddress2 = IpAddressBuilder.getDefaultInstance(tepIp2);
203         ipAddress3 = IpAddressBuilder.getDefaultInstance(tepIp3);
204         gtwyIp1 = IpAddressBuilder.getDefaultInstance(gwyIp1);
205         gtwyIp2 = IpAddressBuilder.getDefaultInstance(gwyIp2);
206         ipPrefixTest = IpPrefixBuilder.getDefaultInstance(subnetIp + "/24");
207         tunnelEndPointsVxlan = new TunnelEndPointsBuilder().setVLANID(vlanId).setPortname(portName1).setIpAddress
208                 (ipAddress3).setGwIpAddress(gtwyIp1).setInterfaceName(parentInterfaceName).setTransportZone
209                 (transportZone1).setTunnelType(tunnelType1).setSubnetMask(ipPrefixTest).build();
210         tunnelEndPointsListVxlan.add(tunnelEndPointsVxlan);
211         dpntePsInfoVxlan = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).setKey(new DPNTEPsInfoKey(dpId1))
212                 .setTunnelEndPoints(tunnelEndPointsListVxlan).build();
213         deviceVteps1 = new DeviceVtepsBuilder().setIpAddress(ipAddress1).setKey(new DeviceVtepsKey(ipAddress1,
214                 source)).setNodeId(source).setTopologyId("hwvtep:1").build();
215         deviceVteps2 = new DeviceVtepsBuilder().setIpAddress(ipAddress2).setKey(new DeviceVtepsKey(ipAddress2,
216                 destination)).setNodeId(destination).setTopologyId("hwvtep:1").build();
217         hwVtep1 = new HwVtep();
218         hwVtep1.setTransportZone(transportZone1);
219         hwVtep1.setGatewayIP(gtwyIp1);
220         hwVtep1.setHwIp(ipAddress1);
221         hwVtep1.setTunnel_type(tunnelType1);
222         hwVtep1.setVlanID(vlanId);
223         hwVtep1.setTopo_id("hwvtep:1");
224         hwVtep1.setNode_id(source);
225         hwVtep1.setIpPrefix(ipPrefixTest);
226         cfgdDpnListVxlan.add(dpntePsInfoVxlan);
227         cfgdHwVtepsList.add(hwVtep1);
228         bigIntegerList.add(dpId1);
229         deviceVtepsList.add(deviceVteps1);
230         deviceVtepsList.add(deviceVteps2);
231         vtepsTest = new VtepsBuilder().setDpnId(dpId1).setIpAddress(ipAddress3).setPortname(portName1).setKey(new
232                 VtepsKey(dpId1,portName1)).build();
233         vtepsList.add(vtepsTest);
234         dpnEndpointsVxlan = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListVxlan).build();
235         transportZone = new TransportZoneBuilder().setTunnelType(tunnelType1).setZoneName(transportZone1).setKey(new
236                 TransportZoneKey(transportZone1)).setSubnets(subnetsList).build();
237         idOutputOptional1 = RpcResultBuilder.success(expectedId1).buildFuture();
238         getIdInput1 = new AllocateIdInputBuilder()
239                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
240                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.40:VXLAN").build();
241         doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
242         idOutputOptional2 = RpcResultBuilder.success(expectedId2).buildFuture();
243         getIdInput2 = new AllocateIdInputBuilder()
244                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
245                 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.30:VXLAN").build();
246         doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
247         idOutputOptional3 = RpcResultBuilder.success(expectedId3).buildFuture();
248         getIdInput3 = new AllocateIdInputBuilder()
249                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
250                 .setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.101:VXLAN")
251                 .build();
252         doReturn(idOutputOptional3).when(idManagerService).allocateId(getIdInput3);
253         idOutputOptional4 = RpcResultBuilder.success(expectedId4).buildFuture();
254         getIdInput4 = new AllocateIdInputBuilder()
255                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
256                 .setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.101:VXLAN")
257                 .build();
258         doReturn(idOutputOptional4).when(idManagerService).allocateId(getIdInput4);
259         idOutputOptional5 = RpcResultBuilder.success(expectedId5).buildFuture();
260         getIdInput5 = new AllocateIdInputBuilder()
261                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
262                 .setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.40:VXLAN")
263                 .build();
264         doReturn(idOutputOptional5).when(idManagerService).allocateId(getIdInput5);
265         idOutputOptional6 = RpcResultBuilder.success(expectedId6).buildFuture();
266         getIdInput6 = new AllocateIdInputBuilder()
267                 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
268                 .setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.30:VXLAN")
269                 .build();
270         doReturn(idOutputOptional6).when(idManagerService).allocateId(getIdInput6);
271         TunnelMonitorParams = new TunnelMonitorParamsBuilder().setEnabled(true).build();
272         tunnelMonitorInterval = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
273
274         trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService,parentInterfaceName,
275                 tunnelEndPointsVxlan.getIpAddress().getIpv4Address().getValue(),ipAddress2.getIpv4Address().getValue
276                         (),tunnelType1.getName());
277         interfaceIdentifier = ItmUtils.buildId(trunkInterfaceName);
278         externalTunnelIdentifier = InstanceIdentifier.create(ExternalTunnelList.class)
279                 .child(ExternalTunnel.class, new ExternalTunnelKey(ipAddress2.toString(), dpId1.toString(), tunnelType1));
280         iface = ItmUtils.buildTunnelInterface(dpId1,trunkInterfaceName, String.format("%s %s",
281                 ItmUtils.convertTunnelTypetoString(tunnelType1), "Trunk Interface"),true,tunnelType1,ipAddress3
282                 ,ipAddress2,gtwyIp1,tunnelEndPointsVxlan.getVLANID(),false,false,monitorProtocol,null, false);
283         externalTunnel = ItmUtils.buildExternalTunnel(dpId1.toString(),ipAddress2.toString(),tunnelType1,
284                 trunkInterfaceName);
285         subnets = new SubnetsBuilder().setGatewayIp(gtwyIp1).setVlanId(vlanId).setKey(new SubnetsKey(ipPrefixTest))
286                 .setVteps(vtepsList).setDeviceVteps(deviceVtepsList).build();
287         subnetsList.add(subnets);
288
289         doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
290         doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
291         doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
292
293     }
294
295     @Test
296     public void testBuildTunnelsToExternalEndPoint(){
297
298         externalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker,idManagerService,cfgdDpnListVxlan,
299                 ipAddress2,tunnelType1);
300
301         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
302         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
303
304     }
305
306     @Test
307     public void testBuildTunnelsFromDpnToExternalEndPoint(){
308
309         externalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker,idManagerService,bigIntegerList,
310                 ipAddress2,tunnelType1);
311
312         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
313         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
314
315     }
316
317     @Test
318     public void testBuildHwVtepsTunnels(){
319
320         Interface extTunnelIf1 = ItmUtils.buildTunnelInterface(dpId1, "tun030025bd04f", String.format("%s %s", tunnelType1
321                         .getName(), "Trunk Interface"), true, tunnelType1, tunnelEndPointsVxlan.getIpAddress(), ipAddress1,
322                 gtwyIp1, vlanId, false,false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, false);
323         Interface hwTunnelIf2 = ItmUtils.buildHwTunnelInterface("tun9a55a9c38f2", String.format("%s %s", tunnelType1.getName(),
324                 "Trunk Interface"), true, hwVtep1.getTopo_id(), hwVtep1.getNode_id(), tunnelType1, ipAddress1, ipAddress3, gtwyIp1,
325                 false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
326         Interface extTunnelIf3 = ItmUtils.buildTunnelInterface(dpId1, "tun17c6e20c283", String.format("%s %s", tunnelType1
327                         .getName(), "Trunk Interface"), true, tunnelType1, tunnelEndPointsVxlan.getIpAddress(), ipAddress2,
328                 gtwyIp1, vlanId, false,false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, false);
329         Interface hwTunnelIf4 = ItmUtils.buildHwTunnelInterface("tunaa109b6c8c5", String.format("%s %s", tunnelType1.getName(),
330                 "Trunk Interface"), true, hwVtep1.getTopo_id(), destination, tunnelType1, ipAddress2,
331                 ipAddress3, gtwyIp1, false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
332         Interface hwTunnelIf5 = ItmUtils.buildHwTunnelInterface("tund903ed434d5", String.format("%s %s", tunnelType1.getName(),
333                 "Trunk Interface"), true, hwVtep1.getTopo_id(), hwVtep1.getNode_id(), tunnelType1, ipAddress1,
334                 ipAddress2, gtwyIp1, false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
335         Interface hwTunnelIf6 = ItmUtils.buildHwTunnelInterface("tunc3315b110a6", String.format("%s %s", tunnelType1
336                         .getName(), "Trunk Interface"), true, hwVtep1.getTopo_id(), destination, tunnelType1, ipAddress2,
337                 ipAddress1, gtwyIp1, false, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
338         ExternalTunnel externalTunnel1 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(dpId1.toString()),
339                 getExternalTunnelKey(source), tunnelType1, "tun030025bd04f");
340         ExternalTunnel externalTunnel2 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(source),
341                 getExternalTunnelKey(dpId1.toString()), tunnelType1, "tun9a55a9c38f2");
342         ExternalTunnel externalTunnel3 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(dpId1.toString()),
343                 getExternalTunnelKey(destination), tunnelType1, "tun17c6e20c283");
344         ExternalTunnel externalTunnel4 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(destination),
345                 getExternalTunnelKey(dpId1.toString()), tunnelType1, "tunaa109b6c8c5");
346         ExternalTunnel externalTunnel5 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(source),
347                 getExternalTunnelKey(destination), tunnelType1, "tund903ed434d5");
348         ExternalTunnel externalTunnel6 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(destination),
349                 getExternalTunnelKey(source), tunnelType1, "tunc3315b110a6");
350
351         InstanceIdentifier<TransportZone> transportZoneIdentifier = InstanceIdentifier.builder(TransportZones.class).child
352                 (TransportZone.class, new TransportZoneKey(transportZone1)).build();
353         InstanceIdentifier<Interface> ifIID1 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new
354                 InterfaceKey("tun030025bd04f")).build();
355         InstanceIdentifier<Interface> ifIID2 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
356                 new InterfaceKey("tun9a55a9c38f2")).build();
357         InstanceIdentifier<Interface> ifIID3 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
358                 new InterfaceKey("tun17c6e20c283")).build();
359         InstanceIdentifier<Interface> ifIID4 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
360                 new InterfaceKey("tunaa109b6c8c5")).build();
361         InstanceIdentifier<Interface> ifIID5 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
362                 new InterfaceKey("tund903ed434d5")).build();
363         InstanceIdentifier<Interface> ifIID6 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
364                 new InterfaceKey("tunc3315b110a6")).build();
365         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier1 = InstanceIdentifier.create(ExternalTunnelList
366                 .class).child(ExternalTunnel.class, new ExternalTunnelKey( getExternalTunnelKey(source),
367                 getExternalTunnelKey(dpId1.toString()), tunnelType1));
368         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier2 = InstanceIdentifier.create
369                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dpId1.toString()),
370                 getExternalTunnelKey(source), tunnelType1));
371         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier3 = InstanceIdentifier.create
372                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
373                 (destination), getExternalTunnelKey(dpId1.toString()),
374                 tunnelType1));
375         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier4 = InstanceIdentifier.create
376                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
377                 (dpId1.toString()), getExternalTunnelKey(destination), tunnelType1));
378         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier5 = InstanceIdentifier.create
379                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
380                 (destination), getExternalTunnelKey(source), tunnelType1));
381         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier6 = InstanceIdentifier.create
382                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
383                 (source), getExternalTunnelKey(destination), tunnelType1));
384
385         Optional<TransportZone> optionalTransportZone = Optional.of(transportZone);
386
387         doReturn(Futures.immediateCheckedFuture(optionalTransportZone)).when(mockReadTx).read(LogicalDatastoreType
388                 .CONFIGURATION,transportZoneIdentifier);
389
390         externalTunnelAddWorker.buildHwVtepsTunnels(dataBroker,idManagerService,cfgdDpnListVxlan,null);
391         externalTunnelAddWorker.buildHwVtepsTunnels(dataBroker,idManagerService,null,cfgdHwVtepsList);
392
393         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID1,extTunnelIf1,true);
394         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier1,
395                 externalTunnel1, true);
396         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID2,hwTunnelIf2,true);
397         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier2,
398                 externalTunnel2, true);
399         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID3,extTunnelIf3,true);
400         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier3,
401                 externalTunnel3, true);
402         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID4,hwTunnelIf4,true);
403         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier4,
404                 externalTunnel4, true);
405         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID5,hwTunnelIf5,true);
406         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier5,
407                 externalTunnel5, true);
408         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID6,hwTunnelIf6,true);
409         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier6,
410                 externalTunnel6, true);
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 }