Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [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.tetopology.management.api; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import java.util.BitSet; |
| 23 | |
| 24 | /** |
| 25 | * Representation of topology common attributes. |
| 26 | */ |
| 27 | public class CommonTopologyData { |
| 28 | private final OptimizationType optimization; |
| 29 | private final BitSet flags; |
| 30 | private final KeyId networkId; |
| 31 | private final DeviceId ownerId; |
| 32 | |
| 33 | /** |
| 34 | * Create an instance of CommonTopologyData. |
| 35 | * |
| 36 | * @param networkId the network identifier |
| 37 | * @param optimization the TE topology optimization criteria |
| 38 | * @param flags the topology characteristics flags |
| 39 | * @param ownerId the controller identifier owning this topology |
| 40 | */ |
| 41 | public CommonTopologyData(KeyId networkId, OptimizationType optimization, |
| 42 | BitSet flags, DeviceId ownerId) { |
| 43 | this.optimization = optimization; |
| 44 | this.flags = flags; |
| 45 | this.networkId = networkId; |
| 46 | this.ownerId = ownerId; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Creates an instance of CommonTopologyData from a given TE topology. |
| 51 | * |
| 52 | * @param teTopology the given TE Topology |
| 53 | */ |
| 54 | public CommonTopologyData(TeTopology teTopology) { |
| 55 | optimization = teTopology.optimization(); |
| 56 | flags = teTopology.flags(); |
| 57 | networkId = teTopology.networkId(); |
| 58 | ownerId = teTopology.ownerId(); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * Returns the topology optimization type. |
| 64 | * |
| 65 | * @return the optimization type |
| 66 | */ |
| 67 | public OptimizationType optimization() { |
| 68 | return optimization; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the network identifier. |
| 73 | * |
| 74 | * @return the network id |
| 75 | */ |
| 76 | public KeyId networkId() { |
| 77 | return networkId; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the topology characteristics flags. |
| 82 | * |
| 83 | * @return the flags |
| 84 | */ |
| 85 | public BitSet flags() { |
| 86 | return flags; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the SDN controller identifier owning this topology. |
| 91 | * |
| 92 | * @return the SDN controller id |
| 93 | */ |
| 94 | public DeviceId ownerId() { |
| 95 | return ownerId; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hashCode(optimization, flags, ownerId, networkId); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public boolean equals(Object object) { |
| 105 | if (this == object) { |
| 106 | return true; |
| 107 | } |
| 108 | if (object instanceof CommonTopologyData) { |
| 109 | CommonTopologyData that = (CommonTopologyData) object; |
| 110 | return Objects.equal(optimization, that.optimization) && |
| 111 | Objects.equal(flags, that.flags) && |
| 112 | Objects.equal(networkId, that.networkId) && |
| 113 | Objects.equal(ownerId, that.ownerId); |
| 114 | } |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public String toString() { |
| 120 | return MoreObjects.toStringHelper(this) |
| 121 | .add("optimization", optimization) |
| 122 | .add("flags", flags) |
| 123 | .add("ownerId", ownerId) |
| 124 | .add("networkId", networkId) |
| 125 | .toString(); |
| 126 | } |
| 127 | } |