Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [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 | package org.onosproject.net.flow.instructions; |
| 17 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 18 | import org.onlab.packet.TpPort; |
| 19 | |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Abstraction of a single traffic treatment step. |
| 26 | */ |
| 27 | public abstract class L4ModificationInstruction implements Instruction { |
| 28 | |
| 29 | /** |
| 30 | * Represents the type of traffic treatment. |
| 31 | */ |
| 32 | public enum L4SubType { |
| 33 | /** |
| 34 | * TCP src modification. |
| 35 | */ |
| 36 | TCP_SRC, |
| 37 | |
| 38 | /** |
| 39 | * TCP dst modification. |
| 40 | */ |
| 41 | TCP_DST, |
| 42 | |
| 43 | /** |
| 44 | * UDP src modification. |
| 45 | */ |
| 46 | UDP_SRC, |
| 47 | |
| 48 | /** |
| 49 | * UDP dst modification. |
| 50 | */ |
| 51 | UDP_DST |
| 52 | |
| 53 | //TODO: remaining types |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the subtype of the modification instruction. |
| 58 | * |
| 59 | * @return type of instruction |
| 60 | */ |
| 61 | public abstract L4SubType subtype(); |
| 62 | |
| 63 | @Override |
| 64 | public Type type() { |
| 65 | return Type.L4MODIFICATION; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Represents a L4 src/dst modification instruction. |
| 70 | */ |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 71 | public static final class ModTransportPortInstruction extends L4ModificationInstruction { |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 72 | |
| 73 | private final L4SubType subtype; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 74 | private final TpPort port; |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 75 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 76 | public ModTransportPortInstruction(L4SubType subtype, TpPort port) { |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 77 | this.subtype = subtype; |
| 78 | this.port = port; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public L4SubType subtype() { |
| 83 | return this.subtype; |
| 84 | } |
| 85 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 86 | public TpPort port() { |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 87 | return this.port; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return toStringHelper(subtype().toString()) |
| 93 | .add("port", port).toString(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public int hashCode() { |
| 98 | return Objects.hash(type(), subtype(), port); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean equals(Object obj) { |
| 103 | if (this == obj) { |
| 104 | return true; |
| 105 | } |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 106 | if (obj instanceof ModTransportPortInstruction) { |
| 107 | ModTransportPortInstruction that = (ModTransportPortInstruction) obj; |
Hyunsun Moon | 9fed528 | 2015-07-16 17:55:22 -0700 | [diff] [blame] | 108 | return Objects.equals(port, that.port) && |
| 109 | Objects.equals(this.subtype(), that.subtype()); |
| 110 | } |
| 111 | return false; |
| 112 | } |
| 113 | } |
| 114 | } |