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