blob: 451c1a98ac849f1379eb1836952fb3f1149f958b [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.segmentrouting.policy.api.Policy;
19import org.onosproject.segmentrouting.policy.api.PolicyId;
20import org.onosproject.segmentrouting.policy.api.PolicyState;
21
22import java.util.Objects;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Policy request tracked by the system.
28 */
29final class PolicyRequest {
30 // Stores need to track policy info and the state
31 private final Policy policy;
32 private PolicyState policyState;
33
34 /**
35 * Creates a policy request in pending add.
36 *
37 * @param pol the policy
38 */
39 public PolicyRequest(Policy pol) {
40 policy = pol;
41 policyState = PolicyState.PENDING_ADD;
42 }
43
44 /**
45 * Returns the current state of the request.
46 *
47 * @return the policy state
48 */
49 public PolicyState policyState() {
50 return policyState;
51 }
52
53 /**
54 * Returns the policy id.
55 *
56 * @return the policy id
57 */
58 public PolicyId policyId() {
59 return policy.policyId();
60 }
61
62 /**
63 * Returns the policy type.
64 *
65 * @return the type of a policy
66 */
67 public Policy.PolicyType policyType() {
68 return policy.policyType();
69 }
70
71 /**
72 * To update the policy state.
73 *
74 * @param policystate the new state.
75 */
76 public void policyState(PolicyState policystate) {
77 policyState = policystate;
78 }
79
80 /**
81 * Returns the policy associated to this request.
82 *
83 * @return the policy
84 */
85 public Policy policy() {
86 return policy;
87 }
88
89 @Override
90 public boolean equals(final Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (!(obj instanceof PolicyRequest)) {
95 return false;
96 }
97 final PolicyRequest other = (PolicyRequest) obj;
98 return Objects.equals(this.policy, other.policy);
99 }
100
101 @Override
102 public int hashCode() {
103 return Objects.hash(policy);
104 }
105
106 @Override
107 public String toString() {
108 return toStringHelper(this)
109 .add("policyState", policyState)
110 .add("policy", policy)
111 .toString();
112 }
113
114}