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; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 25 | import org.onosproject.net.config.NetworkConfigService; |
| 26 | import org.onosproject.incubator.net.intf.Interface; |
| 27 | import org.onosproject.incubator.net.intf.InterfaceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 31 | import org.onosproject.net.flow.TrafficSelector; |
| 32 | import org.onosproject.net.flow.TrafficTreatment; |
Jonathan Hart | 2a9ea49 | 2015-07-30 15:53:04 -0700 | [diff] [blame] | 33 | import org.onosproject.net.host.InterfaceIpAddress; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.intent.PointToPointIntent; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 35 | import org.onosproject.routing.RoutingService; |
| 36 | import org.onosproject.routing.config.BgpConfig; |
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 | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 44 | import static com.google.common.base.Preconditions.checkNotNull; |
| 45 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Manages the connectivity requirements between peers. |
| 48 | */ |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 49 | public class PeerConnectivityManager { |
Pavlin Radoslavov | 2aa1f32 | 2015-03-11 17:59:44 -0700 | [diff] [blame] | 50 | private static final int PRIORITY_OFFSET = 1000; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 51 | |
| 52 | private static final Logger log = LoggerFactory.getLogger( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 53 | PeerConnectivityManager.class); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 54 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 55 | private static final short BGP_PORT = 179; |
| 56 | |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 57 | private final IntentSynchronizer intentSynchronizer; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 58 | private final NetworkConfigService configService; |
| 59 | private final InterfaceService interfaceService; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 60 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 61 | private final ApplicationId appId; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 62 | private final ApplicationId routerAppId; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 63 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 64 | /** |
| 65 | * Creates a new PeerConnectivityManager. |
| 66 | * |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 67 | * @param appId the application ID |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 68 | * @param intentSynchronizer the intent synchronizer |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 69 | * @param configService the SDN-IP config service |
Ray Milkey | 9b36d81 | 2015-09-09 15:24:54 -0700 | [diff] [blame^] | 70 | * @param interfaceService the interface service |
| 71 | * @param routerAppId application ID |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 72 | */ |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 73 | public PeerConnectivityManager(ApplicationId appId, |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 74 | IntentSynchronizer intentSynchronizer, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 75 | NetworkConfigService configService, |
| 76 | ApplicationId routerAppId, |
| 77 | InterfaceService interfaceService) { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 78 | this.appId = appId; |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 79 | this.intentSynchronizer = intentSynchronizer; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 80 | this.configService = configService; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 81 | this.routerAppId = routerAppId; |
| 82 | this.interfaceService = interfaceService; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Starts the peer connectivity manager. |
| 87 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 88 | public void start() { |
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 |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 100 | * BGP speakers and external BGP peers. |
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 | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 105 | BgpConfig config = configService.getConfig(routerAppId, RoutingService.CONFIG_CLASS); |
| 106 | |
| 107 | if (config == null) { |
| 108 | log.warn("No BgpConfig found"); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | for (BgpConfig.BgpSpeakerConfig bgpSpeaker : config.bgpSpeakers()) { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 113 | log.debug("Start to set up BGP paths for BGP speaker: {}", |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 114 | bgpSpeaker); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 115 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 116 | intents.addAll(buildSpeakerIntents(bgpSpeaker)); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 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 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 123 | private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker) { |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 124 | List<PointToPointIntent> intents = new ArrayList<>(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 125 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 126 | for (IpAddress peerAddress : speaker.peers()) { |
| 127 | Interface peeringInterface = interfaceService.getMatchingInterface(peerAddress); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 128 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 129 | if (peeringInterface == null) { |
| 130 | log.debug("No peering interface found for peer {} on speaker {}", |
| 131 | peerAddress, speaker); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 132 | continue; |
| 133 | } |
| 134 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 135 | IpAddress peeringAddress = null; |
| 136 | for (InterfaceIpAddress address : peeringInterface.ipAddresses()) { |
| 137 | if (address.subnetAddress().contains(peerAddress)) { |
| 138 | peeringAddress = address.ipAddress(); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 139 | break; |
Jonathan Hart | 2a9ea49 | 2015-07-30 15:53:04 -0700 | [diff] [blame] | 140 | } |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 141 | } |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 142 | |
| 143 | checkNotNull(peeringAddress); |
| 144 | |
| 145 | intents.addAll(buildIntents(speaker.connectPoint(), peeringAddress, |
| 146 | peeringInterface.connectPoint(), peerAddress)); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 149 | return intents; |
| 150 | } |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 151 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 152 | /** |
| 153 | * Builds the required intents between the two pairs of connect points and |
| 154 | * IP addresses. |
| 155 | * |
| 156 | * @param portOne the first connect point |
| 157 | * @param ipOne the first IP address |
| 158 | * @param portTwo the second connect point |
| 159 | * @param ipTwo the second IP address |
| 160 | * @return the intents to install |
| 161 | */ |
| 162 | private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, |
| 163 | IpAddress ipOne, |
| 164 | ConnectPoint portTwo, |
| 165 | IpAddress ipTwo) { |
| 166 | |
| 167 | List<PointToPointIntent> intents = new ArrayList<>(); |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 168 | |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 169 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 170 | |
| 171 | TrafficSelector selector; |
| 172 | |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 173 | byte tcpProtocol; |
| 174 | byte icmpProtocol; |
| 175 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 176 | if (ipOne.isIp4()) { |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 177 | tcpProtocol = IPv4.PROTOCOL_TCP; |
| 178 | icmpProtocol = IPv4.PROTOCOL_ICMP; |
| 179 | } else { |
| 180 | tcpProtocol = IPv6.PROTOCOL_TCP; |
| 181 | icmpProtocol = IPv6.PROTOCOL_ICMP6; |
| 182 | } |
| 183 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 184 | // Path from BGP speaker to BGP peer matching destination TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 185 | selector = buildSelector(tcpProtocol, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 186 | ipOne, |
| 187 | ipTwo, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 188 | null, |
| 189 | BGP_PORT); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 190 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 191 | intents.add(PointToPointIntent.builder() |
| 192 | .appId(appId) |
| 193 | .selector(selector) |
| 194 | .treatment(treatment) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 195 | .ingressPoint(portOne) |
| 196 | .egressPoint(portTwo) |
| 197 | .priority(PRIORITY_OFFSET) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 198 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 199 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 200 | // Path from BGP speaker to BGP peer matching source TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 201 | selector = buildSelector(tcpProtocol, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 202 | ipOne, |
| 203 | ipTwo, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 204 | BGP_PORT, |
| 205 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 206 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 207 | intents.add(PointToPointIntent.builder() |
| 208 | .appId(appId) |
| 209 | .selector(selector) |
| 210 | .treatment(treatment) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 211 | .ingressPoint(portOne) |
| 212 | .egressPoint(portTwo) |
| 213 | .priority(PRIORITY_OFFSET) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 214 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 215 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 216 | // Path from BGP peer to BGP speaker matching destination TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 217 | selector = buildSelector(tcpProtocol, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 218 | ipTwo, |
| 219 | ipOne, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 220 | null, |
| 221 | BGP_PORT); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 222 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 223 | intents.add(PointToPointIntent.builder() |
| 224 | .appId(appId) |
| 225 | .selector(selector) |
| 226 | .treatment(treatment) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 227 | .ingressPoint(portTwo) |
| 228 | .egressPoint(portOne) |
| 229 | .priority(PRIORITY_OFFSET) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 230 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 231 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 232 | // Path from BGP peer to BGP speaker matching source TCP port 179 |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 233 | selector = buildSelector(tcpProtocol, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 234 | ipTwo, |
| 235 | ipOne, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 236 | BGP_PORT, |
| 237 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 238 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 239 | intents.add(PointToPointIntent.builder() |
| 240 | .appId(appId) |
| 241 | .selector(selector) |
| 242 | .treatment(treatment) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 243 | .ingressPoint(portTwo) |
| 244 | .egressPoint(portOne) |
| 245 | .priority(PRIORITY_OFFSET) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 246 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 247 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 248 | // ICMP path from BGP speaker to BGP peer |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 249 | selector = buildSelector(icmpProtocol, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 250 | ipOne, |
| 251 | ipTwo, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 252 | null, |
| 253 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 254 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 255 | intents.add(PointToPointIntent.builder() |
| 256 | .appId(appId) |
| 257 | .selector(selector) |
| 258 | .treatment(treatment) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 259 | .ingressPoint(portOne) |
| 260 | .egressPoint(portTwo) |
| 261 | .priority(PRIORITY_OFFSET) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 262 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 263 | |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 264 | // ICMP path from BGP peer to BGP speaker |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 265 | selector = buildSelector(icmpProtocol, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 266 | ipTwo, |
| 267 | ipOne, |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 268 | null, |
| 269 | null); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 270 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 271 | intents.add(PointToPointIntent.builder() |
| 272 | .appId(appId) |
| 273 | .selector(selector) |
| 274 | .treatment(treatment) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 275 | .ingressPoint(portTwo) |
| 276 | .egressPoint(portOne) |
| 277 | .priority(PRIORITY_OFFSET) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 278 | .build()); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 279 | |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 280 | return intents; |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Builds a traffic selector based on the set of input parameters. |
| 285 | * |
| 286 | * @param ipProto IP protocol |
| 287 | * @param srcIp source IP address |
| 288 | * @param dstIp destination IP address |
| 289 | * @param srcTcpPort source TCP port, or null if shouldn't be set |
| 290 | * @param dstTcpPort destination TCP port, or null if shouldn't be set |
| 291 | * @return the new traffic selector |
| 292 | */ |
| 293 | private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 294 | IpAddress dstIp, Short srcTcpPort, |
| 295 | Short dstTcpPort) { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 296 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
| 297 | .matchEthType(Ethernet.TYPE_IPV4) |
| 298 | .matchIPProtocol(ipProto); |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 299 | |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 300 | if (dstIp.isIp4()) { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 301 | builder.matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) |
| 302 | .matchIPDst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET_MASK_LENGTH)); |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 303 | } else { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 304 | builder.matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) |
| 305 | .matchIPv6Dst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET6_MASK_LENGTH)); |
Kunihiro Ishiguro | 6e2ee15 | 2015-01-20 16:57:54 -0800 | [diff] [blame] | 306 | } |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 307 | |
| 308 | if (srcTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 309 | builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | if (dstTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 313 | builder.matchTcpDst(TpPort.tpPort(dstTcpPort)); |
Jonathan Hart | 6ec6829 | 2014-11-14 15:09:30 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return builder.build(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 319 | } |