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
8 package org.opendaylight.netvirt.elan.l2gw.nodehandlertest;
10 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
11 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
13 import com.google.common.base.Optional;
14 import java.util.UUID;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
20 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
21 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
22 import org.opendaylight.netvirt.elan.l2gw.ha.handlers.NodeConnectedHandler;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Created by eaksahu on 10/14/2016.
38 public class NodeConnectedHandlerTest extends AbstractConcurrentDataBrokerTest {
40 // Uncomment this to keep running this test indefinitely
41 // This is very useful to detect concurrency issues, respectively prove
42 // that the use of AbstractConcurrentDataBrokerTest instead of AbstractDataBrokerTest
43 // does NOT cause any concurrency issues and make this test flaky...
44 // public static @ClassRule RunUntilFailureClassRule classRepeater = new RunUntilFailureClassRule();
45 // public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
47 static Logger LOG = LoggerFactory.getLogger(NodeConnectedHandlerTest.class);
48 DataBroker dataBroker;
50 NodeConnectedHandler nodeConnectedHandler = new NodeConnectedHandler(this.dataBroker);
51 NodeConnectedHandlerUtils handlerUtils = new NodeConnectedHandlerUtils();
56 Optional<Node> d1GlobalOpNode;
57 Optional<Node> d2GlobalOpNode;
58 Optional<Node> haGlobalOpNode;
60 Optional<Node> d1PsOpNode;
61 Optional<Node> d2PsOpNode;
62 Optional<Node> haPsOpNode;
64 Optional<Node> d1GlobalConfigNode;
65 Optional<Node> d2GlobalConfigNode;
66 Optional<Node> haGlobalConfigNode;
68 Optional<Node> d1PsConfigNode;
69 Optional<Node> d2PsConfigNode;
70 Optional<Node> haPsConfigNode;
72 static String managerHAId = "s3-clusterid";
73 static String switchName = "s3";
75 InstanceIdentifier<Node> d1NodePath;
76 InstanceIdentifier<Node> d2NodePath;
77 InstanceIdentifier<Node> haNodePath;
79 InstanceIdentifier<Node> d1PsNodePath;
80 InstanceIdentifier<Node> d2PsNodePath;
81 InstanceIdentifier<Node> haPsNodePath;
86 public void setupForHANode() {
87 dataBroker = getDataBroker();
88 d1UUID = java.util.UUID.nameUUIDFromBytes("d1uuid".getBytes()).toString();
89 d2UUID = java.util.UUID.nameUUIDFromBytes("d2uuid".getBytes()).toString();
90 d1NodePath = getInstanceIdentifier(d1UUID);
91 d2NodePath = getInstanceIdentifier(d2UUID);
92 haNodePath = getInstanceIdentifier(managerHAId);
94 haNodeId = getNodeId(managerHAId);
96 NodeId d1NodeId = d1NodePath.firstKeyOf(Node.class).getNodeId();
97 String d1PsNodeIdVal = d1NodeId.getValue() + "/physicalswitch/" + switchName;
98 d1PsNodePath = createInstanceIdentifier(d1PsNodeIdVal);
100 NodeId d2NodeId = d2NodePath.firstKeyOf(Node.class).getNodeId();
101 String d2PsNodeIdVal = d2NodeId.getValue() + "/physicalswitch/" + switchName;
102 d2PsNodePath = createInstanceIdentifier(d2PsNodeIdVal);
104 haPsNodePath = createInstanceIdentifier(haNodeId.getValue() + "/physicalswitch/" + switchName);
108 public void testD1Connect() throws Exception {
109 ReadWriteTransaction tx = this.dataBroker.newReadWriteTransaction();
110 handlerUtils.addPsNode(d1PsNodePath, d1NodePath, DataProvider.getPortNameListD1(), tx).checkedGet();
112 tx = this.dataBroker.newReadWriteTransaction();
113 handlerUtils.addNode(d1NodePath, d1PsNodePath, DataProvider.getLogicalSwitchDataD1(),
114 DataProvider.getLocalUcasMacDataD1(), DataProvider.getLocalMcastDataD1(),
115 DataProvider.getRemoteMcastDataD1(), DataProvider.getRemoteUcasteMacDataD1(),
116 DataProvider.getGlobalTerminationPointIpD1(), tx).checkedGet();
119 tx = this.dataBroker.newReadWriteTransaction();
120 nodeConnectedHandler.handleNodeConnected(d1GlobalOpNode.get(), d1NodePath, haNodePath, haGlobalConfigNode,
122 tx.submit().checkedGet();
124 //verify global ha manager config should have ha_children
125 Assert.assertTrue(haGlobalConfigNode.isPresent() && d1GlobalOpNode.isPresent());
126 TestUtil.verifyHAconfigNode(haGlobalConfigNode.get(), d1GlobalOpNode.get());
128 Assert.assertTrue(d1GlobalOpNode.isPresent() && haGlobalOpNode.isPresent() && d1PsOpNode.isPresent()
129 && haPsOpNode.isPresent());
130 TestUtil.verifyHAOpNode(d1GlobalOpNode.get(), haGlobalOpNode.get(),
131 d1PsOpNode.get(), haPsOpNode.get(), haNodePath, d1PsNodePath, haPsNodePath, haNodeId, this.dataBroker);
134 public static InstanceIdentifier<Node> createInstanceIdentifier(String nodeIdString) {
135 NodeId nodeId = new NodeId(new Uri(nodeIdString));
136 NodeKey nodeKey = new NodeKey(nodeId);
137 TopologyKey topoKey = new TopologyKey(new TopologyId(new Uri("hwvtep:1")));
138 return InstanceIdentifier.builder(NetworkTopology.class)
139 .child(Topology.class, topoKey)
140 .child(Node.class, nodeKey)
144 public static InstanceIdentifier<Node> getInstanceIdentifier(String haUUidVal) {
145 String nodeString = "hwvtep://uuid/" + UUID.nameUUIDFromBytes(haUUidVal.getBytes()).toString();
146 NodeId nodeId = new NodeId(new Uri(nodeString));
147 NodeKey nodeKey = new NodeKey(nodeId);
148 TopologyKey topoKey = new TopologyKey(new TopologyId(new Uri("hwvtep:1")));
149 return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, topoKey)
150 .child(Node.class, nodeKey).build();
153 public static NodeId getNodeId(String haId) {
154 String nodeString = "hwvtep://uuid/" + UUID.nameUUIDFromBytes(haId.getBytes()).toString();
155 NodeId nodeId = new NodeId(new Uri(nodeString));
159 public void readNodes() throws Exception {
160 ReadOnlyTransaction tx = this.dataBroker.newReadOnlyTransaction();
161 d1GlobalOpNode = TestUtil.readNode(OPERATIONAL, d1NodePath, tx);
162 d2GlobalOpNode = TestUtil.readNode(OPERATIONAL, d2NodePath, tx);
163 haGlobalOpNode = TestUtil.readNode(OPERATIONAL, haNodePath, tx);
165 d1PsOpNode = TestUtil.readNode(OPERATIONAL, d1PsNodePath, tx);
166 d2PsOpNode = TestUtil.readNode(OPERATIONAL, d2PsNodePath, tx);
167 haPsOpNode = TestUtil.readNode(OPERATIONAL, haPsNodePath, tx);
169 haGlobalConfigNode = TestUtil.readNode(CONFIGURATION, haNodePath, tx);
170 d1GlobalConfigNode = TestUtil.readNode(CONFIGURATION, d1NodePath, tx);
171 d2GlobalConfigNode = TestUtil.readNode(CONFIGURATION, d2NodePath, tx);
173 haPsConfigNode = TestUtil.readNode(CONFIGURATION, haPsNodePath, tx);
174 d1PsConfigNode = TestUtil.readNode(CONFIGURATION, d1PsNodePath, tx);
175 d2PsConfigNode = TestUtil.readNode(CONFIGURATION, d2PsNodePath, tx);