2d7cfc2e200bef94d35eb295607afa8d4162529a
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / commands / TunnelCmd.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
9
10 import java.util.List;
11 import javax.annotation.Nullable;
12 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
22 import org.opendaylight.yangtools.yang.binding.Identifier;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 public class TunnelCmd  extends MergeCommand<Tunnels, PhysicalSwitchAugmentationBuilder, PhysicalSwitchAugmentation> {
26
27     public TunnelCmd() {
28     }
29
30     @Override
31     @Nullable
32     public List<Tunnels> getData(PhysicalSwitchAugmentation node) {
33         if (node != null) {
34             return node.getTunnels();
35         }
36         return null;
37     }
38
39     @Override
40     public void setData(PhysicalSwitchAugmentationBuilder builder, List<Tunnels> data) {
41         builder.setTunnels(data);
42     }
43
44     @Override
45     public InstanceIdentifier<Tunnels> generateId(InstanceIdentifier<Node> id, Tunnels src) {
46         HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef =
47                 HwvtepHAUtil.convertLocatorRef(src.getLocalLocatorRef(), id);
48         HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef1 =
49                 HwvtepHAUtil.convertLocatorRef(src.getRemoteLocatorRef(), id);
50         TunnelsKey key = new TunnelsKey(hwvtepPhysicalLocatorRef, hwvtepPhysicalLocatorRef1);
51         return id.augmentation(PhysicalSwitchAugmentation.class).child(Tunnels.class, key);
52     }
53
54     @Override
55     public Tunnels transform(InstanceIdentifier<Node> nodePath, Tunnels src) {
56         TunnelsBuilder tunnelsBuilder = new TunnelsBuilder(src);
57         tunnelsBuilder.setLocalLocatorRef(HwvtepHAUtil.convertLocatorRef(src.getLocalLocatorRef(), nodePath));
58         tunnelsBuilder.setRemoteLocatorRef(HwvtepHAUtil.convertLocatorRef(src.getRemoteLocatorRef(), nodePath));
59         tunnelsBuilder.setTunnelUuid(HwvtepHAUtil.getUUid(HwvtepHAUtil.getTepIpVal(src.getRemoteLocatorRef())));
60         HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef =
61                 HwvtepHAUtil.convertLocatorRef(src.getLocalLocatorRef(), nodePath);
62         HwvtepPhysicalLocatorRef hwvtepPhysicalLocatorRef1 =
63                 HwvtepHAUtil.convertLocatorRef(src.getRemoteLocatorRef(), nodePath);
64
65         tunnelsBuilder.withKey(new TunnelsKey(hwvtepPhysicalLocatorRef,hwvtepPhysicalLocatorRef1));
66         return tunnelsBuilder.build();
67     }
68
69     @Override
70     public Identifier getKey(Tunnels data) {
71         return data.key();
72     }
73
74     @Override
75     public String getDescription() {
76         return "Tunnels";
77     }
78
79     @Override
80     public boolean areEqual(Tunnels updated, Tunnels orig) {
81         InstanceIdentifier<TerminationPoint> remoteLocatorRefUpdated = (InstanceIdentifier<TerminationPoint>)
82                 updated.getRemoteLocatorRef().getValue();
83         InstanceIdentifier<TerminationPoint> remoteLocatorRefOriginal = (InstanceIdentifier<TerminationPoint>)
84                 orig.getRemoteLocatorRef().getValue();
85         TpId tpId1 = remoteLocatorRefUpdated.firstKeyOf(TerminationPoint.class).getTpId();
86         TpId tpId2 = remoteLocatorRefOriginal.firstKeyOf(TerminationPoint.class).getTpId();
87         return tpId1.equals(tpId2);
88     }
89
90     @Override
91     public Tunnels withoutUuid(Tunnels data) {
92         return new TunnelsBuilder(data).setTunnelUuid(null).build();
93     }
94 }