sangho
Committed by Jonathan Hart

ONOS-1438: Improved the routing rule population process for link add and failure…

…; computes the routes changed from the link changes and populates the rules only for the routes.

Change-Id: Id4dbd80da37b333f2c19bc97333472dc8031481b
......@@ -139,6 +139,7 @@ public class IpHandler {
OutboundPacket packet = new DefaultOutboundPacket(deviceId,
treatment, ByteBuffer.wrap(eth.serialize()));
srManager.packetService.emit(packet);
ipPacketQueue.get(destIpAddress).remove(ipPacket);
}
}
}
......
......@@ -40,6 +40,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -47,8 +48,9 @@ public class RoutingRulePopulator {
private static final Logger log = LoggerFactory.getLogger(RoutingRulePopulator.class);
private SegmentRoutingManager srManager;
private NetworkConfigHandler config;
private final SegmentRoutingManager srManager;
private final NetworkConfigHandler config;
private AtomicLong rulePopulationCounter;
/**
* Creates a RoutingRulePopulator object.
......@@ -58,6 +60,21 @@ public class RoutingRulePopulator {
public RoutingRulePopulator(SegmentRoutingManager srManager) {
this.srManager = srManager;
this.config = checkNotNull(srManager.networkConfigHandler);
this.rulePopulationCounter = new AtomicLong(0);
}
/**
* Resets the population counter.
*/
public void resetCounter() {
rulePopulationCounter.set(0);
}
/**
* Returns the number of rules populated.
*/
public long getCounter() {
return rulePopulationCounter.get();
}
/**
......@@ -87,6 +104,7 @@ public class RoutingRulePopulator {
srManager.appId, 600, false, FlowRule.Type.IP);
srManager.flowRuleService.applyFlowRules(f);
rulePopulationCounter.incrementAndGet();
log.debug("Flow rule {} is set to switch {}", f, deviceId);
}
......@@ -162,6 +180,7 @@ public class RoutingRulePopulator {
srManager.appId, 600, false, FlowRule.Type.IP);
srManager.flowRuleService.applyFlowRules(f);
rulePopulationCounter.incrementAndGet();
log.debug("IP flow rule {} is set to switch {}", f, deviceId);
return true;
......@@ -216,6 +235,7 @@ public class RoutingRulePopulator {
FlowRule f = new DefaultFlowRule(deviceId, selector, treatment, 100,
srManager.appId, 600, false, FlowRule.Type.MPLS);
srManager.flowRuleService.applyFlowRules(f);
rulePopulationCounter.incrementAndGet();
log.debug("MPLS rule {} is set to {}", f, deviceId);
}
......
......@@ -151,8 +151,7 @@ public class SegmentRoutingManager {
groupHandler.createGroups();
groupHandlerMap.put(device.id(), groupHandler);
log.debug("Initiating default group handling for {}", device.id());
defaultRoutingHandler.startPopulationProcess();
defaultRoutingHandler.populateTtpRules(device.id());
} else {
log.debug("Activate: Local role {} "
+ "is not MASTER for device {}",
......@@ -162,6 +161,8 @@ public class SegmentRoutingManager {
}
}
defaultRoutingHandler.startPopulationProcess();
log.info("Started");
}
......@@ -239,6 +240,8 @@ public class SegmentRoutingManager {
switch (event.type()) {
case DEVICE_ADDED:
case PORT_REMOVED:
case DEVICE_UPDATED:
case DEVICE_AVAILABILITY_CHANGED:
scheduleEventHandlerIfNotScheduled(event);
break;
default:
......@@ -294,8 +297,12 @@ public class SegmentRoutingManager {
processLinkRemoved((Link) event.subject());
} else if (event.type() == GroupEvent.Type.GROUP_ADDED) {
processGroupAdded((Group) event.subject());
} else if (event.type() == DeviceEvent.Type.DEVICE_ADDED) {
processDeviceAdded((Device) event.subject());
} else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
if (deviceService.isAvailable(((Device) event.subject()).id())) {
processDeviceAdded((Device) event.subject());
}
} else if (event.type() == DeviceEvent.Type.PORT_REMOVED) {
processPortRemoved((Device) event.subject(),
((DeviceEvent) event).port());
......@@ -321,12 +328,12 @@ public class SegmentRoutingManager {
groupHandler.linkUp(link);
}
}
defaultRoutingHandler.startPopulationProcess();
defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null);
}
private void processLinkRemoved(Link link) {
log.debug("A link {} was removed", link.toString());
defaultRoutingHandler.startPopulationProcess();
defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link);
}
......