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