2 * Copyright (c) 2015 CableLabs 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.unimgr.impl;
10 import java.util.List;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
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;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 public class UnimgrMapper {
33 public static InstanceIdentifier<Node> createOvsdbBridgeNodeIid(Node ovsdbNode,
35 String bridgeNodeName = ovsdbNode.getNodeId().getValue()
36 + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
38 NodeId bridgeNodeId = new NodeId(bridgeNodeName);
39 InstanceIdentifier<Node> bridgeNodePath = InstanceIdentifier
40 .create(NetworkTopology.class)
41 .child(Topology.class,
42 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
43 .child(Node.class, new NodeKey(bridgeNodeId));
44 return bridgeNodePath;
47 public static InstanceIdentifier<Link> getEvcLinkIid(LinkId id) {
48 InstanceIdentifier<Link> linkPath = InstanceIdentifier
49 .create(NetworkTopology.class)
50 .child(Topology.class,
51 new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
57 public static InstanceIdentifier<Topology> getEvcTopologyIid() {
58 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
59 .create(NetworkTopology.class)
60 .child(Topology.class,
61 new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID));
65 public static InstanceIdentifier<Node> getEvcTopologyNodeIid() {
66 InstanceIdentifier<Node> nodePath = InstanceIdentifier
67 .create(NetworkTopology.class)
68 .child(Topology.class,
69 new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
74 public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(Node ovsdbNode) {
75 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
76 InstanceIdentifier<Node> nodePath = ovsdbNodeAugmentation
77 .getManagedNodeEntry()
82 .firstIdentifierOf(Node.class);
86 public static InstanceIdentifier<Node> getOvsdbNodeIid(IpAddress ipAddress) {
87 String nodeId = UnimgrConstants.OVSDB_PREFIX
88 + ipAddress.getIpv4Address().getValue().toString()
90 + UnimgrConstants.OVSDB_PORT;
91 InstanceIdentifier<Node> nodePath = InstanceIdentifier
92 .create(NetworkTopology.class)
93 .child(Topology.class,
94 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
96 new NodeKey(new NodeId(nodeId)));
100 public static InstanceIdentifier<Node> getOvsdbNodeIid(NodeId nodeId) {
101 InstanceIdentifier<Node> nodePath = InstanceIdentifier
102 .create(NetworkTopology.class)
103 .child(Topology.class,
104 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
106 new NodeKey(nodeId));
110 public static InstanceIdentifier<Topology> getOvsdbTopologyIid() {
111 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
112 .create(NetworkTopology.class)
113 .child(Topology.class,
114 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID));
118 public static InstanceIdentifier<TerminationPoint> getTerminationPointIid(
121 InstanceIdentifier<TerminationPoint> terminationPointPath =
123 .create(NetworkTopology.class)
124 .child(Topology.class,
125 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
126 .child(Node.class, bridgeNode.getKey())
127 .child(TerminationPoint.class,
128 new TerminationPointKey(new TpId(portName)));
129 return terminationPointPath;
132 public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
134 List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
135 LogicalDatastoreType.OPERATIONAL);
136 for (Node node : uniNodes) {
137 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
138 if (uniAugmentation.getIpAddress().equals(ip)) {
139 InstanceIdentifier<Node> uniNode = InstanceIdentifier
140 .create(NetworkTopology.class)
141 .child(Topology.class,
142 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
144 new NodeKey(node.getKey()));
151 public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
153 LogicalDatastoreType store) {
154 List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
156 for (Node node : uniNodes) {
157 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
158 if (uniAugmentation.getIpAddress().equals(ip)) {
159 InstanceIdentifier<Node> uniNode = InstanceIdentifier
160 .create(NetworkTopology.class)
161 .child(Topology.class,
162 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
164 new NodeKey(node.getKey()));
171 public static InstanceIdentifier<Topology> getUniTopologyIid() {
172 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
173 .create(NetworkTopology.class)
174 .child(Topology.class,
175 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID));
179 public static InstanceIdentifier<Node> getUniTopologyNodeIid() {
180 InstanceIdentifier<Node> nodePath = InstanceIdentifier
181 .create(NetworkTopology.class)
182 .child(Topology.class,
183 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))