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.ReadWriteTransaction;
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 ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
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);
162 private boolean isPresent(Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap,
163 InstanceIdentifier<Node> nodeIid, InstanceIdentifier dataIid) {
164 if (dataMap.containsKey(nodeIid)) {
165 return dataMap.get(nodeIid).containsKey(dataIid);
170 private DataObject getData(Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap,
171 InstanceIdentifier<Node> nodeIid, InstanceIdentifier dataIid) {
172 if (dataMap.containsKey(nodeIid)) {
173 return dataMap.get(nodeIid).get(dataIid);
178 private void fillNodesData(Map<InstanceIdentifier<Node>, Node> nodes,
179 Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap) {
181 for (Map.Entry<InstanceIdentifier<Node>, Node> entry : nodes.entrySet()) {
182 InstanceIdentifier<Node> nodeId = entry.getKey();
183 Node node = entry.getValue();
184 Map<InstanceIdentifier, DataObject> map = new HashMap<>();
185 dataMap.put(nodeId, map);
186 if (node.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
187 for (MergeCommand command : globalCommands) {
188 List<DataObject> data = command.getData(node.getAugmentation(HwvtepGlobalAugmentation.class));
190 for (DataObject dataObject : data) {
191 map.put(command.generateId(nodeId, dataObject), dataObject);
196 for (MergeCommand command : physicalSwitchCommands) {
197 List<DataObject> data = command.getData(node);
199 for (DataObject dataObject : data) {
200 map.put(command.generateId(nodeId, dataObject), dataObject);
209 * Checks the diff between config and operational topology nodes and prints it to the file if any.
210 * This will tell what is present in the controller config and not in the device
212 private void verifyConfigVsOperationalDiff() {
213 for (Node cfgNode : configNodes.values()) {
214 InstanceIdentifier<Node> nodeId = topoIid.child(Node.class, cfgNode.getKey());
215 compareNodes(cfgNode, operationalNodes.get(nodeId), false, LogicalDatastoreType.CONFIGURATION);
220 * Checks the diff between HA parent and child nodes.
221 * Whatever config data in parent should be present in child nodes
222 * Whatever operational data in child should be present in parent node
224 private void verifyHANodes() {
225 pw.println("Verifying HA nodes");
226 boolean parentChildComparison = true;
227 HwvtepHACache haCache = HwvtepHACache.getInstance();
228 Set<InstanceIdentifier<Node>> parentNodes = HwvtepHACache.getInstance().getHAParentNodes();
229 if (HwvtepHAUtil.isEmpty(parentNodes)) {
232 for (InstanceIdentifier<Node> parentNodeIid : parentNodes) {
233 String parentNodeId = parentNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
234 Node parentOpNode = operationalNodes.get(parentNodeIid);
235 Node parentCfgNode = configNodes.get(parentNodeIid);
236 Set<InstanceIdentifier<Node>> childNodeIids = haCache.getChildrenForHANode(parentNodeIid);
237 if (HwvtepHAUtil.isEmpty(childNodeIids)) {
238 pw.println("No child nodes could be found for parent node " + parentNodeId);
241 for (InstanceIdentifier<Node> childNodeIid : childNodeIids) {
242 String childNodeId = childNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
243 if (parentOpNode != null) {
244 compareNodes(parentOpNode, operationalNodes.get(childNodeIid), parentChildComparison,
245 LogicalDatastoreType.OPERATIONAL);
247 pw.println("Missing parent operational node for id " + parentNodeId);
249 if (parentCfgNode != null) {
250 if (configNodes.get(childNodeIid) == null) {
251 if (containsLogicalSwitch(parentCfgNode)) {
252 pw.println("Missing child config data " + childNodeId);
255 compareNodes(parentCfgNode, configNodes.get(childNodeIid), parentChildComparison,
256 LogicalDatastoreType.CONFIGURATION);
259 pw.println("Missing parent config node for id " + parentNodeId);
265 private boolean containsLogicalSwitch(Node node) {
266 if (node == null || node.getAugmentation(HwvtepGlobalAugmentation.class) == null
267 || HwvtepHAUtil.isEmptyList(
268 node.getAugmentation(HwvtepGlobalAugmentation.class).getLogicalSwitches())) {
274 private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison,
275 LogicalDatastoreType datastoreType) {
277 if (node1 == null || node2 == null) {
280 InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
281 InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
283 NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
284 NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
286 PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
287 PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
289 HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
290 HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
292 boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
293 MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
295 for (MergeCommand cmd : commands) {
297 List<DataObject> data1 = null;
298 List<DataObject> data2 = null;
301 data1 = cmd.getData(aug1);
302 data2 = cmd.getData(aug2);
304 data1 = cmd.getData(node1);
305 data2 = cmd.getData(node2);
307 data1 = data1 == null ? Collections.EMPTY_LIST : data1;
308 data2 = data2 == null ? Collections.EMPTY_LIST : data2;
310 if (parentChildComparison) {
311 data2 = cmd.transform(nodeIid1, data2);
313 Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
314 data1 = Lists.transform(data1, withoutUuidTransformer);
315 data2 = Lists.transform(data2, withoutUuidTransformer);
317 Map<Identifier<?>, DataObject> map1 = new HashMap<>();
318 Map<Identifier<?>, DataObject> map2 = new HashMap<>();
319 for (DataObject dataObject : data1) {
320 map1.put(cmd.getKey(dataObject), dataObject);
322 for (DataObject dataObject : data2) {
323 map2.put(cmd.getKey(dataObject), dataObject);
325 Set<DataObject> diff = Sets.newHashSet();
327 for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
328 DataObject obj1 = entry.getValue();
329 DataObject obj2 = map2.get(entry.getKey());
330 if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
335 if (!diff.isEmpty()) {
336 if (parentChildComparison) {
337 pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType
338 + " parent node " + nodeId1 + " contain " + " more entries than child "
339 + nodeId2 + " " + diff.size());
341 pw.println("Missing " + cmd.getDescription() + " op entries config "
342 + nodeId1 + " contain " + " more entries than operational node " + diff.size());
344 if (diff.size() < 10) {
345 for (Object obj : diff) {
346 pw.println(cmd.getKey((DataObject) obj));
351 diff = Sets.newHashSet();
352 for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
353 DataObject obj1 = entry.getValue();
354 DataObject obj2 = map1.get(entry.getKey());
355 if (globalNodes || parentChildComparison) {
356 if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
361 if (!diff.isEmpty()) {
362 if (parentChildComparison) {
363 pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node "
364 + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
366 pw.println("Extra " + cmd.getDescription() + " operational node "
367 + nodeId2 + " contain " + " more entries than config node " + diff.size());
369 if (diff.size() < 10) {
370 for (Object obj : diff) {
371 pw.println(cmd.getKey((DataObject) obj));
379 private void verifyL2GatewayConnections() {
380 boolean isValid = true;
381 for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
383 L2gateway l2gateway = uuidToL2Gateway.get(l2gatewayConnection.getL2gatewayId());
384 String logicalSwitchName = l2gatewayConnection.getNetworkId().getValue();
385 List<Devices> devices = l2gateway.getDevices();
387 for (Devices device : devices) {
389 L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(device.getDeviceName());
390 isValid = verifyL2GatewayDevice(l2gateway, device, l2GatewayDevice);
394 NodeId nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
395 InstanceIdentifier<Node> nodeIid = topoIid.child(Node.class, new NodeKey(nodeId));
397 isValid = verfiyLogicalSwitch(logicalSwitchName, nodeIid);
399 isValid = verifyMcastMac(logicalSwitchName, l2GatewayDevice, nodeIid);
400 verifyVlanBindings(nodeIid, logicalSwitchName, device, l2gatewayConnection.getSegmentId());
401 L2GatewayDevice elanL2gatewayDevice = ElanL2GwCacheUtils
402 .getL2GatewayDeviceFromCache(logicalSwitchName, nodeId.getValue());
403 if (elanL2gatewayDevice == null) {
404 pw.println("Failed elan l2gateway device not found for network " + logicalSwitchName
405 + " and device " + device.getDeviceName() + " " + l2GatewayDevice.getHwvtepNodeId()
406 + " l2gw connection id " + l2gatewayConnection.getUuid());
413 private boolean verifyL2GatewayDevice(L2gateway l2gateway, Devices device, L2GatewayDevice l2GatewayDevice) {
414 if (l2GatewayDevice == null) {
415 pw.println("Failed l2gateway not found in cache for device " + device.getDeviceName());
418 if (l2GatewayDevice.getHwvtepNodeId() == null) {
419 pw.println("L2gateway cache is not updated with node id for device " + device.getDeviceName());
422 if (l2GatewayDevice.getTunnelIp() == null) {
423 pw.println("L2gateway cache is not updated with tunnel ip for device " + device.getDeviceName());
426 if (!l2GatewayDevice.getL2GatewayIds().contains(l2gateway.getUuid())) {
427 pw.println("L2gateway cache is not updated with l2gw id for device " + device.getDeviceName());
433 private InstanceIdentifier<TerminationPoint> getPhysicalPortTerminationPointIid(NodeId nodeId, String portName) {
434 TerminationPointKey tpKey = new TerminationPointKey(new TpId(portName));
435 InstanceIdentifier<TerminationPoint> iid = HwvtepSouthboundUtils.createTerminationPointId(nodeId, tpKey);
439 private boolean verfiyLogicalSwitch(String logicalSwitchName, InstanceIdentifier<Node> nodeIid) {
440 NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
441 InstanceIdentifier<LogicalSwitches> logicalSwitchPath = HwvtepSouthboundUtils
442 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
444 if (!isPresent(configNodesData, nodeIid, logicalSwitchPath)) {
445 pw.println("Failed to find config logical switch " + logicalSwitchName + " for node "
446 + nodeId.getValue());
450 if (!isPresent(operationalNodesData, nodeIid, logicalSwitchPath)) {
451 pw.println("Failed to find operational logical switch " + logicalSwitchName + " for node "
452 + nodeId.getValue());
458 private boolean verifyMcastMac(String logicalSwitchName,
459 L2GatewayDevice l2GatewayDevice,
460 InstanceIdentifier<Node> nodeIid) {
461 NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
463 HwvtepLogicalSwitchRef lsRef = new HwvtepLogicalSwitchRef(HwvtepSouthboundUtils
464 .createLogicalSwitchesInstanceIdentifier(
465 new NodeId(new Uri(nodeId)), new HwvtepNodeName(logicalSwitchName)));
467 RemoteMcastMacs remoteMcastMac = new RemoteMcastMacsBuilder()
468 .setMacEntryKey(new MacAddress(ElanConstants.UNKNOWN_DMAC)).setLogicalSwitchRef(lsRef).build();
469 InstanceIdentifier<RemoteMcastMacs> mcastMacIid = HwvtepSouthboundUtils
470 .createRemoteMcastMacsInstanceIdentifier(new NodeId(new Uri(nodeId)), remoteMcastMac.getKey());
473 if (!isPresent(configNodesData, nodeIid, mcastMacIid)) {
474 pw.println("Failed to find config mcast mac for logical switch " + logicalSwitchName
475 + " node id " + nodeId.getValue());
479 if (!isPresent(operationalNodesData, nodeIid, mcastMacIid)) {
480 pw.println("Failed to find operational mcast mac for logical switch " + logicalSwitchName
481 + " node id " + nodeId.getValue());
487 private boolean verifyVlanBindings(InstanceIdentifier<Node> nodeIid,
488 String logicalSwitchName,
489 Devices hwVtepDevice,
490 Integer defaultVlanId) {
491 boolean valid = true;
492 NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
493 if (hwVtepDevice.getInterfaces() == null) {
496 for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
497 .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
499 NodeId switchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
500 InstanceIdentifier<Node> physicalSwitchNodeIid = topoIid.child(Node.class, new NodeKey(switchNodeId));
501 InstanceIdentifier<TerminationPoint> terminationPointIid =
502 getPhysicalPortTerminationPointIid(switchNodeId, deviceInterface.getInterfaceName());
504 TerminationPoint operationalTerminationPoint = (TerminationPoint) getData(operationalNodesData,
505 physicalSwitchNodeIid, terminationPointIid);
506 if (operationalTerminationPoint == null) {
508 pw.println("Failed to find the operational port " + deviceInterface.getInterfaceName()
509 + " for node " + hwVtepDevice.getDeviceName() + " nodeid " + nodeId.getValue());
512 TerminationPoint configTerminationPoint = (TerminationPoint) getData(configNodesData,
513 physicalSwitchNodeIid, terminationPointIid);
514 if (configTerminationPoint == null) {
516 pw.println("Failed to find the configurational port " + deviceInterface.getInterfaceName()
517 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
518 + " nodeid " + nodeId.getValue());
522 List<VlanBindings> expectedVlans = new ArrayList<>();
523 if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
524 for (Integer vlanId : deviceInterface.getSegmentationIds()) {
525 expectedVlans.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, vlanId, logicalSwitchName));
528 expectedVlans.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, defaultVlanId, logicalSwitchName));
531 HwvtepPhysicalPortAugmentation portAugmentation = configTerminationPoint.getAugmentation(
532 HwvtepPhysicalPortAugmentation.class);
533 if (portAugmentation == null || HwvtepHAUtil.isEmptyList(portAugmentation.getVlanBindings())) {
534 pw.println("Failed to find the config vlan bindings for port " + deviceInterface.getInterfaceName()
535 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
536 + " nodeid " + nodeId.getValue());
540 portAugmentation = operationalTerminationPoint.getAugmentation(HwvtepPhysicalPortAugmentation.class);
541 if (portAugmentation == null || HwvtepHAUtil.isEmptyList(portAugmentation.getVlanBindings())) {
542 pw.println("Failed to find the operational vlan bindings for port " + deviceInterface.getInterfaceName()
543 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
544 + " nodeid " + nodeId.getValue());
548 VlanBindings expectedBindings = !expectedVlans.isEmpty() ? expectedVlans.get(0) : null;
549 boolean foundBindings = false;
550 List<VlanBindings> vlanBindingses = configTerminationPoint.getAugmentation(
551 HwvtepPhysicalPortAugmentation.class).getVlanBindings();
552 for (VlanBindings actual : vlanBindingses) {
553 if (actual.equals(expectedBindings)) {
554 foundBindings = true;
558 if (!foundBindings) {
559 pw.println("Mismatch in vlan bindings for port " + deviceInterface.getInterfaceName()
560 + " for node " + hwVtepDevice.getDeviceName() + " for logical switch " + logicalSwitchName
561 + " nodeid " + nodeId.getValue());
562 pw.println("Failed to find the vlan bindings " + expectedBindings);
563 pw.println("Actual bindings present in config are ");
564 for (VlanBindings actual : vlanBindingses) {
565 pw.println(actual.toString());