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