blob: 70142511639074068ad2c5fa398f7d813190cce8 [file] [log] [blame]
Jian Li0e09eaa2017-02-14 02:01:18 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li0e09eaa2017-02-14 02:01:18 +09003 *
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.mapping.addresses;
17
18import org.onlab.packet.IpPrefix;
19
20import java.util.Objects;
21
22/**
23 * Implementation of IP mapping address.
24 */
25public final class IPMappingAddress implements MappingAddress {
26
27 private final IpPrefix ip;
28 private final Type type;
29
30 /**
31 * Default constructor of IPMappingAddress.
32 *
33 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
34 * @param type the match type, the type can be one of the following:
35 * Type.IPV4, Type.IPV6
36 */
37 IPMappingAddress(IpPrefix ip, Type type) {
38 this.ip = ip;
39 this.type = type;
40 }
41
42 @Override
43 public Type type() {
44 return type;
45 }
46
47 /**
48 * Obtains the IP prefix to look up.
49 *
50 * @return the IP prefix to look up
51 */
52 public IpPrefix ip() {
53 return this.ip;
54 }
55
56 @Override
57 public String toString() {
58 return type().toString() + TYPE_SEPARATOR + ip;
59 }
60
61 @Override
62 public int hashCode() {
63 return Objects.hash(type().ordinal(), ip);
64 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (this == obj) {
69 return true;
70 }
71 if (obj instanceof IPMappingAddress) {
72 IPMappingAddress that = (IPMappingAddress) obj;
73 return Objects.equals(ip, that.ip) &&
74 Objects.equals(type, that.type);
75 }
76 return false;
77 }
78}