blob: 6a9cb949a9135e40568ba81d09a357ad4b7525da [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
Yixiao Chen265b3bb2017-01-13 10:17:03 -050021import java.math.BigInteger;
22import java.util.BitSet;
23import java.util.List;
24
Hesam Rahimi39bdc002016-11-10 15:01:26 -050025import org.onlab.packet.Ip4Address;
26import org.onosproject.tetopology.management.api.KeyId;
27import org.onosproject.tetopology.management.api.TeStatus;
28import org.onosproject.tetopology.management.api.TeTopologyKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050029import org.onosproject.tetopology.management.api.TeTopologyService;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050030import org.onosproject.tetopology.management.api.link.CommonLinkData;
31import org.onosproject.tetopology.management.api.link.DefaultNetworkLink;
32import org.onosproject.tetopology.management.api.link.DefaultTeLink;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050033import org.onosproject.tetopology.management.api.link.ElementType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050034import org.onosproject.tetopology.management.api.link.ExternalLink;
35import org.onosproject.tetopology.management.api.link.LinkBandwidth;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050036import org.onosproject.tetopology.management.api.link.NetworkLink;
Hesam Rahimi41208102016-12-09 17:54:03 -050037import org.onosproject.tetopology.management.api.link.NetworkLinkEventSubject;
Yixiao Chen39828a62016-09-14 14:37:06 -040038import org.onosproject.tetopology.management.api.link.NetworkLinkKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050039import org.onosproject.tetopology.management.api.link.PathElement;
40import org.onosproject.tetopology.management.api.link.TeLink;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050041import org.onosproject.tetopology.management.api.link.TeLinkId;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050042import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
43import org.onosproject.tetopology.management.api.link.TeLinkTpKey;
44import org.onosproject.tetopology.management.api.link.TePathAttributes;
45import org.onosproject.tetopology.management.api.link.TeTunnelId;
46import org.onosproject.tetopology.management.api.link.TunnelProtectionType;
47import org.onosproject.tetopology.management.api.link.UnderlayBackupPath;
48import org.onosproject.tetopology.management.api.link.UnderlayPath;
49import org.onosproject.tetopology.management.api.node.NodeTpKey;
50import org.onosproject.tetopology.management.api.node.TeNode;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050051import org.onosproject.tetopology.management.api.node.TerminationPointKey;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050052import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.IpAddress;
Yixiao Chen39828a62016-09-14 14:37:06 -040053import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050054import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks;
55import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
56import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050057import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.network.Node;
58import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
59 .ietfnetworktopology.LinkId;
60import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
61 .ietfnetworktopology.TpId;
62import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.AugmentedNdNetwork;
63import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
64 .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink;
65import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
66 .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink.LinkBuilder;
67import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
68 .ietfnetworktopology.networks.network.augmentedndnetwork.Link;
69import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
70 .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultDestination;
71import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
72 .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSource;
73import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
74 .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSupportingLink;
75import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
76 .ietfnetworktopology.networks.network.augmentedndnetwork.link.Destination
77 .DestinationBuilder;
78import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
79 .ietfnetworktopology.networks.network.augmentedndnetwork.link.Source.SourceBuilder;
80import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
81 .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink;
82import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
83 .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink
84 .SupportingLinkBuilder;
85import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.node.AugmentedNdNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050086import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.DefaultTeLinkEvent;
87import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.TeBandwidth;
88import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.TeLinkEvent;
89import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourceperlinkattributes.DefaultInformationSourceState;
90import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourceperlinkattributes.InformationSourceState;
91import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourceperlinkattributes.informationsourcestate.DefaultTopology;
92import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourceperlinkattributes.informationsourcestate.Topology;
93import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.networks.network.AugmentedNwNetwork;
94import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050095 .ietftetopology.networks.network.link.AugmentedNtLink;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050096import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050097 .ietftetopology.networks.network.link.DefaultAugmentedNtLink;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050098import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050099 .ietftetopology.networks.network.link.DefaultAugmentedNtLink.AugmentedNtLinkBuilder;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500100import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.networks.network.node.AugmentedNwNode;
101import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
102import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.DefaultTe;
103import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.DefaultTe.TeBuilder;
104import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.te.Config;
105import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.te.DefaultConfig;
106import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.te.DefaultConfig.ConfigBuilder;
107import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.te.DefaultState;
108import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.te.DefaultState.StateBuilder;
109import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkaugment.te.State;
110import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes;
111import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes.TeLinkAttributesBuilder;
112import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.TeLinkAttributes;
113import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain;
114import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain.ExternalDomainBuilder;
115import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay;
116import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay.UnderlayBuilder;
117import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconfigattributes.telinkattributes.ExternalDomain;
118import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs;
119import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs.TeSrlgsBuilder;
120import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth;
121import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth.UnreservedBandwidthBuilder;
122import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.TeSrlgs;
123import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.UnreservedBandwidth;
124import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkinfoattributes.LinkProtectionTypeEnum;
125import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.DefaultBackupPath;
126import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.DefaultBackupPath.BackupPathBuilder;
127import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.DefaultPrimaryPath;
128import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.DefaultPrimaryPath.PrimaryPathBuilder;
129import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.PrimaryPath;
130import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.primarypath.DefaultPathElement;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500131import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg;
132import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId;
133import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeOperStatus;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500134import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500135import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500136import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink;
137import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink.UnnumberedLinkBuilder;
138import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.UnnumberedLink;
139import 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 -0500140
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500141import com.google.common.collect.Lists;
Yixiao Chen39828a62016-09-14 14:37:06 -0400142
143/**
144 * The conversion functions.
145 */
146public final class LinkConverter {
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500147 private static final String E_NULL_TELINK_UNDERLAY_PATH =
148 "TeSubsystem link underlayPath object cannot be null";
149 private static final String E_NULL_TELINK_DATA =
150 "TeSubsystem teLinkAttrBuilder data cannot be null";
151 private static final String E_NULL_TELINK =
152 "TeSubsystem teLink object cannot be null";
153 private static final String E_NULL_YANG_TELINK_CONFIG =
154 "YANG telink config object cannot be null";
155 private static final String E_NULL_YANG_TELINK =
156 "YANG Link object cannot be null";
Yixiao Chen39828a62016-09-14 14:37:06 -0400157
158 // no instantiation
159 private LinkConverter() {
160 }
161
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500162 private static LinkProtectionTypeEnum teSubsystem2YangLinkProtectionType(TunnelProtectionType linkProtectionType) {
163 switch (linkProtectionType) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500164 case ENHANCED:
165 return LinkProtectionTypeEnum.ENHANCED;
166 case EXTRA_TRAFFIC:
167 return LinkProtectionTypeEnum.EXTRA_TRAFFIC;
168 case SHARED:
169 return LinkProtectionTypeEnum.SHARED;
170 case UNPROTECTED:
171 return LinkProtectionTypeEnum.UNPROTECTED;
172 case ONE_FOR_ONE:
173 return LinkProtectionTypeEnum.YANGAUTOPREFIX1_FOR_1;
174 case ONE_PLUS_ONE:
175 return LinkProtectionTypeEnum.YANGAUTOPREFIX1_PLUS_1;
176 default:
177 return null;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500178 }
179 }
180 /**
181 * TE Link Config object conversion from TE Topology subsystem to YANG.
182 *
183 * @param teLink TE link object
184 * @return TE Link Config YANG object
185 */
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500186 private static Config teLink2YangConfig(TeLink teLink, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500187 checkNotNull(teLink, E_NULL_TELINK_DATA);
Yixiao Chen39828a62016-09-14 14:37:06 -0400188
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500189 TeLinkAttributesBuilder attrBuilder = DefaultTeLinkAttributes.builder();
190
191 if (teLink.teLinkKey() != null) {
192 // what is link index? for now I used teLinkTpId
193 attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId()));
194 }
195
196 if (teLink.adminStatus() != null) {
197 attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus()));
198 }
199
200 if (teLink.tunnelProtectionType() != null) {
201 attrBuilder = attrBuilder
202 .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500203 .tunnelProtectionType()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500204 }
205
206 attrBuilder = attrBuilder.teDefaultMetric(teLink.cost());
207
208 if (teLink.srlgs() != null) {
209 TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder();
210 for (Long srlgLongVal : teLink.srlgs()) {
211 teSrlgsBuilder = teSrlgsBuilder.addToValue(new Srlg(srlgLongVal));
212 }
213 attrBuilder = attrBuilder.teSrlgs(teSrlgsBuilder.build());
214 }
215 attrBuilder = attrBuilder.isAbstract(teLink.flags().get(TeNode.BIT_ABSTRACT));
216
217 if (teLink.externalLink() != null) {
218 ExternalDomainBuilder edBuilder =
219 DefaultExternalDomain.builder();
220 if (teLink.externalLink().plugId() != null) {
221 edBuilder.plugId(teLink.externalLink().plugId());
222 }
223 if (teLink.externalLink().externalLinkKey() != null) {
224 edBuilder = edBuilder
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500225 .remoteTeLinkTpId(TeTpId.fromString(String.valueOf(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500226 .externalLink()
227 .externalLinkKey()
228 .teLinkTpId())))
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500229 .remoteTeNodeId(TeNodeId.fromString(String.valueOf(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500230 .externalLink()
231 .externalLinkKey()
232 .teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500233 }
234 attrBuilder = attrBuilder.externalDomain(edBuilder.build());
235 }
236
237 if (teLink.availBandwidth() != null) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500238 for (short i = 0; i < teLink.availBandwidth().length; i++) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500239 UnreservedBandwidthBuilder urBuilder =
240 DefaultUnreservedBandwidth.builder()
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500241 .bandwidth(TeBandwidth.fromString(String
242 .valueOf(teLink.availBandwidth()[i])))
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500243 .priority(i);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500244 attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build());
245 }
246 }
247
248 if (teLink.maxBandwidth() != null) {
249 // maxBandwidth is an array of float[], but in yang is just a big decimal
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500250 attrBuilder = attrBuilder.maxLinkBandwidth(TeBandwidth
251 .fromString(String.valueOf(teLink.maxBandwidth()[0])));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500252 }
253 // FIXME: how to retrieve maxResvLinkBandwidth from teLink
254// if (teLink.maxResvLinkBandwidth() != null) {
255// attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth());
256// }
257
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500258 if (teLink.primaryPath() != null || teLink.backupPaths() != null) {
259 UnderlayBuilder builder = DefaultUnderlay.builder();
260 if (teLink.primaryPath() != null) {
261 // TODO: what is underlayProtectionType in tePath?
262 // builder =
263 // builder.underlayProtectionType(tePath.protectionType());
264 builder = te2YangConfigUnderlayPrimaryPath(builder, teLink,
265 teTopologyService);
266 }
267
268 if (teLink.backupPaths() != null) {
269 builder = te2YangConfigUnderlayBackupPaths(builder, teLink,
270 teTopologyService);
271 }
272
273 attrBuilder = attrBuilder.underlay(builder.build());
274 }
275
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500276
277 ConfigBuilder yangConfigBuilder = DefaultConfig.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500278 .teLinkAttributes(attrBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500279 return yangConfigBuilder.build();
280 }
281
282 /**
283 * TE Link State object conversion from TE Topology subsystem to YANG.
284 *
285 * @param teLink TE link object
286 * @return TE Link State YANG object
287 */
288 private static State teLink2YangState(TeLink teLink) {
289 TeLinkAttributes
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500290 .TeLinkAttributesBuilder attrBuilder =
291 DefaultTeLinkAttributes
292 .builder()
293 .teDefaultMetric(teLink.cost())
294 .isAbstract(teLink.flags().get(TeLink.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500295 if (teLink.teLinkKey() != null) {
296 // what is link index? for now I used teLinkTpId
297 attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId()));
298 }
299
300 if (teLink.adminStatus() != null) {
301 attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus()));
302 }
303 if (teLink.tunnelProtectionType() != null) {
304 attrBuilder = attrBuilder
305 .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500306 .tunnelProtectionType()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500307 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500308 if (teLink.maxBandwidth() != null) {
309 // maxBandwidth is an array of float[], but in yang is just a big decimal
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500310 attrBuilder = attrBuilder.maxLinkBandwidth(TeBandwidth
311 .fromString(String.valueOf(teLink.maxBandwidth()[0])));
Hesam Rahimi41208102016-12-09 17:54:03 -0500312 }
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
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500349 .builder()
350 .bandwidth(TeBandwidth.fromString(String.valueOf(f)))
351 .priority(i);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500352 i++;
353 attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build());
354 }
355 }
356
357 StateBuilder yangStateBuilder = DefaultState.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500358 .teLinkAttributes(attrBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500359 if (teLink.opStatus() != null) {
360 yangStateBuilder = yangStateBuilder.operStatus(EnumConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500361 .teSubsystem2YangOperStatus(teLink.opStatus()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500362 }
363
364 if (teLink.sourceTeLinkId() != null) {
365 InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder();
366
367 Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500368 // TODO: pass teTopologyService and retrieve linkRef and NetworkRef from there
369
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500370 issBuilder = issBuilder.topology(topologyBuilder.build());
371 yangStateBuilder.informationSourceState(issBuilder.build());
372 }
373
374 // Once stateDerived underlay is available in yang and core TE Topology
375 // object model, set the value properly
376 // stateDerivedUnderlay = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500377 // .rev20170110.ietftetopology.telinkstatederived.Underlay
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500378 //yangStateBuilder = yangStateBuilder.underlay(stateDerivedUnderlay);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500379
380 return yangStateBuilder.build();
381 }
382
383 /**
384 * Link object conversion from TE Topology subsystem to YANG.
385 *
386 * @param teSubsNetworkLink TE subsystem link object
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500387 * @param teTopologyService TE Topology Service object
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500388 * @return YANG link object
389 */
390 public static Link teSubsystem2YangLink(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500391 org.onosproject.tetopology.management.api.link.NetworkLink teSubsNetworkLink,
392 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500393 checkNotNull(teSubsNetworkLink, E_NULL_TELINK);
394
395 LinkId linkId = LinkId.fromString(teSubsNetworkLink.linkId().toString());
396 LinkBuilder builder = DefaultLink.builder().linkId(linkId);
397 if (teSubsNetworkLink.supportingLinkIds() != null) {
398 List<SupportingLink> slinks = Lists.newArrayList();
399 SupportingLinkBuilder spLinkBuilder = DefaultSupportingLink.builder();
400 for (NetworkLinkKey linkKey : teSubsNetworkLink.supportingLinkIds()) {
401 slinks.add(spLinkBuilder.networkRef(NetworkId.fromString(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500402 linkKey.networkId().toString()))
403 .linkRef(LinkId.fromString(
404 linkKey.linkId().toString()))
405 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500406 }
407 builder = builder.supportingLink(slinks);
408 }
409 if (teSubsNetworkLink.source() != null) {
410 SourceBuilder sourceBuilder = DefaultSource
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500411 .builder()
412 .sourceNode(NodeId.fromString(
413 teSubsNetworkLink.source().nodeId().toString()))
414 .sourceTp(TpId.fromString(
415 teSubsNetworkLink.source().tpId().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500416 builder = builder.source(sourceBuilder.build());
417 }
418 if (teSubsNetworkLink.destination() != null) {
419 DestinationBuilder destBuilder = DefaultDestination
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500420 .builder()
421 .destNode(NodeId.fromString(
422 teSubsNetworkLink.destination().nodeId().toString()))
423 .destTp(TpId.fromString(
424 teSubsNetworkLink.destination().tpId().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500425 builder = builder.destination(destBuilder.build());
426 }
427
428 if (teSubsNetworkLink.teLink() != null) {
429 TeLink teData = teSubsNetworkLink.teLink();
430 TeBuilder yangTeBuilder = DefaultTe.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500431 .config(teLink2YangConfig(teData, teTopologyService))
432 .state(teLink2YangState(teData));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500433 // ignoring supportingTeLinkId when converting from core to yang?
434 // if (teData.supportingTeLinkId() != null) {
435 // }
436 AugmentedNtLinkBuilder linkAugmentBuilder =
437 DefaultAugmentedNtLink.builder()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500438 .te(yangTeBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500439 builder.addYangAugmentedInfo(linkAugmentBuilder.build(), AugmentedNtLink.class);
440 }
441
442 return builder.build();
443 }
444
445 private static UnderlayBuilder te2YangConfigUnderlayPrimaryPath(
446 UnderlayBuilder yangBuilder,
Hesam Rahimi41208102016-12-09 17:54:03 -0500447 TeLink teLink, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500448
449 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath tePath = teLink.primaryPath();
450
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500451 PrimaryPathBuilder pathBuilder = DefaultPrimaryPath.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500452 if (tePath.pathElements() != null) {
453 for (PathElement pathElementTe : tePath.pathElements()) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500454 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
455 .ietftetopology.telinkunderlayattributes.primarypath.PathElement
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500456 .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
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500472 pathBuilder = pathBuilder.networkRef(teTopologyService
473 .networkId(teLink.underlayTeTopologyId()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500474
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500475 return yangBuilder.primaryPath(pathBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500476 }
477
478 private static UnderlayBuilder te2YangConfigUnderlayBackupPaths(UnderlayBuilder yangBuilder,
Hesam Rahimi41208102016-12-09 17:54:03 -0500479 TeLink teLink,
480 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500481 List<UnderlayBackupPath> tePaths = teLink.backupPaths();
482
483 for (UnderlayBackupPath tePath : tePaths) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500484 BackupPathBuilder pathBuilder = DefaultBackupPath
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500485 .builder();
486 pathBuilder = pathBuilder.index(tePath.index());
Hesam Rahimi41208102016-12-09 17:54:03 -0500487
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500488 pathBuilder = pathBuilder.networkRef(teTopologyService
489 .networkId(teLink.underlayTeTopologyId()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500490
491 for (PathElement backupPathElementTe : tePath.pathElements()) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500492 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
493 .ietftetopology.telinkunderlayattributes.backuppath.PathElement
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500494 .PathElementBuilder elementBuilder =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500495 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
496 .ietftetopology.telinkunderlayattributes.backuppath.DefaultPathElement
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500497 .builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500498
499 elementBuilder = elementBuilder.pathElementId(backupPathElementTe.pathElementId());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500500 //TODO: check more types here
501 if (backupPathElementTe.type() instanceof TeLinkId) {
502 UnnumberedLinkBuilder unmBuilder = DefaultUnnumberedLink.builder()
503 .routerId(IpAddress.fromString(
504 Ip4Address.valueOf((int) backupPathElementTe.teNodeId()).toString()))
505 .interfaceId(((TeLinkId) backupPathElementTe.type()).value());
506 elementBuilder = elementBuilder.type(unmBuilder.build());
507 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500508
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500509 pathBuilder = pathBuilder.addToPathElement(elementBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500510 }
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500511 yangBuilder = yangBuilder.addToBackupPath(pathBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500512 }
513
514 return yangBuilder;
515 }
516
517 private static TeLink yang2TeLinkAttributes(TeLinkAttributes yangLinkAttr,
518 State opState, Link yangLink,
519 Network yangNetwork,
520 Networks yangNetworks) {
521 TeNodeId teNodeId = findTeNodeId(yangNetwork,
Hesam Rahimi41208102016-12-09 17:54:03 -0500522 yangLink.source().sourceNode());
523 long teNodeIdLong = -1;
524 if (teNodeId != null && teNodeId.dottedQuad() != null) {
525 teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string())
526 .toInt();
527 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500528
529 TeLinkTpKey teLinkKey = new TeLinkTpKey(teNodeIdLong,
530 findTeTpId(yangNetwork,
531 yangLink.source().sourceNode(),
532 yangLink.source().sourceTp()));
533
Hesam Rahimi41208102016-12-09 17:54:03 -0500534 TeNodeId teNodeIdDest = null;
535 if (yangLink.destination() != null) {
536 teNodeIdDest = findTeNodeId(yangNetwork,
537 yangLink.destination().destNode());
538 }
539 long teNodeIdDestLong = -1;
540 if (teNodeIdDest != null && teNodeIdDest.dottedQuad() != null) {
541 teNodeIdDestLong = Ip4Address.valueOf(teNodeIdDest.dottedQuad().string()).toInt();
542 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500543
Hesam Rahimi41208102016-12-09 17:54:03 -0500544 TeLinkTpKey peerTeLinkKey = null;
545 if (yangLink.destination() != null) {
546 peerTeLinkKey = new TeLinkTpKey(teNodeIdDestLong,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500547 findTeTpId(yangNetwork,
548 yangLink.destination().destNode(),
549 yangLink.destination().destTp()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500550 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500551
552 TeLinkTpGlobalKey supportTeLinkId = findSupportTeLinkId(yangNetworks, yangLink);
553
554 org.onosproject.tetopology.management.api.TeStatus opStatus = null;
555 if (opState != null && opState.operStatus() != null) {
556 opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState.operStatus());
557 }
558
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500559 TeTopologyKey underlayTopologyId = null;
560 if (yangLinkAttr != null && yangLinkAttr.underlay() != null && yangLinkAttr.underlay().primaryPath() != null) {
561 underlayTopologyId = findTopologyId(yangNetworks, yangLinkAttr.underlay().primaryPath().networkRef());
562 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500563
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500564 TeLink teLink = yangLinkAttr2TeLinkAttributes(yangLinkAttr, opStatus,
565 teNodeIdLong,
566 teNodeIdDestLong,
567 teLinkKey,
568 peerTeLinkKey,
569 supportTeLinkId,
570 underlayTopologyId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500571
572 return teLink;
573 }
574
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500575 /**
576 * Finds the TE TopologyKey from yangNetworks and a networkRef.
577 *
578 * @param yangNetworks YANG networks object
579 * @param networkRef YANG network reference
580 * @return TeTopologyKey the TE TopologyKey
581 */
582 public static TeTopologyKey findTopologyId(Networks yangNetworks, Object networkRef) {
583 // TODO: add implementation
584 return null;
585 }
586
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500587 private static TeLink yangLinkAttr2TeLinkAttributes(TeLinkAttributes yangLinkAtrr,
588 org.onosproject.tetopology.management.api.TeStatus opStatus,
589 long teNodeIdLong,
590 long teNodeIdDestLong,
591 TeLinkTpKey teLinkKey,
592 TeLinkTpKey peerTeLinkKey,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500593 TeLinkTpGlobalKey supportTeLinkId,
594 TeTopologyKey underlayTopologyId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500595 org.onosproject.tetopology.management.api.TeStatus adminStatus = null;
596
597 TeLinkTpGlobalKey sourceTeLinkId = null; // from yang to core, we can ignore sourceTeLinkId
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500598
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500599 CommonLinkData teData = null;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500600
601 if (yangLinkAtrr.adminStatus() != null) {
602 adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangLinkAtrr.adminStatus());
603 }
604
605 BitSet flags = new BitSet();
606 if (yangLinkAtrr.isAbstract()) {
607 flags.set(TeLink.BIT_ABSTRACT);
608 }
609
Hesam Rahimi41208102016-12-09 17:54:03 -0500610 ExternalLink externalLink = null;
611 if (yangLinkAtrr != null && yangLinkAtrr.externalDomain() != null) {
612 externalLink = new ExternalLink(null, yangLinkAtrr.externalDomain().plugId());
613 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500614
615 UnderlayPath underlayPath = null;
616 underlayPath = yang2TeSubsystemUnderlayPath(yangLinkAtrr, teNodeIdLong,
617 teNodeIdDestLong);
Hesam Rahimi41208102016-12-09 17:54:03 -0500618 Long adminGroup = null;
619 if (yangLinkAtrr != null && yangLinkAtrr.administrativeGroup() != null) {
620 adminGroup = Long.valueOf(yangLinkAtrr.administrativeGroup().toString());
621 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500622 List<Long> interLayerLocks = null; // FIXME: how to find interLayerLocks?
623
624 List<UnreservedBandwidth> listOfUnreservedBandwidth = yangLinkAtrr.unreservedBandwidth();
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500625 float[] availBandwidth = new float[MAX_PRIORITY + 1];
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500626 for (UnreservedBandwidth urbw : listOfUnreservedBandwidth) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500627 availBandwidth[urbw.priority()] = Float.valueOf(urbw.bandwidth().string());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500628 }
629
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500630 float[] maxBandwidth = new float[MAX_PRIORITY + 1];
Hesam Rahimi41208102016-12-09 17:54:03 -0500631 if (yangLinkAtrr.maxLinkBandwidth() != null) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500632 // Core TE has an array, but YANG is an integer
633 for (short p = 0; p <= MAX_PRIORITY; p++) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500634 maxBandwidth[p] = Float.valueOf(yangLinkAtrr.maxLinkBandwidth().string());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500635 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500636 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500637
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500638 float[] maxAvailLspBandwidth = availBandwidth; // FIXME: how to find this?
639 float[] minAvailLspBandwidth = availBandwidth; // FIXME: how to find this?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500640 LinkBandwidth bandwidth = new LinkBandwidth(
641 maxBandwidth,
642 availBandwidth,
643 maxAvailLspBandwidth,
644 minAvailLspBandwidth,
645 null); // FIXME: how to find odu resource?
646 List<Long> srlgs = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500647 if (yangLinkAtrr.teSrlgs() != null
648 && yangLinkAtrr.teSrlgs().value() != null
649 && !yangLinkAtrr.teSrlgs().value().isEmpty()) {
650 for (Srlg srlg : yangLinkAtrr.teSrlgs().value()) {
651 srlgs.add(srlg.uint32());
652 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500653 }
654 TePathAttributes teAttributes =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500655 new TePathAttributes(yangLinkAtrr.teDefaultMetric(), yangLinkAtrr.teDelayMetric(),
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500656 srlgs);
657 teData = new CommonLinkData(adminStatus,
658 opStatus,
659 flags,
660 null, // switchingLayer
661 null, // encodingLayer
662 externalLink,
663 underlayPath,
664 teAttributes,
665 adminGroup,
666 interLayerLocks,
667 bandwidth);
668
669 TeLink te = new DefaultTeLink(teLinkKey, peerTeLinkKey,
670 underlayTopologyId, supportTeLinkId,
671 sourceTeLinkId, teData);
672 return te;
673 }
674
675 private static TeLinkTpGlobalKey findSupportTeLinkId(Networks yangNetworks,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500676 Link yangLink) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500677 Network teNetworkFound = null;
678 LinkId teLinkIdFound = null;
Hesam Rahimi41208102016-12-09 17:54:03 -0500679 TeLinkTpGlobalKey supportTeLinkId = null;
680
681 if (yangLink != null && yangLink.supportingLink() != null && !yangLink.supportingLink().isEmpty()) {
682 if (yangNetworks.network() != null && !yangNetworks.network().isEmpty()) {
683 for (Network ynetItem : yangNetworks.network()) {
684 if (ynetItem.networkId() != null) {
685 if (ynetItem.networkId().equals(yangLink.supportingLink().get(0).networkRef())) {
686 teNetworkFound = ynetItem;
687 teLinkIdFound = yangLink.supportingLink().get(0).linkRef();
688 break;
689 }
690 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500691 }
692 }
Hesam Rahimi41208102016-12-09 17:54:03 -0500693 Link teLinkFound = null;
694 if (teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class) != null) {
695 AugmentedNdNetwork augmentLink =
696 (AugmentedNdNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class);
697 for (Link link : augmentLink.link()) {
698 if (link.linkId().equals(teLinkIdFound)) {
699 teLinkFound = link;
700 break;
701 }
702 }
703 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500704
Hesam Rahimi41208102016-12-09 17:54:03 -0500705 TeNodeId teSupportNodeId = findTeNodeId(teNetworkFound,
706 teLinkFound.source().sourceNode());
707 long tenIdLong = -1;
708 if (teSupportNodeId != null) {
709 tenIdLong = Ip4Address.valueOf(teSupportNodeId.dottedQuad().string()).toInt();
710 }
711 long teSupportLinkTpId = findTeTpId(teNetworkFound,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500712 teLinkFound.source().sourceNode(),
713 teLinkFound.source().sourceTp());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500714
Hesam Rahimi41208102016-12-09 17:54:03 -0500715 org.onosproject.tetopology.management.api.TeTopologyId teTopologyId = null;
716 if (teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class) != null) {
717 AugmentedNwNetwork augmentTeIds =
718 (AugmentedNwNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class);
719 teTopologyId =
720 new org.onosproject.tetopology.management.api.TeTopologyId(
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500721 augmentTeIds.clientId().uint32(),
722 augmentTeIds.providerId().uint32(),
723 augmentTeIds.teTopologyId().string());
Hesam Rahimi41208102016-12-09 17:54:03 -0500724 }
725
726 supportTeLinkId = new TeLinkTpGlobalKey(teTopologyId.providerId(),
727 teTopologyId.clientId(),
728 Long.valueOf(teTopologyId
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500729 .topologyId()),
Hesam Rahimi41208102016-12-09 17:54:03 -0500730 tenIdLong, teSupportLinkTpId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500731 }
732
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500733 return supportTeLinkId;
734 }
735
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500736 /**
737 * Finds TeNodeId from a yangNetwork and yangNodeId.
738 *
739 * @param yangNetwork YANG network object
740 * @param yangNodeId YANG node Id
741 * @return teNodeId teNodeId
742 */
743 public static TeNodeId findTeNodeId(Network yangNetwork, NodeId yangNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500744 TeNodeId teNodeId = null;
745 for (Node node : yangNetwork.node()) {
746 if (node.nodeId().equals(yangNodeId)) {
747 if (node.yangAugmentedInfoMap() != null
748 && !node.yangAugmentedInfoMap().isEmpty()) {
749 AugmentedNwNode yangNodeAugment = (AugmentedNwNode) node
750 .yangAugmentedInfo(AugmentedNwNode.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500751 if (yangNodeAugment != null
752 && yangNodeAugment.teNodeId() != null) {
753 teNodeId = yangNodeAugment.teNodeId();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500754 }
755 }
756 }
757 }
758 return teNodeId;
759 }
760
761 private static long findTeTpId(Network yangNetwork, NodeId yangNodeId, TpId yangTpId) {
762 long teTpId = 0;
763 for (Node node : yangNetwork.node()) {
764 if (node.nodeId().equals(yangNodeId)) {
765 if (node.yangAugmentedInfoMap() != null
766 && !node.yangAugmentedInfoMap().isEmpty()) {
767
768 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) node
769 .yangAugmentedInfo(AugmentedNdNode.class);
770 if (yangTpNodeAugment.terminationPoint() != null) {
771 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
772 .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
773 yangTpnode : yangTpNodeAugment.terminationPoint()) {
774 if (yangTpnode.tpId().equals(yangTpId)) {
775 if (yangTpnode.yangAugmentedInfoMap() != null
776 && !yangTpnode.yangAugmentedInfoMap()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500777 .isEmpty()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500778 AugmentedNtTerminationPoint yangTpAugment =
779 (AugmentedNtTerminationPoint) yangTpnode
780 .yangAugmentedInfo(AugmentedNtTerminationPoint.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500781 if (yangTpAugment.teTpId() != null) {
782 teTpId = Long.valueOf(yangTpAugment.teTpId().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500783 }
784 }
785 }
786 }
787 }
788 }
789 }
790 }
791 return teTpId;
792 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400793 /**
794 * Link object conversion from YANG to TE Topology subsystem.
795 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500796 * @param yangLink YANG link
797 * @param yangNetwork YANG network
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500798 * @param yangNetworks YANG networks
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500799 * @return TE subsystem link
Yixiao Chen39828a62016-09-14 14:37:06 -0400800 */
801 public static org.onosproject.tetopology.management.api.link.NetworkLink
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500802 yang2TeSubsystemLink(Link yangLink, Network yangNetwork,
803 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500804 NetworkId networkId = yangNetwork.networkId();
805 checkNotNull(yangLink, E_NULL_YANG_TELINK);
Yixiao Chen39828a62016-09-14 14:37:06 -0400806
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500807 KeyId linkId = KeyId.keyId(yangLink.linkId().uri().toString());
808 NodeTpKey sourceNodeTpKey = null;
809 NodeTpKey destinationNodeTpKey = null;
810 List<NetworkLinkKey> spLinkIds = null;
811 TeLink te = null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400812
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500813 if (yangLink.supportingLink() != null) {
814 spLinkIds = Lists.newArrayList();
815 for (SupportingLink yangSpLink : yangLink.supportingLink()) {
816 NetworkLinkKey linkKey = new NetworkLinkKey(KeyId.keyId(yangSpLink.networkRef().uri().toString()),
817 KeyId.keyId(yangSpLink.linkRef().uri().toString()));
818 spLinkIds.add(linkKey);
819 }
820 }
821
822 if (yangLink.source() != null) {
823 TerminationPointKey source = new TerminationPointKey(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500824 KeyId.keyId(networkId.uri().toString()),
825 KeyId.keyId(yangLink.source().sourceNode().uri().toString()),
826 KeyId.keyId(yangLink.source().sourceTp().uri().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500827 sourceNodeTpKey = new NodeTpKey(source.nodeId(), source.tpId());
828 }
829
830 if (yangLink.destination() != null) {
831 TerminationPointKey destination = new TerminationPointKey(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500832 KeyId.keyId(networkId.uri().toString()),
833 KeyId.keyId(yangLink.destination().destNode().uri().toString()),
834 KeyId.keyId(yangLink.destination().destTp().uri().toString()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500835 destinationNodeTpKey = new NodeTpKey(destination.nodeId(), destination.tpId());
836 }
837
838 if (yangLink.yangAugmentedInfoMap() != null && !yangLink.yangAugmentedInfoMap().isEmpty()) {
839
840 AugmentedNtLink yangLinkAugment =
841 (AugmentedNtLink) yangLink.yangAugmentedInfo(AugmentedNtLink.class);
842 if (yangLinkAugment != null &&
843 yangLinkAugment.te() != null &&
844 yangLinkAugment.te().config() != null) {
845 TeLinkAttributes yangLinkAtrr =
846 yangLinkAugment.te().config().teLinkAttributes();
847 if (yangLinkAtrr != null && yangLinkAtrr.linkIndex() != null) {
848 te = yang2TeLinkAttributes(yangLinkAtrr,
849 yangLinkAugment.te().state(),
850 yangLink, yangNetwork,
851 yangNetworks);
852 }
853 }
854 }
855
856 org.onosproject.tetopology.management.api.link.DefaultNetworkLink link =
857 new DefaultNetworkLink(linkId,
858 sourceNodeTpKey,
859 destinationNodeTpKey,
860 spLinkIds,
861 te);
862 return link;
Yixiao Chen39828a62016-09-14 14:37:06 -0400863 }
864
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500865 private static org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500866 yang2TeSubsystemUnderlayPrimaryPath(PrimaryPath yangpath,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500867 long teNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500868 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath teUnderlayPrimaryPath = null;
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500869
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500870 List<PathElement> pathElementList = Lists.newArrayList();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500871 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
872 .telinkunderlayattributes.primarypath.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500873 PathElement pathElementYang : yangpath.pathElement()) {
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500874
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500875 long nodeId = 0;
876 ElementType type = null;
877 // TODO: check more types
878 if (pathElementYang.type() instanceof UnnumberedLink) {
879 nodeId = Long.valueOf(((UnnumberedLink) pathElementYang.type()).routerId().toString());
880 type = new TeLinkId(((UnnumberedLink) pathElementYang.type()).interfaceId());
881 }
882 PathElement tePathElement = new PathElement(pathElementYang.pathElementId(),
883 nodeId,
884 type,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500885 false); // FIXME: how to find the proper value for loose?
886 pathElementList.add(tePathElement);
887 }
888
889 teUnderlayPrimaryPath = new org.onosproject.tetopology.management.api.link.
890 UnderlayPrimaryPath(pathElementList, false); // FIXME: how to find the proper value for loose?
891
892 return teUnderlayPrimaryPath;
893 }
894
895 private static List<UnderlayBackupPath>
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500896 yang2TeSubsystemUnderlayBackupPaths(
897 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500898 rev20170110.ietftetopology.telinkunderlayattributes.
899 BackupPath> yangpaths,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500900 long teNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500901
902 List<UnderlayBackupPath> underlayBackupPathsList = Lists.newArrayList();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500903 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500904 .ietftetopology.telinkunderlayattributes.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500905 BackupPath yangConfig : yangpaths) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500906 UnderlayBackupPath ubp = null;
907 List<PathElement> backupPathElementList = Lists.newArrayList();
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500908 long nodeId = 0;
909 ElementType type = null;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500910 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
911 .telinkunderlayattributes.backuppath.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500912 PathElement backupYang : yangConfig.pathElement()) {
913 // TODO: check more types
914 if (backupYang.type() instanceof UnnumberedLink) {
915 nodeId = Long.valueOf(((UnnumberedLink) backupYang.type()).routerId().toString());
916 type = new TeLinkId(((UnnumberedLink) backupYang.type()).interfaceId());
917 }
918 PathElement tePathElementBackup = new PathElement(backupYang.pathElementId(),
919 nodeId,
920 type,
921 false);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500922 backupPathElementList.add(tePathElementBackup);
923 }
924 ubp = new UnderlayBackupPath(yangConfig.index(),
925 backupPathElementList,
926 null); // FIXME: find the proper value for loose
927 underlayBackupPathsList.add(ubp);
928 }
929
930 return underlayBackupPathsList;
931 }
932
933 /**
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500934 * TE Link underlay path Config object conversion from YANG to TE Topology subsystem.
935 *
936 * @param yangLinkAtrr YANG link Config YANG object
937 * @return teSubsystem TE underlay path object
938 */
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500939 private static org.onosproject.tetopology.management.api.link.UnderlayPath
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500940 yang2TeSubsystemUnderlayPath(TeLinkAttributes yangLinkAtrr, long srcTeNodeId, long dstTeNodeId) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500941
942 checkNotNull(yangLinkAtrr, E_NULL_YANG_TELINK_CONFIG);
943
944 org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath underlayPrimaryPath = null;
945 List<UnderlayBackupPath> underlayBackupPathsList = null;
946 TeTunnelId teTunnelId = new TeTunnelId(srcTeNodeId, dstTeNodeId, 0); // FIXME: how to find teTunnelId?
947
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500948 if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().primaryPath() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500949 underlayPrimaryPath =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500950 yang2TeSubsystemUnderlayPrimaryPath(yangLinkAtrr.underlay().primaryPath(), srcTeNodeId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500951 }
952
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500953 if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().backupPath() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500954 underlayBackupPathsList =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500955 yang2TeSubsystemUnderlayBackupPaths(yangLinkAtrr.underlay().backupPath(), srcTeNodeId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500956 }
957
Hesam Rahimi41208102016-12-09 17:54:03 -0500958 org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay = null;
959 if (yangLinkAtrr.underlay() != null) {
960 teUnderlay = new org.onosproject.tetopology.management.api.link.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500961 UnderlayPath(underlayPrimaryPath,
962 underlayBackupPathsList,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500963 TunnelProtectionType.of(yangLinkAtrr.underlay().protectionType()),
964 (Long) yangLinkAtrr.underlay().tunnelSrc().tunnelTpRef(), // null safe?
965 (Long) yangLinkAtrr.underlay().tunnelDes().tunnelTpRef(), // null safe?
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500966 teTunnelId);
Hesam Rahimi41208102016-12-09 17:54:03 -0500967 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500968
969 return teUnderlay;
970 }
971
972 /**
973 * Converts a TE Topology link event from the data format used in
974 * the core to its corresponding YANG Object (YO) format.
975 *
976 * @param eventType Link event type
977 * @param linkData TE Topology link event data
978 * @return YANG Object converted from linkData
979 */
980 public static TeLinkEvent teNetworkLink2yangTeLinkEvent(TeTopologyEventTypeEnum eventType,
Hesam Rahimi41208102016-12-09 17:54:03 -0500981 NetworkLinkEventSubject linkData) {
Henry Yu8ac364b2016-12-15 18:24:20 -0500982 TeLinkEvent.TeLinkEventBuilder teLinkEventBuilder = new DefaultTeLinkEvent.TeLinkEventBuilder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500983
984 TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
Henry Yu8ac364b2016-12-15 18:24:20 -0500985 teLinkEventBuilder.eventType(yangEventType);
986 NetworkId networkId = NetworkId.fromString(linkData.key().networkId().toString());
987 teLinkEventBuilder.networkRef(networkId);
Hesam Rahimi41208102016-12-09 17:54:03 -0500988 LinkId linkId = LinkId.fromString(linkData.key().linkId().toString());
Henry Yu8ac364b2016-12-15 18:24:20 -0500989 teLinkEventBuilder.linkRef(linkId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500990
Henry Yu8ac364b2016-12-15 18:24:20 -0500991 if (linkData != null && linkData.networkLink() != null) {
992 NetworkLink link = linkData.networkLink();
993 State yangTeLinkState = teLink2YangState(link.teLink());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500994
Henry Yu8ac364b2016-12-15 18:24:20 -0500995 teLinkEventBuilder.operStatus(yangTeLinkState.operStatus());
996 teLinkEventBuilder.informationSource(yangTeLinkState.informationSource());
997 teLinkEventBuilder.informationSourceEntry(yangTeLinkState.informationSourceEntry());
998 teLinkEventBuilder.informationSourceState(yangTeLinkState.informationSourceState());
999 teLinkEventBuilder.isTransitional(yangTeLinkState.isTransitional());
1000 teLinkEventBuilder.recovery(yangTeLinkState.recovery());
1001 teLinkEventBuilder.teLinkAttributes(yangTeLinkState.teLinkAttributes());
1002 teLinkEventBuilder.underlay(yangTeLinkState.underlay());
1003 }
1004
1005 return teLinkEventBuilder.build();
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001006 }
1007
Henry Yu05dcc212017-01-05 16:05:26 -05001008 /**
1009 * Retrieves the TE network link key from a given YANG network link
1010 * notification event.
1011 *
1012 * @param yangLinkEvent YANG network link notification
1013 * @return TE network link key
1014 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001015 public static NetworkLinkKey yangLinkEvent2NetworkLinkKey(TeLinkEvent yangLinkEvent) {
Hesam Rahimi41208102016-12-09 17:54:03 -05001016 NetworkId networkRef = NetworkId.fromString(yangLinkEvent.networkRef().toString());
1017 LinkId linkRef = LinkId.fromString(yangLinkEvent.linkRef().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001018 KeyId networkId = KeyId.keyId(networkRef.uri().toString());
1019 KeyId linkId = KeyId.keyId(linkRef.uri().toString());
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001020
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001021 NetworkLinkKey networkLinkKey = new NetworkLinkKey(networkId, linkId);
1022
1023 return networkLinkKey;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001024
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001025 }
1026
Henry Yu05dcc212017-01-05 16:05:26 -05001027 /**
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001028 * Converts a YANG network link notification event into a TE network link.
Henry Yu05dcc212017-01-05 16:05:26 -05001029 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001030 * @param yangLinkEvent YANG network link notification
Henry Yu05dcc212017-01-05 16:05:26 -05001031 * @param teTopologyService TE Topology service used to help the conversion
1032 * @return TE network link
1033 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001034 public static NetworkLink yangLinkEvent2NetworkLink(TeLinkEvent yangLinkEvent,
1035 TeTopologyService teTopologyService) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001036
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001037 KeyId linkId = yangLinkEvent2NetworkLinkKey(yangLinkEvent).linkId();
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001038
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001039 org.onosproject.tetopology.management.api.
1040 Network network = teTopologyService.network(
1041 yangLinkEvent2NetworkLinkKey(yangLinkEvent).networkId());
1042 if (network == null) {
1043 return null;
1044 }
1045
1046 NetworkLink networkLink = network.link(linkId);
1047 if (networkLink == null) {
1048 return null;
1049 }
1050
1051 NodeTpKey sourceTp = networkLink.source();
Henry Yu8ac364b2016-12-15 18:24:20 -05001052 if (sourceTp == null) {
1053 return null;
1054 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001055 NodeTpKey destTp = networkLink.destination();
1056
1057 List<NetworkLinkKey> supportingLinkIds = networkLink.supportingLinkIds();
1058 TeLink teLink = networkLink.teLink();
1059 if (teLink == null) {
1060 return null;
1061 }
1062
1063 TeOperStatus opState = yangLinkEvent.operStatus();
1064 org.onosproject.tetopology.management.api.
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001065 TeStatus opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState);
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001066
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001067 TeLink updatedTeLink = yangLinkEvent2TeLinkAttributes(yangLinkEvent,
1068 teLink, opStatus, teTopologyService);
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001069
1070
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001071 NetworkLink updatedNetworkLink = new DefaultNetworkLink(linkId, sourceTp, destTp, supportingLinkIds,
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001072 updatedTeLink);
1073
1074 return updatedNetworkLink;
1075 }
1076
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001077 private static TeLink yangLinkEvent2TeLinkAttributes(TeLinkEvent yangLinkEvent, TeLink oldTeLink, TeStatus
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001078 opStatus, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001079
1080 TeLinkAttributes yangTeLinkAttrs = yangLinkEvent.teLinkAttributes();
1081
1082 TeLinkTpKey teLinkKey = oldTeLink.teLinkKey();
1083
Henry Yu8ac364b2016-12-15 18:24:20 -05001084 long teNodeIdDest = 0;
1085 long teNodeIdSrc = 0;
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001086
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001087 TeLinkTpGlobalKey supportTeLinkId = oldTeLink.supportingTeLinkId();
1088 TeLinkTpKey peerTeLinkKey = oldTeLink.peerTeLinkKey();
1089
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001090 TeTopologyKey underlayTopologyId = null;
1091 // TODO: add code to retrieve underlayTopologyId
1092
Henry Yu8ac364b2016-12-15 18:24:20 -05001093 TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeIdSrc, teNodeIdDest,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001094 teLinkKey,
1095 peerTeLinkKey,
1096 supportTeLinkId,
1097 underlayTopologyId);
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001098
1099 return updatedTeLink;
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001100 }
Yixiao Chen39828a62016-09-14 14:37:06 -04001101}