Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.flow.instructions; |
| 18 | |
| 19 | |
| 20 | import com.google.common.annotations.Beta; |
| 21 | import com.google.common.base.Objects; |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 22 | import org.onosproject.net.pi.runtime.PiActionProfileGroupId; |
| 23 | import org.onosproject.net.pi.runtime.PiActionProfileMemberId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 24 | import org.onosproject.net.pi.runtime.PiTableAction; |
| 25 | |
| 26 | /** |
| 27 | * Representation of a protocol-independent instruction. |
| 28 | */ |
| 29 | @Beta |
| 30 | public 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 Cascone | 9f15947 | 2017-10-03 16:43:14 +0200 | [diff] [blame] | 76 | switch (tableAction.type()) { |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 77 | 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 Cascone | 9f15947 | 2017-10-03 16:43:14 +0200 | [diff] [blame] | 81 | default: |
| 82 | return tableAction.toString(); |
| 83 | } |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 84 | } |
| 85 | } |