blob: 853fd9767e72816d6226dea858249c88bf6e4ce1 [file] [log] [blame]
Jian Li0e09eaa2017-02-14 02:01:18 +09001/*
2 * Copyright 2017-present 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 */
16package org.onosproject.mapping.addresses;
17
18import org.onosproject.net.DeviceId;
19import org.onosproject.net.flow.criteria.ExtensionSelector;
20
21import java.util.Objects;
22
23/**
24 * Mapping address for implementing extensions.
25 */
26public final class ExtensionMappingAddress implements MappingAddress {
27
28 private final ExtensionSelector extensionSelector;
29 private final DeviceId deviceId;
30
31 /**
32 * Default constructor of ExtensionMappingAddress.
33 *
34 * @param extensionSelector extension selector
35 * @param deviceId device identifier
36 */
37 public ExtensionMappingAddress(ExtensionSelector extensionSelector, DeviceId deviceId) {
38 this.extensionSelector = extensionSelector;
39 this.deviceId = deviceId;
40 }
41
42 @Override
43 public Type type() {
44 return Type.EXTENSION;
45 }
46
47 /**
48 * Returns the extension selector.
49 *
50 * @return extension selector
51 */
52 public ExtensionSelector extensionSelector() {
53 return extensionSelector;
54 }
55
56 /**
57 * Returns the device identifier.
58 *
59 * @return the device identifier
60 */
61 public DeviceId deviceId() {
62 return deviceId;
63 }
64
65 @Override
66 public String toString() {
67 return type().toString() + TYPE_SEPARATOR + deviceId + "/" + extensionSelector;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hash(type().ordinal(), extensionSelector, deviceId);
73 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80 if (obj instanceof ExtensionMappingAddress) {
81 ExtensionMappingAddress that = (ExtensionMappingAddress) obj;
82 return Objects.equals(extensionSelector, that.extensionSelector) &&
83 Objects.equals(deviceId, that.deviceId);
84 }
85 return false;
86 }
87}