Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 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.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onlab.util.ImmutableByteSequence; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkArgument; |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Runtime parameter of an action in a match+action table of a protocol-independent pipeline. |
| 28 | */ |
| 29 | @Beta |
| 30 | public final class PiActionParam { |
| 31 | |
| 32 | private final PiActionParamId id; |
| 33 | private final ImmutableByteSequence value; |
| 34 | |
| 35 | /** |
| 36 | * Creates an action's runtime parameter. |
| 37 | * |
| 38 | * @param id parameter identifier |
| 39 | * @param value value |
| 40 | */ |
| 41 | public PiActionParam(PiActionParamId id, ImmutableByteSequence value) { |
| 42 | this.id = checkNotNull(id); |
| 43 | this.value = checkNotNull(value); |
| 44 | checkArgument(value.size() > 0, "Value can't have size 0"); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the identifier of this parameter. |
| 49 | * |
| 50 | * @return parameter identifier |
| 51 | */ |
| 52 | public PiActionParamId id() { |
| 53 | return id; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the value of this parameter. |
| 58 | * |
| 59 | * @return parameter value |
| 60 | */ |
| 61 | public ImmutableByteSequence value() { |
| 62 | return value; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object o) { |
| 67 | if (this == o) { |
| 68 | return true; |
| 69 | } |
| 70 | if (o == null || getClass() != o.getClass()) { |
| 71 | return false; |
| 72 | } |
| 73 | PiActionParam that = (PiActionParam) o; |
| 74 | return Objects.equal(id, that.id) && |
| 75 | Objects.equal(value, that.value); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public int hashCode() { |
| 80 | return Objects.hashCode(id, value); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public String toString() { |
| 85 | return this.id.toString() + "=" + this.value().toString(); |
| 86 | } |
| 87 | } |