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; |
| 19 | import com.google.common.collect.ImmutableSet; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 20 | |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 21 | import org.onlab.util.Bandwidth; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.core.DefaultGroupId; |
| 23 | import org.onosproject.core.GroupId; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.ElementId; |
| 26 | import org.onosproject.net.Link; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 27 | import org.onosproject.net.NetTestTools; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 28 | import org.onosproject.net.NetworkResource; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.Path; |
| 30 | import org.onosproject.net.flow.FlowId; |
| 31 | import org.onosproject.net.flow.FlowRule; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.FlowRuleExtPayLoad; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.TrafficSelector; |
| 34 | import org.onosproject.net.flow.TrafficTreatment; |
| 35 | import org.onosproject.net.flow.criteria.Criterion; |
| 36 | import org.onosproject.net.flow.criteria.Criterion.Type; |
| 37 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.instructions.Instructions; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 39 | import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 40 | import org.onosproject.net.resource.link.BandwidthResource; |
| 41 | import org.onosproject.net.resource.link.BandwidthResourceRequest; |
| 42 | import org.onosproject.net.resource.link.LambdaResource; |
| 43 | import org.onosproject.net.resource.link.LambdaResourceAllocation; |
| 44 | import org.onosproject.net.resource.link.LambdaResourceRequest; |
| 45 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
| 46 | import org.onosproject.net.resource.link.LinkResourceListener; |
| 47 | import org.onosproject.net.resource.link.LinkResourceRequest; |
| 48 | import org.onosproject.net.resource.link.LinkResourceService; |
| 49 | import org.onosproject.net.resource.link.MplsLabel; |
| 50 | import org.onosproject.net.resource.link.MplsLabelResourceAllocation; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 51 | import org.onosproject.net.resource.ResourceAllocation; |
| 52 | import org.onosproject.net.resource.ResourceRequest; |
| 53 | import org.onosproject.net.resource.ResourceType; |
| 54 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| 55 | import org.onosproject.net.topology.DefaultTopologyVertex; |
| 56 | import org.onosproject.net.topology.LinkWeight; |
| 57 | import org.onosproject.net.topology.PathService; |
| 58 | import org.onosproject.net.topology.TopologyVertex; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 59 | import org.onosproject.store.Timestamp; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 60 | |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 61 | import java.util.Arrays; |
| 62 | import java.util.Collection; |
| 63 | import java.util.Collections; |
| 64 | import java.util.HashSet; |
| 65 | import java.util.LinkedList; |
| 66 | import java.util.List; |
| 67 | import java.util.Objects; |
| 68 | import java.util.Set; |
| 69 | import java.util.concurrent.atomic.AtomicLong; |
| 70 | |
| 71 | import static org.onosproject.net.NetTestTools.createPath; |
| 72 | import static org.onosproject.net.NetTestTools.did; |
| 73 | import static org.onosproject.net.NetTestTools.link; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 74 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Common mocks used by the intent framework tests. |
| 77 | */ |
| 78 | public class IntentTestsMocks { |
| 79 | /** |
| 80 | * Mock traffic selector class used for satisfying API requirements. |
| 81 | */ |
| 82 | public static class MockSelector implements TrafficSelector { |
| 83 | @Override |
| 84 | public Set<Criterion> criteria() { |
| 85 | return new HashSet<>(); |
| 86 | } |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 87 | |
| 88 | @Override |
| 89 | public Criterion getCriterion(Type type) { |
| 90 | return null; |
| 91 | } |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Mock traffic treatment class used for satisfying API requirements. |
| 96 | */ |
| 97 | public static class MockTreatment implements TrafficTreatment { |
| 98 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 99 | public List<Instruction> deferred() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 100 | return Collections.emptyList(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public List<Instruction> immediate() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 105 | return Collections.emptyList(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 109 | public List<Instruction> allInstructions() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 110 | return Collections.emptyList(); |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 114 | public Instructions.TableTypeTransition tableTransition() { |
| 115 | return null; |
| 116 | } |
| 117 | |
| 118 | @Override |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 119 | public boolean clearedDeferred() { |
| 120 | return false; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 121 | } |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 122 | |
| 123 | @Override |
| 124 | public MetadataInstruction writeMetadata() { |
| 125 | return null; |
| 126 | } |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Mock path service for creating paths within the test. |
| 131 | */ |
| 132 | public static class MockPathService implements PathService { |
| 133 | |
| 134 | final String[] pathHops; |
| 135 | final String[] reversePathHops; |
| 136 | |
| 137 | /** |
| 138 | * Constructor that provides a set of hops to mock. |
| 139 | * |
| 140 | * @param pathHops path hops to mock |
| 141 | */ |
| 142 | public MockPathService(String[] pathHops) { |
| 143 | this.pathHops = pathHops; |
| 144 | String[] reversed = pathHops.clone(); |
| 145 | Collections.reverse(Arrays.asList(reversed)); |
| 146 | reversePathHops = reversed; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public Set<Path> getPaths(ElementId src, ElementId dst) { |
| 151 | Set<Path> result = new HashSet<>(); |
| 152 | |
| 153 | String[] allHops = new String[pathHops.length]; |
| 154 | |
| 155 | if (src.toString().endsWith(pathHops[0])) { |
| 156 | System.arraycopy(pathHops, 0, allHops, 0, pathHops.length); |
| 157 | } else { |
| 158 | System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length); |
| 159 | } |
| 160 | |
| 161 | result.add(createPath(allHops)); |
| 162 | return result; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 167 | final Set<Path> paths = getPaths(src, dst); |
| 168 | |
| 169 | for (Path path : paths) { |
| 170 | final DeviceId srcDevice = path.src().deviceId(); |
| 171 | final DeviceId dstDevice = path.dst().deviceId(); |
| 172 | final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice); |
| 173 | final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice); |
| 174 | final Link link = link(src.toString(), 1, dst.toString(), 1); |
| 175 | |
| 176 | final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link)); |
| 177 | if (weightValue < 0) { |
| 178 | return new HashSet<>(); |
| 179 | } |
| 180 | } |
| 181 | return paths; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 184 | |
| 185 | public static class MockLinkResourceAllocations implements LinkResourceAllocations { |
| 186 | @Override |
| 187 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
Ray Milkey | b1b66d3 | 2015-03-02 10:27:11 -0800 | [diff] [blame] | 188 | return ImmutableSet.of( |
Sho SHIMIZU | 94b7ff4 | 2015-05-06 17:51:49 -0700 | [diff] [blame] | 189 | new LambdaResourceAllocation(LambdaResource.valueOf(77)), |
Ray Milkey | b1b66d3 | 2015-03-02 10:27:11 -0800 | [diff] [blame] | 190 | new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Ayaka Koshibe | e114f04 | 2015-05-01 11:43:00 -0700 | [diff] [blame] | 193 | public IntentId intentId() { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 194 | return null; |
| 195 | } |
| 196 | |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 197 | public Collection<Link> links() { |
| 198 | return null; |
| 199 | } |
| 200 | |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 201 | public Set<ResourceRequest> resources() { |
| 202 | return null; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public ResourceType type() { |
| 207 | return null; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | public static class MockedAllocationFailure extends RuntimeException { } |
| 212 | |
| 213 | public static class MockResourceService implements LinkResourceService { |
| 214 | |
| 215 | double availableBandwidth = -1.0; |
| 216 | int availableLambda = -1; |
| 217 | |
| 218 | /** |
| 219 | * Allocates a resource service that will allow bandwidth allocations |
| 220 | * up to a limit. |
| 221 | * |
| 222 | * @param bandwidth available bandwidth limit |
| 223 | * @return resource manager for bandwidth requests |
| 224 | */ |
| 225 | public static MockResourceService makeBandwidthResourceService(double bandwidth) { |
| 226 | final MockResourceService result = new MockResourceService(); |
| 227 | result.availableBandwidth = bandwidth; |
| 228 | return result; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Allocates a resource service that will allow lambda allocations. |
| 233 | * |
| 234 | * @param lambda Lambda to return for allocation requests. Currently unused |
| 235 | * @return resource manager for lambda requests |
| 236 | */ |
| 237 | public static MockResourceService makeLambdaResourceService(int lambda) { |
| 238 | final MockResourceService result = new MockResourceService(); |
| 239 | result.availableLambda = lambda; |
| 240 | return result; |
| 241 | } |
| 242 | |
| 243 | public void setAvailableBandwidth(double availableBandwidth) { |
| 244 | this.availableBandwidth = availableBandwidth; |
| 245 | } |
| 246 | |
| 247 | public void setAvailableLambda(int availableLambda) { |
| 248 | this.availableLambda = availableLambda; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | @Override |
| 253 | public LinkResourceAllocations requestResources(LinkResourceRequest req) { |
| 254 | int lambda = -1; |
| 255 | double bandwidth = -1.0; |
| 256 | |
| 257 | for (ResourceRequest resourceRequest : req.resources()) { |
| 258 | if (resourceRequest.type() == ResourceType.BANDWIDTH) { |
| 259 | final BandwidthResourceRequest brr = (BandwidthResourceRequest) resourceRequest; |
| 260 | bandwidth = brr.bandwidth().toDouble(); |
| 261 | } else if (resourceRequest.type() == ResourceType.LAMBDA) { |
| 262 | lambda = 1; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if (availableBandwidth < bandwidth) { |
| 267 | throw new MockedAllocationFailure(); |
| 268 | } |
| 269 | if (lambda > 0 && availableLambda == 0) { |
| 270 | throw new MockedAllocationFailure(); |
| 271 | } |
| 272 | |
| 273 | return new IntentTestsMocks.MockLinkResourceAllocations(); |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void releaseResources(LinkResourceAllocations allocations) { |
| 278 | // Mock |
| 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public LinkResourceAllocations updateResources(LinkResourceRequest req, |
| 283 | LinkResourceAllocations oldAllocations) { |
| 284 | return null; |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public Iterable<LinkResourceAllocations> getAllocations() { |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 289 | return ImmutableSet.of( |
| 290 | new IntentTestsMocks.MockLinkResourceAllocations()); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public Iterable<LinkResourceAllocations> getAllocations(Link link) { |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 295 | return ImmutableSet.of( |
| 296 | new IntentTestsMocks.MockLinkResourceAllocations()); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public LinkResourceAllocations getAllocations(IntentId intentId) { |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 301 | return new IntentTestsMocks.MockLinkResourceAllocations(); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public Iterable<ResourceRequest> getAvailableResources(Link link) { |
| 306 | final List<ResourceRequest> result = new LinkedList<>(); |
| 307 | if (availableBandwidth > 0.0) { |
Ray Milkey | cf590df | 2015-02-23 17:43:24 -0800 | [diff] [blame] | 308 | result.add(new BandwidthResourceRequest( |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 309 | new BandwidthResource(Bandwidth.bps(availableBandwidth)))); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 310 | } |
| 311 | if (availableLambda > 0) { |
| 312 | result.add(new LambdaResourceRequest()); |
| 313 | } |
| 314 | return result; |
| 315 | } |
| 316 | |
| 317 | @Override |
weibit | 00c94f5 | 2014-11-16 07:09:05 -0800 | [diff] [blame] | 318 | public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 319 | return null; |
| 320 | } |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 321 | |
| 322 | @Override |
| 323 | public void addListener(LinkResourceListener listener) { |
| 324 | |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public void removeListener(LinkResourceListener listener) { |
| 329 | |
| 330 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 333 | private static final IntentTestsMocks.MockSelector SELECTOR = |
| 334 | new IntentTestsMocks.MockSelector(); |
| 335 | private static final IntentTestsMocks.MockTreatment TREATMENT = |
| 336 | new IntentTestsMocks.MockTreatment(); |
| 337 | |
| 338 | public static class MockFlowRule implements FlowRule { |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 339 | static int nextId = 0; |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 340 | |
| 341 | int priority; |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 342 | int tableId; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 343 | long timestamp; |
| 344 | int id; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 345 | FlowRuleExtPayLoad payLoad; |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 346 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 347 | public MockFlowRule(int priority) { |
| 348 | this.priority = priority; |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 349 | this.tableId = 0; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 350 | this.timestamp = System.currentTimeMillis(); |
| 351 | this.id = nextId++; |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 352 | this.payLoad = null; |
| 353 | } |
| 354 | |
| 355 | public MockFlowRule(int priority, FlowRuleExtPayLoad payLoad) { |
| 356 | this.priority = priority; |
| 357 | this.timestamp = System.currentTimeMillis(); |
| 358 | this.id = nextId++; |
| 359 | this.payLoad = payLoad; |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public FlowId id() { |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 364 | return FlowId.valueOf(id); |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public short appId() { |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | @Override |
Sho SHIMIZU | 75a5bd9 | 2014-11-25 11:22:56 -0800 | [diff] [blame] | 373 | public GroupId groupId() { |
| 374 | return new DefaultGroupId(0); |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | @Override |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 378 | public int priority() { |
| 379 | return priority; |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public DeviceId deviceId() { |
| 384 | return did("1"); |
| 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public TrafficSelector selector() { |
| 389 | return SELECTOR; |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public TrafficTreatment treatment() { |
| 394 | return TREATMENT; |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public int timeout() { |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public boolean isPermanent() { |
| 404 | return false; |
| 405 | } |
| 406 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 407 | @Override |
| 408 | public int hashCode() { |
| 409 | return Objects.hash(priority); |
| 410 | } |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 411 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 412 | @Override |
| 413 | public boolean equals(Object obj) { |
| 414 | if (this == obj) { |
| 415 | return true; |
| 416 | } |
| 417 | if (obj == null || getClass() != obj.getClass()) { |
| 418 | return false; |
| 419 | } |
| 420 | final MockFlowRule other = (MockFlowRule) obj; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 421 | return Objects.equals(this.timestamp, other.timestamp) && |
| 422 | this.id == other.id; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 423 | } |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 424 | |
| 425 | @Override |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 426 | public int tableId() { |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 427 | return tableId; |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 428 | } |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 429 | |
| 430 | @Override |
| 431 | public FlowRuleExtPayLoad payLoad() { |
| 432 | return payLoad; |
| 433 | } |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 436 | public static class MockIntent extends Intent { |
| 437 | private static AtomicLong counter = new AtomicLong(0); |
| 438 | |
| 439 | private final Long number; |
| 440 | |
| 441 | public MockIntent(Long number) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 442 | super(NetTestTools.APP_ID, null, Collections.emptyList(), |
| 443 | Intent.DEFAULT_INTENT_PRIORITY); |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 444 | this.number = number; |
| 445 | } |
| 446 | |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 447 | public MockIntent(Long number, Collection<NetworkResource> resources) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 448 | super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY); |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 449 | this.number = number; |
| 450 | } |
| 451 | |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 452 | public Long number() { |
| 453 | return number; |
| 454 | } |
| 455 | |
| 456 | public static Long nextId() { |
| 457 | return counter.getAndIncrement(); |
| 458 | } |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 459 | |
| 460 | @Override |
| 461 | public String toString() { |
| 462 | return MoreObjects.toStringHelper(getClass()) |
| 463 | .add("id", id()) |
| 464 | .add("appId", appId()) |
| 465 | .toString(); |
| 466 | } |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | public static class MockTimestamp implements Timestamp { |
| 470 | final int value; |
| 471 | |
| 472 | public MockTimestamp(int value) { |
| 473 | this.value = value; |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public int compareTo(Timestamp o) { |
| 478 | if (!(o instanceof MockTimestamp)) { |
| 479 | return -1; |
| 480 | } |
| 481 | MockTimestamp that = (MockTimestamp) o; |
Jonathan Hart | 72175c2 | 2015-03-24 18:55:58 -0700 | [diff] [blame] | 482 | return this.value - that.value; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 486 | } |