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