blob: fb579eafc63654ca346e2c1ff786ad3cf61e6d13 [file] [log] [blame]
tombe988312014-09-19 18:38:47 -07001package org.onlab.onos.net.flow.impl;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -07002
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertTrue;
alshabib97044902014-09-18 14:52:16 -07007import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
8import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
alshabib219ebaa2014-09-22 15:41:24 -07009import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070010
11import java.util.ArrayList;
alshabibba5ac482014-10-02 17:15:20 -070012import java.util.Collections;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070013import java.util.List;
alshabibba5ac482014-10-02 17:15:20 -070014import java.util.Set;
alshabib902d41b2014-10-07 16:52:05 -070015import java.util.concurrent.Future;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070016
17import org.junit.After;
18import org.junit.Before;
19import org.junit.Test;
alshabiba68eb962014-09-24 20:34:13 -070020import org.onlab.onos.ApplicationId;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070021import org.onlab.onos.event.impl.TestEventDispatcher;
alshabib92c65ad2014-10-08 21:56:05 -070022import org.onlab.onos.impl.DefaultApplicationId;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070023import org.onlab.onos.net.DefaultDevice;
24import org.onlab.onos.net.Device;
25import org.onlab.onos.net.Device.Type;
26import org.onlab.onos.net.DeviceId;
27import org.onlab.onos.net.MastershipRole;
28import org.onlab.onos.net.Port;
29import org.onlab.onos.net.PortNumber;
30import org.onlab.onos.net.device.DeviceListener;
31import org.onlab.onos.net.device.DeviceService;
alshabib193525b2014-10-08 18:58:03 -070032import org.onlab.onos.net.flow.CompletedBatchOperation;
alshabib1c319ff2014-10-04 20:29:09 -070033import org.onlab.onos.net.flow.DefaultFlowEntry;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070034import org.onlab.onos.net.flow.DefaultFlowRule;
alshabib1c319ff2014-10-04 20:29:09 -070035import org.onlab.onos.net.flow.FlowEntry;
36import org.onlab.onos.net.flow.FlowEntry.FlowEntryState;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070037import org.onlab.onos.net.flow.FlowRule;
alshabib902d41b2014-10-07 16:52:05 -070038import org.onlab.onos.net.flow.FlowRuleBatchEntry;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070039import org.onlab.onos.net.flow.FlowRuleEvent;
40import org.onlab.onos.net.flow.FlowRuleListener;
41import org.onlab.onos.net.flow.FlowRuleProvider;
42import org.onlab.onos.net.flow.FlowRuleProviderRegistry;
43import org.onlab.onos.net.flow.FlowRuleProviderService;
44import org.onlab.onos.net.flow.FlowRuleService;
45import org.onlab.onos.net.flow.TrafficSelector;
46import org.onlab.onos.net.flow.TrafficTreatment;
47import org.onlab.onos.net.flow.criteria.Criterion;
48import org.onlab.onos.net.flow.instructions.Instruction;
alshabib902d41b2014-10-07 16:52:05 -070049import org.onlab.onos.net.intent.BatchOperation;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070050import org.onlab.onos.net.provider.AbstractProvider;
51import org.onlab.onos.net.provider.ProviderId;
tomea961ff2014-10-01 12:45:15 -070052import org.onlab.onos.store.trivial.impl.SimpleFlowRuleStore;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070053
alshabibba5ac482014-10-02 17:15:20 -070054import com.google.common.collect.ImmutableList;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070055import com.google.common.collect.Lists;
56import com.google.common.collect.Sets;
57
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070058/**
59 * Test codifying the flow rule service & flow rule provider service contracts.
60 */
tom202175a2014-09-19 19:00:11 -070061public class FlowRuleManagerTest {
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070062
alshabib92c65ad2014-10-08 21:56:05 -070063
64
tomf6ab2152014-09-18 12:08:29 -070065 private static final ProviderId PID = new ProviderId("of", "foo");
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070066 private static final DeviceId DID = DeviceId.deviceId("of:001");
alshabibba5ac482014-10-02 17:15:20 -070067 private static final int TIMEOUT = 10;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070068 private static final Device DEV = new DefaultDevice(
69 PID, DID, Type.SWITCH, "", "", "", "");
70
tom202175a2014-09-19 19:00:11 -070071 private FlowRuleManager mgr;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070072
73 protected FlowRuleService service;
74 protected FlowRuleProviderRegistry registry;
alshabibbb8b1282014-09-22 17:00:18 -070075 protected FlowRuleProviderService providerService;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070076 protected TestProvider provider;
77 protected TestListener listener = new TestListener();
alshabiba68eb962014-09-24 20:34:13 -070078 private ApplicationId appId;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070079
80 @Before
81 public void setUp() {
tom202175a2014-09-19 19:00:11 -070082 mgr = new FlowRuleManager();
tombe988312014-09-19 18:38:47 -070083 mgr.store = new SimpleFlowRuleStore();
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070084 mgr.eventDispatcher = new TestEventDispatcher();
85 mgr.deviceService = new TestDeviceService();
86 service = mgr;
87 registry = mgr;
88
89 mgr.activate();
90 mgr.addListener(listener);
91 provider = new TestProvider(PID);
alshabibbb8b1282014-09-22 17:00:18 -070092 providerService = registry.register(provider);
alshabib92c65ad2014-10-08 21:56:05 -070093 appId = new TestApplicationId((short) 0, "FlowRuleManagerTest");
Ayaka Koshibeb55524f2014-09-18 09:59:24 -070094 assertTrue("provider should be registered",
95 registry.getProviders().contains(provider.id()));
96 }
97
98 @After
99 public void tearDown() {
100 registry.unregister(provider);
101 assertFalse("provider should not be registered",
alshabib97044902014-09-18 14:52:16 -0700102 registry.getProviders().contains(provider.id()));
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700103 service.removeListener(listener);
104 mgr.deactivate();
105 mgr.eventDispatcher = null;
106 mgr.deviceService = null;
107 }
108
109 private FlowRule flowRule(int tsval, int trval) {
110 TestSelector ts = new TestSelector(tsval);
111 TestTreatment tr = new TestTreatment(trval);
alshabiba0e04982014-10-03 13:03:19 -0700112 return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700113 }
114
alshabibbb8b1282014-09-22 17:00:18 -0700115
116 private FlowRule addFlowRule(int hval) {
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700117 FlowRule rule = flowRule(hval, hval);
alshabibba5ac482014-10-02 17:15:20 -0700118 service.applyFlowRules(rule);
119
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700120 assertNotNull("rule should be found", service.getFlowEntries(DID));
alshabibbb8b1282014-09-22 17:00:18 -0700121 return rule;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700122 }
123
124 private void validateEvents(FlowRuleEvent.Type ... events) {
125 if (events == null) {
126 assertTrue("events generated", listener.events.isEmpty());
127 }
128
129 int i = 0;
alshabibbb42cad2014-09-25 11:43:05 -0700130 System.err.println("events :" + listener.events);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700131 for (FlowRuleEvent e : listener.events) {
132 assertTrue("unexpected event", e.type().equals(events[i]));
133 i++;
134 }
135
136 assertEquals("mispredicted number of events",
137 events.length, listener.events.size());
138
139 listener.events.clear();
140 }
141
142 private int flowCount() {
143 return Sets.newHashSet(service.getFlowEntries(DID)).size();
144 }
145 @Test
146 public void getFlowEntries() {
147 assertTrue("store should be empty",
148 Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
alshabibba5ac482014-10-02 17:15:20 -0700149 FlowRule f1 = addFlowRule(1);
150 FlowRule f2 = addFlowRule(2);
151
alshabib1c319ff2014-10-04 20:29:09 -0700152 FlowEntry fe1 = new DefaultFlowEntry(f1);
153 FlowEntry fe2 = new DefaultFlowEntry(f2);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700154 assertEquals("2 rules should exist", 2, flowCount());
alshabibba5ac482014-10-02 17:15:20 -0700155
alshabib1c319ff2014-10-04 20:29:09 -0700156 providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700157 validateEvents(RULE_ADDED, RULE_ADDED);
158
159 addFlowRule(1);
160 assertEquals("should still be 2 rules", 2, flowCount());
alshabibba5ac482014-10-02 17:15:20 -0700161
alshabib1c319ff2014-10-04 20:29:09 -0700162 providerService.pushFlowMetrics(DID, ImmutableList.of(fe1));
alshabib219ebaa2014-09-22 15:41:24 -0700163 validateEvents(RULE_UPDATED);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700164 }
165
alshabibbb8b1282014-09-22 17:00:18 -0700166
167 //backing store is sensitive to the order of additions/removals
alshabib1c319ff2014-10-04 20:29:09 -0700168 private boolean validateState(FlowEntryState... state) {
169 Iterable<FlowEntry> rules = service.getFlowEntries(DID);
alshabibbb8b1282014-09-22 17:00:18 -0700170 int i = 0;
alshabib1c319ff2014-10-04 20:29:09 -0700171 for (FlowEntry f : rules) {
alshabibbb8b1282014-09-22 17:00:18 -0700172 if (f.state() != state[i]) {
173 return false;
174 }
175 i++;
176 }
177 return true;
178 }
179
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700180 @Test
181 public void applyFlowRules() {
alshabibbb8b1282014-09-22 17:00:18 -0700182
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700183 FlowRule r1 = flowRule(1, 1);
alshabiba68eb962014-09-24 20:34:13 -0700184 FlowRule r2 = flowRule(2, 2);
185 FlowRule r3 = flowRule(3, 3);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700186
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700187 assertTrue("store should be empty",
188 Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
alshabib219ebaa2014-09-22 15:41:24 -0700189 mgr.applyFlowRules(r1, r2, r3);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700190 assertEquals("3 rules should exist", 3, flowCount());
alshabibbb8b1282014-09-22 17:00:18 -0700191 assertTrue("Entries should be pending add.",
alshabib1c319ff2014-10-04 20:29:09 -0700192 validateState(FlowEntryState.PENDING_ADD, FlowEntryState.PENDING_ADD,
193 FlowEntryState.PENDING_ADD));
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700194 }
195
196 @Test
197 public void removeFlowRules() {
alshabibbb8b1282014-09-22 17:00:18 -0700198 FlowRule f1 = addFlowRule(1);
199 FlowRule f2 = addFlowRule(2);
alshabibba5ac482014-10-02 17:15:20 -0700200 FlowRule f3 = addFlowRule(3);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700201 assertEquals("3 rules should exist", 3, flowCount());
alshabibba5ac482014-10-02 17:15:20 -0700202
alshabib1c319ff2014-10-04 20:29:09 -0700203 FlowEntry fe1 = new DefaultFlowEntry(f1);
204 FlowEntry fe2 = new DefaultFlowEntry(f2);
205 FlowEntry fe3 = new DefaultFlowEntry(f3);
206 providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2, fe3));
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700207 validateEvents(RULE_ADDED, RULE_ADDED, RULE_ADDED);
208
alshabib1c319ff2014-10-04 20:29:09 -0700209 mgr.removeFlowRules(f1, f2);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700210 //removing from north, so no events generated
211 validateEvents();
alshabib219ebaa2014-09-22 15:41:24 -0700212 assertEquals("3 rule should exist", 3, flowCount());
alshabibbb8b1282014-09-22 17:00:18 -0700213 assertTrue("Entries should be pending remove.",
alshabib1c319ff2014-10-04 20:29:09 -0700214 validateState(FlowEntryState.PENDING_REMOVE, FlowEntryState.PENDING_REMOVE,
215 FlowEntryState.ADDED));
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700216
alshabib1c319ff2014-10-04 20:29:09 -0700217 mgr.removeFlowRules(f1);
alshabib219ebaa2014-09-22 15:41:24 -0700218 assertEquals("3 rule should still exist", 3, flowCount());
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700219 }
220
221 @Test
222 public void flowRemoved() {
alshabibbb8b1282014-09-22 17:00:18 -0700223 FlowRule f1 = addFlowRule(1);
alshabibba5ac482014-10-02 17:15:20 -0700224 FlowRule f2 = addFlowRule(2);
alshabib1c319ff2014-10-04 20:29:09 -0700225 FlowEntry fe1 = new DefaultFlowEntry(f1);
226 FlowEntry fe2 = new DefaultFlowEntry(f2);
227 providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
alshabiba68eb962014-09-24 20:34:13 -0700228 service.removeFlowRules(f1);
alshabib1c319ff2014-10-04 20:29:09 -0700229 fe1.setState(FlowEntryState.REMOVED);
230 providerService.flowRemoved(fe1);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700231 validateEvents(RULE_ADDED, RULE_ADDED, RULE_REMOVED);
232
alshabib1c319ff2014-10-04 20:29:09 -0700233 providerService.flowRemoved(fe1);
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700234 validateEvents();
alshabibbb42cad2014-09-25 11:43:05 -0700235
alshabibba5ac482014-10-02 17:15:20 -0700236 FlowRule f3 = flowRule(3, 3);
alshabib1c319ff2014-10-04 20:29:09 -0700237 FlowEntry fe3 = new DefaultFlowEntry(f3);
alshabibba5ac482014-10-02 17:15:20 -0700238 service.applyFlowRules(f3);
alshabib1c319ff2014-10-04 20:29:09 -0700239 providerService.pushFlowMetrics(DID, Collections.singletonList(fe3));
alshabibbb42cad2014-09-25 11:43:05 -0700240 validateEvents(RULE_ADDED);
alshabibba5ac482014-10-02 17:15:20 -0700241
alshabib1c319ff2014-10-04 20:29:09 -0700242 providerService.flowRemoved(fe3);
alshabibbb42cad2014-09-25 11:43:05 -0700243 validateEvents();
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700244 }
245
alshabibbb8b1282014-09-22 17:00:18 -0700246 @Test
247 public void flowMetrics() {
248 FlowRule f1 = flowRule(1, 1);
249 FlowRule f2 = flowRule(2, 2);
250 FlowRule f3 = flowRule(3, 3);
251
alshabibba5ac482014-10-02 17:15:20 -0700252 mgr.applyFlowRules(f1, f2, f3);
alshabibbb8b1282014-09-22 17:00:18 -0700253
alshabib1c319ff2014-10-04 20:29:09 -0700254 FlowEntry fe1 = new DefaultFlowEntry(f1);
255 FlowEntry fe2 = new DefaultFlowEntry(f2);
256
257
258 //FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
259 //FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
260
261 providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
alshabibbb8b1282014-09-22 17:00:18 -0700262
263 assertTrue("Entries should be added.",
alshabib1c319ff2014-10-04 20:29:09 -0700264 validateState(FlowEntryState.ADDED, FlowEntryState.ADDED,
265 FlowEntryState.PENDING_ADD));
alshabibbb42cad2014-09-25 11:43:05 -0700266
alshabibba5ac482014-10-02 17:15:20 -0700267 validateEvents(RULE_ADDED, RULE_ADDED);
alshabibbb42cad2014-09-25 11:43:05 -0700268 }
269
270 @Test
271 public void extraneousFlow() {
272 FlowRule f1 = flowRule(1, 1);
273 FlowRule f2 = flowRule(2, 2);
274 FlowRule f3 = flowRule(3, 3);
alshabibba5ac482014-10-02 17:15:20 -0700275 mgr.applyFlowRules(f1, f2);
alshabibbb42cad2014-09-25 11:43:05 -0700276
alshabib1c319ff2014-10-04 20:29:09 -0700277// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
278// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
279// FlowRule updatedF3 = flowRule(f3, FlowRuleState.ADDED);
280 FlowEntry fe1 = new DefaultFlowEntry(f1);
281 FlowEntry fe2 = new DefaultFlowEntry(f2);
282 FlowEntry fe3 = new DefaultFlowEntry(f3);
alshabibbb42cad2014-09-25 11:43:05 -0700283
alshabib1c319ff2014-10-04 20:29:09 -0700284
285 providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2, fe3));
alshabibbb42cad2014-09-25 11:43:05 -0700286
alshabibba5ac482014-10-02 17:15:20 -0700287 validateEvents(RULE_ADDED, RULE_ADDED);
alshabibbb42cad2014-09-25 11:43:05 -0700288
289 }
290
291 /*
292 * Tests whether a rule that was marked for removal but no flowRemoved was received
293 * is indeed removed at the next stats update.
294 */
295 @Test
296 public void flowMissingRemove() {
297 FlowRule f1 = flowRule(1, 1);
298 FlowRule f2 = flowRule(2, 2);
299 FlowRule f3 = flowRule(3, 3);
300
alshabib1c319ff2014-10-04 20:29:09 -0700301// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
302// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
303
304 FlowEntry fe1 = new DefaultFlowEntry(f1);
305 FlowEntry fe2 = new DefaultFlowEntry(f2);
alshabibbb42cad2014-09-25 11:43:05 -0700306 mgr.applyFlowRules(f1, f2, f3);
307
308 mgr.removeFlowRules(f3);
309
alshabib1c319ff2014-10-04 20:29:09 -0700310 providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
alshabibbb42cad2014-09-25 11:43:05 -0700311
alshabibba5ac482014-10-02 17:15:20 -0700312 validateEvents(RULE_ADDED, RULE_ADDED, RULE_REMOVED);
alshabibbb42cad2014-09-25 11:43:05 -0700313
314 }
315
316 @Test
317 public void getByAppId() {
318 FlowRule f1 = flowRule(1, 1);
319 FlowRule f2 = flowRule(2, 2);
320 mgr.applyFlowRules(f1, f2);
321
322 assertTrue("should have two rules",
323 Lists.newLinkedList(mgr.getFlowRulesById(appId)).size() == 2);
324 }
325
326 @Test
327 public void removeByAppId() {
328 FlowRule f1 = flowRule(1, 1);
329 FlowRule f2 = flowRule(2, 2);
330 mgr.applyFlowRules(f1, f2);
331
332
333 mgr.removeFlowRulesById(appId);
334
335 //only check that we are in pending remove. Events and actual remove state will
336 // be set by flowRemoved call.
alshabib1c319ff2014-10-04 20:29:09 -0700337 validateState(FlowEntryState.PENDING_REMOVE, FlowEntryState.PENDING_REMOVE);
alshabibbb8b1282014-09-22 17:00:18 -0700338 }
339
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700340 private static class TestListener implements FlowRuleListener {
341 final List<FlowRuleEvent> events = new ArrayList<>();
342
343 @Override
344 public void event(FlowRuleEvent event) {
345 events.add(event);
346 }
347 }
348
349 private static class TestDeviceService implements DeviceService {
350
351 @Override
352 public int getDeviceCount() {
353 return 0;
354 }
355
356 @Override
357 public Iterable<Device> getDevices() {
358 return null;
359 }
360
361 @Override
362 public Device getDevice(DeviceId deviceId) {
363 return DEV;
364 }
365
366 @Override
367 public MastershipRole getRole(DeviceId deviceId) {
368 return null;
369 }
370
371 @Override
372 public List<Port> getPorts(DeviceId deviceId) {
373 return null;
374 }
375
376 @Override
377 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
378 return null;
379 }
380
381 @Override
382 public boolean isAvailable(DeviceId deviceId) {
383 return false;
384 }
385
386 @Override
387 public void addListener(DeviceListener listener) {
388 }
389
390 @Override
391 public void removeListener(DeviceListener listener) {
392 }
393
394 }
395
396 private class TestProvider extends AbstractProvider implements FlowRuleProvider {
397
398 protected TestProvider(ProviderId id) {
399 super(PID);
400 }
401
402 @Override
403 public void applyFlowRule(FlowRule... flowRules) {
404 }
405
406 @Override
407 public void removeFlowRule(FlowRule... flowRules) {
408 }
409
alshabiba68eb962014-09-24 20:34:13 -0700410 @Override
411 public void removeRulesById(ApplicationId id, FlowRule... flowRules) {
412 }
413
alshabib902d41b2014-10-07 16:52:05 -0700414 @Override
alshabib193525b2014-10-08 18:58:03 -0700415 public Future<CompletedBatchOperation> executeBatch(
alshabib902d41b2014-10-07 16:52:05 -0700416 BatchOperation<FlowRuleBatchEntry> batch) {
417 // TODO Auto-generated method stub
418 return null;
419 }
420
alshabiba68eb962014-09-24 20:34:13 -0700421
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700422 }
423
424 private class TestSelector implements TrafficSelector {
425
426 //for controlling hashcode uniqueness;
alshabib97044902014-09-18 14:52:16 -0700427 private final int testval;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700428
429 public TestSelector(int val) {
430 testval = val;
431 }
432
433 @Override
alshabibba5ac482014-10-02 17:15:20 -0700434 public Set<Criterion> criteria() {
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700435 return null;
436 }
437
438 @Override
439 public int hashCode() {
440 return testval;
441 }
442
443 @Override
444 public boolean equals(Object o) {
445 if (o instanceof TestSelector) {
446 return this.testval == ((TestSelector) o).testval;
447 }
448 return false;
449 }
450 }
451
452 private class TestTreatment implements TrafficTreatment {
453
454 //for controlling hashcode uniqueness;
alshabib97044902014-09-18 14:52:16 -0700455 private final int testval;
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700456
457 public TestTreatment(int val) {
458 testval = val;
459 }
460
461 @Override
462 public List<Instruction> instructions() {
463 return null;
464 }
465
466 @Override
467 public int hashCode() {
468 return testval;
469 }
470
471 @Override
472 public boolean equals(Object o) {
473 if (o instanceof TestTreatment) {
474 return this.testval == ((TestTreatment) o).testval;
475 }
476 return false;
477 }
478
479 }
480
alshabib92c65ad2014-10-08 21:56:05 -0700481 public class TestApplicationId extends DefaultApplicationId {
482
483 public TestApplicationId(short id, String name) {
484 super(id, name);
485 }
486 }
487
Ayaka Koshibeb55524f2014-09-18 09:59:24 -0700488}