sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.segmentrouting; |
| 17 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 19 | import org.onlab.packet.EthType; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 20 | import org.onlab.packet.Ethernet; |
| 21 | import org.onlab.packet.Ip4Address; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ip6Address; |
| 23 | import org.onlab.packet.IpAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 24 | import org.onlab.packet.IpPrefix; |
| 25 | import org.onlab.packet.MacAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 26 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 28 | import org.onosproject.incubator.net.intf.Interface; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 30 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flowobjective.Objective; |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 32 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flowobjective.ObjectiveError; |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 34 | import org.onosproject.net.packet.PacketPriority; |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 35 | import org.onosproject.segmentrouting.DefaultRoutingHandler.PortFilterInfo; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 36 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 37 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 38 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 39 | import org.onosproject.net.DeviceId; |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 40 | import org.onosproject.net.Port; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 41 | import org.onosproject.net.PortNumber; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 42 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flow.TrafficSelector; |
| 45 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 46 | import org.onosproject.net.flow.criteria.Criteria; |
| 47 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 48 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 49 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 50 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 51 | import org.onosproject.net.flowobjective.ForwardingObjective.Builder; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 52 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 53 | import org.slf4j.Logger; |
| 54 | import org.slf4j.LoggerFactory; |
| 55 | |
| 56 | import java.util.ArrayList; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 57 | import java.util.Collection; |
| 58 | import java.util.Collections; |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 59 | import java.util.HashSet; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 60 | import java.util.List; |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 61 | import java.util.Optional; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 62 | import java.util.Set; |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 63 | import java.util.concurrent.atomic.AtomicLong; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 64 | import java.util.stream.Collectors; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 65 | |
| 66 | import static com.google.common.base.Preconditions.checkNotNull; |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 67 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
| 68 | import static org.onlab.packet.Ethernet.TYPE_IPV6; |
| 69 | import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION; |
| 70 | import static org.onlab.packet.IPv6.PROTOCOL_ICMP6; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 71 | import static org.onosproject.segmentrouting.SegmentRoutingManager.INTERNAL_VLAN; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 72 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 73 | /** |
| 74 | * Populator of segment routing flow rules. |
| 75 | */ |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 76 | public class RoutingRulePopulator { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 77 | private static final Logger log = LoggerFactory |
| 78 | .getLogger(RoutingRulePopulator.class); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 79 | |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 80 | private AtomicLong rulePopulationCounter; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 81 | private SegmentRoutingManager srManager; |
| 82 | private DeviceConfiguration config; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 83 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Creates a RoutingRulePopulator object. |
| 86 | * |
Thomas Vachuska | e10f56b | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 87 | * @param srManager segment routing manager reference |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 88 | */ |
| 89 | public RoutingRulePopulator(SegmentRoutingManager srManager) { |
| 90 | this.srManager = srManager; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 91 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 92 | this.rulePopulationCounter = new AtomicLong(0); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Resets the population counter. |
| 97 | */ |
| 98 | public void resetCounter() { |
| 99 | rulePopulationCounter.set(0); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns the number of rules populated. |
Thomas Vachuska | 266b443 | 2015-04-30 18:13:25 -0700 | [diff] [blame] | 104 | * |
| 105 | * @return number of rules |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 106 | */ |
| 107 | public long getCounter() { |
| 108 | return rulePopulationCounter.get(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 112 | * Populates IP rules for a route that has direct connection to the |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 113 | * switch. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 114 | * |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 115 | * @param deviceId device ID of the device that next hop attaches to |
| 116 | * @param prefix IP prefix of the route |
| 117 | * @param hostMac MAC address of the next hop |
| 118 | * @param outPort port where the next hop attaches to |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 119 | */ |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 120 | public void populateRoute(DeviceId deviceId, IpPrefix prefix, |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 121 | MacAddress hostMac, PortNumber outPort) { |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 122 | log.debug("Populate IP table entry for route {} at {}:{}", |
| 123 | prefix, deviceId, outPort); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 124 | ForwardingObjective.Builder fwdBuilder; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 125 | try { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 126 | fwdBuilder = getForwardingObjectiveBuilder( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 127 | deviceId, prefix, hostMac, outPort); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 128 | } catch (DeviceConfigNotFoundException e) { |
| 129 | log.warn(e.getMessage() + " Aborting populateIpRuleForHost."); |
| 130 | return; |
| 131 | } |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 132 | if (fwdBuilder == null) { |
| 133 | log.warn("Aborting host routing table entries due " |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 134 | + "to error for dev:{} route:{}", deviceId, prefix); |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 137 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 138 | (objective) -> log.debug("IP rule for route {} populated", prefix), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 139 | (objective, error) -> |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 140 | log.warn("Failed to populate IP rule for route {}: {}", prefix, error)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 141 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context)); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 142 | rulePopulationCounter.incrementAndGet(); |
| 143 | } |
| 144 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 145 | /** |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 146 | * Removes IP rules for a route when the next hop is gone. |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 147 | * |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 148 | * @param deviceId device ID of the device that next hop attaches to |
| 149 | * @param prefix IP prefix of the route |
| 150 | * @param hostMac MAC address of the next hop |
| 151 | * @param outPort port that next hop attaches to |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 152 | */ |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 153 | public void revokeRoute(DeviceId deviceId, IpPrefix prefix, |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 154 | MacAddress hostMac, PortNumber outPort) { |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 155 | log.debug("Revoke IP table entry for route {} at {}:{}", |
| 156 | prefix, deviceId, outPort); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 157 | ForwardingObjective.Builder fwdBuilder; |
| 158 | try { |
| 159 | fwdBuilder = getForwardingObjectiveBuilder( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 160 | deviceId, prefix, hostMac, outPort); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 161 | } catch (DeviceConfigNotFoundException e) { |
| 162 | log.warn(e.getMessage() + " Aborting revokeIpRuleForHost."); |
| 163 | return; |
| 164 | } |
Charles Chan | 458b826 | 2016-11-30 11:55:05 -0800 | [diff] [blame] | 165 | if (fwdBuilder == null) { |
| 166 | log.warn("Aborting host routing table entries due " |
| 167 | + "to error for dev:{} route:{}", deviceId, prefix); |
| 168 | return; |
| 169 | } |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 170 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 171 | (objective) -> log.debug("IP rule for route {} revoked", prefix), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 172 | (objective, error) -> |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 173 | log.warn("Failed to revoke IP rule for route {}: {}", prefix, error)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 174 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context)); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 177 | /** |
| 178 | * Returns a forwarding objective that points packets destined to a |
| 179 | * given prefix to given port on given device with given destination MAC. |
| 180 | * |
| 181 | * @param deviceId device ID |
| 182 | * @param prefix prefix that need to be routed |
| 183 | * @param hostMac MAC address of the nexthop |
| 184 | * @param outPort port where the nexthop attaches to |
| 185 | * @return forwarding objective builder |
| 186 | * @throws DeviceConfigNotFoundException if given device is not configured |
| 187 | */ |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 188 | private ForwardingObjective.Builder getForwardingObjectiveBuilder( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 189 | DeviceId deviceId, IpPrefix prefix, |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 190 | MacAddress hostMac, PortNumber outPort) |
| 191 | throws DeviceConfigNotFoundException { |
| 192 | MacAddress deviceMac; |
| 193 | deviceMac = config.getDeviceMac(deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 194 | |
Pier Ventre | 968da12 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 195 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 196 | TrafficSelector selector = sbuilder.build(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 197 | |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 198 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 199 | tbuilder.deferred() |
| 200 | .setEthDst(hostMac) |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 201 | .setEthSrc(deviceMac) |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 202 | .setOutput(outPort); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 203 | TrafficTreatment treatment = tbuilder.build(); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 204 | |
| 205 | // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed. |
| 206 | // for switch pipelines that need it, provide outgoing vlan as metadata |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 207 | VlanId untaggedVlan = srManager.getUntaggedVlanId(new ConnectPoint(deviceId, outPort)); |
| 208 | VlanId outvlan = (untaggedVlan != null) ? untaggedVlan : INTERNAL_VLAN; |
| 209 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 210 | TrafficSelector meta = DefaultTrafficSelector.builder() |
| 211 | .matchVlanId(outvlan).build(); |
| 212 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outPort, |
| 213 | treatment, meta); |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 214 | if (portNextObjId == -1) { |
| 215 | // warning log will come from getPortNextObjective method |
| 216 | return null; |
| 217 | } |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 218 | return DefaultForwardingObjective.builder() |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 219 | .withSelector(selector) |
| 220 | .nextStep(portNextObjId) |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 221 | .fromApp(srManager.appId).makePermanent() |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 222 | .withPriority(getPriorityFromPrefix(prefix)) |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 223 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Populates IP flow rules for the subnets of the destination router. |
| 228 | * |
| 229 | * @param deviceId switch ID to set the rules |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 230 | * @param subnets subnet being added |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 231 | * @param destSw destination switch ID |
| 232 | * @param nextHops next hop switch ID list |
| 233 | * @return true if all rules are set successfully, false otherwise |
| 234 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 235 | public boolean populateIpRuleForSubnet(DeviceId deviceId, Set<IpPrefix> subnets, |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 236 | DeviceId destSw, Set<DeviceId> nextHops) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 237 | for (IpPrefix subnet : subnets) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 238 | if (!populateIpRuleForRouter(deviceId, subnet, destSw, nextHops)) { |
| 239 | return false; |
| 240 | } |
| 241 | } |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 242 | return true; |
| 243 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 244 | |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 245 | /** |
| 246 | * Revokes IP flow rules for the subnets. |
| 247 | * |
| 248 | * @param subnets subnet being removed |
| 249 | * @return true if all rules are removed successfully, false otherwise |
| 250 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 251 | public boolean revokeIpRuleForSubnet(Set<IpPrefix> subnets) { |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 252 | for (IpPrefix subnet : subnets) { |
| 253 | if (!revokeIpRuleForRouter(subnet)) { |
| 254 | return false; |
| 255 | } |
| 256 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 257 | return true; |
| 258 | } |
| 259 | |
| 260 | /** |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 261 | * Populates IP flow rules for an IP prefix in the target device. The prefix |
| 262 | * is reachable via destination device. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 263 | * |
Saurav Das | a07f203 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 264 | * @param deviceId target device ID to set the rules |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 265 | * @param ipPrefix the destination IP prefix |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 266 | * @param destSw device ID of the destination router |
| 267 | * @param nextHops next hop switch ID list |
| 268 | * @return true if all rules are set successfully, false otherwise |
| 269 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 270 | public boolean populateIpRuleForRouter(DeviceId deviceId, |
| 271 | IpPrefix ipPrefix, DeviceId destSw, |
| 272 | Set<DeviceId> nextHops) { |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 273 | int segmentId; |
| 274 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 275 | if (ipPrefix.isIp4()) { |
| 276 | segmentId = config.getIPv4SegmentId(destSw); |
| 277 | } else { |
| 278 | segmentId = config.getIPv6SegmentId(destSw); |
| 279 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 280 | } catch (DeviceConfigNotFoundException e) { |
| 281 | log.warn(e.getMessage() + " Aborting populateIpRuleForRouter."); |
| 282 | return false; |
| 283 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 284 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 285 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 286 | TrafficSelector selector = sbuilder.build(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 287 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 288 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 289 | NeighborSet ns; |
| 290 | TrafficTreatment treatment; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 291 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 292 | // If the next hop is the same as the final destination, then MPLS label |
| 293 | // is not set. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 294 | if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 295 | tbuilder.immediate().decNwTtl(); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 296 | ns = new NeighborSet(nextHops, false); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 297 | treatment = tbuilder.build(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 298 | } else { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 299 | ns = new NeighborSet(nextHops, false, segmentId); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 300 | treatment = null; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 303 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 304 | // if needed by the switch pipeline. Since neighbor sets are always to |
| 305 | // other neighboring routers, there is no subnet assigned on those ports. |
| 306 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 307 | metabuilder.matchVlanId(SegmentRoutingManager.INTERNAL_VLAN); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 308 | |
| 309 | int nextId = srManager.getNextObjectiveId(deviceId, ns, metabuilder.build()); |
| 310 | if (nextId <= 0) { |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 311 | log.warn("No next objective in {} for ns: {}", deviceId, ns); |
| 312 | return false; |
| 313 | } |
| 314 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 315 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 316 | .builder() |
| 317 | .fromApp(srManager.appId) |
| 318 | .makePermanent() |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 319 | .nextStep(nextId) |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 320 | .withSelector(selector) |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 321 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 322 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 323 | if (treatment != null) { |
| 324 | fwdBuilder.withTreatment(treatment); |
| 325 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 326 | log.debug("Installing IPv4 forwarding objective " |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 327 | + "for router IP/subnet {} in switch {}", |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 328 | ipPrefix, |
| 329 | deviceId); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 330 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 331 | (objective) -> log.debug("IP rule for router {} populated in dev:{}", |
| 332 | ipPrefix, deviceId), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 333 | (objective, error) -> |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 334 | log.warn("Failed to populate IP rule for router {}: {} in dev:{}", |
| 335 | ipPrefix, error, deviceId)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 336 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context)); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 337 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 338 | |
| 339 | return true; |
| 340 | } |
| 341 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 342 | /** |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 343 | * Revokes IP flow rules for the router IP address. |
| 344 | * |
| 345 | * @param ipPrefix the IP address of the destination router |
| 346 | * @return true if all rules are removed successfully, false otherwise |
| 347 | */ |
| 348 | public boolean revokeIpRuleForRouter(IpPrefix ipPrefix) { |
Pier Ventre | 968da12 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 349 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix); |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 350 | TrafficSelector selector = sbuilder.build(); |
| 351 | TrafficTreatment dummyTreatment = DefaultTrafficTreatment.builder().build(); |
| 352 | |
| 353 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 354 | .builder() |
| 355 | .fromApp(srManager.appId) |
| 356 | .makePermanent() |
| 357 | .withSelector(selector) |
| 358 | .withTreatment(dummyTreatment) |
| 359 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
| 360 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 361 | |
| 362 | ObjectiveContext context = new DefaultObjectiveContext( |
| 363 | (objective) -> log.debug("IP rule for router {} revoked", ipPrefix), |
| 364 | (objective, error) -> |
| 365 | log.warn("Failed to revoke IP rule for router {}: {}", ipPrefix, error)); |
| 366 | |
| 367 | srManager.deviceService.getAvailableDevices().forEach(device -> { |
| 368 | srManager.flowObjectiveService.forward(device.id(), fwdBuilder.remove(context)); |
| 369 | }); |
| 370 | |
| 371 | return true; |
| 372 | } |
| 373 | |
| 374 | /** |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 375 | * Deals with !MPLS Bos use case. |
| 376 | * |
| 377 | * @param targetSwId the target sw |
| 378 | * @param destSwId the destination sw |
| 379 | * @param nextHops the set of next hops |
| 380 | * @param segmentId the segmentId to match |
| 381 | * @param routerIp the router ip |
| 382 | * @return a collection of fwdobjective |
| 383 | */ |
| 384 | private Collection<ForwardingObjective> handleMpls(DeviceId targetSwId, |
| 385 | DeviceId destSwId, |
| 386 | Set<DeviceId> nextHops, |
| 387 | int segmentId, |
| 388 | IpAddress routerIp, |
| 389 | boolean isMplsBos) { |
| 390 | |
| 391 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 392 | List<ForwardingObjective.Builder> fwdObjBuilders = Lists.newArrayList(); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 393 | // For the transport of Pwaas we can use two or three MPLS label |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 394 | sbuilder.matchEthType(Ethernet.MPLS_UNICAST); |
| 395 | sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId)); |
| 396 | sbuilder.matchMplsBos(isMplsBos); |
| 397 | TrafficSelector selector = sbuilder.build(); |
| 398 | |
| 399 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 400 | // if needed by the switch pipeline. Since mpls next-hops are always to |
| 401 | // other neighboring routers, there is no subnet assigned on those ports. |
| 402 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 403 | metabuilder.matchVlanId(SegmentRoutingManager.INTERNAL_VLAN); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 404 | |
| 405 | if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { |
| 406 | // If the next hop is the destination router for the segment, do pop |
| 407 | log.debug("populateMplsRule: Installing MPLS forwarding objective for " |
| 408 | + "label {} in switch {} with pop", segmentId, targetSwId); |
| 409 | // Not-bos pop case (php for the current label). If MPLS-ECMP |
| 410 | // has been configured, the application we will request the |
| 411 | // installation for an MPLS-ECMP group. |
| 412 | ForwardingObjective.Builder fwdObjNoBosBuilder = getMplsForwardingObjective(targetSwId, |
| 413 | nextHops, |
| 414 | true, |
| 415 | isMplsBos, |
| 416 | metabuilder.build(), |
| 417 | routerIp); |
| 418 | // Error case, we cannot handle, exit. |
| 419 | if (fwdObjNoBosBuilder == null) { |
| 420 | return Collections.emptyList(); |
| 421 | } |
| 422 | fwdObjBuilders.add(fwdObjNoBosBuilder); |
| 423 | |
| 424 | } else { |
| 425 | // next hop is not destination, SR CONTINUE case (swap with self) |
| 426 | log.debug("Installing MPLS forwarding objective for " |
| 427 | + "label {} in switch {} without pop", segmentId, targetSwId); |
| 428 | // Not-bos pop case. If MPLS-ECMP has been configured, the |
| 429 | // application we will request the installation for an MPLS-ECMP |
| 430 | // group. |
| 431 | ForwardingObjective.Builder fwdObjNoBosBuilder = getMplsForwardingObjective(targetSwId, |
| 432 | nextHops, |
| 433 | false, |
| 434 | isMplsBos, |
| 435 | metabuilder.build(), |
| 436 | routerIp); |
| 437 | // Error case, we cannot handle, exit. |
| 438 | if (fwdObjNoBosBuilder == null) { |
| 439 | return Collections.emptyList(); |
| 440 | } |
| 441 | fwdObjBuilders.add(fwdObjNoBosBuilder); |
| 442 | |
| 443 | } |
| 444 | |
| 445 | List<ForwardingObjective> fwdObjs = Lists.newArrayList(); |
| 446 | // We add the final property to the fwdObjs. |
| 447 | for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) { |
| 448 | |
| 449 | ((Builder) ((Builder) fwdObjBuilder |
| 450 | .fromApp(srManager.appId) |
| 451 | .makePermanent()) |
| 452 | .withSelector(selector) |
| 453 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)) |
| 454 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 455 | |
| 456 | ObjectiveContext context = new DefaultObjectiveContext( |
| 457 | (objective) -> |
| 458 | log.debug("MPLS rule {} for SID {} populated in dev:{} ", |
| 459 | objective.id(), segmentId, targetSwId), |
| 460 | (objective, error) -> |
| 461 | log.warn("Failed to populate MPLS rule {} for SID {}: {} in dev:{}", |
| 462 | objective.id(), segmentId, error, targetSwId)); |
| 463 | |
| 464 | ForwardingObjective fob = fwdObjBuilder.add(context); |
| 465 | fwdObjs.add(fob); |
| 466 | |
| 467 | } |
| 468 | |
| 469 | return fwdObjs; |
| 470 | } |
| 471 | |
| 472 | /** |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 473 | * Populates MPLS flow rules in the target device to point towards the |
| 474 | * destination device. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 475 | * |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 476 | * @param targetSwId target device ID of the switch to set the rules |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 477 | * @param destSwId destination switch device ID |
| 478 | * @param nextHops next hops switch ID list |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 479 | * @param routerIp the router ip |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 480 | * @return true if all rules are set successfully, false otherwise |
| 481 | */ |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 482 | public boolean populateMplsRule(DeviceId targetSwId, DeviceId destSwId, |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 483 | Set<DeviceId> nextHops, IpAddress routerIp) { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 484 | |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 485 | int segmentId; |
| 486 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 487 | if (routerIp.isIp4()) { |
| 488 | segmentId = config.getIPv4SegmentId(destSwId); |
| 489 | } else { |
| 490 | segmentId = config.getIPv6SegmentId(destSwId); |
| 491 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 492 | } catch (DeviceConfigNotFoundException e) { |
| 493 | log.warn(e.getMessage() + " Aborting populateMplsRule."); |
| 494 | return false; |
| 495 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 496 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 497 | List<ForwardingObjective> fwdObjs = new ArrayList<>(); |
| 498 | Collection<ForwardingObjective> fwdObjsMpls = Collections.emptyList(); |
| 499 | // Generates the transit rules used by the standard "routing". |
| 500 | fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, routerIp, true); |
| 501 | if (fwdObjsMpls.isEmpty()) { |
| 502 | return false; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 503 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 504 | fwdObjs.addAll(fwdObjsMpls); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 505 | // Generates the transit rules used by the MPLS Pwaas. For now it is |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 506 | // the only case !BoS supported. |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 507 | /*fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, routerIp, false); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 508 | if (fwdObjsMpls.isEmpty()) { |
| 509 | return false; |
| 510 | } |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 511 | fwdObjs.addAll(fwdObjsMpls);*/ |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 512 | |
| 513 | for (ForwardingObjective fwdObj : fwdObjs) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 514 | log.debug("Sending MPLS fwd obj {} for SID {}-> next {} in sw: {}", |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 515 | fwdObj.id(), segmentId, fwdObj.nextId(), targetSwId); |
| 516 | srManager.flowObjectiveService.forward(targetSwId, fwdObj); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 517 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | return true; |
| 521 | } |
| 522 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 523 | private ForwardingObjective.Builder getMplsForwardingObjective( |
| 524 | DeviceId deviceId, |
| 525 | Set<DeviceId> nextHops, |
| 526 | boolean phpRequired, |
| 527 | boolean isBos, |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 528 | TrafficSelector meta, |
| 529 | IpAddress routerIp) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 530 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 531 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 532 | .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 533 | |
| 534 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 535 | |
| 536 | if (phpRequired) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 537 | // php case - pop should always be flow-action |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 538 | log.debug("getMplsForwardingObjective: php required"); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 539 | tbuilder.deferred().copyTtlIn(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 540 | if (isBos) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 541 | if (routerIp.isIp4()) { |
| 542 | tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType()); |
| 543 | } else { |
| 544 | tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType()); |
| 545 | } |
| 546 | tbuilder.decNwTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 547 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 548 | tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType()) |
| 549 | .decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 550 | } |
| 551 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 552 | // swap with self case - SR CONTINUE |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 553 | log.debug("getMplsForwardingObjective: php not required"); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 554 | tbuilder.deferred().decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 557 | fwdBuilder.withTreatment(tbuilder.build()); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 558 | // if MPLS-ECMP == True we will build a standard NeighborSet. |
| 559 | // Otherwise a RandomNeighborSet. |
| 560 | NeighborSet ns = NeighborSet.neighborSet(false, nextHops, false); |
| 561 | if (!isBos && this.srManager.getMplsEcmp()) { |
| 562 | ns = NeighborSet.neighborSet(false, nextHops, true); |
| 563 | } else if (!isBos && !this.srManager.getMplsEcmp()) { |
| 564 | ns = NeighborSet.neighborSet(true, nextHops, true); |
| 565 | } |
| 566 | log.info("Trying to get a nextObjId for mpls rule on device:{} to ns:{}", |
| 567 | deviceId, ns); |
| 568 | // If BoS == True, all forwarding is via L3 ECMP group. |
| 569 | // If Bos == False, the forwarding can be via MPLS-ECMP group or through |
| 570 | // MPLS-Interface group. This depends on the configuration of the option |
| 571 | // MPLS-ECMP. |
| 572 | // The metadata informs the driver that the next-Objective will be used |
| 573 | // by MPLS flows and if Bos == False the driver will use MPLS groups. |
| 574 | int nextId = srManager.getNextObjectiveId(deviceId, ns, meta, isBos); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 575 | if (nextId <= 0) { |
| 576 | log.warn("No next objective in {} for ns: {}", deviceId, ns); |
| 577 | return null; |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 578 | } else { |
| 579 | log.debug("nextObjId found:{} for mpls rule on device:{} to ns:{}", |
| 580 | nextId, deviceId, ns); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 583 | fwdBuilder.nextStep(nextId); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 584 | return fwdBuilder; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 588 | * Creates a filtering objective to permit all untagged packets with a |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 589 | * dstMac corresponding to the router's MAC address. For those pipelines |
| 590 | * that need to internally assign vlans to untagged packets, this method |
| 591 | * provides per-subnet vlan-ids as metadata. |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 592 | * <p> |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 593 | * Note that the vlan assignment and filter programming should only be done by |
| 594 | * the master for a switch. This method is typically called at deviceAdd and |
| 595 | * programs filters only for the enabled ports of the device. For port-updates, |
| 596 | * that enable/disable ports after device add, singlePortFilter methods should |
| 597 | * be called. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 598 | * |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 599 | * @param deviceId the switch dpid for the router |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 600 | * @return PortFilterInfo information about the processed ports |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 601 | */ |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 602 | public PortFilterInfo populateRouterMacVlanFilters(DeviceId deviceId) { |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 603 | log.debug("Installing per-port filtering objective for untagged " |
| 604 | + "packets in device {}", deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 605 | |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 606 | List<Port> devPorts = srManager.deviceService.getPorts(deviceId); |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 607 | if (devPorts == null || devPorts.isEmpty()) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 608 | log.warn("Device {} ports not available. Unable to add MacVlan filters", |
| 609 | deviceId); |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 610 | return null; |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 611 | } |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 612 | int disabledPorts = 0, errorPorts = 0, filteredPorts = 0; |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 613 | for (Port port : devPorts) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 614 | if (!port.isEnabled()) { |
| 615 | disabledPorts++; |
| 616 | continue; |
| 617 | } |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 618 | if (populateSinglePortFilters(deviceId, port.number())) { |
| 619 | filteredPorts++; |
| 620 | } else { |
| 621 | errorPorts++; |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 622 | } |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 623 | } |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 624 | log.info("Filtering on dev:{}, disabledPorts:{}, errorPorts:{}, filteredPorts:{}", |
| 625 | deviceId, disabledPorts, errorPorts, filteredPorts); |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 626 | return srManager.defaultRoutingHandler.new PortFilterInfo(disabledPorts, |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 627 | errorPorts, filteredPorts); |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Creates filtering objectives for a single port. Should only be called |
| 632 | * by the master for a switch. |
| 633 | * |
| 634 | * @param deviceId device identifier |
| 635 | * @param portnum port identifier for port to be filtered |
| 636 | * @return true if no errors occurred during the build of the filtering objective |
| 637 | */ |
| 638 | public boolean populateSinglePortFilters(DeviceId deviceId, PortNumber portnum) { |
| 639 | FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum); |
| 640 | if (fob == null) { |
| 641 | // error encountered during build |
| 642 | return false; |
| 643 | } |
| 644 | log.info("Sending filtering objectives for dev/port:{}/{}", deviceId, portnum); |
| 645 | ObjectiveContext context = new DefaultObjectiveContext( |
| 646 | (objective) -> log.debug("Filter for {}/{} populated", deviceId, portnum), |
| 647 | (objective, error) -> |
| 648 | log.warn("Failed to populate filter for {}/{}: {}", |
| 649 | deviceId, portnum, error)); |
| 650 | srManager.flowObjectiveService.filter(deviceId, fob.add(context)); |
| 651 | return true; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Removes filtering objectives for a single port. Should only be called |
| 656 | * by the master for a switch. |
| 657 | * |
| 658 | * @param deviceId device identifier |
| 659 | * @param portnum port identifier |
| 660 | */ |
| 661 | public void revokeSinglePortFilters(DeviceId deviceId, PortNumber portnum) { |
| 662 | FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum); |
| 663 | if (fob == null) { |
| 664 | // error encountered during build |
| 665 | return; |
| 666 | } |
| 667 | log.info("Removing filtering objectives for dev/port:{}/{}", deviceId, portnum); |
| 668 | ObjectiveContext context = new DefaultObjectiveContext( |
| 669 | (objective) -> log.debug("Filter for {}/{} removed", deviceId, portnum), |
| 670 | (objective, error) -> |
| 671 | log.warn("Failed to remove filter for {}/{}: {}", |
| 672 | deviceId, portnum, error)); |
| 673 | srManager.flowObjectiveService.filter(deviceId, fob.remove(context)); |
| 674 | return; |
| 675 | } |
| 676 | |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 677 | private FilteringObjective.Builder buildFilteringObjective(DeviceId deviceId, |
| 678 | PortNumber portnum) { |
| 679 | MacAddress deviceMac; |
| 680 | try { |
| 681 | deviceMac = config.getDeviceMac(deviceId); |
| 682 | } catch (DeviceConfigNotFoundException e) { |
| 683 | log.warn(e.getMessage() + " Processing SinglePortFilters aborted"); |
| 684 | return null; |
| 685 | } |
| 686 | // suppressed ports still have filtering rules pushed by SR using default vlan |
| 687 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portnum); |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 688 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 689 | VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint); |
| 690 | VlanId assignedVlan = (untaggedVlan != null) ? untaggedVlan : INTERNAL_VLAN; |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 691 | |
| 692 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 693 | fob.withKey(Criteria.matchInPort(portnum)) |
| 694 | .addCondition(Criteria.matchEthDst(deviceMac)) |
| 695 | .addCondition(Criteria.matchVlanId(VlanId.NONE)) |
| 696 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY); |
| 697 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
| 698 | .pushVlan().setVlanId(assignedVlan).build(); |
| 699 | fob.withMeta(tt); |
| 700 | fob.permit().fromApp(srManager.appId); |
| 701 | return fob; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 705 | * Creates a forwarding objective to punt all IP packets, destined to the |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 706 | * router's port IP addresses, to the controller. Note that the input |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 707 | * port should not be matched on, as these packets can come from any input. |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 708 | * Furthermore, these are applied only by the master instance. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 709 | * |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 710 | * @param deviceId the switch dpid for the router |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 711 | */ |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 712 | public void populateRouterIpPunts(DeviceId deviceId) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 713 | Ip4Address routerIpv4; |
| 714 | Ip6Address routerIpv6; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 715 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 716 | routerIpv4 = config.getRouterIpv4(deviceId); |
| 717 | routerIpv6 = config.getRouterIpv6(deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 718 | } catch (DeviceConfigNotFoundException e) { |
| 719 | log.warn(e.getMessage() + " Aborting populateRouterIpPunts."); |
| 720 | return; |
| 721 | } |
| 722 | |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 723 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 724 | log.debug("Not installing port-IP punts - not the master for dev:{} ", |
| 725 | deviceId); |
| 726 | return; |
| 727 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 728 | Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId)); |
| 729 | allIps.add(routerIpv4); |
| 730 | if (routerIpv6 != null) { |
| 731 | allIps.add(routerIpv6); |
| 732 | } |
| 733 | for (IpAddress ipaddr : allIps) { |
| 734 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpAddress(ipaddr); |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 735 | Optional<DeviceId> optDeviceId = Optional.of(deviceId); |
| 736 | |
| 737 | srManager.packetService.requestPackets(sbuilder.build(), |
| 738 | PacketPriority.CONTROL, srManager.appId, optDeviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 739 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 742 | /** |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 743 | * Method to build IPv4 or IPv6 selector. |
| 744 | * |
| 745 | * @param addressToMatch the address to match |
| 746 | */ |
| 747 | private TrafficSelector.Builder buildIpSelectorFromIpAddress(IpAddress addressToMatch) { |
| 748 | return buildIpSelectorFromIpPrefix(addressToMatch.toIpPrefix()); |
| 749 | } |
| 750 | |
| 751 | /** |
| 752 | * Method to build IPv4 or IPv6 selector. |
| 753 | * |
| 754 | * @param prefixToMatch the prefix to match |
| 755 | */ |
| 756 | private TrafficSelector.Builder buildIpSelectorFromIpPrefix(IpPrefix prefixToMatch) { |
| 757 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 758 | // If the prefix is IPv4 |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 759 | if (prefixToMatch.isIp4()) { |
| 760 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 761 | selectorBuilder.matchIPDst(prefixToMatch.getIp4Prefix()); |
| 762 | return selectorBuilder; |
| 763 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 764 | // If the prefix is IPv6 |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 765 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 766 | selectorBuilder.matchIPv6Dst(prefixToMatch.getIp6Prefix()); |
| 767 | return selectorBuilder; |
| 768 | } |
| 769 | |
| 770 | /** |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 771 | * Creates forwarding objectives to punt ARP and NDP packets, to the controller. |
| 772 | * Furthermore, these are applied only by the master instance. Deferred actions |
| 773 | * are not cleared such that packets can be flooded in the cross connect use case |
| 774 | * |
| 775 | * @param deviceId the switch dpid for the router |
| 776 | */ |
| 777 | public void populateArpNdpPunts(DeviceId deviceId) { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 778 | // We are not the master just skip. |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 779 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 780 | log.debug("Not installing ARP/NDP punts - not the master for dev:{} ", |
| 781 | deviceId); |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | // We punt all ARP packets towards the controller. |
| 786 | ForwardingObjective puntFwd = puntArpFwdObjective() |
| 787 | .add(new ObjectiveContext() { |
| 788 | @Override |
| 789 | public void onError(Objective objective, ObjectiveError error) { |
| 790 | log.warn("Failed to install packet request for ARP to {}: {}", |
| 791 | deviceId, error); |
| 792 | } |
| 793 | }); |
| 794 | srManager.flowObjectiveService.forward(deviceId, puntFwd); |
| 795 | |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 796 | // We punt all NDP packets towards the controller. |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 797 | puntFwd = puntNdpFwdObjective() |
| 798 | .add(new ObjectiveContext() { |
| 799 | @Override |
| 800 | public void onError(Objective objective, ObjectiveError error) { |
| 801 | log.warn("Failed to install packet request for NDP to {}: {}", |
| 802 | deviceId, error); |
| 803 | } |
| 804 | }); |
| 805 | srManager.flowObjectiveService.forward(deviceId, puntFwd); |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | private ForwardingObjective.Builder fwdObjBuilder(TrafficSelector selector) { |
| 809 | |
| 810 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 811 | tBuilder.punt(); |
| 812 | |
| 813 | return DefaultForwardingObjective.builder() |
| 814 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 815 | .withSelector(selector) |
| 816 | .fromApp(srManager.appId) |
| 817 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 818 | .withTreatment(tBuilder.build()) |
| 819 | .makePermanent(); |
| 820 | } |
| 821 | |
| 822 | private ForwardingObjective.Builder puntArpFwdObjective() { |
| 823 | |
| 824 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 825 | sBuilder.matchEthType(TYPE_ARP); |
| 826 | |
| 827 | return fwdObjBuilder(sBuilder.build()); |
| 828 | } |
| 829 | |
| 830 | private ForwardingObjective.Builder puntNdpFwdObjective() { |
| 831 | |
| 832 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 833 | sBuilder.matchEthType(TYPE_IPV6) |
| 834 | .matchIPProtocol(PROTOCOL_ICMP6) |
| 835 | .matchIcmpv6Type(NEIGHBOR_SOLICITATION) |
| 836 | .build(); |
| 837 | |
| 838 | return fwdObjBuilder(sBuilder.build()); |
| 839 | } |
| 840 | |
| 841 | /** |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 842 | * Populates a forwarding objective to send packets that miss other high |
| 843 | * priority Bridging Table entries to a group that contains all ports of |
| 844 | * its subnet. |
| 845 | * |
| 846 | * Note: We assume that packets sending from the edge switches to the hosts |
| 847 | * have untagged VLAN. |
| 848 | * The VLAN tag will be popped later in the flooding group. |
| 849 | * |
| 850 | * @param deviceId switch ID to set the rules |
| 851 | */ |
| 852 | public void populateSubnetBroadcastRule(DeviceId deviceId) { |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 853 | Set<Interface> interfaces = srManager.interfaceService.getInterfaces(); |
| 854 | Set<VlanId> vlans = |
| 855 | interfaces.stream() |
| 856 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId) && |
| 857 | !intf.vlanUntagged().equals(VlanId.NONE)) |
| 858 | .map(Interface::vlanUntagged) |
| 859 | .collect(Collectors.toSet()); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 860 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 861 | vlans.forEach(vlanId -> { |
| 862 | int nextId = srManager.getVlanNextObjectiveId(deviceId, vlanId); |
| 863 | |
| 864 | if (nextId < 0) { |
| 865 | log.error("Cannot install vlan {} broadcast rule in dev:{} due" |
| 866 | + "to vlanId:{} or nextId:{}", vlanId, deviceId, vlanId, nextId); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 870 | // Driver should treat objective with MacAddress.NONE as the |
| 871 | // subnet broadcast rule |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 872 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 873 | sbuilder.matchVlanId(vlanId); |
| 874 | sbuilder.matchEthDst(MacAddress.NONE); |
| 875 | |
| 876 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 877 | fob.withFlag(Flag.SPECIFIC) |
| 878 | .withSelector(sbuilder.build()) |
| 879 | .nextStep(nextId) |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 880 | .withPriority(SegmentRoutingService.FLOOD_PRIORITY) |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 881 | .fromApp(srManager.appId) |
| 882 | .makePermanent(); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 883 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 884 | (objective) -> log.debug("Vlan broadcast rule for {} populated", vlanId), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 885 | (objective, error) -> |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame^] | 886 | log.warn("Failed to populate vlan broadcast rule for {}: {}", vlanId, error)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 887 | srManager.flowObjectiveService.forward(deviceId, fob.add(context)); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 888 | }); |
| 889 | } |
| 890 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 891 | private int getPriorityFromPrefix(IpPrefix prefix) { |
| 892 | return (prefix.isIp4()) ? |
| 893 | 2000 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY : |
| 894 | 500 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY; |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 895 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 896 | } |