Jonathan Hart

BgpRouter: Added treatment to delete flows

Deleting routes now works.

Change-Id: I7ed682474e571aa2f402a1762a2037190c2d9284
......@@ -211,18 +211,7 @@ public class BgpRouter {
}
private void installFlow(FibEntry entry, Group group) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(entry.prefix())
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.group(group.id())
.build();
FlowRule flowRule = new DefaultFlowRule(deviceId, selector, treatment,
PRIORITY, appId, 0, true,
FlowRule.Type.IP);
FlowRule flowRule = generateRibFlowRule(entry.prefix(), group);
flowService.applyFlowRules(flowRule);
}
......@@ -231,21 +220,33 @@ public class BgpRouter {
for (FibUpdate update : withdraws) {
FibEntry entry = update.entry();
deleteNextHop(entry.prefix());
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(update.entry().prefix())
.build();
Group group = deleteNextHop(entry.prefix());
if (group == null) {
log.warn("Group not found when deleting {}", entry);
return;
}
FlowRule flowRule = new DefaultFlowRule(deviceId, selector, null,
PRIORITY, appId, 0, true,
FlowRule.Type.IP);
FlowRule flowRule = generateRibFlowRule(entry.prefix(), group);
flowService.removeFlowRules(flowRule);
}
}
private FlowRule generateRibFlowRule(IpPrefix prefix, Group group) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(prefix)
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.group(group.id())
.build();
return new DefaultFlowRule(deviceId, selector, treatment,
PRIORITY, appId, 0, true,
FlowRule.Type.IP);
}
private synchronized void addNextHop(FibEntry entry) {
prefixToNextHop.put(entry.prefix(), entry.nextHopIp());
if (nextHopsCount.count(entry.nextHopIp()) == 0) {
......@@ -288,14 +289,16 @@ public class BgpRouter {
nextHopsCount.add(entry.nextHopIp());
}
private synchronized void deleteNextHop(IpPrefix prefix) {
private synchronized Group deleteNextHop(IpPrefix prefix) {
IpAddress nextHopIp = prefixToNextHop.remove(prefix);
NextHop nextHop = nextHops.get(nextHopIp);
if (nextHop == null) {
log.warn("No next hop found when removing prefix {}", prefix);
return;
return null;
}
Group group = groupService.getGroup(deviceId, nextHop.group());
if (nextHopsCount.remove(nextHopIp, 1) <= 1) {
// There was one or less next hops, so there are now none
......@@ -305,6 +308,8 @@ public class BgpRouter {
groupService.removeGroup(deviceId, nextHop.group(), appId);
}
return group;
}
private class InternalFibListener implements FibListener {
......
......@@ -180,6 +180,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.setTableId(TableId.of(flowRule().type().ordinal()))
.build();
return fm;
......