aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/LinkTed.java
blob: 3a6860345688a2ab17c9bd0796aa1ae71b746b3c (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*
 * 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.iptopology.api;

import static com.google.common.base.MoreObjects.toStringHelper;

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

import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.util.Bandwidth;

/**
 * Represents Link Traffic engineering parameters.
 */
public class LinkTed {
    private final Bandwidth maximumLink;
    private final Bandwidth maxReserved;
    private final List<Bandwidth> maxUnResBandwidth;
    private final Metric teMetric;
    private final Metric igpMetric;
    private final List<Ip4Address> ipv4LocRouterId;
    private final List<Ip6Address> ipv6LocRouterId;
    private final List<Ip4Address> ipv4RemRouterId;
    private final List<Ip6Address> ipv6RemRouterId;
    private final Color color;
    private final Signalling signalType;
    private final List<Srlg> srlgGroup;
    private final ProtectionType protectType;

    /**
     * Constructor to initialize its parameter.
     *
     * @param maximumLink maximum bandwidth can be used
     * @param maxReserved max bandwidth that can be reserved
     * @param maxUnResBandwidth amount of bandwidth reservable
     * @param teMetric Traffic engineering metric
     * @param igpMetric IGP metric
     * @param color information on administrative group assigned to the interface
     * @param signalType MPLS signaling protocols
     * @param srlgGroup Shared Risk Link Group information
     * @param protectType protection capabilities of the link
     * @param ipv4LocRouterId IPv4 router-Id of local node
     * @param ipv6LocRouterId IPv6 router-Id of local node
     * @param ipv4RemRouterId IPv4 router-Id of remote node
     * @param ipv6RemRouterId IPv6 router-Id of remote node
     */
    public LinkTed(Bandwidth maximumLink, Bandwidth maxReserved, List<Bandwidth> maxUnResBandwidth,
                   Metric teMetric, Metric igpMetric, Color color, Signalling signalType, List<Srlg> srlgGroup,
                   ProtectionType protectType, List<Ip4Address> ipv4LocRouterId, List<Ip6Address> ipv6LocRouterId,
                   List<Ip4Address> ipv4RemRouterId, List<Ip6Address> ipv6RemRouterId) {
        this.maximumLink = maximumLink;
        this.maxReserved = maxReserved;
        this.maxUnResBandwidth = maxUnResBandwidth;
        this.teMetric = teMetric;
        this.igpMetric = igpMetric;
        this.color = color;
        this.signalType = signalType;
        this.srlgGroup = srlgGroup;
        this.protectType = protectType;
        this.ipv4LocRouterId = ipv4LocRouterId;
        this.ipv6LocRouterId = ipv6LocRouterId;
        this.ipv4RemRouterId = ipv4RemRouterId;
        this.ipv6RemRouterId = ipv6RemRouterId;
    }

    /**
     * Provides maximum bandwidth can be used on the link.
     *
     * @return maximum bandwidth
     */
    public Bandwidth maximumLink() {
        return maximumLink;
    }

    /**
     * Amount of bandwidth reservable on the link.
     *
     * @return unreserved bandwidth
     */
    public List<Bandwidth> maxUnResBandwidth() {
        return maxUnResBandwidth;
    }

    /**
     * Provides max bandwidth that can be reserved on the link.
     *
     * @return max bandwidth reserved
     */
    public Bandwidth maxReserved() {
        return maxReserved;
    }

    /**
     * Provides Traffic engineering metric for the link.
     *
     * @return Traffic engineering metric
     */
    public Metric teMetric() {
        return teMetric;
    }

    /**
     * Provides IGP metric for the link.
     *
     * @return IGP metric
     */
    public Metric igpMetric() {
        return igpMetric;
    }

    /**
     * Provides protection capabilities of the link.
     *
     * @return link protection type
     */
    public ProtectionType protectType() {
        return protectType;
    }

    /**
     * Provides Shared Risk Link Group information.
     *
     * @return Shared Risk Link Group value
     */
    public List<Srlg> srlgGroup() {
        return srlgGroup;
    }

    /**
     * Provides which MPLS signaling protocols are enabled.
     *
     * @return signal type
     */
    public Signalling signalType() {
        return signalType;
    }

    /**
     * Provides information on administrative group assigned to the interface.
     *
     * @return 4-octect bit mask assigned by network administrator
     */
    public Color color() {
        return color;
    }

    /**
     * Provides IPv4 router-Id of local node.
     *
     * @return IPv4 router-Id of local node
     */
    public List<Ip4Address> ipv4LocRouterId() {
        return ipv4LocRouterId;
    }

    /**
     * Provides IPv6 router-Id of local node.
     *
     * @return IPv6 router-Id of local node
     */
    public List<Ip6Address> ipv6LocRouterId() {
        return ipv6LocRouterId;
    }

    /**
     * Provides IPv4 router-Id of remote node.
     *
     * @return IPv4 router-Id of remote node
     */
    public List<Ip4Address> ipv4RemRouterId() {
        return ipv4RemRouterId;
    }

    /**
     * Provides IPv6 router-Id of remote node.
     *
     * @return IPv6 router-Id of remote node
     */
    public List<Ip6Address> ipv6RemRouterId() {
        return ipv6RemRouterId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(maximumLink, maxReserved, maxUnResBandwidth, teMetric, igpMetric,
                ipv4LocRouterId, ipv6LocRouterId, ipv4RemRouterId, ipv6RemRouterId,
                color, signalType, srlgGroup, protectType);
    }

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

        if (obj instanceof LinkTed) {
            int countCommonBandwidth = 0;
            int countOtherCommonBandwidth = 0;
            int countOther4LocRouterId = 0;
            int countCommon4LocRouterId = 0;
            int countOther6RemRouterId = 0;
            int countCommon6RemRouterId = 0;
            int countOther4RemRouterId = 0;
            int countCommon4RemRouterId = 0;
            int countCommon6LocRouterId = 0;
            int countOther6LocRouterId = 0;
            int countCommonSrlg = 0;
            int countOtherSrlg = 0;
            boolean isCommonBandwidth = true;
            boolean isCommonIp4Loc = true;
            boolean isCommonIp4Rem = true;
            boolean isCommonIp6Loc = true;
            boolean isCommonIp6Rem = true;
            boolean isCommonSrlg = true;
            LinkTed other = (LinkTed) obj;
            Iterator<Bandwidth> objListIterator = other.maxUnResBandwidth.iterator();
            countOtherCommonBandwidth = other.maxUnResBandwidth.size();
            countCommonBandwidth = maxUnResBandwidth.size();

            Iterator<Ip4Address> ipv4local = other.ipv4LocRouterId.iterator();
            countOther4LocRouterId = other.ipv4LocRouterId.size();
            countCommon4LocRouterId = ipv4LocRouterId.size();

            Iterator<Ip4Address> ipv4remote = other.ipv4RemRouterId.iterator();
            countOther4RemRouterId = other.ipv4RemRouterId.size();
            countCommon4RemRouterId = ipv4RemRouterId.size();

            Iterator<Ip6Address> ipv6local = other.ipv6LocRouterId.iterator();
            countOther6LocRouterId = other.ipv6LocRouterId.size();
            countCommon6LocRouterId = ipv6LocRouterId.size();

            Iterator<Ip6Address> ipv6remote = other.ipv6RemRouterId.iterator();
            countOther6RemRouterId = other.ipv6RemRouterId.size();
            countCommon6RemRouterId = ipv6RemRouterId.size();

            Iterator<Srlg> srlg = other.srlgGroup.iterator();
            countOtherSrlg = other.srlgGroup.size();
            countCommonSrlg = srlgGroup.size();

            if (countOtherCommonBandwidth != countCommonBandwidth
                    || countOther4LocRouterId != countCommon4LocRouterId
                    || countOther4RemRouterId != countCommon4RemRouterId
                    || countOther6LocRouterId != countCommon6LocRouterId
                    || countOther6RemRouterId != countCommon6RemRouterId
                    || countOtherSrlg != countCommonSrlg) {
                return false;
            } else {
                while (objListIterator.hasNext() && isCommonBandwidth) {
                    Bandwidth subTlv = objListIterator.next();
                    if (maxUnResBandwidth.contains(subTlv) && other.maxUnResBandwidth.contains(subTlv)) {
                        isCommonBandwidth = Objects.equals(maxUnResBandwidth.get(maxUnResBandwidth.indexOf(subTlv)),
                                other.maxUnResBandwidth.get(other.maxUnResBandwidth.indexOf(subTlv)));
                    } else {
                        isCommonBandwidth = false;
                    }
                }
                while (ipv4local.hasNext() && isCommonIp4Loc) {
                    Ip4Address subTlv = ipv4local.next();
                    if (ipv4LocRouterId.contains(subTlv) && other.ipv4LocRouterId.contains(subTlv)) {
                        isCommonIp4Loc = Objects.equals(ipv4LocRouterId.get(ipv4LocRouterId.indexOf(subTlv)),
                                other.ipv4LocRouterId.get(other.ipv4LocRouterId.indexOf(subTlv)));
                    } else {
                        isCommonIp4Loc = false;
                    }
                }
                while (ipv4remote.hasNext() && isCommonIp4Rem) {
                    Ip4Address subTlv = ipv4remote.next();
                    if (ipv4RemRouterId.contains(subTlv) && other.ipv4RemRouterId.contains(subTlv)) {
                        isCommonIp4Rem = Objects.equals(ipv4RemRouterId.get(ipv4RemRouterId.indexOf(subTlv)),
                                other.ipv4RemRouterId.get(other.ipv4RemRouterId.indexOf(subTlv)));
                    } else {
                        isCommonIp4Rem = false;
                    }
                }
                while (ipv6remote.hasNext() && isCommonIp6Rem) {
                    Ip6Address subTlv = ipv6remote.next();
                    if (ipv6RemRouterId.contains(subTlv) && other.ipv6RemRouterId.contains(subTlv)) {
                        isCommonIp6Rem = Objects.equals(ipv6RemRouterId.get(ipv6RemRouterId.indexOf(subTlv)),
                                other.ipv6RemRouterId.get(other.ipv6RemRouterId.indexOf(subTlv)));
                    } else {
                        isCommonIp6Rem = false;
                    }
                }
                while (ipv6local.hasNext() && isCommonIp6Loc) {
                    Ip6Address subTlv = ipv6local.next();
                    if (ipv6LocRouterId.contains(subTlv) && other.ipv6LocRouterId.contains(subTlv)) {
                        isCommonIp6Loc = Objects.equals(ipv6LocRouterId.get(ipv6LocRouterId.indexOf(subTlv)),
                                other.ipv6LocRouterId.get(other.ipv6LocRouterId.indexOf(subTlv)));
                    } else {
                        isCommonIp6Loc = false;
                    }
                }
                while (srlg.hasNext() && isCommonIp6Loc) {
                    Srlg subTlv = srlg.next();
                    if (srlgGroup.contains(subTlv) && other.srlgGroup.contains(subTlv)) {
                        isCommonSrlg = Objects.equals(srlgGroup.get(srlgGroup.indexOf(subTlv)),
                                other.srlgGroup.get(other.srlgGroup.indexOf(subTlv)));
                    } else {
                        isCommonSrlg = false;
                    }
                }
                return isCommonBandwidth && isCommonIp4Loc && isCommonIp4Rem && isCommonIp6Rem && isCommonIp6Loc
                        && isCommonSrlg
                        && Objects.equals(igpMetric, other.igpMetric)
                        && Objects.equals(teMetric, other.teMetric)
                        && Objects.equals(maximumLink, other.maximumLink)
                        && Objects.equals(protectType, other.protectType)
                        && Objects.equals(color, other.color)
                        && Objects.equals(signalType, other.signalType);
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return toStringHelper(this)
                .add("igpMetric", igpMetric)
                .add("teMetric", teMetric)
                .add("maximumLink", maximumLink)
                .add("maxReserved", maxReserved)
                .add("maxUnResBandwidth", maxUnResBandwidth)
                .add("ipv4LocRouterId", ipv4LocRouterId)
                .add("ipv4RemRouterId", ipv4RemRouterId)
                .add("ipv6LocRouterId", ipv6LocRouterId)
                .add("ipv6RemRouterId", ipv6RemRouterId)
                .add("protectType", protectType)
                .add("color", color)
                .add("srlgGroup", srlgGroup)
                .add("signalType", signalType)
                .toString();
    }
}