blob: 3421e703191b609e386e999cc26278b3633762ce [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.ImmutableList;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080020import org.onosproject.net.pi.model.PiPacketMetadataModel;
Carmelo Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.pi.model.PiPacketOperationModel;
22import org.onosproject.net.pi.model.PiPacketOperationType;
23
24import java.util.List;
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 PiPacketOperationModel for P4Runtime.
31 */
32final class P4PacketOperationModel implements PiPacketOperationModel {
33
34 private final PiPacketOperationType type;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080035 private final ImmutableList<PiPacketMetadataModel> metadatas;
Carmelo Cascone87892e22017-11-13 16:01:29 -080036
37 P4PacketOperationModel(PiPacketOperationType type,
pierventre4d2a5422021-01-10 17:29:03 -080038 ImmutableList<PiPacketMetadataModel> metadatas) {
Carmelo Cascone87892e22017-11-13 16:01:29 -080039 this.type = type;
40 this.metadatas = metadatas;
41 }
42
43 @Override
44 public PiPacketOperationType type() {
45 return type;
46 }
47
48 @Override
Carmelo Cascone4c289b72019-01-22 15:30:45 -080049 public List<PiPacketMetadataModel> metadatas() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080050 return metadatas;
51 }
52
53 @Override
54 public int hashCode() {
55 return Objects.hash(type, metadatas);
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 if (this == obj) {
61 return true;
62 }
63 if (obj == null || getClass() != obj.getClass()) {
64 return false;
65 }
66 final P4PacketOperationModel other = (P4PacketOperationModel) obj;
67 return Objects.equals(this.type, other.type)
68 && Objects.equals(this.metadatas, other.metadatas);
69 }
pierventre4d2a5422021-01-10 17:29:03 -080070
71 @Override
72 public String toString() {
73 return toStringHelper(this)
74 .add("type", type)
75 .add("metadatas", metadatas)
76 .toString();
77 }
Carmelo Cascone87892e22017-11-13 16:01:29 -080078}