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