Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 19 | import org.onlab.util.Bandwidth; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.core.DefaultGroupId; |
| 21 | import org.onosproject.core.GroupId; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.ElementId; |
| 24 | import org.onosproject.net.Link; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 25 | import org.onosproject.net.NetTestTools; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 26 | import org.onosproject.net.NetworkResource; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.Path; |
| 28 | import org.onosproject.net.flow.FlowId; |
| 29 | import org.onosproject.net.flow.FlowRule; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 30 | import org.onosproject.net.flow.FlowRuleExtPayLoad; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.TrafficSelector; |
| 32 | import org.onosproject.net.flow.TrafficTreatment; |
| 33 | import org.onosproject.net.flow.criteria.Criterion; |
| 34 | import org.onosproject.net.flow.criteria.Criterion.Type; |
| 35 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 36 | import org.onosproject.net.flow.instructions.Instructions; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 37 | import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction; |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 38 | import org.onosproject.net.newresource.DiscreteResourceId; |
| 39 | import org.onosproject.net.newresource.Resource; |
| 40 | import org.onosproject.net.newresource.ResourceAllocation; |
| 41 | import org.onosproject.net.newresource.ResourceConsumer; |
| 42 | import org.onosproject.net.newresource.ResourceId; |
| 43 | import org.onosproject.net.newresource.ResourceListener; |
| 44 | import org.onosproject.net.newresource.ResourceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| 46 | import org.onosproject.net.topology.DefaultTopologyVertex; |
| 47 | import org.onosproject.net.topology.LinkWeight; |
Thomas Vachuska | 48e64e4 | 2015-09-22 15:32:55 -0700 | [diff] [blame] | 48 | import org.onosproject.net.topology.PathServiceAdapter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 49 | import org.onosproject.net.topology.TopologyVertex; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 50 | import org.onosproject.store.Timestamp; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 51 | |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 52 | import java.util.Arrays; |
| 53 | import java.util.Collection; |
| 54 | import java.util.Collections; |
| 55 | import java.util.HashSet; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 56 | import java.util.List; |
| 57 | import java.util.Objects; |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 58 | import java.util.Optional; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 59 | import java.util.Set; |
| 60 | import java.util.concurrent.atomic.AtomicLong; |
| 61 | |
Thomas Vachuska | 48e64e4 | 2015-09-22 15:32:55 -0700 | [diff] [blame] | 62 | import static org.onosproject.net.NetTestTools.*; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 63 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 64 | /** |
| 65 | * Common mocks used by the intent framework tests. |
| 66 | */ |
| 67 | public class IntentTestsMocks { |
| 68 | /** |
| 69 | * Mock traffic selector class used for satisfying API requirements. |
| 70 | */ |
| 71 | public static class MockSelector implements TrafficSelector { |
| 72 | @Override |
| 73 | public Set<Criterion> criteria() { |
| 74 | return new HashSet<>(); |
| 75 | } |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 76 | |
| 77 | @Override |
| 78 | public Criterion getCriterion(Type type) { |
| 79 | return null; |
| 80 | } |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Mock traffic treatment class used for satisfying API requirements. |
| 85 | */ |
| 86 | public static class MockTreatment implements TrafficTreatment { |
| 87 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 88 | public List<Instruction> deferred() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 89 | return Collections.emptyList(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public List<Instruction> immediate() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 94 | return Collections.emptyList(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 98 | public List<Instruction> allInstructions() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 99 | return Collections.emptyList(); |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 103 | public Instructions.TableTypeTransition tableTransition() { |
| 104 | return null; |
| 105 | } |
| 106 | |
| 107 | @Override |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 108 | public boolean clearedDeferred() { |
| 109 | return false; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 110 | } |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 111 | |
| 112 | @Override |
| 113 | public MetadataInstruction writeMetadata() { |
| 114 | return null; |
| 115 | } |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 116 | |
| 117 | @Override |
| 118 | public Instructions.MeterInstruction metered() { |
| 119 | return null; |
| 120 | } |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Mock path service for creating paths within the test. |
| 125 | */ |
Thomas Vachuska | 48e64e4 | 2015-09-22 15:32:55 -0700 | [diff] [blame] | 126 | public static class MockPathService extends PathServiceAdapter { |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 127 | |
| 128 | final String[] pathHops; |
| 129 | final String[] reversePathHops; |
| 130 | |
| 131 | /** |
| 132 | * Constructor that provides a set of hops to mock. |
| 133 | * |
| 134 | * @param pathHops path hops to mock |
| 135 | */ |
| 136 | public MockPathService(String[] pathHops) { |
| 137 | this.pathHops = pathHops; |
| 138 | String[] reversed = pathHops.clone(); |
| 139 | Collections.reverse(Arrays.asList(reversed)); |
| 140 | reversePathHops = reversed; |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public Set<Path> getPaths(ElementId src, ElementId dst) { |
| 145 | Set<Path> result = new HashSet<>(); |
| 146 | |
| 147 | String[] allHops = new String[pathHops.length]; |
| 148 | |
| 149 | if (src.toString().endsWith(pathHops[0])) { |
| 150 | System.arraycopy(pathHops, 0, allHops, 0, pathHops.length); |
| 151 | } else { |
| 152 | System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length); |
| 153 | } |
| 154 | |
| 155 | result.add(createPath(allHops)); |
| 156 | return result; |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 161 | final Set<Path> paths = getPaths(src, dst); |
| 162 | |
| 163 | for (Path path : paths) { |
| 164 | final DeviceId srcDevice = path.src().deviceId(); |
| 165 | final DeviceId dstDevice = path.dst().deviceId(); |
| 166 | final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice); |
| 167 | final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice); |
| 168 | final Link link = link(src.toString(), 1, dst.toString(), 1); |
| 169 | |
| 170 | final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link)); |
| 171 | if (weightValue < 0) { |
| 172 | return new HashSet<>(); |
| 173 | } |
| 174 | } |
| 175 | return paths; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 178 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 179 | public static final class MockResourceService implements ResourceService { |
| 180 | |
| 181 | private final double bandwidth; |
| 182 | |
| 183 | public static ResourceService makeBandwidthResourceService(double bandwidth) { |
| 184 | return new MockResourceService(bandwidth); |
| 185 | } |
| 186 | |
| 187 | private MockResourceService(double bandwidth) { |
| 188 | this.bandwidth = bandwidth; |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 189 | } |
| 190 | |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 191 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 192 | public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 193 | return null; |
| 194 | } |
| 195 | |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 196 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 197 | public boolean release(List<ResourceAllocation> allocations) { |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public boolean release(ResourceConsumer consumer) { |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public List<ResourceAllocation> getResourceAllocations(ResourceId id) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 208 | return null; |
| 209 | } |
| 210 | |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 211 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 212 | public <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 213 | return null; |
| 214 | } |
| 215 | |
| 216 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 217 | public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 218 | return null; |
| 219 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 220 | |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 221 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 222 | public Set<Resource> getAvailableResources(DiscreteResourceId parent) { |
| 223 | return null; |
| 224 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 225 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 226 | @Override |
| 227 | public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) { |
| 228 | return null; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) { |
| 233 | return null; |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public Set<Resource> getRegisteredResources(DiscreteResourceId parent) { |
| 238 | return null; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public boolean isAvailable(Resource resource) { |
| 243 | if (!resource.isTypeOf(Bandwidth.class)) { |
| 244 | return false; |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 247 | Optional<Double> value = resource.valueAs(Double.class); |
| 248 | return value.filter(requested -> requested <= bandwidth).isPresent(); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 252 | public void addListener(ResourceListener listener) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 256 | public void removeListener(ResourceListener listener) { |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 257 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 260 | private static final IntentTestsMocks.MockSelector SELECTOR = |
| 261 | new IntentTestsMocks.MockSelector(); |
| 262 | private static final IntentTestsMocks.MockTreatment TREATMENT = |
| 263 | new IntentTestsMocks.MockTreatment(); |
| 264 | |
| 265 | public static class MockFlowRule implements FlowRule { |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 266 | static int nextId = 0; |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 267 | |
| 268 | int priority; |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 269 | int tableId; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 270 | long timestamp; |
| 271 | int id; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 272 | FlowRuleExtPayLoad payLoad; |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 273 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 274 | public MockFlowRule(int priority) { |
| 275 | this.priority = priority; |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 276 | this.tableId = 0; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 277 | this.timestamp = System.currentTimeMillis(); |
| 278 | this.id = nextId++; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 279 | this.payLoad = null; |
| 280 | } |
| 281 | |
| 282 | public MockFlowRule(int priority, FlowRuleExtPayLoad payLoad) { |
| 283 | this.priority = priority; |
| 284 | this.timestamp = System.currentTimeMillis(); |
| 285 | this.id = nextId++; |
| 286 | this.payLoad = payLoad; |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public FlowId id() { |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 291 | return FlowId.valueOf(id); |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public short appId() { |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | @Override |
Sho SHIMIZU | 75a5bd9 | 2014-11-25 11:22:56 -0800 | [diff] [blame] | 300 | public GroupId groupId() { |
| 301 | return new DefaultGroupId(0); |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | @Override |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 305 | public int priority() { |
| 306 | return priority; |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public DeviceId deviceId() { |
| 311 | return did("1"); |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public TrafficSelector selector() { |
| 316 | return SELECTOR; |
| 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public TrafficTreatment treatment() { |
| 321 | return TREATMENT; |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public int timeout() { |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public boolean isPermanent() { |
| 331 | return false; |
| 332 | } |
| 333 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 334 | @Override |
| 335 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 336 | return priority; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 337 | } |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 338 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 339 | @Override |
| 340 | public boolean equals(Object obj) { |
| 341 | if (this == obj) { |
| 342 | return true; |
| 343 | } |
| 344 | if (obj == null || getClass() != obj.getClass()) { |
| 345 | return false; |
| 346 | } |
| 347 | final MockFlowRule other = (MockFlowRule) obj; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 348 | return Objects.equals(this.timestamp, other.timestamp) && |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 349 | this.id == other.id; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 350 | } |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 351 | |
| 352 | @Override |
Jonathan Hart | f44e42c | 2015-08-04 09:58:46 -0700 | [diff] [blame] | 353 | public boolean exactMatch(FlowRule rule) { |
| 354 | return this.equals(rule); |
| 355 | } |
| 356 | |
| 357 | @Override |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 358 | public int tableId() { |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 359 | return tableId; |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 360 | } |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 361 | |
| 362 | @Override |
| 363 | public FlowRuleExtPayLoad payLoad() { |
| 364 | return payLoad; |
| 365 | } |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 368 | public static class MockIntent extends Intent { |
| 369 | private static AtomicLong counter = new AtomicLong(0); |
| 370 | |
| 371 | private final Long number; |
| 372 | |
| 373 | public MockIntent(Long number) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 374 | super(NetTestTools.APP_ID, null, Collections.emptyList(), |
Nikhil Cheerla | 2ec191f | 2015-07-09 12:34:54 -0700 | [diff] [blame] | 375 | Intent.DEFAULT_INTENT_PRIORITY); |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 376 | this.number = number; |
| 377 | } |
| 378 | |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 379 | public MockIntent(Long number, Collection<NetworkResource> resources) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 380 | super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY); |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 381 | this.number = number; |
| 382 | } |
| 383 | |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 384 | public Long number() { |
| 385 | return number; |
| 386 | } |
| 387 | |
| 388 | public static Long nextId() { |
| 389 | return counter.getAndIncrement(); |
| 390 | } |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 391 | |
| 392 | @Override |
| 393 | public String toString() { |
| 394 | return MoreObjects.toStringHelper(getClass()) |
| 395 | .add("id", id()) |
| 396 | .add("appId", appId()) |
| 397 | .toString(); |
| 398 | } |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | public static class MockTimestamp implements Timestamp { |
| 402 | final int value; |
| 403 | |
| 404 | public MockTimestamp(int value) { |
| 405 | this.value = value; |
| 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public int compareTo(Timestamp o) { |
| 410 | if (!(o instanceof MockTimestamp)) { |
| 411 | return -1; |
| 412 | } |
| 413 | MockTimestamp that = (MockTimestamp) o; |
Jonathan Hart | 72175c2 | 2015-03-24 18:55:58 -0700 | [diff] [blame] | 414 | return this.value - that.value; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 418 | } |