Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 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; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 30 | import org.onosproject.tetopology.management.api.TeConstants; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 31 | import org.onosproject.tetopology.management.api.TeStatus; |
| 32 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 33 | import org.onosproject.tetopology.management.api.TeTopologyService; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 34 | import org.onosproject.tetopology.management.api.link.ElementType; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 35 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 36 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
| 37 | import org.onosproject.tetopology.management.api.link.TeIpv4; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 38 | import org.onosproject.tetopology.management.api.link.TeLinkId; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 39 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 40 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 41 | import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath; |
| 42 | import org.onosproject.tetopology.management.api.node.CommonNodeData; |
| 43 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrix; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 44 | import org.onosproject.tetopology.management.api.node.DefaultNetworkNode; |
| 45 | import org.onosproject.tetopology.management.api.node.DefaultTeNode; |
| 46 | import org.onosproject.tetopology.management.api.node.LocalLinkConnectivity; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 47 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 48 | import org.onosproject.tetopology.management.api.node.NetworkNodeEventSubject; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 49 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 50 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 51 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 52 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 53 | import org.onosproject.tetopology.management.api.node.TtpKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 54 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 55 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.IpAddress; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 56 | 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] | 57 | 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] | 58 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 59 | 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] | 60 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 61 | .ietfnetwork.networks.network.DefaultNode; |
| 62 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 63 | .ietfnetwork.networks.network.Node; |
| 64 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 65 | .ietfnetwork.networks.network.node.DefaultSupportingNode; |
| 66 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 67 | .ietfnetwork.networks.network.node.SupportingNode; |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 68 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 69 | .ietfnetworktopology.networks.network.node.AugmentedNdNode; |
| 70 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 71 | .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 72 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.DefaultTeNodeEvent; |
| 73 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.TeNodeEvent; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 74 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.connectivitymatrixentryattributes.DefaultUnderlay; |
| 75 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.connectivitymatrixentryattributes.Underlay; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 76 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.DefaultInformationSourceState; |
| 77 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.InformationSourceState; |
| 78 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.informationsourcestate.DefaultTopology; |
| 79 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.informationsourcepernodeattributes.informationsourcestate.Topology; |
| 80 | 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] | 81 | .ietftetopology.networks.network.node.AugmentedNwNode; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 82 | 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] | 83 | .ietftetopology.networks.network.node.DefaultAugmentedNwNode; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 84 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 85 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs; |
| 86 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkconnectivityattributes.TeSrlgs; |
| 87 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.DefaultPrimaryPath; |
| 88 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.PrimaryPath; |
| 89 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.primarypath.DefaultPathElement; |
| 90 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkunderlayattributes.primarypath.PathElement; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 91 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.DefaultTe; |
| 92 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.DefaultTe.TeBuilder; |
| 93 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.Te; |
| 94 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.Config; |
| 95 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultConfig; |
| 96 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultState; |
| 97 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint; |
| 98 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.State; |
| 99 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.TunnelTerminationPoint; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 100 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultSupportingTunnelTerminationPoint; |
| 101 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeaugment.te.tunnelterminationpoint.SupportingTunnelTerminationPoint; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 102 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes; |
| 103 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.TeNodeAttributes; |
| 104 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributes.TeNodeAttributes.TeNodeAttributesBuilder; |
| 105 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.ConnectivityMatrices; |
| 106 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrices; |
| 107 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrices.ConnectivityMatricesBuilder; |
| 108 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.DefaultConnectivityMatrix; |
| 109 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.DefaultConnectivityMatrix.ConnectivityMatrixBuilder; |
| 110 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.connectivitymatrix.DefaultFrom; |
| 111 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.connectivitymatrix.DefaultTo; |
| 112 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology; |
| 113 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeinfoattributes.UnderlayTopology; |
| 114 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.DefaultLocalLinkConnectivities; |
| 115 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.LocalLinkConnectivities; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 116 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities.DefaultLocalLinkConnectivity; |
| 117 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities.DefaultLocalLinkConnectivity.LocalLinkConnectivityBuilder; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 118 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg; |
| 119 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus; |
| 120 | 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] | 121 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType; |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 122 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.AsNumber; |
| 123 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultAsNumber; |
| 124 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink; |
| 125 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.Ipv4Address; |
| 126 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.UnnumberedLink; |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 127 | 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] | 128 | 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] | 129 | |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 130 | import com.google.common.collect.Lists; |
| 131 | import com.google.common.collect.Maps; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * Node conversion functions. |
| 135 | */ |
| 136 | public final class NodeConverter { |
| 137 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 138 | private static final String E_NULL_TE_SUBSYSTEM_TE_NODE = |
| 139 | "TeSubsystem teNode object cannot be null"; |
| 140 | private static final String E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP = |
| 141 | "TeSubsystem teTunnelTp object cannot be null"; |
| 142 | private static final String E_NULL_TE_SUBSYSTEM_NODE = |
| 143 | "TeSubsystem ndoe object cannot be null"; |
| 144 | private static final String E_NULL_YANG_NODE = |
| 145 | "Yang node object cannot be null"; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 146 | |
| 147 | // no instantiation |
| 148 | private NodeConverter() { |
| 149 | } |
| 150 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 151 | /** |
| 152 | * TE Node Config object conversion from TE Topology subsystem to YANG. |
| 153 | * |
| 154 | * @param teSubsystemTeNode TE node object |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 155 | * @param teTopologyService teTopolog core service |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 156 | * @return TE Node Config YANG object |
| 157 | */ |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 158 | private static Config teNode2YangConfig(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 159 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 160 | |
| 161 | TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesConfigBuilder = DefaultTeNodeAttributes |
| 162 | .builder(); |
| 163 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 164 | .isAbstract(teSubsystemTeNode.flags() |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 165 | .get(TeNode.BIT_ABSTRACT)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 166 | |
| 167 | if (teSubsystemTeNode.adminStatus() != null) { |
| 168 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 169 | .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus())); |
| 170 | } |
| 171 | |
| 172 | if (teSubsystemTeNode.name() != null) { |
| 173 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 174 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 175 | } |
| 176 | |
| 177 | if (teSubsystemTeNode.underlayTeTopologyId() != null) { |
| 178 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 179 | .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 180 | .underlayTeTopologyId(), teTopologyService)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | // 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] | 184 | //if (teSubsystemTeNode.supportingTeNodeId() != null) { |
| 185 | //} |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 186 | |
| 187 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
| 188 | teNodeAttributesConfigBuilder = te2YangConnectivityMatrix(teNodeAttributesConfigBuilder, |
| 189 | teSubsystemTeNode.connectivityMatrices()); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder(); |
| 194 | yangConfigBuilder = yangConfigBuilder.teNodeAttributes(teNodeAttributesConfigBuilder.build()); |
| 195 | |
| 196 | return yangConfigBuilder.build(); |
| 197 | } |
| 198 | |
| 199 | private static TeNodeAttributesBuilder |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 200 | te2YangConnectivityMatrix(TeNodeAttributesBuilder teNodeAttributesConfigBuilder, |
| 201 | Map<Long, ConnectivityMatrix> connectivityMatrices) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 202 | ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = DefaultConnectivityMatrix.builder(); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 203 | ConnectivityMatricesBuilder yangConnectivityMatricesBuilder = DefaultConnectivityMatrices.builder(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 204 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 205 | connectivityMatrices.entrySet()) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 206 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 207 | .id(teCmEntry.getKey()) |
| 208 | .isAllowed(!teCmEntry.getValue().flags() |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 209 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 210 | .from(new DefaultFrom.FromBuilder() // TODO: for now, assuming that there is |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 211 | // only one 'from', and mergingList is empty |
| 212 | .tpRef(((TeLinkId) teCmEntry.getValue().from()).value()) |
| 213 | .build()) |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 214 | .to(new DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 215 | // one item in constrainingElements list |
| 216 | .tpRef(((TeLinkId) teCmEntry.getValue().constrainingElements().get(0)).value()) |
| 217 | .build()); |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 218 | if (teCmEntry.getValue().teAttributes() != null) { |
| 219 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 220 | .teDefaultMetric(teCmEntry.getValue().teAttributes().cost()) |
| 221 | .teDelayMetric(teCmEntry.getValue().teAttributes().delay()); |
| 222 | } |
| 223 | |
| 224 | TeSrlgs.TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder(); |
| 225 | if (teCmEntry.getValue().teAttributes().srlgs() != null) { |
| 226 | for (Long val : teCmEntry.getValue().teAttributes().srlgs()) { |
| 227 | Srlg srlg = new Srlg(val); |
| 228 | teSrlgsBuilder = teSrlgsBuilder.addToValue(srlg); |
| 229 | } |
| 230 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 231 | .teSrlgs(teSrlgsBuilder.build()); |
| 232 | } |
| 233 | |
| 234 | Underlay.UnderlayBuilder underlayBuilder = DefaultUnderlay.builder(); |
| 235 | PrimaryPath.PrimaryPathBuilder primaryPathBuilder = DefaultPrimaryPath.builder(); |
| 236 | |
| 237 | PathElement.PathElementBuilder pathElementBuilder = DefaultPathElement.builder(); |
| 238 | if (teCmEntry.getValue().underlayPath() != null && |
| 239 | teCmEntry.getValue().underlayPath().pathElements() != null && |
| 240 | !teCmEntry.getValue().underlayPath().pathElements().isEmpty()) { |
| 241 | for (org.onosproject.tetopology.management.api.link.PathElement patel : teCmEntry.getValue() |
| 242 | .underlayPath().pathElements()) { |
| 243 | pathElementBuilder = pathElementBuilder.pathElementId(patel.pathElementId()); |
| 244 | if (patel.type() instanceof AsNumber) { |
| 245 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes |
| 246 | .explicitroutesubobject.type.AsNumber |
| 247 | .AsNumberBuilder asNumberBuilder = new DefaultAsNumber.AsNumberBuilder(); |
| 248 | asNumberBuilder = asNumberBuilder.asNumber(((AsNumber) patel.type()).asNumber()); |
| 249 | pathElementBuilder = pathElementBuilder.type(asNumberBuilder.build()); |
| 250 | } else if (patel.type() instanceof UnnumberedLink) { |
| 251 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes |
| 252 | .explicitroutesubobject.type.UnnumberedLink |
| 253 | .UnnumberedLinkBuilder unNumberBuilder = DefaultUnnumberedLink.builder(); |
| 254 | unNumberBuilder = unNumberBuilder.interfaceId(((UnnumberedLink) patel.type()).interfaceId()); |
| 255 | unNumberBuilder = unNumberBuilder.routerId(IpAddress.fromString(((UnnumberedLink) patel.type()) |
| 256 | .routerId().toString())); |
| 257 | pathElementBuilder = pathElementBuilder.type(unNumberBuilder.build()); |
| 258 | } |
| 259 | primaryPathBuilder = primaryPathBuilder |
| 260 | .addToPathElement(pathElementBuilder.build()); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | underlayBuilder = underlayBuilder.primaryPath(primaryPathBuilder.build()); |
| 265 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 266 | .underlay(underlayBuilder.build()); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 267 | |
| 268 | yangConnectivityMatricesBuilder = yangConnectivityMatricesBuilder |
| 269 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder.build()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 270 | } |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 271 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 272 | .connectivityMatrices(yangConnectivityMatricesBuilder.build()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 273 | return teNodeAttributesConfigBuilder; |
| 274 | } |
| 275 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 276 | private static UnderlayTopology teNode2YangUnderlay(TeTopologyKey underlayTopology, |
| 277 | TeTopologyService teTopologyService) { |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 278 | UnderlayTopology.UnderlayTopologyBuilder underlayBuilder = DefaultUnderlayTopology.builder(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 279 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 280 | underlayBuilder = underlayBuilder.networkRef(teTopologyService.networkId(underlayTopology)); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 281 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 282 | return underlayBuilder.build(); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * TE Node State object conversion from TE Topology subsystem to YANG. |
| 287 | * |
| 288 | * @param teSubsystemTeNode TE node object |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 289 | * @param teTopologyService teTopology core service |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 290 | * @return TE Node State YANG object |
| 291 | */ |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 292 | private static State teNode2YangState(TeNode teSubsystemTeNode, TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 293 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 294 | |
| 295 | TeNodeAttributes |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 296 | .TeNodeAttributesBuilder teNodeAttributesStateBuilder = |
| 297 | DefaultTeNodeAttributes.builder() |
| 298 | .isAbstract(teSubsystemTeNode.flags() |
| 299 | .get(TeNode.BIT_ABSTRACT)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 300 | |
| 301 | if (teSubsystemTeNode.adminStatus() != null) { |
| 302 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 303 | .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus())); |
| 304 | } |
| 305 | |
| 306 | if (teSubsystemTeNode.name() != null) { |
| 307 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 308 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 309 | } |
| 310 | |
| 311 | if (teSubsystemTeNode.underlayTeTopologyId() != null) { |
| 312 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 313 | .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 314 | .underlayTeTopologyId(), teTopologyService)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
| 318 | teNodeAttributesStateBuilder = te2YangConnectivityMatrix(teNodeAttributesStateBuilder, |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 319 | teSubsystemTeNode.connectivityMatrices()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | // 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] | 323 | //if (teSubsystemTeNode.supportingTeNodeId() != null) { |
| 324 | //} |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 325 | |
| 326 | State.StateBuilder yangStateBuilder = DefaultState.builder(); |
| 327 | yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build()); |
| 328 | |
| 329 | if (teSubsystemTeNode.opStatus() != null) { |
| 330 | yangStateBuilder = yangStateBuilder.operStatus(EnumConverter |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 331 | .teSubsystem2YangOperStatus(teSubsystemTeNode.opStatus())); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | if (teSubsystemTeNode.sourceTeNodeId() != null) { |
| 335 | InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder(); |
| 336 | |
| 337 | Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder(); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 338 | topologyBuilder = topologyBuilder.nodeRef(teTopologyService |
| 339 | .nodeKey(teSubsystemTeNode.sourceTeNodeId()).nodeId()) |
| 340 | .networkRef(teTopologyService |
| 341 | .nodeKey(teSubsystemTeNode.sourceTeNodeId()) |
| 342 | .networkId()); |
| 343 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 344 | issBuilder = issBuilder.topology(topologyBuilder.build()); |
| 345 | yangStateBuilder.informationSourceState(issBuilder.build()); |
| 346 | } |
| 347 | |
| 348 | return yangStateBuilder.build(); |
| 349 | } |
| 350 | |
| 351 | private static class ByteUtils { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 352 | |
| 353 | public static byte[] longToBytes(long x) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 354 | long temp = x; |
| 355 | byte[] b = new byte[8]; |
| 356 | for (int i = 0; i < b.length; i++) { |
| 357 | b[i] = new Long(temp & 0xff).byteValue(); |
| 358 | temp = temp >> 8; |
| 359 | } |
| 360 | return b; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | public static long bytesToLong(byte[] bytes) { |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 364 | return (bytes[7] & 255L) << 56 |
| 365 | | (bytes[6] & 255L) << 48 |
| 366 | | (bytes[5] & 255L) << 40 |
| 367 | | (bytes[4] & 255L) << 32 |
| 368 | | (bytes[3] & 255L) << 24 |
| 369 | | (bytes[2] & 255L) << 16 |
| 370 | | (bytes[1] & 255L) << 8 | bytes[0] & 255L; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG. |
| 376 | * |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 377 | * @param teTunnelTp TE TunnelTerminationPoint object |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 378 | * @param teTpId |
| 379 | * @param teTopologyService |
| 380 | * @param teNodeKey |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 381 | * @return TunnelTerminationPoint YANG object |
| 382 | */ |
| 383 | private static TunnelTerminationPoint teSubsystem2YangTtp( |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 384 | org.onosproject.tetopology.management.api.node |
| 385 | .TunnelTerminationPoint teTunnelTp, Long teTpId, |
| 386 | TeTopologyService teTopologyService, |
| 387 | TeNodeKey teNodeKey) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 388 | checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP); |
| 389 | |
| 390 | TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder = |
| 391 | DefaultTunnelTerminationPoint.builder().tunnelTpId(ByteUtils.longToBytes(teTpId.longValue())); |
| 392 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 393 | 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] | 394 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.Config.ConfigBuilder ttpConfigBuilder = |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 395 | 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] | 396 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder(); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 397 | 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] | 398 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.State.StateBuilder ttpStateBuilder = |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 399 | 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] | 400 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 401 | |
| 402 | // Assuming teTunnelTp only has one interLayerLock |
| 403 | if (teTunnelTp.interLayerLockList() != null && !teTunnelTp.interLayerLockList().isEmpty()) { |
| 404 | ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0)); |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 405 | ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 406 | } |
| 407 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 408 | // TODO: retrieve teTunnelTp.switchingLayer() and set it to ttpConfigBuilder and ttpStateBuilder |
| 409 | // TODO: retrieve more attributes from teTunnelTp and assign to ttpConfigBuilder and ttpStateBuilder |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 410 | // For which ones we can do the conversion? |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 411 | |
| 412 | LocalLinkConnectivities.LocalLinkConnectivitiesBuilder |
| 413 | localLinkConnectivitiesBuilder = DefaultLocalLinkConnectivities.builder(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 414 | if (teTunnelTp.localLinkConnectivityList() != null && !teTunnelTp.localLinkConnectivityList().isEmpty()) { |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 415 | for (LocalLinkConnectivity llcn : teTunnelTp.localLinkConnectivityList()) { |
| 416 | // convert teLinkId to networkLinkKey |
| 417 | if (llcn != null && llcn.constrainingElements() != null |
| 418 | && !llcn.constrainingElements().isEmpty()) { |
| 419 | TeLinkId telinkId = (TeLinkId) llcn.constrainingElements().get(0); |
| 420 | TeLinkTpGlobalKey globalKey = new TeLinkTpGlobalKey(teNodeKey, telinkId.value()); |
| 421 | NetworkLinkKey netLinkKey = teTopologyService.linkKey(globalKey); |
| 422 | NetworkLink networkLink = teTopologyService |
| 423 | .network(netLinkKey.networkId()).links().get(netLinkKey.linkId()); |
| 424 | LocalLinkConnectivityBuilder llcBuilder = DefaultLocalLinkConnectivity.builder(); |
| 425 | llcBuilder = llcBuilder.linkTpRef(networkLink.source().tpId()); |
| 426 | localLinkConnectivitiesBuilder.addToLocalLinkConnectivity(llcBuilder.build()); |
| 427 | } |
| 428 | } |
| 429 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 430 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 431 | ttpConfigBuilder = ttpConfigBuilder.localLinkConnectivities(localLinkConnectivitiesBuilder.build()); |
| 432 | ttpStateBuilder = ttpStateBuilder.localLinkConnectivities(localLinkConnectivitiesBuilder.build()); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 433 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 434 | |
| 435 | tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build()) |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 436 | .state(ttpStateBuilder.build()); |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 437 | SupportingTunnelTerminationPoint.SupportingTunnelTerminationPointBuilder |
| 438 | supportTtpBuilder = DefaultSupportingTunnelTerminationPoint.builder(); |
| 439 | if (teTunnelTp.supportingTtpId() != null) { |
| 440 | TeTopologyKey teTopologyKey = new TeTopologyKey(teTunnelTp.supportingTtpId().providerId(), |
| 441 | teTunnelTp.supportingTtpId().clientId(), |
| 442 | teTunnelTp.supportingTtpId().topologyId()); |
| 443 | |
| 444 | TeNodeKey teNodeKeySup = new TeNodeKey(teTopologyKey, teTunnelTp.supportingTtpId().teNodeId()); |
| 445 | NetworkNodeKey networkNodeKey = teTopologyService.nodeKey(teNodeKeySup); |
| 446 | NetworkId netId = NetworkId.fromString(networkNodeKey.networkId().toString()); |
| 447 | |
| 448 | supportTtpBuilder = supportTtpBuilder |
| 449 | .nodeRef(NodeId.fromString(networkNodeKey.nodeId().toString())) |
| 450 | .networkRef(netId) |
| 451 | .tunnelTpRef(ByteUtils.longToBytes(teTunnelTp.supportingTtpId().ttpId())); |
| 452 | |
| 453 | tunnelTpBuilder = tunnelTpBuilder.addToSupportingTunnelTerminationPoint(supportTtpBuilder.build()); |
| 454 | } |
| 455 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 456 | |
| 457 | return tunnelTpBuilder.build(); |
| 458 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 459 | |
| 460 | /** |
| 461 | * Node object conversion from TE Topology subsystem to YANG. |
| 462 | * |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 463 | * @param teSubsystem TE subsystem node |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 464 | * @param teTopologyService teTopology core service |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 465 | * @param teTopologyKey teTopologyKey |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 466 | * @return YANG node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 467 | */ |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 468 | public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem, |
| 469 | TeTopologyService teTopologyService, |
| 470 | TeTopologyKey teTopologyKey) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 471 | checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE); |
| 472 | |
| 473 | NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString()); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 474 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 475 | Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId); |
| 476 | |
| 477 | if (teSubsystem.supportingNodeIds() != null) { |
| 478 | List<SupportingNode> sNodes = Lists.newArrayList(); |
| 479 | SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode |
| 480 | .builder(); |
| 481 | for (NetworkNodeKey nodeKey : teSubsystem.supportingNodeIds()) { |
| 482 | sNodes.add(spNodeBuilder |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 483 | .networkRef(NetworkId |
| 484 | .fromString(nodeKey.networkId().toString())) |
| 485 | .nodeRef(NodeId.fromString(nodeKey.nodeId().toString())) |
| 486 | .build()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 487 | } |
| 488 | builder = builder.supportingNode(sNodes); |
| 489 | } |
| 490 | |
| 491 | if (teSubsystem.terminationPoints() != null) { |
| 492 | AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode |
| 493 | .builder(); |
| 494 | Map<KeyId, TerminationPoint> teSubsystemTeTp = teSubsystem |
| 495 | .terminationPoints(); |
| 496 | |
| 497 | for (TerminationPoint teTp : teSubsystemTeTp.values()) { |
| 498 | tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 499 | .teSubsystem2YangTerminationPoint(teTp)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 500 | } |
| 501 | builder.addYangAugmentedInfo(tpAugmentBuilder.build(), |
| 502 | AugmentedNdNode.class); |
| 503 | } |
| 504 | |
| 505 | if (teSubsystem.teNode() != null) { |
| 506 | AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode |
| 507 | .builder(); |
| 508 | |
| 509 | TeNode teSubsystemTeNode = teSubsystem.teNode(); |
| 510 | |
| 511 | TeBuilder yangTeBuilder = DefaultTe.builder(); |
| 512 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 513 | nodeAugmentBuilder = nodeAugmentBuilder |
| 514 | .teNodeId(TeNodeId.of(DottedQuad.of(Ip4Address |
| 515 | .valueOf((int) teSubsystemTeNode.teNodeId()) |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 516 | .toString()))); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 517 | |
| 518 | // Set configuration data |
| 519 | // Set state data |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 520 | yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode, teTopologyService)) |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 521 | .state(teNode2YangState(teSubsystemTeNode, teTopologyService)); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 522 | |
| 523 | if (teSubsystemTeNode.tunnelTerminationPoints() != null) { |
| 524 | for (Map.Entry<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> entry : |
| 525 | teSubsystemTeNode.tunnelTerminationPoints().entrySet()) { |
| 526 | yangTeBuilder = yangTeBuilder |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 527 | .addToTunnelTerminationPoint(teSubsystem2YangTtp(entry |
| 528 | .getValue(), entry.getKey(), teTopologyService, |
| 529 | new TeNodeKey(teTopologyKey, teSubsystemTeNode.teNodeId()))); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build()); |
| 534 | builder.addYangAugmentedInfo(nodeAugmentBuilder.build(), |
| 535 | AugmentedNwNode.class); |
| 536 | } |
| 537 | return builder.build(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Node object conversion from YANG to TE Topology subsystem. |
| 542 | * |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 543 | * @param yangNode Node in YANG model |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 544 | * @param yangNetwork YANG network |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 545 | * @param yangNetworks YANG networks |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 546 | * @return TE subsystem node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 547 | */ |
| 548 | public static org.onosproject.tetopology.management.api.node.NetworkNode |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 549 | yang2TeSubsystemNode(Node yangNode, Network yangNetwork, |
| 550 | Networks yangNetworks) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 551 | checkNotNull(yangNode, E_NULL_YANG_NODE); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 552 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 553 | org.onosproject.tetopology.management.api.node.DefaultNetworkNode node; |
| 554 | List<NetworkNodeKey> spNodes = null; |
| 555 | TeNode teNode = null; |
| 556 | Map<KeyId, TerminationPoint> tps = null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 557 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 558 | if (yangNode.supportingNode() != null) { |
| 559 | spNodes = Lists.newArrayList(); |
| 560 | for (SupportingNode yangSpNode : yangNode.supportingNode()) { |
| 561 | NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()), |
| 562 | KeyId.keyId(yangSpNode.networkRef().uri().toString())); |
| 563 | spNodes.add(nodeKey); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (yangNode.yangAugmentedInfoMap() != null |
| 568 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 569 | |
| 570 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 571 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 572 | if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) { |
| 573 | tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment); |
| 574 | } |
| 575 | |
| 576 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode |
| 577 | .yangAugmentedInfo(AugmentedNwNode.class); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 578 | if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.teNodeId() != null) { |
| 579 | TeNodeId teNodeId = yangNodeAugment.teNodeId(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 580 | Te yangNodeAugTe = yangNodeAugment.te(); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 581 | teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, teNodeId, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 582 | yangNetwork, |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 583 | yangNetworks, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 584 | yangNode, |
| 585 | tps); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | node = new org.onosproject.tetopology.management.api.node |
| 590 | .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps); |
| 591 | return node; |
| 592 | } |
| 593 | |
| 594 | // TODO: convert connectivity matrix from yang to te |
| 595 | private static Map<Long, ConnectivityMatrix> |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 596 | yang2TeSubsystemNodeConnectivityMatrix(String networkId, |
| 597 | String nodeId, |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 598 | ConnectivityMatrices yangMatrices) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 599 | |
| 600 | Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap(); |
| 601 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 602 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology |
| 603 | .tenodeconnectivitymatrix.connectivitymatrices.ConnectivityMatrix> |
| 604 | yangMatrix = yangMatrices.connectivityMatrix(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 605 | 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] | 606 | .topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 607 | ConnectivityMatrix cmYang : yangMatrix) { |
| 608 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 609 | 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] | 610 | |
| 611 | UnderlayAbstractPath underlayPath = null; // ignore |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 612 | List<org.onosproject.tetopology.management.api.link.PathElement> pathElements = Lists.newArrayList(); |
| 613 | Boolean loose = false; |
| 614 | long longTeNodeId = TeConstants.NIL_LONG_VALUE; |
| 615 | if (cmYang != null && cmYang.underlay() != null && cmYang.underlay().primaryPath() != null |
| 616 | && cmYang.underlay().primaryPath().pathElement() != null |
| 617 | && !cmYang.underlay().primaryPath().pathElement().isEmpty()) { |
| 618 | for (PathElement yangPathEl : cmYang.underlay().primaryPath().pathElement()) { |
| 619 | ElementType type = null; |
| 620 | if (yangPathEl.type() instanceof UnnumberedLink) { |
| 621 | String rS = ((UnnumberedLink) (yangPathEl.type())).routerId().toString(); |
| 622 | org.onlab.packet.IpAddress routerId = org.onlab.packet.IpAddress.valueOf(rS); |
| 623 | long interfaceId = ((UnnumberedLink) yangPathEl.type()).interfaceId(); |
| 624 | type = new org.onosproject.tetopology.management.api.link.UnnumberedLink(routerId, interfaceId); |
| 625 | longTeNodeId = Long.valueOf(((UnnumberedLink) yangPathEl.type()).routerId().toString()); |
| 626 | } else if (yangPathEl.type() instanceof Ipv4Address) { |
| 627 | short v4PrefixLength = ((Ipv4Address) yangPathEl.type()) |
| 628 | .v4PrefixLength(); |
| 629 | |
| 630 | Ip4Address v4Address = Ip4Address |
| 631 | .valueOf(((Ipv4Address) yangPathEl.type()) |
| 632 | .v4Address().string()); |
| 633 | |
| 634 | loose = ((Ipv4Address) yangPathEl.type()).v4Loose(); |
| 635 | type = new TeIpv4(v4Address, v4PrefixLength); |
| 636 | } |
| 637 | org.onosproject.tetopology.management.api.link.PathElement |
| 638 | patel = new org.onosproject.tetopology.management.api.link |
| 639 | .PathElement(yangPathEl.pathElementId(), |
| 640 | longTeNodeId, |
| 641 | type, |
| 642 | loose); |
| 643 | pathElements.add(patel); |
| 644 | } |
| 645 | } |
| 646 | underlayPath = new UnderlayAbstractPath(pathElements, loose); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 647 | |
| 648 | List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now |
| 649 | |
| 650 | List<ElementType> constrainingElements = Lists.newArrayList(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 651 | 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] | 652 | constrainingElements.add(to); |
| 653 | |
| 654 | BitSet flags = new BitSet(); // what are the flags in cmYang? |
| 655 | |
| 656 | List<Long> srlgs = Lists.newArrayList(); |
| 657 | if (cmYang.teSrlgs() != null) { |
| 658 | for (Srlg srlg : cmYang.teSrlgs().value()) { |
| 659 | srlgs.add(srlg.uint32()); |
| 660 | } |
| 661 | } |
| 662 | TePathAttributes teAttributes = new |
| 663 | TePathAttributes(cmYang.teDefaultMetric(), |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 664 | cmYang.teDelayMetric(), |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 665 | srlgs); |
| 666 | ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(), |
| 667 | from, |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 668 | mergingList, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 669 | constrainingElements, |
| 670 | flags, |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 671 | teAttributes, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 672 | underlayPath); |
| 673 | |
| 674 | teCmList.put(cmYang.id(), coreCm); |
| 675 | } |
| 676 | |
| 677 | return teCmList; |
| 678 | } |
| 679 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 680 | private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut, Networks yangNetworks) { |
| 681 | TeTopologyKey tetopokey = LinkConverter.findTopologyId(yangNetworks, |
| 682 | ut.networkRef()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 683 | return tetopokey; |
| 684 | } |
| 685 | |
| 686 | // TODO: retrieve the details of tunnel termiantion points from yang to te |
| 687 | private static Map<Long, org.onosproject.tetopology.management.api.node. |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 688 | TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps, Node yangNode, |
| 689 | Networks yangNetworks) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 690 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps |
| 691 | .newHashMap(); |
| 692 | for (TunnelTerminationPoint ttpYang : ttps) { |
| 693 | |
| 694 | SwitchingType switchingLayer = null; // how to find switching type? |
| 695 | EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding(); |
| 696 | BitSet flags = new BitSet(); // how to set flags? |
| 697 | List<Long> interLayerLockList = Lists.newArrayList(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 698 | |
| 699 | if (ttpYang.config() != null) { |
| 700 | interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list |
| 701 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 702 | |
| 703 | List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList(); |
| 704 | // FIXME: once new yang model is used, we can make llc |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 705 | ElementType elt = null; |
| 706 | List<ElementType> eltList = Lists.newArrayList(); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 707 | if (ttpYang.config() != null && |
| 708 | ttpYang.config().localLinkConnectivities() != null && |
| 709 | CollectionUtils.isNotEmpty(ttpYang.config().localLinkConnectivities().localLinkConnectivity())) { |
| 710 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110 |
| 711 | .ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities |
| 712 | .LocalLinkConnectivity yangLlc : ttpYang.config() |
| 713 | .localLinkConnectivities().localLinkConnectivity()) { |
| 714 | if (MapUtils.isNotEmpty(yangNode.yangAugmentedInfoMap())) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 715 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 716 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 717 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml |
| 718 | .ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology |
| 719 | .networks.network.node.augmentedndnode |
| 720 | .TerminationPoint tpItem : yangTpNodeAugment.terminationPoint()) { |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 721 | if (tpItem.tpId().uri().string().equals(yangLlc.linkTpRef().toString())) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 722 | if (tpItem.yangAugmentedInfoMap() != null |
| 723 | && !tpItem.yangAugmentedInfoMap().isEmpty()) { |
| 724 | AugmentedNtTerminationPoint yangTpAugment = |
| 725 | (AugmentedNtTerminationPoint) tpItem |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 726 | .yangAugmentedInfo(AugmentedNtTerminationPoint.class); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 727 | if (yangTpAugment.teTpId() != null) { |
| 728 | elt = new TeLinkId(Long.valueOf(yangTpAugment.teTpId().toString())); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 729 | break; |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | eltList.add(elt); |
| 736 | // tercap.linkTp().toString() //tpId -> tp -> te-tp-id (long) |
| 737 | } |
| 738 | } |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 739 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 740 | TePathAttributes teAttributes = null; // how to find these |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 741 | // attributes from ttpYang? |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 742 | UnderlayAbstractPath underlayPath = null; // how to find underlayAbstractPath from ttpYang? |
| 743 | LocalLinkConnectivity llc = new LocalLinkConnectivity(eltList, |
| 744 | flags, |
| 745 | teAttributes, |
| 746 | underlayPath); |
| 747 | localLinkConnectivityList.add(llc); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 748 | |
| 749 | float[] availAdaptBandwidth = null; // how to find availableBandwidth? |
| 750 | |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 751 | TeTopologyKey teTopologyKey = null; |
| 752 | |
| 753 | Object networkRefObj = null; |
| 754 | NetworkId networkId = null; |
| 755 | if (ttpYang != null && ttpYang.supportingTunnelTerminationPoint() != null |
| 756 | && !ttpYang.supportingTunnelTerminationPoint().isEmpty() |
| 757 | && ttpYang.supportingTunnelTerminationPoint().get(0) != null) { |
| 758 | networkRefObj = ttpYang.supportingTunnelTerminationPoint() |
| 759 | .get(0).networkRef(); |
| 760 | } |
| 761 | if (networkRefObj != null) { |
| 762 | teTopologyKey = LinkConverter.findTopologyId(yangNetworks, |
| 763 | networkRefObj); |
| 764 | networkId = NetworkId.fromString((String) networkRefObj); |
| 765 | } |
| 766 | |
| 767 | Network teNetworkFound = null; |
| 768 | if (yangNetworks.network() != null |
| 769 | && !yangNetworks.network().isEmpty() |
| 770 | && networkId != null) { |
| 771 | for (Network ynetItem : yangNetworks.network()) { |
| 772 | if (ynetItem.networkId() != null) { |
| 773 | if (ynetItem.networkId().equals(networkId)) { |
| 774 | teNetworkFound = ynetItem; |
| 775 | break; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | TeNodeId teNodeIdSupport = null; |
| 781 | if (teNetworkFound != null |
| 782 | && ttpYang != null |
| 783 | && ttpYang.supportingTunnelTerminationPoint() != null |
| 784 | && ttpYang.supportingTunnelTerminationPoint().get(0) != null) { |
| 785 | |
| 786 | String s = ((String) ttpYang.supportingTunnelTerminationPoint().get(0).nodeRef()); |
| 787 | int integ = Integer.valueOf(s); |
| 788 | NodeId nodeId = NodeId.fromString(DottedQuad.of(Ip4Address.valueOf(integ).toString()).toString()); |
| 789 | teNodeIdSupport = LinkConverter |
| 790 | .findTeNodeId(teNetworkFound, |
| 791 | nodeId); |
| 792 | } |
| 793 | |
| 794 | long tenIdLong = -1; |
| 795 | if (teNodeIdSupport != null) { |
| 796 | tenIdLong = Ip4Address |
| 797 | .valueOf(teNodeIdSupport.dottedQuad().string()).toInt(); |
| 798 | } |
| 799 | |
| 800 | TeNodeKey teNodeKey = null; |
| 801 | if (teTopologyKey != null && tenIdLong != -1) { |
| 802 | teNodeKey = new TeNodeKey(teTopologyKey, tenIdLong); |
| 803 | } |
| 804 | TtpKey supportTtpKey = null; |
| 805 | if (teNodeKey != null && ttpYang != null |
| 806 | && ttpYang.supportingTunnelTerminationPoint() != null |
| 807 | && !ttpYang.supportingTunnelTerminationPoint().isEmpty() |
| 808 | && ttpYang.supportingTunnelTerminationPoint().get(0) != null) { |
| 809 | supportTtpKey = new TtpKey(teNodeKey, |
| 810 | ByteUtils.bytesToLong((byte[]) ttpYang |
| 811 | .supportingTunnelTerminationPoint().get(0) |
| 812 | .tunnelTpRef())); |
| 813 | } |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 814 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 815 | org.onosproject.tetopology.management.api.node. |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 816 | TunnelTerminationPoint ttpTe = new |
| 817 | org.onosproject.tetopology.management.api.node. |
| 818 | DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), |
| 819 | switchingLayer, |
| 820 | encodingLayer, |
| 821 | flags, |
| 822 | interLayerLockList, |
| 823 | localLinkConnectivityList, |
| 824 | availAdaptBandwidth, |
Aihua Guo | 6026b35 | 2017-02-08 17:26:54 -0500 | [diff] [blame] | 825 | supportTtpKey); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 826 | |
| 827 | ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe); |
| 828 | } |
| 829 | |
| 830 | return ttpsMap; |
| 831 | } |
| 832 | |
| 833 | private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe, |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 834 | TeNodeId teNodeId, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 835 | Network yangNetwork, |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 836 | Networks yangNetworks, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 837 | Node yangNode, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 838 | Map<KeyId, TerminationPoint> teTps) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 839 | |
| 840 | |
| 841 | NodeId yangNodeId = yangNode.nodeId(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 842 | |
| 843 | NetworkId yangNetworkId = yangNetwork.networkId(); |
| 844 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 845 | long teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string()).toInt(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 846 | |
| 847 | TeTopologyKey underlayTopologyIdId = null; |
| 848 | |
| 849 | // FIXME: yang has a list of supporting nodes, but TeNode only has one |
| 850 | // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId? |
| 851 | TeNodeKey supportTeNodeId = null; |
| 852 | // supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId) |
| 853 | // yangSupportNodes.get(0). |
| 854 | |
| 855 | TeNodeKey sourceTeNodeId = null; //ignore |
| 856 | CommonNodeData teData = null; |
| 857 | Map<Long, ConnectivityMatrix> connMatrices = null; |
| 858 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null; |
| 859 | List<Long> teLinkIds = Lists.newArrayList(); |
| 860 | List<Long> teTpIds = Lists.newArrayList(); |
| 861 | |
| 862 | // ********************************************** to find teLinkIds |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 863 | // teLinkIds should be supposed to get from YANG Link and TP data. |
| 864 | // For now, assuming each teTp is sourcing a TE link . |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 865 | if (MapUtils.isNotEmpty(teTps)) { |
| 866 | for (Map.Entry<KeyId, TerminationPoint> entry : teTps.entrySet()) { |
| 867 | if (entry.getValue().teTpId() != null) { |
| 868 | teTpIds.add(entry.getValue().teTpId()); |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 869 | teLinkIds.add(entry.getValue().teTpId()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | // ********************************************** to find teTpIds |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 874 | // if (yangNode.yangAugmentedInfoMap() != null |
| 875 | // && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 876 | // |
| 877 | // AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 878 | // .yangAugmentedInfo(AugmentedNdNode.class); |
| 879 | // |
| 880 | // if (yangTpNodeAugment.terminationPoint() != null) { |
| 881 | // for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 882 | // .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 883 | // yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 884 | // teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string())); |
| 885 | // } |
| 886 | // } |
| 887 | // } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 888 | // ********************************************** |
| 889 | |
| 890 | Config ynodeAugCfg = yangNodeAugTe.config(); |
| 891 | |
| 892 | if (ynodeAugCfg != null) { |
| 893 | TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes(); |
| 894 | if (teNodeAttr != null) { |
| 895 | |
| 896 | if (teNodeAttr.underlayTopology() != null) { |
| 897 | |
| 898 | underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 899 | .underlayTopology(), yangNetworks); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 900 | } |
| 901 | BitSet flags = new BitSet(); |
| 902 | if (teNodeAttr.isAbstract()) { |
| 903 | flags.set(TeNode.BIT_ABSTRACT); |
| 904 | } |
| 905 | teData = new CommonNodeData( |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 906 | null, // teNodeAttr.name().string(), |
| 907 | EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()), |
| 908 | EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()), |
| 909 | flags); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 910 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 911 | // if (teNodeAttr.connectivityMatrix() != null) { |
| 912 | if (teNodeAttr.connectivityMatrices() != null) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 913 | connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(), |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 914 | yangNodeId.uri().toString(), |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 915 | teNodeAttr.connectivityMatrices()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | if (yangNodeAugTe.tunnelTerminationPoint() != null) { |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 922 | ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint(), |
| 923 | yangNode, |
| 924 | yangNetworks); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 925 | } |
| 926 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 927 | TeNode teNode = new DefaultTeNode(teNodeIdLong, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 928 | underlayTopologyIdId, |
| 929 | supportTeNodeId, |
| 930 | sourceTeNodeId, |
| 931 | teData, |
| 932 | connMatrices, |
| 933 | teLinkIds, |
| 934 | ttps, |
| 935 | teTpIds); |
| 936 | return teNode; |
| 937 | } |
| 938 | |
| 939 | private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) { |
| 940 | Map<KeyId, TerminationPoint> tps; |
| 941 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 942 | tps = Maps.newHashMap(); |
| 943 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 944 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 945 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 946 | tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()), |
| 947 | TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode)); |
| 948 | } |
| 949 | return tps; |
| 950 | } |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 951 | return null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 954 | /** |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 955 | * Converts a TE Topology node event from the data format used in the core |
| 956 | * to its corresponding YANG Object (YO) format. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 957 | * |
| 958 | * @param eventType Node event type |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 959 | * @param eventData TE Topology node event data |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 960 | * @return YANG Object converted from nodeData |
| 961 | */ |
| 962 | public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 963 | NetworkNodeEventSubject eventData) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 964 | TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 965 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 966 | TeTopologyEventType yangEventType = new TeTopologyEventType(eventType); |
| 967 | builder.eventType(yangEventType); |
| 968 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 969 | NetworkId newtorkId = NetworkId.fromString(eventData.key().networkId().toString()); |
| 970 | builder.networkRef(newtorkId); |
| 971 | NodeId nodeId = NodeId.fromString(eventData.key().nodeId().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 972 | builder.nodeRef(nodeId); |
| 973 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 974 | NetworkNode node = eventData.neworkNode(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 975 | 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] | 976 | rev20170110.ietftetopology.tenodeconfigattributesnotification. |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 977 | TeNodeAttributes teNodeAttributes = node == null ? null |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 978 | : teNode2YangTeNodeAttributes(node.teNode()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 979 | builder.teNodeAttributes(teNodeAttributes); |
| 980 | |
| 981 | return builder.build(); |
| 982 | } |
| 983 | |
| 984 | private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 985 | ietf.te.topology.rev20170110.ietftetopology. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 986 | tenodeconfigattributesnotification. |
| 987 | TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) { |
| 988 | |
| 989 | 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] | 990 | rev20170110.ietftetopology.tenodeconfigattributesnotification. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 991 | TeNodeAttributes.TeNodeAttributesBuilder attrBuilder = |
| 992 | 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] | 993 | rev20170110.ietftetopology.tenodeconfigattributesnotification. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 994 | DefaultTeNodeAttributes.builder(); |
| 995 | |
| 996 | if (teNode.connectivityMatrices() != null) { |
| 997 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 998 | 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] | 999 | .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix |
| 1000 | .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf. |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1001 | params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs. |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1002 | DefaultConnectivityMatrix.builder(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1003 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1004 | teNode.connectivityMatrices().entrySet()) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1005 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 1006 | .id(teCmEntry.getKey()) |
| 1007 | .isAllowed(!teCmEntry.getValue().flags() |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1008 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1009 | .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] | 1010 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom |
| 1011 | .FromBuilder() // TODO: for now, assuming that there is |
| 1012 | // only one 'from', and mergingList is empty |
| 1013 | .tpRef(teCmEntry.getValue().from()) |
| 1014 | .build()) |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1015 | .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] | 1016 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix |
| 1017 | .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
| 1018 | // one item in constrainingElements list |
| 1019 | .tpRef(teCmEntry.getValue().constrainingElements().get(0)) |
| 1020 | .build()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1021 | attrBuilder = attrBuilder |
| 1022 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1023 | .build()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | 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] | 1028 | rev20170110.ietftetopology.tenodeconfigattributesnotification. |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1029 | TeNodeAttributes teNodeAttributes = attrBuilder.build(); |
| 1030 | |
| 1031 | return teNodeAttributes; |
| 1032 | } |
| 1033 | |
| 1034 | public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 1035 | NetworkId networkRef = NetworkId.fromString(yangNodeEvent.networkRef().toString()); |
| 1036 | NodeId nodeRef = NodeId.fromString(yangNodeEvent.nodeRef().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1037 | KeyId networkId = KeyId.keyId(networkRef.uri().toString()); |
| 1038 | KeyId nodeId = KeyId.keyId(nodeRef.uri().toString()); |
| 1039 | |
| 1040 | NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId); |
| 1041 | |
| 1042 | return networkNodeKey; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 1045 | /** |
| 1046 | * Converts YangNode event to NetworkNode. |
| 1047 | * |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1048 | * @param yangNodeEvent yangNodeEvent |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 1049 | * @param teTopologyService teTopologyService |
| 1050 | * @return NetworkNode |
| 1051 | */ |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1052 | public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent, |
| 1053 | TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1054 | KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId(); |
| 1055 | |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 1056 | org.onosproject.tetopology.management.api.Network network = teTopologyService.network( |
| 1057 | yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1058 | if (network == null) { |
| 1059 | return null; |
| 1060 | } |
| 1061 | |
| 1062 | NetworkNode networkNode = network.node(networkNodeId); |
| 1063 | if (networkNode == null) { |
| 1064 | return null; |
| 1065 | } |
| 1066 | |
| 1067 | List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds(); |
| 1068 | Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints(); |
| 1069 | |
| 1070 | TeNode teNode = networkNode.teNode(); |
| 1071 | if (teNode == null) { |
| 1072 | return null; |
| 1073 | } |
| 1074 | |
| 1075 | TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode); |
| 1076 | |
| 1077 | NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps); |
| 1078 | |
| 1079 | return updatedNetworkNode; |
| 1080 | } |
| 1081 | |
| 1082 | private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) { |
| 1083 | |
| 1084 | long teNodeId = oldTeNode.teNodeId(); |
| 1085 | TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId(); |
| 1086 | TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId(); |
| 1087 | TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId(); |
| 1088 | Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices(); |
| 1089 | List<Long> teLinkIds = oldTeNode.teLinkIds(); |
| 1090 | Map<Long, org.onosproject.tetopology.management. |
| 1091 | api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints(); |
| 1092 | List<Long> teTpIds = oldTeNode.teLinkIds(); |
| 1093 | String name = oldTeNode.name(); |
| 1094 | TeStatus adminStatus = oldTeNode.adminStatus(); |
| 1095 | TeStatus opStatus = oldTeNode.opStatus(); |
| 1096 | BitSet flags = oldTeNode.flags(); |
| 1097 | |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1098 | 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] | 1099 | .tenodeconfigattributesnotification |
| 1100 | .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes(); |
| 1101 | |
| 1102 | if (yangTeNodeAttrs != null) { |
| 1103 | TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus(); |
| 1104 | if (yangAdminStatus != null) { |
| 1105 | adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus); |
| 1106 | } |
| 1107 | |
| 1108 | BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags(); |
| 1109 | if (yangFlags != null) { |
| 1110 | flags = yangFlags; |
| 1111 | } |
| 1112 | |
| 1113 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1114 | ietf.te.topology.rev20170110.ietftetopology |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1115 | .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs |
| 1116 | .connectivityMatrix(); |
| 1117 | if (yangConnMatrices != null) { |
| 1118 | for (org.onosproject.yang.gen.v1. |
| 1119 | urn.ietf.params.xml.ns.yang. |
| 1120 | ietf.te.topology |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1121 | .rev20170110.ietftetopology |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1122 | .tenodeconnectivitymatrixabs |
| 1123 | .ConnectivityMatrix yangConnMatrix : yangConnMatrices) { |
| 1124 | Long cmId = new Long(yangConnMatrix.id()); |
| 1125 | ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id())); |
| 1126 | if (oldConnMatrix != null) { |
| 1127 | ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix, |
| 1128 | oldConnMatrix); |
| 1129 | connMatrices.remove(cmId); |
| 1130 | connMatrices.put(cmId, newConnMatrix); |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags); |
| 1137 | TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData, |
| 1138 | connMatrices, teLinkIds, ttps, teTpIds); |
| 1139 | |
| 1140 | return updatedTeNode; |
| 1141 | } |
| 1142 | |
| 1143 | private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1. |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1144 | urn.ietf.params.xml.ns.yang. |
| 1145 | ietf.te.topology |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 1146 | .rev20170110.ietftetopology |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 1147 | .tenodeconnectivitymatrixabs |
| 1148 | .ConnectivityMatrix yangConnMatrix, |
| 1149 | ConnectivityMatrix oldTeConnMatrix) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 1150 | |
| 1151 | long id = yangConnMatrix.id(); |
| 1152 | ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef())); |
| 1153 | UnderlayAbstractPath underlayPath = null; |
| 1154 | List<ElementType> mergingList = Lists.newArrayList(); |
| 1155 | |
| 1156 | List<ElementType> constrainingElements = Lists.newArrayList(); |
| 1157 | ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef())); |
| 1158 | constrainingElements.add(to); |
| 1159 | |
| 1160 | BitSet flags = oldTeConnMatrix.flags(); |
| 1161 | |
| 1162 | TePathAttributes teAttributes = oldTeConnMatrix.teAttributes(); |
| 1163 | |
| 1164 | ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id, |
| 1165 | from, |
| 1166 | mergingList, |
| 1167 | constrainingElements, |
| 1168 | flags, |
| 1169 | teAttributes, |
| 1170 | underlayPath); |
| 1171 | return updatedConnMatrix; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1172 | } |
| 1173 | } |