kishore
Committed by Gerrit Code Review

Add/Remove interface, Addressed patch set 2

Change-Id: Ibee195f20cb8ebea7da89ce7324d1617e78c36b2

Add/Remove interface, Addressed patch set 1

Change-Id: If98c4cbf74d1ca5eeb2e51154308c8eb2af8c195

Add/Remove interface, Addressed patch set 1

Change-Id: If98c4cbf74d1ca5eeb2e51154308c8eb2af8c195
...@@ -131,6 +131,13 @@ ...@@ -131,6 +131,13 @@
131 <scope>test</scope> 131 <scope>test</scope>
132 <classifier>tests</classifier> 132 <classifier>tests</classifier>
133 </dependency> 133 </dependency>
134 + <dependency>
135 + <groupId>org.onosproject</groupId>
136 + <artifactId>onos-incubator-api</artifactId>
137 + <version>${project.version}</version>
138 + <scope>test</scope>
139 + <classifier>tests</classifier>
140 + </dependency>
134 141
135 </dependencies> 142 </dependencies>
136 143
......
...@@ -16,8 +16,16 @@ ...@@ -16,8 +16,16 @@
16 16
17 package org.onosproject.routing.impl; 17 package org.onosproject.routing.impl;
18 18
19 -import com.google.common.collect.ImmutableSortedSet; 19 +import static com.google.common.base.Preconditions.checkState;
20 -import com.google.common.collect.Maps; 20 +import static org.slf4j.LoggerFactory.getLogger;
21 +
22 +import java.util.Collections;
23 +import java.util.Iterator;
24 +import java.util.List;
25 +import java.util.Map;
26 +import java.util.Optional;
27 +import java.util.Set;
28 +
21 import org.apache.felix.scr.annotations.Activate; 29 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 30 import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 31 import org.apache.felix.scr.annotations.Deactivate;
...@@ -30,6 +38,8 @@ import org.onlab.packet.VlanId; ...@@ -30,6 +38,8 @@ import org.onlab.packet.VlanId;
30 import org.onosproject.core.ApplicationId; 38 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.CoreService; 39 import org.onosproject.core.CoreService;
32 import org.onosproject.incubator.net.intf.Interface; 40 import org.onosproject.incubator.net.intf.Interface;
41 +import org.onosproject.incubator.net.intf.InterfaceEvent;
42 +import org.onosproject.incubator.net.intf.InterfaceListener;
33 import org.onosproject.incubator.net.intf.InterfaceService; 43 import org.onosproject.incubator.net.intf.InterfaceService;
34 import org.onosproject.mastership.MastershipService; 44 import org.onosproject.mastership.MastershipService;
35 import org.onosproject.net.ConnectPoint; 45 import org.onosproject.net.ConnectPoint;
...@@ -59,15 +69,8 @@ import org.onosproject.routing.RoutingService; ...@@ -59,15 +69,8 @@ import org.onosproject.routing.RoutingService;
59 import org.onosproject.routing.config.RouterConfig; 69 import org.onosproject.routing.config.RouterConfig;
60 import org.slf4j.Logger; 70 import org.slf4j.Logger;
61 71
62 -import java.util.Collections; 72 +import com.google.common.collect.ImmutableSortedSet;
63 -import java.util.Iterator; 73 +import com.google.common.collect.Maps;
64 -import java.util.List;
65 -import java.util.Map;
66 -import java.util.Optional;
67 -import java.util.Set;
68 -
69 -import static org.slf4j.LoggerFactory.getLogger;
70 -import static com.google.common.base.Preconditions.checkState;
71 74
72 /** 75 /**
73 * Manages connectivity between peers redirecting control traffic to a routing 76 * Manages connectivity between peers redirecting control traffic to a routing
...@@ -115,6 +118,7 @@ public class ControlPlaneRedirectManager { ...@@ -115,6 +118,7 @@ public class ControlPlaneRedirectManager {
115 private final InternalNetworkConfigListener networkConfigListener = 118 private final InternalNetworkConfigListener networkConfigListener =
116 new InternalNetworkConfigListener(); 119 new InternalNetworkConfigListener();
117 private final InternalHostListener hostListener = new InternalHostListener(); 120 private final InternalHostListener hostListener = new InternalHostListener();
121 + private final InternalInterfaceListener interfaceListener = new InternalInterfaceListener();
118 122
119 @Activate 123 @Activate
120 public void activate() { 124 public void activate() {
...@@ -123,6 +127,7 @@ public class ControlPlaneRedirectManager { ...@@ -123,6 +127,7 @@ public class ControlPlaneRedirectManager {
123 deviceService.addListener(deviceListener); 127 deviceService.addListener(deviceListener);
124 networkConfigService.addListener(networkConfigListener); 128 networkConfigService.addListener(networkConfigListener);
125 hostService.addListener(hostListener); 129 hostService.addListener(hostListener);
130 + interfaceService.addListener(interfaceListener);
126 131
127 updateConfig(); 132 updateConfig();
128 } 133 }
...@@ -132,6 +137,7 @@ public class ControlPlaneRedirectManager { ...@@ -132,6 +137,7 @@ public class ControlPlaneRedirectManager {
132 deviceService.removeListener(deviceListener); 137 deviceService.removeListener(deviceListener);
133 networkConfigService.removeListener(networkConfigListener); 138 networkConfigService.removeListener(networkConfigListener);
134 hostService.removeListener(hostListener); 139 hostService.removeListener(hostListener);
140 + interfaceService.removeListener(interfaceListener);
135 } 141 }
136 142
137 private void updateConfig() { 143 private void updateConfig() {
...@@ -167,33 +173,44 @@ public class ControlPlaneRedirectManager { ...@@ -167,33 +173,44 @@ public class ControlPlaneRedirectManager {
167 } 173 }
168 } 174 }
169 175
170 - private void provisionInterface(Interface intf) { 176 + private void removeInterface(Interface intf) {
171 - addBasicInterfaceForwarding(intf); 177 + modifyBasicInterfaceForwarding(intf, false);
172 - updateOspfForwarding(intf); 178 + updateOspfForwarding(intf, false);
173 } 179 }
174 180
175 - private void addBasicInterfaceForwarding(Interface intf) { 181 + private void provisionInterface(Interface intf) {
182 + modifyBasicInterfaceForwarding(intf, true);
183 + updateOspfForwarding(intf, true);
184 + }
185 + /**
186 + * Install or removes the basic forwarding flows for each interface
187 + * based on the flag used.
188 + *
189 + * @param intf the Interface on which event is received
190 + * @param install true to create an add objective, false to create a remove
191 + * objective
192 + **/
193 + private void modifyBasicInterfaceForwarding(Interface intf, boolean install) {
176 log.debug("Adding interface objectives for {}", intf); 194 log.debug("Adding interface objectives for {}", intf);
177 195
178 DeviceId deviceId = controlPlaneConnectPoint.deviceId(); 196 DeviceId deviceId = controlPlaneConnectPoint.deviceId();
179 PortNumber controlPlanePort = controlPlaneConnectPoint.port(); 197 PortNumber controlPlanePort = controlPlaneConnectPoint.port();
180 -
181 for (InterfaceIpAddress ip : intf.ipAddresses()) { 198 for (InterfaceIpAddress ip : intf.ipAddresses()) {
182 // create nextObjectives for forwarding to this interface and the 199 // create nextObjectives for forwarding to this interface and the
183 // controlPlaneConnectPoint 200 // controlPlaneConnectPoint
184 int cpNextId, intfNextId; 201 int cpNextId, intfNextId;
185 if (intf.vlan() == VlanId.NONE) { 202 if (intf.vlan() == VlanId.NONE) {
186 - cpNextId = createNextObjective(deviceId, controlPlanePort, 203 + cpNextId = modifyNextObjective(deviceId, controlPlanePort,
187 VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), 204 VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN),
188 - true); 205 + true, install);
189 - intfNextId = createNextObjective(deviceId, intf.connectPoint().port(), 206 + intfNextId = modifyNextObjective(deviceId, intf.connectPoint().port(),
190 VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), 207 VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN),
191 - true); 208 + true, install);
192 } else { 209 } else {
193 - cpNextId = createNextObjective(deviceId, controlPlanePort, 210 + cpNextId = modifyNextObjective(deviceId, controlPlanePort,
194 - intf.vlan(), false); 211 + intf.vlan(), false, install);
195 - intfNextId = createNextObjective(deviceId, intf.connectPoint().port(), 212 + intfNextId = modifyNextObjective(deviceId, intf.connectPoint().port(),
196 - intf.vlan(), false); 213 + intf.vlan(), false, install);
197 } 214 }
198 215
199 // IPv4 to router 216 // IPv4 to router
...@@ -206,7 +223,7 @@ public class ControlPlaneRedirectManager { ...@@ -206,7 +223,7 @@ public class ControlPlaneRedirectManager {
206 .build(); 223 .build();
207 224
208 flowObjectiveService.forward(deviceId, 225 flowObjectiveService.forward(deviceId,
209 - buildForwardingObjective(toSelector, null, cpNextId, true)); 226 + buildForwardingObjective(toSelector, null, cpNextId, install));
210 227
211 // IPv4 from router 228 // IPv4 from router
212 TrafficSelector fromSelector = DefaultTrafficSelector.builder() 229 TrafficSelector fromSelector = DefaultTrafficSelector.builder()
...@@ -218,7 +235,7 @@ public class ControlPlaneRedirectManager { ...@@ -218,7 +235,7 @@ public class ControlPlaneRedirectManager {
218 .build(); 235 .build();
219 236
220 flowObjectiveService.forward(deviceId, 237 flowObjectiveService.forward(deviceId,
221 - buildForwardingObjective(fromSelector, null, intfNextId, true)); 238 + buildForwardingObjective(fromSelector, null, intfNextId, install));
222 239
223 // ARP to router 240 // ARP to router
224 toSelector = DefaultTrafficSelector.builder() 241 toSelector = DefaultTrafficSelector.builder()
...@@ -232,7 +249,7 @@ public class ControlPlaneRedirectManager { ...@@ -232,7 +249,7 @@ public class ControlPlaneRedirectManager {
232 .build(); 249 .build();
233 250
234 flowObjectiveService.forward(deviceId, 251 flowObjectiveService.forward(deviceId,
235 - buildForwardingObjective(toSelector, puntTreatment, cpNextId, true)); 252 + buildForwardingObjective(toSelector, puntTreatment, cpNextId, install));
236 253
237 // ARP from router 254 // ARP from router
238 fromSelector = DefaultTrafficSelector.builder() 255 fromSelector = DefaultTrafficSelector.builder()
...@@ -244,11 +261,18 @@ public class ControlPlaneRedirectManager { ...@@ -244,11 +261,18 @@ public class ControlPlaneRedirectManager {
244 .build(); 261 .build();
245 262
246 flowObjectiveService.forward(deviceId, 263 flowObjectiveService.forward(deviceId,
247 - buildForwardingObjective(fromSelector, puntTreatment, intfNextId, true)); 264 + buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install));
248 } 265 }
249 } 266 }
250 267
251 - private void updateOspfForwarding(Interface intf) { 268 + /**
269 + * Install or removes ospf forwarding rules.
270 + *
271 + * @param intf the Interface on which event is received
272 + * @param install true to create an add objective, false to create a remove
273 + * objective
274 + **/
275 + private void updateOspfForwarding(Interface intf, boolean install) {
252 // OSPF to router 276 // OSPF to router
253 TrafficSelector toSelector = DefaultTrafficSelector.builder() 277 TrafficSelector toSelector = DefaultTrafficSelector.builder()
254 .matchInPort(intf.connectPoint().port()) 278 .matchInPort(intf.connectPoint().port())
...@@ -262,16 +286,16 @@ public class ControlPlaneRedirectManager { ...@@ -262,16 +286,16 @@ public class ControlPlaneRedirectManager {
262 PortNumber controlPlanePort = controlPlaneConnectPoint.port(); 286 PortNumber controlPlanePort = controlPlaneConnectPoint.port();
263 int cpNextId; 287 int cpNextId;
264 if (intf.vlan() == VlanId.NONE) { 288 if (intf.vlan() == VlanId.NONE) {
265 - cpNextId = createNextObjective(deviceId, controlPlanePort, 289 + cpNextId = modifyNextObjective(deviceId, controlPlanePort,
266 VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), 290 VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN),
267 - true); 291 + true, install);
268 } else { 292 } else {
269 - cpNextId = createNextObjective(deviceId, controlPlanePort, 293 + cpNextId = modifyNextObjective(deviceId, controlPlanePort,
270 - intf.vlan(), false); 294 + intf.vlan(), false, install);
271 } 295 }
272 log.debug("ospf flows intf:{} nextid:{}", intf, cpNextId); 296 log.debug("ospf flows intf:{} nextid:{}", intf, cpNextId);
273 flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(), 297 flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(),
274 - buildForwardingObjective(toSelector, null, cpNextId, ospfEnabled)); 298 + buildForwardingObjective(toSelector, null, cpNextId, install ? ospfEnabled : install));
275 } 299 }
276 300
277 /** 301 /**
...@@ -282,10 +306,12 @@ public class ControlPlaneRedirectManager { ...@@ -282,10 +306,12 @@ public class ControlPlaneRedirectManager {
282 * @param portNumber the egress port 306 * @param portNumber the egress port
283 * @param vlanId vlan information for egress port 307 * @param vlanId vlan information for egress port
284 * @param popVlan if vlan tag should be popped or not 308 * @param popVlan if vlan tag should be popped or not
309 + * @param install true to create an add next objective, false to create a remove
310 + * next objective
285 * @return nextId of the next objective created 311 * @return nextId of the next objective created
286 */ 312 */
287 - private int createNextObjective(DeviceId deviceId, PortNumber portNumber, 313 + private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber,
288 - VlanId vlanId, boolean popVlan) { 314 + VlanId vlanId, boolean popVlan, boolean install) {
289 int nextId = flowObjectiveService.allocateNextId(); 315 int nextId = flowObjectiveService.allocateNextId();
290 NextObjective.Builder nextObjBuilder = DefaultNextObjective 316 NextObjective.Builder nextObjBuilder = DefaultNextObjective
291 .builder().withId(nextId) 317 .builder().withId(nextId)
...@@ -307,10 +333,13 @@ public class ControlPlaneRedirectManager { ...@@ -307,10 +333,13 @@ public class ControlPlaneRedirectManager {
307 nextObjBuilder.addTreatment(ttBuilder.build()); 333 nextObjBuilder.addTreatment(ttBuilder.build());
308 log.debug("Submited next objective {} in device {} for port/vlan {}/{}", 334 log.debug("Submited next objective {} in device {} for port/vlan {}/{}",
309 nextId, deviceId, portNumber, vlanId); 335 nextId, deviceId, portNumber, vlanId);
310 - flowObjectiveService.next(deviceId, nextObjBuilder.add()); 336 + if (install) {
337 + flowObjectiveService.next(deviceId, nextObjBuilder.add());
338 + } else {
339 + flowObjectiveService.next(deviceId, nextObjBuilder.remove());
340 + }
311 return nextId; 341 return nextId;
312 } 342 }
313 -
314 /** 343 /**
315 * Builds a forwarding objective from the given selector, treatment and nextId. 344 * Builds a forwarding objective from the given selector, treatment and nextId.
316 * 345 *
...@@ -344,6 +373,7 @@ public class ControlPlaneRedirectManager { ...@@ -344,6 +373,7 @@ public class ControlPlaneRedirectManager {
344 * Listener for device events. 373 * Listener for device events.
345 */ 374 */
346 private class InternalDeviceListener implements DeviceListener { 375 private class InternalDeviceListener implements DeviceListener {
376 +
347 @Override 377 @Override
348 public void event(DeviceEvent event) { 378 public void event(DeviceEvent event) {
349 if (controlPlaneConnectPoint != null && 379 if (controlPlaneConnectPoint != null &&
...@@ -374,6 +404,7 @@ public class ControlPlaneRedirectManager { ...@@ -374,6 +404,7 @@ public class ControlPlaneRedirectManager {
374 * Listener for network config events. 404 * Listener for network config events.
375 */ 405 */
376 private class InternalNetworkConfigListener implements NetworkConfigListener { 406 private class InternalNetworkConfigListener implements NetworkConfigListener {
407 +
377 @Override 408 @Override
378 public void event(NetworkConfigEvent event) { 409 public void event(NetworkConfigEvent event) {
379 if (event.configClass().equals(RoutingService.ROUTER_CONFIG_CLASS)) { 410 if (event.configClass().equals(RoutingService.ROUTER_CONFIG_CLASS)) {
...@@ -396,6 +427,7 @@ public class ControlPlaneRedirectManager { ...@@ -396,6 +427,7 @@ public class ControlPlaneRedirectManager {
396 * Listener for host events. 427 * Listener for host events.
397 */ 428 */
398 private class InternalHostListener implements HostListener { 429 private class InternalHostListener implements HostListener {
430 +
399 private void peerAdded(HostEvent event) { 431 private void peerAdded(HostEvent event) {
400 Host peer = event.subject(); 432 Host peer = event.subject();
401 Optional<Interface> peerIntf = 433 Optional<Interface> peerIntf =
...@@ -536,4 +568,27 @@ public class ControlPlaneRedirectManager { ...@@ -536,4 +568,27 @@ public class ControlPlaneRedirectManager {
536 2000 * prefix.prefixLength() + MIN_IP_PRIORITY : 568 2000 * prefix.prefixLength() + MIN_IP_PRIORITY :
537 500 * prefix.prefixLength() + MIN_IP_PRIORITY; 569 500 * prefix.prefixLength() + MIN_IP_PRIORITY;
538 } 570 }
571 + private class InternalInterfaceListener implements InterfaceListener {
572 +
573 + @Override
574 + public void event(InterfaceEvent event) {
575 + Interface intf = event.subject();
576 + switch (event.type()) {
577 + case INTERFACE_ADDED:
578 + if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) {
579 + provisionInterface(intf);
580 + }
581 + break;
582 + case INTERFACE_UPDATED:
583 + break;
584 + case INTERFACE_REMOVED:
585 + if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) {
586 + removeInterface(intf);
587 + }
588 + break;
589 + default:
590 + break;
591 + }
592 + }
593 + }
539 } 594 }
......
...@@ -23,7 +23,7 @@ import static org.easymock.EasyMock.verify; ...@@ -23,7 +23,7 @@ import static org.easymock.EasyMock.verify;
23 import static org.slf4j.LoggerFactory.getLogger; 23 import static org.slf4j.LoggerFactory.getLogger;
24 24
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 -import java.util.Collections; 26 +import java.util.HashSet;
27 import java.util.List; 27 import java.util.List;
28 import java.util.Objects; 28 import java.util.Objects;
29 import java.util.Set; 29 import java.util.Set;
...@@ -32,7 +32,6 @@ import org.easymock.EasyMock; ...@@ -32,7 +32,6 @@ import org.easymock.EasyMock;
32 import org.junit.Before; 32 import org.junit.Before;
33 import org.junit.Test; 33 import org.junit.Test;
34 import org.onlab.packet.EthType; 34 import org.onlab.packet.EthType;
35 -import org.onlab.packet.Ip4Address;
36 import org.onlab.packet.IpAddress; 35 import org.onlab.packet.IpAddress;
37 import org.onlab.packet.IpPrefix; 36 import org.onlab.packet.IpPrefix;
38 import org.onlab.packet.MacAddress; 37 import org.onlab.packet.MacAddress;
...@@ -41,7 +40,10 @@ import org.onosproject.core.ApplicationId; ...@@ -41,7 +40,10 @@ import org.onosproject.core.ApplicationId;
41 import org.onosproject.core.CoreService; 40 import org.onosproject.core.CoreService;
42 import org.onosproject.core.CoreServiceAdapter; 41 import org.onosproject.core.CoreServiceAdapter;
43 import org.onosproject.incubator.net.intf.Interface; 42 import org.onosproject.incubator.net.intf.Interface;
43 +import org.onosproject.incubator.net.intf.InterfaceEvent;
44 +import org.onosproject.incubator.net.intf.InterfaceListener;
44 import org.onosproject.incubator.net.intf.InterfaceService; 45 import org.onosproject.incubator.net.intf.InterfaceService;
46 +import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
45 import org.onosproject.mastership.MastershipService; 47 import org.onosproject.mastership.MastershipService;
46 import org.onosproject.mastership.MastershipServiceAdapter; 48 import org.onosproject.mastership.MastershipServiceAdapter;
47 import org.onosproject.net.ConnectPoint; 49 import org.onosproject.net.ConnectPoint;
...@@ -85,7 +87,6 @@ import com.google.common.collect.Sets; ...@@ -85,7 +87,6 @@ import com.google.common.collect.Sets;
85 public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { 87 public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
86 88
87 private final Logger log = getLogger(getClass()); 89 private final Logger log = getLogger(getClass());
88 -
89 private DeviceService deviceService; 90 private DeviceService deviceService;
90 private FlowObjectiveService flowObjectiveService; 91 private FlowObjectiveService flowObjectiveService;
91 private NetworkConfigService networkConfigService; 92 private NetworkConfigService networkConfigService;
...@@ -118,28 +119,25 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -118,28 +119,25 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
118 private DeviceListener deviceListener; 119 private DeviceListener deviceListener;
119 private MastershipService mastershipService = new InternalMastershipServiceTest(); 120 private MastershipService mastershipService = new InternalMastershipServiceTest();
120 private HostListener hostListener; 121 private HostListener hostListener;
121 - 122 + private InterfaceListener interfaceListener;
122 - /**
123 - * @throws java.lang.Exception
124 - */
125 @Override 123 @Override
126 @Before 124 @Before
127 - public void setUp() throws Exception { 125 + public void setUp() {
128 - super.setUp();
129 - interfaceService = createMock(InterfaceService.class);
130 networkConfigListener = createMock(NetworkConfigListener.class); 126 networkConfigListener = createMock(NetworkConfigListener.class);
131 hostService = new TestHostService(); 127 hostService = new TestHostService();
132 deviceService = new TestDeviceService(); 128 deviceService = new TestDeviceService();
133 deviceListener = createMock(DeviceListener.class); 129 deviceListener = createMock(DeviceListener.class);
134 hostListener = createMock(HostListener.class); 130 hostListener = createMock(HostListener.class);
131 + interfaceListener = createMock(InterfaceListener.class);
135 hostService.addListener(hostListener); 132 hostService.addListener(hostListener);
136 deviceService.addListener(deviceListener); 133 deviceService.addListener(deviceListener);
137 setUpInterfaceService(); 134 setUpInterfaceService();
135 + interfaceService = new InternalInterfaceService();
136 + interfaceService.addListener(interfaceListener);
138 networkConfigService = new TestNetworkConfigService(); 137 networkConfigService = new TestNetworkConfigService();
139 networkConfigService.addListener(networkConfigListener); 138 networkConfigService.addListener(networkConfigListener);
140 flowObjectiveService = createMock(FlowObjectiveService.class); 139 flowObjectiveService = createMock(FlowObjectiveService.class);
141 setUpFlowObjectiveService(); 140 setUpFlowObjectiveService();
142 -
143 controlPlaneRedirectManager.coreService = coreService; 141 controlPlaneRedirectManager.coreService = coreService;
144 controlPlaneRedirectManager.flowObjectiveService = flowObjectiveService; 142 controlPlaneRedirectManager.flowObjectiveService = flowObjectiveService;
145 controlPlaneRedirectManager.networkConfigService = networkConfigService; 143 controlPlaneRedirectManager.networkConfigService = networkConfigService;
...@@ -150,98 +148,167 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -150,98 +148,167 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
150 controlPlaneRedirectManager.activate(); 148 controlPlaneRedirectManager.activate();
151 verify(flowObjectiveService); 149 verify(flowObjectiveService);
152 } 150 }
151 +
152 + /**
153 + * Tests adding new Device to a openflow router.
154 + */
155 + @Test
156 + public void testAddDevice() {
157 + ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4));
158 + Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
159 + interfaceIpAddresses4
160 + .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
161 +
162 + Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
163 + MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
164 + interfaces.add(sw1Eth4);
165 + EasyMock.reset(flowObjectiveService);
166 + setUpFlowObjectiveService();
167 + deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3));
168 + verify(flowObjectiveService);
169 + }
170 +
171 + /**
172 + * Tests adding while updating the networkConfig.
173 + */
174 + @Test
175 + public void testUpdateNetworkConfig() {
176 + ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4));
177 + Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
178 + interfaceIpAddresses4
179 + .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
180 +
181 + Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
182 + MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
183 + interfaces.add(sw1Eth4);
184 + EasyMock.reset(flowObjectiveService);
185 + setUpFlowObjectiveService();
186 + networkConfigListener
187 + .event(new NetworkConfigEvent(Type.CONFIG_UPDATED, dev3, RoutingService.ROUTER_CONFIG_CLASS));
188 + networkConfigService.addListener(networkConfigListener);
189 + verify(flowObjectiveService);
190 + }
191 +
153 /** 192 /**
154 - * setup flow Configuration for all configured Interfaces. 193 + * Tests adding while updating the networkConfig.
194 + */
195 + @Test
196 + public void testAddInterface() {
197 + ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4));
198 + Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
199 + interfaceIpAddresses4
200 + .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
201 +
202 + Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
203 + MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
204 + interfaces.add(sw1Eth4);
205 +
206 + EasyMock.reset(flowObjectiveService);
207 + expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes();
208 +
209 + setUpInterfaceConfiguration(sw1Eth4, true);
210 + replay(flowObjectiveService);
211 + interfaceListener.event(new InterfaceEvent(
212 + org.onosproject.incubator.net.intf.InterfaceEvent.Type.INTERFACE_ADDED, sw1Eth4, 500L));
213 + verify(flowObjectiveService);
214 + }
215 +
216 + @Test
217 + public void testRemoveInterface() {
218 + ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4));
219 + Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
220 + interfaceIpAddresses4
221 + .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
222 +
223 + Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
224 + MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
225 + EasyMock.reset(flowObjectiveService);
226 + expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes();
227 +
228 + setUpInterfaceConfiguration(sw1Eth4, false);
229 + replay(flowObjectiveService);
230 + interfaceListener.event(new InterfaceEvent(
231 + org.onosproject.incubator.net.intf.InterfaceEvent.Type.INTERFACE_REMOVED, sw1Eth4, 500L));
232 + verify(flowObjectiveService);
233 + }
234 +
235 + /**
236 + * Setup flow Configuration for all configured Interfaces.
155 * 237 *
156 **/ 238 **/
157 private void setUpFlowObjectiveService() { 239 private void setUpFlowObjectiveService() {
158 -
159 expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes(); 240 expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes();
160 - DeviceId deviceId = controlPlaneConnectPoint.deviceId();
161 - PortNumber controlPlanePort = controlPlaneConnectPoint.port();
162 - int cpNextId, intfNextId;
163 for (Interface intf : interfaceService.getInterfaces()) { 241 for (Interface intf : interfaceService.getInterfaces()) {
164 - for (InterfaceIpAddress ip : intf.ipAddresses()) { 242 + setUpInterfaceConfiguration(intf, true);
165 - if (intf.vlan() == VlanId.NONE) {
166 - // cpNextId = 1;
167 - // intfNextId = 1;
168 - cpNextId = createNextObjective(deviceId, controlPlanePort,
169 - VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), true);
170 - intfNextId = createNextObjective(deviceId, intf.connectPoint().port(),
171 - VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), true);
172 - } else {
173 - // cpNextId = 1;
174 - // intfNextId = 1;
175 -
176 - cpNextId = createNextObjective(deviceId, controlPlanePort, intf.vlan(), false);
177 - intfNextId = createNextObjective(deviceId, intf.connectPoint().port(), intf.vlan(), false);
178 - }
179 - TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port())
180 - .matchEthDst(intf.mac()).matchEthType(EthType.EtherType.IPV4.ethType().toShort())
181 - .matchVlanId(intf.vlan()).matchIPDst(ip.ipAddress().toIpPrefix()).build();
182 - flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, null, cpNextId, true));
183 - expectLastCall().once();
184 - // IPv4 from router
185 - TrafficSelector fromSelector = DefaultTrafficSelector.builder().matchInPort(controlPlanePort)
186 - .matchEthSrc(intf.mac()).matchVlanId(intf.vlan())
187 - .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
188 - .matchIPSrc(ip.ipAddress().toIpPrefix()).build();
189 - flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, null, intfNextId, true));
190 - expectLastCall().once();
191 - // ARP to router
192 - toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port())
193 - .matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchVlanId(intf.vlan()).build();
194 -
195 - TrafficTreatment puntTreatment = DefaultTrafficTreatment.builder().punt().build();
196 - flowObjectiveService.forward(deviceId,
197 - buildForwardingObjective(toSelector, puntTreatment, cpNextId, true));
198 - expectLastCall().once();
199 - // ARP from router
200 - fromSelector = DefaultTrafficSelector.builder().matchInPort(controlPlanePort).matchEthSrc(intf.mac())
201 - .matchVlanId(intf.vlan()).matchEthType(EthType.EtherType.ARP.ethType().toShort())
202 - .matchArpSpa(ip.ipAddress().getIp4Address()).build();
203 - flowObjectiveService.forward(deviceId,
204 - buildForwardingObjective(fromSelector, puntTreatment, intfNextId, true));
205 - expectLastCall().once();
206 -
207 - }
208 - updateOspfForwarding(intf);
209 } 243 }
210 -
211 replay(flowObjectiveService); 244 replay(flowObjectiveService);
212 } 245 }
213 246
214 /** 247 /**
215 - * setup expectations on flowobjectService.forward for ospfForwarding. 248 + * Setting up flowobjective expectations for basic forwarding and ospf.
216 - *
217 **/ 249 **/
218 - private void updateOspfForwarding(Interface intf) { 250 + private void setUpInterfaceConfiguration(Interface intf, boolean install) {
219 - // OSPF to router 251 + DeviceId deviceId = controlPlaneConnectPoint.deviceId();
252 + PortNumber controlPlanePort = controlPlaneConnectPoint.port();
253 +
254 + for (InterfaceIpAddress ip : intf.ipAddresses()) {
255 + int cpNextId, intfNextId;
256 +
257 + cpNextId = modifyNextObjective(deviceId, controlPlanePort,
258 + VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), true, install);
259 + intfNextId = modifyNextObjective(deviceId, intf.connectPoint().port(),
260 + VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), true, install);
261 +
262 + // IPv4 to router
263 + TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port())
264 + .matchEthDst(intf.mac()).matchEthType(EthType.EtherType.IPV4.ethType().toShort())
265 + .matchVlanId(intf.vlan()).matchIPDst(ip.ipAddress().toIpPrefix()).build();
266 +
267 + flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, null, cpNextId, install));
268 + expectLastCall().once();
269 + // IPv4 from router
270 + TrafficSelector fromSelector = DefaultTrafficSelector.builder().matchInPort(controlPlanePort)
271 + .matchEthSrc(intf.mac()).matchVlanId(intf.vlan())
272 + .matchEthType(EthType.EtherType.IPV4.ethType().toShort()).matchIPSrc(ip.ipAddress().toIpPrefix())
273 + .build();
274 +
275 + flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, null, intfNextId, install));
276 + expectLastCall().once();
277 + // ARP to router
278 + toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port())
279 + .matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchVlanId(intf.vlan()).build();
280 +
281 + TrafficTreatment puntTreatment = DefaultTrafficTreatment.builder().punt().build();
282 +
283 + flowObjectiveService.forward(deviceId,
284 + buildForwardingObjective(toSelector, puntTreatment, cpNextId, install));
285 + expectLastCall().once();
286 + // ARP from router
287 + fromSelector = DefaultTrafficSelector.builder().matchInPort(controlPlanePort).matchEthSrc(intf.mac())
288 + .matchVlanId(intf.vlan()).matchEthType(EthType.EtherType.ARP.ethType().toShort())
289 + .matchArpSpa(ip.ipAddress().getIp4Address()).build();
290 +
291 + flowObjectiveService.forward(deviceId,
292 + buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install));
293 + expectLastCall().once();
294 + }
295 + // setting expectations for ospf forwarding.
220 TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port()) 296 TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port())
221 .matchEthType(EthType.EtherType.IPV4.ethType().toShort()).matchVlanId(intf.vlan()) 297 .matchEthType(EthType.EtherType.IPV4.ethType().toShort()).matchVlanId(intf.vlan())
222 .matchIPProtocol((byte) OSPF_IP_PROTO).build(); 298 .matchIPProtocol((byte) OSPF_IP_PROTO).build();
223 299
224 - PortNumber controlPlanePort = controlPlaneConnectPoint.port(); 300 + modifyNextObjective(deviceId, controlPlanePort, VlanId.vlanId((short) 4094), true, install);
225 - DeviceId deviceId = controlPlaneConnectPoint.deviceId();
226 - int cpNextId;
227 - if (intf.vlan() == VlanId.NONE) {
228 - cpNextId = createNextObjective(deviceId, controlPlanePort,
229 - VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN), true);
230 - } else {
231 - cpNextId = createNextObjective(deviceId, controlPlanePort, intf.vlan(), false);
232 - }
233 - log.debug("ospf flows intf:{} nextid:{}", intf, cpNextId);
234 flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(), 301 flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(),
235 - buildForwardingObjective(toSelector, null, cpNextId, true)); 302 + buildForwardingObjective(toSelector, null, 1, install));
236 expectLastCall().once(); 303 expectLastCall().once();
237 } 304 }
238 305
239 /** 306 /**
240 - * setup expectations on flowObjectiveService.next for NextObjective. 307 + * Setup expectations on flowObjectiveService.next for NextObjective.
241 * 308 *
242 **/ 309 **/
243 - private int createNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan) { 310 + private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan,
244 - 311 + boolean modifyFlag) {
245 NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(1) 312 NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(1)
246 .withType(NextObjective.Type.SIMPLE).fromApp(APPID); 313 .withType(NextObjective.Type.SIMPLE).fromApp(APPID);
247 314
...@@ -251,25 +318,25 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -251,25 +318,25 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
251 } 318 }
252 ttBuilder.setOutput(portNumber); 319 ttBuilder.setOutput(portNumber);
253 320
254 - // setup metadata to pass to nextObjective - indicate the vlan on egress
255 - // if needed by the switch pipeline.
256 TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); 321 TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
257 metabuilder.matchVlanId(vlanId); 322 metabuilder.matchVlanId(vlanId);
258 323
259 nextObjBuilder.withMeta(metabuilder.build()); 324 nextObjBuilder.withMeta(metabuilder.build());
260 nextObjBuilder.addTreatment(ttBuilder.build()); 325 nextObjBuilder.addTreatment(ttBuilder.build());
261 - log.debug("Submited next objective {} in device {} for port/vlan {}/{}", 1, deviceId, portNumber, vlanId); 326 + if (modifyFlag) {
262 - flowObjectiveService.next(deviceId, nextObjBuilder.add()); 327 + flowObjectiveService.next(deviceId, nextObjBuilder.add());
263 - expectLastCall().once(); 328 + expectLastCall().once();
329 + } else {
330 + flowObjectiveService.next(deviceId, nextObjBuilder.remove());
331 + expectLastCall().once();
332 + }
264 return 1; 333 return 1;
265 } 334 }
266 335
267 /** 336 /**
268 - * setup Interface expectation for all Testcases. 337 + * Setup Interface expectation for all Testcases.
269 - *
270 **/ 338 **/
271 private void setUpInterfaceService() { 339 private void setUpInterfaceService() {
272 -
273 Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); 340 Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
274 interfaceIpAddresses1 341 interfaceIpAddresses1
275 .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), IpPrefix.valueOf("192.168.10.0/24"))); 342 .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), IpPrefix.valueOf("192.168.10.0/24")));
...@@ -291,90 +358,8 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -291,90 +358,8 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
291 MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE); 358 MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE);
292 interfaces.add(sw1Eth3); 359 interfaces.add(sw1Eth3);
293 360
294 - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(Collections.singleton(sw1Eth1)).anyTimes();
295 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))).andReturn(sw1Eth1).anyTimes();
296 - expect(interfaceService.getInterfacesByPort(SW1_ETH2)).andReturn(Collections.singleton(sw1Eth2)).anyTimes();
297 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))).andReturn(sw1Eth2).anyTimes();
298 -
299 - expect(interfaceService.getInterfacesByPort(SW1_ETH3)).andReturn(Collections.singleton(sw1Eth3)).anyTimes();
300 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))).andReturn(sw1Eth3).anyTimes();
301 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
302 - replay(interfaceService);
303 - interfaceService.getInterfaces();
304 - verify(interfaceService);
305 - }
306 -
307 - /**
308 - * Tests adding new Device to a controlplane.
309 - *
310 - * @throws SecurityException
311 - * @throws NoSuchFieldException
312 - * @throws IllegalAccessException
313 - * @throws IllegalArgumentException
314 - */
315 -
316 - @Test
317 - public void testAddDevice()
318 - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
319 -
320 - ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4));
321 - Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
322 - interfaceIpAddresses4
323 - .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
324 -
325 - Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
326 - MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
327 - interfaces.add(sw1Eth4);
328 - EasyMock.reset(interfaceService);
329 - expect(interfaceService.getInterfacesByPort(sw1eth4)).andReturn(Collections.singleton(sw1Eth4)).anyTimes();
330 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1"))).andReturn(sw1Eth4).anyTimes();
331 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
332 - replay(interfaceService);
333 - interfaceService.getInterfaces();
334 - EasyMock.reset(flowObjectiveService);
335 - setUpFlowObjectiveService();
336 - deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3));
337 - deviceService.addListener(deviceListener);
338 -
339 - verify(flowObjectiveService);
340 } 361 }
341 362
342 - /**
343 - * Tests adding while updating the networkConfig.
344 - *
345 - * @throws SecurityException
346 - * @throws NoSuchFieldException
347 - * @throws IllegalAccessException
348 - * @throws IllegalArgumentException
349 - */
350 - @Test
351 - public void testUpdateNetworkConfig()
352 - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
353 -
354 - ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4));
355 - Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet();
356 - interfaceIpAddresses4
357 - .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
358 -
359 - Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses4,
360 - MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
361 - interfaces.add(sw1Eth4);
362 - EasyMock.reset(interfaceService);
363 - expect(interfaceService.getInterfacesByPort(sw1eth4)).andReturn(Collections.singleton(sw1Eth4)).anyTimes();
364 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1"))).andReturn(sw1Eth4).anyTimes();
365 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
366 - replay(interfaceService);
367 - interfaceService.getInterfaces();
368 - EasyMock.reset(flowObjectiveService);
369 - setUpFlowObjectiveService();
370 - networkConfigListener
371 - .event(new NetworkConfigEvent(Type.CONFIG_UPDATED, dev3, RoutingService.ROUTER_CONFIG_CLASS));
372 - // deviceService.addListener(deviceListener);
373 - networkConfigService.addListener(networkConfigListener);
374 - verify(flowObjectiveService);
375 - }
376 -
377 -
378 private ForwardingObjective buildForwardingObjective(TrafficSelector selector, TrafficTreatment treatment, 363 private ForwardingObjective buildForwardingObjective(TrafficSelector selector, TrafficTreatment treatment,
379 int nextId, boolean add) { 364 int nextId, boolean add) {
380 DefaultForwardingObjective.Builder fobBuilder = DefaultForwardingObjective.builder(); 365 DefaultForwardingObjective.Builder fobBuilder = DefaultForwardingObjective.builder();
...@@ -390,11 +375,8 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -390,11 +375,8 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
390 return add ? fobBuilder.add() : fobBuilder.remove(); 375 return add ? fobBuilder.add() : fobBuilder.remove();
391 } 376 }
392 377
393 - /**
394 - * @param intf
395 - */
396 -
397 private class TestCoreService extends CoreServiceAdapter { 378 private class TestCoreService extends CoreServiceAdapter {
379 +
398 @Override 380 @Override
399 public ApplicationId getAppId(String name) { 381 public ApplicationId getAppId(String name) {
400 return APPID; 382 return APPID;
...@@ -402,7 +384,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -402,7 +384,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
402 384
403 @Override 385 @Override
404 public ApplicationId registerApplication(String name) { 386 public ApplicationId registerApplication(String name) {
405 - // TODO Auto-generated method stub
406 return new TestApplicationId(name); 387 return new TestApplicationId(name);
407 } 388 }
408 389
...@@ -412,7 +393,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -412,7 +393,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
412 393
413 @Override 394 @Override
414 public boolean isAvailable(DeviceId deviceId) { 395 public boolean isAvailable(DeviceId deviceId) {
415 - // TODO Auto-generated method stub
416 boolean flag = false; 396 boolean flag = false;
417 if (deviceId.equals(controlPlaneConnectPoint.deviceId())) { 397 if (deviceId.equals(controlPlaneConnectPoint.deviceId())) {
418 flag = true; 398 flag = true;
...@@ -422,7 +402,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -422,7 +402,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
422 402
423 @Override 403 @Override
424 public void addListener(DeviceListener listener) { 404 public void addListener(DeviceListener listener) {
425 - // TODO Auto-generated method stub
426 ControlPlaneRedirectManagerTest.this.deviceListener = listener; 405 ControlPlaneRedirectManagerTest.this.deviceListener = listener;
427 } 406 }
428 407
...@@ -432,7 +411,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -432,7 +411,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
432 411
433 @Override 412 @Override
434 public void addListener(HostListener listener) { 413 public void addListener(HostListener listener) {
435 - // TODO Auto-generated method stub
436 ControlPlaneRedirectManagerTest.this.hostListener = listener; 414 ControlPlaneRedirectManagerTest.this.hostListener = listener;
437 } 415 }
438 416
...@@ -442,20 +420,16 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -442,20 +420,16 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
442 420
443 @Override 421 @Override
444 public ConnectPoint getControlPlaneConnectPoint() { 422 public ConnectPoint getControlPlaneConnectPoint() {
445 - // TODO Auto-generated method stub
446 return controlPlaneConnectPoint; 423 return controlPlaneConnectPoint;
447 } 424 }
448 425
449 @Override 426 @Override
450 public boolean getOspfEnabled() { 427 public boolean getOspfEnabled() {
451 - // TODO Auto-generated method stub
452 return true; 428 return true;
453 } 429 }
454 430
455 @Override 431 @Override
456 public List<String> getInterfaces() { 432 public List<String> getInterfaces() {
457 - // TODO Auto-generated method stub
458 -
459 ArrayList<String> interfaces = new ArrayList<>(); 433 ArrayList<String> interfaces = new ArrayList<>();
460 interfaces.add("of:0000000000000001"); 434 interfaces.add("of:0000000000000001");
461 interfaces.add("of:0000000000000001/2"); 435 interfaces.add("of:0000000000000001/2");
...@@ -469,14 +443,11 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -469,14 +443,11 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
469 443
470 @Override 444 @Override
471 public void addListener(NetworkConfigListener listener) { 445 public void addListener(NetworkConfigListener listener) {
472 - // TODO Auto-generated method stub
473 ControlPlaneRedirectManagerTest.this.networkConfigListener = listener; 446 ControlPlaneRedirectManagerTest.this.networkConfigListener = listener;
474 } 447 }
475 448
476 @Override 449 @Override
477 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { 450 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
478 - // TODO Auto-generated method stub
479 -
480 return (C) ControlPlaneRedirectManagerTest.this.routerConfig; 451 return (C) ControlPlaneRedirectManagerTest.this.routerConfig;
481 } 452 }
482 453
...@@ -533,7 +504,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -533,7 +504,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
533 if (name == null) { 504 if (name == null) {
534 if (other.name != null) { 505 if (other.name != null) {
535 return false; 506 return false;
536 - } 507 + }
537 } else if (!name.equals(other.name)) { 508 } else if (!name.equals(other.name)) {
538 return false; 509 return false;
539 } 510 }
...@@ -545,10 +516,49 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { ...@@ -545,10 +516,49 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest {
545 516
546 @Override 517 @Override
547 public boolean isLocalMaster(DeviceId deviceId) { 518 public boolean isLocalMaster(DeviceId deviceId) {
548 - // TODO Auto-generated method stub
549 boolean flag = deviceId.equals(controlPlaneConnectPoint.deviceId()); 519 boolean flag = deviceId.equals(controlPlaneConnectPoint.deviceId());
550 return flag; 520 return flag;
551 } 521 }
552 522
553 } 523 }
524 +
525 + private class InternalInterfaceService extends InterfaceServiceAdapter {
526 +
527 + @Override
528 + public void addListener(InterfaceListener listener) {
529 + ControlPlaneRedirectManagerTest.this.interfaceListener = listener;
530 + }
531 +
532 + @Override
533 + public Set<Interface> getInterfaces() {
534 + return interfaces;
535 + }
536 +
537 + @Override
538 + public Set<Interface> getInterfacesByPort(ConnectPoint port) {
539 + Set<Interface> setIntf = new HashSet<Interface>();
540 + for (Interface intf : interfaces) {
541 + if (intf.connectPoint().equals(port)) {
542 + setIntf.add(intf);
543 + }
544 + }
545 + return setIntf;
546 + }
547 +
548 + @Override
549 + public Interface getMatchingInterface(IpAddress ip) {
550 + Interface intff = null;
551 + for (Interface intf : interfaces) {
552 + for (InterfaceIpAddress address : intf.ipAddresses()) {
553 + if (address.ipAddress().equals(ip)) {
554 + intff = intf;
555 + break;
556 + }
557 + }
558 + }
559 +
560 + return intff;
561 + }
562 +
563 + }
554 } 564 }
......