Bump odlparent->6.0.0,mdsal->5.0.3
[netvirt.git] / elanmanager / impl / src / test / java / org / opendaylight / netvirt / elanmanager / tests / ElanServiceTestBase.java
1 /*
2  * Copyright © 2017 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.netvirt.elanmanager.tests;
9
10 import com.google.common.collect.Lists;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Comparator;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.concurrent.TimeUnit;
18 import javax.inject.Inject;
19 import org.apache.commons.lang3.tuple.ImmutablePair;
20 import org.apache.commons.lang3.tuple.Pair;
21 import org.awaitility.Awaitility;
22 import org.awaitility.core.ConditionFactory;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
26 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
27 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
28 import org.opendaylight.genius.mdsalutil.MDSALUtil;
29 import org.opendaylight.genius.testutils.TestInterfaceManager;
30 import org.opendaylight.genius.testutils.interfacemanager.TunnelInterfaceDetails;
31 import org.opendaylight.genius.testutils.itm.ItmRpcTestImpl;
32 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
33 import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
34 import org.opendaylight.netvirt.elan.utils.ElanUtils;
35 import org.opendaylight.netvirt.elanmanager.api.ElanHelper;
36 import org.opendaylight.netvirt.elanmanager.tests.utils.InterfaceHelper;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Ordered;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntriesBuilder;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
73 import org.opendaylight.yangtools.yang.binding.DataObject;
74 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
75 import org.opendaylight.yangtools.yang.common.Uint32;
76 import org.opendaylight.yangtools.yang.common.Uint64;
77
78 public class ElanServiceTestBase {
79
80     protected  @Inject DataBroker dataBroker;
81     protected  @Inject TestInterfaceManager interfaceMgr;
82     protected  @Inject ItmRpcTestImpl itmRpc;
83     protected  @Inject ElanInstanceManager elanInstanceManager;
84     protected  @Inject ElanInstanceCache elanInstanceCache;
85     protected @Inject SingleTransactionDataBroker singleTxdataBroker;
86     protected @Inject OdlInterfaceRpcService odlInterfaceRpcService;
87     public static final String ELAN1 = "34701c04-1118-4c65-9425-78a80d49a211";
88     public static final Uint32 ELAN1_SEGMENT_ID = Uint32.valueOf(100L);
89
90     protected static final Uint64 DPN1_ID = Uint64.valueOf("1").intern();
91     protected static final Uint64 DPN2_ID = Uint64.valueOf("2").intern();
92     protected static final Uint64 DPN3_ID = Uint64.valueOf("3").intern();
93
94     protected static final String DPN1_ID_STR = "1";
95     protected static final String DPN2_ID_STR = "2";
96     protected static final String DPN3_ID_STR = "3";
97
98     protected static final String DPN1_TEPIP = "192.168.56.30";
99     protected static final String DPN2_TEPIP = "192.168.56.40";
100     protected static final String DPN3_TEPIP = "192.168.56.50";
101     protected static final String TOR1_TEPIP = "192.168.56.60";
102     protected static final String TOR2_TEPIP = "192.168.56.70";
103     public static final String DCGW_TEPIP = "192.168.56.80";
104
105     protected static final String DPN1MAC1 = "10:00:00:00:00:01";
106     protected static final String DPN1MAC2 = "10:00:00:00:00:02";
107
108     protected static final String DPN2MAC1 = "10:00:00:00:00:03";
109     protected static final String DPN2MAC2 = "10:00:00:00:00:04";
110
111     protected static final String DPN3MAC1 = "10:00:00:00:00:05";
112     protected static final String DPN3MAC2 = "10:00:00:00:00:06";
113
114     protected static final String TOR1_MAC1 = "10:00:00:00:00:07";
115     protected static final String TOR1_IP1 = "10.0.0.1";
116     protected static final String TOR1_MAC2 = "10:00:00:00:00:08";
117     protected static final String TOR1_IP2 = "10.0.0.2";
118
119     protected static final String TOR2_MAC1 = "10:00:00:00:00:09";
120     protected static final String TOR2_MAC2 = "10:00:00:00:00:10";
121
122     protected static final String DPN1_TO_DPN2TNL_MAC = "91:00:00:00:00:01";
123     protected static final String DPN1_TO_TOR1TNL_MAC = "91:00:00:00:00:02";
124     protected static final String DPN1_TO_DCGWTNL_MAC = "91:00:00:00:00:03";
125     protected static final String DPN1_TO_DPN3_TNL_MAC = "91:00:00:00:00:04";
126
127     protected static final String DPN2_TO_DPN1_TNL_MAC = "92:00:00:00:00:01";
128     protected static final String DPN2_TO_TOR1_TNL_MAC = "92:00:00:00:00:02";
129     protected static final String DPN2_TO_DCGW_TNL_MAC = "92:00:00:00:00:03";
130     protected static final String DPN2_TO_DPN3_TNL_MAC = "92:00:00:00:00:04";
131
132     protected static final String DPN3_TO_DPN1_TNL_MAC = "93:00:00:00:00:01";
133     protected static final String DPN3_TO_DPN2_TNL_MAC = "93:00:00:00:00:02";
134     protected static final String DPN3_TO_TOR1_TNL_MAC = "93:00:00:00:00:03";
135
136     protected static final String DPN1_TO_TOR2_TNL_MAC = "94:00:00:00:00:01";
137     protected static final String DPN2_TO_TOR2_TNL_MAC = "94:00:00:00:00:02";
138     protected static final String DPN3_TO_TOR2_TNL_MAC = "94:00:00:00:00:03";
139
140
141     protected static final String DPN1IP1 = "10.0.0.11";
142     protected static final String DPN1IP2 = "10.0.0.12";
143     protected static final String DPN2IP1 = "10.0.0.13";
144     protected static final String DPN2IP2 = "10.0.0.14";
145     protected static final String DPN3IP1 = "10.0.0.15";
146     protected static final String DPN3IP2 = "10.0.0.16";
147
148     protected static final String EVPNRECVMAC1 = "10:00:00:00:00:51";
149     protected static final String EVPNRECVMAC2 = "10:00:00:00:00:52";
150
151     protected static final String EVPNRECVIP1 = "192.168.122.51";
152     protected static final String EVPNRECVIP2 = "192.168.122.52";
153
154     protected static final String TOR1_NODE_ID = "hwvtep://uuid/34701c04-1118-4c65-9425-78a80d49a211";
155     protected static final String TOR2_NODE_ID = "hwvtep://uuid/34701c04-1118-4c65-9425-78a80d49a212";
156
157     protected static final String L2GW1 = "l2gw1";
158     protected static final String L2GW2 = "l2gw2";
159     protected static final String L2GW_CONN1 = "l2gwConnection1";
160     protected static final String L2GW_CONN2 = "l2gwConnection2";
161     protected static final String PS1 = "ps1";
162     protected static final String PS2 = "ps2";
163
164     protected static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params
165             .xml.ns.yang.network.topology.rev131021.network.topology.topology.Node>
166             TOR1_NODE_IID = createInstanceIdentifier(TOR1_NODE_ID);
167     protected static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params
168             .xml.ns.yang.network.topology.rev131021.network.topology.topology.Node>
169             TOR2_NODE_IID = createInstanceIdentifier(TOR2_NODE_ID);
170
171     protected static final String DCGWID = DCGW_TEPIP;
172
173     public static final String RD = "100:1";
174     public static final String EVPN1 = "evpn1";
175
176     protected static Map<String, Pair<InterfaceInfo, String>> ELAN_INTERFACES = new HashMap<>();
177     protected static Map<String, TunnelInterfaceDetails> EXTN_INTFS = new HashMap<>();
178
179     static {
180         //Adding elan dpn macs
181         /*ELAN1+":"+DPN1MAC1 ->
182         (vlanInterfaceInfo(String interfaceName, BigInteger dpId, int portNo, int lportTag, String mac), vmPrefix)*/
183         ELAN_INTERFACES.put(ELAN1 + ":" + DPN1MAC1 ,
184                 ImmutablePair.of(InterfaceHelper
185                         .buildVlanInterfaceInfo("23701c04-1118-4c65-9425-78a80d49a211",
186                 DPN1_ID, 1, 10, DPN1MAC1), DPN1IP1));
187
188         ELAN_INTERFACES.put(ELAN1 + ":" + DPN1MAC2 ,
189                 ImmutablePair.of(InterfaceHelper
190                         .buildVlanInterfaceInfo("23701c04-1218-4c65-9425-78a80d49a211",
191                 DPN1_ID, 2, 11, DPN1MAC2), DPN1IP2));
192
193         ELAN_INTERFACES.put(ELAN1 + ":" + DPN2MAC1 ,
194                 ImmutablePair.of(InterfaceHelper
195                         .buildVlanInterfaceInfo("23701c04-2118-4c65-9425-78a80d49a211",
196                         DPN2_ID, 3, 12, DPN2MAC1), DPN2IP1));
197
198         ELAN_INTERFACES.put(ELAN1 + ":" + DPN2MAC2 ,
199                 ImmutablePair.of(InterfaceHelper
200                         .buildVlanInterfaceInfo("23701c04-2218-4c65-9425-78a80d49a211",
201                         DPN2_ID, 4, 13, DPN2MAC2), DPN2IP2));
202
203         ELAN_INTERFACES.put(ELAN1 + ":" + DPN3MAC1 ,
204                 ImmutablePair.of(InterfaceHelper
205                         .buildVlanInterfaceInfo("23701c04-3118-4c65-9425-78a80d49a211",
206                         DPN3_ID, 5, 14, DPN3MAC1), DPN3IP1));
207
208         ELAN_INTERFACES.put(ELAN1 + ":" + DPN3MAC2 ,
209                 ImmutablePair.of(InterfaceHelper
210                         .buildVlanInterfaceInfo("23701c04-3218-4c65-9425-78a80d49a211",
211                         DPN3_ID, 6, 15, DPN3MAC2), DPN3IP2));
212
213         //Adding the external tunnel interfaces
214         EXTN_INTFS.put(DPN1_ID_STR + ":" + DPN2_ID_STR, new TunnelInterfaceDetails(DPN1_TEPIP, DPN2_TEPIP, true,
215                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-10", DPN1_ID, 5, 14, DPN1_TO_DPN2TNL_MAC)));
216
217         EXTN_INTFS.put(DPN1_ID_STR + ":" + TOR1_NODE_ID, new TunnelInterfaceDetails(DPN1_TEPIP, TOR1_TEPIP, true,
218                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-12", DPN1_ID, 6, 15, DPN1_TO_TOR1TNL_MAC)));
219         EXTN_INTFS.put(DPN1_ID_STR + ":" + TOR1_TEPIP, EXTN_INTFS.get(DPN1_ID_STR + ":" + TOR1_NODE_ID));
220
221         EXTN_INTFS.put(DPN2_ID_STR + ":" + DPN1_ID_STR, new TunnelInterfaceDetails(DPN2_TEPIP, DPN1_TEPIP, true,
222                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-11", DPN2_ID, 7, 16, DPN2_TO_DPN1_TNL_MAC)));
223
224         EXTN_INTFS.put(DPN2_ID_STR + ":" + TOR1_NODE_ID, new TunnelInterfaceDetails(DPN2_TEPIP, TOR1_TEPIP, true,
225                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-13", DPN2_ID, 8, 17, DPN2_TO_TOR1_TNL_MAC)));
226         EXTN_INTFS.put(DPN2_ID_STR + ":" + TOR1_TEPIP, EXTN_INTFS.get(DPN2_ID_STR + ":" + TOR1_NODE_ID));
227
228         EXTN_INTFS.put(DPN1_ID_STR + ":" + DPN3_ID_STR, new TunnelInterfaceDetails(DPN1_TEPIP, DPN3_TEPIP, true,
229                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-14", DPN1_ID, 9, 18, DPN1_TO_DPN3_TNL_MAC)));
230
231         EXTN_INTFS.put(DPN3_ID_STR + ":" + DPN1_ID_STR, new TunnelInterfaceDetails(DPN3_TEPIP, DPN1_TEPIP, true,
232                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-15", DPN3_ID, 10, 19, DPN3_TO_DPN1_TNL_MAC)));
233
234         EXTN_INTFS.put(DPN3_ID_STR + ":" + DPN2_ID_STR, new TunnelInterfaceDetails(DPN3_TEPIP, DPN2_TEPIP, true,
235                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-16", DPN3_ID, 11, 20, DPN3_TO_DPN2_TNL_MAC)));
236
237         EXTN_INTFS.put(DPN2_ID_STR + ":" + DPN3_ID_STR, new TunnelInterfaceDetails(DPN2_TEPIP, DPN3_TEPIP, true,
238                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-17", DPN2_ID, 12, 21, DPN2_TO_DPN3_TNL_MAC)));
239
240         EXTN_INTFS.put(DPN3_ID_STR + ":" + TOR1_NODE_ID, new TunnelInterfaceDetails(DPN3_TEPIP, TOR1_TEPIP, true,
241                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-18", DPN3_ID, 13, 22, DPN3_TO_TOR1_TNL_MAC)));
242         EXTN_INTFS.put(DPN3_ID_STR + ":" + TOR1_TEPIP, EXTN_INTFS.get(DPN3_ID_STR + ":" + TOR1_NODE_ID));
243
244         EXTN_INTFS.put(DPN1_ID_STR + ":" + TOR2_NODE_ID, new TunnelInterfaceDetails(DPN1_TEPIP, TOR2_TEPIP, true,
245                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-19", DPN1_ID, 14, 23, DPN1_TO_TOR2_TNL_MAC)));
246         EXTN_INTFS.put(DPN1_ID_STR + ":" + TOR2_TEPIP, EXTN_INTFS.get(DPN1_ID_STR + ":" + TOR2_NODE_ID));
247
248         EXTN_INTFS.put(DPN2_ID_STR + ":" + TOR2_NODE_ID, new TunnelInterfaceDetails(DPN2_TEPIP, TOR2_TEPIP, true,
249                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-20", DPN2_ID, 15, 24, DPN2_TO_TOR2_TNL_MAC)));
250         EXTN_INTFS.put(DPN2_ID_STR + ":" + TOR2_TEPIP, EXTN_INTFS.get(DPN2_ID_STR + ":" + TOR2_NODE_ID));
251
252         EXTN_INTFS.put(DPN3_ID_STR + ":" + TOR2_NODE_ID, new TunnelInterfaceDetails(DPN3_TEPIP, TOR2_TEPIP, true,
253                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-21", DPN3_ID, 16, 25, DPN3_TO_TOR2_TNL_MAC)));
254         EXTN_INTFS.put(DPN3_ID_STR + ":" + TOR2_TEPIP, EXTN_INTFS.get(DPN3_ID_STR + ":" + TOR2_NODE_ID));
255
256         EXTN_INTFS.put(DPN1_ID_STR + ":" + DCGWID, new TunnelInterfaceDetails(DPN1_TEPIP, DCGW_TEPIP, true,
257                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-22", DPN1_ID, 17, 26, DPN1_TO_DCGWTNL_MAC)));
258
259         EXTN_INTFS.put(DPN2_ID_STR + ":" + DCGWID, new TunnelInterfaceDetails(DPN2_TEPIP, DCGWID, true,
260                 InterfaceHelper.buildVxlanInterfaceInfo("tun23701c04-23", DPN2_ID, 18, 27, DPN2_TO_DCGW_TNL_MAC)));
261
262     }
263
264     protected ConditionFactory getAwaiter() {
265         return Awaitility.await("TestableListener")
266                 .atMost(30, TimeUnit.SECONDS)//TODO constant
267                 .pollInterval(100, TimeUnit.MILLISECONDS);
268     }
269
270     void awaitForData(LogicalDatastoreType dsType, InstanceIdentifier<? extends DataObject> iid) {
271         getAwaiter().until(() -> MDSALUtil.read(dataBroker, dsType, iid).isPresent());
272     }
273
274     void awaitForDataDelete(LogicalDatastoreType dsType, InstanceIdentifier<? extends DataObject> iid) {
275         getAwaiter().until(() -> !MDSALUtil.read(dataBroker, dsType, iid).isPresent());
276     }
277
278     Flow getFlowWithoutCookie(Flow flow) {
279         FlowBuilder flowBuilder = new FlowBuilder(flow);
280         return flowBuilder.setCookie(null).build();
281     }
282
283     Flow getSortedActions(Flow flow) {
284         FlowBuilder flowBuilder = new FlowBuilder(flow);
285         Instructions instructions = flowBuilder.getInstructions();
286         InstructionsBuilder builder = new InstructionsBuilder();
287         InstructionBuilder instructionBuilder = new InstructionBuilder(instructions.getInstruction().get(0));
288         instructionBuilder.setInstruction(sortActions(instructionBuilder.getInstruction()));
289         builder.setInstruction(Lists.newArrayList(instructionBuilder.build()));
290         return flowBuilder.setInstructions(builder.build()).build();
291     }
292
293     org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction
294         sortActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction input) {
295         if (input instanceof  ApplyActionsCase) {
296             List<Action> action = new ArrayList<>(((ApplyActionsCase)input).getApplyActions().getAction());
297             action.sort(Comparator.comparing(Ordered::getOrder));
298
299             ApplyActions actions = new ApplyActionsBuilder().setAction(action).build();
300             return new ApplyActionsCaseBuilder().setApplyActions(actions).build();
301         }
302         return null;
303     }
304
305     protected static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology
306             .rev131021.network.topology.topology.Node> createInstanceIdentifier(String nodeIdString) {
307         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId nodeId
308                 = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network
309                 .topology.rev131021.NodeId(new Uri(nodeIdString));
310         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology
311                 .topology.NodeKey nodeKey = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
312                 .network.topology.rev131021.network.topology.topology.NodeKey(nodeId);
313         TopologyKey topoKey = new TopologyKey(new TopologyId(new Uri("hwvtep:1")));
314         return InstanceIdentifier.builder(NetworkTopology.class)
315                 .child(Topology.class, topoKey)
316                 .child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
317                         .network.topology.rev131021.network.topology.topology.Node.class, nodeKey)
318                 .build();
319     }
320
321
322     protected void setupItm() throws TransactionCommitFailedException {
323         /*Add tap port and tunnel ports in DPN1 and DPN2*/
324         interfaceMgr.addInterfaceInfo(ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft());
325         interfaceMgr.addInterfaceInfo(ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC2).getLeft());
326         interfaceMgr.addInterfaceInfo(ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC1).getLeft());
327         interfaceMgr.addInterfaceInfo(ELAN_INTERFACES.get(ELAN1 + ":" + DPN2MAC2).getLeft());
328         interfaceMgr.addInterfaceInfo(ELAN_INTERFACES.get(ELAN1 + ":" + DPN3MAC1).getLeft());
329         interfaceMgr.addInterfaceInfo(ELAN_INTERFACES.get(ELAN1 + ":" + DPN3MAC2).getLeft());
330
331         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN1_ID_STR + ":" + DPN2_ID_STR));
332         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN2_ID_STR + ":" + DPN1_ID_STR));
333         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN1_ID_STR + ":" + DPN3_ID_STR));
334         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN3_ID_STR + ":" + DPN1_ID_STR));
335         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN2_ID_STR + ":" + DPN3_ID_STR));
336         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN3_ID_STR + ":" + DPN2_ID_STR));
337
338         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN1_ID_STR + ":" + TOR1_NODE_ID));
339         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN2_ID_STR + ":" + TOR1_NODE_ID));
340         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN3_ID_STR + ":" + TOR1_NODE_ID));
341         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN1_ID_STR + ":" + TOR2_NODE_ID));
342         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN2_ID_STR + ":" + TOR2_NODE_ID));
343         interfaceMgr.addTunnelInterface(EXTN_INTFS.get(DPN3_ID_STR + ":" + TOR2_NODE_ID));
344
345         /*Add DPN1 and DPN2 TEPs*/
346         itmRpc.addDpn(DPN1_ID, DPN1_TEPIP);
347         itmRpc.addDpn(DPN2_ID, DPN2_TEPIP);
348         itmRpc.addDpn(DPN3_ID, DPN3_TEPIP);
349
350         /*add external interface*/
351         itmRpc.addInterface(DPN1_ID,
352                 DPN2_TEPIP, EXTN_INTFS.get(DPN1_ID_STR + ":" + DPN2_ID_STR).getInterfaceInfo().getInterfaceName());
353         itmRpc.addInterface(DPN2_ID,
354                 DPN1_TEPIP, EXTN_INTFS.get(DPN2_ID_STR + ":" + DPN1_ID_STR).getInterfaceInfo().getInterfaceName());
355         itmRpc.addInterface(DPN1_ID,
356                 DPN3_TEPIP, EXTN_INTFS.get(DPN1_ID_STR + ":" + DPN3_ID_STR).getInterfaceInfo().getInterfaceName());
357         itmRpc.addInterface(DPN3_ID,
358                 DPN1_TEPIP, EXTN_INTFS.get(DPN3_ID_STR + ":" + DPN1_ID_STR).getInterfaceInfo().getInterfaceName());
359         itmRpc.addInterface(DPN2_ID,
360                 DPN3_TEPIP, EXTN_INTFS.get(DPN2_ID_STR + ":" + DPN3_ID_STR).getInterfaceInfo().getInterfaceName());
361         itmRpc.addInterface(DPN3_ID,
362                 DPN2_TEPIP, EXTN_INTFS.get(DPN3_ID_STR + ":" + DPN2_ID_STR).getInterfaceInfo().getInterfaceName());
363
364
365         itmRpc.addL2GwInterface(DPN1_ID,
366                 DCGWID, EXTN_INTFS.get(DPN1_ID_STR + ":" + DCGWID).getInterfaceInfo().getInterfaceName());
367         itmRpc.addL2GwInterface(DPN1_ID,
368                 TOR1_NODE_ID, EXTN_INTFS.get(DPN1_ID_STR + ":" + TOR1_NODE_ID).getInterfaceInfo().getInterfaceName());
369         itmRpc.addL2GwInterface(DPN2_ID,
370                 TOR1_NODE_ID, EXTN_INTFS.get(DPN2_ID_STR + ":" + TOR1_NODE_ID).getInterfaceInfo().getInterfaceName());
371         itmRpc.addL2GwInterface(DPN3_ID,
372                 TOR1_NODE_ID, EXTN_INTFS.get(DPN3_ID_STR + ":" + TOR1_NODE_ID).getInterfaceInfo().getInterfaceName());
373         itmRpc.addL2GwInterface(DPN1_ID,
374                 TOR2_NODE_ID, EXTN_INTFS.get(DPN1_ID_STR + ":" + TOR2_NODE_ID).getInterfaceInfo().getInterfaceName());
375         itmRpc.addL2GwInterface(DPN2_ID,
376                 TOR2_NODE_ID, EXTN_INTFS.get(DPN2_ID_STR + ":" + TOR2_NODE_ID).getInterfaceInfo().getInterfaceName());
377         itmRpc.addL2GwInterface(DPN3_ID,
378                 TOR2_NODE_ID, EXTN_INTFS.get(DPN3_ID_STR + ":" + TOR2_NODE_ID).getInterfaceInfo().getInterfaceName());
379
380
381     }
382
383     protected InstanceIdentifier<Flow> getFlowIid(short tableId, FlowId flowid, Uint64 dpnId) {
384
385         FlowKey flowKey = new FlowKey(new FlowId(flowid));
386         NodeId nodeId =
387                 new NodeId("openflow:" + dpnId);
388         Node nodeDpn =
389                 new NodeBuilder().setId(nodeId).withKey(new NodeKey(nodeId)).build();
390         return InstanceIdentifier.builder(Nodes.class)
391                 .child(Node.class,
392                         nodeDpn.key()).augmentation(FlowCapableNode.class)
393                 .child(Table.class, new TableKey(tableId)).child(Flow.class, flowKey).build();
394     }
395
396
397     protected void createElanInstance(String elan1, Uint32 elan1SegmentId) {
398         ElanInstance elanInstance = ExpectedObjects.createElanInstance(elan1, elan1SegmentId);
399         MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
400                 ElanHelper.getElanInstanceConfigurationDataPath(elan1), elanInstance);
401     }
402
403     public void addElanInterface(String elanInstanceName, InterfaceInfo interfaceInfo, String prefix) {
404         ElanInstance existingElanInstance = elanInstanceCache.get(elanInstanceName).orNull();
405         String interfaceName = interfaceInfo.getInterfaceName();
406
407         if (existingElanInstance != null) {
408             ElanInterfaceBuilder elanInterfaceBuilder = new ElanInterfaceBuilder()
409                     .setElanInstanceName(elanInstanceName)
410                     .setName(interfaceName)
411                     .withKey(new ElanInterfaceKey(interfaceName));
412
413             StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
414             List<StaticMacEntries> staticMacEntries = new ArrayList<>();
415             List<PhysAddress> physAddressList = Collections.singletonList(
416                     new PhysAddress(interfaceInfo.getMacAddress()));
417             for (PhysAddress physAddress : physAddressList) {
418                 staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress)
419                         .setIpPrefix(new IpAddress(new Ipv4Address(prefix))).build());
420             }
421             elanInterfaceBuilder.setStaticMacEntries(staticMacEntries);
422             ElanInterface elanInterface = elanInterfaceBuilder.build();
423
424             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
425                     ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
426         }
427     }
428
429     public void deleteElanInterface(InterfaceInfo interfaceInfo) throws TransactionCommitFailedException {
430         String interfaceName = interfaceInfo.getInterfaceName();
431         singleTxdataBroker.syncDelete(LogicalDatastoreType.CONFIGURATION,
432                 ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName));
433
434     }
435 }