Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.bgpio.protocol.linkstate; |
| 17 | |
| 18 | import java.util.Iterator; |
| 19 | import java.util.List; |
| 20 | import java.util.Objects; |
| 21 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 22 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType; |
| 23 | import org.onosproject.bgpio.types.BgpValueType; |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 24 | |
| 25 | import com.google.common.base.MoreObjects; |
| 26 | |
| 27 | /** |
| 28 | * This Class stores path Attributes, protocol ID and Identifier of LinkState NLRI. |
| 29 | */ |
| 30 | public class PathAttrNlriDetails { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 31 | private List<BgpValueType> pathAttributes; |
Sho SHIMIZU | 98fc1e7 | 2015-11-23 10:25:22 -0800 | [diff] [blame] | 32 | private ProtocolType protocolID; |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 33 | private long identifier; |
| 34 | |
| 35 | /** |
| 36 | * Sets path attribute with specified path attribute. |
| 37 | * |
| 38 | * @param pathAttributes in update message |
| 39 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 40 | public void setPathAttribute(List<BgpValueType> pathAttributes) { |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 41 | this.pathAttributes = pathAttributes; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns path attributes. |
| 46 | * |
| 47 | * @return path attributes |
| 48 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 49 | public List<BgpValueType> pathAttributes() { |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 50 | return this.pathAttributes; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Sets protocolID with specified protocolID. |
| 55 | * |
| 56 | * @param protocolID in linkstate nlri |
| 57 | */ |
Sho SHIMIZU | 98fc1e7 | 2015-11-23 10:25:22 -0800 | [diff] [blame] | 58 | public void setProtocolID(ProtocolType protocolID) { |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 59 | this.protocolID = protocolID; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns protocolID. |
| 64 | * |
| 65 | * @return protocolID |
| 66 | */ |
Sho SHIMIZU | 98fc1e7 | 2015-11-23 10:25:22 -0800 | [diff] [blame] | 67 | public ProtocolType protocolID() { |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 68 | return this.protocolID; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Sets identifier with specified identifier. |
| 73 | * |
| 74 | * @param identifier in linkstate nlri |
| 75 | */ |
| 76 | public void setIdentifier(long identifier) { |
| 77 | this.identifier = identifier; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns Identifier. |
| 82 | * |
| 83 | * @return Identifier |
| 84 | */ |
| 85 | public long identifier() { |
| 86 | return this.identifier; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public int hashCode() { |
| 91 | return Objects.hash(pathAttributes, protocolID, identifier); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public boolean equals(Object obj) { |
| 96 | if (this == obj) { |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | if (obj instanceof PathAttrNlriDetails) { |
| 101 | int countObjSubTlv = 0; |
| 102 | int countOtherSubTlv = 0; |
| 103 | boolean isCommonSubTlv = true; |
| 104 | PathAttrNlriDetails other = (PathAttrNlriDetails) obj; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 105 | Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator(); |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 106 | countOtherSubTlv = other.pathAttributes.size(); |
| 107 | countObjSubTlv = pathAttributes.size(); |
| 108 | if (countObjSubTlv != countOtherSubTlv) { |
| 109 | return false; |
| 110 | } else { |
| 111 | while (objListIterator.hasNext() && isCommonSubTlv) { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 112 | BgpValueType subTlv = objListIterator.next(); |
Priyanka B | da60542 | 2015-11-18 09:36:58 +0530 | [diff] [blame] | 113 | if (pathAttributes.contains(subTlv) && other.pathAttributes.contains(subTlv)) { |
| 114 | isCommonSubTlv = Objects.equals(pathAttributes.get(pathAttributes.indexOf(subTlv)), |
| 115 | other.pathAttributes.get(other.pathAttributes.indexOf(subTlv))); |
| 116 | } else { |
| 117 | isCommonSubTlv = false; |
| 118 | } |
| 119 | } |
| 120 | return isCommonSubTlv && Objects.equals(identifier, other.identifier) |
| 121 | && Objects.equals(protocolID, other.protocolID); |
| 122 | } |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public String toString() { |
| 129 | return MoreObjects.toStringHelper(getClass()) |
| 130 | .add("identifier", identifier) |
| 131 | .add("protocolID", protocolID) |
| 132 | .add("pathAttributes", pathAttributes) |
| 133 | .toString(); |
| 134 | } |
Sho SHIMIZU | 98fc1e7 | 2015-11-23 10:25:22 -0800 | [diff] [blame] | 135 | } |