blob: fa93335586e3a2aada4659649eb31e8a920d2c43 [file] [log] [blame]
yoonseon6b972c32016-12-06 16:45:03 -08001/*
2 * Copyright 2016-present 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 */
16
17package org.onosproject.incubator.net.virtual.impl;
18
yoonseonbd8a93d2016-12-07 15:51:21 -080019import com.google.common.collect.ImmutableList;
20import com.google.common.collect.ImmutableMap;
yoonseon6b972c32016-12-06 16:45:03 -080021import com.google.common.collect.Lists;
22import com.google.common.collect.Sets;
23import com.google.common.util.concurrent.MoreExecutors;
24import org.junit.After;
25import org.junit.Before;
26import org.junit.Test;
27import org.onlab.junit.TestUtils;
28import org.onlab.osgi.ServiceDirectory;
29import org.onlab.osgi.TestServiceDirectory;
yoonseon6b972c32016-12-06 16:45:03 -080030import org.onosproject.TestApplicationId;
31import org.onosproject.common.event.impl.TestEventDispatcher;
32import org.onosproject.core.ApplicationId;
33import org.onosproject.core.CoreService;
yoonseonbd8a93d2016-12-07 15:51:21 -080034import org.onosproject.event.EventDeliveryService;
yoonseon6b972c32016-12-06 16:45:03 -080035import org.onosproject.incubator.net.virtual.NetworkId;
yoonseon6b972c32016-12-06 16:45:03 -080036import org.onosproject.incubator.net.virtual.VirtualNetwork;
37import org.onosproject.incubator.net.virtual.VirtualNetworkFlowRuleStore;
38import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
yoonseonbd8a93d2016-12-07 15:51:21 -080039import org.onosproject.incubator.net.virtual.event.VirtualEvent;
40import org.onosproject.incubator.net.virtual.event.VirtualListenerRegistryManager;
yoonseon6b972c32016-12-06 16:45:03 -080041import org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager;
42import org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider;
43import org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProvider;
yoonseonbd8a93d2016-12-07 15:51:21 -080044import org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProviderService;
yoonseon6b972c32016-12-06 16:45:03 -080045import org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService;
46import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
yoonseonbd8a93d2016-12-07 15:51:21 -080047import org.onosproject.incubator.store.virtual.impl.SimpleVirtualFlowRuleStore;
yoonseon6b972c32016-12-06 16:45:03 -080048import org.onosproject.net.DeviceId;
yoonseon6b972c32016-12-06 16:45:03 -080049import org.onosproject.net.NetTestTools;
yoonseon6b972c32016-12-06 16:45:03 -080050import org.onosproject.net.flow.DefaultFlowEntry;
51import org.onosproject.net.flow.DefaultFlowRule;
52import org.onosproject.net.flow.FlowEntry;
yoonseon6b972c32016-12-06 16:45:03 -080053import org.onosproject.net.flow.FlowRule;
yoonseon6b972c32016-12-06 16:45:03 -080054import org.onosproject.net.flow.FlowRuleBatchOperation;
55import org.onosproject.net.flow.FlowRuleEvent;
56import org.onosproject.net.flow.FlowRuleListener;
57import org.onosproject.net.flow.FlowRuleService;
yoonseon6b972c32016-12-06 16:45:03 -080058import org.onosproject.net.flow.StoredFlowEntry;
yoonseon6b972c32016-12-06 16:45:03 -080059import org.onosproject.net.flow.TrafficSelector;
60import org.onosproject.net.flow.TrafficTreatment;
61import org.onosproject.net.flow.criteria.Criterion;
62import org.onosproject.net.flow.instructions.Instruction;
63import org.onosproject.net.flow.instructions.Instructions;
64import org.onosproject.net.intent.FakeIntentManager;
65import org.onosproject.net.intent.TestableIntentService;
66import org.onosproject.net.provider.ProviderId;
67import org.onosproject.store.service.TestStorageService;
68
69import java.util.ArrayList;
70import java.util.Collections;
yoonseonbd8a93d2016-12-07 15:51:21 -080071import java.util.HashMap;
yoonseon6b972c32016-12-06 16:45:03 -080072import java.util.List;
yoonseonbd8a93d2016-12-07 15:51:21 -080073import java.util.Map;
yoonseon6b972c32016-12-06 16:45:03 -080074import java.util.Set;
yoonseon6b972c32016-12-06 16:45:03 -080075
76import static org.junit.Assert.*;
yoonseonbd8a93d2016-12-07 15:51:21 -080077import static org.onosproject.net.flow.FlowRuleEvent.Type.*;
yoonseon6b972c32016-12-06 16:45:03 -080078
yoonseon322c9c32016-12-07 16:47:02 -080079public class VirtualNetworkFlowRuleManagerTest extends VirtualNetworkTestUtil {
yoonseon6b972c32016-12-06 16:45:03 -080080 private static final int TIMEOUT = 10;
81
82 private VirtualNetworkManager manager;
83 private DistributedVirtualNetworkStore virtualNetworkManagerStore;
84 private TestableIntentService intentService = new FakeIntentManager();
85 private ServiceDirectory testDirectory;
86 private VirtualNetworkFlowRuleStore flowRuleStore;
yoonseonbd8a93d2016-12-07 15:51:21 -080087 private VirtualProviderManager providerRegistryService;
88
89 private EventDeliveryService eventDeliveryService;
90 VirtualListenerRegistryManager listenerRegistryManager =
91 VirtualListenerRegistryManager.getInstance();
yoonseon6b972c32016-12-06 16:45:03 -080092
93 private VirtualNetworkFlowRuleManager vnetFlowRuleService1;
94 private VirtualNetworkFlowRuleManager vnetFlowRuleService2;
95
96 private VirtualFlowRuleProvider provider = new TestProvider();
yoonseonbd8a93d2016-12-07 15:51:21 -080097 private VirtualFlowRuleProviderService providerService1;
98 private VirtualFlowRuleProviderService providerService2;
yoonseon6b972c32016-12-06 16:45:03 -080099
100 protected TestFlowRuleListener listener1 = new TestFlowRuleListener();
101 protected TestFlowRuleListener listener2 = new TestFlowRuleListener();
102
yoonseon6b972c32016-12-06 16:45:03 -0800103 private VirtualNetwork vnet1;
104 private VirtualNetwork vnet2;
105
106 private ApplicationId appId;
107
yoonseon6b972c32016-12-06 16:45:03 -0800108 @Before
109 public void setUp() throws Exception {
110 virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
111
112 CoreService coreService = new TestCoreService();
yoonseonc6a69272017-01-12 18:22:20 -0800113 TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
yoonseon6b972c32016-12-06 16:45:03 -0800114 TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
115 virtualNetworkManagerStore.activate();
116
yoonseonbd8a93d2016-12-07 15:51:21 -0800117 flowRuleStore = new SimpleVirtualFlowRuleStore();
yoonseon6b972c32016-12-06 16:45:03 -0800118
119 providerRegistryService = new VirtualProviderManager();
120 providerRegistryService.registerProvider(provider);
121
122 manager = new VirtualNetworkManager();
123 manager.store = virtualNetworkManagerStore;
124 manager.intentService = intentService;
125 TestUtils.setField(manager, "coreService", coreService);
yoonseonbd8a93d2016-12-07 15:51:21 -0800126
127 eventDeliveryService = new TestEventDispatcher();
128 NetTestTools.injectEventDispatcher(manager, eventDeliveryService);
129 eventDeliveryService.addSink(VirtualEvent.class, listenerRegistryManager);
yoonseon6b972c32016-12-06 16:45:03 -0800130
131 appId = new TestApplicationId("FlowRuleManagerTest");
132
yoonseon6b972c32016-12-06 16:45:03 -0800133 testDirectory = new TestServiceDirectory()
134 .add(VirtualNetworkStore.class, virtualNetworkManagerStore)
135 .add(CoreService.class, coreService)
136 .add(VirtualProviderRegistryService.class, providerRegistryService)
yoonseonbd8a93d2016-12-07 15:51:21 -0800137 .add(EventDeliveryService.class, eventDeliveryService)
yoonseon6b972c32016-12-06 16:45:03 -0800138 .add(VirtualNetworkFlowRuleStore.class, flowRuleStore);
yoonseonc6a69272017-01-12 18:22:20 -0800139 TestUtils.setField(manager, "serviceDirectory", testDirectory);
yoonseon6b972c32016-12-06 16:45:03 -0800140
yoonseonc6a69272017-01-12 18:22:20 -0800141 manager.activate();
yoonseon6b972c32016-12-06 16:45:03 -0800142
yoonseon322c9c32016-12-07 16:47:02 -0800143 vnet1 = setupVirtualNetworkTopology(manager, TID1);
144 vnet2 = setupVirtualNetworkTopology(manager, TID2);
yoonseon6b972c32016-12-06 16:45:03 -0800145
yoonseonc6a69272017-01-12 18:22:20 -0800146 vnetFlowRuleService1 = new VirtualNetworkFlowRuleManager(manager, vnet1.id());
147 vnetFlowRuleService2 = new VirtualNetworkFlowRuleManager(manager, vnet2.id());
yoonseon6b972c32016-12-06 16:45:03 -0800148 vnetFlowRuleService1.addListener(listener1);
yoonseonbd8a93d2016-12-07 15:51:21 -0800149 vnetFlowRuleService2.addListener(listener2);
yoonseon6b972c32016-12-06 16:45:03 -0800150
151 vnetFlowRuleService1.operationsService = MoreExecutors.newDirectExecutorService();
152 vnetFlowRuleService2.operationsService = MoreExecutors.newDirectExecutorService();
153 vnetFlowRuleService1.deviceInstallers = MoreExecutors.newDirectExecutorService();
154 vnetFlowRuleService2.deviceInstallers = MoreExecutors.newDirectExecutorService();
yoonseonbd8a93d2016-12-07 15:51:21 -0800155
156 providerService1 = (VirtualFlowRuleProviderService)
Yoonseon Hanc70b4e02016-10-20 15:24:33 -0700157 providerRegistryService.getProviderService(vnet1.id(), VirtualFlowRuleProvider.class);
yoonseonbd8a93d2016-12-07 15:51:21 -0800158 providerService2 = (VirtualFlowRuleProviderService)
Yoonseon Hanc70b4e02016-10-20 15:24:33 -0700159 providerRegistryService.getProviderService(vnet2.id(), VirtualFlowRuleProvider.class);
yoonseon6b972c32016-12-06 16:45:03 -0800160 }
161
162 @After
163 public void tearDown() {
164 manager.deactivate();
165 virtualNetworkManagerStore.deactivate();
166 }
167
yoonseon6b972c32016-12-06 16:45:03 -0800168 private FlowRule flowRule(int tsval, int trval) {
yoonseon322c9c32016-12-07 16:47:02 -0800169 return flowRule(VDID1, tsval, trval);
yoonseon6b972c32016-12-06 16:45:03 -0800170 }
171
172 private FlowRule flowRule(DeviceId did, int tsval, int trval) {
173 TestSelector ts = new TestSelector(tsval);
174 TestTreatment tr = new TestTreatment(trval);
175 return DefaultFlowRule.builder()
176 .forDevice(did)
177 .withSelector(ts)
178 .withTreatment(tr)
179 .withPriority(10)
180 .fromApp(appId)
181 .makeTemporary(TIMEOUT)
182 .build();
183 }
184
185 private FlowRule addFlowRule(int hval) {
186 FlowRule rule = flowRule(hval, hval);
187 vnetFlowRuleService1.applyFlowRules(rule);
188
yoonseon322c9c32016-12-07 16:47:02 -0800189 assertNotNull("rule should be found", vnetFlowRuleService1.getFlowEntries(VDID1));
yoonseon6b972c32016-12-06 16:45:03 -0800190 return rule;
191 }
192
193 private int flowCount(FlowRuleService service) {
194 List<FlowEntry> entries = Lists.newArrayList();
yoonseon322c9c32016-12-07 16:47:02 -0800195 service.getFlowEntries(VDID1).forEach(entries::add);
yoonseon6b972c32016-12-06 16:45:03 -0800196 return entries.size();
197 }
198
199 @Test
200 public void getFlowEntries() {
201 assertTrue("store should be empty",
yoonseon322c9c32016-12-07 16:47:02 -0800202 Sets.newHashSet(vnetFlowRuleService1.getFlowEntries(VDID1)).isEmpty());
yoonseon6b972c32016-12-06 16:45:03 -0800203 assertTrue("store should be empty",
yoonseon322c9c32016-12-07 16:47:02 -0800204 Sets.newHashSet(vnetFlowRuleService2.getFlowEntries(VDID1)).isEmpty());
yoonseonbd8a93d2016-12-07 15:51:21 -0800205
yoonseon6b972c32016-12-06 16:45:03 -0800206 FlowRule f1 = addFlowRule(1);
207 FlowRule f2 = addFlowRule(2);
208
209 FlowEntry fe1 = new DefaultFlowEntry(f1);
210 FlowEntry fe2 = new DefaultFlowEntry(f2);
211
212 assertEquals("2 rules should exist", 2, flowCount(vnetFlowRuleService1));
213 assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
yoonseonbd8a93d2016-12-07 15:51:21 -0800214
yoonseon322c9c32016-12-07 16:47:02 -0800215 providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
yoonseonbd8a93d2016-12-07 15:51:21 -0800216 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
217 RULE_ADDED, RULE_ADDED);
218
219 addFlowRule(1);
220 assertEquals("should still be 2 rules", 2, flowCount(vnetFlowRuleService1));
221 System.err.println("events :" + listener1.events);
222 assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
223
yoonseon322c9c32016-12-07 16:47:02 -0800224 providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1));
yoonseonbd8a93d2016-12-07 15:51:21 -0800225 validateEvents(listener1, RULE_UPDATED, RULE_UPDATED);
226 }
227
228 @Test
229 public void applyFlowRules() {
230 FlowRule r1 = flowRule(1, 1);
231 FlowRule r2 = flowRule(2, 2);
232 FlowRule r3 = flowRule(3, 3);
233
234 assertTrue("store should be empty",
235 Sets.newHashSet(vnetFlowRuleService1.getFlowEntries(DID1)).isEmpty());
236 vnetFlowRuleService1.applyFlowRules(r1, r2, r3);
237 assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
238 assertTrue("Entries should be pending add.",
239 validateState(ImmutableMap.of(
240 r1, FlowEntry.FlowEntryState.PENDING_ADD,
241 r2, FlowEntry.FlowEntryState.PENDING_ADD,
242 r3, FlowEntry.FlowEntryState.PENDING_ADD)));
243 }
244
245 @Test
246 public void purgeFlowRules() {
247 FlowRule f1 = addFlowRule(1);
248 FlowRule f2 = addFlowRule(2);
249 FlowRule f3 = addFlowRule(3);
250 assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
251 FlowEntry fe1 = new DefaultFlowEntry(f1);
252 FlowEntry fe2 = new DefaultFlowEntry(f2);
253 FlowEntry fe3 = new DefaultFlowEntry(f3);
yoonseon322c9c32016-12-07 16:47:02 -0800254 providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2, fe3));
yoonseonbd8a93d2016-12-07 15:51:21 -0800255 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
256 RULE_ADDED, RULE_ADDED, RULE_ADDED);
yoonseon322c9c32016-12-07 16:47:02 -0800257 vnetFlowRuleService1.purgeFlowRules(VDID1);
yoonseonbd8a93d2016-12-07 15:51:21 -0800258 assertEquals("0 rule should exist", 0, flowCount(vnetFlowRuleService1));
259 }
260
261 @Test
262 public void removeFlowRules() {
263 FlowRule f1 = addFlowRule(1);
264 FlowRule f2 = addFlowRule(2);
265 FlowRule f3 = addFlowRule(3);
266 assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
267
268 FlowEntry fe1 = new DefaultFlowEntry(f1);
269 FlowEntry fe2 = new DefaultFlowEntry(f2);
270 FlowEntry fe3 = new DefaultFlowEntry(f3);
yoonseon322c9c32016-12-07 16:47:02 -0800271 providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2, fe3));
yoonseonbd8a93d2016-12-07 15:51:21 -0800272 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
273 RULE_ADDED, RULE_ADDED, RULE_ADDED);
274
275 vnetFlowRuleService1.removeFlowRules(f1, f2);
276 //removing from north, so no events generated
277 validateEvents(listener1, RULE_REMOVE_REQUESTED, RULE_REMOVE_REQUESTED);
278 assertEquals("3 rule should exist", 3, flowCount(vnetFlowRuleService1));
279 assertTrue("Entries should be pending remove.",
280 validateState(ImmutableMap.of(
281 f1, FlowEntry.FlowEntryState.PENDING_REMOVE,
282 f2, FlowEntry.FlowEntryState.PENDING_REMOVE,
283 f3, FlowEntry.FlowEntryState.ADDED)));
284
285 vnetFlowRuleService1.removeFlowRules(f1);
286 assertEquals("3 rule should still exist", 3, flowCount(vnetFlowRuleService1));
287 }
288
289 @Test
290 public void flowRemoved() {
291 FlowRule f1 = addFlowRule(1);
292 FlowRule f2 = addFlowRule(2);
293 StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
294 FlowEntry fe2 = new DefaultFlowEntry(f2);
295
yoonseon322c9c32016-12-07 16:47:02 -0800296 providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
yoonseonbd8a93d2016-12-07 15:51:21 -0800297 vnetFlowRuleService1.removeFlowRules(f1);
298
299 //FIXME modification of "stored" flow entry outside of store
300 fe1.setState(FlowEntry.FlowEntryState.REMOVED);
301
302 providerService1.flowRemoved(fe1);
303
304 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED,
305 RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
306
307 providerService1.flowRemoved(fe1);
308 validateEvents(listener1);
309
310 FlowRule f3 = flowRule(3, 3);
311 FlowEntry fe3 = new DefaultFlowEntry(f3);
312 vnetFlowRuleService1.applyFlowRules(f3);
313
yoonseon322c9c32016-12-07 16:47:02 -0800314 providerService1.pushFlowMetrics(VDID1, Collections.singletonList(fe3));
yoonseonbd8a93d2016-12-07 15:51:21 -0800315 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
316
317 providerService1.flowRemoved(fe3);
318 validateEvents(listener1);
319 }
320
321 @Test
322 public void extraneousFlow() {
323 FlowRule f1 = flowRule(1, 1);
324 FlowRule f2 = flowRule(2, 2);
325 FlowRule f3 = flowRule(3, 3);
326 vnetFlowRuleService1.applyFlowRules(f1, f2);
327
328 FlowEntry fe1 = new DefaultFlowEntry(f1);
329 FlowEntry fe2 = new DefaultFlowEntry(f2);
330 FlowEntry fe3 = new DefaultFlowEntry(f3);
331
332
yoonseon322c9c32016-12-07 16:47:02 -0800333 providerService1.pushFlowMetrics(VDID1, Lists.newArrayList(fe1, fe2, fe3));
yoonseonbd8a93d2016-12-07 15:51:21 -0800334
335 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
336 RULE_ADDED, RULE_ADDED);
337 }
338
339 /*
340 * Tests whether a rule that was marked for removal but no flowRemoved was received
341 * is indeed removed at the next stats update.
342 */
343 @Test
344 public void flowMissingRemove() {
345 FlowRule f1 = flowRule(1, 1);
346 FlowRule f2 = flowRule(2, 2);
347 FlowRule f3 = flowRule(3, 3);
348
349 FlowEntry fe1 = new DefaultFlowEntry(f1);
350 FlowEntry fe2 = new DefaultFlowEntry(f2);
351 vnetFlowRuleService1.applyFlowRules(f1, f2, f3);
352
353 vnetFlowRuleService1.removeFlowRules(f3);
354
yoonseon322c9c32016-12-07 16:47:02 -0800355 providerService1.pushFlowMetrics(VDID1, Lists.newArrayList(fe1, fe2));
yoonseonbd8a93d2016-12-07 15:51:21 -0800356
357 validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
358 RULE_REMOVE_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVED);
359 }
360
361 @Test
362 public void removeByAppId() {
363 FlowRule f1 = flowRule(1, 1);
364 FlowRule f2 = flowRule(2, 2);
365 vnetFlowRuleService1.applyFlowRules(f1, f2);
366
367 vnetFlowRuleService1.removeFlowRulesById(appId);
368
369 //only check that we are in pending remove. Events and actual remove state will
370 // be set by flowRemoved call.
371 validateState(ImmutableMap.of(
372 f1, FlowEntry.FlowEntryState.PENDING_REMOVE,
373 f2, FlowEntry.FlowEntryState.PENDING_REMOVE));
374 }
375
376 //TODO:Tests for fallback
377
378 private boolean validateState(Map<FlowRule, FlowEntry.FlowEntryState> expected) {
379 Map<FlowRule, FlowEntry.FlowEntryState> expectedToCheck = new HashMap<>(expected);
yoonseon322c9c32016-12-07 16:47:02 -0800380 Iterable<FlowEntry> rules = vnetFlowRuleService1.getFlowEntries(VDID1);
yoonseonbd8a93d2016-12-07 15:51:21 -0800381 for (FlowEntry f : rules) {
382 assertTrue("Unexpected FlowRule " + f, expectedToCheck.containsKey(f));
383 assertEquals("FlowEntry" + f, expectedToCheck.get(f), f.state());
384 expectedToCheck.remove(f);
385 }
386 assertEquals(Collections.emptySet(), expectedToCheck.entrySet());
387 return true;
yoonseon6b972c32016-12-06 16:45:03 -0800388 }
389
390 private class TestSelector implements TrafficSelector {
391
392 //for controlling hashcode uniqueness;
393 private final int testval;
394
395 public TestSelector(int val) {
396 testval = val;
397 }
398
399 @Override
400 public Set<Criterion> criteria() {
401 return Collections.emptySet();
402 }
403
404 @Override
405 public Criterion getCriterion(
406 org.onosproject.net.flow.criteria.Criterion.Type type) {
407 return null;
408 }
409
410 @Override
411 public int hashCode() {
412 return testval;
413 }
414
415 @Override
416 public boolean equals(Object o) {
417 if (o instanceof TestSelector) {
418 return this.testval == ((TestSelector) o).testval;
419 }
420 return false;
421 }
yoonseon6b972c32016-12-06 16:45:03 -0800422 }
423
424 private class TestTreatment implements TrafficTreatment {
425
426 //for controlling hashcode uniqueness;
427 private final int testval;
428
429 public TestTreatment(int val) {
430 testval = val;
431 }
432
433 @Override
434 public List<Instruction> deferred() {
435 return null;
436 }
437
438 @Override
439 public List<Instruction> immediate() {
440 return null;
441 }
442
443 @Override
444 public List<Instruction> allInstructions() {
445 return null;
446 }
447
448 @Override
449 public Instructions.TableTypeTransition tableTransition() {
450 return null;
451 }
452
453 @Override
454 public boolean clearedDeferred() {
455 return false;
456 }
457
458 @Override
459 public int hashCode() {
460 return testval;
461 }
462
463 @Override
464 public boolean equals(Object o) {
465 if (o instanceof TestTreatment) {
466 return this.testval == ((TestTreatment) o).testval;
467 }
468 return false;
469 }
470
471 @Override
472 public Instructions.MetadataInstruction writeMetadata() {
473 return null;
474 }
475
476 @Override
477 public Instructions.MeterInstruction metered() {
478 return null;
479 }
480 }
481
yoonseon6b972c32016-12-06 16:45:03 -0800482 private void validateEvents(TestFlowRuleListener listener, FlowRuleEvent.Type... events) {
483 if (events == null) {
484 assertTrue("events generated", listener.events.isEmpty());
485 }
486
487 int i = 0;
488 System.err.println("events :" + listener.events);
489 for (FlowRuleEvent e : listener.events) {
490 assertEquals("unexpected event", events[i], e.type());
491 i++;
492 }
493
494 assertEquals("mispredicted number of events",
495 events.length, listener.events.size());
496
497 listener.events.clear();
498 }
499
500 private class TestFlowRuleListener implements FlowRuleListener {
501
502 public final List<FlowRuleEvent> events = new ArrayList<>();
503
504 @Override
505 public void event(FlowRuleEvent event) {
yoonseonbd8a93d2016-12-07 15:51:21 -0800506 events.add(event);
yoonseon6b972c32016-12-06 16:45:03 -0800507 }
508 }
509
510 private class TestProvider extends AbstractVirtualProvider
511 implements VirtualFlowRuleProvider {
512
513 protected TestProvider() {
514 super(new ProviderId("test", "org.onosproject.virtual.testprovider"));
515 }
516
517 @Override
518 public void applyFlowRule(NetworkId networkId, FlowRule... flowRules) {
519
520 }
521
522 @Override
523 public void removeFlowRule(NetworkId networkId, FlowRule... flowRules) {
524
525 }
526
527 @Override
528 public void executeBatch(NetworkId networkId, FlowRuleBatchOperation batch) {
529
530 }
531 }
532}