Rafactored PeerConnectivityManager for code reuse between the two path types.
Change-Id: Ib05f676d071ef1c545e93244a9ed5ed89672113f
Showing
1 changed file
with
146 additions
and
201 deletions
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.sdnip; | 16 | package org.onlab.onos.sdnip; |
17 | 17 | ||
18 | +import java.util.ArrayList; | ||
18 | import java.util.List; | 19 | import java.util.List; |
19 | 20 | ||
20 | import org.onlab.onos.core.ApplicationId; | 21 | import org.onlab.onos.core.ApplicationId; |
... | @@ -23,6 +24,7 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector; | ... | @@ -23,6 +24,7 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector; |
23 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; | 24 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
24 | import org.onlab.onos.net.flow.TrafficSelector; | 25 | import org.onlab.onos.net.flow.TrafficSelector; |
25 | import org.onlab.onos.net.flow.TrafficTreatment; | 26 | import org.onlab.onos.net.flow.TrafficTreatment; |
27 | +import org.onlab.onos.net.intent.Intent; | ||
26 | import org.onlab.onos.net.intent.IntentService; | 28 | import org.onlab.onos.net.intent.IntentService; |
27 | import org.onlab.onos.net.intent.PointToPointIntent; | 29 | import org.onlab.onos.net.intent.PointToPointIntent; |
28 | import org.onlab.onos.sdnip.bgp.BgpConstants; | 30 | import org.onlab.onos.sdnip.bgp.BgpConstants; |
... | @@ -90,231 +92,174 @@ public class PeerConnectivityManager { | ... | @@ -90,231 +92,174 @@ public class PeerConnectivityManager { |
90 | return; | 92 | return; |
91 | } | 93 | } |
92 | 94 | ||
93 | - setupBgpPaths(); | 95 | + setUpConnectivity(); |
94 | - setupIcmpPaths(); | ||
95 | } | 96 | } |
96 | 97 | ||
97 | /** | 98 | /** |
98 | - * Sets up paths for all {@link BgpSpeaker}s and all external peers. | 99 | + * Sets up paths to establish connectivity between all internal |
99 | - * <p/> | 100 | + * {@link BgpSpeaker}s and all external {@link BgpPeer}s. |
100 | - * Run a loop for all BGP speakers and a loop for all BGP peers outside. | ||
101 | - * Push intents for paths from each BGP speaker to all peers. Push intents | ||
102 | - * for paths from all peers to each BGP speaker. | ||
103 | */ | 101 | */ |
104 | - private void setupBgpPaths() { | 102 | + private void setUpConnectivity() { |
105 | for (BgpSpeaker bgpSpeaker : configService.getBgpSpeakers() | 103 | for (BgpSpeaker bgpSpeaker : configService.getBgpSpeakers() |
106 | .values()) { | 104 | .values()) { |
107 | log.debug("Start to set up BGP paths for BGP speaker: {}", | 105 | log.debug("Start to set up BGP paths for BGP speaker: {}", |
108 | bgpSpeaker); | 106 | bgpSpeaker); |
109 | - ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); | ||
110 | - | ||
111 | - List<InterfaceAddress> interfaceAddresses = | ||
112 | - bgpSpeaker.interfaceAddresses(); | ||
113 | 107 | ||
114 | for (BgpPeer bgpPeer : configService.getBgpPeers().values()) { | 108 | for (BgpPeer bgpPeer : configService.getBgpPeers().values()) { |
115 | 109 | ||
116 | log.debug("Start to set up BGP paths between BGP speaker: {} " | 110 | log.debug("Start to set up BGP paths between BGP speaker: {} " |
117 | + "to BGP peer: {}", bgpSpeaker, bgpPeer); | 111 | + "to BGP peer: {}", bgpSpeaker, bgpPeer); |
118 | 112 | ||
119 | - Interface peerInterface = interfaceService.getInterface( | 113 | + buildPeerIntents(bgpSpeaker, bgpPeer); |
120 | - bgpPeer.connectPoint()); | ||
121 | - if (peerInterface == null) { | ||
122 | - log.error("Can not find the corresponding Interface from " | ||
123 | - + "configuration for BGP peer {}", | ||
124 | - bgpPeer.ipAddress()); | ||
125 | - continue; | ||
126 | - } | ||
127 | - | ||
128 | - IpAddress bgpdAddress = null; | ||
129 | - for (InterfaceAddress interfaceAddress : interfaceAddresses) { | ||
130 | - if (interfaceAddress.connectPoint().equals( | ||
131 | - peerInterface.connectPoint())) { | ||
132 | - bgpdAddress = interfaceAddress.ipAddress(); | ||
133 | - break; | ||
134 | - } | ||
135 | - } | ||
136 | - if (bgpdAddress == null) { | ||
137 | - log.debug("There is no interface IP address for bgpPeer: {}" | ||
138 | - + " on interface {}", bgpPeer, bgpPeer.connectPoint()); | ||
139 | - continue; | ||
140 | - } | ||
141 | - | ||
142 | - IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); | ||
143 | - ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint(); | ||
144 | - | ||
145 | - // install intent for BGP path from BGPd to BGP peer matching | ||
146 | - // destination TCP port 179 | ||
147 | - TrafficSelector selector = DefaultTrafficSelector.builder() | ||
148 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
149 | - .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
150 | - .matchIPSrc(IpPrefix.valueOf(bgpdAddress, | ||
151 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
152 | - .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress, | ||
153 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
154 | - .matchTcpDst((short) BgpConstants.BGP_PORT) | ||
155 | - .build(); | ||
156 | - | ||
157 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
158 | - .build(); | ||
159 | - | ||
160 | - PointToPointIntent intentMatchDstTcpPort = | ||
161 | - new PointToPointIntent(appId, selector, treatment, | ||
162 | - bgpdConnectPoint, bgpdPeerConnectPoint); | ||
163 | - intentService.submit(intentMatchDstTcpPort); | ||
164 | - log.debug("Submitted BGP path intent matching dst TCP port 179 " | ||
165 | - + "from BGPd {} to peer {}: {}", | ||
166 | - bgpdAddress, bgpdPeerAddress, intentMatchDstTcpPort); | ||
167 | - | ||
168 | - // install intent for BGP path from BGPd to BGP peer matching | ||
169 | - // source TCP port 179 | ||
170 | - selector = DefaultTrafficSelector.builder() | ||
171 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
172 | - .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
173 | - .matchIPSrc(IpPrefix.valueOf(bgpdAddress, | ||
174 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
175 | - .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress, | ||
176 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
177 | - .matchTcpSrc((short) BgpConstants.BGP_PORT) | ||
178 | - .build(); | ||
179 | - | ||
180 | - PointToPointIntent intentMatchSrcTcpPort = | ||
181 | - new PointToPointIntent(appId, selector, treatment, | ||
182 | - bgpdConnectPoint, bgpdPeerConnectPoint); | ||
183 | - intentService.submit(intentMatchSrcTcpPort); | ||
184 | - log.debug("Submitted BGP path intent matching src TCP port 179" | ||
185 | - + "from BGPd {} to peer {}: {}", | ||
186 | - bgpdAddress, bgpdPeerAddress, intentMatchSrcTcpPort); | ||
187 | - | ||
188 | - // install intent for reversed BGP path from BGP peer to BGPd | ||
189 | - // matching destination TCP port 179 | ||
190 | - selector = DefaultTrafficSelector.builder() | ||
191 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
192 | - .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
193 | - .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress, | ||
194 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
195 | - .matchIPDst(IpPrefix.valueOf(bgpdAddress, | ||
196 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
197 | - .matchTcpDst((short) BgpConstants.BGP_PORT) | ||
198 | - .build(); | ||
199 | - | ||
200 | - PointToPointIntent reversedIntentMatchDstTcpPort = | ||
201 | - new PointToPointIntent(appId, selector, treatment, | ||
202 | - bgpdPeerConnectPoint, bgpdConnectPoint); | ||
203 | - intentService.submit(reversedIntentMatchDstTcpPort); | ||
204 | - log.debug("Submitted BGP path intent matching dst TCP port 179" | ||
205 | - + "from BGP peer {} to BGPd {} : {}", | ||
206 | - bgpdPeerAddress, bgpdAddress, reversedIntentMatchDstTcpPort); | ||
207 | - | ||
208 | - // install intent for reversed BGP path from BGP peer to BGPd | ||
209 | - // matching source TCP port 179 | ||
210 | - selector = DefaultTrafficSelector.builder() | ||
211 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
212 | - .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
213 | - .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress, | ||
214 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
215 | - .matchIPDst(IpPrefix.valueOf(bgpdAddress, | ||
216 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
217 | - .matchTcpSrc((short) BgpConstants.BGP_PORT) | ||
218 | - .build(); | ||
219 | - | ||
220 | - PointToPointIntent reversedIntentMatchSrcTcpPort = | ||
221 | - new PointToPointIntent(appId, selector, treatment, | ||
222 | - bgpdPeerConnectPoint, bgpdConnectPoint); | ||
223 | - intentService.submit(reversedIntentMatchSrcTcpPort); | ||
224 | - log.debug("Submitted BGP path intent matching src TCP port 179" | ||
225 | - + "from BGP peer {} to BGPd {} : {}", | ||
226 | - bgpdPeerAddress, bgpdAddress, reversedIntentMatchSrcTcpPort); | ||
227 | - | ||
228 | } | 114 | } |
229 | } | 115 | } |
230 | } | 116 | } |
231 | 117 | ||
232 | /** | 118 | /** |
233 | - * Sets up ICMP paths between each {@link BgpSpeaker} and all BGP peers | 119 | + * Builds the required intents between a given internal BGP speaker and |
234 | - * located in other external networks. | 120 | + * external BGP peer. |
235 | - * <p/> | 121 | + * |
236 | - * Run a loop for all BGP speakers and a loop for all BGP Peers. Push | 122 | + * @param bgpSpeaker the BGP speaker |
237 | - * intents for paths from each BGP speaker to all peers. Push intents | 123 | + * @param bgpPeer the BGP peer |
238 | - * for paths from all peers to each BGP speaker. | ||
239 | */ | 124 | */ |
240 | - private void setupIcmpPaths() { | 125 | + private void buildPeerIntents(BgpSpeaker bgpSpeaker, BgpPeer bgpPeer) { |
241 | - for (BgpSpeaker bgpSpeaker : configService.getBgpSpeakers() | 126 | + List<Intent> intents = new ArrayList<Intent>(); |
242 | - .values()) { | ||
243 | - log.debug("Start to set up ICMP paths for BGP speaker: {}", | ||
244 | - bgpSpeaker); | ||
245 | - ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); | ||
246 | - List<InterfaceAddress> interfaceAddresses = bgpSpeaker | ||
247 | - .interfaceAddresses(); | ||
248 | 127 | ||
249 | - for (BgpPeer bgpPeer : configService.getBgpPeers().values()) { | 128 | + ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); |
250 | 129 | ||
251 | - Interface peerInterface = interfaceService.getInterface( | 130 | + List<InterfaceAddress> interfaceAddresses = |
252 | - bgpPeer.connectPoint()); | 131 | + bgpSpeaker.interfaceAddresses(); |
253 | - | 132 | + |
254 | - if (peerInterface == null) { | 133 | + Interface peerInterface = interfaceService.getInterface( |
255 | - log.error("Can not find the corresponding Interface from " | 134 | + bgpPeer.connectPoint()); |
256 | - + "configuration for BGP peer {}", | 135 | + |
257 | - bgpPeer.ipAddress()); | 136 | + if (peerInterface == null) { |
258 | - continue; | 137 | + log.error("No interface found for peer {}", bgpPeer.ipAddress()); |
259 | - } | 138 | + return; |
260 | - IpAddress bgpdAddress = null; | 139 | + } |
261 | - for (InterfaceAddress interfaceAddress : interfaceAddresses) { | 140 | + |
262 | - if (interfaceAddress.connectPoint().equals( | 141 | + IpAddress bgpdAddress = null; |
263 | - peerInterface.connectPoint())) { | 142 | + for (InterfaceAddress interfaceAddress : interfaceAddresses) { |
264 | - bgpdAddress = interfaceAddress.ipAddress(); | 143 | + if (interfaceAddress.connectPoint().equals( |
265 | - break; | 144 | + peerInterface.connectPoint())) { |
266 | - } | 145 | + bgpdAddress = interfaceAddress.ipAddress(); |
267 | - | 146 | + break; |
268 | - } | ||
269 | - if (bgpdAddress == null) { | ||
270 | - log.debug("There is no IP address for bgpPeer: {} on " | ||
271 | - + "interface port: {}", bgpPeer, | ||
272 | - bgpPeer.connectPoint()); | ||
273 | - continue; | ||
274 | - } | ||
275 | - | ||
276 | - IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); | ||
277 | - ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint(); | ||
278 | - | ||
279 | - // install intent for ICMP path from BGPd to BGP peer | ||
280 | - TrafficSelector selector = DefaultTrafficSelector.builder() | ||
281 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
282 | - .matchIPProtocol(IPv4.PROTOCOL_ICMP) | ||
283 | - .matchIPSrc(IpPrefix.valueOf(bgpdAddress, | ||
284 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
285 | - .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress, | ||
286 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
287 | - .build(); | ||
288 | - | ||
289 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
290 | - .build(); | ||
291 | - | ||
292 | - PointToPointIntent intent = | ||
293 | - new PointToPointIntent(appId, selector, treatment, | ||
294 | - bgpdConnectPoint, bgpdPeerConnectPoint); | ||
295 | - intentService.submit(intent); | ||
296 | - log.debug("Submitted ICMP path intent from BGPd {} to peer {} :" | ||
297 | - + " {}", bgpdAddress, bgpdPeerAddress, intent); | ||
298 | - | ||
299 | - // install intent for reversed ICMP path from BGP peer to BGPd | ||
300 | - selector = DefaultTrafficSelector.builder() | ||
301 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
302 | - .matchIPProtocol(IPv4.PROTOCOL_ICMP) | ||
303 | - .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress, | ||
304 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
305 | - .matchIPDst(IpPrefix.valueOf(bgpdAddress, | ||
306 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
307 | - .build(); | ||
308 | - | ||
309 | - PointToPointIntent reversedIntent = | ||
310 | - new PointToPointIntent(appId, selector, treatment, | ||
311 | - bgpdPeerConnectPoint, bgpdConnectPoint); | ||
312 | - intentService.submit(reversedIntent); | ||
313 | - log.debug("Submitted ICMP path intent from BGP peer {} to BGPd" | ||
314 | - + " {} : {}", | ||
315 | - bgpdPeerAddress, bgpdAddress, reversedIntent); | ||
316 | } | 147 | } |
317 | } | 148 | } |
149 | + if (bgpdAddress == null) { | ||
150 | + log.debug("No IP address found for peer {} on interface {}", | ||
151 | + bgpPeer, bgpPeer.connectPoint()); | ||
152 | + return; | ||
153 | + } | ||
154 | + | ||
155 | + IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); | ||
156 | + ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint(); | ||
157 | + | ||
158 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
159 | + .build(); | ||
160 | + | ||
161 | + TrafficSelector selector; | ||
162 | + | ||
163 | + // install intent for BGP path from BGPd to BGP peer matching | ||
164 | + // destination TCP port 179 | ||
165 | + selector = buildSelector(IPv4.PROTOCOL_TCP, | ||
166 | + bgpdAddress, | ||
167 | + bgpdPeerAddress, | ||
168 | + null, | ||
169 | + (short) BgpConstants.BGP_PORT); | ||
170 | + | ||
171 | + intents.add(new PointToPointIntent(appId, selector, treatment, | ||
172 | + bgpdConnectPoint, bgpdPeerConnectPoint)); | ||
173 | + | ||
174 | + // install intent for BGP path from BGPd to BGP peer matching | ||
175 | + // source TCP port 179 | ||
176 | + selector = buildSelector(IPv4.PROTOCOL_TCP, | ||
177 | + bgpdAddress, | ||
178 | + bgpdPeerAddress, | ||
179 | + (short) BgpConstants.BGP_PORT, | ||
180 | + null); | ||
181 | + | ||
182 | + intents.add(new PointToPointIntent(appId, selector, treatment, | ||
183 | + bgpdConnectPoint, bgpdPeerConnectPoint)); | ||
184 | + | ||
185 | + // install intent for reversed BGP path from BGP peer to BGPd | ||
186 | + // matching destination TCP port 179 | ||
187 | + selector = buildSelector(IPv4.PROTOCOL_TCP, | ||
188 | + bgpdPeerAddress, | ||
189 | + bgpdAddress, | ||
190 | + null, | ||
191 | + (short) BgpConstants.BGP_PORT); | ||
192 | + | ||
193 | + intents.add(new PointToPointIntent(appId, selector, treatment, | ||
194 | + bgpdPeerConnectPoint, bgpdConnectPoint)); | ||
195 | + | ||
196 | + // install intent for reversed BGP path from BGP peer to BGPd | ||
197 | + // matching source TCP port 179 | ||
198 | + selector = buildSelector(IPv4.PROTOCOL_TCP, | ||
199 | + bgpdPeerAddress, | ||
200 | + bgpdAddress, | ||
201 | + (short) BgpConstants.BGP_PORT, | ||
202 | + null); | ||
203 | + | ||
204 | + intents.add(new PointToPointIntent(appId, selector, treatment, | ||
205 | + bgpdPeerConnectPoint, bgpdConnectPoint)); | ||
206 | + | ||
207 | + // install intent for ICMP path from BGPd to BGP peer | ||
208 | + selector = buildSelector(IPv4.PROTOCOL_ICMP, | ||
209 | + bgpdAddress, | ||
210 | + bgpdPeerAddress, | ||
211 | + null, | ||
212 | + null); | ||
213 | + | ||
214 | + intents.add(new PointToPointIntent(appId, selector, treatment, | ||
215 | + bgpdConnectPoint, bgpdPeerConnectPoint)); | ||
216 | + | ||
217 | + // install intent for reversed ICMP path from BGP peer to BGPd | ||
218 | + selector = buildSelector(IPv4.PROTOCOL_ICMP, | ||
219 | + bgpdPeerAddress, | ||
220 | + bgpdAddress, | ||
221 | + null, | ||
222 | + null); | ||
223 | + | ||
224 | + intents.add(new PointToPointIntent(appId, selector, treatment, | ||
225 | + bgpdPeerConnectPoint, bgpdConnectPoint)); | ||
226 | + | ||
227 | + // Submit all the intents. | ||
228 | + // TODO submit as a batch | ||
229 | + for (Intent intent : intents) { | ||
230 | + intentService.submit(intent); | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * Builds a traffic selector based on the set of input parameters. | ||
236 | + * | ||
237 | + * @param ipProto IP protocol | ||
238 | + * @param srcIp source IP address | ||
239 | + * @param dstIp destination IP address | ||
240 | + * @param srcTcpPort source TCP port, or null if shouldn't be set | ||
241 | + * @param dstTcpPort destination TCP port, or null if shouldn't be set | ||
242 | + * @return the new traffic selector | ||
243 | + */ | ||
244 | + private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, | ||
245 | + IpAddress dstIp, Short srcTcpPort, Short dstTcpPort) { | ||
246 | + TrafficSelector.Builder builder = DefaultTrafficSelector.builder() | ||
247 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
248 | + .matchIPProtocol(ipProto) | ||
249 | + .matchIPSrc(IpPrefix.valueOf(srcIp, | ||
250 | + IpPrefix.MAX_INET_MASK_LENGTH)) | ||
251 | + .matchIPDst(IpPrefix.valueOf(dstIp, | ||
252 | + IpPrefix.MAX_INET_MASK_LENGTH)); | ||
253 | + | ||
254 | + if (srcTcpPort != null) { | ||
255 | + builder.matchTcpSrc(srcTcpPort); | ||
256 | + } | ||
257 | + | ||
258 | + if (dstTcpPort != null) { | ||
259 | + builder.matchTcpDst(dstTcpPort); | ||
260 | + } | ||
261 | + | ||
262 | + return builder.build(); | ||
318 | } | 263 | } |
319 | 264 | ||
320 | } | 265 | } | ... | ... |
-
Please register or login to post a comment