blob: 3ac2f4d6068d618871dc07d92b692314bef3f791 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07003 *
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.net.flow.criteria;
17
18import org.onosproject.net.PortNumber;
19
20import java.util.Objects;
21
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070022/**
23 * Implementation of input port criterion.
24 */
25public final class PortCriterion implements Criterion {
26 private final PortNumber port;
27 private final Type type;
28
29 /**
30 * Constructor.
31 *
32 * @param port the input port number to match
33 * @param type the match type. Should be either Type.IN_PORT or
34 * Type.IN_PHY_PORT
35 */
36 PortCriterion(PortNumber port, Type type) {
37 this.port = port;
38 this.type = type;
39 }
40
41 @Override
42 public Type type() {
43 return this.type;
44 }
45
46 /**
47 * Gets the input port number to match.
48 *
49 * @return the input port number to match
50 */
51 public PortNumber port() {
52 return this.port;
53 }
54
55 @Override
56 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080057 return type().toString() + SEPARATOR + port;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070058 }
59
60 @Override
61 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070062 return Objects.hash(type().ordinal(), port);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070063 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof PortCriterion) {
71 PortCriterion that = (PortCriterion) obj;
72 return Objects.equals(port, that.port) &&
73 Objects.equals(this.type(), that.type());
74 }
75 return false;
76 }
77}