blob: c567667319127bab2498fd4eb5f022348c3665e4 [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
Henry Yu05dcc212017-01-05 16:05:26 -050018import com.google.common.collect.Lists;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050019import org.onlab.packet.Ip4Address;
20import org.onosproject.tetopology.management.api.KeyId;
21import org.onosproject.tetopology.management.api.TeStatus;
22import org.onosproject.tetopology.management.api.TeTopologyKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050023import org.onosproject.tetopology.management.api.TeTopologyService;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050024import org.onosproject.tetopology.management.api.link.CommonLinkData;
25import org.onosproject.tetopology.management.api.link.DefaultNetworkLink;
26import org.onosproject.tetopology.management.api.link.DefaultTeLink;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050027import org.onosproject.tetopology.management.api.link.ExternalLink;
28import org.onosproject.tetopology.management.api.link.LinkBandwidth;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050029import org.onosproject.tetopology.management.api.link.NetworkLink;
Hesam Rahimi41208102016-12-09 17:54:03 -050030import org.onosproject.tetopology.management.api.link.NetworkLinkEventSubject;
Yixiao Chen39828a62016-09-14 14:37:06 -040031import org.onosproject.tetopology.management.api.link.NetworkLinkKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050032import org.onosproject.tetopology.management.api.link.PathElement;
33import org.onosproject.tetopology.management.api.link.TeLink;
34import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
35import org.onosproject.tetopology.management.api.link.TeLinkTpKey;
36import org.onosproject.tetopology.management.api.link.TePathAttributes;
37import org.onosproject.tetopology.management.api.link.TeTunnelId;
38import org.onosproject.tetopology.management.api.link.TunnelProtectionType;
39import org.onosproject.tetopology.management.api.link.UnderlayBackupPath;
40import org.onosproject.tetopology.management.api.link.UnderlayPath;
41import org.onosproject.tetopology.management.api.node.NodeTpKey;
42import org.onosproject.tetopology.management.api.node.TeNode;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050043import org.onosproject.tetopology.management.api.node.TerminationPointKey;
Yixiao Chen39828a62016-09-14 14:37:06 -040044import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050045import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks;
46import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
47import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
Henry Yu05dcc212017-01-05 16:05:26 -050048import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.network
49 .Node;
50import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
51 .LinkId;
52import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
53 .TpId;
54import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
55 .networks.network.AugmentedNdNetwork;
56import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
57 .networks.network.augmentedndnetwork.DefaultLink;
58import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
59 .networks.network.augmentedndnetwork.DefaultLink.LinkBuilder;
60import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
61 .networks.network.augmentedndnetwork.Link;
62import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
63 .networks.network.augmentedndnetwork.link.DefaultDestination;
64import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
65 .networks.network.augmentedndnetwork.link.DefaultSource;
66import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
67 .networks.network.augmentedndnetwork.link.DefaultSupportingLink;
68import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
69 .networks.network.augmentedndnetwork.link.Destination.DestinationBuilder;
70import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
71 .networks.network.augmentedndnetwork.link.Source.SourceBuilder;
72import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
73 .networks.network.augmentedndnetwork.link.SupportingLink;
74import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
75 .networks.network.augmentedndnetwork.link.SupportingLink.SupportingLinkBuilder;
76import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
77 .networks.network.node.AugmentedNdNode;
78import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
79 .DefaultTeLinkEvent;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050080import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeLinkEvent;
Henry Yu05dcc212017-01-05 16:05:26 -050081import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
82 .informationsourceattributes.DefaultInformationSourceState;
83import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
84 .informationsourceattributes.InformationSourceState;
85import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
86 .informationsourceattributes.informationsourcestate.DefaultTopology;
87import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
88 .informationsourceattributes.informationsourcestate.Topology;
89import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks
90 .network.AugmentedNwNetwork;
91import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks
92 .network.link.AugmentedNtLink;
93import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks
94 .network.link.DefaultAugmentedNtLink;
95import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks
96 .network.link.DefaultAugmentedNtLink.AugmentedNtLinkBuilder;
97import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks
98 .network.node.AugmentedNwNode;
99import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks
100 .network.node.terminationpoint.AugmentedNtTerminationPoint;
101import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
102 .telinkaugment.DefaultTe;
103import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
104 .telinkaugment.DefaultTe.TeBuilder;
105import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
106 .telinkaugment.te.Config;
107import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
108 .telinkaugment.te.DefaultConfig;
109import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
110 .telinkaugment.te.DefaultConfig.ConfigBuilder;
111import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
112 .telinkaugment.te.DefaultState;
113import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
114 .telinkaugment.te.DefaultState.StateBuilder;
115import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
116 .telinkaugment.te.State;
117import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
118 .telinkconfigattributes.DefaultTeLinkAttributes;
119import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
120 .telinkconfigattributes.DefaultTeLinkAttributes.TeLinkAttributesBuilder;
121import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
122 .telinkconfigattributes.TeLinkAttributes;
123import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
124 .telinkconfigattributes.telinkattributes.DefaultExternalDomain;
125import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
126 .telinkconfigattributes.telinkattributes.DefaultExternalDomain.ExternalDomainBuilder;
127import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
128 .telinkconfigattributes.telinkattributes.DefaultUnderlay.UnderlayBuilder;
129import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
130 .telinkconfigattributes.telinkattributes.ExternalDomain;
131import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
132 .telinkconnectivityattributes.DefaultTeSrlgs;
133import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
134 .telinkconnectivityattributes.DefaultTeSrlgs.TeSrlgsBuilder;
135import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
136 .telinkconnectivityattributes.DefaultUnreservedBandwidth;
137import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
138 .telinkconnectivityattributes.DefaultUnreservedBandwidth.UnreservedBandwidthBuilder;
139import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
140 .telinkconnectivityattributes.TeSrlgs;
141import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
142 .telinkconnectivityattributes.UnreservedBandwidth;
143import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
144 .telinkinfoattributes.LinkProtectionTypeEnum;
145import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
146 .telinkunderlayattributes.DefaultUnderlayBackupPath;
147import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
148 .telinkunderlayattributes.DefaultUnderlayBackupPath.UnderlayBackupPathBuilder;
149import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
150 .telinkunderlayattributes.DefaultUnderlayPrimaryPath;
151import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
152 .telinkunderlayattributes.DefaultUnderlayPrimaryPath.UnderlayPrimaryPathBuilder;
153import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
154 .telinkunderlayattributes.UnderlayPrimaryPath;
155import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
156 .telinkunderlayattributes.underlayprimarypath.DefaultPathElement;
157import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
158 .tenodeaugment.Te;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500159import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg;
160import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId;
161import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeOperStatus;
Henry Yu05dcc212017-01-05 16:05:26 -0500162import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes
163 .TeTopologyEventType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500164import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId;
Henry Yu05dcc212017-01-05 16:05:26 -0500165import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes
166 .tetopologyeventtype.TeTopologyEventTypeEnum;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500167
Henry Yu05dcc212017-01-05 16:05:26 -0500168import java.math.BigDecimal;
169import java.math.BigInteger;
170import java.util.BitSet;
171import java.util.List;
172
173import static com.google.common.base.Preconditions.checkNotNull;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500174
Yixiao Chen39828a62016-09-14 14:37:06 -0400175
176/**
177 * The conversion functions.
178 */
179public final class LinkConverter {
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500180 private static final String E_NULL_TELINK_UNDERLAY_PATH =
181 "TeSubsystem link underlayPath object cannot be null";
182 private static final String E_NULL_TELINK_DATA =
183 "TeSubsystem teLinkAttrBuilder data cannot be null";
184 private static final String E_NULL_TELINK =
185 "TeSubsystem teLink object cannot be null";
186 private static final String E_NULL_YANG_TELINK_CONFIG =
187 "YANG telink config object cannot be null";
188 private static final String E_NULL_YANG_TELINK =
189 "YANG Link object cannot be null";
Yixiao Chen39828a62016-09-14 14:37:06 -0400190
191 // no instantiation
192 private LinkConverter() {
193 }
194
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500195 private static LinkProtectionTypeEnum teSubsystem2YangLinkProtectionType(TunnelProtectionType linkProtectionType) {
196 switch (linkProtectionType) {
Henry Yu05dcc212017-01-05 16:05:26 -0500197 case ENHANCED:
198 return LinkProtectionTypeEnum.ENHANCED;
199 case EXTRA_TRAFFIC:
200 return LinkProtectionTypeEnum.EXTRA_TRAFFIC;
201 case SHARED:
202 return LinkProtectionTypeEnum.SHARED;
203 case UNPROTECTED:
204 return LinkProtectionTypeEnum.UNPROTECTED;
205 case ONE_FOR_ONE:
206 return LinkProtectionTypeEnum.YANGAUTOPREFIX1_FOR_1;
207 case ONE_PLUS_ONE:
208 return LinkProtectionTypeEnum.YANGAUTOPREFIX1_PLUS_1;
209 default:
210 return null;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500211 }
212 }
Henry Yu05dcc212017-01-05 16:05:26 -0500213
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500214 /**
215 * TE Link Config object conversion from TE Topology subsystem to YANG.
216 *
217 * @param teLink TE link object
218 * @return TE Link Config YANG object
219 */
220 private static Config teLink2YangConfig(TeLink teLink) {
221 checkNotNull(teLink, E_NULL_TELINK_DATA);
Yixiao Chen39828a62016-09-14 14:37:06 -0400222
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500223 TeLinkAttributesBuilder attrBuilder = DefaultTeLinkAttributes.builder();
224
225 if (teLink.teLinkKey() != null) {
226 // what is link index? for now I used teLinkTpId
227 attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId()));
228 }
229
230 if (teLink.adminStatus() != null) {
231 attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus()));
232 }
233
234 if (teLink.tunnelProtectionType() != null) {
235 attrBuilder = attrBuilder
236 .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink
Henry Yu05dcc212017-01-05 16:05:26 -0500237 .tunnelProtectionType()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500238 }
239
240 attrBuilder = attrBuilder.teDefaultMetric(teLink.cost());
241
242 if (teLink.srlgs() != null) {
243 TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder();
244 for (Long srlgLongVal : teLink.srlgs()) {
245 teSrlgsBuilder = teSrlgsBuilder.addToValue(new Srlg(srlgLongVal));
246 }
247 attrBuilder = attrBuilder.teSrlgs(teSrlgsBuilder.build());
248 }
249 attrBuilder = attrBuilder.isAbstract(teLink.flags().get(TeNode.BIT_ABSTRACT));
250
251 if (teLink.externalLink() != null) {
252 ExternalDomainBuilder edBuilder =
253 DefaultExternalDomain.builder();
254 if (teLink.externalLink().plugId() != null) {
255 edBuilder.plugId(teLink.externalLink().plugId());
256 }
257 if (teLink.externalLink().externalLinkKey() != null) {
258 edBuilder = edBuilder
259 .remoteTeLinkTpId(TeTpId.fromString(
Henry Yu05dcc212017-01-05 16:05:26 -0500260 String.valueOf(teLink
261 .externalLink()
262 .externalLinkKey()
263 .teLinkTpId())))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500264 .remoteTeNodeId(TeNodeId.fromString(
Henry Yu05dcc212017-01-05 16:05:26 -0500265 String.valueOf(teLink
266 .externalLink()
267 .externalLinkKey()
268 .teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500269 }
270 attrBuilder = attrBuilder.externalDomain(edBuilder.build());
271 }
272
273 if (teLink.availBandwidth() != null) {
274 short i = 0;
275 for (float f : teLink.availBandwidth()) {
276 UnreservedBandwidthBuilder urBuilder =
277 DefaultUnreservedBandwidth.builder()
Henry Yu05dcc212017-01-05 16:05:26 -0500278 .bandwidth(BigDecimal.valueOf(f))
279 .priority(i);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500280 i++;
281 attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build());
282 }
283 }
284
285 if (teLink.maxBandwidth() != null) {
286 // maxBandwidth is an array of float[], but in yang is just a big decimal
287 attrBuilder = attrBuilder.maxLinkBandwidth(BigDecimal.valueOf(teLink.maxBandwidth()[0]));
288 }
289 // FIXME: how to retrieve maxResvLinkBandwidth from teLink
290// if (teLink.maxResvLinkBandwidth() != null) {
291// attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth());
292// }
293
Hesam Rahimi41208102016-12-09 17:54:03 -0500294// UnderlayBuilder builder = DefaultUnderlay.builder();
295// if (teLink.primaryPath() != null) {
296//
297// // TODO: what is underlayProtectionType in tePath?
298// // builder = builder.underlayProtectionType(tePath.protectionType());
299//
300// builder = te2YangConfigUnderlayPrimaryPath(builder, teLink);
301// }
302//
303// if (teLink.backupPaths() != null) {
304// builder = te2YangConfigUnderlayBackupPaths(builder, teLink);
305// }
306//
307// attrBuilder = attrBuilder.underlay(builder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500308
309 ConfigBuilder yangConfigBuilder = DefaultConfig.builder()
Henry Yu05dcc212017-01-05 16:05:26 -0500310 .teLinkAttributes(attrBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500311 return yangConfigBuilder.build();
312 }
313
314 /**
315 * TE Link State object conversion from TE Topology subsystem to YANG.
316 *
317 * @param teLink TE link object
318 * @return TE Link State YANG object
319 */
320 private static State teLink2YangState(TeLink teLink) {
321 TeLinkAttributes
Henry Yu05dcc212017-01-05 16:05:26 -0500322 .TeLinkAttributesBuilder attrBuilder =
323 DefaultTeLinkAttributes
324 .builder()
325 .teDefaultMetric(teLink.cost())
326 .isAbstract(teLink.flags().get(TeLink.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500327 if (teLink.teLinkKey() != null) {
328 // what is link index? for now I used teLinkTpId
329 attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId()));
330 }
331
332 if (teLink.adminStatus() != null) {
333 attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus()));
334 }
335 if (teLink.tunnelProtectionType() != null) {
336 attrBuilder = attrBuilder
337 .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink
Henry Yu05dcc212017-01-05 16:05:26 -0500338 .tunnelProtectionType()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500339 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500340 if (teLink.maxBandwidth() != null) {
341 // maxBandwidth is an array of float[], but in yang is just a big decimal
342 attrBuilder = attrBuilder.maxLinkBandwidth(BigDecimal.valueOf(teLink.maxBandwidth()[0]));
343 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500344// if (teLink.maxResvLinkBandwidth() != null) {
345// attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth());
346// }
347 if (teLink.srlgs() != null) {
348 TeSrlgs.TeSrlgsBuilder srlgsBuilder = DefaultTeSrlgs.builder();
349 for (Long srlgLongVal : teLink.srlgs()) {
350 srlgsBuilder = srlgsBuilder.addToValue(new Srlg(srlgLongVal));
351 }
352 attrBuilder = attrBuilder.teSrlgs(srlgsBuilder.build());
353 }
354
355 if (teLink.externalLink() != null) {
356 ExternalDomain.ExternalDomainBuilder edBuilder = DefaultExternalDomain
357 .builder();
358 if (teLink.externalLink().plugId() != null) {
359 edBuilder = edBuilder.plugId(teLink.externalLink().plugId());
360 }
361 if (teLink.externalLink().externalLinkKey() != null) {
362 edBuilder = edBuilder
363 .remoteTeLinkTpId(TeTpId.fromString(String.valueOf(teLink
Henry Yu05dcc212017-01-05 16:05:26 -0500364 .externalLink()
365 .externalLinkKey()
366 .teLinkTpId())))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500367 .remoteTeNodeId(TeNodeId.fromString(String.valueOf(teLink
Henry Yu05dcc212017-01-05 16:05:26 -0500368 .externalLink()
369 .externalLinkKey()
370 .teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500371 }
372 attrBuilder = attrBuilder.externalDomain(edBuilder.build());
373
374 }
375
376 if (teLink.availBandwidth() != null) {
377 short i = 0;
378 for (float f : teLink.availBandwidth()) {
379 UnreservedBandwidth.UnreservedBandwidthBuilder urBuilder = DefaultUnreservedBandwidth
380 .builder()
Henry Yu05dcc212017-01-05 16:05:26 -0500381 .bandwidth(BigDecimal.valueOf(f))
382 .priority(i);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500383 i++;
384 attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build());
385 }
386 }
387
388 StateBuilder yangStateBuilder = DefaultState.builder()
Henry Yu05dcc212017-01-05 16:05:26 -0500389 .teLinkAttributes(attrBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500390 if (teLink.opStatus() != null) {
391 yangStateBuilder = yangStateBuilder.operStatus(EnumConverter
Henry Yu05dcc212017-01-05 16:05:26 -0500392 .teSubsystem2YangOperStatus(teLink.opStatus()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500393 }
394
395 if (teLink.sourceTeLinkId() != null) {
396 InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder();
397
398 Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder();
399 topologyBuilder = topologyBuilder.clientIdRef(teLink.sourceTeLinkId().clientId())
Henry Yu05dcc212017-01-05 16:05:26 -0500400 .providerIdRef(teLink.sourceTeLinkId().providerId())
401 .teTopologyIdRef(teLink.sourceTeLinkId().topologyId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500402 issBuilder = issBuilder.topology(topologyBuilder.build());
403 yangStateBuilder.informationSourceState(issBuilder.build());
404 }
405
406 // Once stateDerived underlay is available in yang and core TE Topology
407 // object model, set the value properly
408 // stateDerivedUnderlay = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology
409 // .rev20160708.ietftetopology.telinkstatederived.Underlay
410 // yangStateBuilder = yangStateBuilder.underlay(stateDerivedUnderlay);
411
412 return yangStateBuilder.build();
413 }
414
415 /**
416 * Link object conversion from TE Topology subsystem to YANG.
417 *
418 * @param teSubsNetworkLink TE subsystem link object
419 * @return YANG link object
420 */
421 public static Link teSubsystem2YangLink(
422 org.onosproject.tetopology.management.api.link.NetworkLink teSubsNetworkLink) {
423 checkNotNull(teSubsNetworkLink, E_NULL_TELINK);
424
425 LinkId linkId = LinkId.fromString(teSubsNetworkLink.linkId().toString());
426 LinkBuilder builder = DefaultLink.builder().linkId(linkId);
427 if (teSubsNetworkLink.supportingLinkIds() != null) {
428 List<SupportingLink> slinks = Lists.newArrayList();
429 SupportingLinkBuilder spLinkBuilder = DefaultSupportingLink.builder();
430 for (NetworkLinkKey linkKey : teSubsNetworkLink.supportingLinkIds()) {
431 slinks.add(spLinkBuilder.networkRef(NetworkId.fromString(
Henry Yu05dcc212017-01-05 16:05:26 -0500432 linkKey.networkId().toString()))
433 .linkRef(LinkId.fromString(
434 linkKey.linkId().toString()))
435 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500436 }
437 builder = builder.supportingLink(slinks);
438 }
439 if (teSubsNetworkLink.source() != null) {
440 SourceBuilder sourceBuilder = DefaultSource
Henry Yu05dcc212017-01-05 16:05:26 -0500441 .builder()
442 .sourceNode(NodeId.fromString(
443 teSubsNetworkLink.source().nodeId().toString()))
444 .sourceTp(TpId.fromString(
445 teSubsNetworkLink.source().tpId().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500446 builder = builder.source(sourceBuilder.build());
447 }
448 if (teSubsNetworkLink.destination() != null) {
449 DestinationBuilder destBuilder = DefaultDestination
Henry Yu05dcc212017-01-05 16:05:26 -0500450 .builder()
451 .destNode(NodeId.fromString(
452 teSubsNetworkLink.destination().nodeId().toString()))
453 .destTp(TpId.fromString(
454 teSubsNetworkLink.destination().tpId().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500455 builder = builder.destination(destBuilder.build());
456 }
457
458 if (teSubsNetworkLink.teLink() != null) {
459 TeLink teData = teSubsNetworkLink.teLink();
460 TeBuilder yangTeBuilder = DefaultTe.builder()
Henry Yu05dcc212017-01-05 16:05:26 -0500461 .config(teLink2YangConfig(teData))
462 .state(teLink2YangState(teData));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500463 // ignoring supportingTeLinkId when converting from core to yang?
464 // if (teData.supportingTeLinkId() != null) {
465 // }
466 AugmentedNtLinkBuilder linkAugmentBuilder =
467 DefaultAugmentedNtLink.builder()
Henry Yu05dcc212017-01-05 16:05:26 -0500468 .te(yangTeBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500469 builder.addYangAugmentedInfo(linkAugmentBuilder.build(), AugmentedNtLink.class);
470 }
471
472 return builder.build();
473 }
474
475 private static UnderlayBuilder te2YangConfigUnderlayPrimaryPath(
476 UnderlayBuilder yangBuilder,
Hesam Rahimi41208102016-12-09 17:54:03 -0500477 TeLink teLink, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500478
479 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath tePath = teLink.primaryPath();
480
481 UnderlayPrimaryPathBuilder pathBuilder =
Henry Yu05dcc212017-01-05 16:05:26 -0500482 DefaultUnderlayPrimaryPath.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500483 if (tePath.pathElements() != null) {
484 for (PathElement pathElementTe : tePath.pathElements()) {
485 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Henry Yu05dcc212017-01-05 16:05:26 -0500486 .ietftetopology.telinkunderlayattributes.underlayprimarypath.PathElement
487 .PathElementBuilder pathElementYangBuilder = DefaultPathElement.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500488
489 pathElementYangBuilder = pathElementYangBuilder.pathElementId(pathElementTe.pathElementId());
490 //TODO: add some Type cross converter
491// pathElementYangBuilder = pathElementYangBuilder.type(Type pathElementTe.type())
492
493 pathBuilder = pathBuilder.addToPathElement(pathElementYangBuilder.build());
494 }
495 }
496
497 pathBuilder = pathBuilder.clientIdRef(teLink.underlayTeTopologyId().clientId())
Henry Yu05dcc212017-01-05 16:05:26 -0500498 .providerIdRef(teLink.underlayTeTopologyId().providerId())
499 .teTopologyIdRef(teLink.underlayTeTopologyId().topologyId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500500
Hesam Rahimi41208102016-12-09 17:54:03 -0500501 pathBuilder = pathBuilder.networkIdRef(teTopologyService.networkId(teLink.underlayTeTopologyId()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500502
503 return yangBuilder.underlayPrimaryPath(pathBuilder.build());
504 }
505
506 private static UnderlayBuilder te2YangConfigUnderlayBackupPaths(UnderlayBuilder yangBuilder,
Hesam Rahimi41208102016-12-09 17:54:03 -0500507 TeLink teLink,
508 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500509 List<UnderlayBackupPath> tePaths = teLink.backupPaths();
510
511 for (UnderlayBackupPath tePath : tePaths) {
512 UnderlayBackupPathBuilder pathBuilder = DefaultUnderlayBackupPath
513 .builder();
514 pathBuilder = pathBuilder.index(tePath.index());
515 pathBuilder = pathBuilder.clientIdRef(teLink.underlayTeTopologyId().clientId())
Henry Yu05dcc212017-01-05 16:05:26 -0500516 .providerIdRef(teLink.underlayTeTopologyId().providerId())
517 .teTopologyIdRef(teLink.underlayTeTopologyId().topologyId());
Hesam Rahimi41208102016-12-09 17:54:03 -0500518
519 pathBuilder = pathBuilder.networkIdRef(teTopologyService.networkId(teLink.underlayTeTopologyId()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500520
521 for (PathElement backupPathElementTe : tePath.pathElements()) {
522 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Henry Yu05dcc212017-01-05 16:05:26 -0500523 .ietftetopology.telinkunderlayattributes.underlaybackuppath.PathElement
524 .PathElementBuilder elementBuilder =
525 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
526 .ietftetopology.telinkunderlayattributes.underlaybackuppath.DefaultPathElement
527 .builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500528
529 elementBuilder = elementBuilder.pathElementId(backupPathElementTe.pathElementId());
530 // TODO: add some Type cross conversion
531// elementBuilder.type(type);
532
533 pathBuilder = pathBuilder
534 .addToPathElement(elementBuilder.build());
535 }
536 yangBuilder = yangBuilder
537 .addToUnderlayBackupPath(pathBuilder.build());
538 }
539
540 return yangBuilder;
541 }
542
543 private static TeLink yang2TeLinkAttributes(TeLinkAttributes yangLinkAttr,
544 State opState, Link yangLink,
545 Network yangNetwork,
546 Networks yangNetworks) {
547 TeNodeId teNodeId = findTeNodeId(yangNetwork,
Hesam Rahimi41208102016-12-09 17:54:03 -0500548 yangLink.source().sourceNode());
549 long teNodeIdLong = -1;
550 if (teNodeId != null && teNodeId.dottedQuad() != null) {
551 teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string())
552 .toInt();
553 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500554
555 TeLinkTpKey teLinkKey = new TeLinkTpKey(teNodeIdLong,
556 findTeTpId(yangNetwork,
557 yangLink.source().sourceNode(),
558 yangLink.source().sourceTp()));
559
Hesam Rahimi41208102016-12-09 17:54:03 -0500560 TeNodeId teNodeIdDest = null;
561 if (yangLink.destination() != null) {
562 teNodeIdDest = findTeNodeId(yangNetwork,
563 yangLink.destination().destNode());
564 }
565 long teNodeIdDestLong = -1;
566 if (teNodeIdDest != null && teNodeIdDest.dottedQuad() != null) {
567 teNodeIdDestLong = Ip4Address.valueOf(teNodeIdDest.dottedQuad().string()).toInt();
568 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500569
Hesam Rahimi41208102016-12-09 17:54:03 -0500570 TeLinkTpKey peerTeLinkKey = null;
571 if (yangLink.destination() != null) {
572 peerTeLinkKey = new TeLinkTpKey(teNodeIdDestLong,
Henry Yu05dcc212017-01-05 16:05:26 -0500573 findTeTpId(yangNetwork,
574 yangLink.destination().destNode(),
575 yangLink.destination().destTp()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500576 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500577
578 TeLinkTpGlobalKey supportTeLinkId = findSupportTeLinkId(yangNetworks, yangLink);
579
580 org.onosproject.tetopology.management.api.TeStatus opStatus = null;
581 if (opState != null && opState.operStatus() != null) {
582 opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState.operStatus());
583 }
584
585
586 TeLink teLink = yangLinkAttr2TeLinkAttributes(yangLinkAttr, opStatus, teNodeIdLong, teNodeIdDestLong, teLinkKey,
587 peerTeLinkKey, supportTeLinkId);
588
589 return teLink;
590 }
591
592 private static TeLink yangLinkAttr2TeLinkAttributes(TeLinkAttributes yangLinkAtrr,
593 org.onosproject.tetopology.management.api.TeStatus opStatus,
594 long teNodeIdLong,
595 long teNodeIdDestLong,
596 TeLinkTpKey teLinkKey,
597 TeLinkTpKey peerTeLinkKey,
598 TeLinkTpGlobalKey supportTeLinkId) {
599 org.onosproject.tetopology.management.api.TeStatus adminStatus = null;
600
601 TeLinkTpGlobalKey sourceTeLinkId = null; // from yang to core, we can ignore sourceTeLinkId
602 TeTopologyKey underlayTopologyId = null;
603 CommonLinkData teData = null;
604
Hesam Rahimi41208102016-12-09 17:54:03 -0500605 if (yangLinkAtrr != null && yangLinkAtrr.underlay() != null &&
606 yangLinkAtrr.underlay().underlayPrimaryPath() != null) {
607 underlayTopologyId = new
608 TeTopologyKey((long) yangLinkAtrr.underlay().underlayPrimaryPath().providerIdRef(),
609 (long) yangLinkAtrr.underlay().underlayPrimaryPath().clientIdRef(),
610 (long) yangLinkAtrr.underlay().underlayPrimaryPath().teTopologyIdRef());
611 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500612
613 if (yangLinkAtrr.adminStatus() != null) {
614 adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangLinkAtrr.adminStatus());
615 }
616
617 BitSet flags = new BitSet();
618 if (yangLinkAtrr.isAbstract()) {
619 flags.set(TeLink.BIT_ABSTRACT);
620 }
621
Hesam Rahimi41208102016-12-09 17:54:03 -0500622 ExternalLink externalLink = null;
623 if (yangLinkAtrr != null && yangLinkAtrr.externalDomain() != null) {
624 externalLink = new ExternalLink(null, yangLinkAtrr.externalDomain().plugId());
625 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500626
627 UnderlayPath underlayPath = null;
628 underlayPath = yang2TeSubsystemUnderlayPath(yangLinkAtrr, teNodeIdLong,
629 teNodeIdDestLong);
Hesam Rahimi41208102016-12-09 17:54:03 -0500630 Long adminGroup = null;
631 if (yangLinkAtrr != null && yangLinkAtrr.administrativeGroup() != null) {
632 adminGroup = Long.valueOf(yangLinkAtrr.administrativeGroup().toString());
633 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500634 List<Long> interLayerLocks = null; // FIXME: how to find interLayerLocks?
635
636 List<UnreservedBandwidth> listOfUnreservedBandwidth = yangLinkAtrr.unreservedBandwidth();
637 float[] availBandwidth = new float[listOfUnreservedBandwidth.size()];
638 int i = 0;
639 for (UnreservedBandwidth urbw : listOfUnreservedBandwidth) {
640 availBandwidth[i] = urbw.bandwidth().floatValue();
641 i++;
642 }
643
644 float[] maxBandwidth = new float[1];
Hesam Rahimi41208102016-12-09 17:54:03 -0500645 if (yangLinkAtrr.maxLinkBandwidth() != null) {
646 maxBandwidth[0] = yangLinkAtrr.maxLinkBandwidth().floatValue();
647 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500648
649 float[] maxAvailLspBandwidth = null; // FIXME: how to find this?
650 float[] minAvailLspBandwidth = null; // FIXME: how to find this?
651 LinkBandwidth bandwidth = new LinkBandwidth(
652 maxBandwidth,
653 availBandwidth,
654 maxAvailLspBandwidth,
655 minAvailLspBandwidth,
656 null); // FIXME: how to find odu resource?
657 List<Long> srlgs = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500658 if (yangLinkAtrr.teSrlgs() != null
659 && yangLinkAtrr.teSrlgs().value() != null
660 && !yangLinkAtrr.teSrlgs().value().isEmpty()) {
661 for (Srlg srlg : yangLinkAtrr.teSrlgs().value()) {
662 srlgs.add(srlg.uint32());
663 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500664 }
665 TePathAttributes teAttributes =
666 new TePathAttributes(yangLinkAtrr.teDefaultMetric(),
Hesam Rahimi41208102016-12-09 17:54:03 -0500667 yangLinkAtrr.performanceMetric() == null ? null :
Henry Yu05dcc212017-01-05 16:05:26 -0500668 (yangLinkAtrr.performanceMetric().measurement() == null ? null :
669 yangLinkAtrr.performanceMetric().measurement()
670 .unidirectionalDelay()),
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500671 srlgs);
672 teData = new CommonLinkData(adminStatus,
673 opStatus,
674 flags,
675 null, // switchingLayer
676 null, // encodingLayer
677 externalLink,
678 underlayPath,
679 teAttributes,
680 adminGroup,
681 interLayerLocks,
682 bandwidth);
683
684 TeLink te = new DefaultTeLink(teLinkKey, peerTeLinkKey,
685 underlayTopologyId, supportTeLinkId,
686 sourceTeLinkId, teData);
687 return te;
688 }
689
690 private static TeLinkTpGlobalKey findSupportTeLinkId(Networks yangNetworks,
Henry Yu05dcc212017-01-05 16:05:26 -0500691 Link yangLink) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500692 Network teNetworkFound = null;
693 LinkId teLinkIdFound = null;
Hesam Rahimi41208102016-12-09 17:54:03 -0500694 TeLinkTpGlobalKey supportTeLinkId = null;
695
696 if (yangLink != null && yangLink.supportingLink() != null && !yangLink.supportingLink().isEmpty()) {
697 if (yangNetworks.network() != null && !yangNetworks.network().isEmpty()) {
698 for (Network ynetItem : yangNetworks.network()) {
699 if (ynetItem.networkId() != null) {
700 if (ynetItem.networkId().equals(yangLink.supportingLink().get(0).networkRef())) {
701 teNetworkFound = ynetItem;
702 teLinkIdFound = yangLink.supportingLink().get(0).linkRef();
703 break;
704 }
705 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500706 }
707 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500708 Link teLinkFound = null;
709 if (teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class) != null) {
710 AugmentedNdNetwork augmentLink =
711 (AugmentedNdNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class);
712 for (Link link : augmentLink.link()) {
713 if (link.linkId().equals(teLinkIdFound)) {
714 teLinkFound = link;
715 break;
716 }
717 }
718 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500719
Hesam Rahimi41208102016-12-09 17:54:03 -0500720 TeNodeId teSupportNodeId = findTeNodeId(teNetworkFound,
721 teLinkFound.source().sourceNode());
722 long tenIdLong = -1;
723 if (teSupportNodeId != null) {
724 tenIdLong = Ip4Address.valueOf(teSupportNodeId.dottedQuad().string()).toInt();
725 }
726 long teSupportLinkTpId = findTeTpId(teNetworkFound,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500727 teLinkFound.source().sourceNode(),
728 teLinkFound.source().sourceTp());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500729
Hesam Rahimi41208102016-12-09 17:54:03 -0500730 org.onosproject.tetopology.management.api.TeTopologyId teTopologyId = null;
731 if (teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class) != null) {
732 AugmentedNwNetwork augmentTeIds =
733 (AugmentedNwNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class);
734 teTopologyId =
735 new org.onosproject.tetopology.management.api.TeTopologyId(
736 augmentTeIds.te().clientId().uint32(),
737 augmentTeIds.te().providerId().uint32(),
738 augmentTeIds.te().teTopologyId().string());
739 }
740
741 supportTeLinkId = new TeLinkTpGlobalKey(teTopologyId.providerId(),
742 teTopologyId.clientId(),
743 Long.valueOf(teTopologyId
Henry Yu05dcc212017-01-05 16:05:26 -0500744 .topologyId()),
Hesam Rahimi41208102016-12-09 17:54:03 -0500745 tenIdLong, teSupportLinkTpId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500746 }
747
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500748 return supportTeLinkId;
749 }
750
Hesam Rahimi41208102016-12-09 17:54:03 -0500751 private static TeNodeId findTeNodeId(Network yangNetwork, NodeId yangNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500752 TeNodeId teNodeId = null;
753 for (Node node : yangNetwork.node()) {
754 if (node.nodeId().equals(yangNodeId)) {
755 if (node.yangAugmentedInfoMap() != null
756 && !node.yangAugmentedInfoMap().isEmpty()) {
757 AugmentedNwNode yangNodeAugment = (AugmentedNwNode) node
758 .yangAugmentedInfo(AugmentedNwNode.class);
759 if (yangNodeAugment != null && yangNodeAugment.te() != null
760 && yangNodeAugment.te().teNodeId() != null) {
761 Te yangNodeAugTe = yangNodeAugment.te();
762 teNodeId = yangNodeAugTe.teNodeId();
763 }
764 }
765 }
766 }
767 return teNodeId;
768 }
769
770 private static long findTeTpId(Network yangNetwork, NodeId yangNodeId, TpId yangTpId) {
771 long teTpId = 0;
772 for (Node node : yangNetwork.node()) {
773 if (node.nodeId().equals(yangNodeId)) {
774 if (node.yangAugmentedInfoMap() != null
775 && !node.yangAugmentedInfoMap().isEmpty()) {
776
777 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) node
778 .yangAugmentedInfo(AugmentedNdNode.class);
779 if (yangTpNodeAugment.terminationPoint() != null) {
780 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
781 .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
782 yangTpnode : yangTpNodeAugment.terminationPoint()) {
783 if (yangTpnode.tpId().equals(yangTpId)) {
784 if (yangTpnode.yangAugmentedInfoMap() != null
785 && !yangTpnode.yangAugmentedInfoMap()
Henry Yu05dcc212017-01-05 16:05:26 -0500786 .isEmpty()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500787 AugmentedNtTerminationPoint yangTpAugment =
788 (AugmentedNtTerminationPoint) yangTpnode
789 .yangAugmentedInfo(AugmentedNtTerminationPoint.class);
790 if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) {
791 teTpId = Long.valueOf(yangTpAugment.te().teTpId().toString());
792 }
793 }
794 }
795 }
796 }
797 }
798 }
799 }
800 return teTpId;
801 }
Henry Yu05dcc212017-01-05 16:05:26 -0500802
Yixiao Chen39828a62016-09-14 14:37:06 -0400803 /**
804 * Link object conversion from YANG to TE Topology subsystem.
805 *
Henry Yu05dcc212017-01-05 16:05:26 -0500806 * @param yangLink YANG link
807 * @param yangNetwork YANG network
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500808 * @param yangNetworks YANG networks
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500809 * @return TE subsystem link
Yixiao Chen39828a62016-09-14 14:37:06 -0400810 */
811 public static org.onosproject.tetopology.management.api.link.NetworkLink
Henry Yu05dcc212017-01-05 16:05:26 -0500812 yang2TeSubsystemLink(Link yangLink, Network yangNetwork,
813 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500814 NetworkId networkId = yangNetwork.networkId();
815 checkNotNull(yangLink, E_NULL_YANG_TELINK);
Yixiao Chen39828a62016-09-14 14:37:06 -0400816
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500817 KeyId linkId = KeyId.keyId(yangLink.linkId().uri().toString());
818 NodeTpKey sourceNodeTpKey = null;
819 NodeTpKey destinationNodeTpKey = null;
820 List<NetworkLinkKey> spLinkIds = null;
821 TeLink te = null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400822
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500823 if (yangLink.supportingLink() != null) {
824 spLinkIds = Lists.newArrayList();
825 for (SupportingLink yangSpLink : yangLink.supportingLink()) {
826 NetworkLinkKey linkKey = new NetworkLinkKey(KeyId.keyId(yangSpLink.networkRef().uri().toString()),
827 KeyId.keyId(yangSpLink.linkRef().uri().toString()));
828 spLinkIds.add(linkKey);
829 }
830 }
831
832 if (yangLink.source() != null) {
833 TerminationPointKey source = new TerminationPointKey(
Henry Yu05dcc212017-01-05 16:05:26 -0500834 KeyId.keyId(networkId.uri().toString()),
835 KeyId.keyId(yangLink.source().sourceNode().uri().toString()),
836 KeyId.keyId(yangLink.source().sourceTp().uri().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500837 sourceNodeTpKey = new NodeTpKey(source.nodeId(), source.tpId());
838 }
839
840 if (yangLink.destination() != null) {
841 TerminationPointKey destination = new TerminationPointKey(
Henry Yu05dcc212017-01-05 16:05:26 -0500842 KeyId.keyId(networkId.uri().toString()),
843 KeyId.keyId(yangLink.destination().destNode().uri().toString()),
844 KeyId.keyId(yangLink.destination().destTp().uri().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500845 destinationNodeTpKey = new NodeTpKey(destination.nodeId(), destination.tpId());
846 }
847
848 if (yangLink.yangAugmentedInfoMap() != null && !yangLink.yangAugmentedInfoMap().isEmpty()) {
849
850 AugmentedNtLink yangLinkAugment =
851 (AugmentedNtLink) yangLink.yangAugmentedInfo(AugmentedNtLink.class);
852 if (yangLinkAugment != null &&
853 yangLinkAugment.te() != null &&
854 yangLinkAugment.te().config() != null) {
855 TeLinkAttributes yangLinkAtrr =
856 yangLinkAugment.te().config().teLinkAttributes();
857 if (yangLinkAtrr != null && yangLinkAtrr.linkIndex() != null) {
858 te = yang2TeLinkAttributes(yangLinkAtrr,
859 yangLinkAugment.te().state(),
860 yangLink, yangNetwork,
861 yangNetworks);
862 }
863 }
864 }
865
866 org.onosproject.tetopology.management.api.link.DefaultNetworkLink link =
867 new DefaultNetworkLink(linkId,
868 sourceNodeTpKey,
869 destinationNodeTpKey,
870 spLinkIds,
871 te);
872 return link;
Yixiao Chen39828a62016-09-14 14:37:06 -0400873 }
874
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500875 private static org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath
Henry Yu05dcc212017-01-05 16:05:26 -0500876 yang2TeSubsystemUnderlayPrimaryPath(UnderlayPrimaryPath yangpath,
877 long teNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500878 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath teUnderlayPrimaryPath = null;
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500879
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500880 List<PathElement> pathElementList = Lists.newArrayList();
881 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
882 .telinkunderlayattributes.underlayprimarypath.
883 PathElement pathElementConfigYang : yangpath.pathElement()) {
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500884
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500885 // TODO: find the proper type (ElementType) from pathElementConfigYang.type()
886 PathElement tePathElement = new PathElement(pathElementConfigYang.pathElementId(),
887 teNodeId,
888 null,
889 false); // FIXME: how to find the proper value for loose?
890 pathElementList.add(tePathElement);
891 }
892
893 teUnderlayPrimaryPath = new org.onosproject.tetopology.management.api.link.
894 UnderlayPrimaryPath(pathElementList, false); // FIXME: how to find the proper value for loose?
895
896 return teUnderlayPrimaryPath;
897 }
898
899 private static List<UnderlayBackupPath>
Henry Yu05dcc212017-01-05 16:05:26 -0500900 yang2TeSubsystemUnderlayBackupPaths(
901 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500902 rev20160708.ietftetopology.telinkunderlayattributes.
903 UnderlayBackupPath> yangpaths,
Henry Yu05dcc212017-01-05 16:05:26 -0500904 long teNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500905
906 List<UnderlayBackupPath> underlayBackupPathsList = Lists.newArrayList();
907 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
908 .ietftetopology.telinkunderlayattributes.
909 UnderlayBackupPath yangConfig : yangpaths) {
910 UnderlayBackupPath ubp = null;
911 List<PathElement> backupPathElementList = Lists.newArrayList();
912 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
913 .telinkunderlayattributes.underlaybackuppath.
914 PathElement pathElementBackupYang : yangConfig.pathElement()) {
915
916 PathElement tePathElementBackup = new PathElement(pathElementBackupYang.pathElementId(),
917 teNodeId,
918 null, // FIXME: find the proper ElementType
Henry Yu05dcc212017-01-05 16:05:26 -0500919 // from pathElementBackupYang.type()
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500920 false); // FIXME: find the proper value for loose
921 backupPathElementList.add(tePathElementBackup);
922 }
923 ubp = new UnderlayBackupPath(yangConfig.index(),
924 backupPathElementList,
925 null); // FIXME: find the proper value for loose
926 underlayBackupPathsList.add(ubp);
927 }
928
929 return underlayBackupPathsList;
930 }
931
932 /**
Henry Yu05dcc212017-01-05 16:05:26 -0500933 * TE Link underlay path Config object conversion from YANG to TE Topology subsystem.
934 *
935 * @param yangLinkAtrr YANG link Config YANG object
936 * @return teSubsystem TE underlay path object
937 */
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500938 private static org.onosproject.tetopology.management.api.link.UnderlayPath
Henry Yu05dcc212017-01-05 16:05:26 -0500939 yang2TeSubsystemUnderlayPath(TeLinkAttributes yangLinkAtrr, long srcTeNodeId, long dstTeNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500940
941 checkNotNull(yangLinkAtrr, E_NULL_YANG_TELINK_CONFIG);
942
943 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath underlayPrimaryPath = null;
944 List<UnderlayBackupPath> underlayBackupPathsList = null;
945 TeTunnelId teTunnelId = new TeTunnelId(srcTeNodeId, dstTeNodeId, 0); // FIXME: how to find teTunnelId?
946
Hesam Rahimi41208102016-12-09 17:54:03 -0500947 if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().underlayPrimaryPath() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500948 underlayPrimaryPath =
949 yang2TeSubsystemUnderlayPrimaryPath(yangLinkAtrr.underlay().underlayPrimaryPath(), srcTeNodeId);
950 }
951
Hesam Rahimi41208102016-12-09 17:54:03 -0500952 if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().underlayBackupPath() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500953 underlayBackupPathsList =
954 yang2TeSubsystemUnderlayBackupPaths(yangLinkAtrr.underlay().underlayBackupPath(), srcTeNodeId);
955 }
956
Hesam Rahimi41208102016-12-09 17:54:03 -0500957 org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay = null;
958 if (yangLinkAtrr.underlay() != null) {
959 teUnderlay = new org.onosproject.tetopology.management.api.link.
Henry Yu05dcc212017-01-05 16:05:26 -0500960 UnderlayPath(underlayPrimaryPath,
961 underlayBackupPathsList,
962 TunnelProtectionType.of(yangLinkAtrr.underlay().underlayProtectionType()),
963 (long) yangLinkAtrr.underlay().underlayTrailSrc().tpRef(), // Is this correct?
964 (long) yangLinkAtrr.underlay().underlayTrailDes().tpRef(), // Is this correct?
965 teTunnelId);
Hesam Rahimi41208102016-12-09 17:54:03 -0500966 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500967
968 return teUnderlay;
969 }
970
971 /**
972 * Converts a TE Topology link event from the data format used in
973 * the core to its corresponding YANG Object (YO) format.
974 *
975 * @param eventType Link event type
976 * @param linkData TE Topology link event data
977 * @return YANG Object converted from linkData
978 */
979 public static TeLinkEvent teNetworkLink2yangTeLinkEvent(TeTopologyEventTypeEnum eventType,
Hesam Rahimi41208102016-12-09 17:54:03 -0500980 NetworkLinkEventSubject linkData) {
Henry Yu8ac364b2016-12-15 18:24:20 -0500981 TeLinkEvent.TeLinkEventBuilder teLinkEventBuilder = new DefaultTeLinkEvent.TeLinkEventBuilder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500982
983 TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
Henry Yu8ac364b2016-12-15 18:24:20 -0500984 teLinkEventBuilder.eventType(yangEventType);
985 NetworkId networkId = NetworkId.fromString(linkData.key().networkId().toString());
986 teLinkEventBuilder.networkRef(networkId);
Hesam Rahimi41208102016-12-09 17:54:03 -0500987 LinkId linkId = LinkId.fromString(linkData.key().linkId().toString());
Henry Yu8ac364b2016-12-15 18:24:20 -0500988 teLinkEventBuilder.linkRef(linkId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500989
Henry Yu8ac364b2016-12-15 18:24:20 -0500990 if (linkData != null && linkData.networkLink() != null) {
991 NetworkLink link = linkData.networkLink();
992 State yangTeLinkState = teLink2YangState(link.teLink());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500993
Henry Yu8ac364b2016-12-15 18:24:20 -0500994 teLinkEventBuilder.operStatus(yangTeLinkState.operStatus());
995 teLinkEventBuilder.informationSource(yangTeLinkState.informationSource());
996 teLinkEventBuilder.informationSourceEntry(yangTeLinkState.informationSourceEntry());
997 teLinkEventBuilder.informationSourceState(yangTeLinkState.informationSourceState());
998 teLinkEventBuilder.isTransitional(yangTeLinkState.isTransitional());
999 teLinkEventBuilder.recovery(yangTeLinkState.recovery());
1000 teLinkEventBuilder.teLinkAttributes(yangTeLinkState.teLinkAttributes());
1001 teLinkEventBuilder.underlay(yangTeLinkState.underlay());
1002 }
1003
1004 return teLinkEventBuilder.build();
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001005 }
1006
Henry Yu05dcc212017-01-05 16:05:26 -05001007 /**
1008 * Retrieves the TE network link key from a given YANG network link
1009 * notification event.
1010 *
1011 * @param yangLinkEvent YANG network link notification
1012 * @return TE network link key
1013 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001014 public static NetworkLinkKey yangLinkEvent2NetworkLinkKey(TeLinkEvent yangLinkEvent) {
Hesam Rahimi41208102016-12-09 17:54:03 -05001015 NetworkId networkRef = NetworkId.fromString(yangLinkEvent.networkRef().toString());
1016 LinkId linkRef = LinkId.fromString(yangLinkEvent.linkRef().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001017 KeyId networkId = KeyId.keyId(networkRef.uri().toString());
1018 KeyId linkId = KeyId.keyId(linkRef.uri().toString());
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001019
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001020 NetworkLinkKey networkLinkKey = new NetworkLinkKey(networkId, linkId);
1021
1022 return networkLinkKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001023 }
1024
Henry Yu05dcc212017-01-05 16:05:26 -05001025 /**
1026 * Converts a YANG network link notification event into a TE network
1027 * link.
1028 *
1029 * @param yangLinkEvent YANG network link notification
1030 * @param teTopologyService TE Topology service used to help the conversion
1031 * @return TE network link
1032 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001033 public static NetworkLink yangLinkEvent2NetworkLink(TeLinkEvent yangLinkEvent,
1034 TeTopologyService teTopologyService) {
1035
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001036 KeyId linkId = yangLinkEvent2NetworkLinkKey(yangLinkEvent).linkId();
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001037
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001038 org.onosproject.tetopology.management.api.
1039 Network network = teTopologyService.network(
1040 yangLinkEvent2NetworkLinkKey(yangLinkEvent).networkId());
1041 if (network == null) {
1042 return null;
1043 }
1044
1045 NetworkLink networkLink = network.link(linkId);
1046 if (networkLink == null) {
1047 return null;
1048 }
1049
1050 NodeTpKey sourceTp = networkLink.source();
Henry Yu8ac364b2016-12-15 18:24:20 -05001051 if (sourceTp == null) {
1052 return null;
1053 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001054 NodeTpKey destTp = networkLink.destination();
1055
1056 List<NetworkLinkKey> supportingLinkIds = networkLink.supportingLinkIds();
1057 TeLink teLink = networkLink.teLink();
1058 if (teLink == null) {
1059 return null;
1060 }
1061
1062 TeOperStatus opState = yangLinkEvent.operStatus();
1063 org.onosproject.tetopology.management.api.
Henry Yu05dcc212017-01-05 16:05:26 -05001064 TeStatus opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState);
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001065
1066 TeLink updatedTeLink = yangLinkEvent2TeLinkAttributes(yangLinkEvent, teLink, opStatus);
1067
1068
Henry Yu05dcc212017-01-05 16:05:26 -05001069 NetworkLink updatedNetworkLink = new DefaultNetworkLink(linkId,
1070 sourceTp,
1071 destTp,
1072 supportingLinkIds,
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001073 updatedTeLink);
1074
1075 return updatedNetworkLink;
1076 }
1077
Henry Yu05dcc212017-01-05 16:05:26 -05001078 private static TeLink yangLinkEvent2TeLinkAttributes(TeLinkEvent yangLinkEvent,
1079 TeLink oldTeLink,
1080 TeStatus opStatus) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001081
1082 TeLinkAttributes yangTeLinkAttrs = yangLinkEvent.teLinkAttributes();
1083
1084 TeLinkTpKey teLinkKey = oldTeLink.teLinkKey();
1085
Henry Yu8ac364b2016-12-15 18:24:20 -05001086 long teNodeIdDest = 0;
1087 long teNodeIdSrc = 0;
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001088
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001089 TeLinkTpGlobalKey supportTeLinkId = oldTeLink.supportingTeLinkId();
1090 TeLinkTpKey peerTeLinkKey = oldTeLink.peerTeLinkKey();
1091
Henry Yu8ac364b2016-12-15 18:24:20 -05001092 TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeIdSrc, teNodeIdDest,
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001093 teLinkKey, peerTeLinkKey, supportTeLinkId);
1094
1095 return updatedTeLink;
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001096 }
Yixiao Chen39828a62016-09-14 14:37:06 -04001097}