2 * Copyright (c) 2016, 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
8 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
10 import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.Objects;
16 import javax.annotation.Nullable;
17 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSetBuilder;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yangtools.yang.binding.Identifier;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 public class RemoteMcastCmd extends
33 MergeCommand<RemoteMcastMacs, HwvtepGlobalAugmentationBuilder, HwvtepGlobalAugmentation> {
35 public RemoteMcastCmd() {
40 public List<RemoteMcastMacs> getData(HwvtepGlobalAugmentation augmentation) {
41 if (augmentation != null) {
42 return augmentation.getRemoteMcastMacs();
48 public void setData(HwvtepGlobalAugmentationBuilder builder, List<RemoteMcastMacs> data) {
49 builder.setRemoteMcastMacs(data);
53 public InstanceIdentifier<RemoteMcastMacs> generateId(InstanceIdentifier<Node> id, RemoteMcastMacs node) {
54 HwvtepLogicalSwitchRef lsRef = HwvtepHAUtil.convertLogicalSwitchRef(node.key().getLogicalSwitchRef(), id);
55 RemoteMcastMacsKey key = new RemoteMcastMacsKey(lsRef, node.getMacEntryKey());
57 return id.augmentation(HwvtepGlobalAugmentation.class).child(RemoteMcastMacs.class, key);
61 public RemoteMcastMacs transform(InstanceIdentifier<Node> nodePath, RemoteMcastMacs src) {
62 RemoteMcastMacsBuilder ucmlBuilder = new RemoteMcastMacsBuilder(src);
63 List<LocatorSet> locatorSet = new ArrayList<>();
64 for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.<LocatorSet>emptyList())) {
65 locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath,
66 HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build());
68 ucmlBuilder.setLocatorSet(locatorSet);
69 ucmlBuilder.setLogicalSwitchRef(HwvtepHAUtil.convertLogicalSwitchRef(src.getLogicalSwitchRef(), nodePath));
70 ucmlBuilder.setMacEntryUuid(HwvtepHAUtil.getUUid(src.getMacEntryKey().getValue()));
72 RemoteMcastMacsKey key = new RemoteMcastMacsKey(ucmlBuilder.getLogicalSwitchRef(),
73 ucmlBuilder.getMacEntryKey());
74 ucmlBuilder.withKey(key);
76 return ucmlBuilder.build();
80 public Identifier getKey(RemoteMcastMacs data) {
85 public String getDescription() {
86 return "RemoteMcastMacs";
90 public boolean areEqual(RemoteMcastMacs updated, RemoteMcastMacs orig) {
91 InstanceIdentifier<?> updatedMacRefIdentifier = updated.getLogicalSwitchRef().getValue();
92 HwvtepNodeName updatedMacNodeName = updatedMacRefIdentifier.firstKeyOf(LogicalSwitches.class)
94 InstanceIdentifier<?> origMacRefIdentifier = orig.getLogicalSwitchRef().getValue();
95 HwvtepNodeName origMacNodeName = origMacRefIdentifier.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName();
96 if (Objects.equals(updated.getMacEntryKey(), orig.getMacEntryKey())
97 && updatedMacNodeName.equals(origMacNodeName)) {
98 List<LocatorSet> updatedLocatorSet = updated.getLocatorSet();
99 List<LocatorSet> origLocatorSet = orig.getLocatorSet();
100 if (!areSameSize(updatedLocatorSet, origLocatorSet)) {
103 List<LocatorSet> added = diffOf(updatedLocatorSet, origLocatorSet, locatorSetComparator);
104 if (!HwvtepHAUtil.isEmptyList(added)) {
107 List<LocatorSet> removed = diffOf(origLocatorSet, updatedLocatorSet, locatorSetComparator);
108 if (!HwvtepHAUtil.isEmptyList(removed)) {
117 public RemoteMcastMacs withoutUuid(RemoteMcastMacs data) {
118 return new RemoteMcastMacsBuilder(data).setMacEntryUuid(null).build();