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; |
| 22 | import org.onosproject.net.pi.runtime.PiTableAction; |
| 23 | |
| 24 | /** |
| 25 | * Representation of a protocol-independent instruction. |
| 26 | */ |
| 27 | @Beta |
| 28 | public final class PiInstruction implements Instruction { |
| 29 | |
| 30 | private final PiTableAction tableAction; |
| 31 | |
| 32 | /** |
| 33 | * Creates a new instruction with the given protocol-independent table action. |
| 34 | * |
| 35 | * @param tableAction a protocol-independent action |
| 36 | */ |
| 37 | PiInstruction(PiTableAction tableAction) { |
| 38 | this.tableAction = tableAction; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the protocol-independent table action defined by this instruction. |
| 43 | * |
| 44 | * @return an action |
| 45 | */ |
| 46 | public PiTableAction action() { |
| 47 | return tableAction; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Type type() { |
| 52 | return Type.PROTOCOL_INDEPENDENT; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object o) { |
| 57 | if (this == o) { |
| 58 | return true; |
| 59 | } |
| 60 | if (o == null || getClass() != o.getClass()) { |
| 61 | return false; |
| 62 | } |
| 63 | PiInstruction that = (PiInstruction) o; |
| 64 | return Objects.equal(tableAction, that.tableAction); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public int hashCode() { |
| 69 | return Objects.hashCode(tableAction); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String toString() { |
| 74 | return tableAction.toString(); |
| 75 | } |
| 76 | } |