Modified scm section.
[unimgr.git] / impl / src / main / java / org / opendaylight / vcpe / impl / VcpeMapper.java
1 /*
2  * Copyright (c) 2015 CableLabs 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.vcpe.impl;
9
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.Evcs;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.Unis;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.evcs.Evc;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.evcs.EvcKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.unis.Uni;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vcpe.rev150622.unis.UniKey;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class VcpeMapper {
31
32     private static final Logger LOG = LoggerFactory.getLogger(VcpeMapper.class);
33
34     public static InstanceIdentifier<Unis> getUnisIid() {
35         return InstanceIdentifier.builder(Unis.class)
36                 .build();
37     }
38
39     public static InstanceIdentifier<Uni> getUniIid() {
40         return InstanceIdentifier.builder(Unis.class)
41                 .child(Uni.class)
42                 .build();
43     }
44
45     public static InstanceIdentifier<Uni> getUniIid(String id) {
46         return InstanceIdentifier.builder(Unis.class)
47                 .child(Uni.class, new UniKey(new NodeId(id)))
48                 .build();
49     }
50
51     public static InstanceIdentifier<Uni> getUniIid(UniKey uniKey) {
52         return InstanceIdentifier.builder(Unis.class)
53                 .child(Uni.class, uniKey)
54                 .build();
55     }
56
57     public static InstanceIdentifier<Uni> getUniIid(NodeId uniNodeId) {
58         return InstanceIdentifier.builder(Unis.class)
59                 .child(Uni.class, new UniKey(uniNodeId))
60                 .build();
61     }
62
63     public static InstanceIdentifier<Uni> getUniIid(Uni uni) {
64         return InstanceIdentifier.builder(Unis.class)
65                 .child(Uni.class, uni.getKey())
66                 .build();
67     }
68
69     public static InstanceIdentifier<Evcs> getEvcsIid() {
70         return InstanceIdentifier.builder(Evcs.class)
71                 .build();
72     }
73
74     public static InstanceIdentifier<Evc> getEvcIid() {
75         return InstanceIdentifier.builder(Evcs.class)
76                 .child(Evc.class)
77                 .build();
78     }
79
80     public static InstanceIdentifier<Evc> getEvcIid(String id) {
81         return InstanceIdentifier.builder(Evcs.class)
82                 .child(Evc.class, new EvcKey(new NodeId(id)))
83                 .build();
84     }
85
86     public static InstanceIdentifier<Node> getOvsdbNodeIID(NodeId nodeId) {
87         InstanceIdentifier<Node> nodePath = InstanceIdentifier
88                 .create(NetworkTopology.class)
89                 .child(Topology.class, new TopologyKey(VcpeConstants.OVSDB_TOPOLOGY_ID))
90                 .child(Node.class,new NodeKey(nodeId));
91         return nodePath;
92     }
93
94     public static InstanceIdentifier<Node> getOvsdbBridgeNodeIID(NodeId ovsdbNode, String bridgeName) {
95         NodeId bridgeNodeId = new NodeId(ovsdbNode + VcpeConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX + bridgeName);
96         InstanceIdentifier<Node> nodePath = InstanceIdentifier
97                 .create(NetworkTopology.class)
98                 .child(Topology.class, new TopologyKey(VcpeConstants.OVSDB_TOPOLOGY_ID))
99                 .child(Node.class,new NodeKey(bridgeNodeId));
100         return nodePath;
101     }
102
103     public static InstanceIdentifier<Node> getOvsdbNodeIID(IpAddress ipAddress) {
104         String nodeId = VcpeConstants.OVSDB_PREFIX
105                 + ipAddress.getIpv4Address().getValue().toString()
106                 + ":"
107                 + VcpeConstants.OVSDB_PORT;
108         InstanceIdentifier<Node> nodePath = InstanceIdentifier
109                 .create(NetworkTopology.class)
110                 .child(Topology.class, new TopologyKey(VcpeConstants.OVSDB_TOPOLOGY_ID))
111                 .child(Node.class,new NodeKey(new NodeId(nodeId)));
112         return nodePath;
113     }
114
115     public static NodeId createNodeId(IpAddress ipAddress) {
116         String nodeId = VcpeConstants.OVSDB_PREFIX
117                 + ipAddress.getIpv4Address().getValue().toString()
118                 + ":"
119                 + VcpeConstants.OVSDB_PORT;
120         return new NodeId(nodeId);
121     }
122
123     public static InstanceIdentifier<Node> getOvsdbTopologyIdentifier() {
124         InstanceIdentifier<Node> path = InstanceIdentifier
125                 .create(NetworkTopology.class)
126                 .child(Topology.class,
127                         new TopologyKey(VcpeConstants.OVSDB_TOPOLOGY_ID))
128                 .child(Node.class);
129         return path;
130     }
131
132     public static InstanceIdentifier<TerminationPoint> createTerminationPointInstanceIdentifier(
133             Node bridgeNode, String portName) {
134         InstanceIdentifier<TerminationPoint> terminationPointPath = InstanceIdentifier
135                 .create(NetworkTopology.class)
136                 .child(Topology.class, new TopologyKey(VcpeConstants.OVSDB_TOPOLOGY_ID))
137                 .child(Node.class,bridgeNode.getKey())
138                 .child(TerminationPoint.class, new TerminationPointKey(new TpId(portName)));
139
140         LOG.debug("Termination point InstanceIdentifier generated : {}",terminationPointPath);
141         return terminationPointPath;
142     }
143 }