Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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.flow.impl; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.Lists; |
| 21 | import com.google.common.collect.Sets; |
| 22 | import com.google.common.util.concurrent.ListenableFuture; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 23 | import com.google.common.util.concurrent.MoreExecutors; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 24 | import org.junit.After; |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.core.ApplicationId; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 28 | import org.onosproject.core.CoreService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.core.DefaultApplicationId; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 30 | import org.onosproject.core.IdGenerator; |
| 31 | import org.onosproject.core.Version; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.event.impl.TestEventDispatcher; |
| 33 | import org.onosproject.net.DefaultDevice; |
| 34 | import org.onosproject.net.Device; |
| 35 | import org.onosproject.net.Device.Type; |
| 36 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.MastershipRole; |
| 38 | import org.onosproject.net.Port; |
| 39 | import org.onosproject.net.PortNumber; |
| 40 | import org.onosproject.net.device.DeviceListener; |
| 41 | import org.onosproject.net.device.DeviceServiceAdapter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 42 | import org.onosproject.net.flow.CompletedBatchOperation; |
| 43 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 44 | import org.onosproject.net.flow.DefaultFlowRule; |
| 45 | import org.onosproject.net.flow.FlowEntry; |
| 46 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
| 47 | import org.onosproject.net.flow.FlowRule; |
| 48 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
| 49 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 50 | import org.onosproject.net.flow.FlowRuleEvent; |
| 51 | import org.onosproject.net.flow.FlowRuleListener; |
| 52 | import org.onosproject.net.flow.FlowRuleProvider; |
| 53 | import org.onosproject.net.flow.FlowRuleProviderRegistry; |
| 54 | import org.onosproject.net.flow.FlowRuleProviderService; |
| 55 | import org.onosproject.net.flow.FlowRuleService; |
| 56 | import org.onosproject.net.flow.StoredFlowEntry; |
| 57 | import org.onosproject.net.flow.TrafficSelector; |
| 58 | import org.onosproject.net.flow.TrafficTreatment; |
| 59 | import org.onosproject.net.flow.criteria.Criterion; |
| 60 | import org.onosproject.net.flow.instructions.Instruction; |
| 61 | import org.onosproject.net.provider.AbstractProvider; |
| 62 | import org.onosproject.net.provider.ProviderId; |
| 63 | import org.onosproject.store.trivial.impl.SimpleFlowRuleStore; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 64 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
| 66 | import java.util.Arrays; |
| 67 | import java.util.Collections; |
| 68 | import java.util.HashMap; |
| 69 | import java.util.List; |
| 70 | import java.util.Map; |
| 71 | import java.util.Set; |
| 72 | import java.util.concurrent.ExecutionException; |
| 73 | import java.util.concurrent.Executor; |
| 74 | import java.util.concurrent.Future; |
| 75 | import java.util.concurrent.TimeUnit; |
| 76 | import java.util.concurrent.TimeoutException; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 77 | import java.util.concurrent.atomic.AtomicLong; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 78 | |
| 79 | import static org.junit.Assert.*; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 80 | import static org.onosproject.net.flow.FlowRuleEvent.Type.*; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 81 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 82 | /** |
| 83 | * Test codifying the flow rule service & flow rule provider service contracts. |
| 84 | */ |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 85 | public class FlowRuleManagerTest { |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 86 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 87 | |
tom | f6ab215 | 2014-09-18 12:08:29 -0700 | [diff] [blame] | 88 | private static final ProviderId PID = new ProviderId("of", "foo"); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 89 | private static final DeviceId DID = DeviceId.deviceId("of:001"); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 90 | private static final int TIMEOUT = 10; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 91 | private static final Device DEV = new DefaultDevice( |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 92 | PID, DID, Type.SWITCH, "", "", "", "", null); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 93 | |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 94 | private FlowRuleManager mgr; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 95 | |
| 96 | protected FlowRuleService service; |
| 97 | protected FlowRuleProviderRegistry registry; |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 98 | protected FlowRuleProviderService providerService; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 99 | protected TestProvider provider; |
| 100 | protected TestListener listener = new TestListener(); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 101 | private ApplicationId appId; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 102 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 103 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 104 | @Before |
| 105 | public void setUp() { |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 106 | mgr = new FlowRuleManager(); |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 107 | mgr.store = new SimpleFlowRuleStore(); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 108 | mgr.eventDispatcher = new TestEventDispatcher(); |
| 109 | mgr.deviceService = new TestDeviceService(); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 110 | mgr.coreService = new TestCoreService(); |
| 111 | mgr.operationsService = MoreExecutors.newDirectExecutorService(); |
| 112 | mgr.deviceInstallers = MoreExecutors.newDirectExecutorService(); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 113 | service = mgr; |
| 114 | registry = mgr; |
| 115 | |
| 116 | mgr.activate(); |
| 117 | mgr.addListener(listener); |
| 118 | provider = new TestProvider(PID); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 119 | providerService = registry.register(provider); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 120 | appId = new TestApplicationId(0, "FlowRuleManagerTest"); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 121 | assertTrue("provider should be registered", |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 122 | registry.getProviders().contains(provider.id())); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @After |
| 126 | public void tearDown() { |
| 127 | registry.unregister(provider); |
| 128 | assertFalse("provider should not be registered", |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 129 | registry.getProviders().contains(provider.id())); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 130 | service.removeListener(listener); |
| 131 | mgr.deactivate(); |
| 132 | mgr.eventDispatcher = null; |
| 133 | mgr.deviceService = null; |
| 134 | } |
| 135 | |
| 136 | private FlowRule flowRule(int tsval, int trval) { |
| 137 | TestSelector ts = new TestSelector(tsval); |
| 138 | TestTreatment tr = new TestTreatment(trval); |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 139 | return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT, false); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 140 | } |
| 141 | |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 142 | |
| 143 | private FlowRule addFlowRule(int hval) { |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 144 | FlowRule rule = flowRule(hval, hval); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 145 | service.applyFlowRules(rule); |
| 146 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 147 | assertNotNull("rule should be found", service.getFlowEntries(DID)); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 148 | return rule; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 151 | private void validateEvents(FlowRuleEvent.Type... events) { |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 152 | if (events == null) { |
| 153 | assertTrue("events generated", listener.events.isEmpty()); |
| 154 | } |
| 155 | |
| 156 | int i = 0; |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 157 | System.err.println("events :" + listener.events); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 158 | for (FlowRuleEvent e : listener.events) { |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 159 | assertEquals("unexpected event", events[i], e.type()); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 160 | i++; |
| 161 | } |
| 162 | |
| 163 | assertEquals("mispredicted number of events", |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 164 | events.length, listener.events.size()); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 165 | |
| 166 | listener.events.clear(); |
| 167 | } |
| 168 | |
| 169 | private int flowCount() { |
| 170 | return Sets.newHashSet(service.getFlowEntries(DID)).size(); |
| 171 | } |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 172 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 173 | @Test |
| 174 | public void getFlowEntries() { |
| 175 | assertTrue("store should be empty", |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 176 | Sets.newHashSet(service.getFlowEntries(DID)).isEmpty()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 177 | FlowRule f1 = addFlowRule(1); |
| 178 | FlowRule f2 = addFlowRule(2); |
| 179 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 180 | FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 181 | FlowEntry fe2 = new DefaultFlowEntry(f2); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 182 | assertEquals("2 rules should exist", 2, flowCount()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 183 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 184 | providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2)); |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 185 | validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, |
| 186 | RULE_ADDED, RULE_ADDED); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 187 | |
| 188 | addFlowRule(1); |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 189 | System.err.println("events :" + listener.events); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 190 | assertEquals("should still be 2 rules", 2, flowCount()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 191 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 192 | providerService.pushFlowMetrics(DID, ImmutableList.of(fe1)); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 193 | validateEvents(RULE_UPDATED); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 196 | private boolean validateState(Map<FlowRule, FlowEntryState> expected) { |
| 197 | Map<FlowRule, FlowEntryState> expectedToCheck = new HashMap<>(expected); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 198 | Iterable<FlowEntry> rules = service.getFlowEntries(DID); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 199 | for (FlowEntry f : rules) { |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 200 | assertTrue("Unexpected FlowRule " + f, expectedToCheck.containsKey(f)); |
| 201 | assertEquals("FlowEntry" + f, expectedToCheck.get(f), f.state()); |
| 202 | expectedToCheck.remove(f); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 203 | } |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 204 | assertEquals(Collections.emptySet(), expectedToCheck.entrySet()); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 205 | return true; |
| 206 | } |
| 207 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 208 | @Test |
| 209 | public void applyFlowRules() { |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 210 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 211 | FlowRule r1 = flowRule(1, 1); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 212 | FlowRule r2 = flowRule(2, 2); |
| 213 | FlowRule r3 = flowRule(3, 3); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 214 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 215 | assertTrue("store should be empty", |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 216 | Sets.newHashSet(service.getFlowEntries(DID)).isEmpty()); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 217 | mgr.applyFlowRules(r1, r2, r3); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 218 | assertEquals("3 rules should exist", 3, flowCount()); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 219 | assertTrue("Entries should be pending add.", |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 220 | validateState(ImmutableMap.of( |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 221 | r1, FlowEntryState.PENDING_ADD, |
| 222 | r2, FlowEntryState.PENDING_ADD, |
| 223 | r3, FlowEntryState.PENDING_ADD))); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Test |
| 227 | public void removeFlowRules() { |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 228 | FlowRule f1 = addFlowRule(1); |
| 229 | FlowRule f2 = addFlowRule(2); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 230 | FlowRule f3 = addFlowRule(3); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 231 | assertEquals("3 rules should exist", 3, flowCount()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 232 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 233 | FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 234 | FlowEntry fe2 = new DefaultFlowEntry(f2); |
| 235 | FlowEntry fe3 = new DefaultFlowEntry(f3); |
| 236 | providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2, fe3)); |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 237 | validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, |
| 238 | RULE_ADDED, RULE_ADDED, RULE_ADDED); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 239 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 240 | mgr.removeFlowRules(f1, f2); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 241 | //removing from north, so no events generated |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 242 | validateEvents(RULE_REMOVE_REQUESTED, RULE_REMOVE_REQUESTED); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 243 | assertEquals("3 rule should exist", 3, flowCount()); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 244 | assertTrue("Entries should be pending remove.", |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 245 | validateState(ImmutableMap.of( |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 246 | f1, FlowEntryState.PENDING_REMOVE, |
| 247 | f2, FlowEntryState.PENDING_REMOVE, |
| 248 | f3, FlowEntryState.ADDED))); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 249 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 250 | mgr.removeFlowRules(f1); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 251 | assertEquals("3 rule should still exist", 3, flowCount()); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Test |
| 255 | public void flowRemoved() { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 256 | |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 257 | FlowRule f1 = addFlowRule(1); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 258 | FlowRule f2 = addFlowRule(2); |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 259 | StoredFlowEntry fe1 = new DefaultFlowEntry(f1); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 260 | FlowEntry fe2 = new DefaultFlowEntry(f2); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 261 | |
| 262 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 263 | providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2)); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 264 | service.removeFlowRules(f1); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 265 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 266 | fe1.setState(FlowEntryState.REMOVED); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 267 | |
| 268 | |
| 269 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 270 | providerService.flowRemoved(fe1); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 271 | |
| 272 | |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 273 | validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, |
| 274 | RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 275 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 276 | providerService.flowRemoved(fe1); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 277 | validateEvents(); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 278 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 279 | FlowRule f3 = flowRule(3, 3); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 280 | FlowEntry fe3 = new DefaultFlowEntry(f3); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 281 | service.applyFlowRules(f3); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 282 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 283 | providerService.pushFlowMetrics(DID, Collections.singletonList(fe3)); |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 284 | validateEvents(RULE_ADD_REQUESTED, RULE_ADDED); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 285 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 286 | providerService.flowRemoved(fe3); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 287 | validateEvents(); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 288 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 289 | } |
| 290 | |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 291 | @Test |
| 292 | public void flowMetrics() { |
| 293 | FlowRule f1 = flowRule(1, 1); |
| 294 | FlowRule f2 = flowRule(2, 2); |
| 295 | FlowRule f3 = flowRule(3, 3); |
| 296 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 297 | mgr.applyFlowRules(f1, f2, f3); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 298 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 299 | FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 300 | FlowEntry fe2 = new DefaultFlowEntry(f2); |
| 301 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 302 | //FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); |
| 303 | //FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); |
| 304 | |
| 305 | providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2)); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 306 | |
| 307 | assertTrue("Entries should be added.", |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 308 | validateState(ImmutableMap.of( |
| 309 | f1, FlowEntryState.ADDED, |
| 310 | f2, FlowEntryState.ADDED, |
| 311 | f3, FlowEntryState.PENDING_ADD))); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 312 | |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 313 | validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, |
| 314 | RULE_ADDED, RULE_ADDED); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Test |
| 318 | public void extraneousFlow() { |
| 319 | FlowRule f1 = flowRule(1, 1); |
| 320 | FlowRule f2 = flowRule(2, 2); |
| 321 | FlowRule f3 = flowRule(3, 3); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 322 | mgr.applyFlowRules(f1, f2); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 323 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 324 | // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); |
| 325 | // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); |
| 326 | // FlowRule updatedF3 = flowRule(f3, FlowRuleState.ADDED); |
| 327 | FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 328 | FlowEntry fe2 = new DefaultFlowEntry(f2); |
| 329 | FlowEntry fe3 = new DefaultFlowEntry(f3); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 330 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 331 | |
| 332 | providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2, fe3)); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 333 | |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 334 | validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 335 | |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * Tests whether a rule that was marked for removal but no flowRemoved was received |
| 340 | * is indeed removed at the next stats update. |
| 341 | */ |
| 342 | @Test |
| 343 | public void flowMissingRemove() { |
| 344 | FlowRule f1 = flowRule(1, 1); |
| 345 | FlowRule f2 = flowRule(2, 2); |
| 346 | FlowRule f3 = flowRule(3, 3); |
| 347 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 348 | // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); |
| 349 | // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); |
| 350 | |
| 351 | FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 352 | FlowEntry fe2 = new DefaultFlowEntry(f2); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 353 | mgr.applyFlowRules(f1, f2, f3); |
| 354 | |
| 355 | mgr.removeFlowRules(f3); |
| 356 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 357 | providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2)); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 358 | |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 359 | validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, |
| 360 | RULE_REMOVE_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVED); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 361 | |
| 362 | } |
| 363 | |
| 364 | @Test |
| 365 | public void getByAppId() { |
| 366 | FlowRule f1 = flowRule(1, 1); |
| 367 | FlowRule f2 = flowRule(2, 2); |
| 368 | mgr.applyFlowRules(f1, f2); |
| 369 | |
| 370 | assertTrue("should have two rules", |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 371 | Lists.newLinkedList(mgr.getFlowRulesById(appId)).size() == 2); |
alshabib | bb42cad | 2014-09-25 11:43:05 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void removeByAppId() { |
| 376 | FlowRule f1 = flowRule(1, 1); |
| 377 | FlowRule f2 = flowRule(2, 2); |
| 378 | mgr.applyFlowRules(f1, f2); |
| 379 | |
| 380 | |
| 381 | mgr.removeFlowRulesById(appId); |
| 382 | |
| 383 | //only check that we are in pending remove. Events and actual remove state will |
| 384 | // be set by flowRemoved call. |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 385 | validateState(ImmutableMap.of( |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 386 | f1, FlowEntryState.PENDING_REMOVE, |
| 387 | f2, FlowEntryState.PENDING_REMOVE)); |
alshabib | bb8b128 | 2014-09-22 17:00:18 -0700 | [diff] [blame] | 388 | } |
| 389 | |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 390 | @Test |
| 391 | public void applyBatch() { |
| 392 | FlowRule f1 = flowRule(1, 1); |
| 393 | FlowRule f2 = flowRule(2, 2); |
| 394 | |
| 395 | |
| 396 | mgr.applyFlowRules(f1); |
| 397 | |
| 398 | FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 399 | providerService.pushFlowMetrics(DID, Collections.<FlowEntry>singletonList(fe1)); |
| 400 | |
| 401 | FlowRuleBatchEntry fbe1 = new FlowRuleBatchEntry( |
| 402 | FlowRuleBatchEntry.FlowRuleOperation.REMOVE, f1); |
| 403 | |
| 404 | FlowRuleBatchEntry fbe2 = new FlowRuleBatchEntry( |
| 405 | FlowRuleBatchEntry.FlowRuleOperation.ADD, f2); |
| 406 | |
| 407 | FlowRuleBatchOperation fbo = new FlowRuleBatchOperation( |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 408 | Lists.newArrayList(fbe1, fbe2), null, 0); |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 409 | Future<CompletedBatchOperation> future = mgr.applyBatch(fbo); |
| 410 | assertTrue("Entries in wrong state", |
Yuta HIGUCHI | 605347c | 2014-10-17 21:05:23 -0700 | [diff] [blame] | 411 | validateState(ImmutableMap.of( |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 412 | f1, FlowEntryState.PENDING_REMOVE, |
| 413 | f2, FlowEntryState.PENDING_ADD))); |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 414 | CompletedBatchOperation completed = null; |
| 415 | try { |
| 416 | completed = future.get(); |
| 417 | } catch (InterruptedException | ExecutionException e) { |
| 418 | fail("Unexpected exception: " + e); |
| 419 | } |
| 420 | if (!completed.isSuccess()) { |
| 421 | fail("Installation should be a success"); |
| 422 | } |
| 423 | |
| 424 | } |
| 425 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 426 | private static class TestListener implements FlowRuleListener { |
| 427 | final List<FlowRuleEvent> events = new ArrayList<>(); |
| 428 | |
| 429 | @Override |
| 430 | public void event(FlowRuleEvent event) { |
| 431 | events.add(event); |
| 432 | } |
| 433 | } |
| 434 | |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 435 | private static class TestDeviceService extends DeviceServiceAdapter { |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 436 | |
| 437 | @Override |
| 438 | public int getDeviceCount() { |
Madan Jampani | 6a45616 | 2014-10-24 11:36:17 -0700 | [diff] [blame] | 439 | return 1; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public Iterable<Device> getDevices() { |
Madan Jampani | 6a45616 | 2014-10-24 11:36:17 -0700 | [diff] [blame] | 444 | return Arrays.asList(DEV); |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | @Override |
| 448 | public Device getDevice(DeviceId deviceId) { |
| 449 | return DEV; |
| 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public MastershipRole getRole(DeviceId deviceId) { |
| 454 | return null; |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public List<Port> getPorts(DeviceId deviceId) { |
| 459 | return null; |
| 460 | } |
| 461 | |
| 462 | @Override |
| 463 | public Port getPort(DeviceId deviceId, PortNumber portNumber) { |
| 464 | return null; |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public boolean isAvailable(DeviceId deviceId) { |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | @Override |
| 473 | public void addListener(DeviceListener listener) { |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public void removeListener(DeviceListener listener) { |
| 478 | } |
| 479 | |
| 480 | } |
| 481 | |
| 482 | private class TestProvider extends AbstractProvider implements FlowRuleProvider { |
| 483 | |
| 484 | protected TestProvider(ProviderId id) { |
| 485 | super(PID); |
| 486 | } |
| 487 | |
| 488 | @Override |
| 489 | public void applyFlowRule(FlowRule... flowRules) { |
| 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public void removeFlowRule(FlowRule... flowRules) { |
| 494 | } |
| 495 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 496 | @Override |
| 497 | public void removeRulesById(ApplicationId id, FlowRule... flowRules) { |
| 498 | } |
| 499 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 500 | @Override |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 501 | public void executeBatch(FlowRuleBatchOperation batch) { |
| 502 | // TODO: need to call batchOperationComplete |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 503 | } |
| 504 | |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 505 | private class TestInstallationFuture |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 506 | implements ListenableFuture<CompletedBatchOperation> { |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 507 | |
| 508 | @Override |
| 509 | public boolean cancel(boolean mayInterruptIfRunning) { |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 510 | return false; |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | @Override |
| 514 | public boolean isCancelled() { |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 515 | return false; |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public boolean isDone() { |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 520 | return true; |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public CompletedBatchOperation get() |
| 525 | throws InterruptedException, ExecutionException { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 526 | return new CompletedBatchOperation(true, Collections.<FlowRule>emptySet(), null); |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public CompletedBatchOperation get(long timeout, TimeUnit unit) |
| 531 | throws InterruptedException, |
| 532 | ExecutionException, TimeoutException { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 533 | return new CompletedBatchOperation(true, Collections.<FlowRule>emptySet(), null); |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 534 | } |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 535 | |
| 536 | @Override |
| 537 | public void addListener(Runnable task, Executor executor) { |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 538 | if (isDone()) { |
| 539 | executor.execute(task); |
| 540 | } |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 541 | } |
alshabib | cf36991 | 2014-10-13 14:16:42 -0700 | [diff] [blame] | 542 | } |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 543 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | private class TestSelector implements TrafficSelector { |
| 547 | |
| 548 | //for controlling hashcode uniqueness; |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 549 | private final int testval; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 550 | |
| 551 | public TestSelector(int val) { |
| 552 | testval = val; |
| 553 | } |
| 554 | |
| 555 | @Override |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 556 | public Set<Criterion> criteria() { |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 557 | return null; |
| 558 | } |
| 559 | |
| 560 | @Override |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 561 | public Criterion getCriterion( |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 562 | org.onosproject.net.flow.criteria.Criterion.Type type) { |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 563 | return null; |
| 564 | } |
| 565 | |
| 566 | @Override |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 567 | public int hashCode() { |
| 568 | return testval; |
| 569 | } |
| 570 | |
| 571 | @Override |
| 572 | public boolean equals(Object o) { |
| 573 | if (o instanceof TestSelector) { |
| 574 | return this.testval == ((TestSelector) o).testval; |
| 575 | } |
| 576 | return false; |
| 577 | } |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 578 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | private class TestTreatment implements TrafficTreatment { |
| 582 | |
| 583 | //for controlling hashcode uniqueness; |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 584 | private final int testval; |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 585 | |
| 586 | public TestTreatment(int val) { |
| 587 | testval = val; |
| 588 | } |
| 589 | |
| 590 | @Override |
| 591 | public List<Instruction> instructions() { |
| 592 | return null; |
| 593 | } |
| 594 | |
| 595 | @Override |
| 596 | public int hashCode() { |
| 597 | return testval; |
| 598 | } |
| 599 | |
| 600 | @Override |
| 601 | public boolean equals(Object o) { |
| 602 | if (o instanceof TestTreatment) { |
| 603 | return this.testval == ((TestTreatment) o).testval; |
| 604 | } |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | } |
| 609 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 610 | public class TestApplicationId extends DefaultApplicationId { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 611 | public TestApplicationId(int id, String name) { |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 612 | super(id, name); |
| 613 | } |
| 614 | } |
| 615 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 616 | private class TestCoreService implements CoreService { |
| 617 | @Override |
| 618 | public Version version() { |
| 619 | return null; |
| 620 | } |
| 621 | |
| 622 | @Override |
| 623 | public Set<ApplicationId> getAppIds() { |
| 624 | return null; |
| 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public ApplicationId getAppId(Short id) { |
| 629 | return null; |
| 630 | } |
| 631 | |
| 632 | @Override |
| 633 | public ApplicationId registerApplication(String identifier) { |
| 634 | return null; |
| 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public IdGenerator getIdGenerator(String topic) { |
| 639 | return new IdGenerator() { |
| 640 | private AtomicLong counter = new AtomicLong(0); |
| 641 | @Override |
| 642 | public long getNewId() { |
| 643 | return counter.getAndIncrement(); |
| 644 | } |
| 645 | }; |
| 646 | } |
| 647 | } |
| 648 | |
Ayaka Koshibe | b55524f | 2014-09-18 09:59:24 -0700 | [diff] [blame] | 649 | } |