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