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