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