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 java.util.ArrayList;
11 import java.util.List;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
23 import org.opendaylight.yangtools.yang.binding.Identifier;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 public class TunnelCmd extends MergeCommand<Tunnels, PhysicalSwitchAugmentationBuilder, PhysicalSwitchAugmentation> {
33 public List<Tunnels> getData(PhysicalSwitchAugmentation node) {
34 if (node != null && node.nonnullTunnels() != null) {
35 return new ArrayList<Tunnels>(node.nonnullTunnels().values());
41 public void setData(PhysicalSwitchAugmentationBuilder builder, List<Tunnels> data) {
42 builder.setTunnels(data);
46 public InstanceIdentifier<Tunnels> generateId(InstanceIdentifier<Node> id, Tunnels src) {
47 HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef =
48 HwvtepHAUtil.convertLocatorRef(src.getLocalLocatorRef(), id);
49 HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef1 =
50 HwvtepHAUtil.convertLocatorRef(src.getRemoteLocatorRef(), id);
51 TunnelsKey key = new TunnelsKey(hwvtepPhysicalLocatorRef, hwvtepPhysicalLocatorRef1);
52 return id.augmentation(PhysicalSwitchAugmentation.class).child(Tunnels.class, key);
56 public Tunnels transform(InstanceIdentifier<Node> nodePath, Tunnels src) {
57 TunnelsBuilder tunnelsBuilder = new TunnelsBuilder(src);
58 tunnelsBuilder.setLocalLocatorRef(HwvtepHAUtil.convertLocatorRef(src.getLocalLocatorRef(), nodePath));
59 tunnelsBuilder.setRemoteLocatorRef(HwvtepHAUtil.convertLocatorRef(src.getRemoteLocatorRef(), nodePath));
60 tunnelsBuilder.setTunnelUuid(HwvtepHAUtil.getUUid(HwvtepHAUtil.getTepIpVal(src.getRemoteLocatorRef())));
61 HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef =
62 HwvtepHAUtil.convertLocatorRef(src.getLocalLocatorRef(), nodePath);
63 HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef1 =
64 HwvtepHAUtil.convertLocatorRef(src.getRemoteLocatorRef(), nodePath);
66 tunnelsBuilder.withKey(new TunnelsKey(hwvtepPhysicalLocatorRef,hwvtepPhysicalLocatorRef1));
67 return tunnelsBuilder.build();
71 public Identifier getKey(Tunnels data) {
76 public String getDescription() {
81 public boolean areEqual(Tunnels updated, Tunnels orig) {
82 InstanceIdentifier<TerminationPoint> remoteLocatorRefUpdated = (InstanceIdentifier<TerminationPoint>)
83 updated.getRemoteLocatorRef().getValue();
84 InstanceIdentifier<TerminationPoint> remoteLocatorRefOriginal = (InstanceIdentifier<TerminationPoint>)
85 orig.getRemoteLocatorRef().getValue();
86 TpId tpId1 = remoteLocatorRefUpdated.firstKeyOf(TerminationPoint.class).getTpId();
87 TpId tpId2 = remoteLocatorRefOriginal.firstKeyOf(TerminationPoint.class).getTpId();
88 return tpId1.equals(tpId2);
92 public Tunnels withoutUuid(Tunnels data) {
93 return new TunnelsBuilder(data).setTunnelUuid(null).build();