blob: bb04f1e59ae59932e484703961e6950ba218a75a [file] [log] [blame]
Hyunsun Moon9fed5282015-07-16 17:55:22 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon9fed5282015-07-16 17:55:22 -07003 *
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 */
16package org.onosproject.net.flow.instructions;
17
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070018import org.onlab.packet.TpPort;
19
Hyunsun Moon9fed5282015-07-16 17:55:22 -070020import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Abstraction of a single traffic treatment step.
26 */
27public 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 Moonc8bd97c2015-07-18 22:47:33 -070071 public static final class ModTransportPortInstruction extends L4ModificationInstruction {
Hyunsun Moon9fed5282015-07-16 17:55:22 -070072
73 private final L4SubType subtype;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070074 private final TpPort port;
Hyunsun Moon9fed5282015-07-16 17:55:22 -070075
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070076 public ModTransportPortInstruction(L4SubType subtype, TpPort port) {
Hyunsun Moon9fed5282015-07-16 17:55:22 -070077 this.subtype = subtype;
78 this.port = port;
79 }
80
81 @Override
82 public L4SubType subtype() {
83 return this.subtype;
84 }
85
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070086 public TpPort port() {
Hyunsun Moon9fed5282015-07-16 17:55:22 -070087 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 Moonc8bd97c2015-07-18 22:47:33 -0700106 if (obj instanceof ModTransportPortInstruction) {
107 ModTransportPortInstruction that = (ModTransportPortInstruction) obj;
Hyunsun Moon9fed5282015-07-16 17:55:22 -0700108 return Objects.equals(port, that.port) &&
109 Objects.equals(this.subtype(), that.subtype());
110 }
111 return false;
112 }
113 }
114}