Bug 615: Removed xtend from Topology Manager
[controller.git] / opendaylight / md-sal / topology-manager / src / main / java / org / opendaylight / md / controller / topology / manager / FlowCapableNodeMapping.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.md.controller.topology.manager;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.topology.inventory.rev131030.InventoryNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.topology.inventory.rev131030.InventoryNodeBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.topology.inventory.rev131030.InventoryNodeConnector;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.topology.inventory.rev131030.InventoryNodeConnectorBuilder;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
31
32 public final class FlowCapableNodeMapping {
33
34     private FlowCapableNodeMapping() {
35         throw new UnsupportedOperationException("Utility class.");
36     }
37
38     public static NodeKey getNodeKey(final NodeRef ref) {
39         return ref.getValue().firstKeyOf(Node.class, NodeKey.class);
40     }
41
42     public static NodeKey getNodeKey(final NodeConnectorRef ref) {
43         return ref.getValue().firstKeyOf(Node.class, NodeKey.class);
44     }
45
46     public static NodeConnectorKey getNodeConnectorKey(final NodeConnectorRef ref) {
47         return ref.getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
48     }
49
50     public static NodeId toTopologyNodeId(
51             final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId) {
52         return new NodeId(nodeId);
53     }
54
55     private static NodeId toTopologyNodeId(final NodeConnectorRef source) {
56         return toTopologyNodeId(getNodeKey(source).getId());
57     }
58
59     public static TpId toTerminationPointId(final NodeConnectorId id) {
60         return new TpId(id);
61     }
62
63     private static TpId toTerminationPointId(final NodeConnectorRef source) {
64         return toTerminationPointId(getNodeConnectorKey(source).getId());
65     }
66
67     public static org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node toTopologyNode(
68             final NodeId nodeId, final NodeRef invNodeRef) {
69         return new NodeBuilder() //
70                 .setNodeId(nodeId) //
71                 .addAugmentation(InventoryNode.class, new InventoryNodeBuilder() //
72                         .setInventoryNodeRef(invNodeRef) //
73                         .build()) //
74                 .build();
75     }
76
77     public static TerminationPoint toTerminationPoint(final TpId id, final NodeConnectorRef invNodeConnectorRef) {
78         return new TerminationPointBuilder() //
79                 .setTpId(id) //
80                 .addAugmentation(InventoryNodeConnector.class, new InventoryNodeConnectorBuilder() //
81                         .setInventoryNodeConnectorRef(invNodeConnectorRef) //
82                         .build()) //
83                 .build();
84     }
85
86     public static Link toTopologyLink(
87             final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.Link link) {
88         return new LinkBuilder() //
89                 .setSource(new SourceBuilder() //
90                         .setSourceNode(toTopologyNodeId(link.getSource())) //
91                         .setSourceTp(toTerminationPointId(link.getSource())) //
92                         .build()) //
93                 .setDestination(new DestinationBuilder() //
94                         .setDestNode(toTopologyNodeId(link.getDestination())) //
95                         .setDestTp(toTerminationPointId(link.getDestination())) //
96                         .build()) //
97                 .setLinkId(new LinkId(getNodeConnectorKey(link.getSource()).getId())) //
98                 .build();
99     }
100 }