aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/iptopology-api/src/main/java/org/onosproject/iptopology/api/IpLinkIdentifier.java
blob: 8522f945548606f6e1467b262455735fbd8f307a (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
/*
 * 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.Objects;

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

/**
 * Represents Ip Link Identifier.
 */
public class IpLinkIdentifier {
    private final InterfaceIdentifier localIndentifier;
    private final InterfaceIdentifier remoteIndentifier;
    private final Ip4Address localIpv4Addr;
    private final Ip4Address remoteIpv4Addr;
    private final Ip6Address localIpv6Addr;
    private final Ip6Address remoteIpv6Addr;
    private final TopologyId topologyId;

    /**
     * Constructor to initialize its parameters.
     *
     * @param localIndentifier  local interface identifier of the link
     * @param remoteIndentifier remote interface identifier of the link
     * @param localIpv4Addr     local IPv4 address of the link
     * @param remoteIpv4Addr    remote IPv4 address of the link
     * @param localIpv6Addr     local IPv6 address of the link
     * @param remoteIpv6Addr    remote IPv6 address of the link
     * @param topologyId        link topology identifier
     */
    public IpLinkIdentifier(InterfaceIdentifier localIndentifier, InterfaceIdentifier remoteIndentifier,
                            Ip4Address localIpv4Addr, Ip4Address remoteIpv4Addr, Ip6Address localIpv6Addr,
                            Ip6Address remoteIpv6Addr, TopologyId topologyId) {
        this.localIndentifier = localIndentifier;
        this.remoteIndentifier = remoteIndentifier;
        this.localIpv4Addr = localIpv4Addr;
        this.remoteIpv4Addr = remoteIpv4Addr;
        this.localIpv6Addr = localIpv6Addr;
        this.remoteIpv6Addr = remoteIpv6Addr;
        this.topologyId = topologyId;
    }

    /**
     * Obtains link local identifier.
     *
     * @return link local identifier
     */
    public InterfaceIdentifier localIndentifier() {
        return localIndentifier;
    }

    /**
     * Obtains link local identifier.
     *
     * @return link local identifier
     */
    public InterfaceIdentifier remoteIndentifier() {
        return remoteIndentifier;
    }

    /**
     * Obtains local IPv4 address of the link.
     *
     * @return local IPv4  address of the link
     */
    public Ip4Address localIpv4Addr() {
        return localIpv4Addr;
    }

    /**
     * Obtains remote IPv4 address of the link.
     *
     * @return remote IPv4  address of the link
     */
    public Ip4Address remoteIpv4Addr() {
        return remoteIpv4Addr;
    }

    /**
     * Obtains local IPv6 address of the link.
     *
     * @return local IPv6 address of the link
     */
    public Ip6Address localIpv6Addr() {
        return localIpv6Addr;
    }

    /**
     * Obtains remote IPv6 address of the link.
     *
     * @return remote IPv6 address of the link
     */
    public Ip6Address remoteIpv6Addr() {
        return remoteIpv6Addr;
    }

    /**
     * Obtains Topology ID of the link.
     *
     * @return Topology ID of the link
     */
    public TopologyId topologyId() {
        return topologyId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(localIndentifier, remoteIndentifier, localIpv4Addr, remoteIpv4Addr,
                localIpv6Addr, remoteIpv6Addr, topologyId);
    }

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

        if (obj instanceof IpLinkIdentifier) {
            IpLinkIdentifier other = (IpLinkIdentifier) obj;
            return Objects.equals(topologyId, other.topologyId)
                    && Objects.equals(localIndentifier, other.localIndentifier)
                    && Objects.equals(remoteIndentifier, other.remoteIndentifier)
                    && Objects.equals(localIpv4Addr, other.localIpv4Addr)
                    && Objects.equals(remoteIpv4Addr, other.remoteIpv4Addr)
                    && Objects.equals(localIpv6Addr, other.localIpv6Addr)
                    && Objects.equals(remoteIpv6Addr, other.remoteIpv6Addr);
        }
        return false;
    }

    @Override
    public String toString() {
        return toStringHelper(this)
                .omitNullValues()
                .add("localIndentifier", localIndentifier)
                .add("remoteIndentifier", remoteIndentifier)
                .add("localIpv4Addr", localIpv4Addr)
                .add("remoteIpv4Addr", remoteIpv4Addr)
                .add("localIpv6Addr", localIpv6Addr)
                .add("remoteIpv6Addr", remoteIpv6Addr)
                .add("topologyId", topologyId)
                .toString();
    }
}