blob: 0f6cd130205e1c904c0ca2c140e5c0001eac8cae [file] [log] [blame]
Jonathan Hart26a8d952015-12-02 15:16:35 -08001/*
2 * Copyright 2015 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 */
16
17package org.onosproject.net.flow.criteria;
18
19import org.onosproject.net.DeviceId;
20
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * Criterion for implementing selector extensions.
27 */
28public class ExtensionCriterion implements Criterion {
29
30 private final ExtensionSelector extensionSelector;
31 private final DeviceId deviceId;
32
33 /**
34 * Constructor.
35 *
36 * @param extensionSelector extension selector
Jian Lidfba7392016-01-22 16:46:58 -080037 * @param deviceId device identification
Jonathan Hart26a8d952015-12-02 15:16:35 -080038 */
39 public ExtensionCriterion(ExtensionSelector extensionSelector, DeviceId deviceId) {
40 this.extensionSelector = extensionSelector;
41 this.deviceId = deviceId;
42 }
43
44 /**
45 * Returns the extension selector.
46 *
47 * @return extension selector
48 */
49 public ExtensionSelector extensionSelector() {
50 return extensionSelector;
51 }
52
53 /**
54 * Returns the device ID.
55 *
56 * @return device ID
57 */
58 public DeviceId deviceId() {
59 return deviceId;
60 }
61
62 @Override
63 public Type type() {
64 return Type.EXTENSION;
65 }
66
67 @Override
68 public String toString() {
69 return toStringHelper(type().toString())
70 .add("extensionSelector", extensionSelector.toString())
71 .add("deviceId", deviceId)
72 .toString();
73 }
74
75 @Override
76 public int hashCode() {
77 return Objects.hash(type().ordinal(), extensionSelector, deviceId);
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85 if (obj instanceof ExtensionCriterion) {
86 ExtensionCriterion that = (ExtensionCriterion) obj;
87 return Objects.equals(extensionSelector, that.extensionSelector) &&
88 Objects.equals(deviceId, that.deviceId) &&
89 Objects.equals(this.type(), that.type());
90 }
91 return false;
92 }
93}