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<TerminationPoint> getTerminationPointIid(
135 InstanceIdentifier<TerminationPoint> terminationPointPath =
137 .create(NetworkTopology.class)
138 .child(Topology.class,
139 new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
142 .child(TerminationPoint.class,
143 new TerminationPointKey(tpId));
144 return terminationPointPath;
147 public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
149 List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
150 LogicalDatastoreType.OPERATIONAL);
151 for (Node node : uniNodes) {
152 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
153 if (uniAugmentation.getIpAddress().equals(ip)) {
154 InstanceIdentifier<Node> uniNode = InstanceIdentifier
155 .create(NetworkTopology.class)
156 .child(Topology.class,
157 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
159 new NodeKey(node.getKey()));
166 public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
168 LogicalDatastoreType store) {
169 List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
171 for (Node node : uniNodes) {
172 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
173 if (uniAugmentation.getIpAddress().equals(ip)) {
174 InstanceIdentifier<Node> uniNode = InstanceIdentifier
175 .create(NetworkTopology.class)
176 .child(Topology.class,
177 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
179 new NodeKey(node.getKey()));
186 public static InstanceIdentifier<Topology> getUniTopologyIid() {
187 InstanceIdentifier<Topology> topoPath = InstanceIdentifier
188 .create(NetworkTopology.class)
189 .child(Topology.class,
190 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID));
194 public static InstanceIdentifier<Node> getUniTopologyNodeIid() {
195 InstanceIdentifier<Node> nodePath = InstanceIdentifier
196 .create(NetworkTopology.class)
197 .child(Topology.class,
198 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))