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