blob: 1b4c0996f4cda61b0cac4b6c6efe00fdc63d04a6 [file] [log] [blame]
Yixiao Chen39828a62016-09-14 14:37:06 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Yixiao Chen39828a62016-09-14 14:37:06 -04003 *
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;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050038import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.interfaceswitchingcapabilitylist.DefaultInterfaceSwitchingCapability;
39import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.interfaceswitchingcapabilitylist.InterfaceSwitchingCapability;
40import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Hesam Rahimi39bdc002016-11-10 15:01:26 -050041 .ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050042import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Hesam Rahimi39bdc002016-11-10 15:01:26 -050043 .ietftetopology.networks.network.node.terminationpoint.DefaultAugmentedNtTerminationPoint;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050044import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkiscdattributes.DefaultMaxLspBandwidth;
45import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkiscdattributes.MaxLspBandwidth;
46import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.DefaultTe;
47import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.DefaultTe.TeBuilder;
48import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.Config;
49import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.DefaultConfig;
50import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.DefaultState;
51import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.State;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050052import 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();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500101 tpAugmentBuilder.teTpId(TeTpId.fromString((String.valueOf(teSubsystem.teTpId()))));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500102 TeBuilder yangTeBuilder = DefaultTe.builder();
103
Hesam Rahimi41208102016-12-09 17:54:03 -0500104// Config yConfig = teSubsystem2YangTeAugConfig(teSubsystem);
105// yangTeBuilder = yangTeBuilder.config(yConfig);
106//
107// State yState = teSubsystem2YangTeAugState(teSubsystem);
108// yangTeBuilder = yangTeBuilder.state(yState);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500109
110 tpAugmentBuilder = tpAugmentBuilder.te(yangTeBuilder.build());
111 builder.addYangAugmentedInfo(tpAugmentBuilder.build(), AugmentedNtTerminationPoint.class);
112 }
113
114 return builder.build();
Yixiao Chen39828a62016-09-14 14:37:06 -0400115 }
116
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500117 private static State teSubsystem2YangTeAugState(org.onosproject.tetopology.management.api.node.
118 TerminationPoint teSubsystemTe) {
119 State.StateBuilder yangStateBuilder = DefaultState.builder();
120 // FIXME: interLayerLocks is a list in core but not in yang
121// yangStateBuilder = yangStateBuilder.interLayerLockId(teLink.interLayerLocks().get(0));
122
123 return yangStateBuilder.build();
124 }
125
126 private static Config teSubsystem2YangTeAugConfig(org.onosproject.tetopology.management.api.node.
127 TerminationPoint teSubsystemTe) {
128 Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder();
129 //FIXME: interLayerLocks is a list in core but not in yang
130 // yangConfigBuilder =
131 // yangConfigBuilder.interLayerLockId(teLink.interLayerLocks().get(0));
132
133 InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder isc =
134 DefaultInterfaceSwitchingCapability.builder();
135
136 MaxLspBandwidth.MaxLspBandwidthBuilder maxlspBW = DefaultMaxLspBandwidth
137 .builder();
138// for (float f : teLink.maxAvialLspBandwidth()) {
139// // is converting from float to long ok?
140// maxlspBW = maxlspBW.bandwidth(BigDecimal.valueOf((long) f));
141// isc = isc.addToMaxLspBandwidth(maxlspBW.build());
142// }
143
144 yangConfigBuilder = yangConfigBuilder.addToInterfaceSwitchingCapability(isc.build());
145
146 return yangConfigBuilder.build();
147 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400148
149 /**
150 * TerminationPoint object translation from YANG to TE Topology subsystem.
151 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500152 * @param yangTp Termination point in YANG Java data structure
153 * @return TerminationPoint TE Topology subsystem termination point
Yixiao Chen39828a62016-09-14 14:37:06 -0400154 */
155 public static org.onosproject.tetopology.management.api.node.TerminationPoint
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500156 yang2teSubsystemTerminationPoint(TerminationPoint yangTp) {
157 checkNotNull(yangTp, E_NULL_YANG_TP);
Yixiao Chen39828a62016-09-14 14:37:06 -0400158
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500159 org.onosproject.tetopology.management.api.node.DefaultTerminationPoint tp = null;
160 List<org.onosproject.tetopology.management.api.node.TerminationPointKey> spTps = null;
161 KeyId teTpId = null;
162
163 if (yangTp.supportingTerminationPoint() != null) {
164 spTps = Lists.newArrayList();
165 for (SupportingTerminationPoint yangSptp : yangTp.supportingTerminationPoint()) {
166 org.onosproject.tetopology.management.api.node.TerminationPointKey tpKey =
167 new org.onosproject.tetopology.management.api.node.TerminationPointKey(
168 KeyId.keyId(yangSptp.networkRef().uri().string()),
169 KeyId.keyId(yangSptp.nodeRef().uri().string()),
170 KeyId.keyId(yangSptp.tpRef().uri().string()));
171 spTps.add(tpKey);
172 }
173 }
174
175 if (yangTp.yangAugmentedInfoMap() != null && !yangTp.yangAugmentedInfoMap().isEmpty()) {
176 AugmentedNtTerminationPoint yangTpAugment =
177 (AugmentedNtTerminationPoint) yangTp.yangAugmentedInfo(AugmentedNtTerminationPoint.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500178 if (yangTpAugment.teTpId() != null) {
179 teTpId = KeyId.keyId(yangTpAugment.teTpId().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500180 }
181 }
182
183 tp = new org.onosproject.tetopology.management.api.node
184 .DefaultTerminationPoint(KeyId.keyId(yangTp.tpId().uri().string()),
185 spTps,
Hesam Rahimi41208102016-12-09 17:54:03 -0500186 teTpId == null ? null : Long.valueOf(teTpId.toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500187 return tp;
Yixiao Chen39828a62016-09-14 14:37:06 -0400188 }
189
190}