aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java
blob: 9578ccfef4b0648fcafcf99b6b36d142b937595a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright 2015 Open Networking Laboratory
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onosproject.bgpio.protocol.linkstate;

import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
import org.onosproject.bgpio.types.BgpValueType;

import com.google.common.base.MoreObjects;

/**
 * This Class stores path Attributes, protocol ID and Identifier of LinkState NLRI.
 */
public class PathAttrNlriDetails {
    private List<BgpValueType> pathAttributes;
    private ProtocolType protocolID;
    private long identifier;

    /**
     * Sets path attribute with specified path attribute.
     *
     * @param pathAttributes in update message
     */
    public void setPathAttribute(List<BgpValueType> pathAttributes) {
        this.pathAttributes = pathAttributes;
    }

    /**
     * Returns path attributes.
     *
     * @return path attributes
     */
    public List<BgpValueType> pathAttributes() {
        return this.pathAttributes;
    }

    /**
     * Sets protocolID with specified protocolID.
     *
     * @param protocolID in linkstate nlri
     */
    public void setProtocolID(ProtocolType protocolID) {
        this.protocolID = protocolID;
    }

    /**
     * Returns protocolID.
     *
     * @return protocolID
     */
    public ProtocolType protocolID() {
        return this.protocolID;
    }

    /**
     * Sets identifier with specified identifier.
     *
     * @param identifier in linkstate nlri
     */
    public void setIdentifier(long identifier) {
        this.identifier = identifier;
    }

    /**
     * Returns Identifier.
     *
     * @return Identifier
     */
    public long identifier() {
        return this.identifier;
    }

    @Override
    public int hashCode() {
        return Objects.hash(pathAttributes, protocolID, identifier);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof PathAttrNlriDetails) {
            int countObjSubTlv = 0;
            int countOtherSubTlv = 0;
            boolean isCommonSubTlv = true;
            PathAttrNlriDetails other = (PathAttrNlriDetails) obj;
            Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator();
            countOtherSubTlv = other.pathAttributes.size();
            countObjSubTlv = pathAttributes.size();
            if (countObjSubTlv != countOtherSubTlv) {
                return false;
            } else {
                while (objListIterator.hasNext() && isCommonSubTlv) {
                    BgpValueType subTlv = objListIterator.next();
                    if (pathAttributes.contains(subTlv) && other.pathAttributes.contains(subTlv)) {
                        isCommonSubTlv = Objects.equals(pathAttributes.get(pathAttributes.indexOf(subTlv)),
                                other.pathAttributes.get(other.pathAttributes.indexOf(subTlv)));
                    } else {
                        isCommonSubTlv = false;
                    }
                }
                return isCommonSubTlv && Objects.equals(identifier, other.identifier)
                        && Objects.equals(protocolID, other.protocolID);
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
                .add("identifier", identifier)
                .add("protocolID", protocolID)
                .add("pathAttributes", pathAttributes)
                .toString();
    }
}