blob: 89c4bed1e3c6fba4b2d37510d13e54e706a026af [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.PiActionProfileModel;
23import org.onosproject.net.pi.model.PiCounterId;
24import org.onosproject.net.pi.model.PiCounterModel;
25import org.onosproject.net.pi.model.PiMatchFieldId;
26import org.onosproject.net.pi.model.PiMatchFieldModel;
27import org.onosproject.net.pi.model.PiMeterId;
28import org.onosproject.net.pi.model.PiMeterModel;
29import org.onosproject.net.pi.model.PiTableId;
30import org.onosproject.net.pi.model.PiTableModel;
31import org.onosproject.net.pi.model.PiTableType;
32
33import java.util.Collection;
34import java.util.Objects;
35import java.util.Optional;
36
37/**
38 * Implementation of PiTableModel for P4Runtime.
39 */
40final class P4TableModel implements PiTableModel {
41
42 private final PiTableId id;
43 private final PiTableType tableType;
44 private final PiActionProfileModel actionProfile;
45 private final long maxSize;
46 private final ImmutableMap<PiCounterId, PiCounterModel> counters;
47 private final ImmutableMap<PiMeterId, PiMeterModel> meters;
48 private final boolean supportAging;
49 private final ImmutableMap<PiMatchFieldId, PiMatchFieldModel> matchFields;
50 private final ImmutableMap<PiActionId, PiActionModel> actions;
51 private final PiActionModel defaultAction;
52 private final boolean hasDefaultMutableParams;
53
54 P4TableModel(PiTableId id, PiTableType tableType,
55 PiActionProfileModel actionProfile, long maxSize,
56 ImmutableMap<PiCounterId, PiCounterModel> counters,
57 ImmutableMap<PiMeterId, PiMeterModel> meters, boolean supportAging,
58 ImmutableMap<PiMatchFieldId, PiMatchFieldModel> matchFields,
59 ImmutableMap<PiActionId, PiActionModel> actions,
60 PiActionModel defaultAction, boolean hasDefaultMutableParams) {
61 this.id = id;
62 this.tableType = tableType;
63 this.actionProfile = actionProfile;
64 this.maxSize = maxSize;
65 this.counters = counters;
66 this.meters = meters;
67 this.supportAging = supportAging;
68 this.matchFields = matchFields;
69 this.actions = actions;
70 this.defaultAction = defaultAction;
71 this.hasDefaultMutableParams = hasDefaultMutableParams;
72 }
73
74 @Override
75 public PiTableId id() {
76 return id;
77 }
78
79 @Override
80 public PiTableType tableType() {
81 return tableType;
82 }
83
84 @Override
85 public PiActionProfileModel actionProfile() {
86 return actionProfile;
87 }
88
89 @Override
90 public long maxSize() {
91 return maxSize;
92 }
93
94 @Override
95 public Collection<PiCounterModel> counters() {
96 return counters.values();
97 }
98
99 @Override
100 public Collection<PiMeterModel> meters() {
101 return meters.values();
102 }
103
104 @Override
105 public boolean supportsAging() {
106 return supportAging;
107 }
108
109 @Override
110 public Collection<PiMatchFieldModel> matchFields() {
111 return matchFields.values();
112 }
113
114 @Override
115 public Collection<PiActionModel> actions() {
116 return actions.values();
117 }
118
119 @Override
120 public Optional<PiActionModel> defaultAction() {
121 return Optional.ofNullable(defaultAction);
122 }
123
124 @Override
125 public boolean hasDefaultMutableParams() {
126 return hasDefaultMutableParams;
127 }
128
129 @Override
130 public Optional<PiActionModel> action(PiActionId actionId) {
131 return Optional.ofNullable(actions.get(actionId));
132 }
133
134 @Override
135 public Optional<PiMatchFieldModel> matchField(PiMatchFieldId matchFieldId) {
136 return Optional.ofNullable(matchFields.get(matchFieldId));
137 }
138
139 @Override
140 public int hashCode() {
141 return Objects.hash(id, tableType, actionProfile, maxSize, counters,
142 meters, supportAging, matchFields, actions,
143 defaultAction, hasDefaultMutableParams);
144 }
145
146 @Override
147 public boolean equals(Object obj) {
148 if (this == obj) {
149 return true;
150 }
151 if (obj == null || getClass() != obj.getClass()) {
152 return false;
153 }
154 final P4TableModel other = (P4TableModel) obj;
155 return Objects.equals(this.id, other.id)
156 && Objects.equals(this.tableType, other.tableType)
157 && Objects.equals(this.actionProfile, other.actionProfile)
158 && Objects.equals(this.maxSize, other.maxSize)
159 && Objects.equals(this.counters, other.counters)
160 && Objects.equals(this.meters, other.meters)
161 && Objects.equals(this.supportAging, other.supportAging)
162 && Objects.equals(this.matchFields, other.matchFields)
163 && Objects.equals(this.actions, other.actions)
164 && Objects.equals(this.defaultAction, other.defaultAction)
165 && Objects.equals(this.hasDefaultMutableParams, other.hasDefaultMutableParams);
166 }
167}