Daniele Moro | 7c31a3b | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.pipelines.fabric.impl.behaviour.upf; |
| 18 | |
| 19 | import org.onlab.util.ImmutableByteSequence; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | /** |
| 24 | * Wrapper for identifying information of FARs and PDRs. |
| 25 | */ |
| 26 | public final class UpfRuleIdentifier { |
| 27 | private final int sessionlocalId; |
| 28 | private final ImmutableByteSequence pfcpSessionId; |
| 29 | |
| 30 | /** |
| 31 | * A PDR or FAR can be globally uniquely identified by the combination of the ID of the PFCP session that |
| 32 | * produced it, and the ID that the rule was assigned in that PFCP session. |
| 33 | * |
| 34 | * @param pfcpSessionId The PFCP session that produced the rule ID |
| 35 | * @param sessionlocalId The rule ID |
| 36 | */ |
| 37 | public UpfRuleIdentifier(ImmutableByteSequence pfcpSessionId, int sessionlocalId) { |
| 38 | this.pfcpSessionId = pfcpSessionId; |
| 39 | this.sessionlocalId = sessionlocalId; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Create an instance of this class from the given PFCP session ID and the session-local Rule ID. |
| 44 | * |
| 45 | * @param pfcpSessionId PFCP session ID of the rule to identify |
| 46 | * @param sessionlocalId session-local Rule ID of the rule to identify |
| 47 | * @return a new rule identifier |
| 48 | */ |
| 49 | public static UpfRuleIdentifier of(ImmutableByteSequence pfcpSessionId, int sessionlocalId) { |
| 50 | return new UpfRuleIdentifier(pfcpSessionId, sessionlocalId); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get the PFCP session-local rule ID. |
| 55 | * |
| 56 | * @return session-local rule ID |
| 57 | */ |
| 58 | public int getSessionLocalId() { |
| 59 | return sessionlocalId; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the PFCP session ID. |
| 64 | * |
| 65 | * @return PFCP session ID |
| 66 | */ |
| 67 | public ImmutableByteSequence getPfcpSessionId() { |
| 68 | return pfcpSessionId; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String toString() { |
| 73 | return "RuleIdentifier{" + |
| 74 | "sessionlocalId=" + sessionlocalId + |
| 75 | ", pfcpSessionId=" + pfcpSessionId + |
| 76 | '}'; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean equals(Object obj) { |
| 81 | if (obj == this) { |
| 82 | return true; |
| 83 | } |
| 84 | if (obj == null) { |
| 85 | return false; |
| 86 | } |
| 87 | if (getClass() != obj.getClass()) { |
| 88 | return false; |
| 89 | } |
| 90 | UpfRuleIdentifier that = (UpfRuleIdentifier) obj; |
| 91 | return (this.sessionlocalId == that.sessionlocalId) && (this.pfcpSessionId.equals(that.pfcpSessionId)); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public int hashCode() { |
| 96 | return Objects.hash(this.sessionlocalId, this.pfcpSessionId); |
| 97 | } |
| 98 | } |