blob: 436a9d06dfc623f95bd9f23c2ea0873da8abbe62 [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 Rahimi01f6ae02017-02-01 13:57:00 -050024import org.apache.commons.collections.CollectionUtils;
Hesam Rahimi41208102016-12-09 17:54:03 -050025import org.apache.commons.collections.MapUtils;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050026import org.onlab.packet.Ip4Address;
27import org.onosproject.tetopology.management.api.EncodingType;
28import org.onosproject.tetopology.management.api.KeyId;
29import org.onosproject.tetopology.management.api.SwitchingType;
30import org.onosproject.tetopology.management.api.TeStatus;
31import org.onosproject.tetopology.management.api.TeTopologyKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050032import org.onosproject.tetopology.management.api.TeTopologyService;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050033import org.onosproject.tetopology.management.api.link.ElementType;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050034import org.onosproject.tetopology.management.api.link.TeLinkId;
35import org.onosproject.tetopology.management.api.link.TePathAttributes;
36import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath;
37import org.onosproject.tetopology.management.api.node.CommonNodeData;
38import org.onosproject.tetopology.management.api.node.ConnectivityMatrix;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050039import org.onosproject.tetopology.management.api.node.DefaultNetworkNode;
40import org.onosproject.tetopology.management.api.node.DefaultTeNode;
41import org.onosproject.tetopology.management.api.node.LocalLinkConnectivity;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050042import org.onosproject.tetopology.management.api.node.NetworkNode;
Hesam Rahimi41208102016-12-09 17:54:03 -050043import org.onosproject.tetopology.management.api.node.NetworkNodeEventSubject;
Yixiao Chen39828a62016-09-14 14:37:06 -040044import org.onosproject.tetopology.management.api.node.NetworkNodeKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050045import org.onosproject.tetopology.management.api.node.TeNode;
46import org.onosproject.tetopology.management.api.node.TeNodeKey;
47import org.onosproject.tetopology.management.api.node.TerminationPoint;
48import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName;
Yixiao Chen39828a62016-09-14 14:37:06 -040049import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050050import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050051import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
52import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050053import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
54 .ietfnetwork.networks.network.DefaultNode;
55import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
56 .ietfnetwork.networks.network.Node;
57import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
58 .ietfnetwork.networks.network.node.DefaultSupportingNode;
59import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
60 .ietfnetwork.networks.network.node.SupportingNode;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050061import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
62 .ietfnetworktopology.networks.network.node.AugmentedNdNode;
63import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
64 .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050065import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.DefaultTeNodeEvent;
66import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.TeNodeEvent;
67import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.DefaultInformationSourceState;
68import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.InformationSourceState;
69import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.informationsourcestate.DefaultTopology;
70import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.informationsourcestate.Topology;
71import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050072 .ietftetopology.networks.network.node.AugmentedNwNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050073import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050074 .ietftetopology.networks.network.node.DefaultAugmentedNwNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050075import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
76import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.DefaultTe;
77import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.DefaultTe.TeBuilder;
78import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.Te;
79import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.Config;
80import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultConfig;
81import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultState;
82import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint;
83import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.State;
84import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.TunnelTerminationPoint;
85import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes;
86import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.TeNodeAttributes;
87import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.TeNodeAttributes.TeNodeAttributesBuilder;
88import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.ConnectivityMatrices;
89import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrices;
90import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrices.ConnectivityMatricesBuilder;
91import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.DefaultConnectivityMatrix;
92import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.DefaultConnectivityMatrix.ConnectivityMatrixBuilder;
93import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.connectivitymatrix.DefaultFrom;
94import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.connectivitymatrix.DefaultTo;
95import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology;
96import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeinfoattributes.UnderlayTopology;
97import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.DefaultLocalLinkConnectivities;
98import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.LocalLinkConnectivities;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050099import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg;
100import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus;
101import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500102import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType;
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();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500179 ConnectivityMatricesBuilder yangConnectivityMatricesBuilder = DefaultConnectivityMatrices.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500180 for (Map.Entry<Long, ConnectivityMatrix> teCmEntry :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500181 connectivityMatrices.entrySet()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500182 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
183 .id(teCmEntry.getKey())
184 .isAllowed(!teCmEntry.getValue().flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500185 .get(ConnectivityMatrix.BIT_DISALLOWED))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500186 .from(new DefaultFrom.FromBuilder() // TODO: for now, assuming that there is
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500187 // only one 'from', and mergingList is empty
188 .tpRef(((TeLinkId) teCmEntry.getValue().from()).value())
189 .build())
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500190 .to(new DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500191 // one item in constrainingElements list
192 .tpRef(((TeLinkId) teCmEntry.getValue().constrainingElements().get(0)).value())
193 .build());
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500194 // TODO: add more attributes to connectivityMatrixConfigBuilder--
195
196 yangConnectivityMatricesBuilder = yangConnectivityMatricesBuilder
197 .addToConnectivityMatrix(connectivityMatrixConfigBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500198 }
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500199 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
200 .connectivityMatrices(yangConnectivityMatricesBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500201 return teNodeAttributesConfigBuilder;
202 }
203
Hesam Rahimi41208102016-12-09 17:54:03 -0500204 private static UnderlayTopology teNode2YangUnderlay(TeTopologyKey underlayTopology,
205 TeTopologyService teTopologyService) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500206 UnderlayTopology.UnderlayTopologyBuilder underlayBuilder = DefaultUnderlayTopology.builder();
Hesam Rahimi41208102016-12-09 17:54:03 -0500207
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500208 underlayBuilder = underlayBuilder.networkRef(teTopologyService.networkId(underlayTopology));
Hesam Rahimi41208102016-12-09 17:54:03 -0500209
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500210 return underlayBuilder.build();
211 }
212
213 /**
214 * TE Node State object conversion from TE Topology subsystem to YANG.
215 *
216 * @param teSubsystemTeNode TE node object
Hesam Rahimi41208102016-12-09 17:54:03 -0500217 * @param teTopologyService teTopology core service
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500218 * @return TE Node State YANG object
219 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500220 private static State teNode2YangState(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500221 checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE);
222
223 TeNodeAttributes
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500224 .TeNodeAttributesBuilder teNodeAttributesStateBuilder =
225 DefaultTeNodeAttributes.builder()
226 .isAbstract(teSubsystemTeNode.flags()
227 .get(TeNode.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500228
229 if (teSubsystemTeNode.adminStatus() != null) {
230 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
231 .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus()));
232 }
233
234 if (teSubsystemTeNode.name() != null) {
235 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
236 .name(DomainName.fromString(teSubsystemTeNode.name()));
237 }
238
239 if (teSubsystemTeNode.underlayTeTopologyId() != null) {
240 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
241 .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500242 .underlayTeTopologyId(), teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500243 }
244
245 if (teSubsystemTeNode.connectivityMatrices() != null) {
246 teNodeAttributesStateBuilder = te2YangConnectivityMatrix(teNodeAttributesStateBuilder,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500247 teSubsystemTeNode.connectivityMatrices());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500248 }
249
250 // TODO: should we ignore this from te to yang? as we've already set yang supportingNode
Ray Milkey8cd9a662016-11-30 16:55:40 -0800251 //if (teSubsystemTeNode.supportingTeNodeId() != null) {
252 //}
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500253
254 State.StateBuilder yangStateBuilder = DefaultState.builder();
255 yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build());
256
257 if (teSubsystemTeNode.opStatus() != null) {
258 yangStateBuilder = yangStateBuilder.operStatus(EnumConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500259 .teSubsystem2YangOperStatus(teSubsystemTeNode.opStatus()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500260 }
261
262 if (teSubsystemTeNode.sourceTeNodeId() != null) {
263 InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder();
264
265 Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500266 topologyBuilder = topologyBuilder.nodeRef(teTopologyService
267 .nodeKey(teSubsystemTeNode.sourceTeNodeId()).nodeId())
268 .networkRef(teTopologyService
269 .nodeKey(teSubsystemTeNode.sourceTeNodeId())
270 .networkId());
271
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500272 issBuilder = issBuilder.topology(topologyBuilder.build());
273 yangStateBuilder.informationSourceState(issBuilder.build());
274 }
275
276 return yangStateBuilder.build();
277 }
278
279 private static class ByteUtils {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500280
281 public static byte[] longToBytes(long x) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500282 long temp = x;
283 byte[] b = new byte[8];
284 for (int i = 0; i < b.length; i++) {
285 b[i] = new Long(temp & 0xff).byteValue();
286 temp = temp >> 8;
287 }
288 return b;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500289 }
290
291 public static long bytesToLong(byte[] bytes) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500292 return (bytes[7] & 255L) << 56
293 | (bytes[6] & 255L) << 48
294 | (bytes[5] & 255L) << 40
295 | (bytes[4] & 255L) << 32
296 | (bytes[3] & 255L) << 24
297 | (bytes[2] & 255L) << 16
298 | (bytes[1] & 255L) << 8 | bytes[0] & 255L;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500299 }
300 }
301
302 /**
303 * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG.
304 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500305 * @param teTunnelTp TE TunnelTerminationPoint object
Hesam Rahimi41208102016-12-09 17:54:03 -0500306 * @param teTpId
307 * @param teTopologyService
308 * @param teNodeKey
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500309 * @return TunnelTerminationPoint YANG object
310 */
311 private static TunnelTerminationPoint teSubsystem2YangTtp(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500312 org.onosproject.tetopology.management.api.node
313 .TunnelTerminationPoint teTunnelTp, Long teTpId,
314 TeTopologyService teTopologyService,
315 TeNodeKey teNodeKey) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500316 checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP);
317
318 TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder =
319 DefaultTunnelTerminationPoint.builder().tunnelTpId(ByteUtils.longToBytes(teTpId.longValue()));
320
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500321 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500322 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.Config.ConfigBuilder ttpConfigBuilder =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500323 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500324 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500325 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500326 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.State.StateBuilder ttpStateBuilder =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500327 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500328 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500329
330 // Assuming teTunnelTp only has one interLayerLock
331 if (teTunnelTp.interLayerLockList() != null && !teTunnelTp.interLayerLockList().isEmpty()) {
332 ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0));
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500333 ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500334 }
335
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500336 // TODO: retrieve teTunnelTp.switchingLayer() and set it to ttpConfigBuilder and ttpStateBuilder
337 // TODO: retrieve more attributes from teTunnelTp and assign to ttpConfigBuilder and ttpStateBuilder
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500338 // For which ones we can do the conversion?
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500339
340 LocalLinkConnectivities.LocalLinkConnectivitiesBuilder
341 localLinkConnectivitiesBuilder = DefaultLocalLinkConnectivities.builder();
Hesam Rahimi41208102016-12-09 17:54:03 -0500342 if (teTunnelTp.localLinkConnectivityList() != null && !teTunnelTp.localLinkConnectivityList().isEmpty()) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500343 // TODO: add more attributes to localLinkConnectivitiesBuilder (add connectivity matrices.--
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500344
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500345 ttpConfigBuilder = ttpConfigBuilder.localLinkConnectivities(localLinkConnectivitiesBuilder.build());
346 ttpStateBuilder = ttpStateBuilder.localLinkConnectivities(localLinkConnectivitiesBuilder.build());
Hesam Rahimi41208102016-12-09 17:54:03 -0500347 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500348
349 tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500350 .state(ttpStateBuilder.build());
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500351 // TODO: add supporting ttp.--
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500352
353 return tunnelTpBuilder.build();
354 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400355
356 /**
357 * Node object conversion from TE Topology subsystem to YANG.
358 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500359 * @param teSubsystem TE subsystem node
Hesam Rahimi41208102016-12-09 17:54:03 -0500360 * @param teTopologyService teTopology core service
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500361 * @param teTopologyKey teTopologyKey
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500362 * @return YANG node
Yixiao Chen39828a62016-09-14 14:37:06 -0400363 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500364 public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem,
365 TeTopologyService teTopologyService,
366 TeTopologyKey teTopologyKey) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500367 checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE);
368
369 NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString());
Hesam Rahimi41208102016-12-09 17:54:03 -0500370
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500371 Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId);
372
373 if (teSubsystem.supportingNodeIds() != null) {
374 List<SupportingNode> sNodes = Lists.newArrayList();
375 SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode
376 .builder();
377 for (NetworkNodeKey nodeKey : teSubsystem.supportingNodeIds()) {
378 sNodes.add(spNodeBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500379 .networkRef(NetworkId
380 .fromString(nodeKey.networkId().toString()))
381 .nodeRef(NodeId.fromString(nodeKey.nodeId().toString()))
382 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500383 }
384 builder = builder.supportingNode(sNodes);
385 }
386
387 if (teSubsystem.terminationPoints() != null) {
388 AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode
389 .builder();
390 Map<KeyId, TerminationPoint> teSubsystemTeTp = teSubsystem
391 .terminationPoints();
392
393 for (TerminationPoint teTp : teSubsystemTeTp.values()) {
394 tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500395 .teSubsystem2YangTerminationPoint(teTp));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500396 }
397 builder.addYangAugmentedInfo(tpAugmentBuilder.build(),
398 AugmentedNdNode.class);
399 }
400
401 if (teSubsystem.teNode() != null) {
402 AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode
403 .builder();
404
405 TeNode teSubsystemTeNode = teSubsystem.teNode();
406
407 TeBuilder yangTeBuilder = DefaultTe.builder();
408
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500409 nodeAugmentBuilder = nodeAugmentBuilder
410 .teNodeId(TeNodeId.of(DottedQuad.of(Ip4Address
411 .valueOf((int) teSubsystemTeNode.teNodeId())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500412 .toString())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500413
414 // Set configuration data
415 // Set state data
Hesam Rahimi41208102016-12-09 17:54:03 -0500416 yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode, teTopologyService))
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500417 .state(teNode2YangState(teSubsystemTeNode, teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500418
419 if (teSubsystemTeNode.tunnelTerminationPoints() != null) {
420 for (Map.Entry<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> entry :
421 teSubsystemTeNode.tunnelTerminationPoints().entrySet()) {
422 yangTeBuilder = yangTeBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500423 .addToTunnelTerminationPoint(teSubsystem2YangTtp(entry
424 .getValue(), entry.getKey(), teTopologyService,
425 new TeNodeKey(teTopologyKey, teSubsystemTeNode.teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500426 }
427 }
428
429 nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build());
430 builder.addYangAugmentedInfo(nodeAugmentBuilder.build(),
431 AugmentedNwNode.class);
432 }
433 return builder.build();
Yixiao Chen39828a62016-09-14 14:37:06 -0400434 }
435
436 /**
437 * Node object conversion from YANG to TE Topology subsystem.
438 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500439 * @param yangNode Node in YANG model
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500440 * @param yangNetwork YANG network
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500441 * @param yangNetworks YANG networks
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500442 * @return TE subsystem node
Yixiao Chen39828a62016-09-14 14:37:06 -0400443 */
444 public static org.onosproject.tetopology.management.api.node.NetworkNode
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500445 yang2TeSubsystemNode(Node yangNode, Network yangNetwork,
446 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500447 checkNotNull(yangNode, E_NULL_YANG_NODE);
Yixiao Chen39828a62016-09-14 14:37:06 -0400448
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500449 org.onosproject.tetopology.management.api.node.DefaultNetworkNode node;
450 List<NetworkNodeKey> spNodes = null;
451 TeNode teNode = null;
452 Map<KeyId, TerminationPoint> tps = null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400453
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500454 if (yangNode.supportingNode() != null) {
455 spNodes = Lists.newArrayList();
456 for (SupportingNode yangSpNode : yangNode.supportingNode()) {
457 NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()),
458 KeyId.keyId(yangSpNode.networkRef().uri().toString()));
459 spNodes.add(nodeKey);
460 }
461 }
462
463 if (yangNode.yangAugmentedInfoMap() != null
464 && !yangNode.yangAugmentedInfoMap().isEmpty()) {
465
466 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
467 .yangAugmentedInfo(AugmentedNdNode.class);
468 if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) {
469 tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment);
470 }
471
472 AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode
473 .yangAugmentedInfo(AugmentedNwNode.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500474 if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.teNodeId() != null) {
475 TeNodeId teNodeId = yangNodeAugment.teNodeId();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500476 Te yangNodeAugTe = yangNodeAugment.te();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500477 teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, teNodeId,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500478 yangNetwork,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500479 yangNetworks,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500480 yangNode,
481 tps);
482 }
483 }
484
485 node = new org.onosproject.tetopology.management.api.node
486 .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps);
487 return node;
488 }
489
490 // TODO: convert connectivity matrix from yang to te
491 private static Map<Long, ConnectivityMatrix>
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500492 yang2TeSubsystemNodeConnectivityMatrix(String networkId,
493 String nodeId,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500494 ConnectivityMatrices yangMatrices) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500495
496 Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap();
497
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500498 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
499 .tenodeconnectivitymatrix.connectivitymatrices.ConnectivityMatrix>
500 yangMatrix = yangMatrices.connectivityMatrix();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500501 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500502 .topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500503 ConnectivityMatrix cmYang : yangMatrix) {
504
Hesam Rahimi41208102016-12-09 17:54:03 -0500505 ElementType from = new TeLinkId(Long.valueOf(((String) cmYang.from().tpRef()))); // is this correct?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500506
507 UnderlayAbstractPath underlayPath = null; // ignore
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500508 // TODO: add pathElements and underlayPath.--
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500509
510 List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now
511
512 List<ElementType> constrainingElements = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500513 ElementType to = new TeLinkId(Long.valueOf(((String) cmYang.to().tpRef()))); // is this correct?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500514 constrainingElements.add(to);
515
516 BitSet flags = new BitSet(); // what are the flags in cmYang?
517
518 List<Long> srlgs = Lists.newArrayList();
519 if (cmYang.teSrlgs() != null) {
520 for (Srlg srlg : cmYang.teSrlgs().value()) {
521 srlgs.add(srlg.uint32());
522 }
523 }
524 TePathAttributes teAttributes = new
525 TePathAttributes(cmYang.teDefaultMetric(),
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500526 cmYang.teDelayMetric(),
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500527 srlgs);
528 ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(),
529 from,
Ray Milkey8cd9a662016-11-30 16:55:40 -0800530 mergingList,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500531 constrainingElements,
532 flags,
Ray Milkey8cd9a662016-11-30 16:55:40 -0800533 teAttributes,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500534 underlayPath);
535
536 teCmList.put(cmYang.id(), coreCm);
537 }
538
539 return teCmList;
540 }
541
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500542 private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut, Networks yangNetworks) {
543 TeTopologyKey tetopokey = LinkConverter.findTopologyId(yangNetworks,
544 ut.networkRef());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500545 return tetopokey;
546 }
547
548 // TODO: retrieve the details of tunnel termiantion points from yang to te
549 private static Map<Long, org.onosproject.tetopology.management.api.node.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500550 TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps, Node yangNode,
551 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500552 Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps
553 .newHashMap();
554 for (TunnelTerminationPoint ttpYang : ttps) {
555
556 SwitchingType switchingLayer = null; // how to find switching type?
557 EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding();
558 BitSet flags = new BitSet(); // how to set flags?
559 List<Long> interLayerLockList = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500560
561 if (ttpYang.config() != null) {
562 interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list
563 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500564
565 List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList();
566 // FIXME: once new yang model is used, we can make llc
Hesam Rahimi41208102016-12-09 17:54:03 -0500567 ElementType elt = null;
568 List<ElementType> eltList = Lists.newArrayList();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500569 if (ttpYang.config() != null &&
570 ttpYang.config().localLinkConnectivities() != null &&
571 CollectionUtils.isNotEmpty(ttpYang.config().localLinkConnectivities().localLinkConnectivity())) {
572 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
573 .ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities
574 .LocalLinkConnectivity yangLlc : ttpYang.config()
575 .localLinkConnectivities().localLinkConnectivity()) {
576 if (MapUtils.isNotEmpty(yangNode.yangAugmentedInfoMap())) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500577 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
578 .yangAugmentedInfo(AugmentedNdNode.class);
579 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml
580 .ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
581 .networks.network.node.augmentedndnode
582 .TerminationPoint tpItem : yangTpNodeAugment.terminationPoint()) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500583 if (tpItem.tpId().uri().string().equals(yangLlc.linkTpRef().toString())) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500584 if (tpItem.yangAugmentedInfoMap() != null
585 && !tpItem.yangAugmentedInfoMap().isEmpty()) {
586 AugmentedNtTerminationPoint yangTpAugment =
587 (AugmentedNtTerminationPoint) tpItem
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500588 .yangAugmentedInfo(AugmentedNtTerminationPoint.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500589 if (yangTpAugment.teTpId() != null) {
590 elt = new TeLinkId(Long.valueOf(yangTpAugment.teTpId().toString()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500591 break;
592 }
593 }
594 }
595 }
596 }
597 eltList.add(elt);
598// tercap.linkTp().toString() //tpId -> tp -> te-tp-id (long)
599 }
600 }
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500601
Hesam Rahimi41208102016-12-09 17:54:03 -0500602 TePathAttributes teAttributes = null; // how to find these
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500603 // attributes from ttpYang?
Hesam Rahimi41208102016-12-09 17:54:03 -0500604 UnderlayAbstractPath underlayPath = null; // how to find underlayAbstractPath from ttpYang?
605 LocalLinkConnectivity llc = new LocalLinkConnectivity(eltList,
606 flags,
607 teAttributes,
608 underlayPath);
609 localLinkConnectivityList.add(llc);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500610
611 float[] availAdaptBandwidth = null; // how to find availableBandwidth?
612
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500613 // TODO: add supportTtp and pass it below instead of null.--
614
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500615 org.onosproject.tetopology.management.api.node.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500616 TunnelTerminationPoint ttpTe = new
617 org.onosproject.tetopology.management.api.node.
618 DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()),
619 switchingLayer,
620 encodingLayer,
621 flags,
622 interLayerLockList,
623 localLinkConnectivityList,
624 availAdaptBandwidth,
625 null);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500626
627 ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe);
628 }
629
630 return ttpsMap;
631 }
632
633 private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500634 TeNodeId teNodeId,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500635 Network yangNetwork,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500636 Networks yangNetworks,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500637 Node yangNode,
Hesam Rahimi41208102016-12-09 17:54:03 -0500638 Map<KeyId, TerminationPoint> teTps) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500639
640
641 NodeId yangNodeId = yangNode.nodeId();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500642
643 NetworkId yangNetworkId = yangNetwork.networkId();
644
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500645 long teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string()).toInt();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500646
647 TeTopologyKey underlayTopologyIdId = null;
648
649 // FIXME: yang has a list of supporting nodes, but TeNode only has one
650 // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId?
651 TeNodeKey supportTeNodeId = null;
652// supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId)
653// yangSupportNodes.get(0).
654
655 TeNodeKey sourceTeNodeId = null; //ignore
656 CommonNodeData teData = null;
657 Map<Long, ConnectivityMatrix> connMatrices = null;
658 Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null;
659 List<Long> teLinkIds = Lists.newArrayList();
660 List<Long> teTpIds = Lists.newArrayList();
661
662 // ********************************************** to find teLinkIds
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500663 // teLinkIds should be supposed to get from YANG Link and TP data.
664 // For now, assuming each teTp is sourcing a TE link .
Hesam Rahimi41208102016-12-09 17:54:03 -0500665 if (MapUtils.isNotEmpty(teTps)) {
666 for (Map.Entry<KeyId, TerminationPoint> entry : teTps.entrySet()) {
667 if (entry.getValue().teTpId() != null) {
668 teTpIds.add(entry.getValue().teTpId());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500669 teLinkIds.add(entry.getValue().teTpId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500670 }
671 }
672 }
673 // ********************************************** to find teTpIds
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500674// if (yangNode.yangAugmentedInfoMap() != null
675// && !yangNode.yangAugmentedInfoMap().isEmpty()) {
676//
677// AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
678// .yangAugmentedInfo(AugmentedNdNode.class);
679//
680// if (yangTpNodeAugment.terminationPoint() != null) {
681// for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
682// .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
683// yangTpnode : yangTpNodeAugment.terminationPoint()) {
684// teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string()));
685// }
686// }
687// }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500688 // **********************************************
689
690 Config ynodeAugCfg = yangNodeAugTe.config();
691
692 if (ynodeAugCfg != null) {
693 TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes();
694 if (teNodeAttr != null) {
695
696 if (teNodeAttr.underlayTopology() != null) {
697
698 underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500699 .underlayTopology(), yangNetworks);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500700 }
701 BitSet flags = new BitSet();
702 if (teNodeAttr.isAbstract()) {
703 flags.set(TeNode.BIT_ABSTRACT);
704 }
705 teData = new CommonNodeData(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500706 null, // teNodeAttr.name().string(),
707 EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()),
708 EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()),
709 flags);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500710
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500711// if (teNodeAttr.connectivityMatrix() != null) {
712 if (teNodeAttr.connectivityMatrices() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500713 connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(),
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500714 yangNodeId.uri().toString(),
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500715 teNodeAttr.connectivityMatrices());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500716 }
717
718 }
719 }
720
721 if (yangNodeAugTe.tunnelTerminationPoint() != null) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500722 ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint(),
723 yangNode,
724 yangNetworks);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500725 }
726
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500727 TeNode teNode = new DefaultTeNode(teNodeIdLong,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500728 underlayTopologyIdId,
729 supportTeNodeId,
730 sourceTeNodeId,
731 teData,
732 connMatrices,
733 teLinkIds,
734 ttps,
735 teTpIds);
736 return teNode;
737 }
738
739 private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) {
740 Map<KeyId, TerminationPoint> tps;
741 if (yangTpNodeAugment.terminationPoint() != null) {
742 tps = Maps.newHashMap();
743 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
744 .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
745 yangTpnode : yangTpNodeAugment.terminationPoint()) {
746 tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()),
747 TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode));
748 }
749 return tps;
750 }
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500751 return null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400752 }
753
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500754 /**
Hesam Rahimi41208102016-12-09 17:54:03 -0500755 * Converts a TE Topology node event from the data format used in the core
756 * to its corresponding YANG Object (YO) format.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500757 *
758 * @param eventType Node event type
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500759 * @param eventData TE Topology node event data
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500760 * @return YANG Object converted from nodeData
761 */
762 public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType,
Hesam Rahimi41208102016-12-09 17:54:03 -0500763 NetworkNodeEventSubject eventData) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500764 TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder();
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500765
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500766 TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
767 builder.eventType(yangEventType);
768
Hesam Rahimi41208102016-12-09 17:54:03 -0500769 NetworkId newtorkId = NetworkId.fromString(eventData.key().networkId().toString());
770 builder.networkRef(newtorkId);
771 NodeId nodeId = NodeId.fromString(eventData.key().nodeId().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500772 builder.nodeRef(nodeId);
773
Hesam Rahimi41208102016-12-09 17:54:03 -0500774 NetworkNode node = eventData.neworkNode();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500775 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500776 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi41208102016-12-09 17:54:03 -0500777 TeNodeAttributes teNodeAttributes = node == null ? null
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500778 : teNode2YangTeNodeAttributes(node.teNode());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500779 builder.teNodeAttributes(teNodeAttributes);
780
781 return builder.build();
782 }
783
784 private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500785 ietf.te.topology.rev20170110.ietftetopology.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500786 tenodeconfigattributesnotification.
787 TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) {
788
789 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500790 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500791 TeNodeAttributes.TeNodeAttributesBuilder attrBuilder =
792 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500793 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500794 DefaultTeNodeAttributes.builder();
795
796 if (teNode.connectivityMatrices() != null) {
797
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500798 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500799 .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix
800 .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500801 params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500802 DefaultConnectivityMatrix.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500803 for (Map.Entry<Long, ConnectivityMatrix> teCmEntry :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500804 teNode.connectivityMatrices().entrySet()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500805 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
806 .id(teCmEntry.getKey())
807 .isAllowed(!teCmEntry.getValue().flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500808 .get(ConnectivityMatrix.BIT_DISALLOWED))
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500809 .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500810 .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom
811 .FromBuilder() // TODO: for now, assuming that there is
812 // only one 'from', and mergingList is empty
813 .tpRef(teCmEntry.getValue().from())
814 .build())
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500815 .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500816 .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix
817 .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
818 // one item in constrainingElements list
819 .tpRef(teCmEntry.getValue().constrainingElements().get(0))
820 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500821 attrBuilder = attrBuilder
822 .addToConnectivityMatrix(connectivityMatrixConfigBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500823 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500824 }
825 }
826
827 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500828 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500829 TeNodeAttributes teNodeAttributes = attrBuilder.build();
830
831 return teNodeAttributes;
832 }
833
834 public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500835 NetworkId networkRef = NetworkId.fromString(yangNodeEvent.networkRef().toString());
836 NodeId nodeRef = NodeId.fromString(yangNodeEvent.nodeRef().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500837 KeyId networkId = KeyId.keyId(networkRef.uri().toString());
838 KeyId nodeId = KeyId.keyId(nodeRef.uri().toString());
839
840 NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId);
841
842 return networkNodeKey;
Yixiao Chen39828a62016-09-14 14:37:06 -0400843 }
844
Hesam Rahimi41208102016-12-09 17:54:03 -0500845 /**
846 * Converts YangNode event to NetworkNode.
847 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500848 * @param yangNodeEvent yangNodeEvent
Hesam Rahimi41208102016-12-09 17:54:03 -0500849 * @param teTopologyService teTopologyService
850 * @return NetworkNode
851 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500852 public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent,
853 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500854 KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId();
855
Ray Milkey8cd9a662016-11-30 16:55:40 -0800856 org.onosproject.tetopology.management.api.Network network = teTopologyService.network(
857 yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500858 if (network == null) {
859 return null;
860 }
861
862 NetworkNode networkNode = network.node(networkNodeId);
863 if (networkNode == null) {
864 return null;
865 }
866
867 List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds();
868 Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints();
869
870 TeNode teNode = networkNode.teNode();
871 if (teNode == null) {
872 return null;
873 }
874
875 TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode);
876
877 NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps);
878
879 return updatedNetworkNode;
880 }
881
882 private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) {
883
884 long teNodeId = oldTeNode.teNodeId();
885 TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId();
886 TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId();
887 TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId();
888 Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices();
889 List<Long> teLinkIds = oldTeNode.teLinkIds();
890 Map<Long, org.onosproject.tetopology.management.
891 api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints();
892 List<Long> teTpIds = oldTeNode.teLinkIds();
893 String name = oldTeNode.name();
894 TeStatus adminStatus = oldTeNode.adminStatus();
895 TeStatus opStatus = oldTeNode.opStatus();
896 BitSet flags = oldTeNode.flags();
897
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500898 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500899 .tenodeconfigattributesnotification
900 .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes();
901
902 if (yangTeNodeAttrs != null) {
903 TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus();
904 if (yangAdminStatus != null) {
905 adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus);
906 }
907
908 BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags();
909 if (yangFlags != null) {
910 flags = yangFlags;
911 }
912
913 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500914 ietf.te.topology.rev20170110.ietftetopology
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500915 .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs
916 .connectivityMatrix();
917 if (yangConnMatrices != null) {
918 for (org.onosproject.yang.gen.v1.
919 urn.ietf.params.xml.ns.yang.
920 ietf.te.topology
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500921 .rev20170110.ietftetopology
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500922 .tenodeconnectivitymatrixabs
923 .ConnectivityMatrix yangConnMatrix : yangConnMatrices) {
924 Long cmId = new Long(yangConnMatrix.id());
925 ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id()));
926 if (oldConnMatrix != null) {
927 ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix,
928 oldConnMatrix);
929 connMatrices.remove(cmId);
930 connMatrices.put(cmId, newConnMatrix);
931 }
932 }
933 }
934 }
935
936 CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags);
937 TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData,
938 connMatrices, teLinkIds, ttps, teTpIds);
939
940 return updatedTeNode;
941 }
942
943 private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500944 urn.ietf.params.xml.ns.yang.
945 ietf.te.topology
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500946 .rev20170110.ietftetopology
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500947 .tenodeconnectivitymatrixabs
948 .ConnectivityMatrix yangConnMatrix,
949 ConnectivityMatrix oldTeConnMatrix) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500950
951 long id = yangConnMatrix.id();
952 ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef()));
953 UnderlayAbstractPath underlayPath = null;
954 List<ElementType> mergingList = Lists.newArrayList();
955
956 List<ElementType> constrainingElements = Lists.newArrayList();
957 ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef()));
958 constrainingElements.add(to);
959
960 BitSet flags = oldTeConnMatrix.flags();
961
962 TePathAttributes teAttributes = oldTeConnMatrix.teAttributes();
963
964 ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id,
965 from,
966 mergingList,
967 constrainingElements,
968 flags,
969 teAttributes,
970 underlayPath);
971 return updatedConnMatrix;
Yixiao Chen39828a62016-09-14 14:37:06 -0400972 }
973}