blob: 5059bceb3f73a226946600c17e1bd33573fbcb4b [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.ImmutableSet;
20import org.onosproject.net.pi.model.PiActionProfileId;
21import org.onosproject.net.pi.model.PiActionProfileModel;
22import org.onosproject.net.pi.model.PiTableId;
23
24import java.util.Collection;
25import java.util.Objects;
26
pierventre4d2a5422021-01-10 17:29:03 -080027import static com.google.common.base.MoreObjects.toStringHelper;
28
Carmelo Cascone87892e22017-11-13 16:01:29 -080029/**
30 * Implementation of PiActionProfileModel for P4Runtime.
31 */
32final class P4ActionProfileModel implements PiActionProfileModel {
33
34 private final PiActionProfileId id;
35 private final ImmutableSet<PiTableId> tables;
36 private final boolean hasSelector;
Carmelo Cascone99c59db2019-01-17 15:39:35 -080037 private final long size;
38 private final int maxGroupSize;
Carmelo Cascone87892e22017-11-13 16:01:29 -080039
40 P4ActionProfileModel(PiActionProfileId id,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080041 ImmutableSet<PiTableId> tables, boolean hasSelector,
42 long size, int maxGroupSize) {
Carmelo Cascone87892e22017-11-13 16:01:29 -080043 this.id = id;
44 this.tables = tables;
45 this.hasSelector = hasSelector;
Carmelo Cascone99c59db2019-01-17 15:39:35 -080046 this.size = size;
47 this.maxGroupSize = maxGroupSize;
Carmelo Cascone87892e22017-11-13 16:01:29 -080048 }
49
50 @Override
51 public PiActionProfileId id() {
52 return id;
53 }
54
55 @Override
56 public Collection<PiTableId> tables() {
57 return tables;
58 }
59
60 @Override
61 public boolean hasSelector() {
62 return hasSelector;
63 }
64
65 @Override
Carmelo Cascone99c59db2019-01-17 15:39:35 -080066 public long size() {
67 return size;
68 }
69
70 @Override
71 public int maxGroupSize() {
72 return maxGroupSize;
Carmelo Cascone87892e22017-11-13 16:01:29 -080073 }
74
75 @Override
76 public int hashCode() {
Carmelo Cascone99c59db2019-01-17 15:39:35 -080077 return Objects.hash(id, tables, hasSelector, size, maxGroupSize);
Carmelo Cascone87892e22017-11-13 16:01:29 -080078 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85 if (obj == null || getClass() != obj.getClass()) {
86 return false;
87 }
88 final P4ActionProfileModel other = (P4ActionProfileModel) obj;
89 return Objects.equals(this.id, other.id)
90 && Objects.equals(this.tables, other.tables)
91 && Objects.equals(this.hasSelector, other.hasSelector)
Carmelo Cascone99c59db2019-01-17 15:39:35 -080092 && Objects.equals(this.size, other.size)
93 && Objects.equals(this.maxGroupSize, other.maxGroupSize);
Carmelo Cascone87892e22017-11-13 16:01:29 -080094 }
pierventre4d2a5422021-01-10 17:29:03 -080095
96 @Override
97 public String toString() {
98 return toStringHelper(this)
99 .add("id", id)
100 .add("tables", tables)
101 .add("hasSelector", hasSelector)
102 .add("size", size)
103 .add("maxGroupSize", maxGroupSize)
104 .toString();
105 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800106}