blob: 1234f7c5b1093f3e014ec17d7b2aefb4c1c9d462 [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
Yixiao Chen265b3bb2017-01-13 10:17:03 -050018import static com.google.common.base.Preconditions.checkNotNull;
19import static org.onosproject.tetopology.management.api.TeConstants.MAX_PRIORITY;
20
21import java.math.BigDecimal;
22import java.math.BigInteger;
23import java.util.BitSet;
24import java.util.List;
25
Hesam Rahimi39bdc002016-11-10 15:01:26 -050026import org.onlab.packet.Ip4Address;
27import org.onosproject.tetopology.management.api.KeyId;
28import org.onosproject.tetopology.management.api.TeStatus;
29import org.onosproject.tetopology.management.api.TeTopologyKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050030import org.onosproject.tetopology.management.api.TeTopologyService;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050031import org.onosproject.tetopology.management.api.link.CommonLinkData;
32import org.onosproject.tetopology.management.api.link.DefaultNetworkLink;
33import org.onosproject.tetopology.management.api.link.DefaultTeLink;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050034import org.onosproject.tetopology.management.api.link.ElementType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050035import org.onosproject.tetopology.management.api.link.ExternalLink;
36import org.onosproject.tetopology.management.api.link.LinkBandwidth;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050037import org.onosproject.tetopology.management.api.link.NetworkLink;
Hesam Rahimi41208102016-12-09 17:54:03 -050038import org.onosproject.tetopology.management.api.link.NetworkLinkEventSubject;
Yixiao Chen39828a62016-09-14 14:37:06 -040039import org.onosproject.tetopology.management.api.link.NetworkLinkKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050040import org.onosproject.tetopology.management.api.link.PathElement;
41import org.onosproject.tetopology.management.api.link.TeLink;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050042import org.onosproject.tetopology.management.api.link.TeLinkId;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050043import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
44import org.onosproject.tetopology.management.api.link.TeLinkTpKey;
45import org.onosproject.tetopology.management.api.link.TePathAttributes;
46import org.onosproject.tetopology.management.api.link.TeTunnelId;
47import org.onosproject.tetopology.management.api.link.TunnelProtectionType;
48import org.onosproject.tetopology.management.api.link.UnderlayBackupPath;
49import org.onosproject.tetopology.management.api.link.UnderlayPath;
50import org.onosproject.tetopology.management.api.node.NodeTpKey;
51import org.onosproject.tetopology.management.api.node.TeNode;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050052import org.onosproject.tetopology.management.api.node.TerminationPointKey;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050053import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.IpAddress;
Yixiao Chen39828a62016-09-14 14:37:06 -040054import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050055import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks;
56import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
57import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050058import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.network.Node;
59import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
60 .ietfnetworktopology.LinkId;
61import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
62 .ietfnetworktopology.TpId;
63import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.AugmentedNdNetwork;
64import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
65 .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink;
66import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
67 .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink.LinkBuilder;
68import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
69 .ietfnetworktopology.networks.network.augmentedndnetwork.Link;
70import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
71 .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultDestination;
72import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
73 .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSource;
74import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
75 .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSupportingLink;
76import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
77 .ietfnetworktopology.networks.network.augmentedndnetwork.link.Destination
78 .DestinationBuilder;
79import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
80 .ietfnetworktopology.networks.network.augmentedndnetwork.link.Source.SourceBuilder;
81import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
82 .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink;
83import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
84 .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink
85 .SupportingLinkBuilder;
86import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.node.AugmentedNdNode;
87import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.DefaultTeLinkEvent;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050088import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeLinkEvent;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050089import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState;
90import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.InformationSourceState;
91import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.DefaultTopology;
92import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.Topology;
93import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.AugmentedNwNetwork;
94import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
95 .ietftetopology.networks.network.link.AugmentedNtLink;
96import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
97 .ietftetopology.networks.network.link.DefaultAugmentedNtLink;
98import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
99 .ietftetopology.networks.network.link.DefaultAugmentedNtLink.AugmentedNtLinkBuilder;
100import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.AugmentedNwNode;
101import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
102import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe;
103import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe.TeBuilder;
104import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.Config;
105import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig;
106import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig.ConfigBuilder;
107import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState;
108import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState.StateBuilder;
109import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.State;
110import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes;
111import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes.TeLinkAttributesBuilder;
112import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.TeLinkAttributes;
113import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain;
114import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain.ExternalDomainBuilder;
115import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay;
116import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay.UnderlayBuilder;
117import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.ExternalDomain;
118import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs;
119import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs.TeSrlgsBuilder;
120import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth;
121import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth.UnreservedBandwidthBuilder;
122import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.TeSrlgs;
123import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.UnreservedBandwidth;
124import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkinfoattributes.LinkProtectionTypeEnum;
125import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayBackupPath;
126import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayBackupPath.UnderlayBackupPathBuilder;
127import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayPrimaryPath;
128import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayPrimaryPath.UnderlayPrimaryPathBuilder;
129import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.UnderlayPrimaryPath;
130import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.underlayprimarypath.DefaultPathElement;
131import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.Te;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500132import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg;
133import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId;
134import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeOperStatus;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500135import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500136import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500137import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink;
138import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink.UnnumberedLinkBuilder;
139import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.UnnumberedLink;
140import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.tetopologyeventtype.TeTopologyEventTypeEnum;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500141
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500142import com.google.common.collect.Lists;
Yixiao Chen39828a62016-09-14 14:37:06 -0400143
144/**
145 * The conversion functions.
146 */
147public final class LinkConverter {
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500148 private static final String E_NULL_TELINK_UNDERLAY_PATH =
149 "TeSubsystem link underlayPath object cannot be null";
150 private static final String E_NULL_TELINK_DATA =
151 "TeSubsystem teLinkAttrBuilder data cannot be null";
152 private static final String E_NULL_TELINK =
153 "TeSubsystem teLink object cannot be null";
154 private static final String E_NULL_YANG_TELINK_CONFIG =
155 "YANG telink config object cannot be null";
156 private static final String E_NULL_YANG_TELINK =
157 "YANG Link object cannot be null";
Yixiao Chen39828a62016-09-14 14:37:06 -0400158
159 // no instantiation
160 private LinkConverter() {
161 }
162
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500163 private static LinkProtectionTypeEnum teSubsystem2YangLinkProtectionType(TunnelProtectionType linkProtectionType) {
164 switch (linkProtectionType) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500165 case ENHANCED:
166 return LinkProtectionTypeEnum.ENHANCED;
167 case EXTRA_TRAFFIC:
168 return LinkProtectionTypeEnum.EXTRA_TRAFFIC;
169 case SHARED:
170 return LinkProtectionTypeEnum.SHARED;
171 case UNPROTECTED:
172 return LinkProtectionTypeEnum.UNPROTECTED;
173 case ONE_FOR_ONE:
174 return LinkProtectionTypeEnum.YANGAUTOPREFIX1_FOR_1;
175 case ONE_PLUS_ONE:
176 return LinkProtectionTypeEnum.YANGAUTOPREFIX1_PLUS_1;
177 default:
178 return null;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500179 }
180 }
181 /**
182 * TE Link Config object conversion from TE Topology subsystem to YANG.
183 *
184 * @param teLink TE link object
185 * @return TE Link Config YANG object
186 */
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500187 private static Config teLink2YangConfig(TeLink teLink, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500188 checkNotNull(teLink, E_NULL_TELINK_DATA);
Yixiao Chen39828a62016-09-14 14:37:06 -0400189
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500190 TeLinkAttributesBuilder attrBuilder = DefaultTeLinkAttributes.builder();
191
192 if (teLink.teLinkKey() != null) {
193 // what is link index? for now I used teLinkTpId
194 attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId()));
195 }
196
197 if (teLink.adminStatus() != null) {
198 attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus()));
199 }
200
201 if (teLink.tunnelProtectionType() != null) {
202 attrBuilder = attrBuilder
203 .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500204 .tunnelProtectionType()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500205 }
206
207 attrBuilder = attrBuilder.teDefaultMetric(teLink.cost());
208
209 if (teLink.srlgs() != null) {
210 TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder();
211 for (Long srlgLongVal : teLink.srlgs()) {
212 teSrlgsBuilder = teSrlgsBuilder.addToValue(new Srlg(srlgLongVal));
213 }
214 attrBuilder = attrBuilder.teSrlgs(teSrlgsBuilder.build());
215 }
216 attrBuilder = attrBuilder.isAbstract(teLink.flags().get(TeNode.BIT_ABSTRACT));
217
218 if (teLink.externalLink() != null) {
219 ExternalDomainBuilder edBuilder =
220 DefaultExternalDomain.builder();
221 if (teLink.externalLink().plugId() != null) {
222 edBuilder.plugId(teLink.externalLink().plugId());
223 }
224 if (teLink.externalLink().externalLinkKey() != null) {
225 edBuilder = edBuilder
226 .remoteTeLinkTpId(TeTpId.fromString(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500227 String.valueOf(teLink
228 .externalLink()
229 .externalLinkKey()
230 .teLinkTpId())))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500231 .remoteTeNodeId(TeNodeId.fromString(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500232 String.valueOf(teLink
233 .externalLink()
234 .externalLinkKey()
235 .teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500236 }
237 attrBuilder = attrBuilder.externalDomain(edBuilder.build());
238 }
239
240 if (teLink.availBandwidth() != null) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500241 for (short i = 0; i < teLink.availBandwidth().length; i++) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500242 UnreservedBandwidthBuilder urBuilder =
243 DefaultUnreservedBandwidth.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500244 .bandwidth(BigDecimal.valueOf(teLink.availBandwidth()[i]))
245 .priority(i);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500246 attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build());
247 }
248 }
249
250 if (teLink.maxBandwidth() != null) {
251 // maxBandwidth is an array of float[], but in yang is just a big decimal
252 attrBuilder = attrBuilder.maxLinkBandwidth(BigDecimal.valueOf(teLink.maxBandwidth()[0]));
253 }
254 // FIXME: how to retrieve maxResvLinkBandwidth from teLink
255// if (teLink.maxResvLinkBandwidth() != null) {
256// attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth());
257// }
258
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500259 if (teLink.primaryPath() != null || teLink.backupPaths() != null) {
260 UnderlayBuilder builder = DefaultUnderlay.builder();
261 if (teLink.primaryPath() != null) {
262 // TODO: what is underlayProtectionType in tePath?
263 // builder =
264 // builder.underlayProtectionType(tePath.protectionType());
265 builder = te2YangConfigUnderlayPrimaryPath(builder, teLink,
266 teTopologyService);
267 }
268
269 if (teLink.backupPaths() != null) {
270 builder = te2YangConfigUnderlayBackupPaths(builder, teLink,
271 teTopologyService);
272 }
273
274 attrBuilder = attrBuilder.underlay(builder.build());
275 }
276
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500277
278 ConfigBuilder yangConfigBuilder = DefaultConfig.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500279 .teLinkAttributes(attrBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500280 return yangConfigBuilder.build();
281 }
282
283 /**
284 * TE Link State object conversion from TE Topology subsystem to YANG.
285 *
286 * @param teLink TE link object
287 * @return TE Link State YANG object
288 */
289 private static State teLink2YangState(TeLink teLink) {
290 TeLinkAttributes
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500291 .TeLinkAttributesBuilder attrBuilder =
292 DefaultTeLinkAttributes
293 .builder()
294 .teDefaultMetric(teLink.cost())
295 .isAbstract(teLink.flags().get(TeLink.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500296 if (teLink.teLinkKey() != null) {
297 // what is link index? for now I used teLinkTpId
298 attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId()));
299 }
300
301 if (teLink.adminStatus() != null) {
302 attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus()));
303 }
304 if (teLink.tunnelProtectionType() != null) {
305 attrBuilder = attrBuilder
306 .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500307 .tunnelProtectionType()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500308 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500309 if (teLink.maxBandwidth() != null) {
310 // maxBandwidth is an array of float[], but in yang is just a big decimal
311 attrBuilder = attrBuilder.maxLinkBandwidth(BigDecimal.valueOf(teLink.maxBandwidth()[0]));
312 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500313// if (teLink.maxResvLinkBandwidth() != null) {
314// attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth());
315// }
316 if (teLink.srlgs() != null) {
317 TeSrlgs.TeSrlgsBuilder srlgsBuilder = DefaultTeSrlgs.builder();
318 for (Long srlgLongVal : teLink.srlgs()) {
319 srlgsBuilder = srlgsBuilder.addToValue(new Srlg(srlgLongVal));
320 }
321 attrBuilder = attrBuilder.teSrlgs(srlgsBuilder.build());
322 }
323
324 if (teLink.externalLink() != null) {
325 ExternalDomain.ExternalDomainBuilder edBuilder = DefaultExternalDomain
326 .builder();
327 if (teLink.externalLink().plugId() != null) {
328 edBuilder = edBuilder.plugId(teLink.externalLink().plugId());
329 }
330 if (teLink.externalLink().externalLinkKey() != null) {
331 edBuilder = edBuilder
332 .remoteTeLinkTpId(TeTpId.fromString(String.valueOf(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500333 .externalLink()
334 .externalLinkKey()
335 .teLinkTpId())))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500336 .remoteTeNodeId(TeNodeId.fromString(String.valueOf(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500337 .externalLink()
338 .externalLinkKey()
339 .teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500340 }
341 attrBuilder = attrBuilder.externalDomain(edBuilder.build());
342
343 }
344
345 if (teLink.availBandwidth() != null) {
346 short i = 0;
347 for (float f : teLink.availBandwidth()) {
348 UnreservedBandwidth.UnreservedBandwidthBuilder urBuilder = DefaultUnreservedBandwidth
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500349 .builder().bandwidth(BigDecimal.valueOf(f)).priority(i);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500350 i++;
351 attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build());
352 }
353 }
354
355 StateBuilder yangStateBuilder = DefaultState.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500356 .teLinkAttributes(attrBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500357 if (teLink.opStatus() != null) {
358 yangStateBuilder = yangStateBuilder.operStatus(EnumConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500359 .teSubsystem2YangOperStatus(teLink.opStatus()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500360 }
361
362 if (teLink.sourceTeLinkId() != null) {
363 InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder();
364
365 Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder();
366 topologyBuilder = topologyBuilder.clientIdRef(teLink.sourceTeLinkId().clientId())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500367 .providerIdRef(teLink.sourceTeLinkId().providerId())
368 .teTopologyIdRef(teLink.sourceTeLinkId().topologyId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500369 issBuilder = issBuilder.topology(topologyBuilder.build());
370 yangStateBuilder.informationSourceState(issBuilder.build());
371 }
372
373 // Once stateDerived underlay is available in yang and core TE Topology
374 // object model, set the value properly
375 // stateDerivedUnderlay = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology
376 // .rev20160708.ietftetopology.telinkstatederived.Underlay
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500377 //yangStateBuilder = yangStateBuilder.underlay(stateDerivedUnderlay);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500378
379 return yangStateBuilder.build();
380 }
381
382 /**
383 * Link object conversion from TE Topology subsystem to YANG.
384 *
385 * @param teSubsNetworkLink TE subsystem link object
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500386 * @param teTopologyService teTopology core service
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500387 * @return YANG link object
388 */
389 public static Link teSubsystem2YangLink(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500390 org.onosproject.tetopology.management.api.link.NetworkLink teSubsNetworkLink,
391 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500392 checkNotNull(teSubsNetworkLink, E_NULL_TELINK);
393
394 LinkId linkId = LinkId.fromString(teSubsNetworkLink.linkId().toString());
395 LinkBuilder builder = DefaultLink.builder().linkId(linkId);
396 if (teSubsNetworkLink.supportingLinkIds() != null) {
397 List<SupportingLink> slinks = Lists.newArrayList();
398 SupportingLinkBuilder spLinkBuilder = DefaultSupportingLink.builder();
399 for (NetworkLinkKey linkKey : teSubsNetworkLink.supportingLinkIds()) {
400 slinks.add(spLinkBuilder.networkRef(NetworkId.fromString(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500401 linkKey.networkId().toString()))
402 .linkRef(LinkId.fromString(
403 linkKey.linkId().toString()))
404 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500405 }
406 builder = builder.supportingLink(slinks);
407 }
408 if (teSubsNetworkLink.source() != null) {
409 SourceBuilder sourceBuilder = DefaultSource
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500410 .builder()
411 .sourceNode(NodeId.fromString(
412 teSubsNetworkLink.source().nodeId().toString()))
413 .sourceTp(TpId.fromString(
414 teSubsNetworkLink.source().tpId().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500415 builder = builder.source(sourceBuilder.build());
416 }
417 if (teSubsNetworkLink.destination() != null) {
418 DestinationBuilder destBuilder = DefaultDestination
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500419 .builder()
420 .destNode(NodeId.fromString(
421 teSubsNetworkLink.destination().nodeId().toString()))
422 .destTp(TpId.fromString(
423 teSubsNetworkLink.destination().tpId().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500424 builder = builder.destination(destBuilder.build());
425 }
426
427 if (teSubsNetworkLink.teLink() != null) {
428 TeLink teData = teSubsNetworkLink.teLink();
429 TeBuilder yangTeBuilder = DefaultTe.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500430 .config(teLink2YangConfig(teData, teTopologyService))
431 .state(teLink2YangState(teData));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500432 // ignoring supportingTeLinkId when converting from core to yang?
433 // if (teData.supportingTeLinkId() != null) {
434 // }
435 AugmentedNtLinkBuilder linkAugmentBuilder =
436 DefaultAugmentedNtLink.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500437 .te(yangTeBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500438 builder.addYangAugmentedInfo(linkAugmentBuilder.build(), AugmentedNtLink.class);
439 }
440
441 return builder.build();
442 }
443
444 private static UnderlayBuilder te2YangConfigUnderlayPrimaryPath(
445 UnderlayBuilder yangBuilder,
Hesam Rahimi41208102016-12-09 17:54:03 -0500446 TeLink teLink, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500447
448 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath tePath = teLink.primaryPath();
449
450 UnderlayPrimaryPathBuilder pathBuilder =
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500451 DefaultUnderlayPrimaryPath.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500452 if (tePath.pathElements() != null) {
453 for (PathElement pathElementTe : tePath.pathElements()) {
454 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500455 .ietftetopology.telinkunderlayattributes.underlayprimarypath.PathElement
456 .PathElementBuilder pathElementYangBuilder = DefaultPathElement.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500457
458 pathElementYangBuilder = pathElementYangBuilder.pathElementId(pathElementTe.pathElementId());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500459 //TODO: check more types here
460 if (pathElementTe.type() instanceof TeLinkId) {
461 UnnumberedLinkBuilder unmBuilder = DefaultUnnumberedLink.builder()
462 .routerId(IpAddress.fromString(
463 Ip4Address.valueOf((int) pathElementTe.teNodeId()).toString()))
464 .interfaceId(((TeLinkId) pathElementTe.type()).value());
465 pathElementYangBuilder = pathElementYangBuilder.type(unmBuilder.build());
466 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500467
468 pathBuilder = pathBuilder.addToPathElement(pathElementYangBuilder.build());
469 }
470 }
471
472 pathBuilder = pathBuilder.clientIdRef(teLink.underlayTeTopologyId().clientId())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500473 .providerIdRef(teLink.underlayTeTopologyId().providerId())
474 .teTopologyIdRef(teLink.underlayTeTopologyId().topologyId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500475
Hesam Rahimi41208102016-12-09 17:54:03 -0500476 pathBuilder = pathBuilder.networkIdRef(teTopologyService.networkId(teLink.underlayTeTopologyId()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500477
478 return yangBuilder.underlayPrimaryPath(pathBuilder.build());
479 }
480
481 private static UnderlayBuilder te2YangConfigUnderlayBackupPaths(UnderlayBuilder yangBuilder,
Hesam Rahimi41208102016-12-09 17:54:03 -0500482 TeLink teLink,
483 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500484 List<UnderlayBackupPath> tePaths = teLink.backupPaths();
485
486 for (UnderlayBackupPath tePath : tePaths) {
487 UnderlayBackupPathBuilder pathBuilder = DefaultUnderlayBackupPath
488 .builder();
489 pathBuilder = pathBuilder.index(tePath.index());
490 pathBuilder = pathBuilder.clientIdRef(teLink.underlayTeTopologyId().clientId())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500491 .providerIdRef(teLink.underlayTeTopologyId().providerId())
492 .teTopologyIdRef(teLink.underlayTeTopologyId().topologyId());
Hesam Rahimi41208102016-12-09 17:54:03 -0500493
494 pathBuilder = pathBuilder.networkIdRef(teTopologyService.networkId(teLink.underlayTeTopologyId()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500495
496 for (PathElement backupPathElementTe : tePath.pathElements()) {
497 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500498 .ietftetopology.telinkunderlayattributes.underlaybackuppath.PathElement
499 .PathElementBuilder elementBuilder =
500 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
501 .ietftetopology.telinkunderlayattributes.underlaybackuppath.DefaultPathElement
502 .builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500503
504 elementBuilder = elementBuilder.pathElementId(backupPathElementTe.pathElementId());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500505 //TODO: check more types here
506 if (backupPathElementTe.type() instanceof TeLinkId) {
507 UnnumberedLinkBuilder unmBuilder = DefaultUnnumberedLink.builder()
508 .routerId(IpAddress.fromString(
509 Ip4Address.valueOf((int) backupPathElementTe.teNodeId()).toString()))
510 .interfaceId(((TeLinkId) backupPathElementTe.type()).value());
511 elementBuilder = elementBuilder.type(unmBuilder.build());
512 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500513
514 pathBuilder = pathBuilder
515 .addToPathElement(elementBuilder.build());
516 }
517 yangBuilder = yangBuilder
518 .addToUnderlayBackupPath(pathBuilder.build());
519 }
520
521 return yangBuilder;
522 }
523
524 private static TeLink yang2TeLinkAttributes(TeLinkAttributes yangLinkAttr,
525 State opState, Link yangLink,
526 Network yangNetwork,
527 Networks yangNetworks) {
528 TeNodeId teNodeId = findTeNodeId(yangNetwork,
Hesam Rahimi41208102016-12-09 17:54:03 -0500529 yangLink.source().sourceNode());
530 long teNodeIdLong = -1;
531 if (teNodeId != null && teNodeId.dottedQuad() != null) {
532 teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string())
533 .toInt();
534 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500535
536 TeLinkTpKey teLinkKey = new TeLinkTpKey(teNodeIdLong,
537 findTeTpId(yangNetwork,
538 yangLink.source().sourceNode(),
539 yangLink.source().sourceTp()));
540
Hesam Rahimi41208102016-12-09 17:54:03 -0500541 TeNodeId teNodeIdDest = null;
542 if (yangLink.destination() != null) {
543 teNodeIdDest = findTeNodeId(yangNetwork,
544 yangLink.destination().destNode());
545 }
546 long teNodeIdDestLong = -1;
547 if (teNodeIdDest != null && teNodeIdDest.dottedQuad() != null) {
548 teNodeIdDestLong = Ip4Address.valueOf(teNodeIdDest.dottedQuad().string()).toInt();
549 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500550
Hesam Rahimi41208102016-12-09 17:54:03 -0500551 TeLinkTpKey peerTeLinkKey = null;
552 if (yangLink.destination() != null) {
553 peerTeLinkKey = new TeLinkTpKey(teNodeIdDestLong,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500554 findTeTpId(yangNetwork,
555 yangLink.destination().destNode(),
556 yangLink.destination().destTp()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500557 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500558
559 TeLinkTpGlobalKey supportTeLinkId = findSupportTeLinkId(yangNetworks, yangLink);
560
561 org.onosproject.tetopology.management.api.TeStatus opStatus = null;
562 if (opState != null && opState.operStatus() != null) {
563 opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState.operStatus());
564 }
565
566
567 TeLink teLink = yangLinkAttr2TeLinkAttributes(yangLinkAttr, opStatus, teNodeIdLong, teNodeIdDestLong, teLinkKey,
568 peerTeLinkKey, supportTeLinkId);
569
570 return teLink;
571 }
572
573 private static TeLink yangLinkAttr2TeLinkAttributes(TeLinkAttributes yangLinkAtrr,
574 org.onosproject.tetopology.management.api.TeStatus opStatus,
575 long teNodeIdLong,
576 long teNodeIdDestLong,
577 TeLinkTpKey teLinkKey,
578 TeLinkTpKey peerTeLinkKey,
579 TeLinkTpGlobalKey supportTeLinkId) {
580 org.onosproject.tetopology.management.api.TeStatus adminStatus = null;
581
582 TeLinkTpGlobalKey sourceTeLinkId = null; // from yang to core, we can ignore sourceTeLinkId
583 TeTopologyKey underlayTopologyId = null;
584 CommonLinkData teData = null;
585
Hesam Rahimi41208102016-12-09 17:54:03 -0500586 if (yangLinkAtrr != null && yangLinkAtrr.underlay() != null &&
587 yangLinkAtrr.underlay().underlayPrimaryPath() != null) {
588 underlayTopologyId = new
589 TeTopologyKey((long) yangLinkAtrr.underlay().underlayPrimaryPath().providerIdRef(),
590 (long) yangLinkAtrr.underlay().underlayPrimaryPath().clientIdRef(),
591 (long) yangLinkAtrr.underlay().underlayPrimaryPath().teTopologyIdRef());
592 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500593
594 if (yangLinkAtrr.adminStatus() != null) {
595 adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangLinkAtrr.adminStatus());
596 }
597
598 BitSet flags = new BitSet();
599 if (yangLinkAtrr.isAbstract()) {
600 flags.set(TeLink.BIT_ABSTRACT);
601 }
602
Hesam Rahimi41208102016-12-09 17:54:03 -0500603 ExternalLink externalLink = null;
604 if (yangLinkAtrr != null && yangLinkAtrr.externalDomain() != null) {
605 externalLink = new ExternalLink(null, yangLinkAtrr.externalDomain().plugId());
606 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500607
608 UnderlayPath underlayPath = null;
609 underlayPath = yang2TeSubsystemUnderlayPath(yangLinkAtrr, teNodeIdLong,
610 teNodeIdDestLong);
Hesam Rahimi41208102016-12-09 17:54:03 -0500611 Long adminGroup = null;
612 if (yangLinkAtrr != null && yangLinkAtrr.administrativeGroup() != null) {
613 adminGroup = Long.valueOf(yangLinkAtrr.administrativeGroup().toString());
614 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500615 List<Long> interLayerLocks = null; // FIXME: how to find interLayerLocks?
616
617 List<UnreservedBandwidth> listOfUnreservedBandwidth = yangLinkAtrr.unreservedBandwidth();
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500618 float[] availBandwidth = new float[MAX_PRIORITY + 1];
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500619 for (UnreservedBandwidth urbw : listOfUnreservedBandwidth) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500620 availBandwidth[urbw.priority()] = urbw.bandwidth().floatValue();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500621 }
622
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500623 float[] maxBandwidth = new float[MAX_PRIORITY + 1];
Hesam Rahimi41208102016-12-09 17:54:03 -0500624 if (yangLinkAtrr.maxLinkBandwidth() != null) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500625 // Core TE has an array, but YANG is an integer
626 for (short p = 0; p <= MAX_PRIORITY; p++) {
627 maxBandwidth[p] = yangLinkAtrr.maxLinkBandwidth().floatValue();
628 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500629 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500630
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500631 float[] maxAvailLspBandwidth = availBandwidth; // FIXME: how to find this?
632 float[] minAvailLspBandwidth = availBandwidth; // FIXME: how to find this?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500633 LinkBandwidth bandwidth = new LinkBandwidth(
634 maxBandwidth,
635 availBandwidth,
636 maxAvailLspBandwidth,
637 minAvailLspBandwidth,
638 null); // FIXME: how to find odu resource?
639 List<Long> srlgs = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500640 if (yangLinkAtrr.teSrlgs() != null
641 && yangLinkAtrr.teSrlgs().value() != null
642 && !yangLinkAtrr.teSrlgs().value().isEmpty()) {
643 for (Srlg srlg : yangLinkAtrr.teSrlgs().value()) {
644 srlgs.add(srlg.uint32());
645 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500646 }
647 TePathAttributes teAttributes =
648 new TePathAttributes(yangLinkAtrr.teDefaultMetric(),
Hesam Rahimi41208102016-12-09 17:54:03 -0500649 yangLinkAtrr.performanceMetric() == null ? null :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500650 (yangLinkAtrr.performanceMetric().measurement() == null ? null :
651 yangLinkAtrr.performanceMetric().measurement().unidirectionalDelay()),
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500652 srlgs);
653 teData = new CommonLinkData(adminStatus,
654 opStatus,
655 flags,
656 null, // switchingLayer
657 null, // encodingLayer
658 externalLink,
659 underlayPath,
660 teAttributes,
661 adminGroup,
662 interLayerLocks,
663 bandwidth);
664
665 TeLink te = new DefaultTeLink(teLinkKey, peerTeLinkKey,
666 underlayTopologyId, supportTeLinkId,
667 sourceTeLinkId, teData);
668 return te;
669 }
670
671 private static TeLinkTpGlobalKey findSupportTeLinkId(Networks yangNetworks,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500672 Link yangLink) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500673 Network teNetworkFound = null;
674 LinkId teLinkIdFound = null;
Hesam Rahimi41208102016-12-09 17:54:03 -0500675 TeLinkTpGlobalKey supportTeLinkId = null;
676
677 if (yangLink != null && yangLink.supportingLink() != null && !yangLink.supportingLink().isEmpty()) {
678 if (yangNetworks.network() != null && !yangNetworks.network().isEmpty()) {
679 for (Network ynetItem : yangNetworks.network()) {
680 if (ynetItem.networkId() != null) {
681 if (ynetItem.networkId().equals(yangLink.supportingLink().get(0).networkRef())) {
682 teNetworkFound = ynetItem;
683 teLinkIdFound = yangLink.supportingLink().get(0).linkRef();
684 break;
685 }
686 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500687 }
688 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500689 Link teLinkFound = null;
690 if (teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class) != null) {
691 AugmentedNdNetwork augmentLink =
692 (AugmentedNdNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class);
693 for (Link link : augmentLink.link()) {
694 if (link.linkId().equals(teLinkIdFound)) {
695 teLinkFound = link;
696 break;
697 }
698 }
699 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500700
Hesam Rahimi41208102016-12-09 17:54:03 -0500701 TeNodeId teSupportNodeId = findTeNodeId(teNetworkFound,
702 teLinkFound.source().sourceNode());
703 long tenIdLong = -1;
704 if (teSupportNodeId != null) {
705 tenIdLong = Ip4Address.valueOf(teSupportNodeId.dottedQuad().string()).toInt();
706 }
707 long teSupportLinkTpId = findTeTpId(teNetworkFound,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500708 teLinkFound.source().sourceNode(),
709 teLinkFound.source().sourceTp());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500710
Hesam Rahimi41208102016-12-09 17:54:03 -0500711 org.onosproject.tetopology.management.api.TeTopologyId teTopologyId = null;
712 if (teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class) != null) {
713 AugmentedNwNetwork augmentTeIds =
714 (AugmentedNwNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class);
715 teTopologyId =
716 new org.onosproject.tetopology.management.api.TeTopologyId(
717 augmentTeIds.te().clientId().uint32(),
718 augmentTeIds.te().providerId().uint32(),
719 augmentTeIds.te().teTopologyId().string());
720 }
721
722 supportTeLinkId = new TeLinkTpGlobalKey(teTopologyId.providerId(),
723 teTopologyId.clientId(),
724 Long.valueOf(teTopologyId
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500725 .topologyId()),
Hesam Rahimi41208102016-12-09 17:54:03 -0500726 tenIdLong, teSupportLinkTpId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500727 }
728
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500729 return supportTeLinkId;
730 }
731
Hesam Rahimi41208102016-12-09 17:54:03 -0500732 private static TeNodeId findTeNodeId(Network yangNetwork, NodeId yangNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500733 TeNodeId teNodeId = null;
734 for (Node node : yangNetwork.node()) {
735 if (node.nodeId().equals(yangNodeId)) {
736 if (node.yangAugmentedInfoMap() != null
737 && !node.yangAugmentedInfoMap().isEmpty()) {
738 AugmentedNwNode yangNodeAugment = (AugmentedNwNode) node
739 .yangAugmentedInfo(AugmentedNwNode.class);
740 if (yangNodeAugment != null && yangNodeAugment.te() != null
741 && yangNodeAugment.te().teNodeId() != null) {
742 Te yangNodeAugTe = yangNodeAugment.te();
743 teNodeId = yangNodeAugTe.teNodeId();
744 }
745 }
746 }
747 }
748 return teNodeId;
749 }
750
751 private static long findTeTpId(Network yangNetwork, NodeId yangNodeId, TpId yangTpId) {
752 long teTpId = 0;
753 for (Node node : yangNetwork.node()) {
754 if (node.nodeId().equals(yangNodeId)) {
755 if (node.yangAugmentedInfoMap() != null
756 && !node.yangAugmentedInfoMap().isEmpty()) {
757
758 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) node
759 .yangAugmentedInfo(AugmentedNdNode.class);
760 if (yangTpNodeAugment.terminationPoint() != null) {
761 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
762 .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
763 yangTpnode : yangTpNodeAugment.terminationPoint()) {
764 if (yangTpnode.tpId().equals(yangTpId)) {
765 if (yangTpnode.yangAugmentedInfoMap() != null
766 && !yangTpnode.yangAugmentedInfoMap()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500767 .isEmpty()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500768 AugmentedNtTerminationPoint yangTpAugment =
769 (AugmentedNtTerminationPoint) yangTpnode
770 .yangAugmentedInfo(AugmentedNtTerminationPoint.class);
771 if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) {
772 teTpId = Long.valueOf(yangTpAugment.te().teTpId().toString());
773 }
774 }
775 }
776 }
777 }
778 }
779 }
780 }
781 return teTpId;
782 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400783 /**
784 * Link object conversion from YANG to TE Topology subsystem.
785 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500786 * @param yangLink YANG link
787 * @param yangNetwork YANG network
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500788 * @param yangNetworks YANG networks
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500789 * @return TE subsystem link
Yixiao Chen39828a62016-09-14 14:37:06 -0400790 */
791 public static org.onosproject.tetopology.management.api.link.NetworkLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500792 yang2TeSubsystemLink(Link yangLink, Network yangNetwork,
793 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500794 NetworkId networkId = yangNetwork.networkId();
795 checkNotNull(yangLink, E_NULL_YANG_TELINK);
Yixiao Chen39828a62016-09-14 14:37:06 -0400796
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500797 KeyId linkId = KeyId.keyId(yangLink.linkId().uri().toString());
798 NodeTpKey sourceNodeTpKey = null;
799 NodeTpKey destinationNodeTpKey = null;
800 List<NetworkLinkKey> spLinkIds = null;
801 TeLink te = null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400802
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500803 if (yangLink.supportingLink() != null) {
804 spLinkIds = Lists.newArrayList();
805 for (SupportingLink yangSpLink : yangLink.supportingLink()) {
806 NetworkLinkKey linkKey = new NetworkLinkKey(KeyId.keyId(yangSpLink.networkRef().uri().toString()),
807 KeyId.keyId(yangSpLink.linkRef().uri().toString()));
808 spLinkIds.add(linkKey);
809 }
810 }
811
812 if (yangLink.source() != null) {
813 TerminationPointKey source = new TerminationPointKey(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500814 KeyId.keyId(networkId.uri().toString()),
815 KeyId.keyId(yangLink.source().sourceNode().uri().toString()),
816 KeyId.keyId(yangLink.source().sourceTp().uri().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500817 sourceNodeTpKey = new NodeTpKey(source.nodeId(), source.tpId());
818 }
819
820 if (yangLink.destination() != null) {
821 TerminationPointKey destination = new TerminationPointKey(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500822 KeyId.keyId(networkId.uri().toString()),
823 KeyId.keyId(yangLink.destination().destNode().uri().toString()),
824 KeyId.keyId(yangLink.destination().destTp().uri().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500825 destinationNodeTpKey = new NodeTpKey(destination.nodeId(), destination.tpId());
826 }
827
828 if (yangLink.yangAugmentedInfoMap() != null && !yangLink.yangAugmentedInfoMap().isEmpty()) {
829
830 AugmentedNtLink yangLinkAugment =
831 (AugmentedNtLink) yangLink.yangAugmentedInfo(AugmentedNtLink.class);
832 if (yangLinkAugment != null &&
833 yangLinkAugment.te() != null &&
834 yangLinkAugment.te().config() != null) {
835 TeLinkAttributes yangLinkAtrr =
836 yangLinkAugment.te().config().teLinkAttributes();
837 if (yangLinkAtrr != null && yangLinkAtrr.linkIndex() != null) {
838 te = yang2TeLinkAttributes(yangLinkAtrr,
839 yangLinkAugment.te().state(),
840 yangLink, yangNetwork,
841 yangNetworks);
842 }
843 }
844 }
845
846 org.onosproject.tetopology.management.api.link.DefaultNetworkLink link =
847 new DefaultNetworkLink(linkId,
848 sourceNodeTpKey,
849 destinationNodeTpKey,
850 spLinkIds,
851 te);
852 return link;
Yixiao Chen39828a62016-09-14 14:37:06 -0400853 }
854
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500855 private static org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500856 yang2TeSubsystemUnderlayPrimaryPath(UnderlayPrimaryPath yangpath,
857 long teNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500858 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath teUnderlayPrimaryPath = null;
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500859
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500860 List<PathElement> pathElementList = Lists.newArrayList();
861 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
862 .telinkunderlayattributes.underlayprimarypath.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500863 PathElement pathElementYang : yangpath.pathElement()) {
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500864
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500865 long nodeId = 0;
866 ElementType type = null;
867 // TODO: check more types
868 if (pathElementYang.type() instanceof UnnumberedLink) {
869 nodeId = Long.valueOf(((UnnumberedLink) pathElementYang.type()).routerId().toString());
870 type = new TeLinkId(((UnnumberedLink) pathElementYang.type()).interfaceId());
871 }
872 PathElement tePathElement = new PathElement(pathElementYang.pathElementId(),
873 nodeId,
874 type,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500875 false); // FIXME: how to find the proper value for loose?
876 pathElementList.add(tePathElement);
877 }
878
879 teUnderlayPrimaryPath = new org.onosproject.tetopology.management.api.link.
880 UnderlayPrimaryPath(pathElementList, false); // FIXME: how to find the proper value for loose?
881
882 return teUnderlayPrimaryPath;
883 }
884
885 private static List<UnderlayBackupPath>
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500886 yang2TeSubsystemUnderlayBackupPaths(
887 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500888 rev20160708.ietftetopology.telinkunderlayattributes.
889 UnderlayBackupPath> yangpaths,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500890 long teNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500891
892 List<UnderlayBackupPath> underlayBackupPathsList = Lists.newArrayList();
893 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
894 .ietftetopology.telinkunderlayattributes.
895 UnderlayBackupPath yangConfig : yangpaths) {
896 UnderlayBackupPath ubp = null;
897 List<PathElement> backupPathElementList = Lists.newArrayList();
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500898 long nodeId = 0;
899 ElementType type = null;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500900 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
901 .telinkunderlayattributes.underlaybackuppath.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500902 PathElement backupYang : yangConfig.pathElement()) {
903 // TODO: check more types
904 if (backupYang.type() instanceof UnnumberedLink) {
905 nodeId = Long.valueOf(((UnnumberedLink) backupYang.type()).routerId().toString());
906 type = new TeLinkId(((UnnumberedLink) backupYang.type()).interfaceId());
907 }
908 PathElement tePathElementBackup = new PathElement(backupYang.pathElementId(),
909 nodeId,
910 type,
911 false);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500912 backupPathElementList.add(tePathElementBackup);
913 }
914 ubp = new UnderlayBackupPath(yangConfig.index(),
915 backupPathElementList,
916 null); // FIXME: find the proper value for loose
917 underlayBackupPathsList.add(ubp);
918 }
919
920 return underlayBackupPathsList;
921 }
922
923 /**
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500924 * TE Link underlay path Config object conversion from YANG to TE Topology subsystem.
925 *
926 * @param yangLinkAtrr YANG link Config YANG object
927 * @return teSubsystem TE underlay path object
928 */
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500929 private static org.onosproject.tetopology.management.api.link.UnderlayPath
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500930 yang2TeSubsystemUnderlayPath(TeLinkAttributes yangLinkAtrr, long srcTeNodeId, long dstTeNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500931
932 checkNotNull(yangLinkAtrr, E_NULL_YANG_TELINK_CONFIG);
933
934 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath underlayPrimaryPath = null;
935 List<UnderlayBackupPath> underlayBackupPathsList = null;
936 TeTunnelId teTunnelId = new TeTunnelId(srcTeNodeId, dstTeNodeId, 0); // FIXME: how to find teTunnelId?
937
Hesam Rahimi41208102016-12-09 17:54:03 -0500938 if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().underlayPrimaryPath() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500939 underlayPrimaryPath =
940 yang2TeSubsystemUnderlayPrimaryPath(yangLinkAtrr.underlay().underlayPrimaryPath(), srcTeNodeId);
941 }
942
Hesam Rahimi41208102016-12-09 17:54:03 -0500943 if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().underlayBackupPath() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500944 underlayBackupPathsList =
945 yang2TeSubsystemUnderlayBackupPaths(yangLinkAtrr.underlay().underlayBackupPath(), srcTeNodeId);
946 }
947
Hesam Rahimi41208102016-12-09 17:54:03 -0500948 org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay = null;
949 if (yangLinkAtrr.underlay() != null) {
950 teUnderlay = new org.onosproject.tetopology.management.api.link.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500951 UnderlayPath(underlayPrimaryPath,
952 underlayBackupPathsList,
953 TunnelProtectionType.of(yangLinkAtrr.underlay().underlayProtectionType()),
954 (long) yangLinkAtrr.underlay().underlayTrailSrc().tpRef(), // Is this correct?
955 (long) yangLinkAtrr.underlay().underlayTrailDes().tpRef(), // Is this correct?
956 teTunnelId);
Hesam Rahimi41208102016-12-09 17:54:03 -0500957 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500958
959 return teUnderlay;
960 }
961
962 /**
963 * Converts a TE Topology link event from the data format used in
964 * the core to its corresponding YANG Object (YO) format.
965 *
966 * @param eventType Link event type
967 * @param linkData TE Topology link event data
968 * @return YANG Object converted from linkData
969 */
970 public static TeLinkEvent teNetworkLink2yangTeLinkEvent(TeTopologyEventTypeEnum eventType,
Hesam Rahimi41208102016-12-09 17:54:03 -0500971 NetworkLinkEventSubject linkData) {
Henry Yu8ac364b2016-12-15 18:24:20 -0500972 TeLinkEvent.TeLinkEventBuilder teLinkEventBuilder = new DefaultTeLinkEvent.TeLinkEventBuilder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500973
974 TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
Henry Yu8ac364b2016-12-15 18:24:20 -0500975 teLinkEventBuilder.eventType(yangEventType);
976 NetworkId networkId = NetworkId.fromString(linkData.key().networkId().toString());
977 teLinkEventBuilder.networkRef(networkId);
Hesam Rahimi41208102016-12-09 17:54:03 -0500978 LinkId linkId = LinkId.fromString(linkData.key().linkId().toString());
Henry Yu8ac364b2016-12-15 18:24:20 -0500979 teLinkEventBuilder.linkRef(linkId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500980
Henry Yu8ac364b2016-12-15 18:24:20 -0500981 if (linkData != null && linkData.networkLink() != null) {
982 NetworkLink link = linkData.networkLink();
983 State yangTeLinkState = teLink2YangState(link.teLink());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500984
Henry Yu8ac364b2016-12-15 18:24:20 -0500985 teLinkEventBuilder.operStatus(yangTeLinkState.operStatus());
986 teLinkEventBuilder.informationSource(yangTeLinkState.informationSource());
987 teLinkEventBuilder.informationSourceEntry(yangTeLinkState.informationSourceEntry());
988 teLinkEventBuilder.informationSourceState(yangTeLinkState.informationSourceState());
989 teLinkEventBuilder.isTransitional(yangTeLinkState.isTransitional());
990 teLinkEventBuilder.recovery(yangTeLinkState.recovery());
991 teLinkEventBuilder.teLinkAttributes(yangTeLinkState.teLinkAttributes());
992 teLinkEventBuilder.underlay(yangTeLinkState.underlay());
993 }
994
995 return teLinkEventBuilder.build();
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500996 }
997
Henry Yu05dcc212017-01-05 16:05:26 -0500998 /**
999 * Retrieves the TE network link key from a given YANG network link
1000 * notification event.
1001 *
1002 * @param yangLinkEvent YANG network link notification
1003 * @return TE network link key
1004 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001005 public static NetworkLinkKey yangLinkEvent2NetworkLinkKey(TeLinkEvent yangLinkEvent) {
Hesam Rahimi41208102016-12-09 17:54:03 -05001006 NetworkId networkRef = NetworkId.fromString(yangLinkEvent.networkRef().toString());
1007 LinkId linkRef = LinkId.fromString(yangLinkEvent.linkRef().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001008 KeyId networkId = KeyId.keyId(networkRef.uri().toString());
1009 KeyId linkId = KeyId.keyId(linkRef.uri().toString());
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001010
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001011 NetworkLinkKey networkLinkKey = new NetworkLinkKey(networkId, linkId);
1012
1013 return networkLinkKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001014 }
1015
Henry Yu05dcc212017-01-05 16:05:26 -05001016 /**
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001017 * Converts a YANG network link notification event into a TE network link.
Henry Yu05dcc212017-01-05 16:05:26 -05001018 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001019 * @param yangLinkEvent YANG network link notification
Henry Yu05dcc212017-01-05 16:05:26 -05001020 * @param teTopologyService TE Topology service used to help the conversion
1021 * @return TE network link
1022 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001023 public static NetworkLink yangLinkEvent2NetworkLink(TeLinkEvent yangLinkEvent,
1024 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001025 KeyId linkId = yangLinkEvent2NetworkLinkKey(yangLinkEvent).linkId();
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001026
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001027 org.onosproject.tetopology.management.api.
1028 Network network = teTopologyService.network(
1029 yangLinkEvent2NetworkLinkKey(yangLinkEvent).networkId());
1030 if (network == null) {
1031 return null;
1032 }
1033
1034 NetworkLink networkLink = network.link(linkId);
1035 if (networkLink == null) {
1036 return null;
1037 }
1038
1039 NodeTpKey sourceTp = networkLink.source();
Henry Yu8ac364b2016-12-15 18:24:20 -05001040 if (sourceTp == null) {
1041 return null;
1042 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001043 NodeTpKey destTp = networkLink.destination();
1044
1045 List<NetworkLinkKey> supportingLinkIds = networkLink.supportingLinkIds();
1046 TeLink teLink = networkLink.teLink();
1047 if (teLink == null) {
1048 return null;
1049 }
1050
1051 TeOperStatus opState = yangLinkEvent.operStatus();
1052 org.onosproject.tetopology.management.api.
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001053 TeStatus opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState);
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001054
1055 TeLink updatedTeLink = yangLinkEvent2TeLinkAttributes(yangLinkEvent, teLink, opStatus);
1056
1057
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001058 NetworkLink updatedNetworkLink = new DefaultNetworkLink(linkId, sourceTp, destTp, supportingLinkIds,
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001059 updatedTeLink);
1060
1061 return updatedNetworkLink;
1062 }
1063
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001064 private static TeLink yangLinkEvent2TeLinkAttributes(TeLinkEvent yangLinkEvent, TeLink oldTeLink, TeStatus
1065 opStatus) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001066
1067 TeLinkAttributes yangTeLinkAttrs = yangLinkEvent.teLinkAttributes();
1068
1069 TeLinkTpKey teLinkKey = oldTeLink.teLinkKey();
1070
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001071
1072 //long teNodeIdDest = oldTeLink.peerTeLinkKey().teNodeId();
1073 //long teNodeIdSrc = oldTeLink.teLinkKey().teNodeId();
Henry Yu8ac364b2016-12-15 18:24:20 -05001074 long teNodeIdDest = 0;
1075 long teNodeIdSrc = 0;
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001076
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001077 TeLinkTpGlobalKey supportTeLinkId = oldTeLink.supportingTeLinkId();
1078 TeLinkTpKey peerTeLinkKey = oldTeLink.peerTeLinkKey();
1079
Henry Yu8ac364b2016-12-15 18:24:20 -05001080 TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeIdSrc, teNodeIdDest,
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001081 teLinkKey, peerTeLinkKey, supportTeLinkId);
1082
1083 return updatedTeLink;
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001084 }
Yixiao Chen39828a62016-09-14 14:37:06 -04001085}