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