Committed by
Gerrit Code Review
BgpRouter: Add default flows for BGP traffic in control plane switch
Change-Id: Ia963b22c5a7460fb7fa2e75ddf66bcbb40004dca
Showing
2 changed files
with
55 additions
and
19 deletions
| ... | @@ -149,7 +149,8 @@ public class BgpRouter { | ... | @@ -149,7 +149,8 @@ public class BgpRouter { |
| 149 | 149 | ||
| 150 | connectivityManager = new TunnellingConnectivityManager(appId, | 150 | connectivityManager = new TunnellingConnectivityManager(appId, |
| 151 | configService, | 151 | configService, |
| 152 | - packetService); | 152 | + packetService, |
| 153 | + flowService); | ||
| 153 | 154 | ||
| 154 | routingService.start(new InternalFibListener()); | 155 | routingService.start(new InternalFibListener()); |
| 155 | 156 | ... | ... |
| ... | @@ -21,7 +21,12 @@ import org.onlab.packet.IpAddress; | ... | @@ -21,7 +21,12 @@ import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.TCP; | 21 | import org.onlab.packet.TCP; |
| 22 | import org.onosproject.core.ApplicationId; | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.ConnectPoint; | 23 | import org.onosproject.net.ConnectPoint; |
| 24 | +import org.onosproject.net.flow.DefaultFlowRule; | ||
| 25 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 24 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 26 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 27 | +import org.onosproject.net.flow.FlowRuleOperations; | ||
| 28 | +import org.onosproject.net.flow.FlowRuleService; | ||
| 29 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 25 | import org.onosproject.net.flow.TrafficTreatment; | 30 | import org.onosproject.net.flow.TrafficTreatment; |
| 26 | import org.onosproject.net.packet.DefaultOutboundPacket; | 31 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 27 | import org.onosproject.net.packet.OutboundPacket; | 32 | import org.onosproject.net.packet.OutboundPacket; |
| ... | @@ -32,8 +37,6 @@ import org.onosproject.routing.config.BgpPeer; | ... | @@ -32,8 +37,6 @@ import org.onosproject.routing.config.BgpPeer; |
| 32 | import org.onosproject.routing.config.BgpSpeaker; | 37 | import org.onosproject.routing.config.BgpSpeaker; |
| 33 | import org.onosproject.routing.config.InterfaceAddress; | 38 | import org.onosproject.routing.config.InterfaceAddress; |
| 34 | import org.onosproject.routing.config.RoutingConfigurationService; | 39 | import org.onosproject.routing.config.RoutingConfigurationService; |
| 35 | -import org.slf4j.Logger; | ||
| 36 | -import org.slf4j.LoggerFactory; | ||
| 37 | 40 | ||
| 38 | 41 | ||
| 39 | /** | 42 | /** |
| ... | @@ -46,6 +49,8 @@ public class TunnellingConnectivityManager { | ... | @@ -46,6 +49,8 @@ public class TunnellingConnectivityManager { |
| 46 | 49 | ||
| 47 | private final ApplicationId appId; | 50 | private final ApplicationId appId; |
| 48 | 51 | ||
| 52 | + private final BgpSpeaker bgpSpeaker; | ||
| 53 | + | ||
| 49 | private final PacketService packetService; | 54 | private final PacketService packetService; |
| 50 | private final RoutingConfigurationService configService; | 55 | private final RoutingConfigurationService configService; |
| 51 | 56 | ||
| ... | @@ -53,10 +58,46 @@ public class TunnellingConnectivityManager { | ... | @@ -53,10 +58,46 @@ public class TunnellingConnectivityManager { |
| 53 | 58 | ||
| 54 | public TunnellingConnectivityManager(ApplicationId appId, | 59 | public TunnellingConnectivityManager(ApplicationId appId, |
| 55 | RoutingConfigurationService configService, | 60 | RoutingConfigurationService configService, |
| 56 | - PacketService packetService) { | 61 | + PacketService packetService, |
| 62 | + FlowRuleService flowService) { | ||
| 57 | this.appId = appId; | 63 | this.appId = appId; |
| 58 | this.configService = configService; | 64 | this.configService = configService; |
| 59 | this.packetService = packetService; | 65 | this.packetService = packetService; |
| 66 | + | ||
| 67 | + BgpSpeaker bgpSpeaker = null; | ||
| 68 | + for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) { | ||
| 69 | + bgpSpeaker = speaker; | ||
| 70 | + break; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + if (bgpSpeaker == null) { | ||
| 74 | + throw new IllegalArgumentException("Must have at least one BGP speaker configured"); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + this.bgpSpeaker = bgpSpeaker; | ||
| 78 | + | ||
| 79 | + TrafficSelector selectorDst = DefaultTrafficSelector.builder() | ||
| 80 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
| 81 | + .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
| 82 | + .matchTcpDst(BGP_PORT) | ||
| 83 | + .build(); | ||
| 84 | + | ||
| 85 | + TrafficSelector selectorSrc = DefaultTrafficSelector.builder() | ||
| 86 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
| 87 | + .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
| 88 | + .matchTcpSrc(BGP_PORT) | ||
| 89 | + .build(); | ||
| 90 | + | ||
| 91 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
| 92 | + .punt() | ||
| 93 | + .build(); | ||
| 94 | + | ||
| 95 | + FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); | ||
| 96 | + builder.add(new DefaultFlowRule(bgpSpeaker.connectPoint().deviceId(), | ||
| 97 | + selectorSrc, treatment, 0, appId, 0, true)); | ||
| 98 | + builder.add(new DefaultFlowRule(bgpSpeaker.connectPoint().deviceId(), | ||
| 99 | + selectorDst, treatment, 0, appId, 0, true)); | ||
| 100 | + flowService.apply(builder.build()); | ||
| 60 | } | 101 | } |
| 61 | 102 | ||
| 62 | public void start() { | 103 | public void start() { |
| ... | @@ -74,27 +115,21 @@ public class TunnellingConnectivityManager { | ... | @@ -74,27 +115,21 @@ public class TunnellingConnectivityManager { |
| 74 | * @param context the packet context of the incoming packet | 115 | * @param context the packet context of the incoming packet |
| 75 | */ | 116 | */ |
| 76 | private void forward(PacketContext context) { | 117 | private void forward(PacketContext context) { |
| 77 | - | ||
| 78 | ConnectPoint outputPort = null; | 118 | ConnectPoint outputPort = null; |
| 79 | - Logger log = LoggerFactory.getLogger(getClass()); | ||
| 80 | - | ||
| 81 | 119 | ||
| 82 | IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload(); | 120 | IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload(); |
| 83 | IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress()); | 121 | IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress()); |
| 84 | 122 | ||
| 85 | - for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) { | 123 | + if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) { |
| 86 | - if (context.inPacket().receivedFrom().equals(speaker.connectPoint())) { | 124 | + BgpPeer peer = configService.getBgpPeers().get(dstAddress); |
| 87 | - BgpPeer peer = configService.getBgpPeers().get(dstAddress); | 125 | + if (peer != null) { |
| 88 | - if (peer != null) { | 126 | + outputPort = peer.connectPoint(); |
| 89 | - outputPort = peer.connectPoint(); | ||
| 90 | - } | ||
| 91 | - break; | ||
| 92 | } | 127 | } |
| 93 | - for (InterfaceAddress addr : speaker.interfaceAddresses()) { | 128 | + } |
| 94 | - if (addr.ipAddress().equals(dstAddress) && !context.inPacket() | 129 | + for (InterfaceAddress addr : bgpSpeaker.interfaceAddresses()) { |
| 95 | - .receivedFrom().equals(speaker.connectPoint())) { | 130 | + if (addr.ipAddress().equals(dstAddress) && !context.inPacket() |
| 96 | - outputPort = speaker.connectPoint(); | 131 | + .receivedFrom().equals(bgpSpeaker.connectPoint())) { |
| 97 | - } | 132 | + outputPort = bgpSpeaker.connectPoint(); |
| 98 | } | 133 | } |
| 99 | } | 134 | } |
| 100 | 135 | ... | ... |
-
Please register or login to post a comment