Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.sdnip; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.packet.IPv4; |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 20 | import org.onlab.packet.IPv6; |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 22 | import org.onlab.packet.IpPrefix; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 23 | import org.onlab.packet.TpPort; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.net.ConnectPoint; |
| 26 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 27 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 28 | import org.onosproject.net.flow.TrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
Jonathan Hart | 2a9ea49 | 2015-07-30 15:53:04 -0700 | [diff] [blame] | 30 | import org.onosproject.net.host.InterfaceIpAddress; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.intent.PointToPointIntent; |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 32 | import org.onosproject.routing.config.BgpPeer; |
| 33 | import org.onosproject.routing.config.BgpSpeaker; |
| 34 | import org.onosproject.routing.config.Interface; |
| 35 | import org.onosproject.routing.config.InterfaceAddress; |
| 36 | import org.onosproject.routing.config.RoutingConfigurationService; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 37 | import org.slf4j.Logger; |
| 38 | import org.slf4j.LoggerFactory; |
| 39 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 40 | import java.util.ArrayList; |
| 41 | import java.util.Collection; |
| 42 | import java.util.List; |
| 43 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Manages the connectivity requirements between peers. |
| 46 | */ |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 47 | public class PeerConnectivityManager { |
Pavlin Radoslavov | 2aa1f32 | 2015-03-11 17:59:44 -0700 | [diff] [blame] | 48 | private static final int PRIORITY_OFFSET = 1000; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 49 | |
| 50 | private static final Logger log = LoggerFactory.getLogger( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 51 | PeerConnectivityManager.class); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 52 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 53 | private static final short BGP_PORT = 179; |
| 54 | |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 55 | private final IntentSynchronizer intentSynchronizer; |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 56 | private final RoutingConfigurationService configService; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 57 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 58 | private final ApplicationId appId; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 59 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 60 | /** |
| 61 | * Creates a new PeerConnectivityManager. |
| 62 | * |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 63 | * @param appId the application ID |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 64 | * @param intentSynchronizer the intent synchronizer |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 65 | * @param configService the SDN-IP config service |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 66 | */ |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 67 | public PeerConnectivityManager(ApplicationId appId, |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 68 | IntentSynchronizer intentSynchronizer, |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 69 | RoutingConfigurationService configService) { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 70 | this.appId = appId; |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 71 | this.intentSynchronizer = intentSynchronizer; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 72 | this.configService = configService; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Starts the peer connectivity manager. |
| 77 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 78 | public void start() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 79 | if (configService.getInterfaces().isEmpty()) { |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 80 | log.warn("No interfaces found in configuration file"); |
Jonathan Hart | de08912 | 2014-12-03 22:33:14 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if (configService.getBgpPeers().isEmpty()) { |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 84 | log.warn("No BGP peers found in configuration file"); |
Jonathan Hart | de08912 | 2014-12-03 22:33:14 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | if (configService.getBgpSpeakers().isEmpty()) { |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 88 | log.error("No BGP speakers found in configuration file"); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 91 | setUpConnectivity(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 95 | * Stops the peer connectivity manager. |
| 96 | */ |
| 97 | public void stop() { |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 101 | * Sets up paths to establish connectivity between all internal |
| 102 | * {@link BgpSpeaker}s and all external {@link BgpPeer}s. |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 103 | */ |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 104 | private void setUpConnectivity() { |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 105 | List<PointToPointIntent> intents = new ArrayList<>(); |
| 106 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 107 | for (BgpSpeaker bgpSpeaker : configService.getBgpSpeakers() |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 108 | .values()) { |
| 109 | log.debug("Start to set up BGP paths for BGP speaker: {}", |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 110 | bgpSpeaker); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 111 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 112 | for (BgpPeer bgpPeer : configService.getBgpPeers().values()) { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 113 | |
| 114 | log.debug("Start to set up BGP paths between BGP speaker: {} " |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 115 | + "to BGP peer: {}", bgpSpeaker, bgpPeer); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 116 | |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 117 | intents.addAll(buildPeerIntents(bgpSpeaker, bgpPeer)); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 120 | |
| 121 | // Submit all the intents. |
| 122 | intentSynchronizer.submitPeerIntents(intents); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /** |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 126 | * Builds the required intents between a given internal BGP speaker and |
| 127 | * external BGP peer. |
| 128 | * |
| 129 | * @param bgpSpeaker the BGP speaker |
| 130 | * @param bgpPeer the BGP peer |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 131 | * @return the intents to install |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 132 | */ |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 133 | private Collection<PointToPointIntent> buildPeerIntents( |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 134 | BgpSpeaker bgpSpeaker, |
| 135 | BgpPeer bgpPeer) { |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 136 | List<PointToPointIntent> intents = new ArrayList<>(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 137 | |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 138 | ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 139 | |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 140 | List<InterfaceAddress> interfaceAddresses = |
| 141 | bgpSpeaker.interfaceAddresses(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 142 | |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 143 | IpAddress bgpdAddress = null; |
| 144 | for (InterfaceAddress interfaceAddress : interfaceAddresses) { |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 145 | Interface peerInterface = configService.getInterface(interfaceAddress.ipAddress()); |
| 146 | if (peerInterface == null) { |
| 147 | continue; |
| 148 | } |
| 149 | |
| 150 | for (InterfaceIpAddress interfaceIpAddress : peerInterface.ipAddresses()) { |
| 151 | // Only add intents where the peer and ONOS's addresses are |
| 152 | // in the same subnet |
| 153 | if (interfaceIpAddress.subnetAddress().contains(bgpPeer.ipAddress())) { |
| 154 | bgpdAddress = interfaceAddress.ipAddress(); |
| 155 | break; |
Jonathan Hart | 2a9ea49 | 2015-07-30 15:53:04 -0700 | [diff] [blame] | 156 | } |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 157 | } |
| 158 | if (bgpdAddress != null) { |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 159 | break; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 160 | } |
| 161 | } |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 162 | if (bgpdAddress == null) { |
| 163 | log.debug("No IP address found for peer {} on interface {}", |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 164 | bgpPeer, bgpPeer.connectPoint()); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 165 | return intents; |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 169 | ConnectPoint bgpdPeerConnectPoint = bgpPeer.connectPoint(); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 170 | |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 171 | if (bgpdAddress.version() != bgpdPeerAddress.version()) { |
| 172 | return intents; |
| 173 | } |
| 174 | |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 175 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 176 | |
| 177 | TrafficSelector selector; |
| 178 | |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 179 | byte tcpProtocol; |
| 180 | byte icmpProtocol; |
| 181 | |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 182 | if (bgpdAddress.isIp4()) { |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 183 | tcpProtocol = IPv4.PROTOCOL_TCP; |
| 184 | icmpProtocol = IPv4.PROTOCOL_ICMP; |
| 185 | } else { |
| 186 | tcpProtocol = IPv6.PROTOCOL_TCP; |
| 187 | icmpProtocol = IPv6.PROTOCOL_ICMP6; |
| 188 | } |
| 189 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 190 | // Path from BGP speaker to BGP peer matching destination TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 191 | selector = buildSelector(tcpProtocol, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 192 | bgpdAddress, |
| 193 | bgpdPeerAddress, |
| 194 | null, |
| 195 | BGP_PORT); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 196 | |
Pavlin Radoslavov | 2aa1f32 | 2015-03-11 17:59:44 -0700 | [diff] [blame] | 197 | int priority = PRIORITY_OFFSET; |
| 198 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 199 | intents.add(PointToPointIntent.builder() |
| 200 | .appId(appId) |
| 201 | .selector(selector) |
| 202 | .treatment(treatment) |
| 203 | .ingressPoint(bgpdConnectPoint) |
| 204 | .egressPoint(bgpdPeerConnectPoint) |
| 205 | .priority(priority) |
| 206 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 207 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 208 | // Path from BGP speaker to BGP peer matching source TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 209 | selector = buildSelector(tcpProtocol, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 210 | bgpdAddress, |
| 211 | bgpdPeerAddress, |
| 212 | BGP_PORT, |
| 213 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 214 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 215 | intents.add(PointToPointIntent.builder() |
| 216 | .appId(appId) |
| 217 | .selector(selector) |
| 218 | .treatment(treatment) |
| 219 | .ingressPoint(bgpdConnectPoint) |
| 220 | .egressPoint(bgpdPeerConnectPoint) |
| 221 | .priority(priority) |
| 222 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 223 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 224 | // Path from BGP peer to BGP speaker matching destination TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 225 | selector = buildSelector(tcpProtocol, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 226 | bgpdPeerAddress, |
| 227 | bgpdAddress, |
| 228 | null, |
| 229 | BGP_PORT); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 230 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 231 | intents.add(PointToPointIntent.builder() |
| 232 | .appId(appId) |
| 233 | .selector(selector) |
| 234 | .treatment(treatment) |
| 235 | .ingressPoint(bgpdPeerConnectPoint) |
| 236 | .egressPoint(bgpdConnectPoint) |
| 237 | .priority(priority) |
| 238 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 239 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 240 | // Path from BGP peer to BGP speaker matching source TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 241 | selector = buildSelector(tcpProtocol, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 242 | bgpdPeerAddress, |
| 243 | bgpdAddress, |
| 244 | BGP_PORT, |
| 245 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 246 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 247 | intents.add(PointToPointIntent.builder() |
| 248 | .appId(appId) |
| 249 | .selector(selector) |
| 250 | .treatment(treatment) |
| 251 | .ingressPoint(bgpdPeerConnectPoint) |
| 252 | .egressPoint(bgpdConnectPoint) |
| 253 | .priority(priority) |
| 254 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 255 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 256 | // ICMP path from BGP speaker to BGP peer |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 257 | selector = buildSelector(icmpProtocol, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 258 | bgpdAddress, |
| 259 | bgpdPeerAddress, |
| 260 | null, |
| 261 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 262 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 263 | intents.add(PointToPointIntent.builder() |
| 264 | .appId(appId) |
| 265 | .selector(selector) |
| 266 | .treatment(treatment) |
| 267 | .ingressPoint(bgpdConnectPoint) |
| 268 | .egressPoint(bgpdPeerConnectPoint) |
| 269 | .priority(priority) |
| 270 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 271 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 272 | // ICMP path from BGP peer to BGP speaker |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 273 | selector = buildSelector(icmpProtocol, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 274 | bgpdPeerAddress, |
| 275 | bgpdAddress, |
| 276 | null, |
| 277 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 278 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 279 | intents.add(PointToPointIntent.builder() |
| 280 | .appId(appId) |
| 281 | .selector(selector) |
| 282 | .treatment(treatment) |
| 283 | .ingressPoint(bgpdPeerConnectPoint) |
| 284 | .egressPoint(bgpdConnectPoint) |
| 285 | .priority(priority) |
| 286 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 287 | |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 288 | return intents; |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Builds a traffic selector based on the set of input parameters. |
| 293 | * |
| 294 | * @param ipProto IP protocol |
| 295 | * @param srcIp source IP address |
| 296 | * @param dstIp destination IP address |
| 297 | * @param srcTcpPort source TCP port, or null if shouldn't be set |
| 298 | * @param dstTcpPort destination TCP port, or null if shouldn't be set |
| 299 | * @return the new traffic selector |
| 300 | */ |
| 301 | private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 302 | IpAddress dstIp, Short srcTcpPort, |
| 303 | Short dstTcpPort) { |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 304 | TrafficSelector.Builder builder = null; |
| 305 | |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 306 | if (dstIp.isIp4()) { |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 307 | builder = DefaultTrafficSelector.builder() |
| 308 | .matchEthType(Ethernet.TYPE_IPV4) |
| 309 | .matchIPProtocol(ipProto) |
| 310 | .matchIPSrc(IpPrefix.valueOf(srcIp, |
| 311 | IpPrefix.MAX_INET_MASK_LENGTH)) |
| 312 | .matchIPDst(IpPrefix.valueOf(dstIp, |
| 313 | IpPrefix.MAX_INET_MASK_LENGTH)); |
| 314 | } else { |
| 315 | builder = DefaultTrafficSelector.builder() |
| 316 | .matchEthType(Ethernet.TYPE_IPV6) |
| 317 | .matchIPProtocol(ipProto) |
| 318 | .matchIPv6Src(IpPrefix.valueOf(srcIp, |
| 319 | IpPrefix.MAX_INET6_MASK_LENGTH)) |
| 320 | .matchIPv6Dst(IpPrefix.valueOf(dstIp, |
| 321 | IpPrefix.MAX_INET6_MASK_LENGTH)); |
| 322 | } |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 323 | |
| 324 | if (srcTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 325 | builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | if (dstTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 329 | builder.matchTcpDst(TpPort.tpPort(dstTcpPort)); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | return builder.build(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 335 | } |