MRI version bumpup for Aluminium
[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.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;
25
26 public class TunnelCmd  extends MergeCommand<Tunnels, PhysicalSwitchAugmentationBuilder, PhysicalSwitchAugmentation> {
27
28     public TunnelCmd() {
29     }
30
31     @Override
32     @Nullable
33     public List<Tunnels> getData(PhysicalSwitchAugmentation node) {
34         if (node != null && node.getTunnels() != null) {
35             return new ArrayList<Tunnels>(node.getTunnels().values());
36         }
37         return null;
38     }
39
40     @Override
41     public void setData(PhysicalSwitchAugmentationBuilder builder, List<Tunnels> data) {
42         builder.setTunnels(data);
43     }
44
45     @Override
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);
53     }
54
55     @Override
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);
65
66         tunnelsBuilder.withKey(new TunnelsKey(hwvtepPhysicalLocatorRef,hwvtepPhysicalLocatorRef1));
67         return tunnelsBuilder.build();
68     }
69
70     @Override
71     public Identifier getKey(Tunnels data) {
72         return data.key();
73     }
74
75     @Override
76     public String getDescription() {
77         return "Tunnels";
78     }
79
80     @Override
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);
89     }
90
91     @Override
92     public Tunnels withoutUuid(Tunnels data) {
93         return new TunnelsBuilder(data).setTunnelUuid(null).build();
94     }
95 }