alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 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 | */ |
Jonathan Hart | 6af92be | 2016-01-05 20:52:25 -0800 | [diff] [blame] | 16 | package org.onosproject.routing.impl; |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 18 | import com.google.common.util.concurrent.MoreExecutors; |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 21 | import org.onlab.packet.Ethernet; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ip4Prefix; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.IpPrefix; |
| 25 | import org.onlab.packet.MacAddress; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 26 | import org.onosproject.TestApplicationId; |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 27 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 28 | import org.onosproject.cluster.ControllerNode; |
| 29 | import org.onosproject.cluster.DefaultControllerNode; |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 30 | import org.onosproject.cluster.LeadershipServiceAdapter; |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 31 | import org.onosproject.cluster.NodeId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.core.ApplicationId; |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 33 | import org.onosproject.core.CoreServiceAdapter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.ConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.DeviceId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 36 | import org.onosproject.net.PortNumber; |
| 37 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 38 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 39 | import org.onosproject.net.flow.TrafficSelector; |
| 40 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 41 | import org.onosproject.net.intent.AbstractIntentTest; |
| 42 | import org.onosproject.net.intent.Intent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.net.intent.IntentService; |
| 44 | import org.onosproject.net.intent.IntentState; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 45 | import org.onosproject.net.intent.Key; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 46 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 47 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 48 | import java.util.Collections; |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 49 | import java.util.HashSet; |
| 50 | import java.util.Set; |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 51 | import java.util.concurrent.ExecutorService; |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 52 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 53 | import static org.easymock.EasyMock.createMock; |
| 54 | import static org.easymock.EasyMock.expect; |
| 55 | import static org.easymock.EasyMock.replay; |
| 56 | import static org.easymock.EasyMock.reset; |
| 57 | import static org.easymock.EasyMock.verify; |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 60 | * This class tests the intent synchronization function in the |
| 61 | * IntentSynchronizer class. |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 62 | */ |
Jonathan Hart | 6af92be | 2016-01-05 20:52:25 -0800 | [diff] [blame] | 63 | public class IntentSynchronizerTest extends AbstractIntentTest { |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 64 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 65 | private IntentService intentService; |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 66 | |
| 67 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
| 68 | DeviceId.deviceId("of:0000000000000001"), |
| 69 | PortNumber.portNumber(1)); |
| 70 | |
| 71 | private static final ConnectPoint SW2_ETH1 = new ConnectPoint( |
| 72 | DeviceId.deviceId("of:0000000000000002"), |
| 73 | PortNumber.portNumber(1)); |
| 74 | |
| 75 | private static final ConnectPoint SW3_ETH1 = new ConnectPoint( |
| 76 | DeviceId.deviceId("of:0000000000000003"), |
| 77 | PortNumber.portNumber(1)); |
| 78 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 79 | private static final ConnectPoint SW4_ETH1 = new ConnectPoint( |
| 80 | DeviceId.deviceId("of:0000000000000004"), |
| 81 | PortNumber.portNumber(1)); |
| 82 | |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 83 | private IntentSynchronizer intentSynchronizer; |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 84 | private final Set<ConnectPoint> connectPoints = new HashSet<>(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 85 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 86 | private static final ApplicationId APPID = |
| 87 | TestApplicationId.create("intent-sync-test"); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 88 | |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 89 | private static final ControllerNode LOCAL_NODE = |
| 90 | new DefaultControllerNode(new NodeId("foo"), IpAddress.valueOf("127.0.0.1")); |
| 91 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 92 | @Before |
| 93 | public void setUp() throws Exception { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 94 | super.setUp(); |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 95 | |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 96 | setUpConnectPoints(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 97 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 98 | intentService = createMock(IntentService.class); |
| 99 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 100 | intentSynchronizer = new TestIntentSynchronizer(); |
| 101 | |
| 102 | intentSynchronizer.coreService = new TestCoreService(); |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 103 | intentSynchronizer.clusterService = new TestClusterService(); |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 104 | intentSynchronizer.leadershipService = new LeadershipServiceAdapter(); |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 105 | intentSynchronizer.intentService = intentService; |
| 106 | |
| 107 | intentSynchronizer.activate(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 111 | * Sets up connect points. |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 112 | */ |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 113 | private void setUpConnectPoints() { |
| 114 | connectPoints.add(SW1_ETH1); |
| 115 | connectPoints.add(SW2_ETH1); |
| 116 | connectPoints.add(SW3_ETH1); |
| 117 | connectPoints.add(SW4_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 121 | * Tests the synchronization behavior of intent synchronizer. We set up |
| 122 | * a discrepancy between the intent service state and the intent |
| 123 | * synchronizer's state and ensure that this is reconciled correctly. |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 124 | */ |
| 125 | @Test |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 126 | public void testIntentSync() { |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 127 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 128 | // Construct routes and intents. |
| 129 | // This test simulates the following cases during the master change |
| 130 | // time interval: |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 131 | // 1. intent1 did not change and the intent also did not change. |
| 132 | // 2. intent2 was deleted, but the intent was not deleted. |
| 133 | // 3. intent3 was newly added, and the intent was also submitted. |
| 134 | // 4. intent4 was updated to RouteEntry4Update, and the intent was |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 135 | // also updated to a new one. |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 136 | // 5. intent5 did not change, but its intent id changed. |
| 137 | // 6. intent6 was newly added, but the intent was not submitted. |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 138 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 139 | MultiPointToSinglePointIntent intent1 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 140 | Ip4Prefix.valueOf("1.1.1.0/24"), "00:00:00:00:00:01", SW1_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 141 | MultiPointToSinglePointIntent intent2 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 142 | Ip4Prefix.valueOf("2.2.2.0/24"), "00:00:00:00:00:02", SW2_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 143 | MultiPointToSinglePointIntent intent3 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 144 | Ip4Prefix.valueOf("3.3.3.0/24"), "00:00:00:00:00:03", SW3_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 145 | MultiPointToSinglePointIntent intent4 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 146 | Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:03", SW3_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 147 | MultiPointToSinglePointIntent intent4Update = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 148 | Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:02", SW2_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 149 | MultiPointToSinglePointIntent intent5 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 150 | Ip4Prefix.valueOf("5.5.5.0/24"), "00:00:00:00:00:01", SW1_ETH1); |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 151 | MultiPointToSinglePointIntent intent7 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 152 | Ip4Prefix.valueOf("7.7.7.0/24"), "00:00:00:00:00:01", SW1_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 153 | |
| 154 | MultiPointToSinglePointIntent intent6 = intentBuilder( |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 155 | Ip4Prefix.valueOf("6.6.6.0/24"), "00:00:00:00:00:01", SW1_ETH1); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 156 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 157 | // Set up expectation |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 158 | Set<Intent> intents = new HashSet<>(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 159 | intents.add(intent1); |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 160 | expect(intentService.getIntentState(intent1.key())) |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 161 | .andReturn(IntentState.INSTALLED).anyTimes(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 162 | intents.add(intent2); |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 163 | expect(intentService.getIntentState(intent2.key())) |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 164 | .andReturn(IntentState.INSTALLED).anyTimes(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 165 | intents.add(intent4); |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 166 | expect(intentService.getIntentState(intent4.key())) |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 167 | .andReturn(IntentState.INSTALLED).anyTimes(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 168 | intents.add(intent5); |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 169 | expect(intentService.getIntentState(intent5.key())) |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 170 | .andReturn(IntentState.INSTALLED).anyTimes(); |
| 171 | intents.add(intent7); |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 172 | expect(intentService.getIntentState(intent7.key())) |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 173 | .andReturn(IntentState.WITHDRAWING).anyTimes(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 174 | expect(intentService.getIntents()).andReturn(intents).anyTimes(); |
| 175 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 176 | // These are the operations that should be done to the intentService |
| 177 | // during synchronization |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 178 | intentService.withdraw(intent2); |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 179 | intentService.submit(intent3); |
| 180 | intentService.submit(intent4Update); |
| 181 | intentService.submit(intent6); |
| 182 | intentService.submit(intent7); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 183 | replay(intentService); |
| 184 | |
| 185 | // Start the test |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 186 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 187 | // Simulate some input from the clients. The intent synchronizer has not |
| 188 | // gained the global leadership yet, but it will remember this input for |
| 189 | // when it does. |
| 190 | intentSynchronizer.submit(intent1); |
| 191 | intentSynchronizer.submit(intent2); |
| 192 | intentSynchronizer.withdraw(intent2); |
| 193 | intentSynchronizer.submit(intent3); |
| 194 | intentSynchronizer.submit(intent4); |
| 195 | intentSynchronizer.submit(intent4Update); |
| 196 | intentSynchronizer.submit(intent5); |
| 197 | intentSynchronizer.submit(intent6); |
| 198 | intentSynchronizer.submit(intent7); |
| 199 | |
| 200 | // Give the leadership to the intent synchronizer. It will now attempt |
| 201 | // to synchronize the intents in the store with the intents it has |
| 202 | // recorded based on the earlier user input. |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 203 | intentSynchronizer.modifyPrimary(true); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 204 | |
| 205 | verify(intentService); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Tests the behavior of the submit API, both when the synchronizer has |
| 210 | * leadership and when it does not. |
| 211 | */ |
| 212 | @Test |
| 213 | public void testSubmit() { |
| 214 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 215 | Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1); |
| 216 | |
| 217 | // Set up expectations |
| 218 | intentService.submit(intent); |
| 219 | expect(intentService.getIntents()).andReturn(Collections.emptyList()) |
| 220 | .anyTimes(); |
| 221 | replay(intentService); |
| 222 | |
| 223 | // Give the intent synchronizer leadership so it will submit intents |
| 224 | // to the intent service |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 225 | intentSynchronizer.modifyPrimary(true); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 226 | |
| 227 | // Test the submit |
| 228 | intentSynchronizer.submit(intent); |
| 229 | |
| 230 | verify(intentService); |
| 231 | |
| 232 | // Now we'll remove leadership from the intent synchronizer and verify |
| 233 | // that it does not submit any intents to the intent service when we |
| 234 | // call the submit API |
| 235 | reset(intentService); |
| 236 | replay(intentService); |
| 237 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 238 | intentSynchronizer.modifyPrimary(false); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 239 | |
| 240 | intentSynchronizer.submit(intent); |
| 241 | |
| 242 | verify(intentService); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Tests the behavior of the withdraw API, both when the synchronizer has |
| 247 | * leadership and when it does not. |
| 248 | */ |
| 249 | @Test |
| 250 | public void testWithdraw() { |
| 251 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 252 | Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1); |
| 253 | |
| 254 | // Submit an intent first so we can withdraw it later |
| 255 | intentService.submit(intent); |
| 256 | intentService.withdraw(intent); |
| 257 | expect(intentService.getIntents()).andReturn(Collections.emptyList()) |
| 258 | .anyTimes(); |
| 259 | replay(intentService); |
| 260 | |
| 261 | // Give the intent synchronizer leadership so it will submit intents |
| 262 | // to the intent service |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 263 | intentSynchronizer.modifyPrimary(true); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 264 | |
| 265 | // Test the submit then withdraw |
| 266 | intentSynchronizer.submit(intent); |
| 267 | intentSynchronizer.withdraw(intent); |
| 268 | |
| 269 | verify(intentService); |
| 270 | |
| 271 | // Now we'll remove leadership from the intent synchronizer and verify |
| 272 | // that it does not withdraw any intents to the intent service when we |
| 273 | // call the withdraw API |
| 274 | reset(intentService); |
| 275 | replay(intentService); |
| 276 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 277 | intentSynchronizer.modifyPrimary(false); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 278 | |
| 279 | intentSynchronizer.submit(intent); |
| 280 | intentSynchronizer.withdraw(intent); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 281 | |
| 282 | verify(intentService); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * MultiPointToSinglePointIntent builder. |
| 287 | * |
| 288 | * @param ipPrefix the ipPrefix to match |
| 289 | * @param nextHopMacAddress to which the destination MAC address in packet |
| 290 | * should be rewritten |
| 291 | * @param egressPoint to which packets should be sent |
| 292 | * @return the constructed MultiPointToSinglePointIntent |
| 293 | */ |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 294 | private MultiPointToSinglePointIntent intentBuilder(IpPrefix ipPrefix, |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 295 | String nextHopMacAddress, ConnectPoint egressPoint) { |
| 296 | |
| 297 | TrafficSelector.Builder selectorBuilder = |
| 298 | DefaultTrafficSelector.builder(); |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 299 | if (ipPrefix.isIp4()) { |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 300 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); |
Pavlin Radoslavov | a853709 | 2015-02-23 10:15:20 -0800 | [diff] [blame] | 301 | selectorBuilder.matchIPDst(ipPrefix); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 302 | } else { |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 303 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
Pavlin Radoslavov | a853709 | 2015-02-23 10:15:20 -0800 | [diff] [blame] | 304 | selectorBuilder.matchIPv6Dst(ipPrefix); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 305 | } |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 306 | |
| 307 | TrafficTreatment.Builder treatmentBuilder = |
| 308 | DefaultTrafficTreatment.builder(); |
| 309 | treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress)); |
| 310 | |
Jonathan Hart | de6e203 | 2016-04-15 13:28:02 -0700 | [diff] [blame] | 311 | Set<ConnectPoint> ingressPoints = new HashSet<>(connectPoints); |
| 312 | ingressPoints.remove(egressPoint); |
| 313 | |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 314 | MultiPointToSinglePointIntent intent = |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 315 | MultiPointToSinglePointIntent.builder() |
| 316 | .appId(APPID) |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 317 | .key(Key.of(ipPrefix.toString(), APPID)) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 318 | .selector(selectorBuilder.build()) |
| 319 | .treatment(treatmentBuilder.build()) |
| 320 | .ingressPoints(ingressPoints) |
| 321 | .egressPoint(egressPoint) |
| 322 | .build(); |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 323 | return intent; |
| 324 | } |
| 325 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 326 | private class TestIntentSynchronizer extends IntentSynchronizer { |
| 327 | @Override |
| 328 | protected ExecutorService createExecutor() { |
| 329 | return MoreExecutors.newDirectExecutorService(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | private class TestCoreService extends CoreServiceAdapter { |
| 334 | @Override |
| 335 | public ApplicationId registerApplication(String name) { |
| 336 | return APPID; |
| 337 | } |
| 338 | } |
| 339 | |
Madan Jampani | 620f70d | 2016-01-30 22:22:47 -0800 | [diff] [blame] | 340 | private class TestClusterService extends ClusterServiceAdapter { |
| 341 | @Override |
| 342 | public ControllerNode getLocalNode() { |
| 343 | return LOCAL_NODE; |
| 344 | } |
| 345 | } |
Pingping | f5d9093 | 2014-10-27 10:50:04 -0700 | [diff] [blame] | 346 | } |