blob: 4a2e87f2255bbe276657cb21f552db4402f3a751 [file] [log] [blame]
Yixiao Chen39828a62016-09-14 14:37:06 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Yixiao Chen39828a62016-09-14 14:37:06 -04003 *
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;
Aihua Guo6026b352017-02-08 17:26:54 -050030import org.onosproject.tetopology.management.api.TeConstants;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050031import org.onosproject.tetopology.management.api.TeStatus;
32import org.onosproject.tetopology.management.api.TeTopologyKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050033import org.onosproject.tetopology.management.api.TeTopologyService;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050034import org.onosproject.tetopology.management.api.link.ElementType;
Aihua Guo6026b352017-02-08 17:26:54 -050035import org.onosproject.tetopology.management.api.link.NetworkLink;
36import org.onosproject.tetopology.management.api.link.NetworkLinkKey;
37import org.onosproject.tetopology.management.api.link.TeIpv4;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050038import org.onosproject.tetopology.management.api.link.TeLinkId;
Aihua Guo6026b352017-02-08 17:26:54 -050039import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050040import org.onosproject.tetopology.management.api.link.TePathAttributes;
41import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath;
42import org.onosproject.tetopology.management.api.node.CommonNodeData;
43import org.onosproject.tetopology.management.api.node.ConnectivityMatrix;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050044import org.onosproject.tetopology.management.api.node.DefaultNetworkNode;
45import org.onosproject.tetopology.management.api.node.DefaultTeNode;
46import org.onosproject.tetopology.management.api.node.LocalLinkConnectivity;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050047import org.onosproject.tetopology.management.api.node.NetworkNode;
Hesam Rahimi41208102016-12-09 17:54:03 -050048import org.onosproject.tetopology.management.api.node.NetworkNodeEventSubject;
Yixiao Chen39828a62016-09-14 14:37:06 -040049import org.onosproject.tetopology.management.api.node.NetworkNodeKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050050import org.onosproject.tetopology.management.api.node.TeNode;
51import org.onosproject.tetopology.management.api.node.TeNodeKey;
52import org.onosproject.tetopology.management.api.node.TerminationPoint;
Aihua Guo6026b352017-02-08 17:26:54 -050053import org.onosproject.tetopology.management.api.node.TtpKey;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050054import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName;
Aihua Guo6026b352017-02-08 17:26:54 -050055import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.IpAddress;
Yixiao Chen39828a62016-09-14 14:37:06 -040056import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050057import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks;
Hesam Rahimi39bdc002016-11-10 15:01:26 -050058import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId;
59import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050060import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
61 .ietfnetwork.networks.network.DefaultNode;
62import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
63 .ietfnetwork.networks.network.Node;
64import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
65 .ietfnetwork.networks.network.node.DefaultSupportingNode;
66import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208
67 .ietfnetwork.networks.network.node.SupportingNode;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050068import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
69 .ietfnetworktopology.networks.network.node.AugmentedNdNode;
70import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208
71 .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050072import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.DefaultTeNodeEvent;
73import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.TeNodeEvent;
Aihua Guo6026b352017-02-08 17:26:54 -050074import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.connectivitymatrixentryattributes.DefaultUnderlay;
75import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.connectivitymatrixentryattributes.Underlay;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050076import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.DefaultInformationSourceState;
77import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.InformationSourceState;
78import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.informationsourcestate.DefaultTopology;
79import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.informationsourcestate.Topology;
80import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050081 .ietftetopology.networks.network.node.AugmentedNwNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050082import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -050083 .ietftetopology.networks.network.node.DefaultAugmentedNwNode;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050084import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint;
Aihua Guo6026b352017-02-08 17:26:54 -050085import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs;
86import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.TeSrlgs;
87import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.DefaultPrimaryPath;
88import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.PrimaryPath;
89import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.primarypath.DefaultPathElement;
90import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.primarypath.PathElement;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -050091import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.DefaultTe;
92import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.DefaultTe.TeBuilder;
93import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.Te;
94import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.Config;
95import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultConfig;
96import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultState;
97import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint;
98import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.State;
99import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.TunnelTerminationPoint;
Aihua Guo6026b352017-02-08 17:26:54 -0500100import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultSupportingTunnelTerminationPoint;
101import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.tunnelterminationpoint.SupportingTunnelTerminationPoint;
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500102import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes;
103import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.TeNodeAttributes;
104import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.TeNodeAttributes.TeNodeAttributesBuilder;
105import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.ConnectivityMatrices;
106import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrices;
107import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrices.ConnectivityMatricesBuilder;
108import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.DefaultConnectivityMatrix;
109import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.DefaultConnectivityMatrix.ConnectivityMatrixBuilder;
110import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.connectivitymatrix.DefaultFrom;
111import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.connectivitymatrix.DefaultTo;
112import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology;
113import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeinfoattributes.UnderlayTopology;
114import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.DefaultLocalLinkConnectivities;
115import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.LocalLinkConnectivities;
Aihua Guo6026b352017-02-08 17:26:54 -0500116import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities.DefaultLocalLinkConnectivity;
117import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities.DefaultLocalLinkConnectivity.LocalLinkConnectivityBuilder;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500118import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg;
119import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus;
120import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500121import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType;
Aihua Guo6026b352017-02-08 17:26:54 -0500122import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.AsNumber;
123import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultAsNumber;
124import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink;
125import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.Ipv4Address;
126import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.UnnumberedLink;
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500127import 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 -0500128import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.ietfyangtypes.DottedQuad;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500129
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500130import com.google.common.collect.Lists;
131import com.google.common.collect.Maps;
Yixiao Chen39828a62016-09-14 14:37:06 -0400132
133/**
134 * Node conversion functions.
135 */
136public final class NodeConverter {
137
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500138 private static final String E_NULL_TE_SUBSYSTEM_TE_NODE =
139 "TeSubsystem teNode object cannot be null";
140 private static final String E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP =
141 "TeSubsystem teTunnelTp object cannot be null";
142 private static final String E_NULL_TE_SUBSYSTEM_NODE =
143 "TeSubsystem ndoe object cannot be null";
144 private static final String E_NULL_YANG_NODE =
145 "Yang node object cannot be null";
Yixiao Chen39828a62016-09-14 14:37:06 -0400146
147 // no instantiation
148 private NodeConverter() {
149 }
150
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500151 /**
152 * TE Node Config object conversion from TE Topology subsystem to YANG.
153 *
154 * @param teSubsystemTeNode TE node object
Hesam Rahimi41208102016-12-09 17:54:03 -0500155 * @param teTopologyService teTopolog core service
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500156 * @return TE Node Config YANG object
157 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500158 private static Config teNode2YangConfig(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500159 checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE);
160
161 TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesConfigBuilder = DefaultTeNodeAttributes
162 .builder();
163 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
164 .isAbstract(teSubsystemTeNode.flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500165 .get(TeNode.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500166
167 if (teSubsystemTeNode.adminStatus() != null) {
168 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
169 .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus()));
170 }
171
172 if (teSubsystemTeNode.name() != null) {
173 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
174 .name(DomainName.fromString(teSubsystemTeNode.name()));
175 }
176
177 if (teSubsystemTeNode.underlayTeTopologyId() != null) {
178 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
179 .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500180 .underlayTeTopologyId(), teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500181 }
182
183 // TODO: should we ignore this from te to yang? as we've already set yang supportingNode
Ray Milkey8cd9a662016-11-30 16:55:40 -0800184 //if (teSubsystemTeNode.supportingTeNodeId() != null) {
185 //}
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500186
187 if (teSubsystemTeNode.connectivityMatrices() != null) {
188 teNodeAttributesConfigBuilder = te2YangConnectivityMatrix(teNodeAttributesConfigBuilder,
189 teSubsystemTeNode.connectivityMatrices());
190 }
191
192
193 Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder();
194 yangConfigBuilder = yangConfigBuilder.teNodeAttributes(teNodeAttributesConfigBuilder.build());
195
196 return yangConfigBuilder.build();
197 }
198
199 private static TeNodeAttributesBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500200 te2YangConnectivityMatrix(TeNodeAttributesBuilder teNodeAttributesConfigBuilder,
201 Map<Long, ConnectivityMatrix> connectivityMatrices) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500202 ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = DefaultConnectivityMatrix.builder();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500203 ConnectivityMatricesBuilder yangConnectivityMatricesBuilder = DefaultConnectivityMatrices.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500204 for (Map.Entry<Long, ConnectivityMatrix> teCmEntry :
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500205 connectivityMatrices.entrySet()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500206 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
207 .id(teCmEntry.getKey())
208 .isAllowed(!teCmEntry.getValue().flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500209 .get(ConnectivityMatrix.BIT_DISALLOWED))
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500210 .from(new DefaultFrom.FromBuilder() // TODO: for now, assuming that there is
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500211 // only one 'from', and mergingList is empty
212 .tpRef(((TeLinkId) teCmEntry.getValue().from()).value())
213 .build())
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500214 .to(new DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500215 // one item in constrainingElements list
216 .tpRef(((TeLinkId) teCmEntry.getValue().constrainingElements().get(0)).value())
217 .build());
Aihua Guo6026b352017-02-08 17:26:54 -0500218 if (teCmEntry.getValue().teAttributes() != null) {
219 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
220 .teDefaultMetric(teCmEntry.getValue().teAttributes().cost())
221 .teDelayMetric(teCmEntry.getValue().teAttributes().delay());
222 }
223
224 TeSrlgs.TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder();
225 if (teCmEntry.getValue().teAttributes().srlgs() != null) {
226 for (Long val : teCmEntry.getValue().teAttributes().srlgs()) {
227 Srlg srlg = new Srlg(val);
228 teSrlgsBuilder = teSrlgsBuilder.addToValue(srlg);
229 }
230 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
231 .teSrlgs(teSrlgsBuilder.build());
232 }
233
234 Underlay.UnderlayBuilder underlayBuilder = DefaultUnderlay.builder();
235 PrimaryPath.PrimaryPathBuilder primaryPathBuilder = DefaultPrimaryPath.builder();
236
237 PathElement.PathElementBuilder pathElementBuilder = DefaultPathElement.builder();
238 if (teCmEntry.getValue().underlayPath() != null &&
239 teCmEntry.getValue().underlayPath().pathElements() != null &&
240 !teCmEntry.getValue().underlayPath().pathElements().isEmpty()) {
241 for (org.onosproject.tetopology.management.api.link.PathElement patel : teCmEntry.getValue()
242 .underlayPath().pathElements()) {
243 pathElementBuilder = pathElementBuilder.pathElementId(patel.pathElementId());
244 if (patel.type() instanceof AsNumber) {
245 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes
246 .explicitroutesubobject.type.AsNumber
247 .AsNumberBuilder asNumberBuilder = new DefaultAsNumber.AsNumberBuilder();
248 asNumberBuilder = asNumberBuilder.asNumber(((AsNumber) patel.type()).asNumber());
249 pathElementBuilder = pathElementBuilder.type(asNumberBuilder.build());
250 } else if (patel.type() instanceof UnnumberedLink) {
251 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes
252 .explicitroutesubobject.type.UnnumberedLink
253 .UnnumberedLinkBuilder unNumberBuilder = DefaultUnnumberedLink.builder();
254 unNumberBuilder = unNumberBuilder.interfaceId(((UnnumberedLink) patel.type()).interfaceId());
255 unNumberBuilder = unNumberBuilder.routerId(IpAddress.fromString(((UnnumberedLink) patel.type())
256 .routerId().toString()));
257 pathElementBuilder = pathElementBuilder.type(unNumberBuilder.build());
258 }
259 primaryPathBuilder = primaryPathBuilder
260 .addToPathElement(pathElementBuilder.build());
261 }
262 }
263
264 underlayBuilder = underlayBuilder.primaryPath(primaryPathBuilder.build());
265 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
266 .underlay(underlayBuilder.build());
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500267
268 yangConnectivityMatricesBuilder = yangConnectivityMatricesBuilder
269 .addToConnectivityMatrix(connectivityMatrixConfigBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500270 }
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500271 teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder
272 .connectivityMatrices(yangConnectivityMatricesBuilder.build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500273 return teNodeAttributesConfigBuilder;
274 }
275
Hesam Rahimi41208102016-12-09 17:54:03 -0500276 private static UnderlayTopology teNode2YangUnderlay(TeTopologyKey underlayTopology,
277 TeTopologyService teTopologyService) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500278 UnderlayTopology.UnderlayTopologyBuilder underlayBuilder = DefaultUnderlayTopology.builder();
Hesam Rahimi41208102016-12-09 17:54:03 -0500279
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500280 underlayBuilder = underlayBuilder.networkRef(teTopologyService.networkId(underlayTopology));
Hesam Rahimi41208102016-12-09 17:54:03 -0500281
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500282 return underlayBuilder.build();
283 }
284
285 /**
286 * TE Node State object conversion from TE Topology subsystem to YANG.
287 *
288 * @param teSubsystemTeNode TE node object
Hesam Rahimi41208102016-12-09 17:54:03 -0500289 * @param teTopologyService teTopology core service
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500290 * @return TE Node State YANG object
291 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500292 private static State teNode2YangState(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500293 checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE);
294
295 TeNodeAttributes
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500296 .TeNodeAttributesBuilder teNodeAttributesStateBuilder =
297 DefaultTeNodeAttributes.builder()
298 .isAbstract(teSubsystemTeNode.flags()
299 .get(TeNode.BIT_ABSTRACT));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500300
301 if (teSubsystemTeNode.adminStatus() != null) {
302 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
303 .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus()));
304 }
305
306 if (teSubsystemTeNode.name() != null) {
307 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
308 .name(DomainName.fromString(teSubsystemTeNode.name()));
309 }
310
311 if (teSubsystemTeNode.underlayTeTopologyId() != null) {
312 teNodeAttributesStateBuilder = teNodeAttributesStateBuilder
313 .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500314 .underlayTeTopologyId(), teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500315 }
316
317 if (teSubsystemTeNode.connectivityMatrices() != null) {
318 teNodeAttributesStateBuilder = te2YangConnectivityMatrix(teNodeAttributesStateBuilder,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500319 teSubsystemTeNode.connectivityMatrices());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500320 }
321
322 // TODO: should we ignore this from te to yang? as we've already set yang supportingNode
Ray Milkey8cd9a662016-11-30 16:55:40 -0800323 //if (teSubsystemTeNode.supportingTeNodeId() != null) {
324 //}
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500325
326 State.StateBuilder yangStateBuilder = DefaultState.builder();
327 yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build());
328
329 if (teSubsystemTeNode.opStatus() != null) {
330 yangStateBuilder = yangStateBuilder.operStatus(EnumConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500331 .teSubsystem2YangOperStatus(teSubsystemTeNode.opStatus()));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500332 }
333
334 if (teSubsystemTeNode.sourceTeNodeId() != null) {
335 InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder();
336
337 Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500338 topologyBuilder = topologyBuilder.nodeRef(teTopologyService
339 .nodeKey(teSubsystemTeNode.sourceTeNodeId()).nodeId())
340 .networkRef(teTopologyService
341 .nodeKey(teSubsystemTeNode.sourceTeNodeId())
342 .networkId());
343
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500344 issBuilder = issBuilder.topology(topologyBuilder.build());
345 yangStateBuilder.informationSourceState(issBuilder.build());
346 }
347
348 return yangStateBuilder.build();
349 }
350
351 private static class ByteUtils {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500352
353 public static byte[] longToBytes(long x) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500354 long temp = x;
355 byte[] b = new byte[8];
356 for (int i = 0; i < b.length; i++) {
357 b[i] = new Long(temp & 0xff).byteValue();
358 temp = temp >> 8;
359 }
360 return b;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500361 }
362
363 public static long bytesToLong(byte[] bytes) {
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500364 return (bytes[7] & 255L) << 56
365 | (bytes[6] & 255L) << 48
366 | (bytes[5] & 255L) << 40
367 | (bytes[4] & 255L) << 32
368 | (bytes[3] & 255L) << 24
369 | (bytes[2] & 255L) << 16
370 | (bytes[1] & 255L) << 8 | bytes[0] & 255L;
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500371 }
372 }
373
374 /**
375 * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG.
376 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500377 * @param teTunnelTp TE TunnelTerminationPoint object
Hesam Rahimi41208102016-12-09 17:54:03 -0500378 * @param teTpId
379 * @param teTopologyService
380 * @param teNodeKey
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500381 * @return TunnelTerminationPoint YANG object
382 */
383 private static TunnelTerminationPoint teSubsystem2YangTtp(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500384 org.onosproject.tetopology.management.api.node
385 .TunnelTerminationPoint teTunnelTp, Long teTpId,
386 TeTopologyService teTopologyService,
387 TeNodeKey teNodeKey) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500388 checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP);
389
390 TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder =
391 DefaultTunnelTerminationPoint.builder().tunnelTpId(ByteUtils.longToBytes(teTpId.longValue()));
392
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500393 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500394 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.Config.ConfigBuilder ttpConfigBuilder =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500395 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500396 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500397 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500398 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.State.StateBuilder ttpStateBuilder =
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500399 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500400 .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500401
402 // Assuming teTunnelTp only has one interLayerLock
403 if (teTunnelTp.interLayerLockList() != null && !teTunnelTp.interLayerLockList().isEmpty()) {
404 ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0));
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500405 ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500406 }
407
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500408 // TODO: retrieve teTunnelTp.switchingLayer() and set it to ttpConfigBuilder and ttpStateBuilder
409 // TODO: retrieve more attributes from teTunnelTp and assign to ttpConfigBuilder and ttpStateBuilder
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500410 // For which ones we can do the conversion?
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500411
412 LocalLinkConnectivities.LocalLinkConnectivitiesBuilder
413 localLinkConnectivitiesBuilder = DefaultLocalLinkConnectivities.builder();
Hesam Rahimi41208102016-12-09 17:54:03 -0500414 if (teTunnelTp.localLinkConnectivityList() != null && !teTunnelTp.localLinkConnectivityList().isEmpty()) {
Aihua Guo6026b352017-02-08 17:26:54 -0500415 for (LocalLinkConnectivity llcn : teTunnelTp.localLinkConnectivityList()) {
416 // convert teLinkId to networkLinkKey
417 if (llcn != null && llcn.constrainingElements() != null
418 && !llcn.constrainingElements().isEmpty()) {
419 TeLinkId telinkId = (TeLinkId) llcn.constrainingElements().get(0);
420 TeLinkTpGlobalKey globalKey = new TeLinkTpGlobalKey(teNodeKey, telinkId.value());
421 NetworkLinkKey netLinkKey = teTopologyService.linkKey(globalKey);
422 NetworkLink networkLink = teTopologyService
423 .network(netLinkKey.networkId()).links().get(netLinkKey.linkId());
424 LocalLinkConnectivityBuilder llcBuilder = DefaultLocalLinkConnectivity.builder();
425 llcBuilder = llcBuilder.linkTpRef(networkLink.source().tpId());
426 localLinkConnectivitiesBuilder.addToLocalLinkConnectivity(llcBuilder.build());
427 }
428 }
429
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500430
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500431 ttpConfigBuilder = ttpConfigBuilder.localLinkConnectivities(localLinkConnectivitiesBuilder.build());
432 ttpStateBuilder = ttpStateBuilder.localLinkConnectivities(localLinkConnectivitiesBuilder.build());
Hesam Rahimi41208102016-12-09 17:54:03 -0500433 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500434
435 tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500436 .state(ttpStateBuilder.build());
Aihua Guo6026b352017-02-08 17:26:54 -0500437 SupportingTunnelTerminationPoint.SupportingTunnelTerminationPointBuilder
438 supportTtpBuilder = DefaultSupportingTunnelTerminationPoint.builder();
439 if (teTunnelTp.supportingTtpId() != null) {
440 TeTopologyKey teTopologyKey = new TeTopologyKey(teTunnelTp.supportingTtpId().providerId(),
441 teTunnelTp.supportingTtpId().clientId(),
442 teTunnelTp.supportingTtpId().topologyId());
443
444 TeNodeKey teNodeKeySup = new TeNodeKey(teTopologyKey, teTunnelTp.supportingTtpId().teNodeId());
445 NetworkNodeKey networkNodeKey = teTopologyService.nodeKey(teNodeKeySup);
446 NetworkId netId = NetworkId.fromString(networkNodeKey.networkId().toString());
447
448 supportTtpBuilder = supportTtpBuilder
449 .nodeRef(NodeId.fromString(networkNodeKey.nodeId().toString()))
450 .networkRef(netId)
451 .tunnelTpRef(ByteUtils.longToBytes(teTunnelTp.supportingTtpId().ttpId()));
452
453 tunnelTpBuilder = tunnelTpBuilder.addToSupportingTunnelTerminationPoint(supportTtpBuilder.build());
454 }
455
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500456
457 return tunnelTpBuilder.build();
458 }
Yixiao Chen39828a62016-09-14 14:37:06 -0400459
460 /**
461 * Node object conversion from TE Topology subsystem to YANG.
462 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500463 * @param teSubsystem TE subsystem node
Hesam Rahimi41208102016-12-09 17:54:03 -0500464 * @param teTopologyService teTopology core service
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500465 * @param teTopologyKey teTopologyKey
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500466 * @return YANG node
Yixiao Chen39828a62016-09-14 14:37:06 -0400467 */
Hesam Rahimi41208102016-12-09 17:54:03 -0500468 public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem,
469 TeTopologyService teTopologyService,
470 TeTopologyKey teTopologyKey) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500471 checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE);
472
473 NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString());
Hesam Rahimi41208102016-12-09 17:54:03 -0500474
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500475 Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId);
476
477 if (teSubsystem.supportingNodeIds() != null) {
478 List<SupportingNode> sNodes = Lists.newArrayList();
479 SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode
480 .builder();
481 for (NetworkNodeKey nodeKey : teSubsystem.supportingNodeIds()) {
482 sNodes.add(spNodeBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500483 .networkRef(NetworkId
484 .fromString(nodeKey.networkId().toString()))
485 .nodeRef(NodeId.fromString(nodeKey.nodeId().toString()))
486 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500487 }
488 builder = builder.supportingNode(sNodes);
489 }
490
491 if (teSubsystem.terminationPoints() != null) {
492 AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode
493 .builder();
494 Map<KeyId, TerminationPoint> teSubsystemTeTp = teSubsystem
495 .terminationPoints();
496
497 for (TerminationPoint teTp : teSubsystemTeTp.values()) {
498 tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500499 .teSubsystem2YangTerminationPoint(teTp));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500500 }
501 builder.addYangAugmentedInfo(tpAugmentBuilder.build(),
502 AugmentedNdNode.class);
503 }
504
505 if (teSubsystem.teNode() != null) {
506 AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode
507 .builder();
508
509 TeNode teSubsystemTeNode = teSubsystem.teNode();
510
511 TeBuilder yangTeBuilder = DefaultTe.builder();
512
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500513 nodeAugmentBuilder = nodeAugmentBuilder
514 .teNodeId(TeNodeId.of(DottedQuad.of(Ip4Address
515 .valueOf((int) teSubsystemTeNode.teNodeId())
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500516 .toString())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500517
518 // Set configuration data
519 // Set state data
Hesam Rahimi41208102016-12-09 17:54:03 -0500520 yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode, teTopologyService))
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500521 .state(teNode2YangState(teSubsystemTeNode, teTopologyService));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500522
523 if (teSubsystemTeNode.tunnelTerminationPoints() != null) {
524 for (Map.Entry<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> entry :
525 teSubsystemTeNode.tunnelTerminationPoints().entrySet()) {
526 yangTeBuilder = yangTeBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500527 .addToTunnelTerminationPoint(teSubsystem2YangTtp(entry
528 .getValue(), entry.getKey(), teTopologyService,
529 new TeNodeKey(teTopologyKey, teSubsystemTeNode.teNodeId())));
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500530 }
531 }
532
533 nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build());
534 builder.addYangAugmentedInfo(nodeAugmentBuilder.build(),
535 AugmentedNwNode.class);
536 }
537 return builder.build();
Yixiao Chen39828a62016-09-14 14:37:06 -0400538 }
539
540 /**
541 * Node object conversion from YANG to TE Topology subsystem.
542 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500543 * @param yangNode Node in YANG model
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500544 * @param yangNetwork YANG network
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500545 * @param yangNetworks YANG networks
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500546 * @return TE subsystem node
Yixiao Chen39828a62016-09-14 14:37:06 -0400547 */
548 public static org.onosproject.tetopology.management.api.node.NetworkNode
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500549 yang2TeSubsystemNode(Node yangNode, Network yangNetwork,
550 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500551 checkNotNull(yangNode, E_NULL_YANG_NODE);
Yixiao Chen39828a62016-09-14 14:37:06 -0400552
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500553 org.onosproject.tetopology.management.api.node.DefaultNetworkNode node;
554 List<NetworkNodeKey> spNodes = null;
555 TeNode teNode = null;
556 Map<KeyId, TerminationPoint> tps = null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400557
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500558 if (yangNode.supportingNode() != null) {
559 spNodes = Lists.newArrayList();
560 for (SupportingNode yangSpNode : yangNode.supportingNode()) {
561 NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()),
562 KeyId.keyId(yangSpNode.networkRef().uri().toString()));
563 spNodes.add(nodeKey);
564 }
565 }
566
567 if (yangNode.yangAugmentedInfoMap() != null
568 && !yangNode.yangAugmentedInfoMap().isEmpty()) {
569
570 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
571 .yangAugmentedInfo(AugmentedNdNode.class);
572 if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) {
573 tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment);
574 }
575
576 AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode
577 .yangAugmentedInfo(AugmentedNwNode.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500578 if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.teNodeId() != null) {
579 TeNodeId teNodeId = yangNodeAugment.teNodeId();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500580 Te yangNodeAugTe = yangNodeAugment.te();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500581 teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, teNodeId,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500582 yangNetwork,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500583 yangNetworks,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500584 yangNode,
585 tps);
586 }
587 }
588
589 node = new org.onosproject.tetopology.management.api.node
590 .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps);
591 return node;
592 }
593
594 // TODO: convert connectivity matrix from yang to te
595 private static Map<Long, ConnectivityMatrix>
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500596 yang2TeSubsystemNodeConnectivityMatrix(String networkId,
597 String nodeId,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500598 ConnectivityMatrices yangMatrices) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500599
600 Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap();
601
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500602 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
603 .tenodeconnectivitymatrix.connectivitymatrices.ConnectivityMatrix>
604 yangMatrix = yangMatrices.connectivityMatrix();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500605 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500606 .topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500607 ConnectivityMatrix cmYang : yangMatrix) {
608
Hesam Rahimi41208102016-12-09 17:54:03 -0500609 ElementType from = new TeLinkId(Long.valueOf(((String) cmYang.from().tpRef()))); // is this correct?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500610
611 UnderlayAbstractPath underlayPath = null; // ignore
Aihua Guo6026b352017-02-08 17:26:54 -0500612 List<org.onosproject.tetopology.management.api.link.PathElement> pathElements = Lists.newArrayList();
613 Boolean loose = false;
614 long longTeNodeId = TeConstants.NIL_LONG_VALUE;
615 if (cmYang != null && cmYang.underlay() != null && cmYang.underlay().primaryPath() != null
616 && cmYang.underlay().primaryPath().pathElement() != null
617 && !cmYang.underlay().primaryPath().pathElement().isEmpty()) {
618 for (PathElement yangPathEl : cmYang.underlay().primaryPath().pathElement()) {
619 ElementType type = null;
620 if (yangPathEl.type() instanceof UnnumberedLink) {
621 String rS = ((UnnumberedLink) (yangPathEl.type())).routerId().toString();
622 org.onlab.packet.IpAddress routerId = org.onlab.packet.IpAddress.valueOf(rS);
623 long interfaceId = ((UnnumberedLink) yangPathEl.type()).interfaceId();
624 type = new org.onosproject.tetopology.management.api.link.UnnumberedLink(routerId, interfaceId);
625 longTeNodeId = Long.valueOf(((UnnumberedLink) yangPathEl.type()).routerId().toString());
626 } else if (yangPathEl.type() instanceof Ipv4Address) {
627 short v4PrefixLength = ((Ipv4Address) yangPathEl.type())
628 .v4PrefixLength();
629
630 Ip4Address v4Address = Ip4Address
631 .valueOf(((Ipv4Address) yangPathEl.type())
632 .v4Address().string());
633
634 loose = ((Ipv4Address) yangPathEl.type()).v4Loose();
635 type = new TeIpv4(v4Address, v4PrefixLength);
636 }
637 org.onosproject.tetopology.management.api.link.PathElement
638 patel = new org.onosproject.tetopology.management.api.link
639 .PathElement(yangPathEl.pathElementId(),
640 longTeNodeId,
641 type,
642 loose);
643 pathElements.add(patel);
644 }
645 }
646 underlayPath = new UnderlayAbstractPath(pathElements, loose);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500647
648 List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now
649
650 List<ElementType> constrainingElements = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500651 ElementType to = new TeLinkId(Long.valueOf(((String) cmYang.to().tpRef()))); // is this correct?
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500652 constrainingElements.add(to);
653
654 BitSet flags = new BitSet(); // what are the flags in cmYang?
655
656 List<Long> srlgs = Lists.newArrayList();
657 if (cmYang.teSrlgs() != null) {
658 for (Srlg srlg : cmYang.teSrlgs().value()) {
659 srlgs.add(srlg.uint32());
660 }
661 }
662 TePathAttributes teAttributes = new
663 TePathAttributes(cmYang.teDefaultMetric(),
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500664 cmYang.teDelayMetric(),
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500665 srlgs);
666 ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(),
667 from,
Ray Milkey8cd9a662016-11-30 16:55:40 -0800668 mergingList,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500669 constrainingElements,
670 flags,
Ray Milkey8cd9a662016-11-30 16:55:40 -0800671 teAttributes,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500672 underlayPath);
673
674 teCmList.put(cmYang.id(), coreCm);
675 }
676
677 return teCmList;
678 }
679
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500680 private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut, Networks yangNetworks) {
681 TeTopologyKey tetopokey = LinkConverter.findTopologyId(yangNetworks,
682 ut.networkRef());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500683 return tetopokey;
684 }
685
686 // TODO: retrieve the details of tunnel termiantion points from yang to te
687 private static Map<Long, org.onosproject.tetopology.management.api.node.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500688 TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps, Node yangNode,
689 Networks yangNetworks) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500690 Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps
691 .newHashMap();
692 for (TunnelTerminationPoint ttpYang : ttps) {
693
694 SwitchingType switchingLayer = null; // how to find switching type?
695 EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding();
696 BitSet flags = new BitSet(); // how to set flags?
697 List<Long> interLayerLockList = Lists.newArrayList();
Hesam Rahimi41208102016-12-09 17:54:03 -0500698
699 if (ttpYang.config() != null) {
700 interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list
701 }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500702
703 List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList();
704 // FIXME: once new yang model is used, we can make llc
Hesam Rahimi41208102016-12-09 17:54:03 -0500705 ElementType elt = null;
706 List<ElementType> eltList = Lists.newArrayList();
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500707 if (ttpYang.config() != null &&
708 ttpYang.config().localLinkConnectivities() != null &&
709 CollectionUtils.isNotEmpty(ttpYang.config().localLinkConnectivities().localLinkConnectivity())) {
710 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
711 .ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities
712 .LocalLinkConnectivity yangLlc : ttpYang.config()
713 .localLinkConnectivities().localLinkConnectivity()) {
714 if (MapUtils.isNotEmpty(yangNode.yangAugmentedInfoMap())) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500715 AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
716 .yangAugmentedInfo(AugmentedNdNode.class);
717 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml
718 .ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology
719 .networks.network.node.augmentedndnode
720 .TerminationPoint tpItem : yangTpNodeAugment.terminationPoint()) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500721 if (tpItem.tpId().uri().string().equals(yangLlc.linkTpRef().toString())) {
Hesam Rahimi41208102016-12-09 17:54:03 -0500722 if (tpItem.yangAugmentedInfoMap() != null
723 && !tpItem.yangAugmentedInfoMap().isEmpty()) {
724 AugmentedNtTerminationPoint yangTpAugment =
725 (AugmentedNtTerminationPoint) tpItem
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500726 .yangAugmentedInfo(AugmentedNtTerminationPoint.class);
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500727 if (yangTpAugment.teTpId() != null) {
728 elt = new TeLinkId(Long.valueOf(yangTpAugment.teTpId().toString()));
Hesam Rahimi41208102016-12-09 17:54:03 -0500729 break;
730 }
731 }
732 }
733 }
734 }
735 eltList.add(elt);
736// tercap.linkTp().toString() //tpId -> tp -> te-tp-id (long)
737 }
738 }
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500739
Hesam Rahimi41208102016-12-09 17:54:03 -0500740 TePathAttributes teAttributes = null; // how to find these
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500741 // attributes from ttpYang?
Hesam Rahimi41208102016-12-09 17:54:03 -0500742 UnderlayAbstractPath underlayPath = null; // how to find underlayAbstractPath from ttpYang?
743 LocalLinkConnectivity llc = new LocalLinkConnectivity(eltList,
744 flags,
745 teAttributes,
746 underlayPath);
747 localLinkConnectivityList.add(llc);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500748
749 float[] availAdaptBandwidth = null; // how to find availableBandwidth?
750
Aihua Guo6026b352017-02-08 17:26:54 -0500751 TeTopologyKey teTopologyKey = null;
752
753 Object networkRefObj = null;
754 NetworkId networkId = null;
755 if (ttpYang != null && ttpYang.supportingTunnelTerminationPoint() != null
756 && !ttpYang.supportingTunnelTerminationPoint().isEmpty()
757 && ttpYang.supportingTunnelTerminationPoint().get(0) != null) {
758 networkRefObj = ttpYang.supportingTunnelTerminationPoint()
759 .get(0).networkRef();
760 }
761 if (networkRefObj != null) {
762 teTopologyKey = LinkConverter.findTopologyId(yangNetworks,
763 networkRefObj);
764 networkId = NetworkId.fromString((String) networkRefObj);
765 }
766
767 Network teNetworkFound = null;
768 if (yangNetworks.network() != null
769 && !yangNetworks.network().isEmpty()
770 && networkId != null) {
771 for (Network ynetItem : yangNetworks.network()) {
772 if (ynetItem.networkId() != null) {
773 if (ynetItem.networkId().equals(networkId)) {
774 teNetworkFound = ynetItem;
775 break;
776 }
777 }
778 }
779 }
780 TeNodeId teNodeIdSupport = null;
781 if (teNetworkFound != null
782 && ttpYang != null
783 && ttpYang.supportingTunnelTerminationPoint() != null
784 && ttpYang.supportingTunnelTerminationPoint().get(0) != null) {
785
786 String s = ((String) ttpYang.supportingTunnelTerminationPoint().get(0).nodeRef());
787 int integ = Integer.valueOf(s);
788 NodeId nodeId = NodeId.fromString(DottedQuad.of(Ip4Address.valueOf(integ).toString()).toString());
789 teNodeIdSupport = LinkConverter
790 .findTeNodeId(teNetworkFound,
791 nodeId);
792 }
793
794 long tenIdLong = -1;
795 if (teNodeIdSupport != null) {
796 tenIdLong = Ip4Address
797 .valueOf(teNodeIdSupport.dottedQuad().string()).toInt();
798 }
799
800 TeNodeKey teNodeKey = null;
801 if (teTopologyKey != null && tenIdLong != -1) {
802 teNodeKey = new TeNodeKey(teTopologyKey, tenIdLong);
803 }
804 TtpKey supportTtpKey = null;
805 if (teNodeKey != null && ttpYang != null
806 && ttpYang.supportingTunnelTerminationPoint() != null
807 && !ttpYang.supportingTunnelTerminationPoint().isEmpty()
808 && ttpYang.supportingTunnelTerminationPoint().get(0) != null) {
809 supportTtpKey = new TtpKey(teNodeKey,
810 ByteUtils.bytesToLong((byte[]) ttpYang
811 .supportingTunnelTerminationPoint().get(0)
812 .tunnelTpRef()));
813 }
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500814
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500815 org.onosproject.tetopology.management.api.node.
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500816 TunnelTerminationPoint ttpTe = new
817 org.onosproject.tetopology.management.api.node.
818 DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()),
819 switchingLayer,
820 encodingLayer,
821 flags,
822 interLayerLockList,
823 localLinkConnectivityList,
824 availAdaptBandwidth,
Aihua Guo6026b352017-02-08 17:26:54 -0500825 supportTtpKey);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500826
827 ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe);
828 }
829
830 return ttpsMap;
831 }
832
833 private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500834 TeNodeId teNodeId,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500835 Network yangNetwork,
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500836 Networks yangNetworks,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500837 Node yangNode,
Hesam Rahimi41208102016-12-09 17:54:03 -0500838 Map<KeyId, TerminationPoint> teTps) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500839
840
841 NodeId yangNodeId = yangNode.nodeId();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500842
843 NetworkId yangNetworkId = yangNetwork.networkId();
844
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500845 long teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string()).toInt();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500846
847 TeTopologyKey underlayTopologyIdId = null;
848
849 // FIXME: yang has a list of supporting nodes, but TeNode only has one
850 // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId?
851 TeNodeKey supportTeNodeId = null;
852// supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId)
853// yangSupportNodes.get(0).
854
855 TeNodeKey sourceTeNodeId = null; //ignore
856 CommonNodeData teData = null;
857 Map<Long, ConnectivityMatrix> connMatrices = null;
858 Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null;
859 List<Long> teLinkIds = Lists.newArrayList();
860 List<Long> teTpIds = Lists.newArrayList();
861
862 // ********************************************** to find teLinkIds
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500863 // teLinkIds should be supposed to get from YANG Link and TP data.
864 // For now, assuming each teTp is sourcing a TE link .
Hesam Rahimi41208102016-12-09 17:54:03 -0500865 if (MapUtils.isNotEmpty(teTps)) {
866 for (Map.Entry<KeyId, TerminationPoint> entry : teTps.entrySet()) {
867 if (entry.getValue().teTpId() != null) {
868 teTpIds.add(entry.getValue().teTpId());
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500869 teLinkIds.add(entry.getValue().teTpId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500870 }
871 }
872 }
873 // ********************************************** to find teTpIds
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500874// if (yangNode.yangAugmentedInfoMap() != null
875// && !yangNode.yangAugmentedInfoMap().isEmpty()) {
876//
877// AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode
878// .yangAugmentedInfo(AugmentedNdNode.class);
879//
880// if (yangTpNodeAugment.terminationPoint() != null) {
881// for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
882// .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
883// yangTpnode : yangTpNodeAugment.terminationPoint()) {
884// teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string()));
885// }
886// }
887// }
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500888 // **********************************************
889
890 Config ynodeAugCfg = yangNodeAugTe.config();
891
892 if (ynodeAugCfg != null) {
893 TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes();
894 if (teNodeAttr != null) {
895
896 if (teNodeAttr.underlayTopology() != null) {
897
898 underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500899 .underlayTopology(), yangNetworks);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500900 }
901 BitSet flags = new BitSet();
902 if (teNodeAttr.isAbstract()) {
903 flags.set(TeNode.BIT_ABSTRACT);
904 }
905 teData = new CommonNodeData(
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500906 null, // teNodeAttr.name().string(),
907 EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()),
908 EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()),
909 flags);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500910
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500911// if (teNodeAttr.connectivityMatrix() != null) {
912 if (teNodeAttr.connectivityMatrices() != null) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500913 connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(),
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500914 yangNodeId.uri().toString(),
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500915 teNodeAttr.connectivityMatrices());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500916 }
917
918 }
919 }
920
921 if (yangNodeAugTe.tunnelTerminationPoint() != null) {
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500922 ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint(),
923 yangNode,
924 yangNetworks);
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500925 }
926
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500927 TeNode teNode = new DefaultTeNode(teNodeIdLong,
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500928 underlayTopologyIdId,
929 supportTeNodeId,
930 sourceTeNodeId,
931 teData,
932 connMatrices,
933 teLinkIds,
934 ttps,
935 teTpIds);
936 return teNode;
937 }
938
939 private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) {
940 Map<KeyId, TerminationPoint> tps;
941 if (yangTpNodeAugment.terminationPoint() != null) {
942 tps = Maps.newHashMap();
943 for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology
944 .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint
945 yangTpnode : yangTpNodeAugment.terminationPoint()) {
946 tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()),
947 TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode));
948 }
949 return tps;
950 }
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500951 return null;
Yixiao Chen39828a62016-09-14 14:37:06 -0400952 }
953
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500954 /**
Hesam Rahimi41208102016-12-09 17:54:03 -0500955 * Converts a TE Topology node event from the data format used in the core
956 * to its corresponding YANG Object (YO) format.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500957 *
958 * @param eventType Node event type
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500959 * @param eventData TE Topology node event data
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500960 * @return YANG Object converted from nodeData
961 */
962 public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType,
Hesam Rahimi41208102016-12-09 17:54:03 -0500963 NetworkNodeEventSubject eventData) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500964 TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder();
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500965
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500966 TeTopologyEventType yangEventType = new TeTopologyEventType(eventType);
967 builder.eventType(yangEventType);
968
Hesam Rahimi41208102016-12-09 17:54:03 -0500969 NetworkId newtorkId = NetworkId.fromString(eventData.key().networkId().toString());
970 builder.networkRef(newtorkId);
971 NodeId nodeId = NodeId.fromString(eventData.key().nodeId().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500972 builder.nodeRef(nodeId);
973
Hesam Rahimi41208102016-12-09 17:54:03 -0500974 NetworkNode node = eventData.neworkNode();
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500975 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500976 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi41208102016-12-09 17:54:03 -0500977 TeNodeAttributes teNodeAttributes = node == null ? null
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500978 : teNode2YangTeNodeAttributes(node.teNode());
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500979 builder.teNodeAttributes(teNodeAttributes);
980
981 return builder.build();
982 }
983
984 private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500985 ietf.te.topology.rev20170110.ietftetopology.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500986 tenodeconfigattributesnotification.
987 TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) {
988
989 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500990 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500991 TeNodeAttributes.TeNodeAttributesBuilder attrBuilder =
992 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500993 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500994 DefaultTeNodeAttributes.builder();
995
996 if (teNode.connectivityMatrices() != null) {
997
Hesam Rahimi01f6ae02017-02-01 13:57:00 -0500998 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500999 .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix
1000 .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001001 params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs.
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001002 DefaultConnectivityMatrix.builder();
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001003 for (Map.Entry<Long, ConnectivityMatrix> teCmEntry :
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001004 teNode.connectivityMatrices().entrySet()) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001005 connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder
1006 .id(teCmEntry.getKey())
1007 .isAllowed(!teCmEntry.getValue().flags()
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001008 .get(ConnectivityMatrix.BIT_DISALLOWED))
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001009 .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001010 .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom
1011 .FromBuilder() // TODO: for now, assuming that there is
1012 // only one 'from', and mergingList is empty
1013 .tpRef(teCmEntry.getValue().from())
1014 .build())
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001015 .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001016 .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix
1017 .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
1018 // one item in constrainingElements list
1019 .tpRef(teCmEntry.getValue().constrainingElements().get(0))
1020 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001021 attrBuilder = attrBuilder
1022 .addToConnectivityMatrix(connectivityMatrixConfigBuilder
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001023 .build());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001024 }
1025 }
1026
1027 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001028 rev20170110.ietftetopology.tenodeconfigattributesnotification.
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001029 TeNodeAttributes teNodeAttributes = attrBuilder.build();
1030
1031 return teNodeAttributes;
1032 }
1033
1034 public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) {
Hesam Rahimi41208102016-12-09 17:54:03 -05001035 NetworkId networkRef = NetworkId.fromString(yangNodeEvent.networkRef().toString());
1036 NodeId nodeRef = NodeId.fromString(yangNodeEvent.nodeRef().toString());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001037 KeyId networkId = KeyId.keyId(networkRef.uri().toString());
1038 KeyId nodeId = KeyId.keyId(nodeRef.uri().toString());
1039
1040 NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId);
1041
1042 return networkNodeKey;
Yixiao Chen39828a62016-09-14 14:37:06 -04001043 }
1044
Hesam Rahimi41208102016-12-09 17:54:03 -05001045 /**
1046 * Converts YangNode event to NetworkNode.
1047 *
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001048 * @param yangNodeEvent yangNodeEvent
Hesam Rahimi41208102016-12-09 17:54:03 -05001049 * @param teTopologyService teTopologyService
1050 * @return NetworkNode
1051 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001052 public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent,
1053 TeTopologyService teTopologyService) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001054 KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId();
1055
Ray Milkey8cd9a662016-11-30 16:55:40 -08001056 org.onosproject.tetopology.management.api.Network network = teTopologyService.network(
1057 yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId());
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001058 if (network == null) {
1059 return null;
1060 }
1061
1062 NetworkNode networkNode = network.node(networkNodeId);
1063 if (networkNode == null) {
1064 return null;
1065 }
1066
1067 List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds();
1068 Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints();
1069
1070 TeNode teNode = networkNode.teNode();
1071 if (teNode == null) {
1072 return null;
1073 }
1074
1075 TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode);
1076
1077 NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps);
1078
1079 return updatedNetworkNode;
1080 }
1081
1082 private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) {
1083
1084 long teNodeId = oldTeNode.teNodeId();
1085 TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId();
1086 TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId();
1087 TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId();
1088 Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices();
1089 List<Long> teLinkIds = oldTeNode.teLinkIds();
1090 Map<Long, org.onosproject.tetopology.management.
1091 api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints();
1092 List<Long> teTpIds = oldTeNode.teLinkIds();
1093 String name = oldTeNode.name();
1094 TeStatus adminStatus = oldTeNode.adminStatus();
1095 TeStatus opStatus = oldTeNode.opStatus();
1096 BitSet flags = oldTeNode.flags();
1097
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001098 org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001099 .tenodeconfigattributesnotification
1100 .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes();
1101
1102 if (yangTeNodeAttrs != null) {
1103 TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus();
1104 if (yangAdminStatus != null) {
1105 adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus);
1106 }
1107
1108 BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags();
1109 if (yangFlags != null) {
1110 flags = yangFlags;
1111 }
1112
1113 List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001114 ietf.te.topology.rev20170110.ietftetopology
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001115 .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs
1116 .connectivityMatrix();
1117 if (yangConnMatrices != null) {
1118 for (org.onosproject.yang.gen.v1.
1119 urn.ietf.params.xml.ns.yang.
1120 ietf.te.topology
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001121 .rev20170110.ietftetopology
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001122 .tenodeconnectivitymatrixabs
1123 .ConnectivityMatrix yangConnMatrix : yangConnMatrices) {
1124 Long cmId = new Long(yangConnMatrix.id());
1125 ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id()));
1126 if (oldConnMatrix != null) {
1127 ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix,
1128 oldConnMatrix);
1129 connMatrices.remove(cmId);
1130 connMatrices.put(cmId, newConnMatrix);
1131 }
1132 }
1133 }
1134 }
1135
1136 CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags);
1137 TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData,
1138 connMatrices, teLinkIds, ttps, teTpIds);
1139
1140 return updatedTeNode;
1141 }
1142
1143 private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1.
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001144 urn.ietf.params.xml.ns.yang.
1145 ietf.te.topology
Hesam Rahimi01f6ae02017-02-01 13:57:00 -05001146 .rev20170110.ietftetopology
Yixiao Chen265b3bb2017-01-13 10:17:03 -05001147 .tenodeconnectivitymatrixabs
1148 .ConnectivityMatrix yangConnMatrix,
1149 ConnectivityMatrix oldTeConnMatrix) {
Hesam Rahimi39bdc002016-11-10 15:01:26 -05001150
1151 long id = yangConnMatrix.id();
1152 ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef()));
1153 UnderlayAbstractPath underlayPath = null;
1154 List<ElementType> mergingList = Lists.newArrayList();
1155
1156 List<ElementType> constrainingElements = Lists.newArrayList();
1157 ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef()));
1158 constrainingElements.add(to);
1159
1160 BitSet flags = oldTeConnMatrix.flags();
1161
1162 TePathAttributes teAttributes = oldTeConnMatrix.teAttributes();
1163
1164 ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id,
1165 from,
1166 mergingList,
1167 constrainingElements,
1168 flags,
1169 teAttributes,
1170 underlayPath);
1171 return updatedConnMatrix;
Yixiao Chen39828a62016-09-14 14:37:06 -04001172 }
1173}