blob: 87542bd4abf4198cb29b898a76b97c5747aad47b [file] [log] [blame]
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04003 *
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.net.flow.instructions;
18
19
20import com.google.common.annotations.Beta;
21import com.google.common.base.Objects;
Carmelo Casconecb4327a2018-09-11 15:17:23 -070022import org.onosproject.net.pi.runtime.PiActionProfileGroupId;
23import org.onosproject.net.pi.runtime.PiActionProfileMemberId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040024import org.onosproject.net.pi.runtime.PiTableAction;
25
26/**
27 * Representation of a protocol-independent instruction.
28 */
29@Beta
30public final class PiInstruction implements Instruction {
31
32 private final PiTableAction tableAction;
33
34 /**
35 * Creates a new instruction with the given protocol-independent table action.
36 *
37 * @param tableAction a protocol-independent action
38 */
39 PiInstruction(PiTableAction tableAction) {
40 this.tableAction = tableAction;
41 }
42
43 /**
44 * Returns the protocol-independent table action defined by this instruction.
45 *
46 * @return an action
47 */
48 public PiTableAction action() {
49 return tableAction;
50 }
51
52 @Override
53 public Type type() {
54 return Type.PROTOCOL_INDEPENDENT;
55 }
56
57 @Override
58 public boolean equals(Object o) {
59 if (this == o) {
60 return true;
61 }
62 if (o == null || getClass() != o.getClass()) {
63 return false;
64 }
65 PiInstruction that = (PiInstruction) o;
66 return Objects.equal(tableAction, that.tableAction);
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hashCode(tableAction);
72 }
73
74 @Override
75 public String toString() {
Carmelo Cascone9f159472017-10-03 16:43:14 +020076 switch (tableAction.type()) {
Carmelo Casconecb4327a2018-09-11 15:17:23 -070077 case ACTION_PROFILE_GROUP_ID:
78 return "GROUP:0x" + Integer.toHexString(((PiActionProfileGroupId) tableAction).id());
79 case ACTION_PROFILE_MEMBER_ID:
80 return "GROUP_MEMBER:0x" + Integer.toHexString(((PiActionProfileMemberId) tableAction).id());
Carmelo Cascone9f159472017-10-03 16:43:14 +020081 default:
82 return tableAction.toString();
83 }
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040084 }
85}