blob: ac3e07892aab930b2c424b0234004009c5ba8acc [file] [log] [blame]
Jonathan Hart26a8d952015-12-02 15:16:35 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Jonathan Hart26a8d952015-12-02 15:16:35 -08003 *
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
Jonathan Hart26a8d952015-12-02 15:16:35 -080023/**
24 * Criterion for implementing selector extensions.
25 */
26public class ExtensionCriterion implements Criterion {
27
28 private final ExtensionSelector extensionSelector;
29 private final DeviceId deviceId;
30
31 /**
32 * Constructor.
33 *
34 * @param extensionSelector extension selector
Jian Lidfba7392016-01-22 16:46:58 -080035 * @param deviceId device identification
Jonathan Hart26a8d952015-12-02 15:16:35 -080036 */
37 public ExtensionCriterion(ExtensionSelector extensionSelector, DeviceId deviceId) {
38 this.extensionSelector = extensionSelector;
39 this.deviceId = deviceId;
40 }
41
42 /**
43 * Returns the extension selector.
44 *
45 * @return extension selector
46 */
47 public ExtensionSelector extensionSelector() {
48 return extensionSelector;
49 }
50
51 /**
52 * Returns the device ID.
53 *
54 * @return device ID
55 */
56 public DeviceId deviceId() {
57 return deviceId;
58 }
59
60 @Override
61 public Type type() {
62 return Type.EXTENSION;
63 }
64
65 @Override
66 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080067 return type().toString() + SEPARATOR + deviceId + "/" + extensionSelector;
Jonathan Hart26a8d952015-12-02 15:16:35 -080068 }
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 ExtensionCriterion) {
81 ExtensionCriterion that = (ExtensionCriterion) obj;
82 return Objects.equals(extensionSelector, that.extensionSelector) &&
83 Objects.equals(deviceId, that.deviceId) &&
84 Objects.equals(this.type(), that.type());
85 }
86 return false;
87 }
88}