blob: 6b1af83cf4c30ee718afab7fb856fafd252fd441 [file] [log] [blame]
Carmelo Cascone87892e22017-11-13 16:01:29 -08001/*
2 * Copyright 2017-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
17package org.onosproject.p4runtime.model;
18
19import com.google.common.collect.ImmutableMap;
20import org.onosproject.net.pi.model.PiActionId;
21import org.onosproject.net.pi.model.PiActionModel;
22import org.onosproject.net.pi.model.PiActionParamId;
23import org.onosproject.net.pi.model.PiActionParamModel;
24
25import java.util.Collection;
26import java.util.Objects;
27import java.util.Optional;
28
pierventre4d2a5422021-01-10 17:29:03 -080029import static com.google.common.base.MoreObjects.toStringHelper;
30
Carmelo Cascone87892e22017-11-13 16:01:29 -080031/**
32 * Implementation of PiActionModel for P4Runtime.
33 */
34final class P4ActionModel implements PiActionModel {
35
36 private final PiActionId id;
37 private final ImmutableMap<PiActionParamId, PiActionParamModel> params;
38
39 P4ActionModel(PiActionId id,
40 ImmutableMap<PiActionParamId, PiActionParamModel> params) {
41 this.id = id;
42 this.params = params;
43 }
44
45 @Override
46 public PiActionId id() {
47 return id;
48 }
49
50 @Override
51 public Optional<PiActionParamModel> param(PiActionParamId paramId) {
52 return Optional.ofNullable(params.get(paramId));
53 }
54
55 @Override
56 public Collection<PiActionParamModel> params() {
57 return params.values();
58 }
59
60 @Override
61 public int hashCode() {
62 return Objects.hash(id, params);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj == null || getClass() != obj.getClass()) {
71 return false;
72 }
73 final P4ActionModel other = (P4ActionModel) obj;
74 return Objects.equals(this.id, other.id)
75 && Objects.equals(this.params, other.params);
76 }
pierventre4d2a5422021-01-10 17:29:03 -080077
78 @Override
79 public String toString() {
80 return toStringHelper(this)
81 .add("id", id)
82 .add("params", params.values())
83 .toString();
84 }
Carmelo Cascone87892e22017-11-13 16:01:29 -080085}