blob: 18ac803b6240f24f9733f4395d2c21cf730a6a0d [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
Hesam Rahimi39bdc002016-11-10 15:01:26 -050018import 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.TerminationPointKey;
24import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
25import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
26import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
27 .ietfnetworktopology.TpId;
28import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
29 .ietfnetworktopology.networks.network.node.augmentedndnode.DefaultTerminationPoint;
30import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
31 .ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint;
32import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
33 .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint
34 .DefaultSupportingTerminationPoint;
35import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
36 .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint
37 .SupportingTerminationPoint;
38import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.interfaceswitchingcapabilitylist.DefaultInterfaceSwitchingCapability;
39import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.interfaceswitchingcapabilitylist.InterfaceSwitchingCapability;
40import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.interfaceswitchingcapabilitylist.interfaceswitchingcapability.DefaultMaxLspBandwidth;
41import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.interfaceswitchingcapabilitylist.interfaceswitchingcapability.MaxLspBandwidth;
42import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
43 .ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
44import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
45 .ietftetopology.networks.network.node.terminationpoint.DefaultAugmentedNtTerminationPoint;
46import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.DefaultTe;
47import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.DefaultTe.TeBuilder;
48import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.Config;
49import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.DefaultConfig;
50import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.DefaultState;
51import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.State;
52import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId;
53
54import com.google.common.collect.Lists;
Yixiao Chen39828a62016-09-14 14:37:06 -040055
56/**
57 * The termination point translations.
58 */
59public final class TerminationPointConverter {
60
Henry Yu4b4a7eb2016-11-09 20:07:53 -050061 private static final String E_NULL_TE_SUBSYSTEM_TP =
62 "TeSubsystem terminationPoint object cannot be null";
63 private static final String E_NULL_YANG_TP =
64 "YANG terminationPoint object cannot be null";
Yixiao Chen39828a62016-09-14 14:37:06 -040065
66 // no instantiation
67 private TerminationPointConverter() {
68 }
69
70 /**
71 * TerminationPoint object translation from TE Topology subsystem to YANG.
72 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -050073 * @param teSubsystem TE Topology subsystem termination point
74 * @return Termination point in YANG Java data structure
Yixiao Chen39828a62016-09-14 14:37:06 -040075 */
Hesam Rahimi39bdc002016-11-10 15:01:26 -050076 public static TerminationPoint teSubsystem2YangTerminationPoint(org.onosproject.tetopology.management.api.node.
77 TerminationPoint teSubsystem) {
78 checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_TP);
Yixiao Chen39828a62016-09-14 14:37:06 -040079
Hesam Rahimi39bdc002016-11-10 15:01:26 -050080 TpId tpId = TpId.fromString(teSubsystem.tpId().toString());
81 TerminationPoint.TerminationPointBuilder builder =
82 new DefaultTerminationPoint.TerminationPointBuilder().tpId(tpId);
83
84 if (teSubsystem.supportingTpIds() != null) {
85 List<SupportingTerminationPoint> tps = Lists.newArrayList();
86 SupportingTerminationPoint.SupportingTerminationPointBuilder
87 spTpBuilder = DefaultSupportingTerminationPoint.builder();
88 for (TerminationPointKey tpKey : teSubsystem.supportingTpIds()) {
89 tps.add(spTpBuilder.networkRef(NetworkId.fromString(tpKey.networkId().toString()))
90 .nodeRef(NodeId.fromString(tpKey.nodeId().toString()))
91 .tpRef(TpId.fromString(tpKey.tpId().toString()))
92 .build());
93 }
94 builder = builder.supportingTerminationPoint(tps);
95 }
96
97 if (teSubsystem.teTpId() != null) {
98 AugmentedNtTerminationPoint.AugmentedNtTerminationPointBuilder
99 tpAugmentBuilder = DefaultAugmentedNtTerminationPoint.builder();
100
101 TeBuilder yangTeBuilder = DefaultTe.builder();
102
103 yangTeBuilder = yangTeBuilder.teTpId(TeTpId.fromString((String.valueOf(teSubsystem.teTpId()))));
104
105 Config yConfig = teSubsystem2YangTeAugConfig(teSubsystem);
106 yangTeBuilder = yangTeBuilder.config(yConfig);
107
108 State yState = teSubsystem2YangTeAugState(teSubsystem);
109 yangTeBuilder = yangTeBuilder.state(yState);
110
111 tpAugmentBuilder = tpAugmentBuilder.te(yangTeBuilder.build());
112 builder.addYangAugmentedInfo(tpAugmentBuilder.build(), AugmentedNtTerminationPoint.class);
113 }
114
115 return builder.build();
Yixiao Chen39828a62016-09-14 14:37:06 -0400116 }
117
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500118 private static State teSubsystem2YangTeAugState(org.onosproject.tetopology.management.api.node.
119 TerminationPoint teSubsystemTe) {
120 State.StateBuilder yangStateBuilder = DefaultState.builder();
121 // FIXME: interLayerLocks is a list in core but not in yang
122// yangStateBuilder = yangStateBuilder.interLayerLockId(teLink.interLayerLocks().get(0));
123
124 return yangStateBuilder.build();
125 }
126
127 private static Config teSubsystem2YangTeAugConfig(org.onosproject.tetopology.management.api.node.
128 TerminationPoint teSubsystemTe) {
129 Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder();
130 //FIXME: interLayerLocks is a list in core but not in yang
131 // yangConfigBuilder =
132 // yangConfigBuilder.interLayerLockId(teLink.interLayerLocks().get(0));
133
134 InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder isc =
135 DefaultInterfaceSwitchingCapability.builder();
136
137 MaxLspBandwidth.MaxLspBandwidthBuilder maxlspBW = DefaultMaxLspBandwidth
138 .builder();
139// for (float f : teLink.maxAvialLspBandwidth()) {
140// // is converting from float to long ok?
141// maxlspBW = maxlspBW.bandwidth(BigDecimal.valueOf((long) f));
142// isc = isc.addToMaxLspBandwidth(maxlspBW.build());
143// }
144
145 yangConfigBuilder = yangConfigBuilder.addToInterfaceSwitchingCapability(isc.build());
146
147 return yangConfigBuilder.build();
148 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400149
150 /**
151 * TerminationPoint object translation from YANG to TE Topology subsystem.
152 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500153 * @param yangTp Termination point in YANG Java data structure
154 * @return TerminationPoint TE Topology subsystem termination point
Yixiao Chen39828a62016-09-14 14:37:06 -0400155 */
156 public static org.onosproject.tetopology.management.api.node.TerminationPoint
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500157 yang2teSubsystemTerminationPoint(TerminationPoint yangTp) {
158 checkNotNull(yangTp, E_NULL_YANG_TP);
Yixiao Chen39828a62016-09-14 14:37:06 -0400159
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500160 org.onosproject.tetopology.management.api.node.DefaultTerminationPoint tp = null;
161 List<org.onosproject.tetopology.management.api.node.TerminationPointKey> spTps = null;
162 KeyId teTpId = null;
163
164 if (yangTp.supportingTerminationPoint() != null) {
165 spTps = Lists.newArrayList();
166 for (SupportingTerminationPoint yangSptp : yangTp.supportingTerminationPoint()) {
167 org.onosproject.tetopology.management.api.node.TerminationPointKey tpKey =
168 new org.onosproject.tetopology.management.api.node.TerminationPointKey(
169 KeyId.keyId(yangSptp.networkRef().uri().string()),
170 KeyId.keyId(yangSptp.nodeRef().uri().string()),
171 KeyId.keyId(yangSptp.tpRef().uri().string()));
172 spTps.add(tpKey);
173 }
174 }
175
176 if (yangTp.yangAugmentedInfoMap() != null && !yangTp.yangAugmentedInfoMap().isEmpty()) {
177 AugmentedNtTerminationPoint yangTpAugment =
178 (AugmentedNtTerminationPoint) yangTp.yangAugmentedInfo(AugmentedNtTerminationPoint.class);
179 if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) {
180 teTpId = KeyId.keyId(yangTpAugment.te().teTpId().toString());
181 }
182 }
183
184 tp = new org.onosproject.tetopology.management.api.node
185 .DefaultTerminationPoint(KeyId.keyId(yangTp.tpId().uri().string()),
186 spTps,
187 Long.valueOf(teTpId.toString()));
188 return tp;
Yixiao Chen39828a62016-09-14 14:37:06 -0400189 }
190
191}