Pavlin Radoslavov

Fixes related to SDN-IP intents:

 * Use intent priority when installing multipoint-to-singlepoint intents:
   the loinger the routing prefix match, the higher the intent priority.
   This is needed to perform correctly the equivalent of longest prefix
   match in the switch.
 * Use intent priority for the point-to-point intents: the priority for
   this BGP-related control traffic is higher than the
   multipoint-to-singlepoint intents.

 * Use the appropriate Key when installing multipoint-to-singlepoint intents.
   The key is the network (destination routing) prefix address represented
   as a string.

Change-Id: Ic489a1e5f31adceb4c9d1dcea52293a2b3db0b79
...@@ -32,6 +32,7 @@ import org.onosproject.net.flow.criteria.Criterion; ...@@ -32,6 +32,7 @@ import org.onosproject.net.flow.criteria.Criterion;
32 import org.onosproject.net.intent.Intent; 32 import org.onosproject.net.intent.Intent;
33 import org.onosproject.net.intent.IntentService; 33 import org.onosproject.net.intent.IntentService;
34 import org.onosproject.net.intent.IntentState; 34 import org.onosproject.net.intent.IntentState;
35 +import org.onosproject.net.intent.Key;
35 import org.onosproject.net.intent.MultiPointToSinglePointIntent; 36 import org.onosproject.net.intent.MultiPointToSinglePointIntent;
36 import org.onosproject.net.intent.PointToPointIntent; 37 import org.onosproject.net.intent.PointToPointIntent;
37 import org.onosproject.routing.FibListener; 38 import org.onosproject.routing.FibListener;
...@@ -43,6 +44,7 @@ import org.slf4j.Logger; ...@@ -43,6 +44,7 @@ import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory; 44 import org.slf4j.LoggerFactory;
44 45
45 import java.util.Collection; 46 import java.util.Collection;
47 +import java.util.Collections;
46 import java.util.HashMap; 48 import java.util.HashMap;
47 import java.util.HashSet; 49 import java.util.HashSet;
48 import java.util.LinkedList; 50 import java.util.LinkedList;
...@@ -62,6 +64,9 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -62,6 +64,9 @@ import static com.google.common.base.Preconditions.checkArgument;
62 * IntentService. 64 * IntentService.
63 */ 65 */
64 public class IntentSynchronizer implements FibListener { 66 public class IntentSynchronizer implements FibListener {
67 + private static final int PRIORITY_OFFSET = 100;
68 + private static final int PRIORITY_MULTIPLIER = 5;
69 +
65 private static final Logger log = 70 private static final Logger log =
66 LoggerFactory.getLogger(IntentSynchronizer.class); 71 LoggerFactory.getLogger(IntentSynchronizer.class);
67 72
...@@ -332,9 +337,14 @@ public class IntentSynchronizer implements FibListener { ...@@ -332,9 +337,14 @@ public class IntentSynchronizer implements FibListener {
332 selector.matchVlanId(VlanId.ANY); 337 selector.matchVlanId(VlanId.ANY);
333 } 338 }
334 339
335 - return new MultiPointToSinglePointIntent(appId, selector.build(), 340 + int priority =
341 + prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
342 + Key key = Key.of(prefix.toString(), appId);
343 + return new MultiPointToSinglePointIntent(appId, key, selector.build(),
336 treatment.build(), 344 treatment.build(),
337 - ingressPorts, egressPort); 345 + ingressPorts, egressPort,
346 + Collections.emptyList(),
347 + priority);
338 } 348 }
339 349
340 @Override 350 @Override
......
...@@ -37,12 +37,14 @@ import org.slf4j.LoggerFactory; ...@@ -37,12 +37,14 @@ import org.slf4j.LoggerFactory;
37 37
38 import java.util.ArrayList; 38 import java.util.ArrayList;
39 import java.util.Collection; 39 import java.util.Collection;
40 +import java.util.Collections;
40 import java.util.List; 41 import java.util.List;
41 42
42 /** 43 /**
43 * Manages the connectivity requirements between peers. 44 * Manages the connectivity requirements between peers.
44 */ 45 */
45 public class PeerConnectivityManager { 46 public class PeerConnectivityManager {
47 + private static final int PRIORITY_OFFSET = 1000;
46 48
47 private static final Logger log = LoggerFactory.getLogger( 49 private static final Logger log = LoggerFactory.getLogger(
48 PeerConnectivityManager.class); 50 PeerConnectivityManager.class);
...@@ -188,8 +190,13 @@ public class PeerConnectivityManager { ...@@ -188,8 +190,13 @@ public class PeerConnectivityManager {
188 null, 190 null,
189 BGP_PORT); 191 BGP_PORT);
190 192
193 + int priority = PRIORITY_OFFSET;
194 +
191 intents.add(new PointToPointIntent(appId, selector, treatment, 195 intents.add(new PointToPointIntent(appId, selector, treatment,
192 - bgpdConnectPoint, bgpdPeerConnectPoint)); 196 + bgpdConnectPoint,
197 + bgpdPeerConnectPoint,
198 + Collections.emptyList(),
199 + priority));
193 200
194 // Path from BGP speaker to BGP peer matching source TCP port 179 201 // Path from BGP speaker to BGP peer matching source TCP port 179
195 selector = buildSelector(tcpProtocol, 202 selector = buildSelector(tcpProtocol,
...@@ -199,7 +206,10 @@ public class PeerConnectivityManager { ...@@ -199,7 +206,10 @@ public class PeerConnectivityManager {
199 null); 206 null);
200 207
201 intents.add(new PointToPointIntent(appId, selector, treatment, 208 intents.add(new PointToPointIntent(appId, selector, treatment,
202 - bgpdConnectPoint, bgpdPeerConnectPoint)); 209 + bgpdConnectPoint,
210 + bgpdPeerConnectPoint,
211 + Collections.emptyList(),
212 + priority));
203 213
204 // Path from BGP peer to BGP speaker matching destination TCP port 179 214 // Path from BGP peer to BGP speaker matching destination TCP port 179
205 selector = buildSelector(tcpProtocol, 215 selector = buildSelector(tcpProtocol,
...@@ -209,7 +219,10 @@ public class PeerConnectivityManager { ...@@ -209,7 +219,10 @@ public class PeerConnectivityManager {
209 BGP_PORT); 219 BGP_PORT);
210 220
211 intents.add(new PointToPointIntent(appId, selector, treatment, 221 intents.add(new PointToPointIntent(appId, selector, treatment,
212 - bgpdPeerConnectPoint, bgpdConnectPoint)); 222 + bgpdPeerConnectPoint,
223 + bgpdConnectPoint,
224 + Collections.emptyList(),
225 + priority));
213 226
214 // Path from BGP peer to BGP speaker matching source TCP port 179 227 // Path from BGP peer to BGP speaker matching source TCP port 179
215 selector = buildSelector(tcpProtocol, 228 selector = buildSelector(tcpProtocol,
...@@ -219,7 +232,10 @@ public class PeerConnectivityManager { ...@@ -219,7 +232,10 @@ public class PeerConnectivityManager {
219 null); 232 null);
220 233
221 intents.add(new PointToPointIntent(appId, selector, treatment, 234 intents.add(new PointToPointIntent(appId, selector, treatment,
222 - bgpdPeerConnectPoint, bgpdConnectPoint)); 235 + bgpdPeerConnectPoint,
236 + bgpdConnectPoint,
237 + Collections.emptyList(),
238 + priority));
223 239
224 // ICMP path from BGP speaker to BGP peer 240 // ICMP path from BGP speaker to BGP peer
225 selector = buildSelector(icmpProtocol, 241 selector = buildSelector(icmpProtocol,
...@@ -229,7 +245,10 @@ public class PeerConnectivityManager { ...@@ -229,7 +245,10 @@ public class PeerConnectivityManager {
229 null); 245 null);
230 246
231 intents.add(new PointToPointIntent(appId, selector, treatment, 247 intents.add(new PointToPointIntent(appId, selector, treatment,
232 - bgpdConnectPoint, bgpdPeerConnectPoint)); 248 + bgpdConnectPoint,
249 + bgpdPeerConnectPoint,
250 + Collections.emptyList(),
251 + priority));
233 252
234 // ICMP path from BGP peer to BGP speaker 253 // ICMP path from BGP peer to BGP speaker
235 selector = buildSelector(icmpProtocol, 254 selector = buildSelector(icmpProtocol,
...@@ -239,7 +258,10 @@ public class PeerConnectivityManager { ...@@ -239,7 +258,10 @@ public class PeerConnectivityManager {
239 null); 258 null);
240 259
241 intents.add(new PointToPointIntent(appId, selector, treatment, 260 intents.add(new PointToPointIntent(appId, selector, treatment,
242 - bgpdPeerConnectPoint, bgpdConnectPoint)); 261 + bgpdPeerConnectPoint,
262 + bgpdConnectPoint,
263 + Collections.emptyList(),
264 + priority));
243 265
244 return intents; 266 return intents;
245 } 267 }
......