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