blob: ec74b9ef08962439107f175afb51e5008d1cec43 [file] [log] [blame]
Yixiao Chen39828a62016-09-14 14:37:06 -04001/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.teyang.utils.topology;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.List;
21
22import org.onosproject.tetopology.management.api.KeyId;
23import org.onosproject.tetopology.management.api.node.TeTerminationPoint;
24import org.onosproject.tetopology.management.api.node.TerminationPointKey;
25import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
26import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
27import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
28 .ietfnetworktopology.TpId;
29import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
30 .ietfnetworktopology.networks.network.node.augmentedndnode.DefaultTerminationPoint;
31import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
32 .ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint;
33import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
34 .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint
35 .DefaultSupportingTerminationPoint;
36import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
37 .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint
38 .SupportingTerminationPoint;
39import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
40 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint.DefaultTe;
41import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
42 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint.Te.TeBuilder;
43import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
44 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint.te.Config;
45import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
46 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint.te.DefaultConfig;
47import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
48 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint.te.DefaultState;
49import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
50 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint.te.State;
51import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
52 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint
53 .te.config.DefaultInterfaceSwitchingCapability;
54import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
55 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint
56 .te.config.InterfaceSwitchingCapability;
57import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId;
58import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
59 .ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
60import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
61 .ietftetopology.networks.network.node.terminationpoint.DefaultAugmentedNtTerminationPoint;
62
63import com.google.common.collect.Lists;
64
65/**
66 * The termination point translations.
67 */
68public final class TerminationPointConverter {
69
70 private static final String E_NULL_TE_SUBSYSTEM_TP = "TeSubsystem terminationPoint object cannot be null";
71 private static final String E_NULL_YANG_TP = "YANG terminationPoint object cannot be null";
72
73 // no instantiation
74 private TerminationPointConverter() {
75 }
76
77 /**
78 * TerminationPoint object translation from TE Topology subsystem to YANG.
79 *
80 * @param teSubsystem TE Topology subsystem termination point object
81 * @return TerminationPoint YANG object
82 */
83 public static TerminationPoint teSubsystem2YangTerminationPoint(
84 org.onosproject.tetopology.management.api.node.TerminationPoint teSubsystem) {
85 checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_TP);
86
87 TpId tpId = TpId.fromString(teSubsystem.id().toString());
88 TerminationPoint.TerminationPointBuilder builder =
89 new DefaultTerminationPoint.TerminationPointBuilder().tpId(tpId);
90
91 if (teSubsystem.getSupportingTpIds() != null) {
92 List<SupportingTerminationPoint> tps = Lists.newArrayList();
93 SupportingTerminationPoint.SupportingTerminationPointBuilder
94 spTpBuilder = DefaultSupportingTerminationPoint.builder();
95 for (TerminationPointKey tpKey : teSubsystem.getSupportingTpIds()) {
96 tps.add(spTpBuilder.networkRef(NetworkId.fromString(tpKey.networkId().toString()))
97 .nodeRef(NodeId.fromString(tpKey.nodeId().toString()))
98 .tpRef(TpId.fromString(tpKey.tpId().toString()))
99 .build());
100 }
101 builder = builder.supportingTerminationPoint(tps);
102 }
103
104 if (teSubsystem.getTe() != null) {
105 AugmentedNtTerminationPoint.AugmentedNtTerminationPointBuilder
106 tpAugmentBuilder = DefaultAugmentedNtTerminationPoint.builder();
107
108 TeTerminationPoint teSubsystemTe = teSubsystem.getTe();
109 TeBuilder yangTeBuilder = DefaultTe.builder();
110
111 if (teSubsystemTe.teTpId() != null) {
112 yangTeBuilder = yangTeBuilder.teTpId(TeTpId.fromString(teSubsystemTe.teTpId().toString()));
113 }
114
115 Config yConfig = teSubsystem2YangTeAugConfig(teSubsystemTe);
116 yangTeBuilder = yangTeBuilder.config(yConfig);
117
118 State yState = teSubsystem2YangTeAugState(teSubsystemTe);
119 yangTeBuilder = yangTeBuilder.state(yState);
120
121 tpAugmentBuilder = tpAugmentBuilder.te(yangTeBuilder.build());
122 builder.addYangAugmentedInfo(tpAugmentBuilder.build(), AugmentedNtTerminationPoint.class);
123 }
124
125 return builder.build();
126 }
127
128 private static State teSubsystem2YangTeAugState(TeTerminationPoint teSubsystemTe) {
129 State.StateBuilder yangStateBuilder = DefaultState.builder();
130 yangStateBuilder.interLayerLockId(teSubsystemTe.getInterLayerLockId());
131
132 if (teSubsystemTe.interfaceSwitchingCapabilities() != null) {
133 for (org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability teIsc :
134 teSubsystemTe.interfaceSwitchingCapabilities()) {
135 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
136 .ietftetopology.networks.network.node.terminationpoint.augmentedntterminationpoint
137 .te.state.InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder
138 isc = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology
139 .rev20160708.ietftetopology.networks.network.node.terminationpoint
140 .augmentedntterminationpoint.te.state.DefaultInterfaceSwitchingCapability.builder();
141 // FIXME: teIsc at this moment is empty, therefore we cannot
142 // really add its attributes to isc
143 yangStateBuilder.addToInterfaceSwitchingCapability(isc.build());
144 }
145 }
146 return yangStateBuilder.build();
147 }
148
149 private static Config teSubsystem2YangTeAugConfig(TeTerminationPoint teSubsystemTe) {
150 Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder();
151 yangConfigBuilder = yangConfigBuilder.interLayerLockId(teSubsystemTe.getInterLayerLockId());
152 if (teSubsystemTe.interfaceSwitchingCapabilities() != null) {
153 for (org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability teIsc :
154 teSubsystemTe.interfaceSwitchingCapabilities()) {
155 InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder
156 isc = DefaultInterfaceSwitchingCapability.builder();
157 // FIXME: teIsc at this moment is empty, therefore we cannot
158 // really add its attributes to isc
159 yangConfigBuilder = yangConfigBuilder.addToInterfaceSwitchingCapability(isc.build());
160 }
161 }
162 return yangConfigBuilder.build();
163 }
164
165 /**
166 * TerminationPoint object translation from YANG to TE Topology subsystem.
167 *
168 * @param yangTp TerminationPoint YANG object
169 * @return TerminationPoint TE Topology subsystem termination point object
170 */
171 public static org.onosproject.tetopology.management.api.node.TerminationPoint
172 yang2teSubsystemTerminationPoint(TerminationPoint yangTp) {
173 checkNotNull(yangTp, E_NULL_YANG_TP);
174
175 org.onosproject.tetopology.management.api.node.DefaultTerminationPoint tp = new org.onosproject.tetopology
176 .management.api.node.DefaultTerminationPoint(KeyId.keyId(yangTp.tpId().uri().string()));
177
178 if (yangTp.supportingTerminationPoint() != null) {
179 List<org.onosproject.tetopology.management.api.node.TerminationPointKey> spTps = Lists.newArrayList();
180 for (SupportingTerminationPoint yangSptp : yangTp.supportingTerminationPoint()) {
181 org.onosproject.tetopology.management.api.node.TerminationPointKey tpKey =
182 new org.onosproject.tetopology.management.api.node.TerminationPointKey(
183 KeyId.keyId(yangSptp.networkRef().uri().string()),
184 KeyId.keyId(yangSptp.nodeRef().uri().string()),
185 KeyId.keyId(yangSptp.tpRef().uri().string()));
186 spTps.add(tpKey);
187 }
188 tp.setSupportingTpIds(spTps);
189 }
190
191 if (yangTp.yangAugmentedInfoMap() != null && !yangTp.yangAugmentedInfoMap().isEmpty()) {
192 AugmentedNtTerminationPoint yangTpAugment =
193 (AugmentedNtTerminationPoint) yangTp.yangAugmentedInfo(AugmentedNtTerminationPoint.class);
194 if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) {
195 KeyId teTpId = KeyId.keyId(yangTpAugment.te().teTpId().toString());
196 if (yangTpAugment.te().config() != null) {
197 long interLayerLockId = yangTpAugment.te().config().interLayerLockId();
198 List<org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability>
199 teIscList = Lists.newArrayList();
200 // FIXME: the following line is for config. State also has
201 // similar stuff, but Te Subsystem does not diffrentiate
202 // between the two
203 if (yangTpAugment.te().config().interfaceSwitchingCapability() != null) {
204 for (InterfaceSwitchingCapability iscConfigYang :
205 yangTpAugment.te().config().interfaceSwitchingCapability()) {
206 org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability iscTe =
207 new org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability();
208 // FIXME: at this moment, iscTe does not have any
209 // attributes. Therefore, I cannot feed it with
210 // attributes of iscConfigYang
211 teIscList.add(iscTe);
212 }
213 }
214
215 TeTerminationPoint teSubsystemTp = new TeTerminationPoint(teTpId,
216 teIscList,
217 interLayerLockId);
218 tp.setTe(teSubsystemTp);
219 }
220 }
221 }
222 return tp;
223 }
224
225}