Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [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.tetopology.management.api.node; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import com.google.common.collect.Lists; |
| 22 | import org.onosproject.tetopology.management.api.link.ElementType; |
| 23 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 24 | import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath; |
| 25 | |
| 26 | import java.util.BitSet; |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
| 30 | * Represents node's switching limitations. |
| 31 | */ |
| 32 | public class ConnectivityMatrix extends AbstractConnectivity { |
| 33 | /** |
| 34 | * Indicates that switching is disallowed. |
| 35 | */ |
| 36 | public static final short BIT_DISALLOWED = 0; |
| 37 | |
| 38 | /** |
| 39 | * Indicates that an alternative switching connection path |
| 40 | * is available. |
| 41 | */ |
| 42 | public static final short BIT_ALTERNATIVE_PATH_AVAILABLE = 1; |
| 43 | |
| 44 | /** |
| 45 | * Indicates that switching in this node is disabled. |
| 46 | */ |
| 47 | public static final short BIT_DISABLED = 2; |
| 48 | |
| 49 | private final long key; |
| 50 | private final ElementType from; |
| 51 | // list of elements that can be merged with the "from" element |
| 52 | private final List<ElementType> mergingList; |
| 53 | |
| 54 | /** |
| 55 | * Creates a connectivity matrix instance. |
| 56 | * |
| 57 | * @param key the connectivity matrix key |
| 58 | * @param from the "from" element (e.g. TE link id or |
| 59 | * label) in the matrix |
| 60 | * @param mergingList the list of elements that can be merged |
| 61 | * with the "from" element |
| 62 | * @param constrainingElements the list of elements that can be constrained |
| 63 | * or connected to the "from" element |
| 64 | * @param flags the indicator whether this connectivity |
| 65 | * matrix is usable |
| 66 | * @param teAttributes the connectivity TE attributes of this matrix |
| 67 | * @param underlayPath the underlay path of the matrix |
| 68 | */ |
| 69 | public ConnectivityMatrix(long key, |
| 70 | ElementType from, |
| 71 | List<ElementType> mergingList, |
| 72 | List<ElementType> constrainingElements, |
| 73 | BitSet flags, |
| 74 | TePathAttributes teAttributes, |
| 75 | UnderlayAbstractPath underlayPath) { |
| 76 | super(constrainingElements, flags, teAttributes, underlayPath); |
| 77 | this.key = key; |
| 78 | this.from = from; |
| 79 | this.mergingList = mergingList != null ? |
| 80 | Lists.newArrayList(mergingList) : null; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns the key. |
| 85 | * |
| 86 | * @return connectivity matrix key |
| 87 | */ |
| 88 | public long key() { |
| 89 | return key; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns the "from" element of a connectivity matrix. |
| 94 | * |
| 95 | * @return the "from" of the connectivity matrix |
| 96 | */ |
| 97 | public ElementType from() { |
| 98 | return from; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the "merging list" can be merged with the "from" element. |
| 103 | * |
| 104 | * @return the "merging list" of the connectivity matrix |
| 105 | */ |
| 106 | public List<ElementType> mergingList() { |
| 107 | if (mergingList == null) { |
| 108 | return null; |
| 109 | } |
| 110 | return ImmutableList.copyOf(mergingList); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public int hashCode() { |
| 115 | return Objects.hashCode(key, from, mergingList, super.hashCode()); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean equals(Object object) { |
| 120 | if (this == object) { |
| 121 | return true; |
| 122 | } |
| 123 | if (object instanceof ConnectivityMatrix) { |
| 124 | if (!super.equals(object)) { |
| 125 | return false; |
| 126 | } |
| 127 | ConnectivityMatrix that = (ConnectivityMatrix) object; |
| 128 | return Objects.equal(this.key, that.key) && |
| 129 | Objects.equal(this.from, that.from) && |
| 130 | Objects.equal(this.mergingList, that.mergingList); |
| 131 | } |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public String toString() { |
| 137 | return MoreObjects.toStringHelper(this) |
| 138 | .add("key", key) |
| 139 | .add("from", from) |
| 140 | .add("mergingList", mergingList) |
| 141 | .add("constrainingElements", constrainingElements()) |
| 142 | .add("flags", flags()) |
| 143 | .add("teAttributes", teAttributes()) |
| 144 | .toString(); |
| 145 | } |
| 146 | } |