2 * Copyright (c) 2017 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.netvirt.elan.cli.l2gw;
11 import com.google.common.base.Function;
12 import com.google.common.base.Optional;
13 import com.google.common.collect.Lists;
14 import com.google.common.collect.Sets;
15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17 import java.io.FileOutputStream;
18 import java.io.PrintWriter;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
24 import java.util.Map.Entry;
26 import org.apache.karaf.shell.commands.Command;
27 import org.apache.karaf.shell.console.OsgiCommandSupport;
28 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
29 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
30 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
31 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
32 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
33 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
34 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
35 import org.opendaylight.netvirt.elan.l2gw.ha.commands.LogicalSwitchesCmd;
36 import org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand;
37 import org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteMcastCmd;
38 import org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteUcastCmd;
39 import org.opendaylight.netvirt.elan.l2gw.ha.commands.TerminationPointCmd;
40 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
41 import org.opendaylight.netvirt.elan.utils.ElanConstants;
42 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
43 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
44 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
69 import org.opendaylight.yangtools.yang.binding.DataObject;
70 import org.opendaylight.yangtools.yang.binding.Identifier;
71 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
75 @Command(scope = "l2gw", name = "validate", description = "Validates the hwvtep nodes data")
76 public class L2GwValidateCli extends OsgiCommandSupport {
78 private static final Logger LOG = LoggerFactory.getLogger(L2GwValidateCli.class);
80 private final MergeCommand[] globalCommands = new MergeCommand[]{new LogicalSwitchesCmd(), new RemoteUcastCmd(),
81 new RemoteMcastCmd()};
82 private final MergeCommand[] physicalSwitchCommands = new MergeCommand[]{new TerminationPointCmd()};
84 private final Map<InstanceIdentifier<Node>, Node> operationalNodes = new HashMap<>();
85 private final Map<InstanceIdentifier<Node>, Node> configNodes = new HashMap<>();
86 private final Map<String, ElanInstance> elanInstanceMap = new HashMap<>();
87 private final Map<Uuid, L2gateway> uuidToL2Gateway = new HashMap<>();
88 private final InstanceIdentifier<Topology> topoIid = HwvtepSouthboundUtils.createHwvtepTopologyInstanceIdentifier();
89 private final Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> operationalNodesData =
91 private final Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> configNodesData =
94 private final DataBroker dataBroker;
95 private final L2GatewayCache l2GatewayCache;
97 private List<L2gateway> l2gateways;
98 private List<L2gatewayConnection> l2gatewayConnections;
100 private PrintWriter pw;
102 public L2GwValidateCli(DataBroker dataBroker, L2GatewayCache l2GatewayCache) {
103 this.dataBroker = dataBroker;
104 this.l2GatewayCache = l2GatewayCache;
108 @SuppressFBWarnings("DM_DEFAULT_ENCODING")
109 public Object doExecute() throws Exception {
111 pw = new PrintWriter(new FileOutputStream(new File("l2gw.validation.txt")));
114 verifyConfigVsOperationalDiff();
115 verifyL2GatewayConnections();
117 } catch (ReadFailedException e) {
118 session.getConsole().println("Failed with error " + e.getMessage());
119 LOG.error("Failed with error ", e);
124 private void readNodes() throws ReadFailedException {
125 try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
126 InstanceIdentifier<Topology> topoId = HwvtepSouthboundUtils.createHwvtepTopologyInstanceIdentifier();
128 Optional<Topology> operationalTopoOptional = tx.read(LogicalDatastoreType.OPERATIONAL, topoId).checkedGet();
129 Optional<Topology> configTopoOptional = tx.read(LogicalDatastoreType.CONFIGURATION, topoId).checkedGet();
131 if (operationalTopoOptional.isPresent()) {
132 for (Node node : operationalTopoOptional.get().getNode()) {
133 InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.getKey());
134 operationalNodes.put(nodeIid, node);
137 if (configTopoOptional.isPresent()) {
138 for (Node node : configTopoOptional.get().getNode()) {
139 InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.getKey());
140 configNodes.put(nodeIid, node);
144 fillNodesData(operationalNodes, operationalNodesData);
145 fillNodesData(configNodes, configNodesData);
147 Optional<ElanInstances> elanInstancesOptional = tx.read(LogicalDatastoreType.CONFIGURATION,
148 InstanceIdentifier.builder(ElanInstances.class).build()).checkedGet();
150 if (elanInstancesOptional.isPresent() && elanInstancesOptional.get().getElanInstance() != null) {
151 for (ElanInstance elanInstance : elanInstancesOptional.get().getElanInstance()) {
152 elanInstanceMap.put(elanInstance.getElanInstanceName(), elanInstance);
155 l2gatewayConnections = L2GatewayConnectionUtils.getAllL2gatewayConnections(dataBroker);
156 l2gateways = L2GatewayConnectionUtils.getL2gatewayList(dataBroker);
157 for (L2gateway l2gateway : l2gateways) {
158 uuidToL2Gateway.put(l2gateway.getUuid(), l2gateway);
163 private boolean isPresent(Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap,
164 InstanceIdentifier<Node> nodeIid, InstanceIdentifier dataIid) {
165 if (dataMap.containsKey(nodeIid)) {
166 return dataMap.get(nodeIid).containsKey(dataIid);
171 private DataObject getData(Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap,
172 InstanceIdentifier<Node> nodeIid, InstanceIdentifier dataIid) {
173 if (dataMap.containsKey(nodeIid)) {
174 return dataMap.get(nodeIid).get(dataIid);
179 private void fillNodesData(Map<InstanceIdentifier<Node>, Node> nodes,
180 Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap) {
182 for (Map.Entry<InstanceIdentifier<Node>, Node> entry : nodes.entrySet()) {
183 InstanceIdentifier<Node> nodeId = entry.getKey();
184 Node node = entry.getValue();
185 Map<InstanceIdentifier, DataObject> map = new HashMap<>();
186 dataMap.put(nodeId, map);
187 if (node.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
188 for (MergeCommand command : globalCommands) {
189 List<DataObject> data = command.getData(node.getAugmentation(HwvtepGlobalAugmentation.class));
191 for (DataObject dataObject : data) {
192 map.put(command.generateId(nodeId, dataObject), dataObject);
197 for (MergeCommand command : physicalSwitchCommands) {
198 List<DataObject> data = command.getData(node);
200 for (DataObject dataObject : data) {
201 map.put(command.generateId(nodeId, dataObject), dataObject);
210 * Checks the diff between config and operational topology nodes and prints it to the file if any.
211 * This will tell what is present in the controller config and not in the device
213 private void verifyConfigVsOperationalDiff() {
214 for (Node cfgNode : configNodes.values()) {
215 InstanceIdentifier<Node> nodeId = topoIid.child(Node.class, cfgNode.getKey());
216 compareNodes(cfgNode, operationalNodes.get(nodeId), false, LogicalDatastoreType.CONFIGURATION);
221 * Checks the diff between HA parent and child nodes.
222 * Whatever config data in parent should be present in child nodes
223 * Whatever operational data in child should be present in parent node
225 private void verifyHANodes() {
226 pw.println("Verifying HA nodes");
227 boolean parentChildComparison = true;
228 HwvtepHACache haCache = HwvtepHACache.getInstance();
229 Set<InstanceIdentifier<Node>> parentNodes = HwvtepHACache.getInstance().getHAParentNodes();
230 if (HwvtepHAUtil.isEmpty(parentNodes)) {
233 for (InstanceIdentifier<Node> parentNodeIid : parentNodes) {
234 String parentNodeId = parentNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
235 Node parentOpNode = operationalNodes.get(parentNodeIid);
236 Node parentCfgNode = configNodes.get(parentNodeIid);
237 Set<InstanceIdentifier<Node>> childNodeIids = haCache.getChildrenForHANode(parentNodeIid);
238 if (HwvtepHAUtil.isEmpty(childNodeIids)) {
239 pw.println("No child nodes could be found for parent node " + parentNodeId);
242 for (InstanceIdentifier<Node> childNodeIid : childNodeIids) {
243 String childNodeId = childNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
244 if (parentOpNode != null) {
245 compareNodes(parentOpNode, operationalNodes.get(childNodeIid), parentChildComparison,
246 LogicalDatastoreType.OPERATIONAL);
248 pw.println("Missing parent operational node for id " + parentNodeId);
250 if (parentCfgNode != null) {
251 if (configNodes.get(childNodeIid) == null) {
252 if (containsLogicalSwitch(parentCfgNode)) {
253 pw.println("Missing child config data " + childNodeId);
256 compareNodes(parentCfgNode, configNodes.get(childNodeIid), parentChildComparison,
257 LogicalDatastoreType.CONFIGURATION);
260 pw.println("Missing parent config node for id " + parentNodeId);
266 private boolean containsLogicalSwitch(Node node) {
267 if (node == null || node.getAugmentation(HwvtepGlobalAugmentation.class) == null
268 || HwvtepHAUtil.isEmptyList(
269 node.getAugmentation(HwvtepGlobalAugmentation.class).getLogicalSwitches())) {
275 private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison,
276 LogicalDatastoreType datastoreType) {
278 if (node1 == null || node2 == null) {
281 InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
282 InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
284 NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
285 NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
287 PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
288 PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
290 HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
291 HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
293 boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
294 MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
296 for (MergeCommand cmd : commands) {
298 List<DataObject> data1 = null;
299 List<DataObject> data2 = null;
302 data1 = cmd.getData(aug1);
303 data2 = cmd.getData(aug2);
305 data1 = cmd.getData(node1);
306 data2 = cmd.getData(node2);
308 data1 = data1 == null ? Collections.EMPTY_LIST : data1;
309 data2 = data2 == null ? Collections.EMPTY_LIST : data2;
311 if (parentChildComparison) {
312 data2 = cmd.transform(nodeIid1, data2);
314 Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
315 data1 = Lists.transform(data1, withoutUuidTransformer);
316 data2 = Lists.transform(data2, withoutUuidTransformer);
318 Map<Identifier<?>, DataObject> map1 = new HashMap<>();
319 Map<Identifier<?>, DataObject> map2 = new HashMap<>();
320 for (DataObject dataObject : data1) {
321 map1.put(cmd.getKey(dataObject), dataObject);
323 for (DataObject dataObject : data2) {
324 map2.put(cmd.getKey(dataObject), dataObject);
326 Set<DataObject> diff = Sets.newHashSet();
328 for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
329 DataObject obj1 = entry.getValue();
330 DataObject obj2 = map2.get(entry.getKey());
331 if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
336 if (!diff.isEmpty()) {
337 if (parentChildComparison) {
338 pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType
339 + " parent node " + nodeId1 + " contain " + " more entries than child "
340 + nodeId2 + " " + diff.size());
342 pw.println("Missing " + cmd.getDescription() + " op entries config "
343 + nodeId1 + " contain " + " more entries than operational node " + diff.size());
345 if (diff.size() < 10) {
346 for (Object obj : diff) {
347 pw.println(cmd.getKey((DataObject) obj));
352 diff = Sets.newHashSet();
353 for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
354 DataObject obj1 = entry.getValue();
355 DataObject obj2 = map1.get(entry.getKey());
356 if (globalNodes || parentChildComparison) {
357 if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
362 if (!diff.isEmpty()) {
363 if (parentChildComparison) {
364 pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node "
365 + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
367 pw.println("Extra " + cmd.getDescription() + " operational node "
368 + nodeId2 + " contain " + " more entries than config node " + diff.size());
370 if (diff.size() < 10) {
371 for (Object obj : diff) {
372 pw.println(cmd.getKey((DataObject) obj));
380 private void verifyL2GatewayConnections() {
381 boolean isValid = true;
382 for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
384 L2gateway l2gateway = uuidToL2Gateway.get(l2gatewayConnection.getL2gatewayId());
385 String logicalSwitchName = l2gatewayConnection.getNetworkId().getValue();
386 List<Devices> devices = l2gateway.getDevices();
388 for (Devices device : devices) {
390 L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(device.getDeviceName());
391 isValid = verifyL2GatewayDevice(l2gateway, device, l2GatewayDevice);
395 NodeId nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
396 InstanceIdentifier<Node> nodeIid = topoIid.child(Node.class, new NodeKey(nodeId));
398 isValid = verfiyLogicalSwitch(logicalSwitchName, nodeIid);
400 isValid = verifyMcastMac(logicalSwitchName, l2GatewayDevice, nodeIid);
401 verifyVlanBindings(nodeIid, logicalSwitchName, device, l2gatewayConnection.getSegmentId());
402 L2GatewayDevice elanL2gatewayDevice = ElanL2GwCacheUtils
403 .getL2GatewayDeviceFromCache(logicalSwitchName, nodeId.getValue());
404 if (elanL2gatewayDevice == null) {
405 pw.println("Failed elan l2gateway device not found for network " + logicalSwitchName
406 + " and device " + device.getDeviceName() + " " + l2GatewayDevice.getHwvtepNodeId()
407 + " l2gw connection id " + l2gatewayConnection.getUuid());
414 private boolean verifyL2GatewayDevice(L2gateway l2gateway, Devices device, L2GatewayDevice l2GatewayDevice) {
415 if (l2GatewayDevice == null) {
416 pw.println("Failed l2gateway not found in cache for device " + device.getDeviceName());
419 if (l2GatewayDevice.getHwvtepNodeId() == null) {
420 pw.println("L2gateway cache is not updated with node id for device " + device.getDeviceName());
423 if (l2GatewayDevice.getTunnelIp() == null) {
424 pw.println("L2gateway cache is not updated with tunnel ip for device " + device.getDeviceName());
427 if (!l2GatewayDevice.getL2GatewayIds().contains(l2gateway.getUuid())) {
428 pw.println("L2gateway cache is not updated with l2gw id for device " + device.getDeviceName());
434 private InstanceIdentifier<TerminationPoint> getPhysicalPortTerminationPointIid(NodeId nodeId, String portName) {
435 TerminationPointKey tpKey = new TerminationPointKey(new TpId(portName));
436 InstanceIdentifier<TerminationPoint> iid = HwvtepSouthboundUtils.createTerminationPointId(nodeId, tpKey);
440 private boolean verfiyLogicalSwitch(String logicalSwitchName, InstanceIdentifier<Node> nodeIid) {
441 NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
442 InstanceIdentifier<LogicalSwitches> logicalSwitchPath = HwvtepSouthboundUtils
443 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
445 if (!isPresent(configNodesData, nodeIid, logicalSwitchPath)) {
446 pw.println("Failed to find config logical switch " + logicalSwitchName + " for node "
447 + nodeId.getValue());
451 if (!isPresent(operationalNodesData, nodeIid, logicalSwitchPath)) {
452 pw.println("Failed to find operational logical switch " + logicalSwitchName + " for node "
453 + nodeId.getValue());
459 private boolean verifyMcastMac(String logicalSwitchName,
460 L2GatewayDevice l2GatewayDevice,
461 InstanceIdentifier<Node> nodeIid) {
462 NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
464 HwvtepLogicalSwitchRef lsRef = new HwvtepLogicalSwitchRef(HwvtepSouthboundUtils
465 .createLogicalSwitchesInstanceIdentifier(
466 new NodeId(new Uri(nodeId)), new HwvtepNodeName(logicalSwitchName)));
468 RemoteMcastMacs remoteMcastMac = new RemoteMcastMacsBuilder()
469 .setMacEntryKey(new MacAddress(ElanConstants.UNKNOWN_DMAC)).setLogicalSwitchRef(lsRef).build();
470 InstanceIdentifier<RemoteMcastMacs> mcastMacIid = HwvtepSouthboundUtils
471 .createRemoteMcastMacsInstanceIdentifier(new NodeId(new Uri(nodeId)), remoteMcastMac.getKey());
474 if (!isPresent(configNodesData, nodeIid, mcastMacIid)) {
475 pw.println("Failed to find config mcast mac for logical switch " + logicalSwitchName
476 + " node id " + nodeId.getValue());
480 if (!isPresent(operationalNodesData, nodeIid, mcastMacIid)) {
481 pw.println("Failed to find operational mcast mac for logical switch " + logicalSwitchName
482 + " node id " + nodeId.getValue());
488 private boolean verifyVlanBindings(InstanceIdentifier<Node> nodeIid,
489 String logicalSwitchName,
490 Devices hwVtepDevice,
491 Integer defaultVlanId) {
492 boolean valid = true;
493 NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
494 if (hwVtepDevice.getInterfaces() == null) {
497 for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
498 .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
500 NodeId switchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
501 InstanceIdentifier<Node> physicalSwitchNodeIid = topoIid.child(Node.class, new NodeKey(switchNodeId));
502 InstanceIdentifier<TerminationPoint> terminationPointIid =
503 getPhysicalPortTerminationPointIid(switchNodeId, deviceInterface.getInterfaceName());
505 TerminationPoint operationalTerminationPoint = (TerminationPoint) getData(operationalNodesData,
506 physicalSwitchNodeIid, terminationPointIid);
507 if (operationalTerminationPoint == null) {
509 pw.println("Failed to find the operational port " + deviceInterface.getInterfaceName()
510 + " for node " + hwVtepDevice.getDeviceName() + " nodeid " + nodeId.getValue());
513 TerminationPoint configTerminationPoint = (TerminationPoint) getData(configNodesData,
514 physicalSwitchNodeIid, terminationPointIid);
515 if (configTerminationPoint == null) {
517 pw.println("Failed to find the configurational port " + deviceInterface.getInterfaceName()
518 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
519 + " nodeid " + nodeId.getValue());
523 List<VlanBindings> expectedVlans = new ArrayList<>();
524 if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
525 for (Integer vlanId : deviceInterface.getSegmentationIds()) {
526 expectedVlans.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, vlanId, logicalSwitchName));
529 expectedVlans.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, defaultVlanId, logicalSwitchName));
532 HwvtepPhysicalPortAugmentation portAugmentation = configTerminationPoint.getAugmentation(
533 HwvtepPhysicalPortAugmentation.class);
534 if (portAugmentation == null || HwvtepHAUtil.isEmptyList(portAugmentation.getVlanBindings())) {
535 pw.println("Failed to find the config vlan bindings for port " + deviceInterface.getInterfaceName()
536 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
537 + " nodeid " + nodeId.getValue());
541 portAugmentation = operationalTerminationPoint.getAugmentation(HwvtepPhysicalPortAugmentation.class);
542 if (portAugmentation == null || HwvtepHAUtil.isEmptyList(portAugmentation.getVlanBindings())) {
543 pw.println("Failed to find the operational vlan bindings for port " + deviceInterface.getInterfaceName()
544 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
545 + " nodeid " + nodeId.getValue());
549 VlanBindings expectedBindings = !expectedVlans.isEmpty() ? expectedVlans.get(0) : null;
550 boolean foundBindings = false;
551 List<VlanBindings> vlanBindingses = configTerminationPoint.getAugmentation(
552 HwvtepPhysicalPortAugmentation.class).getVlanBindings();
553 for (VlanBindings actual : vlanBindingses) {
554 if (actual.equals(expectedBindings)) {
555 foundBindings = true;
559 if (!foundBindings) {
560 pw.println("Mismatch in vlan bindings for port " + deviceInterface.getInterfaceName()
561 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
562 + " nodeid " + nodeId.getValue());
563 pw.println("Failed to find the vlan bindings " + expectedBindings);
564 pw.println("Actual bindings present in config are ");
565 for (VlanBindings actual : vlanBindingses) {
566 pw.println(actual.toString());