blob: 1557d7d6139390f9a9ebbfc5cb714959ebabc150 [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;
19
20import java.util.BitSet;
21import java.util.List;
22import java.util.Map;
23
Hesam Rahimi41208102016-12-09 17:54:03 -050024import org.apache.commons.collections.MapUtils;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050025import org.onlab.packet.Ip4Address;
26import org.onosproject.tetopology.management.api.EncodingType;
27import org.onosproject.tetopology.management.api.KeyId;
28import org.onosproject.tetopology.management.api.SwitchingType;
29import org.onosproject.tetopology.management.api.TeStatus;
30import org.onosproject.tetopology.management.api.TeTopologyKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050031import org.onosproject.tetopology.management.api.TeTopologyService;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050032import org.onosproject.tetopology.management.api.link.ElementType;
Hesam Rahimi41208102016-12-09 17:54:03 -050033import org.onosproject.tetopology.management.api.link.NetworkLink;
34import org.onosproject.tetopology.management.api.link.NetworkLinkKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050035import org.onosproject.tetopology.management.api.link.TeLinkId;
Hesam Rahimi41208102016-12-09 17:54:03 -050036import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050037import org.onosproject.tetopology.management.api.link.TePathAttributes;
38import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath;
39import org.onosproject.tetopology.management.api.node.CommonNodeData;
40import org.onosproject.tetopology.management.api.node.ConnectivityMatrix;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050041import org.onosproject.tetopology.management.api.node.DefaultNetworkNode;
42import org.onosproject.tetopology.management.api.node.DefaultTeNode;
43import org.onosproject.tetopology.management.api.node.LocalLinkConnectivity;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050044import org.onosproject.tetopology.management.api.node.NetworkNode;
Hesam Rahimi41208102016-12-09 17:54:03 -050045import org.onosproject.tetopology.management.api.node.NetworkNodeEventSubject;
Yixiao Chen39828a62016-09-14 14:37:06 -040046import org.onosproject.tetopology.management.api.node.NetworkNodeKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050047import org.onosproject.tetopology.management.api.node.TeNode;
48import org.onosproject.tetopology.management.api.node.TeNodeKey;
49import org.onosproject.tetopology.management.api.node.TerminationPoint;
50import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName;
Yixiao Chen39828a62016-09-14 14:37:06 -040051import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050052import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
53import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050054import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
55 .ietfnetwork.networks.network.DefaultNode;
56import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
57 .ietfnetwork.networks.network.Node;
58import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
59 .ietfnetwork.networks.network.node.DefaultSupportingNode;
60import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
61 .ietfnetwork.networks.network.node.SupportingNode;
62import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.TpId;
63import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
64 .ietfnetworktopology.networks.network.node.AugmentedNdNode;
65import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
66 .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode;
67import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.DefaultTeNodeEvent;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050068import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeNodeEvent;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050069import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState;
70import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.InformationSourceState;
71import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.DefaultTopology;
72import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.Topology;
73import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
74 .ietftetopology.networks.network.node.AugmentedNwNode;
75import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
76 .ietftetopology.networks.network.node.DefaultAugmentedNwNode;
77import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
78import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe;
79import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe.TeBuilder;
80import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.Te;
81import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.Config;
82import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultConfig;
83import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultState;
84import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint;
85import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.State;
86import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.TunnelTerminationPoint;
87import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes;
88import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes;
89import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes.TeNodeAttributesBuilder;
90import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix;
91import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix.ConnectivityMatrixBuilder;
92import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultFrom;
93import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultTo;
94import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology;
95import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.UnderlayTopology;
96import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.DefaultTerminationCapability;
97import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.TerminationCapability;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050098import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg;
99import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus;
100import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500101import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500102import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyId;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500103import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.tetopologyeventtype.TeTopologyEventTypeEnum;
Hesam Rahimi41208102016-12-09 17:54:03 -0500104import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.ietfyangtypes.DottedQuad;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500105
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500106import com.google.common.collect.Lists;
107import com.google.common.collect.Maps;
Yixiao Chen39828a62016-09-14 14:37:06 -0400108
109/**
110 * Node conversion functions.
111 */
112public final class NodeConverter {
113
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500114 private static final String E_NULL_TE_SUBSYSTEM_TE_NODE =
115 "TeSubsystem teNode object cannot be null";
116 private static final String E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP =
117 "TeSubsystem teTunnelTp object cannot be null";
118 private static final String E_NULL_TE_SUBSYSTEM_NODE =
119 "TeSubsystem ndoe object cannot be null";
120 private static final String E_NULL_YANG_NODE =
121 "Yang node object cannot be null";
Yixiao Chen39828a62016-09-14 14:37:06 -0400122
123 // no instantiation
124 private NodeConverter() {
125 }
126
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500127 /**
128 * TE Node Config object conversion from TE Topology subsystem to YANG.
129 *
130 * @param teSubsystemTeNode TE node object
Hesam Rahimi41208102016-12-09 17:54:03 -0500131 * @param teTopologyService teTopolog core service
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500132 * @return TE Node Config YANG object
133 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500134 private static Config teNode2YangConfig(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500135 checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE);
136
137 TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesConfigBuilder = DefaultTeNodeAttributes
138 .builder();
139 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
140 .isAbstract(teSubsystemTeNode.flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500141 .get(TeNode.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500142
143 if (teSubsystemTeNode.adminStatus() != null) {
144 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
145 .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus()));
146 }
147
148 if (teSubsystemTeNode.name() != null) {
149 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
150 .name(DomainName.fromString(teSubsystemTeNode.name()));
151 }
152
153 if (teSubsystemTeNode.underlayTeTopologyId() != null) {
154 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
155 .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500156 .underlayTeTopologyId(), teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500157 }
158
159 // TODO: should we ignore this from te to yang? as we've already set yang supportingNode
Ray Milkey8cd9a662016-11-30 16:55:40 -0800160 //if (teSubsystemTeNode.supportingTeNodeId() != null) {
161 //}
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500162
163 if (teSubsystemTeNode.connectivityMatrices() != null) {
164 teNodeAttributesConfigBuilder = te2YangConnectivityMatrix(teNodeAttributesConfigBuilder,
165 teSubsystemTeNode.connectivityMatrices());
166 }
167
168
169 Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder();
170 yangConfigBuilder = yangConfigBuilder.teNodeAttributes(teNodeAttributesConfigBuilder.build());
171
172 return yangConfigBuilder.build();
173 }
174
175 private static TeNodeAttributesBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500176 te2YangConnectivityMatrix(TeNodeAttributesBuilder teNodeAttributesConfigBuilder,
177 Map<Long, ConnectivityMatrix> connectivityMatrices) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500178 ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = DefaultConnectivityMatrix.builder();
179 for (Map.Entry<Long, ConnectivityMatrix> teCmEntry :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500180 connectivityMatrices.entrySet()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500181 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
182 .id(teCmEntry.getKey())
183 .isAllowed(!teCmEntry.getValue().flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500184 .get(ConnectivityMatrix.BIT_DISALLOWED))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500185 .from(new DefaultFrom.FromBuilder() // TODO: for now, assuming that there is
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500186 // only one 'from', and mergingList is empty
187 .tpRef(((TeLinkId) teCmEntry.getValue().from()).value())
188 .build())
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500189 .to(new DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500190 // one item in constrainingElements list
191 .tpRef(((TeLinkId) teCmEntry.getValue().constrainingElements().get(0)).value())
192 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500193 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
194 .addToConnectivityMatrix(connectivityMatrixConfigBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500195 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500196 }
197 return teNodeAttributesConfigBuilder;
198 }
199
Hesam Rahimi41208102016-12-09 17:54:03 -0500200 private static UnderlayTopology teNode2YangUnderlay(TeTopologyKey underlayTopology,
201 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500202 UnderlayTopology.UnderlayTopologyBuilder underlayBuilder = DefaultUnderlayTopology
203 .builder()
204 .teTopologyIdRef(TeTopologyId
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500205 .fromString(String.valueOf(underlayTopology.topologyId())))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500206 .clientIdRef(underlayTopology.clientId())
207 .providerIdRef(underlayTopology.providerId());
Hesam Rahimi41208102016-12-09 17:54:03 -0500208
209 underlayBuilder = underlayBuilder.networkIdRef(teTopologyService.networkId(underlayTopology));
210
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500211 return underlayBuilder.build();
212 }
213
214 /**
215 * TE Node State object conversion from TE Topology subsystem to YANG.
216 *
217 * @param teSubsystemTeNode TE node object
Hesam Rahimi41208102016-12-09 17:54:03 -0500218 * @param teTopologyService teTopology core service
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500219 * @return TE Node State YANG object
220 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500221 private static State teNode2YangState(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500222 checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE);
223
224 TeNodeAttributes
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500225 .TeNodeAttributesBuilder teNodeAttributesStateBuilder =
226 DefaultTeNodeAttributes.builder()
227 .isAbstract(teSubsystemTeNode.flags()
228 .get(TeNode.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500229
230 if (teSubsystemTeNode.adminStatus() != null) {
231 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
232 .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus()));
233 }
234
235 if (teSubsystemTeNode.name() != null) {
236 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
237 .name(DomainName.fromString(teSubsystemTeNode.name()));
238 }
239
240 if (teSubsystemTeNode.underlayTeTopologyId() != null) {
241 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
242 .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500243 .underlayTeTopologyId(), teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500244 }
245
246 if (teSubsystemTeNode.connectivityMatrices() != null) {
247 teNodeAttributesStateBuilder = te2YangConnectivityMatrix(teNodeAttributesStateBuilder,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500248 teSubsystemTeNode.connectivityMatrices());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500249 }
250
251 // TODO: should we ignore this from te to yang? as we've already set yang supportingNode
Ray Milkey8cd9a662016-11-30 16:55:40 -0800252 //if (teSubsystemTeNode.supportingTeNodeId() != null) {
253 //}
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500254
255 State.StateBuilder yangStateBuilder = DefaultState.builder();
256 yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build());
257
258 if (teSubsystemTeNode.opStatus() != null) {
259 yangStateBuilder = yangStateBuilder.operStatus(EnumConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500260 .teSubsystem2YangOperStatus(teSubsystemTeNode.opStatus()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500261 }
262
263 if (teSubsystemTeNode.sourceTeNodeId() != null) {
264 InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder();
265
266 Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder();
267 topologyBuilder =
268 topologyBuilder.clientIdRef(teSubsystemTeNode.sourceTeNodeId().clientId())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500269 .providerIdRef(teSubsystemTeNode.sourceTeNodeId().providerId())
270 // is this correct? Why not sourceTeNodeId().teTopologyKey()?
271 .teTopologyIdRef(teSubsystemTeNode
272 .sourceTeNodeId().topologyId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500273 issBuilder = issBuilder.topology(topologyBuilder.build());
274 yangStateBuilder.informationSourceState(issBuilder.build());
275 }
276
277 return yangStateBuilder.build();
278 }
279
280 private static class ByteUtils {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500281
282 public static byte[] longToBytes(long x) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500283 long temp = x;
284 byte[] b = new byte[8];
285 for (int i = 0; i < b.length; i++) {
286 b[i] = new Long(temp & 0xff).byteValue();
287 temp = temp >> 8;
288 }
289 return b;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500290 }
291
292 public static long bytesToLong(byte[] bytes) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500293 return (bytes[7] & 255L) << 56
294 | (bytes[6] & 255L) << 48
295 | (bytes[5] & 255L) << 40
296 | (bytes[4] & 255L) << 32
297 | (bytes[3] & 255L) << 24
298 | (bytes[2] & 255L) << 16
299 | (bytes[1] & 255L) << 8 | bytes[0] & 255L;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500300 }
301 }
302
303 /**
304 * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG.
305 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500306 * @param teTunnelTp TE TunnelTerminationPoint object
Hesam Rahimi41208102016-12-09 17:54:03 -0500307 * @param teTpId
308 * @param teTopologyService
309 * @param teNodeKey
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500310 * @return TunnelTerminationPoint YANG object
311 */
312 private static TunnelTerminationPoint teSubsystem2YangTtp(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500313 org.onosproject.tetopology.management.api.node
314 .TunnelTerminationPoint teTunnelTp, Long teTpId,
315 TeTopologyService teTopologyService,
316 TeNodeKey teNodeKey) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500317 checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP);
318
319 TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder =
320 DefaultTunnelTerminationPoint.builder().tunnelTpId(ByteUtils.longToBytes(teTpId.longValue()));
321
322 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500323 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.Config.ConfigBuilder ttpConfigBuilder =
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500324 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500325 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder();
326 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
327 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.State.StateBuilder ttpStateBuilder =
328 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
329 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500330
331 // Assuming teTunnelTp only has one interLayerLock
332 if (teTunnelTp.interLayerLockList() != null && !teTunnelTp.interLayerLockList().isEmpty()) {
333 ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0));
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500334 ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500335 }
336
337 TerminationCapability.TerminationCapabilityBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500338 tcapConfigBuilder = DefaultTerminationCapability.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500339 // TODO: retrieve more attributes from teTunnelTp and assign to tcapConfigBuilder.
340 // For which ones we can do the conversion?
341 // FIXME: once new yang model is used, we can make llc from teTunnelTp.localLinkConnectivityList()
Hesam Rahimi41208102016-12-09 17:54:03 -0500342 if (teTunnelTp.localLinkConnectivityList() != null && !teTunnelTp.localLinkConnectivityList().isEmpty()) {
343 for (LocalLinkConnectivity llcn : teTunnelTp.localLinkConnectivityList()) {
344 TeLinkId telinkId = (TeLinkId) llcn.constrainingElements().get(0);
345 TeLinkTpGlobalKey globalKey = new TeLinkTpGlobalKey(teNodeKey, telinkId.value());
346 NetworkLinkKey netLinkKey = teTopologyService.linkKey(globalKey);
347 NetworkLink networkLink = teTopologyService
348 .network(netLinkKey.networkId()).links().get(netLinkKey.linkId());
349 tcapConfigBuilder = tcapConfigBuilder
350 .linkTp(TpId.fromString(networkLink.source().tpId()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500351 .toString()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500352 // convert teLinkId to networkLinkKey
353 ttpConfigBuilder = ttpConfigBuilder.addToTerminationCapability(tcapConfigBuilder.build());
354 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500355
Hesam Rahimi41208102016-12-09 17:54:03 -0500356 // TODO: retrieve teTunnelTp.switchingLayer() and set it to ttpConfigBuilder
357
358 TerminationCapability.TerminationCapabilityBuilder tcapStateBuilder =
359 DefaultTerminationCapability.builder();
360 // TODO: retrieve more attributes from teTunnelTp and assign to tcapStateBuilder
361 // For which ones we can do the conversion?
362 for (LocalLinkConnectivity llcn : teTunnelTp.localLinkConnectivityList()) {
363 TeLinkId telinkId = (TeLinkId) llcn.constrainingElements().get(0);
364 TeLinkTpGlobalKey globalKey = new TeLinkTpGlobalKey(teNodeKey, telinkId.value());
365 NetworkLinkKey netLinkKey = teTopologyService.linkKey(globalKey);
366 NetworkLink networkLink = teTopologyService
367 .network(netLinkKey.networkId()).links().get(netLinkKey.linkId());
368 tcapStateBuilder = tcapStateBuilder
369 .linkTp(TpId.fromString(networkLink.source().tpId()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500370 .toString()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500371 ttpStateBuilder = ttpStateBuilder.addToTerminationCapability(tcapStateBuilder.build());
372 }
373 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500374
375 tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500376 .state(ttpStateBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500377
378 return tunnelTpBuilder.build();
379 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400380
381 /**
382 * Node object conversion from TE Topology subsystem to YANG.
383 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500384 * @param teSubsystem TE subsystem node
Hesam Rahimi41208102016-12-09 17:54:03 -0500385 * @param teTopologyService teTopology core service
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500386 * @param teTopologyKey teTopologyKey
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500387 * @return YANG node
Yixiao Chen39828a62016-09-14 14:37:06 -0400388 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500389 public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem,
390 TeTopologyService teTopologyService,
391 TeTopologyKey teTopologyKey) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500392 checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE);
393
394 NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString());
Hesam Rahimi41208102016-12-09 17:54:03 -0500395
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500396 Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId);
397
398 if (teSubsystem.supportingNodeIds() != null) {
399 List<SupportingNode> sNodes = Lists.newArrayList();
400 SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode
401 .builder();
402 for (NetworkNodeKey nodeKey : teSubsystem.supportingNodeIds()) {
403 sNodes.add(spNodeBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500404 .networkRef(NetworkId
405 .fromString(nodeKey.networkId().toString()))
406 .nodeRef(NodeId.fromString(nodeKey.nodeId().toString()))
407 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500408 }
409 builder = builder.supportingNode(sNodes);
410 }
411
412 if (teSubsystem.terminationPoints() != null) {
413 AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode
414 .builder();
415 Map<KeyId, TerminationPoint> teSubsystemTeTp = teSubsystem
416 .terminationPoints();
417
418 for (TerminationPoint teTp : teSubsystemTeTp.values()) {
419 tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500420 .teSubsystem2YangTerminationPoint(teTp));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500421 }
422 builder.addYangAugmentedInfo(tpAugmentBuilder.build(),
423 AugmentedNdNode.class);
424 }
425
426 if (teSubsystem.teNode() != null) {
427 AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode
428 .builder();
429
430 TeNode teSubsystemTeNode = teSubsystem.teNode();
431
432 TeBuilder yangTeBuilder = DefaultTe.builder();
433
Hesam Rahimi41208102016-12-09 17:54:03 -0500434 yangTeBuilder = yangTeBuilder.teNodeId(TeNodeId.of(DottedQuad
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500435 .of(Ip4Address.valueOf((int) teSubsystemTeNode.teNodeId())
436 .toString())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500437
438 // Set configuration data
439 // Set state data
Hesam Rahimi41208102016-12-09 17:54:03 -0500440 yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode, teTopologyService))
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500441 .state(teNode2YangState(teSubsystemTeNode, teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500442
443 if (teSubsystemTeNode.tunnelTerminationPoints() != null) {
444 for (Map.Entry<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> entry :
445 teSubsystemTeNode.tunnelTerminationPoints().entrySet()) {
446 yangTeBuilder = yangTeBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500447 .addToTunnelTerminationPoint(teSubsystem2YangTtp(entry
448 .getValue(), entry.getKey(), teTopologyService,
449 new TeNodeKey(teTopologyKey, teSubsystemTeNode.teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500450 }
451 }
452
453 nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build());
454 builder.addYangAugmentedInfo(nodeAugmentBuilder.build(),
455 AugmentedNwNode.class);
456 }
457 return builder.build();
Yixiao Chen39828a62016-09-14 14:37:06 -0400458 }
459
460 /**
461 * Node object conversion from YANG to TE Topology subsystem.
462 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500463 * @param yangNode Node in YANG model
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500464 * @param yangNetwork YANG network
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500465 * @return TE subsystem node
Yixiao Chen39828a62016-09-14 14:37:06 -0400466 */
467 public static org.onosproject.tetopology.management.api.node.NetworkNode
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500468 yang2TeSubsystemNode(Node yangNode, Network yangNetwork) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500469 checkNotNull(yangNode, E_NULL_YANG_NODE);
Yixiao Chen39828a62016-09-14 14:37:06 -0400470
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500471 org.onosproject.tetopology.management.api.node.DefaultNetworkNode node;
472 List<NetworkNodeKey> spNodes = null;
473 TeNode teNode = null;
474 Map<KeyId, TerminationPoint> tps = null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400475
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500476 if (yangNode.supportingNode() != null) {
477 spNodes = Lists.newArrayList();
478 for (SupportingNode yangSpNode : yangNode.supportingNode()) {
479 NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()),
480 KeyId.keyId(yangSpNode.networkRef().uri().toString()));
481 spNodes.add(nodeKey);
482 }
483 }
484
485 if (yangNode.yangAugmentedInfoMap() != null
486 && !yangNode.yangAugmentedInfoMap().isEmpty()) {
487
488 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
489 .yangAugmentedInfo(AugmentedNdNode.class);
490 if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) {
491 tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment);
492 }
493
494 AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode
495 .yangAugmentedInfo(AugmentedNwNode.class);
496 if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.te().teNodeId() != null) {
497 Te yangNodeAugTe = yangNodeAugment.te();
498 teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe,
499 yangNetwork,
500 yangNode,
501 tps);
502 }
503 }
504
505 node = new org.onosproject.tetopology.management.api.node
506 .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps);
507 return node;
508 }
509
510 // TODO: convert connectivity matrix from yang to te
511 private static Map<Long, ConnectivityMatrix>
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500512 yang2TeSubsystemNodeConnectivityMatrix(String networkId,
513 String nodeId,
514 List<org.onosproject.yang.gen.v1.urn.ietf
515 .params.xml.ns.yang.ietf.te.topology.rev20160708
516 .ietftetopology.tenodeconnectivitymatrix.
517 ConnectivityMatrix> yangMatrix) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500518
519 Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap();
520
521
522 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te
523 .topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.
524 ConnectivityMatrix cmYang : yangMatrix) {
525
Hesam Rahimi41208102016-12-09 17:54:03 -0500526 ElementType from = new TeLinkId(Long.valueOf(((String) cmYang.from().tpRef()))); // is this correct?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500527
528 UnderlayAbstractPath underlayPath = null; // ignore
529
530 List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now
531
532 List<ElementType> constrainingElements = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500533 ElementType to = new TeLinkId(Long.valueOf(((String) cmYang.to().tpRef()))); // is this correct?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500534 constrainingElements.add(to);
535
536 BitSet flags = new BitSet(); // what are the flags in cmYang?
537
538 List<Long> srlgs = Lists.newArrayList();
539 if (cmYang.teSrlgs() != null) {
540 for (Srlg srlg : cmYang.teSrlgs().value()) {
541 srlgs.add(srlg.uint32());
542 }
543 }
544 TePathAttributes teAttributes = new
545 TePathAttributes(cmYang.teDefaultMetric(),
Hesam Rahimi41208102016-12-09 17:54:03 -0500546 cmYang.performanceMetric() == null ? null :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500547 (cmYang.performanceMetric().measurement() == null ? null :
548 cmYang.performanceMetric().measurement().unidirectionalDelay()),
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500549 srlgs);
550 ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(),
551 from,
Ray Milkey8cd9a662016-11-30 16:55:40 -0800552 mergingList,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500553 constrainingElements,
554 flags,
Ray Milkey8cd9a662016-11-30 16:55:40 -0800555 teAttributes,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500556 underlayPath);
557
558 teCmList.put(cmYang.id(), coreCm);
559 }
560
561 return teCmList;
562 }
563
564 private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut) {
565 TeTopologyKey tetopokey = new TeTopologyKey((Long) ut.providerIdRef(),
566 (Long) ut.clientIdRef(),
Hesam Rahimi41208102016-12-09 17:54:03 -0500567 Long.valueOf((String) ut.teTopologyIdRef()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500568 return tetopokey;
569 }
570
571 // TODO: retrieve the details of tunnel termiantion points from yang to te
572 private static Map<Long, org.onosproject.tetopology.management.api.node.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500573 TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps, Node yangNode) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500574 Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps
575 .newHashMap();
576 for (TunnelTerminationPoint ttpYang : ttps) {
577
578 SwitchingType switchingLayer = null; // how to find switching type?
579 EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding();
580 BitSet flags = new BitSet(); // how to set flags?
581 List<Long> interLayerLockList = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500582
583 if (ttpYang.config() != null) {
584 interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list
585 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500586
587 List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList();
588 // FIXME: once new yang model is used, we can make llc
Hesam Rahimi41208102016-12-09 17:54:03 -0500589 ElementType elt = null;
590 List<ElementType> eltList = Lists.newArrayList();
591
592 if (ttpYang.config() != null
593 && ttpYang.config().terminationCapability() != null
594 && !ttpYang.config().terminationCapability().isEmpty()) {
595 for (TerminationCapability tercap : ttpYang.config()
596 .terminationCapability()) {
597
598 if (yangNode.yangAugmentedInfoMap() != null
599 && !yangNode.yangAugmentedInfoMap().isEmpty()) {
600
601 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
602 .yangAugmentedInfo(AugmentedNdNode.class);
603 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml
604 .ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
605 .networks.network.node.augmentedndnode
606 .TerminationPoint tpItem : yangTpNodeAugment.terminationPoint()) {
607 if (tpItem.tpId().uri().string().equals(tercap.linkTp().toString())) {
608 if (tpItem.yangAugmentedInfoMap() != null
609 && !tpItem.yangAugmentedInfoMap().isEmpty()) {
610 AugmentedNtTerminationPoint yangTpAugment =
611 (AugmentedNtTerminationPoint) tpItem
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500612 .yangAugmentedInfo(AugmentedNtTerminationPoint.class);
Hesam Rahimi41208102016-12-09 17:54:03 -0500613 if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) {
614 elt = new TeLinkId(Long.valueOf(yangTpAugment.te().teTpId().toString()));
615 break;
616 }
617 }
618 }
619 }
620 }
621 eltList.add(elt);
622// tercap.linkTp().toString() //tpId -> tp -> te-tp-id (long)
623 }
624 }
625 TePathAttributes teAttributes = null; // how to find these
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500626 // attributes from ttpYang?
Hesam Rahimi41208102016-12-09 17:54:03 -0500627 UnderlayAbstractPath underlayPath = null; // how to find underlayAbstractPath from ttpYang?
628 LocalLinkConnectivity llc = new LocalLinkConnectivity(eltList,
629 flags,
630 teAttributes,
631 underlayPath);
632 localLinkConnectivityList.add(llc);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500633
634 float[] availAdaptBandwidth = null; // how to find availableBandwidth?
635
636 org.onosproject.tetopology.management.api.node.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500637 TunnelTerminationPoint ttpTe = new
638 org.onosproject.tetopology.management.api.node.
639 DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()),
640 switchingLayer,
641 encodingLayer,
642 flags,
643 interLayerLockList,
644 localLinkConnectivityList,
645 availAdaptBandwidth,
646 null);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500647
648 ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe);
649 }
650
651 return ttpsMap;
652 }
653
654 private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe,
655 Network yangNetwork,
656 Node yangNode,
Hesam Rahimi41208102016-12-09 17:54:03 -0500657 Map<KeyId, TerminationPoint> teTps) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500658
659
660 NodeId yangNodeId = yangNode.nodeId();
661 List<SupportingNode> yangSupportNodes = yangNode.supportingNode();
662
663 NetworkId yangNetworkId = yangNetwork.networkId();
664
665 long teNodeId = Ip4Address.valueOf(yangNodeAugTe.teNodeId().dottedQuad().string()).toInt();
666
667 TeTopologyKey underlayTopologyIdId = null;
668
669 // FIXME: yang has a list of supporting nodes, but TeNode only has one
670 // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId?
671 TeNodeKey supportTeNodeId = null;
672// supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId)
673// yangSupportNodes.get(0).
674
675 TeNodeKey sourceTeNodeId = null; //ignore
676 CommonNodeData teData = null;
677 Map<Long, ConnectivityMatrix> connMatrices = null;
678 Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null;
679 List<Long> teLinkIds = Lists.newArrayList();
680 List<Long> teTpIds = Lists.newArrayList();
681
682 // ********************************************** to find teLinkIds
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500683 // teLinkIds should be supposed to get from YANG Link and TP data.
684 // For now, assuming each teTp is sourcing a TE link .
Hesam Rahimi41208102016-12-09 17:54:03 -0500685 if (MapUtils.isNotEmpty(teTps)) {
686 for (Map.Entry<KeyId, TerminationPoint> entry : teTps.entrySet()) {
687 if (entry.getValue().teTpId() != null) {
688 teTpIds.add(entry.getValue().teTpId());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500689 teLinkIds.add(entry.getValue().teTpId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500690 }
691 }
692 }
693 // ********************************************** to find teTpIds
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500694// if (yangNode.yangAugmentedInfoMap() != null
695// && !yangNode.yangAugmentedInfoMap().isEmpty()) {
696//
697// AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
698// .yangAugmentedInfo(AugmentedNdNode.class);
699//
700// if (yangTpNodeAugment.terminationPoint() != null) {
701// for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
702// .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
703// yangTpnode : yangTpNodeAugment.terminationPoint()) {
704// teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string()));
705// }
706// }
707// }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500708 // **********************************************
709
710 Config ynodeAugCfg = yangNodeAugTe.config();
711
712 if (ynodeAugCfg != null) {
713 TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes();
714 if (teNodeAttr != null) {
715
716 if (teNodeAttr.underlayTopology() != null) {
717
718 underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500719 .underlayTopology());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500720 }
721 BitSet flags = new BitSet();
722 if (teNodeAttr.isAbstract()) {
723 flags.set(TeNode.BIT_ABSTRACT);
724 }
725 teData = new CommonNodeData(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500726 null, // teNodeAttr.name().string(),
727 EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()),
728 EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()),
729 flags);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500730
731 if (teNodeAttr.connectivityMatrix() != null) {
732 connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(),
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500733 yangNodeId.uri().toString(),
734 teNodeAttr.connectivityMatrix());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500735 }
736
737 }
738 }
739
740 if (yangNodeAugTe.tunnelTerminationPoint() != null) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500741 ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint(), yangNode);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500742 }
743
744 TeNode teNode = new DefaultTeNode(teNodeId,
745 underlayTopologyIdId,
746 supportTeNodeId,
747 sourceTeNodeId,
748 teData,
749 connMatrices,
750 teLinkIds,
751 ttps,
752 teTpIds);
753 return teNode;
754 }
755
756 private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) {
757 Map<KeyId, TerminationPoint> tps;
758 if (yangTpNodeAugment.terminationPoint() != null) {
759 tps = Maps.newHashMap();
760 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
761 .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
762 yangTpnode : yangTpNodeAugment.terminationPoint()) {
763 tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()),
764 TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode));
765 }
766 return tps;
767 }
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500768 return null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400769 }
770
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500771 /**
Hesam Rahimi41208102016-12-09 17:54:03 -0500772 * Converts a TE Topology node event from the data format used in the core
773 * to its corresponding YANG Object (YO) format.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500774 *
775 * @param eventType Node event type
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500776 * @param eventData TE Topology node event data
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500777 * @return YANG Object converted from nodeData
778 */
779 public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType,
Hesam Rahimi41208102016-12-09 17:54:03 -0500780 NetworkNodeEventSubject eventData) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500781 TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder();
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500782
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500783 TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
784 builder.eventType(yangEventType);
785
Hesam Rahimi41208102016-12-09 17:54:03 -0500786 NetworkId newtorkId = NetworkId.fromString(eventData.key().networkId().toString());
787 builder.networkRef(newtorkId);
788 NodeId nodeId = NodeId.fromString(eventData.key().nodeId().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500789 builder.nodeRef(nodeId);
790
Hesam Rahimi41208102016-12-09 17:54:03 -0500791 NetworkNode node = eventData.neworkNode();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500792 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
793 rev20160708.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi41208102016-12-09 17:54:03 -0500794 TeNodeAttributes teNodeAttributes = node == null ? null
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500795 : teNode2YangTeNodeAttributes(node.teNode());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500796 builder.teNodeAttributes(teNodeAttributes);
797
798 return builder.build();
799 }
800
801 private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.
802 ietf.te.topology.rev20160708.ietftetopology.
803 tenodeconfigattributesnotification.
804 TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) {
805
806 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
807 rev20160708.ietftetopology.tenodeconfigattributesnotification.
808 TeNodeAttributes.TeNodeAttributesBuilder attrBuilder =
809 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
810 rev20160708.ietftetopology.tenodeconfigattributesnotification.
811 DefaultTeNodeAttributes.builder();
812
813 if (teNode.connectivityMatrices() != null) {
814
815 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500816 .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix
817 .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf.
818 params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrixabs.
819 DefaultConnectivityMatrix.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500820 for (Map.Entry<Long, ConnectivityMatrix> teCmEntry :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500821 teNode.connectivityMatrices().entrySet()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500822 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
823 .id(teCmEntry.getKey())
824 .isAllowed(!teCmEntry.getValue().flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500825 .get(ConnectivityMatrix.BIT_DISALLOWED))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500826 .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500827 .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom
828 .FromBuilder() // TODO: for now, assuming that there is
829 // only one 'from', and mergingList is empty
830 .tpRef(teCmEntry.getValue().from())
831 .build())
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500832 .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500833 .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix
834 .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
835 // one item in constrainingElements list
836 .tpRef(teCmEntry.getValue().constrainingElements().get(0))
837 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500838 attrBuilder = attrBuilder
839 .addToConnectivityMatrix(connectivityMatrixConfigBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500840 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500841 }
842 }
843
844 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
845 rev20160708.ietftetopology.tenodeconfigattributesnotification.
846 TeNodeAttributes teNodeAttributes = attrBuilder.build();
847
848 return teNodeAttributes;
849 }
850
Henry Yu05dcc212017-01-05 16:05:26 -0500851 /**
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500852 * Retrieves the TE network node key from a YANG network node notification
853 * event.
Henry Yu05dcc212017-01-05 16:05:26 -0500854 *
855 * @param yangNodeEvent YANG network node notification event
856 * @return TE network node key
857 */
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500858 public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500859 NetworkId networkRef = NetworkId.fromString(yangNodeEvent.networkRef().toString());
860 NodeId nodeRef = NodeId.fromString(yangNodeEvent.nodeRef().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500861 KeyId networkId = KeyId.keyId(networkRef.uri().toString());
862 KeyId nodeId = KeyId.keyId(nodeRef.uri().toString());
863
864 NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId);
865
866 return networkNodeKey;
Yixiao Chen39828a62016-09-14 14:37:06 -0400867 }
868
Hesam Rahimi41208102016-12-09 17:54:03 -0500869 /**
870 * Converts YangNode event to NetworkNode.
871 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500872 * @param yangNodeEvent yangNodeEvent
Hesam Rahimi41208102016-12-09 17:54:03 -0500873 * @param teTopologyService teTopologyService
874 * @return NetworkNode
875 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500876 public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent,
877 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500878 KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId();
879
Ray Milkey8cd9a662016-11-30 16:55:40 -0800880 org.onosproject.tetopology.management.api.Network network = teTopologyService.network(
881 yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500882 if (network == null) {
883 return null;
884 }
885
886 NetworkNode networkNode = network.node(networkNodeId);
887 if (networkNode == null) {
888 return null;
889 }
890
891 List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds();
892 Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints();
893
894 TeNode teNode = networkNode.teNode();
895 if (teNode == null) {
896 return null;
897 }
898
899 TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode);
900
901 NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps);
902
903 return updatedNetworkNode;
904 }
905
906 private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) {
907
908 long teNodeId = oldTeNode.teNodeId();
909 TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId();
910 TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId();
911 TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId();
912 Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices();
913 List<Long> teLinkIds = oldTeNode.teLinkIds();
914 Map<Long, org.onosproject.tetopology.management.
915 api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints();
916 List<Long> teTpIds = oldTeNode.teLinkIds();
917 String name = oldTeNode.name();
918 TeStatus adminStatus = oldTeNode.adminStatus();
919 TeStatus opStatus = oldTeNode.opStatus();
920 BitSet flags = oldTeNode.flags();
921
922 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology
923 .tenodeconfigattributesnotification
924 .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes();
925
926 if (yangTeNodeAttrs != null) {
927 TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus();
928 if (yangAdminStatus != null) {
929 adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus);
930 }
931
932 BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags();
933 if (yangFlags != null) {
934 flags = yangFlags;
935 }
936
937 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.
938 ietf.te.topology.rev20160708.ietftetopology
939 .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs
940 .connectivityMatrix();
941 if (yangConnMatrices != null) {
942 for (org.onosproject.yang.gen.v1.
943 urn.ietf.params.xml.ns.yang.
944 ietf.te.topology
945 .rev20160708.ietftetopology
946 .tenodeconnectivitymatrixabs
947 .ConnectivityMatrix yangConnMatrix : yangConnMatrices) {
948 Long cmId = new Long(yangConnMatrix.id());
949 ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id()));
950 if (oldConnMatrix != null) {
951 ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix,
952 oldConnMatrix);
953 connMatrices.remove(cmId);
954 connMatrices.put(cmId, newConnMatrix);
955 }
956 }
957 }
958 }
959
960 CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags);
961 TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData,
962 connMatrices, teLinkIds, ttps, teTpIds);
963
964 return updatedTeNode;
965 }
966
967 private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500968 urn.ietf.params.xml.ns.yang.
969 ietf.te.topology
970 .rev20160708.ietftetopology
971 .tenodeconnectivitymatrixabs
972 .ConnectivityMatrix yangConnMatrix,
973 ConnectivityMatrix oldTeConnMatrix) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500974
975 long id = yangConnMatrix.id();
976 ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef()));
977 UnderlayAbstractPath underlayPath = null;
978 List<ElementType> mergingList = Lists.newArrayList();
979
980 List<ElementType> constrainingElements = Lists.newArrayList();
981 ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef()));
982 constrainingElements.add(to);
983
984 BitSet flags = oldTeConnMatrix.flags();
985
986 TePathAttributes teAttributes = oldTeConnMatrix.teAttributes();
987
988 ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id,
989 from,
990 mergingList,
991 constrainingElements,
992 flags,
993 teAttributes,
994 underlayPath);
995 return updatedConnMatrix;
Yixiao Chen39828a62016-09-14 14:37:06 -0400996 }
997}