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