Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.collect.ImmutableList; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Lists; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 21 | import org.apache.commons.collections.ListUtils; |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame^] | 22 | import org.onlab.packet.EthType; |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 25 | import org.onlab.packet.MplsLabel; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 27 | import org.onosproject.core.GroupId; |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 28 | import org.onosproject.net.IndexedLambda; |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.net.flow.instructions.Instruction; |
| 31 | import org.onosproject.net.flow.instructions.Instructions; |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 32 | |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 33 | import java.util.Collections; |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 34 | import java.util.List; |
| 35 | import java.util.Objects; |
Yuta HIGUCHI | 2809bf3 | 2014-10-20 22:44:12 -0700 | [diff] [blame] | 36 | |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 37 | import static com.google.common.base.Preconditions.checkNotNull; |
| 38 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Default traffic treatment implementation. |
| 41 | */ |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 42 | public final class DefaultTrafficTreatment implements TrafficTreatment { |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 43 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 44 | private final List<Instruction> immediate; |
| 45 | private final List<Instruction> deferred; |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 46 | private final List<Instruction> all; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 47 | private final Instructions.TableTypeTransition table; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 48 | private final Instructions.MetadataInstruction meta; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 49 | |
| 50 | private final boolean hasClear; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 51 | |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 52 | private static final DefaultTrafficTreatment EMPTY |
| 53 | = new DefaultTrafficTreatment(Collections.emptyList()); |
| 54 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 55 | /** |
| 56 | * Creates a new traffic treatment from the specified list of instructions. |
| 57 | * |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 58 | * @param immediate immediate instructions |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 59 | */ |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 60 | private DefaultTrafficTreatment(List<Instruction> immediate) { |
| 61 | this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 62 | this.deferred = ImmutableList.of(); |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 63 | this.all = this.immediate; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 64 | this.hasClear = false; |
| 65 | this.table = null; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 66 | this.meta = null; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Creates a new traffic treatment from the specified list of instructions. |
| 71 | * |
| 72 | * @param deferred deferred instructions |
| 73 | * @param immediate immediate instructions |
| 74 | * @param table table transition instruction |
| 75 | * @param clear instruction to clear the deferred actions list |
| 76 | */ |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 77 | private DefaultTrafficTreatment(List<Instruction> deferred, |
| 78 | List<Instruction> immediate, |
| 79 | Instructions.TableTypeTransition table, |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 80 | boolean clear, |
| 81 | Instructions.MetadataInstruction meta) { |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 82 | this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); |
| 83 | this.deferred = ImmutableList.copyOf(checkNotNull(deferred)); |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 84 | this.all = ListUtils.union(this.immediate, this.deferred); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 85 | this.table = table; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 86 | this.meta = meta; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 87 | this.hasClear = clear; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 91 | public List<Instruction> deferred() { |
| 92 | return deferred; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public List<Instruction> immediate() { |
| 97 | return immediate; |
| 98 | } |
| 99 | |
| 100 | @Override |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 101 | public List<Instruction> allInstructions() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 102 | return all; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 106 | public Instructions.TableTypeTransition tableTransition() { |
| 107 | return table; |
| 108 | } |
| 109 | |
| 110 | @Override |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 111 | public boolean clearedDeferred() { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 112 | return hasClear; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 115 | @Override |
| 116 | public Instructions.MetadataInstruction writeMetadata() { |
| 117 | return meta; |
| 118 | } |
| 119 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 120 | /** |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 121 | * Returns a new traffic treatment builder. |
| 122 | * |
| 123 | * @return traffic treatment builder |
| 124 | */ |
| 125 | public static TrafficTreatment.Builder builder() { |
| 126 | return new Builder(); |
| 127 | } |
| 128 | |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 129 | /** |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 130 | * Returns an empty traffic treatment. |
| 131 | * |
| 132 | * @return empty traffic treatment |
| 133 | */ |
| 134 | public static TrafficTreatment emptyTreatment() { |
| 135 | return EMPTY; |
| 136 | } |
| 137 | |
| 138 | /** |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 139 | * Returns a new traffic treatment builder primed to produce entities |
| 140 | * patterned after the supplied treatment. |
| 141 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 142 | * @param treatment base treatment |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 143 | * @return traffic treatment builder |
| 144 | */ |
| 145 | public static TrafficTreatment.Builder builder(TrafficTreatment treatment) { |
| 146 | return new Builder(treatment); |
| 147 | } |
| 148 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 149 | //FIXME: Order of instructions may affect hashcode |
| 150 | @Override |
| 151 | public int hashCode() { |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 152 | return Objects.hash(immediate, deferred, table, meta); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean equals(Object obj) { |
| 157 | if (this == obj) { |
| 158 | return true; |
| 159 | } |
| 160 | if (obj instanceof DefaultTrafficTreatment) { |
| 161 | DefaultTrafficTreatment that = (DefaultTrafficTreatment) obj; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 162 | return Objects.equals(immediate, that.immediate) && |
| 163 | Objects.equals(deferred, that.deferred) && |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 164 | Objects.equals(table, that.table) && |
| 165 | Objects.equals(meta, that.meta); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 166 | |
| 167 | } |
| 168 | return false; |
| 169 | } |
| 170 | |
Jonathan Hart | d87aeca | 2014-10-21 10:42:52 -0700 | [diff] [blame] | 171 | @Override |
| 172 | public String toString() { |
| 173 | return MoreObjects.toStringHelper(getClass()) |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 174 | .add("immediate", immediate) |
| 175 | .add("deferred", deferred) |
| 176 | .add("transition", table == null ? "None" : table.toString()) |
| 177 | .add("cleared", hasClear) |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 178 | .add("metadata", meta) |
Jonathan Hart | d87aeca | 2014-10-21 10:42:52 -0700 | [diff] [blame] | 179 | .toString(); |
| 180 | } |
| 181 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 182 | /** |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 183 | * Builds a list of treatments following the following order. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 184 | * Modifications -> Group -> Output (including drop) |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 185 | */ |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 186 | public static final class Builder implements TrafficTreatment.Builder { |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 187 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 188 | boolean clear = false; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 189 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 190 | Instructions.TableTypeTransition table; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 191 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 192 | Instructions.MetadataInstruction meta; |
| 193 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 194 | List<Instruction> deferred = Lists.newLinkedList(); |
| 195 | |
| 196 | List<Instruction> immediate = Lists.newLinkedList(); |
| 197 | |
| 198 | List<Instruction> current = immediate; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 199 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 200 | // Creates a new builder |
| 201 | private Builder() { |
| 202 | } |
| 203 | |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 204 | // Creates a new builder based off an existing treatment |
| 205 | private Builder(TrafficTreatment treatment) { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 206 | deferred(); |
| 207 | treatment.deferred().forEach(i -> add(i)); |
| 208 | |
| 209 | immediate(); |
| 210 | treatment.immediate().forEach(i -> add(i)); |
| 211 | |
| 212 | clear = treatment.clearedDeferred(); |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 213 | } |
| 214 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 215 | @Override |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 216 | public Builder add(Instruction instruction) { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 217 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 218 | switch (instruction.type()) { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 219 | case DROP: |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 220 | case OUTPUT: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 221 | case GROUP: |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 222 | case L0MODIFICATION: |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 223 | case L2MODIFICATION: |
| 224 | case L3MODIFICATION: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 225 | current.add(instruction); |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 226 | break; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 227 | case TABLE: |
| 228 | table = (Instructions.TableTypeTransition) instruction; |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 229 | break; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 230 | case METADATA: |
| 231 | meta = (Instructions.MetadataInstruction) instruction; |
| 232 | break; |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 233 | default: |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 234 | throw new IllegalArgumentException("Unknown instruction type: " + |
| 235 | instruction.type()); |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 236 | } |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 237 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 238 | return this; |
| 239 | } |
| 240 | |
| 241 | @Override |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 242 | public Builder drop() { |
| 243 | return add(Instructions.createDrop()); |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public Builder punt() { |
| 248 | return add(Instructions.createOutput(PortNumber.CONTROLLER)); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public Builder setOutput(PortNumber number) { |
| 253 | return add(Instructions.createOutput(number)); |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public Builder setEthSrc(MacAddress addr) { |
| 258 | return add(Instructions.modL2Src(addr)); |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public Builder setEthDst(MacAddress addr) { |
| 263 | return add(Instructions.modL2Dst(addr)); |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public Builder setVlanId(VlanId id) { |
| 268 | return add(Instructions.modVlanId(id)); |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public Builder setVlanPcp(Byte pcp) { |
| 273 | return add(Instructions.modVlanPcp(pcp)); |
| 274 | } |
| 275 | |
| 276 | @Override |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 277 | public Builder setIpSrc(IpAddress addr) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 278 | return add(Instructions.modL3Src(addr)); |
| 279 | } |
| 280 | |
| 281 | @Override |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 282 | public Builder setIpDst(IpAddress addr) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 283 | return add(Instructions.modL3Dst(addr)); |
| 284 | } |
| 285 | |
| 286 | @Override |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 287 | public Builder decNwTtl() { |
| 288 | return add(Instructions.decNwTtl()); |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public Builder copyTtlIn() { |
| 293 | return add(Instructions.copyTtlIn()); |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public Builder copyTtlOut() { |
| 298 | return add(Instructions.copyTtlOut()); |
| 299 | } |
| 300 | |
| 301 | @Override |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 302 | public Builder pushMpls() { |
| 303 | return add(Instructions.pushMpls()); |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public Builder popMpls() { |
| 308 | return add(Instructions.popMpls()); |
| 309 | } |
| 310 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 311 | @Override |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 312 | public Builder popMpls(int etherType) { |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame^] | 313 | return add(Instructions.popMpls(new EthType(etherType))); |
| 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public Builder popMpls(EthType etherType) { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 318 | return add(Instructions.popMpls(etherType)); |
| 319 | } |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 320 | |
| 321 | @Override |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 322 | public Builder setMpls(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 323 | return add(Instructions.modMplsLabel(mplsLabel)); |
| 324 | } |
| 325 | |
| 326 | @Override |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 327 | public Builder decMplsTtl() { |
| 328 | return add(Instructions.decMplsTtl()); |
| 329 | } |
| 330 | |
| 331 | @Override |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 332 | public Builder setLambda(short lambda) { |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 333 | return add(Instructions.modL0Lambda(new IndexedLambda(lambda))); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Override |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 337 | public Builder group(GroupId groupId) { |
| 338 | return add(Instructions.createGroup(groupId)); |
| 339 | } |
| 340 | |
| 341 | @Override |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 342 | public Builder popVlan() { |
| 343 | return add(Instructions.popVlan()); |
| 344 | } |
| 345 | |
| 346 | @Override |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 347 | public Builder pushVlan() { |
| 348 | return add(Instructions.pushVlan()); |
| 349 | } |
| 350 | |
| 351 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 352 | public Builder transition(FlowRule.Type type) { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 353 | return add(Instructions.transition(type.ordinal())); |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public Builder transition(Integer tableId) { |
| 358 | return add(Instructions.transition(tableId)); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public Builder immediate() { |
| 363 | current = immediate; |
| 364 | return this; |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public Builder deferred() { |
| 369 | current = deferred; |
| 370 | return this; |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public Builder wipeDeferred() { |
| 375 | clear = true; |
| 376 | return this; |
| 377 | } |
| 378 | |
| 379 | @Override |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 380 | public Builder writeMetadata(long metadata, long metadataMask) { |
| 381 | return add(Instructions.writeMetadata(metadata, metadataMask)); |
| 382 | } |
| 383 | |
| 384 | @Override |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 385 | public TrafficTreatment build() { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 386 | //Don't add DROP instruction by default when instruction |
| 387 | //set is empty. This will be handled in DefaultSingleTablePipeline |
| 388 | //driver. |
| 389 | |
| 390 | //if (deferred.size() == 0 && immediate.size() == 0 |
| 391 | // && table == null && !clear) { |
| 392 | // drop(); |
| 393 | //} |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 394 | return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta); |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | } |
| 398 | |
| 399 | } |