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 {
34 * Create an OVSDB Bridge node Instance Identifier by constructing
35 * a nodeId manually. This function is different from
36 * getOvsdbBridgeNodeIid
37 * @param ovsdbNode The OVSDB node that has the OvsdbNodeAugmentation
38 * @param bridgeName The bridge name appended to the URI.
39 * @return An Instance Identifier of a bridge
41 public static InstanceIdentifier<Node> createOvsdbBridgeNodeIid(Node ovsdbNode,
43 String bridgeNodeName = ovsdbNode.getNodeId().getValue()
44 + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
46 NodeId bridgeNodeId = new NodeId(bridgeNodeName);
47 InstanceIdentifier<Node> bridgeNodePath = InstanceIdentifier
48 .create(NetworkTopology.class)
49 .child(Topology.class,
50 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
51 .child(Node.class, new NodeKey(bridgeNodeId));
52 return bridgeNodePath;
56 * Generates an Instance Identifier by using a Link ID. The Link Id
57 * is appended as a link key.
58 * @param id The LinkId of a given Link. Similiar to a nodeId.
59 * @return An Instance Identifier for a given Link
61 public static InstanceIdentifier<Link> getEvcLinkIid(LinkId id) {
62 InstanceIdentifier<Link> linkPath = InstanceIdentifier
63 .create(NetworkTopology.class)
64 .child(Topology.class,
65 new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
72 * Generates an Instance Identifier for the unimgr:evc URI.
73 * @return An Instance Identifier for the EVC topology: unimgr:evc
75 public static InstanceIdentifier<Topology> getEvcTopologyIid() {
76 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
77 .create(NetworkTopology.class)
78 .child(Topology.class,
79 new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID));
84 * Generates an Instance Identifier for the EVC nodes.
85 * @return An Instance Identifier for the EVC nodes.
87 public static InstanceIdentifier<Node> getEvcTopologyNodeIid() {
88 InstanceIdentifier<Node> nodePath = InstanceIdentifier
89 .create(NetworkTopology.class)
90 .child(Topology.class,
91 new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
97 * Generates an Instance Identifier for an OvsdbBridgeNode by retrieving the Iid
98 * via the OvsdbNodeAugmentation's BridgeRef.
99 * the same as createOvsdbBridgeNodeIid.
101 * @return An Instance Identifier for a bridge associated with an OVSDB node.
103 public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(Node ovsdbNode) {
104 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
105 InstanceIdentifier<Node> nodePath = ovsdbNodeAugmentation
106 .getManagedNodeEntry()
111 .firstIdentifierOf(Node.class);
116 * Generates an Instance Identifier for a specific OVSDB node
117 * by using its IP address.
118 * @param ipAddress The IP address of the OVSDB node. This should be the remote IP
119 * @return An Instance Identifier for a specific OVSDB node
121 public static InstanceIdentifier<Node> getOvsdbNodeIid(IpAddress ipAddress) {
122 String nodeId = UnimgrConstants.OVSDB_PREFIX
123 + ipAddress.getIpv4Address().getValue().toString()
125 + UnimgrConstants.OVSDB_PORT;
126 InstanceIdentifier<Node> nodePath = InstanceIdentifier
127 .create(NetworkTopology.class)
128 .child(Topology.class,
129 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
131 new NodeKey(new NodeId(nodeId)));
136 * Generates an Instance Identifier for a specific OVSDB node by
138 * @param nodeId The node ID of a specific OVSDB node.
139 * @return An Instance Identifier for a specific OVSDB node.
141 public static InstanceIdentifier<Node> getOvsdbNodeIid(NodeId nodeId) {
142 InstanceIdentifier<Node> nodePath = InstanceIdentifier
143 .create(NetworkTopology.class)
144 .child(Topology.class,
145 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
147 new NodeKey(nodeId));
152 * Generates an Instance Identifier for the OVSDB topology ovsdb:1
153 * @return An Instance Identifier for the OVSDB topology ovsdb:1
155 public static InstanceIdentifier<Topology> getOvsdbTopologyIid() {
156 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
157 .create(NetworkTopology.class)
158 .child(Topology.class,
159 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID));
164 * Generates an Instance Identifier for a Termination Point by using
165 * the Bridge Node and the Port Name.
166 * @param bridgeNode The bridge where the port resides.
167 * @param portName The name of the port, example: eth0
170 public static InstanceIdentifier<TerminationPoint> getTerminationPointIid(
173 InstanceIdentifier<TerminationPoint> terminationPointPath =
175 .create(NetworkTopology.class)
176 .child(Topology.class,
177 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
178 .child(Node.class, bridgeNode.getKey())
179 .child(TerminationPoint.class,
180 new TerminationPointKey(new TpId(portName)));
181 return terminationPointPath;
185 * Generates an Instance Identifier for a Termination Point
186 * by using the bridge node and the Termination Point ID.
187 * @param bridgeNode The bridge Node to where the TP resides.
188 * @param tpId The termination point ID
189 * @return An Instance Identifier for a specific TP
191 public static InstanceIdentifier<TerminationPoint> getTerminationPointIid(
194 InstanceIdentifier<TerminationPoint> terminationPointPath =
196 .create(NetworkTopology.class)
197 .child(Topology.class,
198 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
201 .child(TerminationPoint.class,
202 new TerminationPointKey(tpId));
203 return terminationPointPath;
207 * Generates an Instance Identifier for a UNI by querying the datastore.
208 * Query will ask the Operational store by default.
210 * @param ip The IP of the UNI
211 * @return An Instance Identifier of a UNI by using its IP address.
213 public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
215 List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
216 LogicalDatastoreType.OPERATIONAL);
217 for (Node node : uniNodes) {
218 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
219 if (uniAugmentation.getIpAddress().equals(ip)) {
220 InstanceIdentifier<Node> uniNode = InstanceIdentifier
221 .create(NetworkTopology.class)
222 .child(Topology.class,
223 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
225 new NodeKey(node.getKey()));
233 * Generates an Instance Identifier for a UNI by querying the datastore
234 * with the IP address of the UNI.
236 * @param ip The IP of the UNI
237 * @param store The store where the query should be sent
238 * @return An Instance Identifier of a UNI by using its IP address.
240 public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
242 LogicalDatastoreType store) {
243 List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
245 for (Node node : uniNodes) {
246 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
247 if (uniAugmentation.getIpAddress().equals(ip)) {
248 InstanceIdentifier<Node> uniNode = InstanceIdentifier
249 .create(NetworkTopology.class)
250 .child(Topology.class,
251 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
253 new NodeKey(node.getKey()));
261 * Generates an Instance Identifier for the UNI topology: unimgr:uni
262 * @return An Instance Identifier for the UNI topology
264 public static InstanceIdentifier<Topology> getUniTopologyIid() {
265 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
266 .create(NetworkTopology.class)
267 .child(Topology.class,
268 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID));
273 * Generates an Instance Identifier for UNI nodes topology.
274 * @return An Instance Identifier for the UNI nodes topology.
276 public static InstanceIdentifier<Node> getUniTopologyNodeIid() {
277 InstanceIdentifier<Node> nodePath = InstanceIdentifier
278 .create(NetworkTopology.class)
279 .child(Topology.class,
280 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
286 * Generates an Instance Identifier for a specific UNI node by
288 * @param nodeId The node ID of a specific UNI node.
289 * @return An Instance Identifier for a specific UNI node.
291 public static InstanceIdentifier<Node> getUniNodeIid(NodeId nodeId) {
292 InstanceIdentifier<Node> nodePath = InstanceIdentifier
293 .create(NetworkTopology.class)
294 .child(Topology.class,
295 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
297 new NodeKey(nodeId));