Priyanka B
Committed by Gerrit Code Review

[ONOS-2602]Implement Adajacency RIB table

Change-Id: I930cf87894776fe1c4c3823dc079cfe7a0f77150
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 +
22 +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE;
23 +import org.onosproject.bgpio.types.BGPValueType;
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 {
31 + private List<BGPValueType> pathAttributes;
32 + private PROTOCOLTYPE protocolID;
33 + private long identifier;
34 +
35 + /**
36 + * Sets path attribute with specified path attribute.
37 + *
38 + * @param pathAttributes in update message
39 + */
40 + public void setPathAttribute(List<BGPValueType> pathAttributes) {
41 + this.pathAttributes = pathAttributes;
42 + }
43 +
44 + /**
45 + * Returns path attributes.
46 + *
47 + * @return path attributes
48 + */
49 + public List<BGPValueType> pathAttributes() {
50 + return this.pathAttributes;
51 + }
52 +
53 + /**
54 + * Sets protocolID with specified protocolID.
55 + *
56 + * @param protocolID in linkstate nlri
57 + */
58 + public void setProtocolID(PROTOCOLTYPE protocolID) {
59 + this.protocolID = protocolID;
60 + }
61 +
62 + /**
63 + * Returns protocolID.
64 + *
65 + * @return protocolID
66 + */
67 + public PROTOCOLTYPE protocolID() {
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;
105 + Iterator<BGPValueType> objListIterator = other.pathAttributes.iterator();
106 + countOtherSubTlv = other.pathAttributes.size();
107 + countObjSubTlv = pathAttributes.size();
108 + if (countObjSubTlv != countOtherSubTlv) {
109 + return false;
110 + } else {
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)));
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 + }
135 +}
...\ No newline at end of file ...\ No newline at end of file