Merge "Make ActionInfo immutable"
[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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
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.TunnelMonitorInterval;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpoints;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpointsBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info
64         .TunnelEndPoints;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info
66         .TunnelEndPointsBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone
75         .SubnetsBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey;
83 import org.opendaylight.yangtools.concepts.ListenerRegistration;
84 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
85 import org.opendaylight.yangtools.yang.common.RpcResult;
86 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
87
88 @RunWith(MockitoJUnitRunner.class)
89 public class ItmExternalTunnelAddTest {
90
91     BigInteger dpId1 = BigInteger.valueOf(1);
92     int vlanId = 100 ;
93     int interval = 1000;
94     String portName1 = "phy0";
95     String tepIp1 = "192.168.56.30";
96     String tepIp2 = "192.168.56.40";
97     String tepIp3 = "192.168.56.101";
98     String gwyIp1 = "0.0.0.0";
99     String gwyIp2 = "0.0.0.1";
100     String subnetIp = "10.1.1.24";
101     String parentInterfaceName = "1:phy0:100" ;
102     String transportZone1 = "TZA" ;
103     String source = "hwvtep://192.168.101.30:6640/physicalswitch/s3" ;
104     String destination = "hwvtep://192.168.101.40:6640/physicalswitch/s4" ;
105     String trunkInterfaceName = null;
106     TunnelEndPoints tunnelEndPointsVxlan = null;
107     IpAddress ipAddress1 = null;
108     IpAddress ipAddress2 = null;
109     IpAddress ipAddress3 = null;
110     IpAddress gtwyIp1 = null;
111     IpAddress gtwyIp2 = null;
112     IpPrefix ipPrefixTest = null;
113     DPNTEPsInfo dpntePsInfoVxlan = null;
114     ExternalTunnel externalTunnel = null;
115     DpnEndpoints dpnEndpointsVxlan = null;
116     AllocateIdInput getIdInput1 = null;
117     AllocateIdInput getIdInput2 = null;
118     AllocateIdInput getIdInput3 = null;
119     AllocateIdInput getIdInput4 = null;
120     AllocateIdInput getIdInput5 = null;
121     AllocateIdInput getIdInput6 = null;
122     Subnets subnets = 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<BigInteger> bigIntegerList = new ArrayList<>();
135     List<HwVtep> cfgdHwVtepsList = new ArrayList<>();
136     List<Subnets> subnetsList = 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> TunnelMonitorParamsIdentifier = InstanceIdentifier.create(TunnelMonitorParams.class);
143     InstanceIdentifier<TunnelMonitorInterval> tunnelMonitorIntervalIdentifier = InstanceIdentifier.create(TunnelMonitorInterval.class);
144     InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier = null;
145     InstanceIdentifier<DpnEndpoints> dpnEndpointsIdentifier = InstanceIdentifier.builder(DpnEndpoints.class).build();
146     AllocateIdOutput expectedId1 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("100")).build();
147     Future<RpcResult<AllocateIdOutput>> idOutputOptional1 ;
148     AllocateIdOutput expectedId2 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("101")).build();
149     Future<RpcResult<AllocateIdOutput>> idOutputOptional2 ;
150     AllocateIdOutput expectedId3 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("102")).build();
151     Future<RpcResult<AllocateIdOutput>> idOutputOptional3 ;
152     AllocateIdOutput expectedId4 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("103")).build();
153     Future<RpcResult<AllocateIdOutput>> idOutputOptional4 ;
154     AllocateIdOutput expectedId5 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("104")).build();
155     Future<RpcResult<AllocateIdOutput>> idOutputOptional5 ;
156     AllocateIdOutput expectedId6 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("105")).build();
157     Future<RpcResult<AllocateIdOutput>> idOutputOptional6 ;
158     Optional<DpnEndpoints> optionalDpnEndPoints ;
159     Optional<TunnelMonitorParams> TunnelMonitorParamsOptional ;
160     Optional<TunnelMonitorInterval> tunnelMonitorIntervalOptional ;
161
162     @Mock DataBroker dataBroker;
163     @Mock ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
164     @Mock ReadOnlyTransaction mockReadTx;
165     @Mock WriteTransaction mockWriteTx;
166     @Mock IdManagerService idManagerService;
167
168     ItmExternalTunnelAddWorker externalTunnelAddWorker = new ItmExternalTunnelAddWorker();
169
170     @Before
171     public void setUp() throws Exception {
172         when(dataBroker.registerDataChangeListener(
173                 any(LogicalDatastoreType.class),
174                 any(InstanceIdentifier.class),
175                 any(DataChangeListener.class),
176                 any(AsyncDataBroker.DataChangeScope.class)))
177                 .thenReturn(dataChangeListenerRegistration);
178         setupMocks();
179
180         optionalDpnEndPoints = Optional.of(dpnEndpointsVxlan);
181         TunnelMonitorParamsOptional = Optional.of(TunnelMonitorParams);
182         tunnelMonitorIntervalOptional = Optional.of(tunnelMonitorInterval);
183
184         doReturn(Futures.immediateCheckedFuture(optionalDpnEndPoints)).when(mockReadTx).read(LogicalDatastoreType
185                 .CONFIGURATION,dpnEndpointsIdentifier);
186         doReturn(Futures.immediateCheckedFuture(TunnelMonitorParamsOptional)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
187                 TunnelMonitorParamsIdentifier);
188         doReturn(Futures.immediateCheckedFuture(tunnelMonitorIntervalOptional)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
189                 tunnelMonitorIntervalIdentifier);
190
191     }
192
193     @After
194     public void cleanUp() {
195     }
196
197     private void setupMocks(){
198
199         ipAddress1 = IpAddressBuilder.getDefaultInstance(tepIp1);
200         ipAddress2 = IpAddressBuilder.getDefaultInstance(tepIp2);
201         ipAddress3 = IpAddressBuilder.getDefaultInstance(tepIp3);
202         gtwyIp1 = IpAddressBuilder.getDefaultInstance(gwyIp1);
203         gtwyIp2 = IpAddressBuilder.getDefaultInstance(gwyIp2);
204         ipPrefixTest = IpPrefixBuilder.getDefaultInstance(subnetIp + "/24");
205         tunnelEndPointsVxlan = new TunnelEndPointsBuilder().setVLANID(vlanId).setPortname(portName1).setIpAddress
206                 (ipAddress3).setGwIpAddress(gtwyIp1).setInterfaceName(parentInterfaceName).setTransportZone
207                 (transportZone1).setTunnelType(tunnelType1).setSubnetMask(ipPrefixTest).build();
208         tunnelEndPointsListVxlan.add(tunnelEndPointsVxlan);
209         dpntePsInfoVxlan = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).setKey(new DPNTEPsInfoKey(dpId1))
210                 .setTunnelEndPoints(tunnelEndPointsListVxlan).build();
211         deviceVteps1 = new DeviceVtepsBuilder().setIpAddress(ipAddress1).setKey(new DeviceVtepsKey(ipAddress1,
212                 source)).setNodeId(source).setTopologyId("hwvtep:1").build();
213         deviceVteps2 = new DeviceVtepsBuilder().setIpAddress(ipAddress2).setKey(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.setTunnel_type(tunnelType1);
220         hwVtep1.setVlanID(vlanId);
221         hwVtep1.setTopo_id("hwvtep:1");
222         hwVtep1.setNode_id(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).setPortname(portName1).setKey(new
230                 VtepsKey(dpId1,portName1)).build();
231         vtepsList.add(vtepsTest);
232         dpnEndpointsVxlan = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListVxlan).build();
233         transportZone = new TransportZoneBuilder().setTunnelType(tunnelType1).setZoneName(transportZone1).setKey(new
234                 TransportZoneKey(transportZone1)).setSubnets(subnetsList).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         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         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         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         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         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         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(idManagerService,parentInterfaceName,
273                 tunnelEndPointsVxlan.getIpAddress().getIpv4Address().getValue(),ipAddress2.getIpv4Address().getValue
274                         (),tunnelType1.getName());
275         interfaceIdentifier = ItmUtils.buildId(trunkInterfaceName);
276         externalTunnelIdentifier = InstanceIdentifier.create(ExternalTunnelList.class)
277                 .child(ExternalTunnel.class, new ExternalTunnelKey(ipAddress2.toString(), dpId1.toString(), tunnelType1));
278         iface = ItmUtils.buildTunnelInterface(dpId1,trunkInterfaceName, String.format("%s %s",
279                 ItmUtils.convertTunnelTypetoString(tunnelType1), "Trunk Interface"),true,tunnelType1,ipAddress3
280                 ,ipAddress2,gtwyIp1,tunnelEndPointsVxlan.getVLANID(),false,false,monitorProtocol,null);
281         externalTunnel = ItmUtils.buildExternalTunnel(dpId1.toString(),ipAddress2.toString(),tunnelType1,
282                 trunkInterfaceName);
283         subnets = new SubnetsBuilder().setGatewayIp(gtwyIp1).setVlanId(vlanId).setKey(new SubnetsKey(ipPrefixTest))
284                 .setVteps(vtepsList).setDeviceVteps(deviceVtepsList).build();
285         subnetsList.add(subnets);
286
287         doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
288         doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
289         doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
290
291     }
292
293     @Test
294     public void testBuildTunnelsToExternalEndPoint(){
295
296         externalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker,idManagerService,cfgdDpnListVxlan,
297                 ipAddress2,tunnelType1);
298
299         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
300         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
301
302     }
303
304     @Test
305     public void testBuildTunnelsFromDpnToExternalEndPoint(){
306
307         externalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker,idManagerService,bigIntegerList,
308                 ipAddress2,tunnelType1);
309
310         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
311         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
312
313     }
314
315     @Test
316     public void testBuildHwVtepsTunnels(){
317
318         Interface extTunnelIf1 = ItmUtils.buildTunnelInterface(dpId1, "tun030025bd04f", String.format("%s %s", tunnelType1
319                         .getName(), "Trunk Interface"), true, tunnelType1, tunnelEndPointsVxlan.getIpAddress(), ipAddress1,
320                 gtwyIp1, vlanId, false,true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
321         Interface hwTunnelIf2 = ItmUtils.buildHwTunnelInterface("tun9a55a9c38f2", String.format("%s %s", tunnelType1.getName(),
322                 "Trunk Interface"), true, hwVtep1.getTopo_id(), hwVtep1.getNode_id(), tunnelType1, ipAddress1, ipAddress3, gtwyIp1,
323                 true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
324         Interface extTunnelIf3 = ItmUtils.buildTunnelInterface(dpId1, "tun17c6e20c283", String.format("%s %s", tunnelType1
325                         .getName(), "Trunk Interface"), true, tunnelType1, tunnelEndPointsVxlan.getIpAddress(), ipAddress2,
326                 gtwyIp1, vlanId, false,true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
327         Interface hwTunnelIf4 = ItmUtils.buildHwTunnelInterface("tunaa109b6c8c5", String.format("%s %s", tunnelType1.getName(),
328                 "Trunk Interface"), true, hwVtep1.getTopo_id(), destination, tunnelType1, ipAddress2,
329                 ipAddress3, gtwyIp1, true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
330         Interface hwTunnelIf5 = ItmUtils.buildHwTunnelInterface("tund903ed434d5", String.format("%s %s", tunnelType1.getName(),
331                 "Trunk Interface"), true, hwVtep1.getTopo_id(), hwVtep1.getNode_id(), tunnelType1, ipAddress1,
332                 ipAddress2, gtwyIp1, true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
333         Interface hwTunnelIf6 = ItmUtils.buildHwTunnelInterface("tunc3315b110a6", String.format("%s %s", tunnelType1
334                         .getName(), "Trunk Interface"), true, hwVtep1.getTopo_id(), destination, tunnelType1, ipAddress2,
335                 ipAddress1, gtwyIp1, true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
336         ExternalTunnel externalTunnel1 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(dpId1.toString()),
337                 getExternalTunnelKey(source), tunnelType1, "tun030025bd04f");
338         ExternalTunnel externalTunnel2 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(source),
339                 getExternalTunnelKey(dpId1.toString()), tunnelType1, "tun9a55a9c38f2");
340         ExternalTunnel externalTunnel3 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(dpId1.toString()),
341                 getExternalTunnelKey(destination), tunnelType1, "tun17c6e20c283");
342         ExternalTunnel externalTunnel4 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(destination),
343                 getExternalTunnelKey(dpId1.toString()), tunnelType1, "tunaa109b6c8c5");
344         ExternalTunnel externalTunnel5 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(source),
345                 getExternalTunnelKey(destination), tunnelType1, "tund903ed434d5");
346         ExternalTunnel externalTunnel6 = ItmUtils.buildExternalTunnel(  getExternalTunnelKey(destination),
347                 getExternalTunnelKey(source), tunnelType1, "tunc3315b110a6");
348
349         InstanceIdentifier<TransportZone> transportZoneIdentifier = InstanceIdentifier.builder(TransportZones.class).child
350                 (TransportZone.class, new TransportZoneKey(transportZone1)).build();
351         InstanceIdentifier<Interface> ifIID1 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new
352                 InterfaceKey("tun030025bd04f")).build();
353         InstanceIdentifier<Interface> ifIID2 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
354                 new InterfaceKey("tun9a55a9c38f2")).build();
355         InstanceIdentifier<Interface> ifIID3 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
356                 new InterfaceKey("tun17c6e20c283")).build();
357         InstanceIdentifier<Interface> ifIID4 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
358                 new InterfaceKey("tunaa109b6c8c5")).build();
359         InstanceIdentifier<Interface> ifIID5 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
360                 new InterfaceKey("tund903ed434d5")).build();
361         InstanceIdentifier<Interface> ifIID6 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
362                 new InterfaceKey("tunc3315b110a6")).build();
363         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier1 = InstanceIdentifier.create(ExternalTunnelList
364                 .class).child(ExternalTunnel.class, new ExternalTunnelKey( getExternalTunnelKey(source),
365                 getExternalTunnelKey(dpId1.toString()), tunnelType1));
366         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier2 = InstanceIdentifier.create
367                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dpId1.toString()),
368                 getExternalTunnelKey(source), tunnelType1));
369         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier3 = InstanceIdentifier.create
370                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
371                 (destination), getExternalTunnelKey(dpId1.toString()),
372                 tunnelType1));
373         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier4 = InstanceIdentifier.create
374                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
375                 (dpId1.toString()), getExternalTunnelKey(destination), tunnelType1));
376         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier5 = InstanceIdentifier.create
377                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
378                 (destination), getExternalTunnelKey(source), tunnelType1));
379         InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier6 = InstanceIdentifier.create
380                 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
381                 (source), getExternalTunnelKey(destination), tunnelType1));
382
383         Optional<TransportZone> optionalTransportZone = Optional.of(transportZone);
384
385         doReturn(Futures.immediateCheckedFuture(optionalTransportZone)).when(mockReadTx).read(LogicalDatastoreType
386                 .CONFIGURATION,transportZoneIdentifier);
387
388         externalTunnelAddWorker.buildHwVtepsTunnels(dataBroker,idManagerService,cfgdDpnListVxlan,null);
389         externalTunnelAddWorker.buildHwVtepsTunnels(dataBroker,idManagerService,null,cfgdHwVtepsList);
390
391         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID1,extTunnelIf1,true);
392         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier1,
393                 externalTunnel1, true);
394         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID2,hwTunnelIf2,true);
395         verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier2,
396                 externalTunnel2, true);
397         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID3,extTunnelIf3,true);
398         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier3,
399                 externalTunnel3, true);
400         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID4,hwTunnelIf4,true);
401         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier4,
402                 externalTunnel4, true);
403         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID5,hwTunnelIf5,true);
404         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier5,
405                 externalTunnel5, true);
406         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID6,hwTunnelIf6,true);
407         verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier6,
408                 externalTunnel6, true);
409
410     }
411
412     static String getExternalTunnelKey(String nodeid) {
413         if (nodeid.indexOf("physicalswitch") > 0) {
414             nodeid = nodeid.substring(0, nodeid.indexOf("physicalswitch") - 1);
415         }
416         return nodeid;
417     }
418 }