Merge "Add filtering capability to config.ini in order to reference logging bridge...
[controller.git] / opendaylight / md-sal / compatibility / inventory-topology-compatibility / src / main / java / org / opendaylight / controller / md / compatibility / topologymanager / AdSalTopologyMapping.xtend
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.controller.md.compatibility.topologymanager
9
10 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
13 import org.opendaylight.controller.sal.core.NodeConnector
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
16 import java.util.Map
17 import org.opendaylight.controller.sal.core.Edge
18 import java.util.Set
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
20 import java.util.HashSet
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
22 import org.opendaylight.controller.sal.compatibility.NodeMapping
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
30 import java.util.HashMap
31
32 class AdSalTopologyMapping {
33
34     val TopologyKey topologyMapping;
35     @Property
36     val InstanceIdentifier<Topology> topologyPath;
37
38     new(TopologyKey topology) {
39         topologyMapping = topology;
40         _topologyPath = InstanceIdentifier.builder(NetworkTopology).child(Topology, topology).toInstance;
41     }
42
43     def InstanceIdentifier<TerminationPoint> toTerminationPoint(NodeConnector connector) {
44         InstanceIdentifier.builder(topologyPath).child(Node).child(TerminationPoint, connector.toTerminationPointKey()).toInstance;
45     }
46
47     def Map<Edge, Set<org.opendaylight.controller.sal.core.Property>> toEdgePropertiesMap(Iterable<Link> links) {
48         val ret = new HashMap<Edge, Set<org.opendaylight.controller.sal.core.Property>>
49         for (link : links) {
50             ret.put(link.toEdge(), link.toProperties())
51         }
52         return ret;
53     }
54
55     def Set<Edge> toEdges(Iterable<Link> links) {
56         val ret = new HashSet<Edge>
57         for (link : links) {
58             ret.add(link.toEdge)
59         }
60         return ret;
61     }
62
63     def Edge toEdge(Link link) {
64         val tail = link.source.toNodeConnector();
65         val head = link.destination.toNodeConnector();
66         return new Edge(tail, head);
67     }
68
69     def org.opendaylight.controller.sal.core.Node toAdNode(Node node) {
70         return node.nodeId.toAdNode;
71     }
72
73     def org.opendaylight.controller.sal.core.Node toAdNode(
74         org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId node) {
75         val key = new NodeKey(new NodeId(node))
76         return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
77     }
78
79     def NodeConnector toNodeConnector(Source ref) {
80         val adNode = ref.sourceNode.toAdNode();
81         val key = new NodeConnectorKey(new NodeConnectorId(ref.sourceTp))
82         return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
83     }
84
85     def NodeConnector toNodeConnector(Destination ref) {
86         val adNode = ref.destNode.toAdNode();
87         val key = new NodeConnectorKey(new NodeConnectorId(ref.destTp))
88         return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
89     }
90
91     def TerminationPointKey toTerminationPointKey(NodeConnector connector) {
92     }
93
94     def Set<org.opendaylight.controller.sal.core.Property> toProperties(Link link) {
95     }
96 }