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