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