sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.segmentrouting; |
| 17 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 19 | import org.onlab.packet.EthType; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 20 | import org.onlab.packet.Ethernet; |
| 21 | import org.onlab.packet.Ip4Address; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ip6Address; |
| 23 | import org.onlab.packet.IpAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 24 | import org.onlab.packet.IpPrefix; |
| 25 | import org.onlab.packet.MacAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 26 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
Charles Chan | 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; |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 37 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 38 | import org.onosproject.segmentrouting.grouphandler.DestinationSet; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 39 | import org.onosproject.net.DeviceId; |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 40 | import org.onosproject.net.Port; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 41 | import org.onosproject.net.PortNumber; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 42 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flow.TrafficSelector; |
| 45 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 46 | import org.onosproject.net.flow.criteria.Criteria; |
| 47 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 48 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 49 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 50 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 51 | import org.onosproject.net.flowobjective.ForwardingObjective.Builder; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 52 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 53 | import org.slf4j.Logger; |
| 54 | import org.slf4j.LoggerFactory; |
| 55 | |
| 56 | import java.util.ArrayList; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 57 | import java.util.Collection; |
| 58 | import java.util.Collections; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 59 | import java.util.HashMap; |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 60 | import java.util.HashSet; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 61 | import java.util.List; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 62 | import java.util.Map; |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 63 | import java.util.Optional; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 64 | import java.util.Set; |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 65 | import java.util.concurrent.atomic.AtomicLong; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 66 | |
| 67 | import static com.google.common.base.Preconditions.checkNotNull; |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 68 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
| 69 | import static org.onlab.packet.Ethernet.TYPE_IPV6; |
| 70 | import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION; |
| 71 | import static org.onlab.packet.IPv6.PROTOCOL_ICMP6; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 72 | import static org.onosproject.segmentrouting.SegmentRoutingManager.INTERNAL_VLAN; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 73 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Populator of segment routing flow rules. |
| 76 | */ |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 77 | public class RoutingRulePopulator { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 78 | private static final Logger log = LoggerFactory |
| 79 | .getLogger(RoutingRulePopulator.class); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 80 | |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 81 | private AtomicLong rulePopulationCounter; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 82 | private SegmentRoutingManager srManager; |
| 83 | private DeviceConfiguration config; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 84 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Creates a RoutingRulePopulator object. |
| 87 | * |
Thomas Vachuska | e10f56b | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 88 | * @param srManager segment routing manager reference |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 89 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 90 | RoutingRulePopulator(SegmentRoutingManager srManager) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 91 | this.srManager = srManager; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 92 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 93 | this.rulePopulationCounter = new AtomicLong(0); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Resets the population counter. |
| 98 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 99 | void resetCounter() { |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 100 | rulePopulationCounter.set(0); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns the number of rules populated. |
Thomas Vachuska | 266b443 | 2015-04-30 18:13:25 -0700 | [diff] [blame] | 105 | * |
| 106 | * @return number of rules |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 107 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 108 | long getCounter() { |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 109 | return rulePopulationCounter.get(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 113 | * Populates IP rules for a route that has direct connection to the |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 114 | * switch. |
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 | * @param deviceId device ID of the device that next hop attaches to |
| 117 | * @param prefix IP prefix of the route |
| 118 | * @param hostMac MAC address of the next hop |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 119 | * @param hostVlanId Vlan ID of the nexthop |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 120 | * @param outPort port where the next hop attaches to |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 121 | */ |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 122 | public void populateRoute(DeviceId deviceId, IpPrefix prefix, |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 123 | MacAddress hostMac, VlanId hostVlanId, PortNumber outPort) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 124 | log.debug("Populate direct routing entry for route {} at {}:{}", |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 125 | prefix, deviceId, outPort); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 126 | ForwardingObjective.Builder fwdBuilder; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 127 | try { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 128 | fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, |
| 129 | hostVlanId, outPort, false); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 130 | } catch (DeviceConfigNotFoundException e) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 131 | log.warn(e.getMessage() + " Aborting direct populateRoute"); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 132 | return; |
| 133 | } |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 134 | if (fwdBuilder == null) { |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 135 | log.warn("Aborting host routing table entry due " |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 136 | + "to error for dev:{} route:{}", deviceId, prefix); |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 137 | return; |
| 138 | } |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 139 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 140 | (objective) -> log.debug("Direct routing rule for route {} populated", |
| 141 | prefix), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 142 | (objective, error) -> |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 143 | log.warn("Failed to populate direct routing rule for route {}: {}", |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 144 | prefix, error)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 145 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context)); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 146 | rulePopulationCounter.incrementAndGet(); |
| 147 | } |
| 148 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 149 | /** |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 150 | * Removes IP rules for a route when the next hop is gone. |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 151 | * |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 152 | * @param deviceId device ID of the device that next hop attaches to |
| 153 | * @param prefix IP prefix of the route |
| 154 | * @param hostMac MAC address of the next hop |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 155 | * @param hostVlanId Vlan ID of the nexthop |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 156 | * @param outPort port that next hop attaches to |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 157 | */ |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 158 | public void revokeRoute(DeviceId deviceId, IpPrefix prefix, |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 159 | MacAddress hostMac, VlanId hostVlanId, PortNumber outPort) { |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 160 | log.debug("Revoke IP table entry for route {} at {}:{}", |
| 161 | prefix, deviceId, outPort); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 162 | ForwardingObjective.Builder fwdBuilder; |
| 163 | try { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 164 | fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, |
| 165 | hostVlanId, outPort, true); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 166 | } catch (DeviceConfigNotFoundException e) { |
| 167 | log.warn(e.getMessage() + " Aborting revokeIpRuleForHost."); |
| 168 | return; |
| 169 | } |
Charles Chan | 458b826 | 2016-11-30 11:55:05 -0800 | [diff] [blame] | 170 | if (fwdBuilder == null) { |
| 171 | log.warn("Aborting host routing table entries due " |
| 172 | + "to error for dev:{} route:{}", deviceId, prefix); |
| 173 | return; |
| 174 | } |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 175 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 176 | (objective) -> log.debug("IP rule for route {} revoked", prefix), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 177 | (objective, error) -> |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 178 | log.warn("Failed to revoke IP rule for route {}: {}", prefix, error)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 179 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context)); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 182 | /** |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 183 | * Returns a forwarding objective builder for routing rules. |
| 184 | * <p> |
| 185 | * The forwarding objective routes packets destined to a given prefix to |
| 186 | * given port on given device with given destination MAC. |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 187 | * |
| 188 | * @param deviceId device ID |
| 189 | * @param prefix prefix that need to be routed |
| 190 | * @param hostMac MAC address of the nexthop |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 191 | * @param hostVlanId Vlan ID of the nexthop |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 192 | * @param outPort port where the nexthop attaches to |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 193 | * @param revoke true if forwarding objective is meant to revoke forwarding rule |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 194 | * @return forwarding objective builder |
| 195 | * @throws DeviceConfigNotFoundException if given device is not configured |
| 196 | */ |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 197 | private ForwardingObjective.Builder routingFwdObjBuilder( |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 198 | DeviceId deviceId, IpPrefix prefix, |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 199 | MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, |
| 200 | boolean revoke) |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 201 | throws DeviceConfigNotFoundException { |
| 202 | MacAddress deviceMac; |
| 203 | deviceMac = config.getDeviceMac(deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 204 | |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 205 | ConnectPoint connectPoint = new ConnectPoint(deviceId, outPort); |
| 206 | VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint); |
| 207 | Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint); |
| 208 | VlanId nativeVlan = srManager.getNativeVlanId(connectPoint); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 209 | |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 210 | // Create route selector |
| 211 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix); |
| 212 | |
| 213 | // Create route treatment |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 214 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 215 | tbuilder.deferred() |
| 216 | .setEthDst(hostMac) |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 217 | .setEthSrc(deviceMac) |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 218 | .setOutput(outPort); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 219 | |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 220 | // Create route meta |
| 221 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 222 | |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 223 | // Adjust the meta according to VLAN configuration |
| 224 | if (taggedVlans.contains(hostVlanId)) { |
| 225 | tbuilder.setVlanId(hostVlanId); |
| 226 | } else if (hostVlanId.equals(VlanId.NONE)) { |
| 227 | if (untaggedVlan != null) { |
| 228 | mbuilder.matchVlanId(untaggedVlan); |
| 229 | } else if (nativeVlan != null) { |
| 230 | mbuilder.matchVlanId(nativeVlan); |
| 231 | } else { |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 232 | log.warn("Untagged nexthop {}/{} is not allowed on {} without untagged or native vlan", |
| 233 | hostMac, hostVlanId, connectPoint); |
| 234 | return null; |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 235 | } |
| 236 | } else { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 237 | log.warn("Tagged nexthop {}/{} is not allowed on {} without VLAN listed" |
| 238 | + " in tagged vlan", hostMac, hostVlanId, connectPoint); |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 239 | return null; |
| 240 | } |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 241 | // if the objective is to revoke an existing rule, and for some reason |
| 242 | // the next-objective does not exist, then a new one should not be created |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 243 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outPort, |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 244 | tbuilder.build(), mbuilder.build(), !revoke); |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 245 | if (portNextObjId == -1) { |
| 246 | // Warning log will come from getPortNextObjective method |
| 247 | return null; |
| 248 | } |
| 249 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 250 | return DefaultForwardingObjective.builder() |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 251 | .withSelector(sbuilder.build()) |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 252 | .nextStep(portNextObjId) |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 253 | .fromApp(srManager.appId).makePermanent() |
Charles Chan | 1cdecff | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 254 | .withPriority(getPriorityFromPrefix(prefix)) |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 255 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /** |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 259 | * Populates IP flow rules for all the given prefixes reachable from the |
| 260 | * destination switch(es). |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 261 | * |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 262 | * @param targetSw switch where rules are to be programmed |
| 263 | * @param subnets subnets/prefixes being added |
| 264 | * @param destSw1 destination switch where the prefixes are reachable |
| 265 | * @param destSw2 paired destination switch if one exists for the subnets/prefixes. |
| 266 | * Should be null if there is no paired destination switch (by config) |
| 267 | * or if the given prefixes are reachable only via destSw1 |
| 268 | * @param nextHops a map containing a set of next-hops for each destination switch. |
| 269 | * If destSw2 is not null, then this map must contain an |
| 270 | * entry for destSw2 with its next-hops from the targetSw |
| 271 | * (although the next-hop set may be empty in certain scenarios). |
| 272 | * If destSw2 is null, there should not be an entry in this |
| 273 | * map for destSw2. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 274 | * @return true if all rules are set successfully, false otherwise |
| 275 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 276 | boolean populateIpRuleForSubnet(DeviceId targetSw, Set<IpPrefix> subnets, |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 277 | DeviceId destSw1, DeviceId destSw2, Map<DeviceId, Set<DeviceId>> nextHops) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 278 | for (IpPrefix subnet : subnets) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 279 | if (!populateIpRuleForRouter(targetSw, subnet, destSw1, destSw2, nextHops)) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 280 | return false; |
| 281 | } |
| 282 | } |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 283 | return true; |
| 284 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 285 | |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 286 | /** |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 287 | * Revokes IP flow rules for the subnets in each edge switch. |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 288 | * |
| 289 | * @param subnets subnet being removed |
| 290 | * @return true if all rules are removed successfully, false otherwise |
| 291 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 292 | boolean revokeIpRuleForSubnet(Set<IpPrefix> subnets) { |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 293 | for (IpPrefix subnet : subnets) { |
| 294 | if (!revokeIpRuleForRouter(subnet)) { |
| 295 | return false; |
| 296 | } |
| 297 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 298 | return true; |
| 299 | } |
| 300 | |
| 301 | /** |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 302 | * Populates IP flow rules for an IP prefix in the target device. The prefix |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 303 | * is reachable via destination device(s). |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 304 | * |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 305 | * @param targetSw target device ID to set the rules |
| 306 | * @param ipPrefix the IP prefix |
| 307 | * @param destSw1 destination switch where the prefixes are reachable |
| 308 | * @param destSw2 paired destination switch if one exists for the subnets/prefixes. |
| 309 | * Should be null if there is no paired destination switch (by config) |
| 310 | * or if the given prefixes are reachable only via destSw1 |
| 311 | * @param nextHops map of destination switches and their next-hops. |
| 312 | * Should only contain destination switches that are |
| 313 | * actually meant to be routed to. If destSw2 is null, there |
| 314 | * should not be an entry for destSw2 in this map. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 315 | * @return true if all rules are set successfully, false otherwise |
| 316 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 317 | private boolean populateIpRuleForRouter(DeviceId targetSw, |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 318 | IpPrefix ipPrefix, DeviceId destSw1, |
| 319 | DeviceId destSw2, |
| 320 | Map<DeviceId, Set<DeviceId>> nextHops) { |
| 321 | int segmentId1, segmentId2 = -1; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 322 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 323 | if (ipPrefix.isIp4()) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 324 | segmentId1 = config.getIPv4SegmentId(destSw1); |
| 325 | if (destSw2 != null) { |
| 326 | segmentId2 = config.getIPv4SegmentId(destSw2); |
| 327 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 328 | } else { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 329 | segmentId1 = config.getIPv6SegmentId(destSw1); |
| 330 | if (destSw2 != null) { |
| 331 | segmentId2 = config.getIPv6SegmentId(destSw2); |
| 332 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 333 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 334 | } catch (DeviceConfigNotFoundException e) { |
| 335 | log.warn(e.getMessage() + " Aborting populateIpRuleForRouter."); |
| 336 | return false; |
| 337 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 338 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 339 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 340 | TrafficSelector selector = sbuilder.build(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 341 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 342 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 343 | DestinationSet ds; |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 344 | TrafficTreatment treatment; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 345 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 346 | // If the next hop is the same as the final destination, then MPLS label |
| 347 | // is not set. |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 348 | /*if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 349 | tbuilder.immediate().decNwTtl(); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 350 | ds = new DestinationSet(false, destSw); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 351 | treatment = tbuilder.build(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 352 | } else { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 353 | ds = new DestinationSet(false, segmentId, destSw); |
| 354 | treatment = null; |
| 355 | }*/ |
| 356 | if (destSw2 == null) { |
| 357 | // single dst - create destination set based on next-hop |
| 358 | Set<DeviceId> nhd1 = nextHops.get(destSw1); |
| 359 | if (nhd1.size() == 1 && nhd1.iterator().next().equals(destSw1)) { |
| 360 | tbuilder.immediate().decNwTtl(); |
| 361 | ds = new DestinationSet(false, destSw1); |
| 362 | treatment = tbuilder.build(); |
| 363 | } else { |
| 364 | ds = new DestinationSet(false, segmentId1, destSw1); |
| 365 | treatment = null; |
| 366 | } |
| 367 | } else { |
| 368 | // dst pair - IP rules for dst-pairs are always from other edge nodes |
| 369 | // the destination set needs to have both destinations, even if there |
| 370 | // are no next hops to one of them |
| 371 | ds = new DestinationSet(false, segmentId1, destSw1, segmentId2, destSw2); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 372 | treatment = null; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 375 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 376 | // if needed by the switch pipeline. Since neighbor sets are always to |
| 377 | // other neighboring routers, there is no subnet assigned on those ports. |
| 378 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 379 | metabuilder.matchVlanId(SegmentRoutingManager.INTERNAL_VLAN); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 380 | DefaultGroupHandler grpHandler = srManager.getGroupHandler(targetSw); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 381 | if (grpHandler == null) { |
| 382 | log.warn("populateIPRuleForRouter: groupHandler for device {} " |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 383 | + "not found", targetSw); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 384 | return false; |
| 385 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 386 | |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 387 | int nextId = grpHandler.getNextObjectiveId(ds, nextHops, |
| 388 | metabuilder.build(), true); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 389 | if (nextId <= 0) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 390 | log.warn("No next objective in {} for ds: {}", targetSw, ds); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 391 | return false; |
| 392 | } |
| 393 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 394 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 395 | .builder() |
| 396 | .fromApp(srManager.appId) |
| 397 | .makePermanent() |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 398 | .nextStep(nextId) |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 399 | .withSelector(selector) |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 400 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 401 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 402 | if (treatment != null) { |
| 403 | fwdBuilder.withTreatment(treatment); |
| 404 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 405 | log.debug("Installing IPv4 forwarding objective for router IP/subnet {} " |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 406 | + "in switch {} with nextId: {}", ipPrefix, targetSw, nextId); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 407 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 408 | (objective) -> log.debug("IP rule for router {} populated in dev:{}", |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 409 | ipPrefix, targetSw), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 410 | (objective, error) -> |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 411 | log.warn("Failed to populate IP rule for router {}: {} in dev:{}", |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 412 | ipPrefix, error, targetSw)); |
| 413 | srManager.flowObjectiveService.forward(targetSw, fwdBuilder.add(context)); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 414 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 415 | |
| 416 | return true; |
| 417 | } |
| 418 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 419 | /** |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 420 | * Revokes IP flow rules for the router IP address. |
| 421 | * |
| 422 | * @param ipPrefix the IP address of the destination router |
| 423 | * @return true if all rules are removed successfully, false otherwise |
| 424 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 425 | private boolean revokeIpRuleForRouter(IpPrefix ipPrefix) { |
Pier Ventre | 968da12 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 426 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix); |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 427 | TrafficSelector selector = sbuilder.build(); |
| 428 | TrafficTreatment dummyTreatment = DefaultTrafficTreatment.builder().build(); |
| 429 | |
| 430 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 431 | .builder() |
| 432 | .fromApp(srManager.appId) |
| 433 | .makePermanent() |
| 434 | .withSelector(selector) |
| 435 | .withTreatment(dummyTreatment) |
| 436 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
| 437 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 438 | |
| 439 | ObjectiveContext context = new DefaultObjectiveContext( |
| 440 | (objective) -> log.debug("IP rule for router {} revoked", ipPrefix), |
| 441 | (objective, error) -> |
| 442 | log.warn("Failed to revoke IP rule for router {}: {}", ipPrefix, error)); |
| 443 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 444 | srManager.deviceService.getAvailableDevices().forEach(device -> |
| 445 | srManager.flowObjectiveService.forward(device.id(), fwdBuilder.remove(context)) |
| 446 | ); |
Charles Chan | 93e71ba | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 447 | |
| 448 | return true; |
| 449 | } |
| 450 | |
| 451 | /** |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 452 | * Deals with !MPLS Bos use case. |
| 453 | * |
| 454 | * @param targetSwId the target sw |
| 455 | * @param destSwId the destination sw |
| 456 | * @param nextHops the set of next hops |
| 457 | * @param segmentId the segmentId to match |
| 458 | * @param routerIp the router ip |
| 459 | * @return a collection of fwdobjective |
| 460 | */ |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 461 | private Collection<ForwardingObjective> handleMpls( |
| 462 | DeviceId targetSwId, |
| 463 | DeviceId destSwId, |
| 464 | Set<DeviceId> nextHops, |
| 465 | int segmentId, |
| 466 | IpAddress routerIp, |
| 467 | boolean isMplsBos) { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 468 | |
| 469 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 470 | List<ForwardingObjective.Builder> fwdObjBuilders = Lists.newArrayList(); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 471 | // For the transport of Pwaas we can use two or three MPLS label |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 472 | sbuilder.matchEthType(Ethernet.MPLS_UNICAST); |
| 473 | sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId)); |
| 474 | sbuilder.matchMplsBos(isMplsBos); |
| 475 | TrafficSelector selector = sbuilder.build(); |
| 476 | |
| 477 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 478 | // if needed by the switch pipeline. Since mpls next-hops are always to |
| 479 | // other neighboring routers, there is no subnet assigned on those ports. |
| 480 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 481 | metabuilder.matchVlanId(SegmentRoutingManager.INTERNAL_VLAN); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 482 | |
| 483 | if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { |
| 484 | // If the next hop is the destination router for the segment, do pop |
| 485 | log.debug("populateMplsRule: Installing MPLS forwarding objective for " |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 486 | + "label {} in switch {} with pop to next-hops {}", |
| 487 | segmentId, targetSwId, nextHops); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 488 | // Not-bos pop case (php for the current label). If MPLS-ECMP |
| 489 | // has been configured, the application we will request the |
| 490 | // installation for an MPLS-ECMP group. |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 491 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 492 | getMplsForwardingObjective(targetSwId, |
| 493 | nextHops, |
| 494 | true, |
| 495 | isMplsBos, |
| 496 | metabuilder.build(), |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 497 | routerIp, |
| 498 | destSwId); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 499 | // Error case, we cannot handle, exit. |
| 500 | if (fwdObjNoBosBuilder == null) { |
| 501 | return Collections.emptyList(); |
| 502 | } |
| 503 | fwdObjBuilders.add(fwdObjNoBosBuilder); |
| 504 | |
| 505 | } else { |
| 506 | // next hop is not destination, SR CONTINUE case (swap with self) |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 507 | log.debug("Installing MPLS forwarding objective for " |
| 508 | + "label {} in switch {} without pop to next-hops {}", |
| 509 | segmentId, targetSwId, nextHops); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 510 | // Not-bos pop case. If MPLS-ECMP has been configured, the |
| 511 | // application we will request the installation for an MPLS-ECMP |
| 512 | // group. |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 513 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 514 | getMplsForwardingObjective(targetSwId, |
| 515 | nextHops, |
| 516 | false, |
| 517 | isMplsBos, |
| 518 | metabuilder.build(), |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 519 | routerIp, |
| 520 | destSwId); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 521 | // Error case, we cannot handle, exit. |
| 522 | if (fwdObjNoBosBuilder == null) { |
| 523 | return Collections.emptyList(); |
| 524 | } |
| 525 | fwdObjBuilders.add(fwdObjNoBosBuilder); |
| 526 | |
| 527 | } |
| 528 | |
| 529 | List<ForwardingObjective> fwdObjs = Lists.newArrayList(); |
| 530 | // We add the final property to the fwdObjs. |
| 531 | for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) { |
| 532 | |
| 533 | ((Builder) ((Builder) fwdObjBuilder |
| 534 | .fromApp(srManager.appId) |
| 535 | .makePermanent()) |
| 536 | .withSelector(selector) |
| 537 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)) |
| 538 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 539 | |
| 540 | ObjectiveContext context = new DefaultObjectiveContext( |
| 541 | (objective) -> |
| 542 | log.debug("MPLS rule {} for SID {} populated in dev:{} ", |
| 543 | objective.id(), segmentId, targetSwId), |
| 544 | (objective, error) -> |
| 545 | log.warn("Failed to populate MPLS rule {} for SID {}: {} in dev:{}", |
| 546 | objective.id(), segmentId, error, targetSwId)); |
| 547 | |
| 548 | ForwardingObjective fob = fwdObjBuilder.add(context); |
| 549 | fwdObjs.add(fob); |
| 550 | |
| 551 | } |
| 552 | |
| 553 | return fwdObjs; |
| 554 | } |
| 555 | |
| 556 | /** |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 557 | * Populates MPLS flow rules in the target device to point towards the |
| 558 | * destination device. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 559 | * |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 560 | * @param targetSwId target device ID of the switch to set the rules |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 561 | * @param destSwId destination switch device ID |
| 562 | * @param nextHops next hops switch ID list |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 563 | * @param routerIp the router ip |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 564 | * @return true if all rules are set successfully, false otherwise |
| 565 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 566 | boolean populateMplsRule(DeviceId targetSwId, DeviceId destSwId, |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 567 | Set<DeviceId> nextHops, |
| 568 | IpAddress routerIp) { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 569 | |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 570 | int segmentId; |
| 571 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 572 | if (routerIp.isIp4()) { |
| 573 | segmentId = config.getIPv4SegmentId(destSwId); |
| 574 | } else { |
| 575 | segmentId = config.getIPv6SegmentId(destSwId); |
| 576 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 577 | } catch (DeviceConfigNotFoundException e) { |
| 578 | log.warn(e.getMessage() + " Aborting populateMplsRule."); |
| 579 | return false; |
| 580 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 581 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 582 | List<ForwardingObjective> fwdObjs = new ArrayList<>(); |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 583 | Collection<ForwardingObjective> fwdObjsMpls; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 584 | // Generates the transit rules used by the standard "routing". |
| 585 | fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, routerIp, true); |
| 586 | if (fwdObjsMpls.isEmpty()) { |
| 587 | return false; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 588 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 589 | fwdObjs.addAll(fwdObjsMpls); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 590 | // Generates the transit rules used by the MPLS Pwaas. For now it is |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 591 | // the only case !BoS supported. |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 592 | /* |
| 593 | fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, routerIp, false); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 594 | if (fwdObjsMpls.isEmpty()) { |
| 595 | return false; |
| 596 | } |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 597 | fwdObjs.addAll(fwdObjsMpls); |
| 598 | */ |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 599 | |
| 600 | for (ForwardingObjective fwdObj : fwdObjs) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 601 | log.debug("Sending MPLS fwd obj {} for SID {}-> next {} in sw: {}", |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 602 | fwdObj.id(), segmentId, fwdObj.nextId(), targetSwId); |
| 603 | srManager.flowObjectiveService.forward(targetSwId, fwdObj); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 604 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | return true; |
| 608 | } |
| 609 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 610 | private ForwardingObjective.Builder getMplsForwardingObjective( |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 611 | DeviceId targetSw, |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 612 | Set<DeviceId> nextHops, |
| 613 | boolean phpRequired, |
| 614 | boolean isBos, |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 615 | TrafficSelector meta, |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 616 | IpAddress routerIp, |
| 617 | DeviceId destSw) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 618 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 619 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 620 | .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 621 | |
| 622 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 623 | |
| 624 | if (phpRequired) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 625 | // php case - pop should always be flow-action |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 626 | log.debug("getMplsForwardingObjective: php required"); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 627 | tbuilder.deferred().copyTtlIn(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 628 | if (isBos) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 629 | if (routerIp.isIp4()) { |
| 630 | tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType()); |
| 631 | } else { |
| 632 | tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType()); |
| 633 | } |
| 634 | tbuilder.decNwTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 635 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 636 | tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType()) |
| 637 | .decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 638 | } |
| 639 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 640 | // swap with self case - SR CONTINUE |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 641 | log.debug("getMplsForwardingObjective: php not required"); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 642 | tbuilder.deferred().decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 645 | fwdBuilder.withTreatment(tbuilder.build()); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 646 | // if MPLS-ECMP == True we will build a standard NeighborSet. |
| 647 | // Otherwise a RandomNeighborSet. |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 648 | DestinationSet ns = DestinationSet.destinationSet(false, false, destSw); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 649 | if (!isBos && this.srManager.getMplsEcmp()) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 650 | ns = DestinationSet.destinationSet(false, true, destSw); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 651 | } else if (!isBos && !this.srManager.getMplsEcmp()) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 652 | ns = DestinationSet.destinationSet(true, true, destSw); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 653 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 654 | |
Saurav Das | b28d5dd | 2017-03-24 19:03:58 -0700 | [diff] [blame] | 655 | log.debug("Trying to get a nextObjId for mpls rule on device:{} to ns:{}", |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 656 | targetSw, ns); |
| 657 | DefaultGroupHandler gh = srManager.getGroupHandler(targetSw); |
| 658 | if (gh == null) { |
| 659 | log.warn("getNextObjectiveId query - groupHandler for device {} " |
| 660 | + "not found", targetSw); |
| 661 | return null; |
| 662 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 663 | // If BoS == True, all forwarding is via L3 ECMP group. |
| 664 | // If Bos == False, the forwarding can be via MPLS-ECMP group or through |
| 665 | // MPLS-Interface group. This depends on the configuration of the option |
| 666 | // MPLS-ECMP. |
| 667 | // The metadata informs the driver that the next-Objective will be used |
| 668 | // by MPLS flows and if Bos == False the driver will use MPLS groups. |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 669 | Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>(); |
| 670 | dstNextHops.put(destSw, nextHops); |
| 671 | int nextId = gh.getNextObjectiveId(ns, dstNextHops, meta, isBos); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 672 | if (nextId <= 0) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 673 | log.warn("No next objective in {} for ns: {}", targetSw, ns); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 674 | return null; |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 675 | } else { |
| 676 | log.debug("nextObjId found:{} for mpls rule on device:{} to ns:{}", |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 677 | nextId, targetSw, ns); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 680 | fwdBuilder.nextStep(nextId); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 681 | return fwdBuilder; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 685 | * Creates a filtering objective to permit all untagged packets with a |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 686 | * dstMac corresponding to the router's MAC address. For those pipelines |
| 687 | * that need to internally assign vlans to untagged packets, this method |
| 688 | * provides per-subnet vlan-ids as metadata. |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 689 | * <p> |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 690 | * Note that the vlan assignment and filter programming should only be done by |
| 691 | * the master for a switch. This method is typically called at deviceAdd and |
| 692 | * programs filters only for the enabled ports of the device. For port-updates, |
| 693 | * that enable/disable ports after device add, singlePortFilter methods should |
| 694 | * be called. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 695 | * |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 696 | * @param deviceId the switch dpid for the router |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 697 | * @return PortFilterInfo information about the processed ports |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 698 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 699 | PortFilterInfo populateVlanMacFilters(DeviceId deviceId) { |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 700 | log.debug("Installing per-port filtering objective for untagged " |
| 701 | + "packets in device {}", deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 702 | |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 703 | List<Port> devPorts = srManager.deviceService.getPorts(deviceId); |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 704 | if (devPorts == null || devPorts.isEmpty()) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 705 | log.warn("Device {} ports not available. Unable to add MacVlan filters", |
| 706 | deviceId); |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 707 | return null; |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 708 | } |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 709 | int disabledPorts = 0, errorPorts = 0, filteredPorts = 0; |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 710 | for (Port port : devPorts) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 711 | if (!port.isEnabled()) { |
| 712 | disabledPorts++; |
| 713 | continue; |
| 714 | } |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 715 | if (processSinglePortFilters(deviceId, port.number(), true)) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 716 | filteredPorts++; |
| 717 | } else { |
| 718 | errorPorts++; |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 719 | } |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 720 | } |
Charles Chan | 7f9737b | 2017-06-22 14:27:17 -0700 | [diff] [blame] | 721 | log.debug("Filtering on dev:{}, disabledPorts:{}, errorPorts:{}, filteredPorts:{}", |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 722 | deviceId, disabledPorts, errorPorts, filteredPorts); |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 723 | return srManager.defaultRoutingHandler.new PortFilterInfo(disabledPorts, |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 724 | errorPorts, filteredPorts); |
| 725 | } |
| 726 | |
| 727 | /** |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 728 | * Creates or removes filtering objectives for a single port. Should only be |
| 729 | * called by the master for a switch. |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 730 | * |
| 731 | * @param deviceId device identifier |
| 732 | * @param portnum port identifier for port to be filtered |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 733 | * @param install true to install the filtering objective, false to remove |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 734 | * @return true if no errors occurred during the build of the filtering objective |
| 735 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 736 | boolean processSinglePortFilters(DeviceId deviceId, PortNumber portnum, boolean install) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 737 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portnum); |
| 738 | VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint); |
| 739 | Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint); |
| 740 | VlanId nativeVlan = srManager.getNativeVlanId(connectPoint); |
| 741 | |
| 742 | if (taggedVlans.size() != 0) { |
| 743 | // Filter for tagged vlans |
| 744 | if (!srManager.getTaggedVlanId(connectPoint).stream().allMatch(taggedVlanId -> |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 745 | processSinglePortFiltersInternal(deviceId, portnum, false, taggedVlanId, install))) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 746 | return false; |
| 747 | } |
| 748 | if (nativeVlan != null) { |
| 749 | // Filter for native vlan |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 750 | if (!processSinglePortFiltersInternal(deviceId, portnum, true, nativeVlan, install)) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 751 | return false; |
| 752 | } |
| 753 | } |
| 754 | } else if (untaggedVlan != null) { |
| 755 | // Filter for untagged vlan |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 756 | if (!processSinglePortFiltersInternal(deviceId, portnum, true, untaggedVlan, install)) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 757 | return false; |
| 758 | } |
| 759 | } else { |
| 760 | // Unconfigure port, use INTERNAL_VLAN |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 761 | if (!processSinglePortFiltersInternal(deviceId, portnum, true, INTERNAL_VLAN, install)) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 762 | return false; |
| 763 | } |
| 764 | } |
| 765 | return true; |
| 766 | } |
| 767 | |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 768 | private boolean processSinglePortFiltersInternal(DeviceId deviceId, PortNumber portnum, |
| 769 | boolean pushVlan, VlanId vlanId, boolean install) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 770 | FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum, pushVlan, vlanId); |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 771 | if (fob == null) { |
| 772 | // error encountered during build |
| 773 | return false; |
| 774 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 775 | log.debug("{} filtering objectives for dev/port:{}/{}", |
| 776 | install ? "Installing" : "Removing", deviceId, portnum); |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 777 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 778 | (objective) -> log.debug("Filter for {}/{} {}", deviceId, portnum, |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 779 | install ? "installed" : "removed"), |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 780 | (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}", |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 781 | install ? "install" : "remove", deviceId, portnum, error)); |
Charles Chan | 7e4f819 | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 782 | if (install) { |
| 783 | srManager.flowObjectiveService.filter(deviceId, fob.add(context)); |
| 784 | } else { |
| 785 | srManager.flowObjectiveService.filter(deviceId, fob.remove(context)); |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 786 | } |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 787 | return true; |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 788 | } |
| 789 | |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 790 | private FilteringObjective.Builder buildFilteringObjective(DeviceId deviceId, PortNumber portnum, |
| 791 | boolean pushVlan, VlanId vlanId) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 792 | MacAddress deviceMac; |
| 793 | try { |
| 794 | deviceMac = config.getDeviceMac(deviceId); |
| 795 | } catch (DeviceConfigNotFoundException e) { |
| 796 | log.warn(e.getMessage() + " Processing SinglePortFilters aborted"); |
| 797 | return null; |
| 798 | } |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 799 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 800 | fob.withKey(Criteria.matchInPort(portnum)) |
| 801 | .addCondition(Criteria.matchEthDst(deviceMac)) |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 802 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY); |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 803 | |
| 804 | if (pushVlan) { |
| 805 | fob.addCondition(Criteria.matchVlanId(VlanId.NONE)); |
| 806 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
| 807 | .pushVlan().setVlanId(vlanId).build(); |
| 808 | fob.withMeta(tt); |
| 809 | } else { |
| 810 | fob.addCondition(Criteria.matchVlanId(vlanId)); |
| 811 | } |
| 812 | |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 813 | fob.permit().fromApp(srManager.appId); |
| 814 | return fob; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 818 | * Creates a forwarding objective to punt all IP packets, destined to the |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 819 | * router's port IP addresses, to the controller. Note that the input |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 820 | * 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] | 821 | * Furthermore, these are applied only by the master instance. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 822 | * |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 823 | * @param deviceId the switch dpid for the router |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 824 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 825 | void populateIpPunts(DeviceId deviceId) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 826 | Ip4Address routerIpv4, pairRouterIpv4 = null; |
| 827 | Ip6Address routerIpv6, pairRouterIpv6 = null; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 828 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 829 | routerIpv4 = config.getRouterIpv4(deviceId); |
| 830 | routerIpv6 = config.getRouterIpv6(deviceId); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 831 | if (config.isPairedEdge(deviceId)) { |
| 832 | pairRouterIpv4 = config.getRouterIpv4(config.getPairDeviceId(deviceId)); |
| 833 | pairRouterIpv6 = config.getRouterIpv6(config.getPairDeviceId(deviceId)); |
| 834 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 835 | } catch (DeviceConfigNotFoundException e) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 836 | log.warn(e.getMessage() + " Aborting populateIpPunts."); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 837 | return; |
| 838 | } |
| 839 | |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 840 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 841 | log.debug("Not installing port-IP punts - not the master for dev:{} ", |
| 842 | deviceId); |
| 843 | return; |
| 844 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 845 | Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId)); |
| 846 | allIps.add(routerIpv4); |
| 847 | if (routerIpv6 != null) { |
| 848 | allIps.add(routerIpv6); |
| 849 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 850 | if (pairRouterIpv4 != null) { |
| 851 | allIps.add(pairRouterIpv4); |
| 852 | } |
| 853 | if (pairRouterIpv6 != null) { |
| 854 | allIps.add(pairRouterIpv6); |
| 855 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 856 | for (IpAddress ipaddr : allIps) { |
| 857 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpAddress(ipaddr); |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 858 | Optional<DeviceId> optDeviceId = Optional.of(deviceId); |
| 859 | |
| 860 | srManager.packetService.requestPackets(sbuilder.build(), |
| 861 | PacketPriority.CONTROL, srManager.appId, optDeviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 862 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 865 | /** |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 866 | * Method to build IPv4 or IPv6 selector. |
| 867 | * |
| 868 | * @param addressToMatch the address to match |
| 869 | */ |
| 870 | private TrafficSelector.Builder buildIpSelectorFromIpAddress(IpAddress addressToMatch) { |
| 871 | return buildIpSelectorFromIpPrefix(addressToMatch.toIpPrefix()); |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Method to build IPv4 or IPv6 selector. |
| 876 | * |
| 877 | * @param prefixToMatch the prefix to match |
| 878 | */ |
| 879 | private TrafficSelector.Builder buildIpSelectorFromIpPrefix(IpPrefix prefixToMatch) { |
| 880 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 881 | // If the prefix is IPv4 |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 882 | if (prefixToMatch.isIp4()) { |
| 883 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 884 | selectorBuilder.matchIPDst(prefixToMatch.getIp4Prefix()); |
| 885 | return selectorBuilder; |
| 886 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 887 | // If the prefix is IPv6 |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 888 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 889 | selectorBuilder.matchIPv6Dst(prefixToMatch.getIp6Prefix()); |
| 890 | return selectorBuilder; |
| 891 | } |
| 892 | |
| 893 | /** |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 894 | * Creates forwarding objectives to punt ARP and NDP packets, to the controller. |
| 895 | * Furthermore, these are applied only by the master instance. Deferred actions |
| 896 | * are not cleared such that packets can be flooded in the cross connect use case |
| 897 | * |
| 898 | * @param deviceId the switch dpid for the router |
| 899 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 900 | void populateArpNdpPunts(DeviceId deviceId) { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 901 | // We are not the master just skip. |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 902 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 903 | log.debug("Not installing ARP/NDP punts - not the master for dev:{} ", |
| 904 | deviceId); |
| 905 | return; |
| 906 | } |
| 907 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 908 | ForwardingObjective fwdObj; |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 909 | // We punt all ARP packets towards the controller. |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 910 | fwdObj = arpFwdObjective(null, true, PacketPriority.CONTROL.priorityValue()) |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 911 | .add(new ObjectiveContext() { |
| 912 | @Override |
| 913 | public void onError(Objective objective, ObjectiveError error) { |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 914 | log.warn("Failed to install forwarding objective to punt ARP to {}: {}", |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 915 | deviceId, error); |
| 916 | } |
| 917 | }); |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 918 | srManager.flowObjectiveService.forward(deviceId, fwdObj); |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 919 | |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 920 | // We punt all NDP packets towards the controller. |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 921 | fwdObj = ndpFwdObjective(null, true, PacketPriority.CONTROL.priorityValue()) |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 922 | .add(new ObjectiveContext() { |
| 923 | @Override |
| 924 | public void onError(Objective objective, ObjectiveError error) { |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 925 | log.warn("Failed to install forwarding objective to punt NDP to {}: {}", |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 926 | deviceId, error); |
| 927 | } |
| 928 | }); |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 929 | srManager.flowObjectiveService.forward(deviceId, fwdObj); |
| 930 | |
| 931 | srManager.getPairLocalPorts(deviceId).ifPresent(port -> { |
| 932 | ForwardingObjective pairFwdObj; |
| 933 | // Do not punt ARP packets from pair port |
| 934 | pairFwdObj = arpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1) |
| 935 | .add(new ObjectiveContext() { |
| 936 | @Override |
| 937 | public void onError(Objective objective, ObjectiveError error) { |
| 938 | log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", |
| 939 | deviceId, error); |
| 940 | } |
| 941 | }); |
| 942 | srManager.flowObjectiveService.forward(deviceId, pairFwdObj); |
| 943 | |
| 944 | // Do not punt NDP packets from pair port |
| 945 | pairFwdObj = ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1) |
| 946 | .add(new ObjectiveContext() { |
| 947 | @Override |
| 948 | public void onError(Objective objective, ObjectiveError error) { |
| 949 | log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", |
| 950 | deviceId, error); |
| 951 | } |
| 952 | }); |
| 953 | srManager.flowObjectiveService.forward(deviceId, pairFwdObj); |
| 954 | |
| 955 | // Do not forward DAD packets from pair port |
| 956 | pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2) |
| 957 | .add(new ObjectiveContext() { |
| 958 | @Override |
| 959 | public void onError(Objective objective, ObjectiveError error) { |
| 960 | log.warn("Failed to install forwarding objective to drop DAD to {}: {}", |
| 961 | deviceId, error); |
| 962 | } |
| 963 | }); |
| 964 | srManager.flowObjectiveService.forward(deviceId, pairFwdObj); |
| 965 | }); |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 968 | private ForwardingObjective.Builder fwdObjBuilder(TrafficSelector selector, |
| 969 | TrafficTreatment treatment, int priority) { |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 970 | return DefaultForwardingObjective.builder() |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 971 | .withPriority(priority) |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 972 | .withSelector(selector) |
| 973 | .fromApp(srManager.appId) |
| 974 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 975 | .withTreatment(treatment) |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 976 | .makePermanent(); |
| 977 | } |
| 978 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 979 | private ForwardingObjective.Builder arpFwdObjective(PortNumber port, boolean punt, int priority) { |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 980 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 981 | sBuilder.matchEthType(TYPE_ARP); |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 982 | if (port != null) { |
| 983 | sBuilder.matchInPort(port); |
| 984 | } |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 985 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 986 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 987 | if (punt) { |
| 988 | tBuilder.punt(); |
| 989 | } |
| 990 | return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority); |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 993 | private ForwardingObjective.Builder ndpFwdObjective(PortNumber port, boolean punt, int priority) { |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 994 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 995 | sBuilder.matchEthType(TYPE_IPV6) |
| 996 | .matchIPProtocol(PROTOCOL_ICMP6) |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 997 | .matchIcmpv6Type(NEIGHBOR_SOLICITATION); |
| 998 | if (port != null) { |
| 999 | sBuilder.matchInPort(port); |
| 1000 | } |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1001 | |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1002 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1003 | if (punt) { |
| 1004 | tBuilder.punt(); |
| 1005 | } |
| 1006 | return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority); |
| 1007 | } |
| 1008 | |
| 1009 | private ForwardingObjective.Builder dad6FwdObjective(PortNumber port, int priority) { |
| 1010 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 1011 | sBuilder.matchEthType(TYPE_IPV6) |
Charles Chan | c7e36aa | 2017-08-07 12:39:03 -0700 | [diff] [blame^] | 1012 | .matchIPv6Src(Ip6Address.ZERO.toIpPrefix()); |
| 1013 | // TODO CORD-1672 Fix this when OFDPA can distinguish ::/0 and ::/128 correctly |
| 1014 | // .matchIPProtocol(PROTOCOL_ICMP6) |
| 1015 | // .matchIcmpv6Type(NEIGHBOR_SOLICITATION); |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1016 | if (port != null) { |
| 1017 | sBuilder.matchInPort(port); |
| 1018 | } |
| 1019 | |
| 1020 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1021 | tBuilder.wipeDeferred(); |
| 1022 | return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority); |
Pier Luigi | 9e5c5ca | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | /** |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1026 | * Populates a forwarding objective to send packets that miss other high |
| 1027 | * priority Bridging Table entries to a group that contains all ports of |
| 1028 | * its subnet. |
| 1029 | * |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1030 | * @param deviceId switch ID to set the rules |
| 1031 | */ |
Charles Chan | 6523824 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1032 | void populateSubnetBroadcastRule(DeviceId deviceId) { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1033 | srManager.getVlanPortMap(deviceId).asMap().forEach((vlanId, ports) -> { |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1034 | int nextId = srManager.getVlanNextObjectiveId(deviceId, vlanId); |
| 1035 | |
| 1036 | if (nextId < 0) { |
| 1037 | log.error("Cannot install vlan {} broadcast rule in dev:{} due" |
| 1038 | + "to vlanId:{} or nextId:{}", vlanId, deviceId, vlanId, nextId); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1039 | return; |
| 1040 | } |
| 1041 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1042 | // Driver should treat objective with MacAddress.NONE as the |
| 1043 | // subnet broadcast rule |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1044 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1045 | sbuilder.matchVlanId(vlanId); |
| 1046 | sbuilder.matchEthDst(MacAddress.NONE); |
| 1047 | |
| 1048 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 1049 | fob.withFlag(Flag.SPECIFIC) |
| 1050 | .withSelector(sbuilder.build()) |
| 1051 | .nextStep(nextId) |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1052 | .withPriority(SegmentRoutingService.FLOOD_PRIORITY) |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1053 | .fromApp(srManager.appId) |
| 1054 | .makePermanent(); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1055 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1056 | (objective) -> log.debug("Vlan broadcast rule for {} populated", vlanId), |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1057 | (objective, error) -> |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1058 | log.warn("Failed to populate vlan broadcast rule for {}: {}", vlanId, error)); |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1059 | srManager.flowObjectiveService.forward(deviceId, fob.add(context)); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1060 | }); |
| 1061 | } |
| 1062 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1063 | private int getPriorityFromPrefix(IpPrefix prefix) { |
| 1064 | return (prefix.isIp4()) ? |
| 1065 | 2000 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY : |
| 1066 | 500 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY; |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 1067 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1068 | } |