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