Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.teyang.utils.topology; |
| 17 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 20 | import java.util.BitSet; |
| 21 | import java.util.List; |
| 22 | import java.util.Map; |
| 23 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 24 | import org.apache.commons.collections.MapUtils; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 25 | import org.onlab.packet.Ip4Address; |
| 26 | import org.onosproject.tetopology.management.api.EncodingType; |
| 27 | import org.onosproject.tetopology.management.api.KeyId; |
| 28 | import org.onosproject.tetopology.management.api.SwitchingType; |
| 29 | import org.onosproject.tetopology.management.api.TeStatus; |
| 30 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 31 | import org.onosproject.tetopology.management.api.TeTopologyService; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 32 | import org.onosproject.tetopology.management.api.link.ElementType; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 33 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 34 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 35 | import org.onosproject.tetopology.management.api.link.TeLinkId; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 36 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 37 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 38 | import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath; |
| 39 | import org.onosproject.tetopology.management.api.node.CommonNodeData; |
| 40 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrix; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 41 | import org.onosproject.tetopology.management.api.node.DefaultNetworkNode; |
| 42 | import org.onosproject.tetopology.management.api.node.DefaultTeNode; |
| 43 | import org.onosproject.tetopology.management.api.node.LocalLinkConnectivity; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 44 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 45 | import org.onosproject.tetopology.management.api.node.NetworkNodeEventSubject; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 46 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 47 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 48 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 49 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
| 50 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 52 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 53 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network; |
| 54 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 55 | .ietfnetwork.networks.network.DefaultNode; |
| 56 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 57 | .ietfnetwork.networks.network.Node; |
| 58 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 59 | .ietfnetwork.networks.network.node.DefaultSupportingNode; |
| 60 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 61 | .ietfnetwork.networks.network.node.SupportingNode; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 62 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.TpId; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 63 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 64 | .ietfnetworktopology.networks.network.node.AugmentedNdNode; |
| 65 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 66 | .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode; |
| 67 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.DefaultTeNodeEvent; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 68 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeNodeEvent; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 69 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState; |
| 70 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.InformationSourceState; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 71 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.DefaultTopology; |
| 72 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.Topology; |
| 73 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 74 | .ietftetopology.networks.network.node.AugmentedNwNode; |
| 75 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 76 | .ietftetopology.networks.network.node.DefaultAugmentedNwNode; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 77 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 78 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe; |
| 79 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe.TeBuilder; |
| 80 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.Te; |
| 81 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.Config; |
| 82 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultConfig; |
| 83 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultState; |
| 84 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint; |
| 85 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.State; |
| 86 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.TunnelTerminationPoint; |
| 87 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes; |
| 88 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes; |
| 89 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes.TeNodeAttributesBuilder; |
| 90 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix; |
| 91 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix.ConnectivityMatrixBuilder; |
| 92 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultFrom; |
| 93 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultTo; |
| 94 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology; |
| 95 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.UnderlayTopology; |
| 96 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.DefaultTerminationCapability; |
| 97 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.TerminationCapability; |
| 98 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg; |
| 99 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus; |
| 100 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId; |
| 101 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType; |
| 102 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyId; |
| 103 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.tetopologyeventtype.TeTopologyEventTypeEnum; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 104 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.ietfyangtypes.DottedQuad; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 105 | |
| 106 | import com.google.common.collect.Lists; |
| 107 | import com.google.common.collect.Maps; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Node conversion functions. |
| 111 | */ |
| 112 | public final class NodeConverter { |
| 113 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 114 | 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 Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 122 | |
| 123 | // no instantiation |
| 124 | private NodeConverter() { |
| 125 | } |
| 126 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 127 | /** |
| 128 | * TE Node Config object conversion from TE Topology subsystem to YANG. |
| 129 | * |
| 130 | * @param teSubsystemTeNode TE node object |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 131 | * @param teTopologyService teTopolog core service |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 132 | * @return TE Node Config YANG object |
| 133 | */ |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 134 | private static Config teNode2YangConfig(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 135 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 136 | |
| 137 | TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesConfigBuilder = DefaultTeNodeAttributes |
| 138 | .builder(); |
| 139 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 140 | .isAbstract(teSubsystemTeNode.flags() |
| 141 | .get(TeNode.BIT_ABSTRACT)); |
| 142 | |
| 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 |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 156 | .underlayTeTopologyId(), teTopologyService)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | // TODO: should we ignore this from te to yang? as we've already set yang supportingNode |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 160 | //if (teSubsystemTeNode.supportingTeNodeId() != null) { |
| 161 | //} |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 162 | |
| 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 |
| 176 | te2YangConnectivityMatrix(TeNodeAttributesBuilder teNodeAttributesConfigBuilder, |
| 177 | Map<Long, ConnectivityMatrix> connectivityMatrices) { |
| 178 | ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = DefaultConnectivityMatrix.builder(); |
| 179 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
| 180 | connectivityMatrices.entrySet()) { |
| 181 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 182 | .id(teCmEntry.getKey()) |
| 183 | .isAllowed(!teCmEntry.getValue().flags() |
| 184 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
| 185 | .from(new DefaultFrom.FromBuilder() // TODO: for now, assuming that there is |
| 186 | // only one 'from', and mergingList is empty |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 187 | .tpRef(((TeLinkId) teCmEntry.getValue().from()).value()) |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 188 | .build()) |
| 189 | .to(new DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
| 190 | // one item in constrainingElements list |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 191 | .tpRef(((TeLinkId) teCmEntry.getValue().constrainingElements().get(0)).value()) |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 192 | .build()); |
| 193 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 194 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
| 195 | .build()); |
| 196 | } |
| 197 | return teNodeAttributesConfigBuilder; |
| 198 | } |
| 199 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 200 | private static UnderlayTopology teNode2YangUnderlay(TeTopologyKey underlayTopology, |
| 201 | TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 202 | UnderlayTopology.UnderlayTopologyBuilder underlayBuilder = DefaultUnderlayTopology |
| 203 | .builder() |
| 204 | .teTopologyIdRef(TeTopologyId |
| 205 | .fromString(String.valueOf(underlayTopology.topologyId()))) |
| 206 | .clientIdRef(underlayTopology.clientId()) |
| 207 | .providerIdRef(underlayTopology.providerId()); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 208 | |
| 209 | underlayBuilder = underlayBuilder.networkIdRef(teTopologyService.networkId(underlayTopology)); |
| 210 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 211 | return underlayBuilder.build(); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * TE Node State object conversion from TE Topology subsystem to YANG. |
| 216 | * |
| 217 | * @param teSubsystemTeNode TE node object |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 218 | * @param teTopologyService teTopology core service |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 219 | * @return TE Node State YANG object |
| 220 | */ |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 221 | private static State teNode2YangState(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 222 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 223 | |
| 224 | TeNodeAttributes |
| 225 | .TeNodeAttributesBuilder teNodeAttributesStateBuilder = |
| 226 | DefaultTeNodeAttributes.builder() |
| 227 | .isAbstract(teSubsystemTeNode.flags() |
| 228 | .get(TeNode.BIT_ABSTRACT)); |
| 229 | |
| 230 | if (teSubsystemTeNode.adminStatus() != null) { |
| 231 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 232 | .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus())); |
| 233 | } |
| 234 | |
| 235 | if (teSubsystemTeNode.name() != null) { |
| 236 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 237 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 238 | } |
| 239 | |
| 240 | if (teSubsystemTeNode.underlayTeTopologyId() != null) { |
| 241 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 242 | .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 243 | .underlayTeTopologyId(), teTopologyService)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
| 247 | teNodeAttributesStateBuilder = te2YangConnectivityMatrix(teNodeAttributesStateBuilder, |
| 248 | teSubsystemTeNode.connectivityMatrices()); |
| 249 | } |
| 250 | |
| 251 | // TODO: should we ignore this from te to yang? as we've already set yang supportingNode |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 252 | //if (teSubsystemTeNode.supportingTeNodeId() != null) { |
| 253 | //} |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 254 | |
| 255 | State.StateBuilder yangStateBuilder = DefaultState.builder(); |
| 256 | yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build()); |
| 257 | |
| 258 | if (teSubsystemTeNode.opStatus() != null) { |
| 259 | yangStateBuilder = yangStateBuilder.operStatus(EnumConverter |
| 260 | .teSubsystem2YangOperStatus(teSubsystemTeNode.opStatus())); |
| 261 | } |
| 262 | |
| 263 | if (teSubsystemTeNode.sourceTeNodeId() != null) { |
| 264 | InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder(); |
| 265 | |
| 266 | Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder(); |
| 267 | topologyBuilder = |
| 268 | topologyBuilder.clientIdRef(teSubsystemTeNode.sourceTeNodeId().clientId()) |
| 269 | .providerIdRef(teSubsystemTeNode.sourceTeNodeId().providerId()) |
| 270 | // is this correct? Why not sourceTeNodeId().teTopologyKey()? |
| 271 | .teTopologyIdRef(teSubsystemTeNode |
| 272 | .sourceTeNodeId().topologyId()); |
| 273 | issBuilder = issBuilder.topology(topologyBuilder.build()); |
| 274 | yangStateBuilder.informationSourceState(issBuilder.build()); |
| 275 | } |
| 276 | |
| 277 | return yangStateBuilder.build(); |
| 278 | } |
| 279 | |
| 280 | private static class ByteUtils { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 281 | |
| 282 | public static byte[] longToBytes(long x) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 283 | long temp = x; |
| 284 | byte[] b = new byte[8]; |
| 285 | for (int i = 0; i < b.length; i++) { |
| 286 | b[i] = new Long(temp & 0xff).byteValue(); |
| 287 | temp = temp >> 8; |
| 288 | } |
| 289 | return b; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | public static long bytesToLong(byte[] bytes) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 293 | return ((long) bytes[7] & 255L) << 56 |
| 294 | | ((long) bytes[6] & 255L) << 48 |
| 295 | | ((long) bytes[5] & 255L) << 40 |
| 296 | | ((long) bytes[4] & 255L) << 32 |
| 297 | | ((long) bytes[3] & 255L) << 24 |
| 298 | | ((long) bytes[2] & 255L) << 16 |
| 299 | | ((long) bytes[1] & 255L) << 8 | (long) bytes[0] & 255L; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG. |
| 305 | * |
| 306 | * @param teTunnelTp TE TunnelTerminationPoint object |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 307 | * @param teTpId |
| 308 | * @param teTopologyService |
| 309 | * @param teNodeKey |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 310 | * @return TunnelTerminationPoint YANG object |
| 311 | */ |
| 312 | private static TunnelTerminationPoint teSubsystem2YangTtp( |
| 313 | org.onosproject.tetopology.management.api.node |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 314 | .TunnelTerminationPoint teTunnelTp, Long teTpId, |
| 315 | TeTopologyService teTopologyService, |
| 316 | TeNodeKey teNodeKey) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 317 | checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP); |
| 318 | |
| 319 | TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder = |
| 320 | DefaultTunnelTerminationPoint.builder().tunnelTpId(ByteUtils.longToBytes(teTpId.longValue())); |
| 321 | |
| 322 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 323 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.Config.ConfigBuilder ttpConfigBuilder = |
| 324 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 325 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder(); |
| 326 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 327 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.State.StateBuilder ttpStateBuilder = |
| 328 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 329 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder(); |
| 330 | |
| 331 | // Assuming teTunnelTp only has one interLayerLock |
| 332 | if (teTunnelTp.interLayerLockList() != null && !teTunnelTp.interLayerLockList().isEmpty()) { |
| 333 | ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0)); |
| 334 | ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0)); |
| 335 | } |
| 336 | |
| 337 | TerminationCapability.TerminationCapabilityBuilder |
| 338 | tcapConfigBuilder = DefaultTerminationCapability.builder(); |
| 339 | // TODO: retrieve more attributes from teTunnelTp and assign to tcapConfigBuilder. |
| 340 | // For which ones we can do the conversion? |
| 341 | // FIXME: once new yang model is used, we can make llc from teTunnelTp.localLinkConnectivityList() |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 342 | if (teTunnelTp.localLinkConnectivityList() != null && !teTunnelTp.localLinkConnectivityList().isEmpty()) { |
| 343 | for (LocalLinkConnectivity llcn : teTunnelTp.localLinkConnectivityList()) { |
| 344 | TeLinkId telinkId = (TeLinkId) llcn.constrainingElements().get(0); |
| 345 | TeLinkTpGlobalKey globalKey = new TeLinkTpGlobalKey(teNodeKey, telinkId.value()); |
| 346 | NetworkLinkKey netLinkKey = teTopologyService.linkKey(globalKey); |
| 347 | NetworkLink networkLink = teTopologyService |
| 348 | .network(netLinkKey.networkId()).links().get(netLinkKey.linkId()); |
| 349 | tcapConfigBuilder = tcapConfigBuilder |
| 350 | .linkTp(TpId.fromString(networkLink.source().tpId() |
| 351 | .toString())); |
| 352 | // convert teLinkId to networkLinkKey |
| 353 | ttpConfigBuilder = ttpConfigBuilder.addToTerminationCapability(tcapConfigBuilder.build()); |
| 354 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 355 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 356 | // TODO: retrieve teTunnelTp.switchingLayer() and set it to ttpConfigBuilder |
| 357 | |
| 358 | TerminationCapability.TerminationCapabilityBuilder tcapStateBuilder = |
| 359 | DefaultTerminationCapability.builder(); |
| 360 | // TODO: retrieve more attributes from teTunnelTp and assign to tcapStateBuilder |
| 361 | // For which ones we can do the conversion? |
| 362 | for (LocalLinkConnectivity llcn : teTunnelTp.localLinkConnectivityList()) { |
| 363 | TeLinkId telinkId = (TeLinkId) llcn.constrainingElements().get(0); |
| 364 | TeLinkTpGlobalKey globalKey = new TeLinkTpGlobalKey(teNodeKey, telinkId.value()); |
| 365 | NetworkLinkKey netLinkKey = teTopologyService.linkKey(globalKey); |
| 366 | NetworkLink networkLink = teTopologyService |
| 367 | .network(netLinkKey.networkId()).links().get(netLinkKey.linkId()); |
| 368 | tcapStateBuilder = tcapStateBuilder |
| 369 | .linkTp(TpId.fromString(networkLink.source().tpId() |
| 370 | .toString())); |
| 371 | ttpStateBuilder = ttpStateBuilder.addToTerminationCapability(tcapStateBuilder.build()); |
| 372 | } |
| 373 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 374 | |
| 375 | tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build()) |
| 376 | .state(ttpStateBuilder.build()); |
| 377 | |
| 378 | return tunnelTpBuilder.build(); |
| 379 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 380 | |
| 381 | /** |
| 382 | * Node object conversion from TE Topology subsystem to YANG. |
| 383 | * |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 384 | * @param teSubsystem TE subsystem node |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 385 | * @param teTopologyService teTopology core service |
| 386 | * @param teTopologyKey teTopologyKey |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 387 | * @return YANG node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 388 | */ |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 389 | public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem, |
| 390 | TeTopologyService teTopologyService, |
| 391 | TeTopologyKey teTopologyKey) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 392 | checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE); |
| 393 | |
| 394 | NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString()); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 395 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 396 | Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId); |
| 397 | |
| 398 | if (teSubsystem.supportingNodeIds() != null) { |
| 399 | List<SupportingNode> sNodes = Lists.newArrayList(); |
| 400 | SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode |
| 401 | .builder(); |
| 402 | for (NetworkNodeKey nodeKey : teSubsystem.supportingNodeIds()) { |
| 403 | sNodes.add(spNodeBuilder |
| 404 | .networkRef(NetworkId |
| 405 | .fromString(nodeKey.networkId().toString())) |
| 406 | .nodeRef(NodeId.fromString(nodeKey.nodeId().toString())) |
| 407 | .build()); |
| 408 | } |
| 409 | builder = builder.supportingNode(sNodes); |
| 410 | } |
| 411 | |
| 412 | if (teSubsystem.terminationPoints() != null) { |
| 413 | AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode |
| 414 | .builder(); |
| 415 | Map<KeyId, TerminationPoint> teSubsystemTeTp = teSubsystem |
| 416 | .terminationPoints(); |
| 417 | |
| 418 | for (TerminationPoint teTp : teSubsystemTeTp.values()) { |
| 419 | tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter |
| 420 | .teSubsystem2YangTerminationPoint(teTp)); |
| 421 | } |
| 422 | builder.addYangAugmentedInfo(tpAugmentBuilder.build(), |
| 423 | AugmentedNdNode.class); |
| 424 | } |
| 425 | |
| 426 | if (teSubsystem.teNode() != null) { |
| 427 | AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode |
| 428 | .builder(); |
| 429 | |
| 430 | TeNode teSubsystemTeNode = teSubsystem.teNode(); |
| 431 | |
| 432 | TeBuilder yangTeBuilder = DefaultTe.builder(); |
| 433 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 434 | yangTeBuilder = yangTeBuilder.teNodeId(TeNodeId.of(DottedQuad |
| 435 | .of(Ip4Address.valueOf((int) teSubsystemTeNode.teNodeId()) |
| 436 | .toString()))); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 437 | |
| 438 | // Set configuration data |
| 439 | // Set state data |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 440 | yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode, teTopologyService)) |
| 441 | .state(teNode2YangState(teSubsystemTeNode, teTopologyService)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 442 | |
| 443 | if (teSubsystemTeNode.tunnelTerminationPoints() != null) { |
| 444 | for (Map.Entry<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> entry : |
| 445 | teSubsystemTeNode.tunnelTerminationPoints().entrySet()) { |
| 446 | yangTeBuilder = yangTeBuilder |
| 447 | .addToTunnelTerminationPoint(teSubsystem2YangTtp(entry |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 448 | .getValue(), entry.getKey(), teTopologyService, |
| 449 | new TeNodeKey(teTopologyKey, teSubsystemTeNode.teNodeId()))); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build()); |
| 454 | builder.addYangAugmentedInfo(nodeAugmentBuilder.build(), |
| 455 | AugmentedNwNode.class); |
| 456 | } |
| 457 | return builder.build(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Node object conversion from YANG to TE Topology subsystem. |
| 462 | * |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 463 | * @param yangNode Node in YANG model |
| 464 | * @param yangNetwork YANG network |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 465 | * @return TE subsystem node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 466 | */ |
| 467 | public static org.onosproject.tetopology.management.api.node.NetworkNode |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 468 | yang2TeSubsystemNode(Node yangNode, Network yangNetwork) { |
| 469 | checkNotNull(yangNode, E_NULL_YANG_NODE); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 470 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 471 | org.onosproject.tetopology.management.api.node.DefaultNetworkNode node; |
| 472 | List<NetworkNodeKey> spNodes = null; |
| 473 | TeNode teNode = null; |
| 474 | Map<KeyId, TerminationPoint> tps = null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 475 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 476 | if (yangNode.supportingNode() != null) { |
| 477 | spNodes = Lists.newArrayList(); |
| 478 | for (SupportingNode yangSpNode : yangNode.supportingNode()) { |
| 479 | NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()), |
| 480 | KeyId.keyId(yangSpNode.networkRef().uri().toString())); |
| 481 | spNodes.add(nodeKey); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | if (yangNode.yangAugmentedInfoMap() != null |
| 486 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 487 | |
| 488 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 489 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 490 | if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) { |
| 491 | tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment); |
| 492 | } |
| 493 | |
| 494 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode |
| 495 | .yangAugmentedInfo(AugmentedNwNode.class); |
| 496 | if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.te().teNodeId() != null) { |
| 497 | Te yangNodeAugTe = yangNodeAugment.te(); |
| 498 | teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, |
| 499 | yangNetwork, |
| 500 | yangNode, |
| 501 | tps); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | node = new org.onosproject.tetopology.management.api.node |
| 506 | .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps); |
| 507 | return node; |
| 508 | } |
| 509 | |
| 510 | // TODO: convert connectivity matrix from yang to te |
| 511 | private static Map<Long, ConnectivityMatrix> |
| 512 | yang2TeSubsystemNodeConnectivityMatrix(String networkId, |
| 513 | String nodeId, |
| 514 | List<org.onosproject.yang.gen.v1.urn.ietf |
| 515 | .params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 516 | .ietftetopology.tenodeconnectivitymatrix. |
| 517 | ConnectivityMatrix> yangMatrix) { |
| 518 | |
| 519 | Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap(); |
| 520 | |
| 521 | |
| 522 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te |
| 523 | .topology.rev20160708.ietftetopology.tenodeconnectivitymatrix. |
| 524 | ConnectivityMatrix cmYang : yangMatrix) { |
| 525 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 526 | ElementType from = new TeLinkId(Long.valueOf(((String) cmYang.from().tpRef()))); // is this correct? |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 527 | |
| 528 | UnderlayAbstractPath underlayPath = null; // ignore |
| 529 | |
| 530 | List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now |
| 531 | |
| 532 | List<ElementType> constrainingElements = Lists.newArrayList(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 533 | ElementType to = new TeLinkId(Long.valueOf(((String) cmYang.to().tpRef()))); // is this correct? |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 534 | constrainingElements.add(to); |
| 535 | |
| 536 | BitSet flags = new BitSet(); // what are the flags in cmYang? |
| 537 | |
| 538 | List<Long> srlgs = Lists.newArrayList(); |
| 539 | if (cmYang.teSrlgs() != null) { |
| 540 | for (Srlg srlg : cmYang.teSrlgs().value()) { |
| 541 | srlgs.add(srlg.uint32()); |
| 542 | } |
| 543 | } |
| 544 | TePathAttributes teAttributes = new |
| 545 | TePathAttributes(cmYang.teDefaultMetric(), |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 546 | cmYang.performanceMetric() == null ? null : |
| 547 | (cmYang.performanceMetric().measurement() == null ? null : |
| 548 | cmYang.performanceMetric().measurement().unidirectionalDelay()), |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 549 | srlgs); |
| 550 | ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(), |
| 551 | from, |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 552 | mergingList, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 553 | constrainingElements, |
| 554 | flags, |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 555 | teAttributes, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 556 | underlayPath); |
| 557 | |
| 558 | teCmList.put(cmYang.id(), coreCm); |
| 559 | } |
| 560 | |
| 561 | return teCmList; |
| 562 | } |
| 563 | |
| 564 | private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut) { |
| 565 | TeTopologyKey tetopokey = new TeTopologyKey((Long) ut.providerIdRef(), |
| 566 | (Long) ut.clientIdRef(), |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 567 | Long.valueOf((String) ut.teTopologyIdRef())); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 568 | return tetopokey; |
| 569 | } |
| 570 | |
| 571 | // TODO: retrieve the details of tunnel termiantion points from yang to te |
| 572 | private static Map<Long, org.onosproject.tetopology.management.api.node. |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 573 | TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps, Node yangNode) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 574 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps |
| 575 | .newHashMap(); |
| 576 | for (TunnelTerminationPoint ttpYang : ttps) { |
| 577 | |
| 578 | SwitchingType switchingLayer = null; // how to find switching type? |
| 579 | EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding(); |
| 580 | BitSet flags = new BitSet(); // how to set flags? |
| 581 | List<Long> interLayerLockList = Lists.newArrayList(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 582 | |
| 583 | if (ttpYang.config() != null) { |
| 584 | interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list |
| 585 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 586 | |
| 587 | List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList(); |
| 588 | // FIXME: once new yang model is used, we can make llc |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 589 | ElementType elt = null; |
| 590 | List<ElementType> eltList = Lists.newArrayList(); |
| 591 | |
| 592 | if (ttpYang.config() != null |
| 593 | && ttpYang.config().terminationCapability() != null |
| 594 | && !ttpYang.config().terminationCapability().isEmpty()) { |
| 595 | for (TerminationCapability tercap : ttpYang.config() |
| 596 | .terminationCapability()) { |
| 597 | |
| 598 | if (yangNode.yangAugmentedInfoMap() != null |
| 599 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 600 | |
| 601 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 602 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 603 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml |
| 604 | .ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology |
| 605 | .networks.network.node.augmentedndnode |
| 606 | .TerminationPoint tpItem : yangTpNodeAugment.terminationPoint()) { |
| 607 | if (tpItem.tpId().uri().string().equals(tercap.linkTp().toString())) { |
| 608 | if (tpItem.yangAugmentedInfoMap() != null |
| 609 | && !tpItem.yangAugmentedInfoMap().isEmpty()) { |
| 610 | AugmentedNtTerminationPoint yangTpAugment = |
| 611 | (AugmentedNtTerminationPoint) tpItem |
| 612 | .yangAugmentedInfo(AugmentedNtTerminationPoint.class); |
| 613 | if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) { |
| 614 | elt = new TeLinkId(Long.valueOf(yangTpAugment.te().teTpId().toString())); |
| 615 | break; |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | eltList.add(elt); |
| 622 | // tercap.linkTp().toString() //tpId -> tp -> te-tp-id (long) |
| 623 | } |
| 624 | } |
| 625 | TePathAttributes teAttributes = null; // how to find these |
| 626 | // attributes from ttpYang? |
| 627 | UnderlayAbstractPath underlayPath = null; // how to find underlayAbstractPath from ttpYang? |
| 628 | LocalLinkConnectivity llc = new LocalLinkConnectivity(eltList, |
| 629 | flags, |
| 630 | teAttributes, |
| 631 | underlayPath); |
| 632 | localLinkConnectivityList.add(llc); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 633 | |
| 634 | float[] availAdaptBandwidth = null; // how to find availableBandwidth? |
| 635 | |
| 636 | org.onosproject.tetopology.management.api.node. |
| 637 | TunnelTerminationPoint ttpTe = new |
| 638 | org.onosproject.tetopology.management.api.node. |
| 639 | DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 640 | switchingLayer, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 641 | encodingLayer, |
| 642 | flags, |
| 643 | interLayerLockList, |
| 644 | localLinkConnectivityList, |
| 645 | availAdaptBandwidth); |
| 646 | |
| 647 | ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe); |
| 648 | } |
| 649 | |
| 650 | return ttpsMap; |
| 651 | } |
| 652 | |
| 653 | private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe, |
| 654 | Network yangNetwork, |
| 655 | Node yangNode, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 656 | Map<KeyId, TerminationPoint> teTps) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 657 | |
| 658 | |
| 659 | NodeId yangNodeId = yangNode.nodeId(); |
| 660 | List<SupportingNode> yangSupportNodes = yangNode.supportingNode(); |
| 661 | |
| 662 | NetworkId yangNetworkId = yangNetwork.networkId(); |
| 663 | |
| 664 | long teNodeId = Ip4Address.valueOf(yangNodeAugTe.teNodeId().dottedQuad().string()).toInt(); |
| 665 | |
| 666 | TeTopologyKey underlayTopologyIdId = null; |
| 667 | |
| 668 | // FIXME: yang has a list of supporting nodes, but TeNode only has one |
| 669 | // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId? |
| 670 | TeNodeKey supportTeNodeId = null; |
| 671 | // supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId) |
| 672 | // yangSupportNodes.get(0). |
| 673 | |
| 674 | TeNodeKey sourceTeNodeId = null; //ignore |
| 675 | CommonNodeData teData = null; |
| 676 | Map<Long, ConnectivityMatrix> connMatrices = null; |
| 677 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null; |
| 678 | List<Long> teLinkIds = Lists.newArrayList(); |
| 679 | List<Long> teTpIds = Lists.newArrayList(); |
| 680 | |
| 681 | // ********************************************** to find teLinkIds |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 682 | if (MapUtils.isNotEmpty(teTps)) { |
| 683 | for (Map.Entry<KeyId, TerminationPoint> entry : teTps.entrySet()) { |
| 684 | if (entry.getValue().teTpId() != null) { |
| 685 | teTpIds.add(entry.getValue().teTpId()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | } |
| 689 | // ********************************************** to find teTpIds |
| 690 | if (yangNode.yangAugmentedInfoMap() != null |
| 691 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 692 | |
| 693 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 694 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 695 | |
| 696 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 697 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 698 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 699 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 700 | teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string())); |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | // ********************************************** |
| 705 | |
| 706 | Config ynodeAugCfg = yangNodeAugTe.config(); |
| 707 | |
| 708 | if (ynodeAugCfg != null) { |
| 709 | TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes(); |
| 710 | if (teNodeAttr != null) { |
| 711 | |
| 712 | if (teNodeAttr.underlayTopology() != null) { |
| 713 | |
| 714 | underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr |
| 715 | .underlayTopology()); |
| 716 | } |
| 717 | BitSet flags = new BitSet(); |
| 718 | if (teNodeAttr.isAbstract()) { |
| 719 | flags.set(TeNode.BIT_ABSTRACT); |
| 720 | } |
| 721 | teData = new CommonNodeData( |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 722 | null, // teNodeAttr.name().string(), |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 723 | EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()), |
| 724 | EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()), |
| 725 | flags); |
| 726 | |
| 727 | if (teNodeAttr.connectivityMatrix() != null) { |
| 728 | connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(), |
| 729 | yangNodeId.uri().toString(), |
| 730 | teNodeAttr.connectivityMatrix()); |
| 731 | } |
| 732 | |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | if (yangNodeAugTe.tunnelTerminationPoint() != null) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 737 | ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint(), yangNode); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | TeNode teNode = new DefaultTeNode(teNodeId, |
| 741 | underlayTopologyIdId, |
| 742 | supportTeNodeId, |
| 743 | sourceTeNodeId, |
| 744 | teData, |
| 745 | connMatrices, |
| 746 | teLinkIds, |
| 747 | ttps, |
| 748 | teTpIds); |
| 749 | return teNode; |
| 750 | } |
| 751 | |
| 752 | private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) { |
| 753 | Map<KeyId, TerminationPoint> tps; |
| 754 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 755 | tps = Maps.newHashMap(); |
| 756 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 757 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 758 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 759 | tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()), |
| 760 | TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode)); |
| 761 | } |
| 762 | return tps; |
| 763 | } |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 764 | return null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 767 | /** |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 768 | * Converts a TE Topology node event from the data format used in the core |
| 769 | * to its corresponding YANG Object (YO) format. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 770 | * |
| 771 | * @param eventType Node event type |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 772 | * @param eventData TE Topology node event data |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 773 | * @return YANG Object converted from nodeData |
| 774 | */ |
| 775 | public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 776 | NetworkNodeEventSubject eventData) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 777 | TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 778 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 779 | TeTopologyEventType yangEventType = new TeTopologyEventType(eventType); |
| 780 | builder.eventType(yangEventType); |
| 781 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 782 | NetworkId newtorkId = NetworkId.fromString(eventData.key().networkId().toString()); |
| 783 | builder.networkRef(newtorkId); |
| 784 | NodeId nodeId = NodeId.fromString(eventData.key().nodeId().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 785 | builder.nodeRef(nodeId); |
| 786 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 787 | NetworkNode node = eventData.neworkNode(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 788 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 789 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 790 | TeNodeAttributes teNodeAttributes = node == null ? null |
| 791 | : teNode2YangTeNodeAttributes(node.teNode()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 792 | builder.teNodeAttributes(teNodeAttributes); |
| 793 | |
| 794 | return builder.build(); |
| 795 | } |
| 796 | |
| 797 | private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
| 798 | ietf.te.topology.rev20160708.ietftetopology. |
| 799 | tenodeconfigattributesnotification. |
| 800 | TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) { |
| 801 | |
| 802 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 803 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 804 | TeNodeAttributes.TeNodeAttributesBuilder attrBuilder = |
| 805 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 806 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 807 | DefaultTeNodeAttributes.builder(); |
| 808 | |
| 809 | if (teNode.connectivityMatrices() != null) { |
| 810 | |
| 811 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 812 | .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix |
| 813 | .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf. |
| 814 | params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrixabs. |
| 815 | DefaultConnectivityMatrix.builder(); |
| 816 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
| 817 | teNode.connectivityMatrices().entrySet()) { |
| 818 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 819 | .id(teCmEntry.getKey()) |
| 820 | .isAllowed(!teCmEntry.getValue().flags() |
| 821 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
| 822 | .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 823 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom |
| 824 | .FromBuilder() // TODO: for now, assuming that there is |
| 825 | // only one 'from', and mergingList is empty |
| 826 | .tpRef(teCmEntry.getValue().from()) |
| 827 | .build()) |
| 828 | .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 829 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix |
| 830 | .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
| 831 | // one item in constrainingElements list |
| 832 | .tpRef(teCmEntry.getValue().constrainingElements().get(0)) |
| 833 | .build()); |
| 834 | attrBuilder = attrBuilder |
| 835 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
| 836 | .build()); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 841 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 842 | TeNodeAttributes teNodeAttributes = attrBuilder.build(); |
| 843 | |
| 844 | return teNodeAttributes; |
| 845 | } |
| 846 | |
| 847 | public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 848 | NetworkId networkRef = NetworkId.fromString(yangNodeEvent.networkRef().toString()); |
| 849 | NodeId nodeRef = NodeId.fromString(yangNodeEvent.nodeRef().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 850 | KeyId networkId = KeyId.keyId(networkRef.uri().toString()); |
| 851 | KeyId nodeId = KeyId.keyId(nodeRef.uri().toString()); |
| 852 | |
| 853 | NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId); |
| 854 | |
| 855 | return networkNodeKey; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 856 | } |
| 857 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 858 | /** |
| 859 | * Converts YangNode event to NetworkNode. |
| 860 | * |
| 861 | * @param yangNodeEvent yangNodeEvent |
| 862 | * @param teTopologyService teTopologyService |
| 863 | * @return NetworkNode |
| 864 | */ |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 865 | public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent, |
| 866 | TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 867 | KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId(); |
| 868 | |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 869 | org.onosproject.tetopology.management.api.Network network = teTopologyService.network( |
| 870 | yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 871 | if (network == null) { |
| 872 | return null; |
| 873 | } |
| 874 | |
| 875 | NetworkNode networkNode = network.node(networkNodeId); |
| 876 | if (networkNode == null) { |
| 877 | return null; |
| 878 | } |
| 879 | |
| 880 | List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds(); |
| 881 | Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints(); |
| 882 | |
| 883 | TeNode teNode = networkNode.teNode(); |
| 884 | if (teNode == null) { |
| 885 | return null; |
| 886 | } |
| 887 | |
| 888 | TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode); |
| 889 | |
| 890 | NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps); |
| 891 | |
| 892 | return updatedNetworkNode; |
| 893 | } |
| 894 | |
| 895 | private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) { |
| 896 | |
| 897 | long teNodeId = oldTeNode.teNodeId(); |
| 898 | TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId(); |
| 899 | TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId(); |
| 900 | TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId(); |
| 901 | Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices(); |
| 902 | List<Long> teLinkIds = oldTeNode.teLinkIds(); |
| 903 | Map<Long, org.onosproject.tetopology.management. |
| 904 | api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints(); |
| 905 | List<Long> teTpIds = oldTeNode.teLinkIds(); |
| 906 | String name = oldTeNode.name(); |
| 907 | TeStatus adminStatus = oldTeNode.adminStatus(); |
| 908 | TeStatus opStatus = oldTeNode.opStatus(); |
| 909 | BitSet flags = oldTeNode.flags(); |
| 910 | |
| 911 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 912 | .tenodeconfigattributesnotification |
| 913 | .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes(); |
| 914 | |
| 915 | if (yangTeNodeAttrs != null) { |
| 916 | TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus(); |
| 917 | if (yangAdminStatus != null) { |
| 918 | adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus); |
| 919 | } |
| 920 | |
| 921 | BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags(); |
| 922 | if (yangFlags != null) { |
| 923 | flags = yangFlags; |
| 924 | } |
| 925 | |
| 926 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
| 927 | ietf.te.topology.rev20160708.ietftetopology |
| 928 | .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs |
| 929 | .connectivityMatrix(); |
| 930 | if (yangConnMatrices != null) { |
| 931 | for (org.onosproject.yang.gen.v1. |
| 932 | urn.ietf.params.xml.ns.yang. |
| 933 | ietf.te.topology |
| 934 | .rev20160708.ietftetopology |
| 935 | .tenodeconnectivitymatrixabs |
| 936 | .ConnectivityMatrix yangConnMatrix : yangConnMatrices) { |
| 937 | Long cmId = new Long(yangConnMatrix.id()); |
| 938 | ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id())); |
| 939 | if (oldConnMatrix != null) { |
| 940 | ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix, |
| 941 | oldConnMatrix); |
| 942 | connMatrices.remove(cmId); |
| 943 | connMatrices.put(cmId, newConnMatrix); |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags); |
| 950 | TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData, |
| 951 | connMatrices, teLinkIds, ttps, teTpIds); |
| 952 | |
| 953 | return updatedTeNode; |
| 954 | } |
| 955 | |
| 956 | private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1. |
| 957 | urn.ietf.params.xml.ns.yang. |
| 958 | ietf.te.topology |
| 959 | .rev20160708.ietftetopology |
| 960 | .tenodeconnectivitymatrixabs |
| 961 | .ConnectivityMatrix yangConnMatrix, |
| 962 | ConnectivityMatrix oldTeConnMatrix) { |
| 963 | |
| 964 | long id = yangConnMatrix.id(); |
| 965 | ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef())); |
| 966 | UnderlayAbstractPath underlayPath = null; |
| 967 | List<ElementType> mergingList = Lists.newArrayList(); |
| 968 | |
| 969 | List<ElementType> constrainingElements = Lists.newArrayList(); |
| 970 | ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef())); |
| 971 | constrainingElements.add(to); |
| 972 | |
| 973 | BitSet flags = oldTeConnMatrix.flags(); |
| 974 | |
| 975 | TePathAttributes teAttributes = oldTeConnMatrix.teAttributes(); |
| 976 | |
| 977 | ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id, |
| 978 | from, |
| 979 | mergingList, |
| 980 | constrainingElements, |
| 981 | flags, |
| 982 | teAttributes, |
| 983 | underlayPath); |
| 984 | return updatedConnMatrix; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 985 | } |
| 986 | } |