blob: 9578ccfef4b0648fcafcf99b6b36d142b937595a [file] [log] [blame]
Priyanka Bda605422015-11-18 09:36:58 +05301/*
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 */
16package org.onosproject.bgpio.protocol.linkstate;
17
18import java.util.Iterator;
19import java.util.List;
20import java.util.Objects;
21
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053022import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
23import org.onosproject.bgpio.types.BgpValueType;
Priyanka Bda605422015-11-18 09:36:58 +053024
25import com.google.common.base.MoreObjects;
26
27/**
28 * This Class stores path Attributes, protocol ID and Identifier of LinkState NLRI.
29 */
30public class PathAttrNlriDetails {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053031 private List<BgpValueType> pathAttributes;
Sho SHIMIZU98fc1e72015-11-23 10:25:22 -080032 private ProtocolType protocolID;
Priyanka Bda605422015-11-18 09:36:58 +053033 private long identifier;
34
35 /**
36 * Sets path attribute with specified path attribute.
37 *
38 * @param pathAttributes in update message
39 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053040 public void setPathAttribute(List<BgpValueType> pathAttributes) {
Priyanka Bda605422015-11-18 09:36:58 +053041 this.pathAttributes = pathAttributes;
42 }
43
44 /**
45 * Returns path attributes.
46 *
47 * @return path attributes
48 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053049 public List<BgpValueType> pathAttributes() {
Priyanka Bda605422015-11-18 09:36:58 +053050 return this.pathAttributes;
51 }
52
53 /**
54 * Sets protocolID with specified protocolID.
55 *
56 * @param protocolID in linkstate nlri
57 */
Sho SHIMIZU98fc1e72015-11-23 10:25:22 -080058 public void setProtocolID(ProtocolType protocolID) {
Priyanka Bda605422015-11-18 09:36:58 +053059 this.protocolID = protocolID;
60 }
61
62 /**
63 * Returns protocolID.
64 *
65 * @return protocolID
66 */
Sho SHIMIZU98fc1e72015-11-23 10:25:22 -080067 public ProtocolType protocolID() {
Priyanka Bda605422015-11-18 09:36:58 +053068 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 VH5dd8dbe2015-11-26 13:22:18 +0530105 Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator();
Priyanka Bda605422015-11-18 09:36:58 +0530106 countOtherSubTlv = other.pathAttributes.size();
107 countObjSubTlv = pathAttributes.size();
108 if (countObjSubTlv != countOtherSubTlv) {
109 return false;
110 } else {
111 while (objListIterator.hasNext() && isCommonSubTlv) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530112 BgpValueType subTlv = objListIterator.next();
Priyanka Bda605422015-11-18 09:36:58 +0530113 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 SHIMIZU98fc1e72015-11-23 10:25:22 -0800135}