blob: 03ba29b7271a8675b23beb461d01e128447ae0d0 [file] [log] [blame]
sanghob35a6192015-04-01 13:05:26 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sanghob35a6192015-04-01 13:05:26 -07003 *
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
7 *
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.
15 */
16package org.onosproject.segmentrouting;
17
Pier Ventre917127a2016-10-31 16:49:19 -070018import com.google.common.collect.Lists;
Saurav Das8a0732e2015-11-20 15:27:53 -080019import org.onlab.packet.EthType;
sanghob35a6192015-04-01 13:05:26 -070020import org.onlab.packet.Ethernet;
21import org.onlab.packet.Ip4Address;
Pier Ventree0ae7a32016-11-23 09:57:42 -080022import org.onlab.packet.Ip6Address;
23import org.onlab.packet.IpAddress;
sanghob35a6192015-04-01 13:05:26 -070024import org.onlab.packet.IpPrefix;
25import org.onlab.packet.MacAddress;
sanghob35a6192015-04-01 13:05:26 -070026import org.onlab.packet.MplsLabel;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070027import org.onlab.packet.VlanId;
Charles Chane849c192016-01-11 18:28:54 -080028import org.onosproject.net.ConnectPoint;
Charles Chand2990362016-04-18 13:44:03 -070029import org.onosproject.net.flowobjective.DefaultObjectiveContext;
Pier Luigi9e5c5ca2017-01-12 18:14:58 -080030import org.onosproject.net.flowobjective.Objective;
Charles Chand2990362016-04-18 13:44:03 -070031import org.onosproject.net.flowobjective.ObjectiveContext;
Pier Luigi9e5c5ca2017-01-12 18:14:58 -080032import org.onosproject.net.flowobjective.ObjectiveError;
Charles Chan2df0e8a2017-01-09 11:45:08 -080033import org.onosproject.net.packet.PacketPriority;
Saurav Dasd2fded02016-12-02 15:43:47 -080034import org.onosproject.segmentrouting.DefaultRoutingHandler.PortFilterInfo;
Charles Chan0b4e6182015-11-03 10:42:14 -080035import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
36import org.onosproject.segmentrouting.config.DeviceConfiguration;
Saurav Dasc88d4662017-05-15 15:34:25 -070037import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
Saurav Das7bcbe702017-06-13 15:35:54 -070038import org.onosproject.segmentrouting.grouphandler.DestinationSet;
sanghob35a6192015-04-01 13:05:26 -070039import org.onosproject.net.DeviceId;
Saurav Das0e99e2b2015-10-28 12:39:42 -070040import org.onosproject.net.Port;
sanghob35a6192015-04-01 13:05:26 -070041import org.onosproject.net.PortNumber;
sanghob35a6192015-04-01 13:05:26 -070042import org.onosproject.net.flow.DefaultTrafficSelector;
43import org.onosproject.net.flow.DefaultTrafficTreatment;
sanghob35a6192015-04-01 13:05:26 -070044import org.onosproject.net.flow.TrafficSelector;
45import org.onosproject.net.flow.TrafficTreatment;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070046import org.onosproject.net.flow.criteria.Criteria;
47import org.onosproject.net.flowobjective.DefaultFilteringObjective;
48import org.onosproject.net.flowobjective.DefaultForwardingObjective;
49import org.onosproject.net.flowobjective.FilteringObjective;
50import org.onosproject.net.flowobjective.ForwardingObjective;
51import org.onosproject.net.flowobjective.ForwardingObjective.Builder;
Saurav Das822c4e22015-10-23 10:51:11 -070052import org.onosproject.net.flowobjective.ForwardingObjective.Flag;
sanghob35a6192015-04-01 13:05:26 -070053import org.slf4j.Logger;
54import org.slf4j.LoggerFactory;
55
56import java.util.ArrayList;
Pier Ventre917127a2016-10-31 16:49:19 -070057import java.util.Collection;
58import java.util.Collections;
Saurav Das7bcbe702017-06-13 15:35:54 -070059import java.util.HashMap;
Saurav Das837e0bb2015-10-30 17:45:38 -070060import java.util.HashSet;
sanghob35a6192015-04-01 13:05:26 -070061import java.util.List;
Saurav Das7bcbe702017-06-13 15:35:54 -070062import java.util.Map;
Charles Chan2df0e8a2017-01-09 11:45:08 -080063import java.util.Optional;
sanghob35a6192015-04-01 13:05:26 -070064import java.util.Set;
sangho20eff1d2015-04-13 15:15:58 -070065import java.util.concurrent.atomic.AtomicLong;
sanghob35a6192015-04-01 13:05:26 -070066
67import static com.google.common.base.Preconditions.checkNotNull;
Pier Luigi9e5c5ca2017-01-12 18:14:58 -080068import static org.onlab.packet.Ethernet.TYPE_ARP;
69import static org.onlab.packet.Ethernet.TYPE_IPV6;
70import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION;
71import static org.onlab.packet.IPv6.PROTOCOL_ICMP6;
Charles Chan59cc16d2017-02-02 16:20:42 -080072import static org.onosproject.segmentrouting.SegmentRoutingManager.INTERNAL_VLAN;
sanghob35a6192015-04-01 13:05:26 -070073
Charles Chane849c192016-01-11 18:28:54 -080074/**
75 * Populator of segment routing flow rules.
76 */
sanghob35a6192015-04-01 13:05:26 -070077public class RoutingRulePopulator {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070078 private static final Logger log = LoggerFactory
79 .getLogger(RoutingRulePopulator.class);
sanghob35a6192015-04-01 13:05:26 -070080
sangho20eff1d2015-04-13 15:15:58 -070081 private AtomicLong rulePopulationCounter;
sangho666cd6d2015-04-14 16:27:13 -070082 private SegmentRoutingManager srManager;
83 private DeviceConfiguration config;
Saurav Das822c4e22015-10-23 10:51:11 -070084
sanghob35a6192015-04-01 13:05:26 -070085 /**
86 * Creates a RoutingRulePopulator object.
87 *
Thomas Vachuskae10f56b2015-04-15 18:20:08 -070088 * @param srManager segment routing manager reference
sanghob35a6192015-04-01 13:05:26 -070089 */
Charles Chan65238242017-06-22 18:03:14 -070090 RoutingRulePopulator(SegmentRoutingManager srManager) {
sanghob35a6192015-04-01 13:05:26 -070091 this.srManager = srManager;
sangho666cd6d2015-04-14 16:27:13 -070092 this.config = checkNotNull(srManager.deviceConfiguration);
sangho20eff1d2015-04-13 15:15:58 -070093 this.rulePopulationCounter = new AtomicLong(0);
94 }
95
96 /**
97 * Resets the population counter.
98 */
Charles Chan65238242017-06-22 18:03:14 -070099 void resetCounter() {
sangho20eff1d2015-04-13 15:15:58 -0700100 rulePopulationCounter.set(0);
101 }
102
103 /**
104 * Returns the number of rules populated.
Thomas Vachuska266b4432015-04-30 18:13:25 -0700105 *
106 * @return number of rules
sangho20eff1d2015-04-13 15:15:58 -0700107 */
Charles Chan65238242017-06-22 18:03:14 -0700108 long getCounter() {
sangho20eff1d2015-04-13 15:15:58 -0700109 return rulePopulationCounter.get();
sanghob35a6192015-04-01 13:05:26 -0700110 }
111
112 /**
Charles Chan1cdecff2016-10-27 14:19:48 -0700113 * Populates IP rules for a route that has direct connection to the
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700114 * switch.
sanghob35a6192015-04-01 13:05:26 -0700115 *
Charles Chan1cdecff2016-10-27 14:19:48 -0700116 * @param deviceId device ID of the device that next hop attaches to
117 * @param prefix IP prefix of the route
118 * @param hostMac MAC address of the next hop
Charles Chan7ffd81f2017-02-08 15:52:08 -0800119 * @param hostVlanId Vlan ID of the nexthop
Charles Chan1cdecff2016-10-27 14:19:48 -0700120 * @param outPort port where the next hop attaches to
sanghob35a6192015-04-01 13:05:26 -0700121 */
Charles Chan1cdecff2016-10-27 14:19:48 -0700122 public void populateRoute(DeviceId deviceId, IpPrefix prefix,
Charles Chan7ffd81f2017-02-08 15:52:08 -0800123 MacAddress hostMac, VlanId hostVlanId, PortNumber outPort) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700124 log.debug("Populate direct routing entry for route {} at {}:{}",
Charles Chan1cdecff2016-10-27 14:19:48 -0700125 prefix, deviceId, outPort);
Charles Chan68aa62d2015-11-09 16:37:23 -0800126 ForwardingObjective.Builder fwdBuilder;
Charles Chan0b4e6182015-11-03 10:42:14 -0800127 try {
Saurav Das961beb22017-03-29 19:09:17 -0700128 fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac,
129 hostVlanId, outPort, false);
Charles Chan0b4e6182015-11-03 10:42:14 -0800130 } catch (DeviceConfigNotFoundException e) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700131 log.warn(e.getMessage() + " Aborting direct populateRoute");
Charles Chan0b4e6182015-11-03 10:42:14 -0800132 return;
133 }
Saurav Das59232cf2016-04-27 18:35:50 -0700134 if (fwdBuilder == null) {
Saurav Das76ae6812017-03-15 15:15:14 -0700135 log.warn("Aborting host routing table entry due "
Charles Chan1cdecff2016-10-27 14:19:48 -0700136 + "to error for dev:{} route:{}", deviceId, prefix);
Saurav Das59232cf2016-04-27 18:35:50 -0700137 return;
138 }
Charles Chand2990362016-04-18 13:44:03 -0700139 ObjectiveContext context = new DefaultObjectiveContext(
Saurav Das7bcbe702017-06-13 15:35:54 -0700140 (objective) -> log.debug("Direct routing rule for route {} populated",
141 prefix),
Charles Chand2990362016-04-18 13:44:03 -0700142 (objective, error) ->
Saurav Das7bcbe702017-06-13 15:35:54 -0700143 log.warn("Failed to populate direct routing rule for route {}: {}",
Saurav Das76ae6812017-03-15 15:15:14 -0700144 prefix, error));
Charles Chand2990362016-04-18 13:44:03 -0700145 srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
Charles Chan68aa62d2015-11-09 16:37:23 -0800146 rulePopulationCounter.incrementAndGet();
147 }
148
Charles Chane849c192016-01-11 18:28:54 -0800149 /**
Charles Chan1cdecff2016-10-27 14:19:48 -0700150 * Removes IP rules for a route when the next hop is gone.
Charles Chane849c192016-01-11 18:28:54 -0800151 *
Charles Chan1cdecff2016-10-27 14:19:48 -0700152 * @param deviceId device ID of the device that next hop attaches to
153 * @param prefix IP prefix of the route
154 * @param hostMac MAC address of the next hop
Charles Chan7ffd81f2017-02-08 15:52:08 -0800155 * @param hostVlanId Vlan ID of the nexthop
Charles Chan1cdecff2016-10-27 14:19:48 -0700156 * @param outPort port that next hop attaches to
Charles Chane849c192016-01-11 18:28:54 -0800157 */
Charles Chan1cdecff2016-10-27 14:19:48 -0700158 public void revokeRoute(DeviceId deviceId, IpPrefix prefix,
Charles Chan7ffd81f2017-02-08 15:52:08 -0800159 MacAddress hostMac, VlanId hostVlanId, PortNumber outPort) {
Charles Chan1cdecff2016-10-27 14:19:48 -0700160 log.debug("Revoke IP table entry for route {} at {}:{}",
161 prefix, deviceId, outPort);
Charles Chan68aa62d2015-11-09 16:37:23 -0800162 ForwardingObjective.Builder fwdBuilder;
163 try {
Saurav Das961beb22017-03-29 19:09:17 -0700164 fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac,
165 hostVlanId, outPort, true);
Charles Chan68aa62d2015-11-09 16:37:23 -0800166 } catch (DeviceConfigNotFoundException e) {
167 log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
168 return;
169 }
Charles Chan458b8262016-11-30 11:55:05 -0800170 if (fwdBuilder == null) {
171 log.warn("Aborting host routing table entries due "
172 + "to error for dev:{} route:{}", deviceId, prefix);
173 return;
174 }
Charles Chand2990362016-04-18 13:44:03 -0700175 ObjectiveContext context = new DefaultObjectiveContext(
Charles Chan1cdecff2016-10-27 14:19:48 -0700176 (objective) -> log.debug("IP rule for route {} revoked", prefix),
Charles Chand2990362016-04-18 13:44:03 -0700177 (objective, error) ->
Charles Chan1cdecff2016-10-27 14:19:48 -0700178 log.warn("Failed to revoke IP rule for route {}: {}", prefix, error));
Charles Chand2990362016-04-18 13:44:03 -0700179 srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
Charles Chan68aa62d2015-11-09 16:37:23 -0800180 }
181
Charles Chan1cdecff2016-10-27 14:19:48 -0700182 /**
Charles Chanf6ec1532017-02-08 16:10:40 -0800183 * Returns a forwarding objective builder for routing rules.
184 * <p>
185 * The forwarding objective routes packets destined to a given prefix to
186 * given port on given device with given destination MAC.
Charles Chan1cdecff2016-10-27 14:19:48 -0700187 *
188 * @param deviceId device ID
189 * @param prefix prefix that need to be routed
190 * @param hostMac MAC address of the nexthop
Charles Chan7ffd81f2017-02-08 15:52:08 -0800191 * @param hostVlanId Vlan ID of the nexthop
Charles Chan1cdecff2016-10-27 14:19:48 -0700192 * @param outPort port where the nexthop attaches to
Saurav Das961beb22017-03-29 19:09:17 -0700193 * @param revoke true if forwarding objective is meant to revoke forwarding rule
Charles Chan1cdecff2016-10-27 14:19:48 -0700194 * @return forwarding objective builder
195 * @throws DeviceConfigNotFoundException if given device is not configured
196 */
Charles Chanf6ec1532017-02-08 16:10:40 -0800197 private ForwardingObjective.Builder routingFwdObjBuilder(
Charles Chan1cdecff2016-10-27 14:19:48 -0700198 DeviceId deviceId, IpPrefix prefix,
Saurav Das961beb22017-03-29 19:09:17 -0700199 MacAddress hostMac, VlanId hostVlanId, PortNumber outPort,
200 boolean revoke)
Charles Chan68aa62d2015-11-09 16:37:23 -0800201 throws DeviceConfigNotFoundException {
202 MacAddress deviceMac;
203 deviceMac = config.getDeviceMac(deviceId);
Charles Chan0b4e6182015-11-03 10:42:14 -0800204
Charles Chan7ffd81f2017-02-08 15:52:08 -0800205 ConnectPoint connectPoint = new ConnectPoint(deviceId, outPort);
206 VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint);
207 Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint);
208 VlanId nativeVlan = srManager.getNativeVlanId(connectPoint);
sanghob35a6192015-04-01 13:05:26 -0700209
Charles Chan7ffd81f2017-02-08 15:52:08 -0800210 // Create route selector
211 TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix);
212
213 // Create route treatment
Charles Chan1cdecff2016-10-27 14:19:48 -0700214 TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
sangho1e575652015-05-14 00:39:53 -0700215 tbuilder.deferred()
216 .setEthDst(hostMac)
Charles Chan0b4e6182015-11-03 10:42:14 -0800217 .setEthSrc(deviceMac)
sanghob35a6192015-04-01 13:05:26 -0700218 .setOutput(outPort);
Saurav Das4ce45962015-11-24 23:21:05 -0800219
Charles Chan7ffd81f2017-02-08 15:52:08 -0800220 // Create route meta
221 TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
Charles Chan59cc16d2017-02-02 16:20:42 -0800222
Charles Chan7ffd81f2017-02-08 15:52:08 -0800223 // Adjust the meta according to VLAN configuration
224 if (taggedVlans.contains(hostVlanId)) {
225 tbuilder.setVlanId(hostVlanId);
226 } else if (hostVlanId.equals(VlanId.NONE)) {
227 if (untaggedVlan != null) {
228 mbuilder.matchVlanId(untaggedVlan);
229 } else if (nativeVlan != null) {
230 mbuilder.matchVlanId(nativeVlan);
231 } else {
Charles Chan65238242017-06-22 18:03:14 -0700232 log.warn("Untagged nexthop {}/{} is not allowed on {} without untagged or native vlan",
233 hostMac, hostVlanId, connectPoint);
234 return null;
Charles Chan7ffd81f2017-02-08 15:52:08 -0800235 }
236 } else {
Saurav Das961beb22017-03-29 19:09:17 -0700237 log.warn("Tagged nexthop {}/{} is not allowed on {} without VLAN listed"
238 + " in tagged vlan", hostMac, hostVlanId, connectPoint);
Saurav Das59232cf2016-04-27 18:35:50 -0700239 return null;
240 }
Saurav Das961beb22017-03-29 19:09:17 -0700241 // if the objective is to revoke an existing rule, and for some reason
242 // the next-objective does not exist, then a new one should not be created
Charles Chan7ffd81f2017-02-08 15:52:08 -0800243 int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outPort,
Saurav Das961beb22017-03-29 19:09:17 -0700244 tbuilder.build(), mbuilder.build(), !revoke);
Charles Chan7ffd81f2017-02-08 15:52:08 -0800245 if (portNextObjId == -1) {
246 // Warning log will come from getPortNextObjective method
247 return null;
248 }
249
Charles Chan68aa62d2015-11-09 16:37:23 -0800250 return DefaultForwardingObjective.builder()
Charles Chan7ffd81f2017-02-08 15:52:08 -0800251 .withSelector(sbuilder.build())
Saurav Das4ce45962015-11-24 23:21:05 -0800252 .nextStep(portNextObjId)
Charles Chan68aa62d2015-11-09 16:37:23 -0800253 .fromApp(srManager.appId).makePermanent()
Charles Chan1cdecff2016-10-27 14:19:48 -0700254 .withPriority(getPriorityFromPrefix(prefix))
Charles Chan5270ed02016-01-30 23:22:37 -0800255 .withFlag(ForwardingObjective.Flag.SPECIFIC);
sanghob35a6192015-04-01 13:05:26 -0700256 }
257
258 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700259 * Populates IP flow rules for all the given prefixes reachable from the
260 * destination switch(es).
sanghob35a6192015-04-01 13:05:26 -0700261 *
Saurav Das7bcbe702017-06-13 15:35:54 -0700262 * @param targetSw switch where rules are to be programmed
263 * @param subnets subnets/prefixes being added
264 * @param destSw1 destination switch where the prefixes are reachable
265 * @param destSw2 paired destination switch if one exists for the subnets/prefixes.
266 * Should be null if there is no paired destination switch (by config)
267 * or if the given prefixes are reachable only via destSw1
268 * @param nextHops a map containing a set of next-hops for each destination switch.
269 * If destSw2 is not null, then this map must contain an
270 * entry for destSw2 with its next-hops from the targetSw
271 * (although the next-hop set may be empty in certain scenarios).
272 * If destSw2 is null, there should not be an entry in this
273 * map for destSw2.
sanghob35a6192015-04-01 13:05:26 -0700274 * @return true if all rules are set successfully, false otherwise
275 */
Charles Chan65238242017-06-22 18:03:14 -0700276 boolean populateIpRuleForSubnet(DeviceId targetSw, Set<IpPrefix> subnets,
Saurav Das7bcbe702017-06-13 15:35:54 -0700277 DeviceId destSw1, DeviceId destSw2, Map<DeviceId, Set<DeviceId>> nextHops) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700278 for (IpPrefix subnet : subnets) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700279 if (!populateIpRuleForRouter(targetSw, subnet, destSw1, destSw2, nextHops)) {
sanghob35a6192015-04-01 13:05:26 -0700280 return false;
281 }
282 }
Charles Chan93e71ba2016-04-29 14:38:22 -0700283 return true;
284 }
sanghob35a6192015-04-01 13:05:26 -0700285
Charles Chan93e71ba2016-04-29 14:38:22 -0700286 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700287 * Revokes IP flow rules for the subnets in each edge switch.
Charles Chan93e71ba2016-04-29 14:38:22 -0700288 *
289 * @param subnets subnet being removed
290 * @return true if all rules are removed successfully, false otherwise
291 */
Charles Chan65238242017-06-22 18:03:14 -0700292 boolean revokeIpRuleForSubnet(Set<IpPrefix> subnets) {
Charles Chan93e71ba2016-04-29 14:38:22 -0700293 for (IpPrefix subnet : subnets) {
294 if (!revokeIpRuleForRouter(subnet)) {
295 return false;
296 }
297 }
sanghob35a6192015-04-01 13:05:26 -0700298 return true;
299 }
300
301 /**
Saurav Das25190812016-05-27 13:54:07 -0700302 * Populates IP flow rules for an IP prefix in the target device. The prefix
Saurav Das7bcbe702017-06-13 15:35:54 -0700303 * is reachable via destination device(s).
sanghob35a6192015-04-01 13:05:26 -0700304 *
Saurav Das7bcbe702017-06-13 15:35:54 -0700305 * @param targetSw target device ID to set the rules
306 * @param ipPrefix the IP prefix
307 * @param destSw1 destination switch where the prefixes are reachable
308 * @param destSw2 paired destination switch if one exists for the subnets/prefixes.
309 * Should be null if there is no paired destination switch (by config)
310 * or if the given prefixes are reachable only via destSw1
311 * @param nextHops map of destination switches and their next-hops.
312 * Should only contain destination switches that are
313 * actually meant to be routed to. If destSw2 is null, there
314 * should not be an entry for destSw2 in this map.
sanghob35a6192015-04-01 13:05:26 -0700315 * @return true if all rules are set successfully, false otherwise
316 */
Charles Chan65238242017-06-22 18:03:14 -0700317 private boolean populateIpRuleForRouter(DeviceId targetSw,
Saurav Das7bcbe702017-06-13 15:35:54 -0700318 IpPrefix ipPrefix, DeviceId destSw1,
319 DeviceId destSw2,
320 Map<DeviceId, Set<DeviceId>> nextHops) {
321 int segmentId1, segmentId2 = -1;
Charles Chan0b4e6182015-11-03 10:42:14 -0800322 try {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800323 if (ipPrefix.isIp4()) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700324 segmentId1 = config.getIPv4SegmentId(destSw1);
325 if (destSw2 != null) {
326 segmentId2 = config.getIPv4SegmentId(destSw2);
327 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800328 } else {
Saurav Das7bcbe702017-06-13 15:35:54 -0700329 segmentId1 = config.getIPv6SegmentId(destSw1);
330 if (destSw2 != null) {
331 segmentId2 = config.getIPv6SegmentId(destSw2);
332 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800333 }
Charles Chan0b4e6182015-11-03 10:42:14 -0800334 } catch (DeviceConfigNotFoundException e) {
335 log.warn(e.getMessage() + " Aborting populateIpRuleForRouter.");
336 return false;
337 }
sanghob35a6192015-04-01 13:05:26 -0700338
Pier Ventree0ae7a32016-11-23 09:57:42 -0800339 TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix);
Charles Chan68aa62d2015-11-09 16:37:23 -0800340 TrafficSelector selector = sbuilder.build();
sanghob35a6192015-04-01 13:05:26 -0700341
Charles Chan68aa62d2015-11-09 16:37:23 -0800342 TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
Saurav Das7bcbe702017-06-13 15:35:54 -0700343 DestinationSet ds;
Charles Chan68aa62d2015-11-09 16:37:23 -0800344 TrafficTreatment treatment;
sanghob35a6192015-04-01 13:05:26 -0700345
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700346 // If the next hop is the same as the final destination, then MPLS label
347 // is not set.
Saurav Das7bcbe702017-06-13 15:35:54 -0700348 /*if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) {
Charles Chan68aa62d2015-11-09 16:37:23 -0800349 tbuilder.immediate().decNwTtl();
Saurav Das7bcbe702017-06-13 15:35:54 -0700350 ds = new DestinationSet(false, destSw);
Charles Chan68aa62d2015-11-09 16:37:23 -0800351 treatment = tbuilder.build();
sanghob35a6192015-04-01 13:05:26 -0700352 } else {
Saurav Das7bcbe702017-06-13 15:35:54 -0700353 ds = new DestinationSet(false, segmentId, destSw);
354 treatment = null;
355 }*/
356 if (destSw2 == null) {
357 // single dst - create destination set based on next-hop
358 Set<DeviceId> nhd1 = nextHops.get(destSw1);
359 if (nhd1.size() == 1 && nhd1.iterator().next().equals(destSw1)) {
360 tbuilder.immediate().decNwTtl();
361 ds = new DestinationSet(false, destSw1);
362 treatment = tbuilder.build();
363 } else {
364 ds = new DestinationSet(false, segmentId1, destSw1);
365 treatment = null;
366 }
367 } else {
368 // dst pair - IP rules for dst-pairs are always from other edge nodes
369 // the destination set needs to have both destinations, even if there
370 // are no next hops to one of them
371 ds = new DestinationSet(false, segmentId1, destSw1, segmentId2, destSw2);
Charles Chan68aa62d2015-11-09 16:37:23 -0800372 treatment = null;
sanghob35a6192015-04-01 13:05:26 -0700373 }
374
Saurav Das8a0732e2015-11-20 15:27:53 -0800375 // setup metadata to pass to nextObjective - indicate the vlan on egress
376 // if needed by the switch pipeline. Since neighbor sets are always to
377 // other neighboring routers, there is no subnet assigned on those ports.
378 TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector);
Charles Chan59cc16d2017-02-02 16:20:42 -0800379 metabuilder.matchVlanId(SegmentRoutingManager.INTERNAL_VLAN);
Saurav Das7bcbe702017-06-13 15:35:54 -0700380 DefaultGroupHandler grpHandler = srManager.getGroupHandler(targetSw);
Saurav Dasc88d4662017-05-15 15:34:25 -0700381 if (grpHandler == null) {
382 log.warn("populateIPRuleForRouter: groupHandler for device {} "
Saurav Das7bcbe702017-06-13 15:35:54 -0700383 + "not found", targetSw);
Saurav Dasc88d4662017-05-15 15:34:25 -0700384 return false;
385 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800386
Saurav Das7bcbe702017-06-13 15:35:54 -0700387 int nextId = grpHandler.getNextObjectiveId(ds, nextHops,
388 metabuilder.build(), true);
Saurav Das8a0732e2015-11-20 15:27:53 -0800389 if (nextId <= 0) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700390 log.warn("No next objective in {} for ds: {}", targetSw, ds);
sangho834e4b02015-05-01 09:38:25 -0700391 return false;
392 }
393
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700394 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
395 .builder()
396 .fromApp(srManager.appId)
397 .makePermanent()
Saurav Das8a0732e2015-11-20 15:27:53 -0800398 .nextStep(nextId)
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700399 .withSelector(selector)
Charles Chan5270ed02016-01-30 23:22:37 -0800400 .withPriority(getPriorityFromPrefix(ipPrefix))
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700401 .withFlag(ForwardingObjective.Flag.SPECIFIC);
Charles Chan68aa62d2015-11-09 16:37:23 -0800402 if (treatment != null) {
403 fwdBuilder.withTreatment(treatment);
404 }
Saurav Dasc88d4662017-05-15 15:34:25 -0700405 log.debug("Installing IPv4 forwarding objective for router IP/subnet {} "
Saurav Das7bcbe702017-06-13 15:35:54 -0700406 + "in switch {} with nextId: {}", ipPrefix, targetSw, nextId);
Charles Chand2990362016-04-18 13:44:03 -0700407 ObjectiveContext context = new DefaultObjectiveContext(
Saurav Das25190812016-05-27 13:54:07 -0700408 (objective) -> log.debug("IP rule for router {} populated in dev:{}",
Saurav Das7bcbe702017-06-13 15:35:54 -0700409 ipPrefix, targetSw),
Charles Chand2990362016-04-18 13:44:03 -0700410 (objective, error) ->
Saurav Das25190812016-05-27 13:54:07 -0700411 log.warn("Failed to populate IP rule for router {}: {} in dev:{}",
Saurav Das7bcbe702017-06-13 15:35:54 -0700412 ipPrefix, error, targetSw));
413 srManager.flowObjectiveService.forward(targetSw, fwdBuilder.add(context));
sangho20eff1d2015-04-13 15:15:58 -0700414 rulePopulationCounter.incrementAndGet();
sanghob35a6192015-04-01 13:05:26 -0700415
416 return true;
417 }
418
sanghob35a6192015-04-01 13:05:26 -0700419 /**
Charles Chan93e71ba2016-04-29 14:38:22 -0700420 * Revokes IP flow rules for the router IP address.
421 *
422 * @param ipPrefix the IP address of the destination router
423 * @return true if all rules are removed successfully, false otherwise
424 */
Charles Chan65238242017-06-22 18:03:14 -0700425 private boolean revokeIpRuleForRouter(IpPrefix ipPrefix) {
Pier Ventre968da122016-12-09 17:26:04 -0800426 TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix);
Charles Chan93e71ba2016-04-29 14:38:22 -0700427 TrafficSelector selector = sbuilder.build();
428 TrafficTreatment dummyTreatment = DefaultTrafficTreatment.builder().build();
429
430 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
431 .builder()
432 .fromApp(srManager.appId)
433 .makePermanent()
434 .withSelector(selector)
435 .withTreatment(dummyTreatment)
436 .withPriority(getPriorityFromPrefix(ipPrefix))
437 .withFlag(ForwardingObjective.Flag.SPECIFIC);
438
439 ObjectiveContext context = new DefaultObjectiveContext(
440 (objective) -> log.debug("IP rule for router {} revoked", ipPrefix),
441 (objective, error) ->
442 log.warn("Failed to revoke IP rule for router {}: {}", ipPrefix, error));
443
Charles Chan65238242017-06-22 18:03:14 -0700444 srManager.deviceService.getAvailableDevices().forEach(device ->
445 srManager.flowObjectiveService.forward(device.id(), fwdBuilder.remove(context))
446 );
Charles Chan93e71ba2016-04-29 14:38:22 -0700447
448 return true;
449 }
450
451 /**
Pier Ventre917127a2016-10-31 16:49:19 -0700452 * Deals with !MPLS Bos use case.
453 *
454 * @param targetSwId the target sw
455 * @param destSwId the destination sw
456 * @param nextHops the set of next hops
457 * @param segmentId the segmentId to match
458 * @param routerIp the router ip
459 * @return a collection of fwdobjective
460 */
Saurav Das7bcbe702017-06-13 15:35:54 -0700461 private Collection<ForwardingObjective> handleMpls(
462 DeviceId targetSwId,
463 DeviceId destSwId,
464 Set<DeviceId> nextHops,
465 int segmentId,
466 IpAddress routerIp,
467 boolean isMplsBos) {
Pier Ventre917127a2016-10-31 16:49:19 -0700468
469 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
470 List<ForwardingObjective.Builder> fwdObjBuilders = Lists.newArrayList();
Pier Luigi3bfe32c2017-01-30 09:47:36 -0800471 // For the transport of Pwaas we can use two or three MPLS label
Pier Ventre917127a2016-10-31 16:49:19 -0700472 sbuilder.matchEthType(Ethernet.MPLS_UNICAST);
473 sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId));
474 sbuilder.matchMplsBos(isMplsBos);
475 TrafficSelector selector = sbuilder.build();
476
477 // setup metadata to pass to nextObjective - indicate the vlan on egress
478 // if needed by the switch pipeline. Since mpls next-hops are always to
479 // other neighboring routers, there is no subnet assigned on those ports.
480 TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector);
Charles Chan59cc16d2017-02-02 16:20:42 -0800481 metabuilder.matchVlanId(SegmentRoutingManager.INTERNAL_VLAN);
Pier Ventre917127a2016-10-31 16:49:19 -0700482
483 if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) {
484 // If the next hop is the destination router for the segment, do pop
485 log.debug("populateMplsRule: Installing MPLS forwarding objective for "
Saurav Das7bcbe702017-06-13 15:35:54 -0700486 + "label {} in switch {} with pop to next-hops {}",
487 segmentId, targetSwId, nextHops);
Pier Ventre917127a2016-10-31 16:49:19 -0700488 // Not-bos pop case (php for the current label). If MPLS-ECMP
489 // has been configured, the application we will request the
490 // installation for an MPLS-ECMP group.
Saurav Das961beb22017-03-29 19:09:17 -0700491 ForwardingObjective.Builder fwdObjNoBosBuilder =
492 getMplsForwardingObjective(targetSwId,
493 nextHops,
494 true,
495 isMplsBos,
496 metabuilder.build(),
Saurav Dasc88d4662017-05-15 15:34:25 -0700497 routerIp,
498 destSwId);
Pier Ventre917127a2016-10-31 16:49:19 -0700499 // Error case, we cannot handle, exit.
500 if (fwdObjNoBosBuilder == null) {
501 return Collections.emptyList();
502 }
503 fwdObjBuilders.add(fwdObjNoBosBuilder);
504
505 } else {
506 // next hop is not destination, SR CONTINUE case (swap with self)
Saurav Das7bcbe702017-06-13 15:35:54 -0700507 log.debug("Installing MPLS forwarding objective for "
508 + "label {} in switch {} without pop to next-hops {}",
509 segmentId, targetSwId, nextHops);
Pier Ventre917127a2016-10-31 16:49:19 -0700510 // Not-bos pop case. If MPLS-ECMP has been configured, the
511 // application we will request the installation for an MPLS-ECMP
512 // group.
Saurav Das961beb22017-03-29 19:09:17 -0700513 ForwardingObjective.Builder fwdObjNoBosBuilder =
514 getMplsForwardingObjective(targetSwId,
515 nextHops,
516 false,
517 isMplsBos,
518 metabuilder.build(),
Saurav Dasc88d4662017-05-15 15:34:25 -0700519 routerIp,
520 destSwId);
Pier Ventre917127a2016-10-31 16:49:19 -0700521 // Error case, we cannot handle, exit.
522 if (fwdObjNoBosBuilder == null) {
523 return Collections.emptyList();
524 }
525 fwdObjBuilders.add(fwdObjNoBosBuilder);
526
527 }
528
529 List<ForwardingObjective> fwdObjs = Lists.newArrayList();
530 // We add the final property to the fwdObjs.
531 for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) {
532
533 ((Builder) ((Builder) fwdObjBuilder
534 .fromApp(srManager.appId)
535 .makePermanent())
536 .withSelector(selector)
537 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY))
538 .withFlag(ForwardingObjective.Flag.SPECIFIC);
539
540 ObjectiveContext context = new DefaultObjectiveContext(
541 (objective) ->
542 log.debug("MPLS rule {} for SID {} populated in dev:{} ",
543 objective.id(), segmentId, targetSwId),
544 (objective, error) ->
545 log.warn("Failed to populate MPLS rule {} for SID {}: {} in dev:{}",
546 objective.id(), segmentId, error, targetSwId));
547
548 ForwardingObjective fob = fwdObjBuilder.add(context);
549 fwdObjs.add(fob);
550
551 }
552
553 return fwdObjs;
554 }
555
556 /**
Saurav Das25190812016-05-27 13:54:07 -0700557 * Populates MPLS flow rules in the target device to point towards the
558 * destination device.
sanghob35a6192015-04-01 13:05:26 -0700559 *
Saurav Das25190812016-05-27 13:54:07 -0700560 * @param targetSwId target device ID of the switch to set the rules
sanghob35a6192015-04-01 13:05:26 -0700561 * @param destSwId destination switch device ID
562 * @param nextHops next hops switch ID list
Pier Ventre917127a2016-10-31 16:49:19 -0700563 * @param routerIp the router ip
sanghob35a6192015-04-01 13:05:26 -0700564 * @return true if all rules are set successfully, false otherwise
565 */
Charles Chan65238242017-06-22 18:03:14 -0700566 boolean populateMplsRule(DeviceId targetSwId, DeviceId destSwId,
Saurav Das7bcbe702017-06-13 15:35:54 -0700567 Set<DeviceId> nextHops,
568 IpAddress routerIp) {
Pier Ventre917127a2016-10-31 16:49:19 -0700569
Charles Chan0b4e6182015-11-03 10:42:14 -0800570 int segmentId;
571 try {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800572 if (routerIp.isIp4()) {
573 segmentId = config.getIPv4SegmentId(destSwId);
574 } else {
575 segmentId = config.getIPv6SegmentId(destSwId);
576 }
Charles Chan0b4e6182015-11-03 10:42:14 -0800577 } catch (DeviceConfigNotFoundException e) {
578 log.warn(e.getMessage() + " Aborting populateMplsRule.");
579 return false;
580 }
sanghob35a6192015-04-01 13:05:26 -0700581
Pier Ventre917127a2016-10-31 16:49:19 -0700582 List<ForwardingObjective> fwdObjs = new ArrayList<>();
Charles Chan65238242017-06-22 18:03:14 -0700583 Collection<ForwardingObjective> fwdObjsMpls;
Pier Ventre917127a2016-10-31 16:49:19 -0700584 // Generates the transit rules used by the standard "routing".
585 fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, routerIp, true);
586 if (fwdObjsMpls.isEmpty()) {
587 return false;
sanghob35a6192015-04-01 13:05:26 -0700588 }
Pier Ventre917127a2016-10-31 16:49:19 -0700589 fwdObjs.addAll(fwdObjsMpls);
Pier Luigi3bfe32c2017-01-30 09:47:36 -0800590 // Generates the transit rules used by the MPLS Pwaas. For now it is
Pier Ventre917127a2016-10-31 16:49:19 -0700591 // the only case !BoS supported.
Charles Chan65238242017-06-22 18:03:14 -0700592 /*
593 fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, routerIp, false);
Pier Ventre917127a2016-10-31 16:49:19 -0700594 if (fwdObjsMpls.isEmpty()) {
595 return false;
596 }
Charles Chan65238242017-06-22 18:03:14 -0700597 fwdObjs.addAll(fwdObjsMpls);
598 */
Pier Ventre917127a2016-10-31 16:49:19 -0700599
600 for (ForwardingObjective fwdObj : fwdObjs) {
Saurav Das25190812016-05-27 13:54:07 -0700601 log.debug("Sending MPLS fwd obj {} for SID {}-> next {} in sw: {}",
Pier Ventre917127a2016-10-31 16:49:19 -0700602 fwdObj.id(), segmentId, fwdObj.nextId(), targetSwId);
603 srManager.flowObjectiveService.forward(targetSwId, fwdObj);
sangho20eff1d2015-04-13 15:15:58 -0700604 rulePopulationCounter.incrementAndGet();
sanghob35a6192015-04-01 13:05:26 -0700605 }
606
607 return true;
608 }
609
Saurav Das8a0732e2015-11-20 15:27:53 -0800610 private ForwardingObjective.Builder getMplsForwardingObjective(
Saurav Das7bcbe702017-06-13 15:35:54 -0700611 DeviceId targetSw,
Saurav Das8a0732e2015-11-20 15:27:53 -0800612 Set<DeviceId> nextHops,
613 boolean phpRequired,
614 boolean isBos,
Pier Ventree0ae7a32016-11-23 09:57:42 -0800615 TrafficSelector meta,
Saurav Dasc88d4662017-05-15 15:34:25 -0700616 IpAddress routerIp,
617 DeviceId destSw) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800618
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700619 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
620 .builder().withFlag(ForwardingObjective.Flag.SPECIFIC);
sanghob35a6192015-04-01 13:05:26 -0700621
622 TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
623
624 if (phpRequired) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800625 // php case - pop should always be flow-action
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700626 log.debug("getMplsForwardingObjective: php required");
sangho1e575652015-05-14 00:39:53 -0700627 tbuilder.deferred().copyTtlIn();
sanghob35a6192015-04-01 13:05:26 -0700628 if (isBos) {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800629 if (routerIp.isIp4()) {
630 tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType());
631 } else {
632 tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType());
633 }
634 tbuilder.decNwTtl();
sanghob35a6192015-04-01 13:05:26 -0700635 } else {
Saurav Das8a0732e2015-11-20 15:27:53 -0800636 tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType())
637 .decMplsTtl();
sanghob35a6192015-04-01 13:05:26 -0700638 }
639 } else {
Saurav Das8a0732e2015-11-20 15:27:53 -0800640 // swap with self case - SR CONTINUE
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700641 log.debug("getMplsForwardingObjective: php not required");
sangho1e575652015-05-14 00:39:53 -0700642 tbuilder.deferred().decMplsTtl();
sanghob35a6192015-04-01 13:05:26 -0700643 }
644
Saurav Das8a0732e2015-11-20 15:27:53 -0800645 fwdBuilder.withTreatment(tbuilder.build());
Pier Ventre917127a2016-10-31 16:49:19 -0700646 // if MPLS-ECMP == True we will build a standard NeighborSet.
647 // Otherwise a RandomNeighborSet.
Saurav Das7bcbe702017-06-13 15:35:54 -0700648 DestinationSet ns = DestinationSet.destinationSet(false, false, destSw);
Pier Ventre917127a2016-10-31 16:49:19 -0700649 if (!isBos && this.srManager.getMplsEcmp()) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700650 ns = DestinationSet.destinationSet(false, true, destSw);
Pier Ventre917127a2016-10-31 16:49:19 -0700651 } else if (!isBos && !this.srManager.getMplsEcmp()) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700652 ns = DestinationSet.destinationSet(true, true, destSw);
Pier Ventre917127a2016-10-31 16:49:19 -0700653 }
Saurav Das7bcbe702017-06-13 15:35:54 -0700654
Saurav Dasb28d5dd2017-03-24 19:03:58 -0700655 log.debug("Trying to get a nextObjId for mpls rule on device:{} to ns:{}",
Saurav Das7bcbe702017-06-13 15:35:54 -0700656 targetSw, ns);
657 DefaultGroupHandler gh = srManager.getGroupHandler(targetSw);
658 if (gh == null) {
659 log.warn("getNextObjectiveId query - groupHandler for device {} "
660 + "not found", targetSw);
661 return null;
662 }
Pier Ventre917127a2016-10-31 16:49:19 -0700663 // If BoS == True, all forwarding is via L3 ECMP group.
664 // If Bos == False, the forwarding can be via MPLS-ECMP group or through
665 // MPLS-Interface group. This depends on the configuration of the option
666 // MPLS-ECMP.
667 // The metadata informs the driver that the next-Objective will be used
668 // by MPLS flows and if Bos == False the driver will use MPLS groups.
Saurav Das7bcbe702017-06-13 15:35:54 -0700669 Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>();
670 dstNextHops.put(destSw, nextHops);
671 int nextId = gh.getNextObjectiveId(ns, dstNextHops, meta, isBos);
Saurav Das8a0732e2015-11-20 15:27:53 -0800672 if (nextId <= 0) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700673 log.warn("No next objective in {} for ns: {}", targetSw, ns);
Saurav Das8a0732e2015-11-20 15:27:53 -0800674 return null;
Saurav Das25190812016-05-27 13:54:07 -0700675 } else {
676 log.debug("nextObjId found:{} for mpls rule on device:{} to ns:{}",
Saurav Das7bcbe702017-06-13 15:35:54 -0700677 nextId, targetSw, ns);
sanghob35a6192015-04-01 13:05:26 -0700678 }
679
Saurav Das8a0732e2015-11-20 15:27:53 -0800680 fwdBuilder.nextStep(nextId);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700681 return fwdBuilder;
sanghob35a6192015-04-01 13:05:26 -0700682 }
683
684 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700685 * Creates a filtering objective to permit all untagged packets with a
Saurav Das0e99e2b2015-10-28 12:39:42 -0700686 * dstMac corresponding to the router's MAC address. For those pipelines
687 * that need to internally assign vlans to untagged packets, this method
688 * provides per-subnet vlan-ids as metadata.
Saurav Das837e0bb2015-10-30 17:45:38 -0700689 * <p>
Saurav Das018605f2017-02-18 14:05:44 -0800690 * Note that the vlan assignment and filter programming should only be done by
691 * the master for a switch. This method is typically called at deviceAdd and
692 * programs filters only for the enabled ports of the device. For port-updates,
693 * that enable/disable ports after device add, singlePortFilter methods should
694 * be called.
sanghob35a6192015-04-01 13:05:26 -0700695 *
Saurav Das822c4e22015-10-23 10:51:11 -0700696 * @param deviceId the switch dpid for the router
Saurav Dasd2fded02016-12-02 15:43:47 -0800697 * @return PortFilterInfo information about the processed ports
sanghob35a6192015-04-01 13:05:26 -0700698 */
Charles Chan65238242017-06-22 18:03:14 -0700699 PortFilterInfo populateVlanMacFilters(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700700 log.debug("Installing per-port filtering objective for untagged "
701 + "packets in device {}", deviceId);
Charles Chan0b4e6182015-11-03 10:42:14 -0800702
Saurav Das59232cf2016-04-27 18:35:50 -0700703 List<Port> devPorts = srManager.deviceService.getPorts(deviceId);
Jon Hallcbd1b392017-01-18 20:15:44 -0800704 if (devPorts == null || devPorts.isEmpty()) {
Saurav Das59232cf2016-04-27 18:35:50 -0700705 log.warn("Device {} ports not available. Unable to add MacVlan filters",
706 deviceId);
Saurav Dasd2fded02016-12-02 15:43:47 -0800707 return null;
Saurav Das59232cf2016-04-27 18:35:50 -0700708 }
Saurav Das018605f2017-02-18 14:05:44 -0800709 int disabledPorts = 0, errorPorts = 0, filteredPorts = 0;
Saurav Das59232cf2016-04-27 18:35:50 -0700710 for (Port port : devPorts) {
Saurav Das25190812016-05-27 13:54:07 -0700711 if (!port.isEnabled()) {
712 disabledPorts++;
713 continue;
714 }
Charles Chan7e4f8192017-02-26 22:59:35 -0800715 if (processSinglePortFilters(deviceId, port.number(), true)) {
Saurav Das018605f2017-02-18 14:05:44 -0800716 filteredPorts++;
717 } else {
718 errorPorts++;
Saurav Das25190812016-05-27 13:54:07 -0700719 }
Saurav Das0e99e2b2015-10-28 12:39:42 -0700720 }
Charles Chan7f9737b2017-06-22 14:27:17 -0700721 log.debug("Filtering on dev:{}, disabledPorts:{}, errorPorts:{}, filteredPorts:{}",
Saurav Das018605f2017-02-18 14:05:44 -0800722 deviceId, disabledPorts, errorPorts, filteredPorts);
Saurav Dasd2fded02016-12-02 15:43:47 -0800723 return srManager.defaultRoutingHandler.new PortFilterInfo(disabledPorts,
Saurav Das018605f2017-02-18 14:05:44 -0800724 errorPorts, filteredPorts);
725 }
726
727 /**
Charles Chan7e4f8192017-02-26 22:59:35 -0800728 * Creates or removes filtering objectives for a single port. Should only be
729 * called by the master for a switch.
Saurav Das018605f2017-02-18 14:05:44 -0800730 *
731 * @param deviceId device identifier
732 * @param portnum port identifier for port to be filtered
Charles Chan7e4f8192017-02-26 22:59:35 -0800733 * @param install true to install the filtering objective, false to remove
Saurav Das018605f2017-02-18 14:05:44 -0800734 * @return true if no errors occurred during the build of the filtering objective
735 */
Charles Chan65238242017-06-22 18:03:14 -0700736 boolean processSinglePortFilters(DeviceId deviceId, PortNumber portnum, boolean install) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800737 ConnectPoint connectPoint = new ConnectPoint(deviceId, portnum);
738 VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint);
739 Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint);
740 VlanId nativeVlan = srManager.getNativeVlanId(connectPoint);
741
742 if (taggedVlans.size() != 0) {
743 // Filter for tagged vlans
744 if (!srManager.getTaggedVlanId(connectPoint).stream().allMatch(taggedVlanId ->
Charles Chan7e4f8192017-02-26 22:59:35 -0800745 processSinglePortFiltersInternal(deviceId, portnum, false, taggedVlanId, install))) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800746 return false;
747 }
748 if (nativeVlan != null) {
749 // Filter for native vlan
Charles Chan7e4f8192017-02-26 22:59:35 -0800750 if (!processSinglePortFiltersInternal(deviceId, portnum, true, nativeVlan, install)) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800751 return false;
752 }
753 }
754 } else if (untaggedVlan != null) {
755 // Filter for untagged vlan
Charles Chan7e4f8192017-02-26 22:59:35 -0800756 if (!processSinglePortFiltersInternal(deviceId, portnum, true, untaggedVlan, install)) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800757 return false;
758 }
759 } else {
760 // Unconfigure port, use INTERNAL_VLAN
Charles Chan7e4f8192017-02-26 22:59:35 -0800761 if (!processSinglePortFiltersInternal(deviceId, portnum, true, INTERNAL_VLAN, install)) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800762 return false;
763 }
764 }
765 return true;
766 }
767
Charles Chan7e4f8192017-02-26 22:59:35 -0800768 private boolean processSinglePortFiltersInternal(DeviceId deviceId, PortNumber portnum,
769 boolean pushVlan, VlanId vlanId, boolean install) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800770 FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum, pushVlan, vlanId);
Saurav Das018605f2017-02-18 14:05:44 -0800771 if (fob == null) {
772 // error encountered during build
773 return false;
774 }
Saurav Dasc88d4662017-05-15 15:34:25 -0700775 log.debug("{} filtering objectives for dev/port:{}/{}",
776 install ? "Installing" : "Removing", deviceId, portnum);
Saurav Das018605f2017-02-18 14:05:44 -0800777 ObjectiveContext context = new DefaultObjectiveContext(
Charles Chan7e4f8192017-02-26 22:59:35 -0800778 (objective) -> log.debug("Filter for {}/{} {}", deviceId, portnum,
Saurav Dasc88d4662017-05-15 15:34:25 -0700779 install ? "installed" : "removed"),
Charles Chan7e4f8192017-02-26 22:59:35 -0800780 (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}",
Saurav Dasc88d4662017-05-15 15:34:25 -0700781 install ? "install" : "remove", deviceId, portnum, error));
Charles Chan7e4f8192017-02-26 22:59:35 -0800782 if (install) {
783 srManager.flowObjectiveService.filter(deviceId, fob.add(context));
784 } else {
785 srManager.flowObjectiveService.filter(deviceId, fob.remove(context));
Charles Chan7ffd81f2017-02-08 15:52:08 -0800786 }
Charles Chan7ffd81f2017-02-08 15:52:08 -0800787 return true;
Saurav Das018605f2017-02-18 14:05:44 -0800788 }
789
Charles Chan7ffd81f2017-02-08 15:52:08 -0800790 private FilteringObjective.Builder buildFilteringObjective(DeviceId deviceId, PortNumber portnum,
791 boolean pushVlan, VlanId vlanId) {
Saurav Das018605f2017-02-18 14:05:44 -0800792 MacAddress deviceMac;
793 try {
794 deviceMac = config.getDeviceMac(deviceId);
795 } catch (DeviceConfigNotFoundException e) {
796 log.warn(e.getMessage() + " Processing SinglePortFilters aborted");
797 return null;
798 }
Saurav Das018605f2017-02-18 14:05:44 -0800799 FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
800 fob.withKey(Criteria.matchInPort(portnum))
801 .addCondition(Criteria.matchEthDst(deviceMac))
Saurav Das018605f2017-02-18 14:05:44 -0800802 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
Charles Chan7ffd81f2017-02-08 15:52:08 -0800803
804 if (pushVlan) {
805 fob.addCondition(Criteria.matchVlanId(VlanId.NONE));
806 TrafficTreatment tt = DefaultTrafficTreatment.builder()
807 .pushVlan().setVlanId(vlanId).build();
808 fob.withMeta(tt);
809 } else {
810 fob.addCondition(Criteria.matchVlanId(vlanId));
811 }
812
Saurav Das018605f2017-02-18 14:05:44 -0800813 fob.permit().fromApp(srManager.appId);
814 return fob;
sanghob35a6192015-04-01 13:05:26 -0700815 }
816
817 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700818 * Creates a forwarding objective to punt all IP packets, destined to the
Saurav Das837e0bb2015-10-30 17:45:38 -0700819 * router's port IP addresses, to the controller. Note that the input
Saurav Das822c4e22015-10-23 10:51:11 -0700820 * port should not be matched on, as these packets can come from any input.
Saurav Das837e0bb2015-10-30 17:45:38 -0700821 * Furthermore, these are applied only by the master instance.
sanghob35a6192015-04-01 13:05:26 -0700822 *
Saurav Das822c4e22015-10-23 10:51:11 -0700823 * @param deviceId the switch dpid for the router
sanghob35a6192015-04-01 13:05:26 -0700824 */
Charles Chan65238242017-06-22 18:03:14 -0700825 void populateIpPunts(DeviceId deviceId) {
Saurav Das7bcbe702017-06-13 15:35:54 -0700826 Ip4Address routerIpv4, pairRouterIpv4 = null;
827 Ip6Address routerIpv6, pairRouterIpv6 = null;
Charles Chan0b4e6182015-11-03 10:42:14 -0800828 try {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800829 routerIpv4 = config.getRouterIpv4(deviceId);
830 routerIpv6 = config.getRouterIpv6(deviceId);
Saurav Das7bcbe702017-06-13 15:35:54 -0700831 if (config.isPairedEdge(deviceId)) {
832 pairRouterIpv4 = config.getRouterIpv4(config.getPairDeviceId(deviceId));
833 pairRouterIpv6 = config.getRouterIpv6(config.getPairDeviceId(deviceId));
834 }
Charles Chan0b4e6182015-11-03 10:42:14 -0800835 } catch (DeviceConfigNotFoundException e) {
Charles Chanf6ec1532017-02-08 16:10:40 -0800836 log.warn(e.getMessage() + " Aborting populateIpPunts.");
Charles Chan0b4e6182015-11-03 10:42:14 -0800837 return;
838 }
839
Saurav Das837e0bb2015-10-30 17:45:38 -0700840 if (!srManager.mastershipService.isLocalMaster(deviceId)) {
841 log.debug("Not installing port-IP punts - not the master for dev:{} ",
842 deviceId);
843 return;
844 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800845 Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId));
846 allIps.add(routerIpv4);
847 if (routerIpv6 != null) {
848 allIps.add(routerIpv6);
849 }
Saurav Das7bcbe702017-06-13 15:35:54 -0700850 if (pairRouterIpv4 != null) {
851 allIps.add(pairRouterIpv4);
852 }
853 if (pairRouterIpv6 != null) {
854 allIps.add(pairRouterIpv6);
855 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800856 for (IpAddress ipaddr : allIps) {
857 TrafficSelector.Builder sbuilder = buildIpSelectorFromIpAddress(ipaddr);
Charles Chan2df0e8a2017-01-09 11:45:08 -0800858 Optional<DeviceId> optDeviceId = Optional.of(deviceId);
859
860 srManager.packetService.requestPackets(sbuilder.build(),
861 PacketPriority.CONTROL, srManager.appId, optDeviceId);
Saurav Das822c4e22015-10-23 10:51:11 -0700862 }
sanghob35a6192015-04-01 13:05:26 -0700863 }
864
Charles Chan68aa62d2015-11-09 16:37:23 -0800865 /**
Pier Ventree0ae7a32016-11-23 09:57:42 -0800866 * Method to build IPv4 or IPv6 selector.
867 *
868 * @param addressToMatch the address to match
869 */
870 private TrafficSelector.Builder buildIpSelectorFromIpAddress(IpAddress addressToMatch) {
871 return buildIpSelectorFromIpPrefix(addressToMatch.toIpPrefix());
872 }
873
874 /**
875 * Method to build IPv4 or IPv6 selector.
876 *
877 * @param prefixToMatch the prefix to match
878 */
879 private TrafficSelector.Builder buildIpSelectorFromIpPrefix(IpPrefix prefixToMatch) {
880 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
Pier Ventre917127a2016-10-31 16:49:19 -0700881 // If the prefix is IPv4
Pier Ventree0ae7a32016-11-23 09:57:42 -0800882 if (prefixToMatch.isIp4()) {
883 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4);
884 selectorBuilder.matchIPDst(prefixToMatch.getIp4Prefix());
885 return selectorBuilder;
886 }
Pier Ventre917127a2016-10-31 16:49:19 -0700887 // If the prefix is IPv6
Pier Ventree0ae7a32016-11-23 09:57:42 -0800888 selectorBuilder.matchEthType(Ethernet.TYPE_IPV6);
889 selectorBuilder.matchIPv6Dst(prefixToMatch.getIp6Prefix());
890 return selectorBuilder;
891 }
892
893 /**
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800894 * Creates forwarding objectives to punt ARP and NDP packets, to the controller.
895 * Furthermore, these are applied only by the master instance. Deferred actions
896 * are not cleared such that packets can be flooded in the cross connect use case
897 *
898 * @param deviceId the switch dpid for the router
899 */
Charles Chan65238242017-06-22 18:03:14 -0700900 void populateArpNdpPunts(DeviceId deviceId) {
Pier Ventre917127a2016-10-31 16:49:19 -0700901 // We are not the master just skip.
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800902 if (!srManager.mastershipService.isLocalMaster(deviceId)) {
903 log.debug("Not installing ARP/NDP punts - not the master for dev:{} ",
904 deviceId);
905 return;
906 }
907
Charles Chan65238242017-06-22 18:03:14 -0700908 ForwardingObjective fwdObj;
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800909 // We punt all ARP packets towards the controller.
Charles Chan65238242017-06-22 18:03:14 -0700910 fwdObj = arpFwdObjective(null, true, PacketPriority.CONTROL.priorityValue())
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800911 .add(new ObjectiveContext() {
912 @Override
913 public void onError(Objective objective, ObjectiveError error) {
Charles Chan65238242017-06-22 18:03:14 -0700914 log.warn("Failed to install forwarding objective to punt ARP to {}: {}",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800915 deviceId, error);
916 }
917 });
Charles Chan65238242017-06-22 18:03:14 -0700918 srManager.flowObjectiveService.forward(deviceId, fwdObj);
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800919
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800920 // We punt all NDP packets towards the controller.
Charles Chan65238242017-06-22 18:03:14 -0700921 fwdObj = ndpFwdObjective(null, true, PacketPriority.CONTROL.priorityValue())
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800922 .add(new ObjectiveContext() {
923 @Override
924 public void onError(Objective objective, ObjectiveError error) {
Charles Chan65238242017-06-22 18:03:14 -0700925 log.warn("Failed to install forwarding objective to punt NDP to {}: {}",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800926 deviceId, error);
927 }
928 });
Charles Chan65238242017-06-22 18:03:14 -0700929 srManager.flowObjectiveService.forward(deviceId, fwdObj);
930
931 srManager.getPairLocalPorts(deviceId).ifPresent(port -> {
932 ForwardingObjective pairFwdObj;
933 // Do not punt ARP packets from pair port
934 pairFwdObj = arpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1)
935 .add(new ObjectiveContext() {
936 @Override
937 public void onError(Objective objective, ObjectiveError error) {
938 log.warn("Failed to install forwarding objective to ignore ARP to {}: {}",
939 deviceId, error);
940 }
941 });
942 srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
943
944 // Do not punt NDP packets from pair port
945 pairFwdObj = ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1)
946 .add(new ObjectiveContext() {
947 @Override
948 public void onError(Objective objective, ObjectiveError error) {
949 log.warn("Failed to install forwarding objective to ignore ARP to {}: {}",
950 deviceId, error);
951 }
952 });
953 srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
954
955 // Do not forward DAD packets from pair port
956 pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2)
957 .add(new ObjectiveContext() {
958 @Override
959 public void onError(Objective objective, ObjectiveError error) {
960 log.warn("Failed to install forwarding objective to drop DAD to {}: {}",
961 deviceId, error);
962 }
963 });
964 srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
965 });
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800966 }
967
Charles Chan65238242017-06-22 18:03:14 -0700968 private ForwardingObjective.Builder fwdObjBuilder(TrafficSelector selector,
969 TrafficTreatment treatment, int priority) {
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800970 return DefaultForwardingObjective.builder()
Charles Chan65238242017-06-22 18:03:14 -0700971 .withPriority(priority)
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800972 .withSelector(selector)
973 .fromApp(srManager.appId)
974 .withFlag(ForwardingObjective.Flag.VERSATILE)
Charles Chan65238242017-06-22 18:03:14 -0700975 .withTreatment(treatment)
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800976 .makePermanent();
977 }
978
Charles Chan65238242017-06-22 18:03:14 -0700979 private ForwardingObjective.Builder arpFwdObjective(PortNumber port, boolean punt, int priority) {
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800980 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
981 sBuilder.matchEthType(TYPE_ARP);
Charles Chan65238242017-06-22 18:03:14 -0700982 if (port != null) {
983 sBuilder.matchInPort(port);
984 }
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800985
Charles Chan65238242017-06-22 18:03:14 -0700986 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
987 if (punt) {
988 tBuilder.punt();
989 }
990 return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority);
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800991 }
992
Charles Chan65238242017-06-22 18:03:14 -0700993 private ForwardingObjective.Builder ndpFwdObjective(PortNumber port, boolean punt, int priority) {
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800994 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
995 sBuilder.matchEthType(TYPE_IPV6)
996 .matchIPProtocol(PROTOCOL_ICMP6)
Charles Chan65238242017-06-22 18:03:14 -0700997 .matchIcmpv6Type(NEIGHBOR_SOLICITATION);
998 if (port != null) {
999 sBuilder.matchInPort(port);
1000 }
Pier Luigi9e5c5ca2017-01-12 18:14:58 -08001001
Charles Chan65238242017-06-22 18:03:14 -07001002 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
1003 if (punt) {
1004 tBuilder.punt();
1005 }
1006 return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority);
1007 }
1008
1009 private ForwardingObjective.Builder dad6FwdObjective(PortNumber port, int priority) {
1010 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
1011 sBuilder.matchEthType(TYPE_IPV6)
Charles Chanc7e36aa2017-08-07 12:39:03 -07001012 .matchIPv6Src(Ip6Address.ZERO.toIpPrefix());
1013 // TODO CORD-1672 Fix this when OFDPA can distinguish ::/0 and ::/128 correctly
1014 // .matchIPProtocol(PROTOCOL_ICMP6)
1015 // .matchIcmpv6Type(NEIGHBOR_SOLICITATION);
Charles Chan65238242017-06-22 18:03:14 -07001016 if (port != null) {
1017 sBuilder.matchInPort(port);
1018 }
1019
1020 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
1021 tBuilder.wipeDeferred();
1022 return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority);
Pier Luigi9e5c5ca2017-01-12 18:14:58 -08001023 }
1024
1025 /**
Charles Chan68aa62d2015-11-09 16:37:23 -08001026 * Populates a forwarding objective to send packets that miss other high
1027 * priority Bridging Table entries to a group that contains all ports of
1028 * its subnet.
1029 *
Charles Chan68aa62d2015-11-09 16:37:23 -08001030 * @param deviceId switch ID to set the rules
1031 */
Charles Chan65238242017-06-22 18:03:14 -07001032 void populateSubnetBroadcastRule(DeviceId deviceId) {
Charles Chan7ffd81f2017-02-08 15:52:08 -08001033 srManager.getVlanPortMap(deviceId).asMap().forEach((vlanId, ports) -> {
Charles Chan59cc16d2017-02-02 16:20:42 -08001034 int nextId = srManager.getVlanNextObjectiveId(deviceId, vlanId);
1035
1036 if (nextId < 0) {
1037 log.error("Cannot install vlan {} broadcast rule in dev:{} due"
1038 + "to vlanId:{} or nextId:{}", vlanId, deviceId, vlanId, nextId);
Saurav Das4ce45962015-11-24 23:21:05 -08001039 return;
1040 }
1041
Pier Ventre917127a2016-10-31 16:49:19 -07001042 // Driver should treat objective with MacAddress.NONE as the
1043 // subnet broadcast rule
Charles Chan68aa62d2015-11-09 16:37:23 -08001044 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
1045 sbuilder.matchVlanId(vlanId);
1046 sbuilder.matchEthDst(MacAddress.NONE);
1047
1048 ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
1049 fob.withFlag(Flag.SPECIFIC)
1050 .withSelector(sbuilder.build())
1051 .nextStep(nextId)
Charles Chan5270ed02016-01-30 23:22:37 -08001052 .withPriority(SegmentRoutingService.FLOOD_PRIORITY)
Charles Chan68aa62d2015-11-09 16:37:23 -08001053 .fromApp(srManager.appId)
1054 .makePermanent();
Charles Chand2990362016-04-18 13:44:03 -07001055 ObjectiveContext context = new DefaultObjectiveContext(
Charles Chan59cc16d2017-02-02 16:20:42 -08001056 (objective) -> log.debug("Vlan broadcast rule for {} populated", vlanId),
Charles Chand2990362016-04-18 13:44:03 -07001057 (objective, error) ->
Charles Chan59cc16d2017-02-02 16:20:42 -08001058 log.warn("Failed to populate vlan broadcast rule for {}: {}", vlanId, error));
Charles Chand2990362016-04-18 13:44:03 -07001059 srManager.flowObjectiveService.forward(deviceId, fob.add(context));
Charles Chan68aa62d2015-11-09 16:37:23 -08001060 });
1061 }
1062
Charles Chan5270ed02016-01-30 23:22:37 -08001063 private int getPriorityFromPrefix(IpPrefix prefix) {
1064 return (prefix.isIp4()) ?
1065 2000 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY :
1066 500 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY;
Srikanth Vavilapallif3a8bc02015-05-22 13:47:31 -07001067 }
sanghob35a6192015-04-01 13:05:26 -07001068}