blob: dec4d1cc81fb9284912f2e51ed72103b5ba738f0 [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
29/**
30 * Implementation of PiActionModel for P4Runtime.
31 */
32final class P4ActionModel implements PiActionModel {
33
34 private final PiActionId id;
35 private final ImmutableMap<PiActionParamId, PiActionParamModel> params;
36
37 P4ActionModel(PiActionId id,
38 ImmutableMap<PiActionParamId, PiActionParamModel> params) {
39 this.id = id;
40 this.params = params;
41 }
42
43 @Override
44 public PiActionId id() {
45 return id;
46 }
47
48 @Override
49 public Optional<PiActionParamModel> param(PiActionParamId paramId) {
50 return Optional.ofNullable(params.get(paramId));
51 }
52
53 @Override
54 public Collection<PiActionParamModel> params() {
55 return params.values();
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(id, params);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj == null || getClass() != obj.getClass()) {
69 return false;
70 }
71 final P4ActionModel other = (P4ActionModel) obj;
72 return Objects.equals(this.id, other.id)
73 && Objects.equals(this.params, other.params);
74 }
75}