blob: 56bbad2c653584dec419593fc14b8784c9fb82ef [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());
Hesam Rahimi41208102016-12-09 17:54:03 -050081// TpId tpId = TpId.fromString("0");
Hesam Rahimi39bdc002016-11-10 15:01:26 -050082 TerminationPoint.TerminationPointBuilder builder =
83 new DefaultTerminationPoint.TerminationPointBuilder().tpId(tpId);
84
85 if (teSubsystem.supportingTpIds() != null) {
86 List<SupportingTerminationPoint> tps = Lists.newArrayList();
87 SupportingTerminationPoint.SupportingTerminationPointBuilder
88 spTpBuilder = DefaultSupportingTerminationPoint.builder();
89 for (TerminationPointKey tpKey : teSubsystem.supportingTpIds()) {
90 tps.add(spTpBuilder.networkRef(NetworkId.fromString(tpKey.networkId().toString()))
91 .nodeRef(NodeId.fromString(tpKey.nodeId().toString()))
92 .tpRef(TpId.fromString(tpKey.tpId().toString()))
93 .build());
94 }
95 builder = builder.supportingTerminationPoint(tps);
96 }
97
98 if (teSubsystem.teTpId() != null) {
99 AugmentedNtTerminationPoint.AugmentedNtTerminationPointBuilder
100 tpAugmentBuilder = DefaultAugmentedNtTerminationPoint.builder();
101
102 TeBuilder yangTeBuilder = DefaultTe.builder();
103
104 yangTeBuilder = yangTeBuilder.teTpId(TeTpId.fromString((String.valueOf(teSubsystem.teTpId()))));
105
Hesam Rahimi41208102016-12-09 17:54:03 -0500106// Config yConfig = teSubsystem2YangTeAugConfig(teSubsystem);
107// yangTeBuilder = yangTeBuilder.config(yConfig);
108//
109// State yState = teSubsystem2YangTeAugState(teSubsystem);
110// yangTeBuilder = yangTeBuilder.state(yState);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500111
112 tpAugmentBuilder = tpAugmentBuilder.te(yangTeBuilder.build());
113 builder.addYangAugmentedInfo(tpAugmentBuilder.build(), AugmentedNtTerminationPoint.class);
114 }
115
116 return builder.build();
Yixiao Chen39828a62016-09-14 14:37:06 -0400117 }
118
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500119 private static State teSubsystem2YangTeAugState(org.onosproject.tetopology.management.api.node.
120 TerminationPoint teSubsystemTe) {
121 State.StateBuilder yangStateBuilder = DefaultState.builder();
122 // FIXME: interLayerLocks is a list in core but not in yang
123// yangStateBuilder = yangStateBuilder.interLayerLockId(teLink.interLayerLocks().get(0));
124
125 return yangStateBuilder.build();
126 }
127
128 private static Config teSubsystem2YangTeAugConfig(org.onosproject.tetopology.management.api.node.
129 TerminationPoint teSubsystemTe) {
130 Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder();
131 //FIXME: interLayerLocks is a list in core but not in yang
132 // yangConfigBuilder =
133 // yangConfigBuilder.interLayerLockId(teLink.interLayerLocks().get(0));
134
135 InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder isc =
136 DefaultInterfaceSwitchingCapability.builder();
137
138 MaxLspBandwidth.MaxLspBandwidthBuilder maxlspBW = DefaultMaxLspBandwidth
139 .builder();
140// for (float f : teLink.maxAvialLspBandwidth()) {
141// // is converting from float to long ok?
142// maxlspBW = maxlspBW.bandwidth(BigDecimal.valueOf((long) f));
143// isc = isc.addToMaxLspBandwidth(maxlspBW.build());
144// }
145
146 yangConfigBuilder = yangConfigBuilder.addToInterfaceSwitchingCapability(isc.build());
147
148 return yangConfigBuilder.build();
149 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400150
151 /**
152 * TerminationPoint object translation from YANG to TE Topology subsystem.
153 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500154 * @param yangTp Termination point in YANG Java data structure
155 * @return TerminationPoint TE Topology subsystem termination point
Yixiao Chen39828a62016-09-14 14:37:06 -0400156 */
157 public static org.onosproject.tetopology.management.api.node.TerminationPoint
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500158 yang2teSubsystemTerminationPoint(TerminationPoint yangTp) {
159 checkNotNull(yangTp, E_NULL_YANG_TP);
Yixiao Chen39828a62016-09-14 14:37:06 -0400160
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500161 org.onosproject.tetopology.management.api.node.DefaultTerminationPoint tp = null;
162 List<org.onosproject.tetopology.management.api.node.TerminationPointKey> spTps = null;
163 KeyId teTpId = null;
164
165 if (yangTp.supportingTerminationPoint() != null) {
166 spTps = Lists.newArrayList();
167 for (SupportingTerminationPoint yangSptp : yangTp.supportingTerminationPoint()) {
168 org.onosproject.tetopology.management.api.node.TerminationPointKey tpKey =
169 new org.onosproject.tetopology.management.api.node.TerminationPointKey(
170 KeyId.keyId(yangSptp.networkRef().uri().string()),
171 KeyId.keyId(yangSptp.nodeRef().uri().string()),
172 KeyId.keyId(yangSptp.tpRef().uri().string()));
173 spTps.add(tpKey);
174 }
175 }
176
177 if (yangTp.yangAugmentedInfoMap() != null && !yangTp.yangAugmentedInfoMap().isEmpty()) {
178 AugmentedNtTerminationPoint yangTpAugment =
179 (AugmentedNtTerminationPoint) yangTp.yangAugmentedInfo(AugmentedNtTerminationPoint.class);
180 if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) {
181 teTpId = KeyId.keyId(yangTpAugment.te().teTpId().toString());
182 }
183 }
184
185 tp = new org.onosproject.tetopology.management.api.node
186 .DefaultTerminationPoint(KeyId.keyId(yangTp.tpId().uri().string()),
187 spTps,
Hesam Rahimi41208102016-12-09 17:54:03 -0500188 teTpId == null ? null : Long.valueOf(teTpId.toString()));
189
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500190 return tp;
Yixiao Chen39828a62016-09-14 14:37:06 -0400191 }
192
193}