blob: aaddc3d3570648dd73a233e647c1418fd4696133 [file] [log] [blame]
pierventre30368ab2021-02-24 23:23:22 +01001/*
2 * Copyright 2021-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.segmentrouting.policy.impl;
17
18import org.onosproject.net.flow.TrafficSelector;
19import org.onosproject.segmentrouting.policy.api.PolicyId;
20import org.onosproject.segmentrouting.policy.api.TrafficMatch;
21import org.onosproject.segmentrouting.policy.api.TrafficMatchId;
Wailok Shum37dd29a2021-04-27 18:13:55 +080022import org.onosproject.segmentrouting.policy.api.TrafficMatchPriority;
pierventre30368ab2021-02-24 23:23:22 +010023import org.onosproject.segmentrouting.policy.api.TrafficMatchState;
24
25import java.util.Objects;
26
27import static com.google.common.base.MoreObjects.toStringHelper;
28
29/**
30 * Representation of a traffic match.
31 */
32public final class TrafficMatchRequest {
33 // Stores need to track the traffic match info and the state
34 private final TrafficMatch trafficMatch;
35 private TrafficMatchState trafficMatchState;
36
37 /**
38 * Builds a traffic match request in pending add.
39 *
40 * @param tMatch the traffic match
41 */
42 public TrafficMatchRequest(TrafficMatch tMatch) {
43 trafficMatch = tMatch;
44 trafficMatchState = TrafficMatchState.PENDING_ADD;
45 }
46
47 /**
48 * To update the traffic match state.
49 *
50 * @param trafficMatchState the new state
51 */
52 public void trafficMatchState(TrafficMatchState trafficMatchState) {
53 this.trafficMatchState = trafficMatchState;
54 }
55
56 /**
57 * Returns the traffic match state.
58 *
59 * @return the state of the traffic match
60 */
61 public TrafficMatchState trafficMatchState() {
62 return trafficMatchState;
63 }
64
65 /**
66 * Returns the traffic match id.
67 *
68 * @return the id of the traffic match
69 */
70 public TrafficMatchId trafficMatchId() {
71 return trafficMatch.trafficMatchId();
72 }
73
74 /**
75 * Returns the id of the policy associated with.
76 *
77 * @return the policy id
78 */
79 public PolicyId policyId() {
80 return trafficMatch.policyId();
81 }
82
83 /**
84 * Returns the traffic selector associated with.
85 *
86 * @return the traffic selector
87 */
88 public TrafficSelector trafficSelector() {
89 return trafficMatch.trafficSelector();
90 }
91
92 /**
93 * Returns the traffic match associated with.
94 *
95 * @return the traffic match
96 */
97 public TrafficMatch trafficMatch() {
98 return trafficMatch;
99 }
100
Wailok Shum37dd29a2021-04-27 18:13:55 +0800101 /**
102 * Returns the priority.
103 *
104 * @return the priority
105 */
106 public TrafficMatchPriority priority() {
107 return trafficMatch.trafficMatchPriority();
108 }
109
pierventre30368ab2021-02-24 23:23:22 +0100110 @Override
111 public int hashCode() {
112 return Objects.hash(trafficMatch);
113 }
114
115 @Override
116 public boolean equals(Object obj) {
117 if (this == obj) {
118 return true;
119 }
120 if (obj instanceof TrafficMatchRequest) {
121 final TrafficMatchRequest other = (TrafficMatchRequest) obj;
122 return Objects.equals(trafficMatch, other.trafficMatch);
123 }
124 return false;
125 }
126
127 @Override
128 public String toString() {
129 return toStringHelper(this)
130 .add("trafficMatch", trafficMatch)
131 .add("trafficMatchState", trafficMatchState)
132 .toString();
133 }
134}