Committed by
Gerrit Code Review
ONOS-2402 Add L4 modification instruction type and class
Change-Id: I74fec41f865191371a908cef86c00218f8a1a203
Showing
2 changed files
with
118 additions
and
1 deletions
... | @@ -62,7 +62,12 @@ public interface Instruction { | ... | @@ -62,7 +62,12 @@ public interface Instruction { |
62 | /** | 62 | /** |
63 | * Signifies that metadata be attached to traffic. | 63 | * Signifies that metadata be attached to traffic. |
64 | */ | 64 | */ |
65 | - METADATA | 65 | + METADATA, |
66 | + | ||
67 | + /** | ||
68 | + * Signifies that the traffic should be modified in L4 way. | ||
69 | + */ | ||
70 | + L4MODIFICATION | ||
66 | } | 71 | } |
67 | 72 | ||
68 | /** | 73 | /** | ... | ... |
core/api/src/main/java/org/onosproject/net/flow/instructions/L4ModificationInstruction.java
0 → 100644
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.net.flow.instructions; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | + | ||
22 | +/** | ||
23 | + * Abstraction of a single traffic treatment step. | ||
24 | + */ | ||
25 | +public 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 | + */ | ||
69 | + public static final class ModL4PortInstruction extends L4ModificationInstruction { | ||
70 | + | ||
71 | + private final L4SubType subtype; | ||
72 | + private final short port; | ||
73 | + | ||
74 | + public ModL4PortInstruction(L4SubType subtype, short port) { | ||
75 | + 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 | + } | ||
104 | + if (obj instanceof ModL4PortInstruction) { | ||
105 | + ModL4PortInstruction that = (ModL4PortInstruction) obj; | ||
106 | + return Objects.equals(port, that.port) && | ||
107 | + Objects.equals(this.subtype(), that.subtype()); | ||
108 | + } | ||
109 | + return false; | ||
110 | + } | ||
111 | + } | ||
112 | +} |
-
Please register or login to post a comment