2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.bgpio.protocol.linkstate;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Objects;
22 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
23 import org.onosproject.bgpio.types.BgpValueType;
25 import com.google.common.base.MoreObjects;
28 * This Class stores path Attributes, protocol ID and Identifier of LinkState NLRI.
30 public class PathAttrNlriDetails {
31 private List<BgpValueType> pathAttributes;
32 private ProtocolType protocolID;
33 private long identifier;
36 * Sets path attribute with specified path attribute.
38 * @param pathAttributes in update message
40 public void setPathAttribute(List<BgpValueType> pathAttributes) {
41 this.pathAttributes = pathAttributes;
45 * Returns path attributes.
47 * @return path attributes
49 public List<BgpValueType> pathAttributes() {
50 return this.pathAttributes;
54 * Sets protocolID with specified protocolID.
56 * @param protocolID in linkstate nlri
58 public void setProtocolID(ProtocolType protocolID) {
59 this.protocolID = protocolID;
67 public ProtocolType protocolID() {
68 return this.protocolID;
72 * Sets identifier with specified identifier.
74 * @param identifier in linkstate nlri
76 public void setIdentifier(long identifier) {
77 this.identifier = identifier;
85 public long identifier() {
86 return this.identifier;
90 public int hashCode() {
91 return Objects.hash(pathAttributes, protocolID, identifier);
95 public boolean equals(Object obj) {
100 if (obj instanceof PathAttrNlriDetails) {
101 int countObjSubTlv = 0;
102 int countOtherSubTlv = 0;
103 boolean isCommonSubTlv = true;
104 PathAttrNlriDetails other = (PathAttrNlriDetails) obj;
105 Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator();
106 countOtherSubTlv = other.pathAttributes.size();
107 countObjSubTlv = pathAttributes.size();
108 if (countObjSubTlv != countOtherSubTlv) {
111 while (objListIterator.hasNext() && isCommonSubTlv) {
112 BgpValueType subTlv = objListIterator.next();
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)));
117 isCommonSubTlv = false;
120 return isCommonSubTlv && Objects.equals(identifier, other.identifier)
121 && Objects.equals(protocolID, other.protocolID);
128 public String toString() {
129 return MoreObjects.toStringHelper(getClass())
130 .add("identifier", identifier)
131 .add("protocolID", protocolID)
132 .add("pathAttributes", pathAttributes)