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