Jonathan Hart
Committed by Gerrit Code Review

BgpRouter: Add default flows for BGP traffic in control plane switch

Change-Id: Ia963b22c5a7460fb7fa2e75ddf66bcbb40004dca
......@@ -149,7 +149,8 @@ public class BgpRouter {
connectivityManager = new TunnellingConnectivityManager(appId,
configService,
packetService);
packetService,
flowService);
routingService.start(new InternalFibListener());
......
......@@ -21,7 +21,12 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.TCP;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.OutboundPacket;
......@@ -32,8 +37,6 @@ import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
import org.onosproject.routing.config.InterfaceAddress;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
......@@ -46,6 +49,8 @@ public class TunnellingConnectivityManager {
private final ApplicationId appId;
private final BgpSpeaker bgpSpeaker;
private final PacketService packetService;
private final RoutingConfigurationService configService;
......@@ -53,10 +58,46 @@ public class TunnellingConnectivityManager {
public TunnellingConnectivityManager(ApplicationId appId,
RoutingConfigurationService configService,
PacketService packetService) {
PacketService packetService,
FlowRuleService flowService) {
this.appId = appId;
this.configService = configService;
this.packetService = packetService;
BgpSpeaker bgpSpeaker = null;
for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) {
bgpSpeaker = speaker;
break;
}
if (bgpSpeaker == null) {
throw new IllegalArgumentException("Must have at least one BGP speaker configured");
}
this.bgpSpeaker = bgpSpeaker;
TrafficSelector selectorDst = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpDst(BGP_PORT)
.build();
TrafficSelector selectorSrc = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpSrc(BGP_PORT)
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.punt()
.build();
FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
builder.add(new DefaultFlowRule(bgpSpeaker.connectPoint().deviceId(),
selectorSrc, treatment, 0, appId, 0, true));
builder.add(new DefaultFlowRule(bgpSpeaker.connectPoint().deviceId(),
selectorDst, treatment, 0, appId, 0, true));
flowService.apply(builder.build());
}
public void start() {
......@@ -74,27 +115,21 @@ public class TunnellingConnectivityManager {
* @param context the packet context of the incoming packet
*/
private void forward(PacketContext context) {
ConnectPoint outputPort = null;
Logger log = LoggerFactory.getLogger(getClass());
IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) {
if (context.inPacket().receivedFrom().equals(speaker.connectPoint())) {
if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
BgpPeer peer = configService.getBgpPeers().get(dstAddress);
if (peer != null) {
outputPort = peer.connectPoint();
}
break;
}
for (InterfaceAddress addr : speaker.interfaceAddresses()) {
for (InterfaceAddress addr : bgpSpeaker.interfaceAddresses()) {
if (addr.ipAddress().equals(dstAddress) && !context.inPacket()
.receivedFrom().equals(speaker.connectPoint())) {
outputPort = speaker.connectPoint();
}
.receivedFrom().equals(bgpSpeaker.connectPoint())) {
outputPort = bgpSpeaker.connectPoint();
}
}
......