2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.genius.itm.impl;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.Futures;
13 import org.junit.After;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Mock;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
21 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
22 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
23 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.genius.itm.confighelpers.HwVtep;
26 import org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelAddWorker;
27 import org.opendaylight.genius.itm.globals.ITMConstants;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.*;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorInterval;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpoints;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpointsBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info
52 .TunnelEndPointsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.*;
64 import org.opendaylight.yangtools.concepts.ListenerRegistration;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
66 import org.opendaylight.yangtools.yang.common.RpcResult;
67 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
69 import java.math.BigInteger;
70 import java.util.ArrayList;
71 import java.util.List;
72 import java.util.concurrent.Future;
74 import static org.mockito.Matchers.any;
75 import static org.mockito.Mockito.*;
77 @RunWith(MockitoJUnitRunner.class)
78 public class ItmExternalTunnelAddTest {
80 BigInteger dpId1 = BigInteger.valueOf(1);
83 String portName1 = "phy0";
84 String tepIp1 = "192.168.56.30";
85 String tepIp2 = "192.168.56.40";
86 String tepIp3 = "192.168.56.101";
87 String gwyIp1 = "0.0.0.0";
88 String gwyIp2 = "0.0.0.1";
89 String subnetIp = "10.1.1.24";
90 String parentInterfaceName = "1:phy0:100" ;
91 String transportZone1 = "TZA" ;
92 String source = "hwvtep://192.168.101.30:6640/physicalswitch/s3" ;
93 String destination = "hwvtep://192.168.101.40:6640/physicalswitch/s4" ;
94 String trunkInterfaceName = null;
95 TunnelEndPoints tunnelEndPointsVxlan = null;
96 IpAddress ipAddress1 = null;
97 IpAddress ipAddress2 = null;
98 IpAddress ipAddress3 = null;
99 IpAddress gtwyIp1 = null;
100 IpAddress gtwyIp2 = null;
101 IpPrefix ipPrefixTest = null;
102 DPNTEPsInfo dpntePsInfoVxlan = null;
103 ExternalTunnel externalTunnel = null;
104 DpnEndpoints dpnEndpointsVxlan = null;
105 AllocateIdInput getIdInput1 = null;
106 AllocateIdInput getIdInput2 = null;
107 AllocateIdInput getIdInput3 = null;
108 AllocateIdInput getIdInput4 = null;
109 AllocateIdInput getIdInput5 = null;
110 AllocateIdInput getIdInput6 = null;
111 Subnets subnets = null;
112 HwVtep hwVtep1 = null;
113 Vteps vtepsTest = null;
114 DeviceVteps deviceVteps1 = null;
115 DeviceVteps deviceVteps2 = null;
116 TransportZone transportZone = null;
117 TunnelMonitorParams TunnelMonitorParams = null;
118 TunnelMonitorInterval tunnelMonitorInterval = null;
119 Class<? extends TunnelMonitoringTypeBase> monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
120 Interface iface = null;
121 List<DPNTEPsInfo> cfgdDpnListVxlan = new ArrayList<DPNTEPsInfo>() ;
122 List<TunnelEndPoints> tunnelEndPointsListVxlan = new ArrayList<>();
123 List<BigInteger> bigIntegerList = new ArrayList<>();
124 List<HwVtep> cfgdHwVtepsList = new ArrayList<>();
125 List<Subnets> subnetsList = new ArrayList<>();
126 List<DeviceVteps> deviceVtepsList = new ArrayList<>();
127 List<Vteps> vtepsList = new ArrayList<>();
128 java.lang.Class<? extends TunnelTypeBase> tunnelType1 = TunnelTypeVxlan.class;
130 InstanceIdentifier<Interface> interfaceIdentifier = null;
131 InstanceIdentifier<TunnelMonitorParams> TunnelMonitorParamsIdentifier = InstanceIdentifier.create(TunnelMonitorParams.class);
132 InstanceIdentifier<TunnelMonitorInterval> tunnelMonitorIntervalIdentifier = InstanceIdentifier.create(TunnelMonitorInterval.class);
133 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier = null;
134 InstanceIdentifier<DpnEndpoints> dpnEndpointsIdentifier = InstanceIdentifier.builder(DpnEndpoints.class).build();
135 AllocateIdOutput expectedId1 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("100")).build();
136 Future<RpcResult<AllocateIdOutput>> idOutputOptional1 ;
137 AllocateIdOutput expectedId2 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("101")).build();
138 Future<RpcResult<AllocateIdOutput>> idOutputOptional2 ;
139 AllocateIdOutput expectedId3 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("102")).build();
140 Future<RpcResult<AllocateIdOutput>> idOutputOptional3 ;
141 AllocateIdOutput expectedId4 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("103")).build();
142 Future<RpcResult<AllocateIdOutput>> idOutputOptional4 ;
143 AllocateIdOutput expectedId5 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("104")).build();
144 Future<RpcResult<AllocateIdOutput>> idOutputOptional5 ;
145 AllocateIdOutput expectedId6 = new AllocateIdOutputBuilder().setIdValue(Long.valueOf("105")).build();
146 Future<RpcResult<AllocateIdOutput>> idOutputOptional6 ;
147 Optional<DpnEndpoints> optionalDpnEndPoints ;
148 Optional<TunnelMonitorParams> TunnelMonitorParamsOptional ;
149 Optional<TunnelMonitorInterval> tunnelMonitorIntervalOptional ;
151 @Mock DataBroker dataBroker;
152 @Mock ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
153 @Mock ReadOnlyTransaction mockReadTx;
154 @Mock WriteTransaction mockWriteTx;
155 @Mock IdManagerService idManagerService;
157 ItmExternalTunnelAddWorker externalTunnelAddWorker = new ItmExternalTunnelAddWorker();
160 public void setUp() throws Exception {
161 when(dataBroker.registerDataChangeListener(
162 any(LogicalDatastoreType.class),
163 any(InstanceIdentifier.class),
164 any(DataChangeListener.class),
165 any(AsyncDataBroker.DataChangeScope.class)))
166 .thenReturn(dataChangeListenerRegistration);
169 optionalDpnEndPoints = Optional.of(dpnEndpointsVxlan);
170 TunnelMonitorParamsOptional = Optional.of(TunnelMonitorParams);
171 tunnelMonitorIntervalOptional = Optional.of(tunnelMonitorInterval);
173 doReturn(Futures.immediateCheckedFuture(optionalDpnEndPoints)).when(mockReadTx).read(LogicalDatastoreType
174 .CONFIGURATION,dpnEndpointsIdentifier);
175 doReturn(Futures.immediateCheckedFuture(TunnelMonitorParamsOptional)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
176 TunnelMonitorParamsIdentifier);
177 doReturn(Futures.immediateCheckedFuture(tunnelMonitorIntervalOptional)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
178 tunnelMonitorIntervalIdentifier);
183 public void cleanUp() {
186 private void setupMocks(){
188 ipAddress1 = IpAddressBuilder.getDefaultInstance(tepIp1);
189 ipAddress2 = IpAddressBuilder.getDefaultInstance(tepIp2);
190 ipAddress3 = IpAddressBuilder.getDefaultInstance(tepIp3);
191 gtwyIp1 = IpAddressBuilder.getDefaultInstance(gwyIp1);
192 gtwyIp2 = IpAddressBuilder.getDefaultInstance(gwyIp2);
193 ipPrefixTest = IpPrefixBuilder.getDefaultInstance(subnetIp + "/24");
194 tunnelEndPointsVxlan = new TunnelEndPointsBuilder().setVLANID(vlanId).setPortname(portName1).setIpAddress
195 (ipAddress3).setGwIpAddress(gtwyIp1).setInterfaceName(parentInterfaceName).setTransportZone
196 (transportZone1).setTunnelType(tunnelType1).setSubnetMask(ipPrefixTest).build();
197 tunnelEndPointsListVxlan.add(tunnelEndPointsVxlan);
198 dpntePsInfoVxlan = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).setKey(new DPNTEPsInfoKey(dpId1))
199 .setTunnelEndPoints(tunnelEndPointsListVxlan).build();
200 deviceVteps1 = new DeviceVtepsBuilder().setIpAddress(ipAddress1).setKey(new DeviceVtepsKey(ipAddress1,
201 source)).setNodeId(source).setTopologyId("hwvtep:1").build();
202 deviceVteps2 = new DeviceVtepsBuilder().setIpAddress(ipAddress2).setKey(new DeviceVtepsKey(ipAddress2,
203 destination)).setNodeId(destination).setTopologyId("hwvtep:1").build();
204 hwVtep1 = new HwVtep();
205 hwVtep1.setTransportZone(transportZone1);
206 hwVtep1.setGatewayIP(gtwyIp1);
207 hwVtep1.setHwIp(ipAddress1);
208 hwVtep1.setTunnel_type(tunnelType1);
209 hwVtep1.setVlanID(vlanId);
210 hwVtep1.setTopo_id("hwvtep:1");
211 hwVtep1.setNode_id(source);
212 hwVtep1.setIpPrefix(ipPrefixTest);
213 cfgdDpnListVxlan.add(dpntePsInfoVxlan);
214 cfgdHwVtepsList.add(hwVtep1);
215 bigIntegerList.add(dpId1);
216 deviceVtepsList.add(deviceVteps1);
217 deviceVtepsList.add(deviceVteps2);
218 vtepsTest = new VtepsBuilder().setDpnId(dpId1).setIpAddress(ipAddress3).setPortname(portName1).setKey(new
219 VtepsKey(dpId1,portName1)).build();
220 vtepsList.add(vtepsTest);
221 dpnEndpointsVxlan = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListVxlan).build();
222 transportZone = new TransportZoneBuilder().setTunnelType(tunnelType1).setZoneName(transportZone1).setKey(new
223 TransportZoneKey(transportZone1)).setSubnets(subnetsList).build();
224 idOutputOptional1 = RpcResultBuilder.success(expectedId1).buildFuture();
225 getIdInput1 = new AllocateIdInputBuilder()
226 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
227 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.40:VXLAN").build();
228 doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
229 idOutputOptional2 = RpcResultBuilder.success(expectedId2).buildFuture();
230 getIdInput2 = new AllocateIdInputBuilder()
231 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
232 .setIdKey("1:phy0:100:192.168.56.101:192.168.56.30:VXLAN").build();
233 doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
234 idOutputOptional3 = RpcResultBuilder.success(expectedId3).buildFuture();
235 getIdInput3 = new AllocateIdInputBuilder()
236 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
237 .setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.101:VXLAN")
239 doReturn(idOutputOptional3).when(idManagerService).allocateId(getIdInput3);
240 idOutputOptional4 = RpcResultBuilder.success(expectedId4).buildFuture();
241 getIdInput4 = new AllocateIdInputBuilder()
242 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
243 .setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.101:VXLAN")
245 doReturn(idOutputOptional4).when(idManagerService).allocateId(getIdInput4);
246 idOutputOptional5 = RpcResultBuilder.success(expectedId5).buildFuture();
247 getIdInput5 = new AllocateIdInputBuilder()
248 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
249 .setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.40:VXLAN")
251 doReturn(idOutputOptional5).when(idManagerService).allocateId(getIdInput5);
252 idOutputOptional6 = RpcResultBuilder.success(expectedId6).buildFuture();
253 getIdInput6 = new AllocateIdInputBuilder()
254 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
255 .setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.30:VXLAN")
257 doReturn(idOutputOptional6).when(idManagerService).allocateId(getIdInput6);
258 TunnelMonitorParams = new TunnelMonitorParamsBuilder().setEnabled(true).build();
259 tunnelMonitorInterval = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
261 trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService,parentInterfaceName,
262 tunnelEndPointsVxlan.getIpAddress().getIpv4Address().getValue(),ipAddress2.getIpv4Address().getValue
263 (),tunnelType1.getName());
264 interfaceIdentifier = ItmUtils.buildId(trunkInterfaceName);
265 externalTunnelIdentifier = InstanceIdentifier.create(ExternalTunnelList.class)
266 .child(ExternalTunnel.class, new ExternalTunnelKey(ipAddress2.toString(), dpId1.toString(), tunnelType1));
267 iface = ItmUtils.buildTunnelInterface(dpId1,trunkInterfaceName, String.format("%s %s",
268 ItmUtils.convertTunnelTypetoString(tunnelType1), "Trunk Interface"),true,tunnelType1,ipAddress3
269 ,ipAddress2,gtwyIp1,tunnelEndPointsVxlan.getVLANID(),false,false,monitorProtocol,null);
270 externalTunnel = ItmUtils.buildExternalTunnel(dpId1.toString(),ipAddress2.toString(),tunnelType1,
272 subnets = new SubnetsBuilder().setGatewayIp(gtwyIp1).setVlanId(vlanId).setKey(new SubnetsKey(ipPrefixTest))
273 .setVteps(vtepsList).setDeviceVteps(deviceVtepsList).build();
274 subnetsList.add(subnets);
276 doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
277 doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
278 doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
283 public void testBuildTunnelsToExternalEndPoint(){
285 externalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker,idManagerService,cfgdDpnListVxlan,
286 ipAddress2,tunnelType1);
288 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
289 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
294 public void testBuildTunnelsFromDpnToExternalEndPoint(){
296 externalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker,idManagerService,bigIntegerList,
297 ipAddress2,tunnelType1);
299 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
300 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
305 public void testBuildHwVtepsTunnels(){
307 Interface extTunnelIf1 = ItmUtils.buildTunnelInterface(dpId1, "TUNNEL:101", String.format("%s %s", tunnelType1
308 .getName(), "Trunk Interface"), true, tunnelType1, tunnelEndPointsVxlan.getIpAddress(), ipAddress1,
309 gtwyIp1, vlanId, false,true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
310 Interface hwTunnelIf2 = ItmUtils.buildHwTunnelInterface("TUNNEL:102", String.format("%s %s", tunnelType1.getName(),
311 "Trunk Interface"), true, hwVtep1.getTopo_id(), hwVtep1.getNode_id(), tunnelType1, ipAddress1, ipAddress3, gtwyIp1,
312 true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
313 Interface extTunnelIf3 = ItmUtils.buildTunnelInterface(dpId1, "TUNNEL:100", String.format("%s %s", tunnelType1
314 .getName(), "Trunk Interface"), true, tunnelType1, tunnelEndPointsVxlan.getIpAddress(), ipAddress2,
315 gtwyIp1, vlanId, false,true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
316 Interface hwTunnelIf4 = ItmUtils.buildHwTunnelInterface("TUNNEL:103", String.format("%s %s", tunnelType1.getName(),
317 "Trunk Interface"), true, hwVtep1.getTopo_id(), destination, tunnelType1, ipAddress2,
318 ipAddress3, gtwyIp1, true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
319 Interface hwTunnelIf5 = ItmUtils.buildHwTunnelInterface("TUNNEL:104", String.format("%s %s", tunnelType1.getName(),
320 "Trunk Interface"), true, hwVtep1.getTopo_id(), hwVtep1.getNode_id(), tunnelType1, ipAddress1,
321 ipAddress2, gtwyIp1, true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
322 Interface hwTunnelIf6 = ItmUtils.buildHwTunnelInterface("TUNNEL:105", String.format("%s %s", tunnelType1
323 .getName(), "Trunk Interface"), true, hwVtep1.getTopo_id(), destination, tunnelType1, ipAddress2,
324 ipAddress1, gtwyIp1, true, monitorProtocol, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL);
325 ExternalTunnel externalTunnel1 = ItmUtils.buildExternalTunnel( getExternalTunnelKey(dpId1.toString()),
326 getExternalTunnelKey(source), tunnelType1, "TUNNEL:101");
327 ExternalTunnel externalTunnel2 = ItmUtils.buildExternalTunnel( getExternalTunnelKey(source),
328 getExternalTunnelKey(dpId1.toString()), tunnelType1, "TUNNEL:102");
329 ExternalTunnel externalTunnel3 = ItmUtils.buildExternalTunnel( getExternalTunnelKey(dpId1.toString()),
330 getExternalTunnelKey(destination), tunnelType1, "TUNNEL:100");
331 ExternalTunnel externalTunnel4 = ItmUtils.buildExternalTunnel( getExternalTunnelKey(destination),
332 getExternalTunnelKey(dpId1.toString()), tunnelType1, "TUNNEL:103");
333 ExternalTunnel externalTunnel5 = ItmUtils.buildExternalTunnel( getExternalTunnelKey(source),
334 getExternalTunnelKey(destination), tunnelType1, "TUNNEL:104");
335 ExternalTunnel externalTunnel6 = ItmUtils.buildExternalTunnel( getExternalTunnelKey(destination),
336 getExternalTunnelKey(source), tunnelType1, "TUNNEL:105");
338 InstanceIdentifier<TransportZone> transportZoneIdentifier = InstanceIdentifier.builder(TransportZones.class).child
339 (TransportZone.class, new TransportZoneKey(transportZone1)).build();
340 InstanceIdentifier<Interface> ifIID1 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new
341 InterfaceKey("TUNNEL:101")).build();
342 InstanceIdentifier<Interface> ifIID2 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
343 new InterfaceKey("TUNNEL:102")).build();
344 InstanceIdentifier<Interface> ifIID3 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
345 new InterfaceKey("TUNNEL:100")).build();
346 InstanceIdentifier<Interface> ifIID4 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
347 new InterfaceKey("TUNNEL:103")).build();
348 InstanceIdentifier<Interface> ifIID5 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
349 new InterfaceKey("TUNNEL:104")).build();
350 InstanceIdentifier<Interface> ifIID6 = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
351 new InterfaceKey("TUNNEL:105")).build();
352 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier1 = InstanceIdentifier.create(ExternalTunnelList
353 .class).child(ExternalTunnel.class, new ExternalTunnelKey( getExternalTunnelKey(source),
354 getExternalTunnelKey(dpId1.toString()), tunnelType1));
355 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier2 = InstanceIdentifier.create
356 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dpId1.toString()),
357 getExternalTunnelKey(source), tunnelType1));
358 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier3 = InstanceIdentifier.create
359 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
360 (destination), getExternalTunnelKey(dpId1.toString()),
362 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier4 = InstanceIdentifier.create
363 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
364 (dpId1.toString()), getExternalTunnelKey(destination), tunnelType1));
365 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier5 = InstanceIdentifier.create
366 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
367 (destination), getExternalTunnelKey(source), tunnelType1));
368 InstanceIdentifier<ExternalTunnel> externalTunnelIdentifier6 = InstanceIdentifier.create
369 (ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey
370 (source), getExternalTunnelKey(destination), tunnelType1));
372 Optional<TransportZone> optionalTransportZone = Optional.of(transportZone);
374 doReturn(Futures.immediateCheckedFuture(optionalTransportZone)).when(mockReadTx).read(LogicalDatastoreType
375 .CONFIGURATION,transportZoneIdentifier);
377 externalTunnelAddWorker.buildHwVtepsTunnels(dataBroker,idManagerService,cfgdDpnListVxlan,null);
378 externalTunnelAddWorker.buildHwVtepsTunnels(dataBroker,idManagerService,null,cfgdHwVtepsList);
380 verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID1,extTunnelIf1,true);
381 verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID2,hwTunnelIf2,true);
382 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID3,extTunnelIf3,true);
383 verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier1,
384 externalTunnel1, true);
385 verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier2,
386 externalTunnel2, true);
387 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier3,
388 externalTunnel3, true);
389 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID5,hwTunnelIf5,true);
390 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID4,hwTunnelIf4,true);
391 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier4,
392 externalTunnel4, true);
393 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier5,
394 externalTunnel5, true);
395 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID6,hwTunnelIf6,true);
396 verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier6,
397 externalTunnel6, true);
401 static String getExternalTunnelKey(String nodeid) {
402 if (nodeid.indexOf("physicalswitch") > 0) {
403 nodeid = nodeid.substring(0, nodeid.indexOf("physicalswitch") - 1);