Jonathan Hart
Committed by Gerrit Code Review

Fix deleting VLANs on fabric

Change-Id: I980656b06c88c32551e549e8fd4b355ce9042a3e
...@@ -49,6 +49,7 @@ import org.slf4j.Logger; ...@@ -49,6 +49,7 @@ import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory; 49 import org.slf4j.LoggerFactory;
50 50
51 import java.util.ArrayList; 51 import java.util.ArrayList;
52 +import java.util.Collection;
52 import java.util.List; 53 import java.util.List;
53 import java.util.stream.Collectors; 54 import java.util.stream.Collectors;
54 55
...@@ -240,8 +241,13 @@ public class CordFabricManager implements FabricService { ...@@ -240,8 +241,13 @@ public class CordFabricManager implements FabricService {
240 241
241 @Override 242 @Override
242 public void removeVlan(VlanId vlanId) { 243 public void removeVlan(VlanId vlanId) {
243 - vlans.removeAll(vlanId) 244 + Collection<ConnectPoint> ports = vlans.removeAll(vlanId);
244 - .forEach(cp -> removeForwarding(vlanId, cp.deviceId(), cp.port())); 245 +
246 + ports.forEach(cp -> removeForwarding(vlanId, cp.deviceId(), cp.port(),
247 + ports.stream()
248 + .filter(p -> p != cp)
249 + .map(ConnectPoint::port)
250 + .collect(Collectors.toList())));
245 } 251 }
246 252
247 @Override 253 @Override
...@@ -287,19 +293,24 @@ public class CordFabricManager implements FabricService { ...@@ -287,19 +293,24 @@ public class CordFabricManager implements FabricService {
287 flowObjectiveService.forward(deviceId, objective); 293 flowObjectiveService.forward(deviceId, objective);
288 } 294 }
289 295
290 - private void removeForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort) { 296 + private void removeForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort,
297 + List<PortNumber> outPorts) {
291 TrafficSelector selector = DefaultTrafficSelector.builder() 298 TrafficSelector selector = DefaultTrafficSelector.builder()
292 .matchVlanId(vlanId) 299 .matchVlanId(vlanId)
293 .matchInPort(inPort) 300 .matchInPort(inPort)
294 .build(); 301 .build();
295 302
303 + TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
304 +
305 + outPorts.forEach(p -> treatmentBuilder.setOutput(p));
306 +
296 ForwardingObjective objective = DefaultForwardingObjective.builder() 307 ForwardingObjective objective = DefaultForwardingObjective.builder()
297 .fromApp(appId) 308 .fromApp(appId)
298 .makePermanent() 309 .makePermanent()
299 .withFlag(ForwardingObjective.Flag.VERSATILE) 310 .withFlag(ForwardingObjective.Flag.VERSATILE)
300 .withPriority(PRIORITY) 311 .withPriority(PRIORITY)
301 .withSelector(selector) 312 .withSelector(selector)
302 - .withTreatment(DefaultTrafficTreatment.builder().build()) 313 + .withTreatment(treatmentBuilder.build())
303 .remove(new ObjectiveHandler()); 314 .remove(new ObjectiveHandler());
304 315
305 flowObjectiveService.forward(deviceId, objective); 316 flowObjectiveService.forward(deviceId, objective);
......