blob: 6b746a0b15e19940352cf2d4249143c0df93ed07 [file] [log] [blame]
Anton Chigrin4af4f872019-01-14 17:29:56 +02001/*
2 * Copyright 2019-present Open Networking Foundation
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.openflow.controller;
17
18import org.onosproject.net.DeviceId;
19import java.util.Objects;
20
21/**
22 * Represents to OpenFlow messages classifier.
23 */
24public final class OpenFlowClassifier {
25
26 private final short ethernetType;
27 private final int idQueue;
28 private final DeviceId deviceId;
29
30 /**
31 * Builder of the OpenFlow classifier.
32 */
33 public static class Builder {
34 private Short ethernetType = 0;
35 private int idQueue;
36 private DeviceId deviceId;
37
38 /**
39 * Builder constructor for OpenFlow classifier.
40 *
41 * @param deviceId the device id
42 * @param idQueue the queue id
43 */
44 public Builder(DeviceId deviceId, int idQueue) {
45 this.deviceId = deviceId;
46 this.idQueue = idQueue;
47 }
48
49 /**
50 * Sets the ethernet type for the OpenFlow classifier that will be built.
51 *
52 * @param ethernetType the ethernet type
53 * @return this builder
54 */
55 public Builder ethernetType(short ethernetType) {
56 this.ethernetType = ethernetType;
57 return this;
58 }
59
60 /**
61 * Builds the OpenFlow classifier from the accumulated parameters.
62 *
63 * @return OpenFlow classifier instance
64 */
65 public OpenFlowClassifier build() {
66 return new OpenFlowClassifier(this);
67 }
68 }
69
70 private OpenFlowClassifier(Builder builder) {
71 this.idQueue = builder.idQueue;
72 this.ethernetType = builder.ethernetType;
73 this.deviceId = builder.deviceId;
74 }
75
76 /**
77 * Gets the ethernet type matched by the classifier.
78 *
79 * @return matched packet ethernet type
80 */
81 public short ethernetType() {
82 return this.ethernetType;
83 }
84
85 /**
86 * Gets the id of source OpenFlow device matched by the classifier.
87 *
88 * @return connected device id
89 */
90 public DeviceId deviceId() {
91 return this.deviceId;
92 }
93
94 /**
95 * Gets the queue id targeted by the classifier.
96 *
97 * @return target queue id
98 */
99 public int idQueue() {
100 return this.idQueue;
101 }
102
103 /**
104 * Compares OpenFlow classifiers.
105 *
106 * @param o object that we want to compare to
107 * @return equality check result
108 */
109 @Override
110 public boolean equals(Object o) {
111 if (!(o instanceof OpenFlowClassifier)) {
112 return false;
113 }
114 OpenFlowClassifier classifier = (OpenFlowClassifier) o;
115 return this.ethernetType == classifier.ethernetType()
116 && this.idQueue == classifier.idQueue()
117 && this.deviceId.equals(classifier.deviceId());
118 }
119
120 /**
121 * Calculates hashCode of the OpenFlow Classifier object.
122 *
123 * @return hash of the OpenFlow Classifier
124 */
125 @Override
126 public int hashCode() {
127 return Objects.hash(deviceId, idQueue, ethernetType);
128 }
129}