Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.segmentrouting; |
| 18 | |
| 19 | import org.onlab.packet.Ip4Prefix; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.packet.VlanId; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 24 | import org.onosproject.net.Host; |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 25 | import org.onosproject.net.HostLocation; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 26 | import org.onosproject.net.PortNumber; |
| 27 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 29 | import org.onosproject.net.flow.TrafficSelector; |
| 30 | import org.onosproject.net.flow.TrafficTreatment; |
| 31 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 32 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
| 33 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 34 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 35 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 36 | import org.onosproject.net.host.HostEvent; |
| 37 | import org.onosproject.net.host.HostService; |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 38 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 39 | import org.slf4j.Logger; |
| 40 | import org.slf4j.LoggerFactory; |
| 41 | |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 42 | import com.google.common.collect.Sets; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 43 | import java.util.Set; |
| 44 | |
| 45 | /** |
| 46 | * Handles host-related events. |
| 47 | */ |
| 48 | public class HostHandler { |
| 49 | private static final Logger log = LoggerFactory.getLogger(HostHandler.class); |
| 50 | private final SegmentRoutingManager srManager; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 51 | private HostService hostService; |
| 52 | private FlowObjectiveService flowObjectiveService; |
| 53 | |
| 54 | /** |
| 55 | * Constructs the HostHandler. |
| 56 | * |
| 57 | * @param srManager Segment Routing manager |
| 58 | */ |
| 59 | public HostHandler(SegmentRoutingManager srManager) { |
| 60 | this.srManager = srManager; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 61 | hostService = srManager.hostService; |
| 62 | flowObjectiveService = srManager.flowObjectiveService; |
| 63 | } |
| 64 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 65 | protected void init(DeviceId devId) { |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 66 | hostService.getHosts().forEach(host -> { |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 67 | DeviceId deviceId = host.location().deviceId(); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 68 | // The host does not attach to this device |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 69 | if (!deviceId.equals(devId)) { |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 70 | return; |
| 71 | } |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 72 | processHostAdded(host); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 73 | }); |
| 74 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 75 | |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 76 | protected void processHostAddedEvent(HostEvent event) { |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 77 | processHostAdded(event.subject()); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 80 | protected void processHostAdded(Host host) { |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 81 | MacAddress mac = host.mac(); |
| 82 | VlanId vlanId = host.vlan(); |
| 83 | HostLocation location = host.location(); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 84 | DeviceId deviceId = location.deviceId(); |
| 85 | PortNumber port = location.port(); |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 86 | Set<IpAddress> ips = host.ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 87 | log.info("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 88 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 89 | if (accepted(host)) { |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 90 | // Populate bridging table entry |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 91 | log.debug("Populate L2 table entry for host {} at {}:{}", |
| 92 | mac, deviceId, port); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 93 | ForwardingObjective.Builder fob = |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 94 | hostFwdObjBuilder(deviceId, mac, vlanId, port); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 95 | if (fob == null) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 96 | log.warn("Fail to create fwd obj for host {}/{}. Abort.", mac, vlanId); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 97 | return; |
| 98 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 99 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 100 | (objective) -> log.debug("Host rule for {}/{} populated", mac, vlanId), |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 101 | (objective, error) -> |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 102 | log.warn("Failed to populate host rule for {}/{}: {}", mac, vlanId, error)); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 103 | flowObjectiveService.forward(deviceId, fob.add(context)); |
| 104 | |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 105 | ips.forEach(ip -> { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 106 | // Populate IP table entry |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 107 | if (srManager.deviceConfiguration.inSameSubnet(location, ip)) { |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 108 | srManager.routingRulePopulator.populateRoute( |
| 109 | deviceId, ip.toIpPrefix(), mac, port); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 110 | } |
| 111 | }); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 112 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 115 | protected void processHostRemoveEvent(HostEvent event) { |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 116 | processHostRemoved(event.subject()); |
| 117 | } |
| 118 | |
| 119 | protected void processHostRemoved(Host host) { |
| 120 | MacAddress mac = host.mac(); |
| 121 | VlanId vlanId = host.vlan(); |
| 122 | HostLocation location = host.location(); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 123 | DeviceId deviceId = location.deviceId(); |
| 124 | PortNumber port = location.port(); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 125 | Set<IpAddress> ips = host.ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 126 | log.info("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 127 | |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 128 | if (accepted(host)) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 129 | // Revoke bridging table entry |
| 130 | ForwardingObjective.Builder fob = |
| 131 | hostFwdObjBuilder(deviceId, mac, vlanId, port); |
| 132 | if (fob == null) { |
| 133 | log.warn("Fail to create fwd obj for host {}/{}. Abort.", mac, vlanId); |
| 134 | return; |
| 135 | } |
| 136 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 137 | (objective) -> log.debug("Host rule for {} revoked", host), |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 138 | (objective, error) -> |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 139 | log.warn("Failed to revoke host rule for {}: {}", host, error)); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 140 | flowObjectiveService.forward(deviceId, fob.remove(context)); |
| 141 | |
| 142 | // Revoke IP table entry |
| 143 | ips.forEach(ip -> { |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 144 | if (srManager.deviceConfiguration.inSameSubnet(location, ip)) { |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 145 | srManager.routingRulePopulator.revokeRoute( |
| 146 | deviceId, ip.toIpPrefix(), mac, port); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 147 | } |
| 148 | }); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | protected void processHostMovedEvent(HostEvent event) { |
| 153 | MacAddress mac = event.subject().mac(); |
| 154 | VlanId vlanId = event.subject().vlan(); |
| 155 | HostLocation prevLocation = event.prevSubject().location(); |
| 156 | DeviceId prevDeviceId = prevLocation.deviceId(); |
| 157 | PortNumber prevPort = prevLocation.port(); |
| 158 | Set<IpAddress> prevIps = event.prevSubject().ipAddresses(); |
| 159 | HostLocation newLocation = event.subject().location(); |
| 160 | DeviceId newDeviceId = newLocation.deviceId(); |
| 161 | PortNumber newPort = newLocation.port(); |
| 162 | Set<IpAddress> newIps = event.subject().ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 163 | log.info("Host {}/{} is moved from {}:{} to {}:{}", |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 164 | mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort); |
| 165 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 166 | if (accepted(event.prevSubject())) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 167 | // Revoke previous bridging table entry |
| 168 | ForwardingObjective.Builder prevFob = |
| 169 | hostFwdObjBuilder(prevDeviceId, mac, vlanId, prevPort); |
| 170 | if (prevFob == null) { |
| 171 | log.warn("Fail to create fwd obj for host {}/{}. Abort.", mac, vlanId); |
| 172 | return; |
| 173 | } |
| 174 | ObjectiveContext context = new DefaultObjectiveContext( |
| 175 | (objective) -> log.debug("Host rule for {} revoked", event.subject()), |
| 176 | (objective, error) -> |
| 177 | log.warn("Failed to revoke host rule for {}: {}", event.subject(), error)); |
| 178 | flowObjectiveService.forward(prevDeviceId, prevFob.remove(context)); |
| 179 | |
| 180 | // Revoke previous IP table entry |
| 181 | prevIps.forEach(ip -> { |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 182 | if (srManager.deviceConfiguration.inSameSubnet(prevLocation, ip)) { |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 183 | srManager.routingRulePopulator.revokeRoute( |
| 184 | prevDeviceId, ip.toIpPrefix(), mac, prevPort); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 185 | } |
| 186 | }); |
| 187 | } |
| 188 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 189 | if (accepted(event.subject())) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 190 | // Populate new bridging table entry |
| 191 | ForwardingObjective.Builder newFob = |
| 192 | hostFwdObjBuilder(newDeviceId, mac, vlanId, newPort); |
| 193 | if (newFob == null) { |
| 194 | log.warn("Fail to create fwd obj for host {}/{}. Abort.", mac, vlanId); |
| 195 | return; |
| 196 | } |
| 197 | ObjectiveContext context = new DefaultObjectiveContext( |
| 198 | (objective) -> log.debug("Host rule for {} populated", event.subject()), |
| 199 | (objective, error) -> |
| 200 | log.warn("Failed to populate host rule for {}: {}", event.subject(), error)); |
| 201 | flowObjectiveService.forward(newDeviceId, newFob.add(context)); |
| 202 | |
| 203 | // Populate new IP table entry |
| 204 | newIps.forEach(ip -> { |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 205 | if (srManager.deviceConfiguration.inSameSubnet(newLocation, ip)) { |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 206 | srManager.routingRulePopulator.populateRoute( |
| 207 | newDeviceId, ip.toIpPrefix(), mac, newPort); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 208 | } |
| 209 | }); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | protected void processHostUpdatedEvent(HostEvent event) { |
| 214 | MacAddress mac = event.subject().mac(); |
| 215 | VlanId vlanId = event.subject().vlan(); |
| 216 | HostLocation prevLocation = event.prevSubject().location(); |
| 217 | DeviceId prevDeviceId = prevLocation.deviceId(); |
| 218 | PortNumber prevPort = prevLocation.port(); |
| 219 | Set<IpAddress> prevIps = event.prevSubject().ipAddresses(); |
| 220 | HostLocation newLocation = event.subject().location(); |
| 221 | DeviceId newDeviceId = newLocation.deviceId(); |
| 222 | PortNumber newPort = newLocation.port(); |
| 223 | Set<IpAddress> newIps = event.subject().ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 224 | log.info("Host {}/{} is updated", mac, vlanId); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 225 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 226 | if (accepted(event.prevSubject())) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 227 | // Revoke previous IP table entry |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 228 | Sets.difference(prevIps, newIps).forEach(ip -> { |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 229 | if (srManager.deviceConfiguration.inSameSubnet(prevLocation, ip)) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 230 | log.info("revoking previous IP rule:{}", ip); |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 231 | srManager.routingRulePopulator.revokeRoute( |
| 232 | prevDeviceId, ip.toIpPrefix(), mac, prevPort); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 233 | } |
| 234 | }); |
| 235 | } |
| 236 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 237 | if (accepted(event.subject())) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 238 | // Populate new IP table entry |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 239 | Sets.difference(newIps, prevIps).forEach(ip -> { |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 240 | if (srManager.deviceConfiguration.inSameSubnet(newLocation, ip)) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 241 | log.info("populating new IP rule:{}", ip); |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 242 | srManager.routingRulePopulator.populateRoute( |
| 243 | newDeviceId, ip.toIpPrefix(), mac, newPort); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 244 | } |
| 245 | }); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Generates the forwarding objective builder for the host rules. |
| 251 | * |
| 252 | * @param deviceId Device that host attaches to |
| 253 | * @param mac MAC address of the host |
| 254 | * @param vlanId VLAN ID of the host |
| 255 | * @param outport Port that host attaches to |
| 256 | * @return Forwarding objective builder |
| 257 | */ |
| 258 | private ForwardingObjective.Builder hostFwdObjBuilder( |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 259 | DeviceId deviceId, MacAddress mac, VlanId vlanId, |
| 260 | PortNumber outport) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 261 | // Get assigned VLAN for the subnets |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 262 | VlanId outvlan = null; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 263 | // FIXME L2 forwarding should consider also IPv6 |
| 264 | Ip4Prefix subnet = srManager.deviceConfiguration.getPortIPv4Subnet(deviceId, outport); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 265 | if (subnet == null) { |
| 266 | outvlan = VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET); |
| 267 | } else { |
| 268 | outvlan = srManager.getSubnetAssignedVlanId(deviceId, subnet); |
| 269 | } |
| 270 | |
| 271 | // match rule |
| 272 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 273 | sbuilder.matchEthDst(mac); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 274 | /* |
| 275 | * Note: for untagged packets, match on the assigned VLAN. |
| 276 | * for tagged packets, match on its incoming VLAN. |
| 277 | */ |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 278 | if (vlanId.equals(VlanId.NONE)) { |
| 279 | sbuilder.matchVlanId(outvlan); |
| 280 | } else { |
| 281 | sbuilder.matchVlanId(vlanId); |
| 282 | } |
| 283 | |
| 284 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 285 | tbuilder.immediate().popVlan(); |
| 286 | tbuilder.immediate().setOutput(outport); |
| 287 | |
| 288 | // for switch pipelines that need it, provide outgoing vlan as metadata |
| 289 | TrafficSelector meta = DefaultTrafficSelector.builder() |
| 290 | .matchVlanId(outvlan).build(); |
| 291 | |
| 292 | // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed. |
| 293 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport, |
| 294 | tbuilder.build(), |
| 295 | meta); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 296 | if (portNextObjId == -1) { |
| 297 | // warning log will come from getPortNextObjective method |
| 298 | return null; |
| 299 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 300 | |
| 301 | return DefaultForwardingObjective.builder() |
| 302 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 303 | .withSelector(sbuilder.build()) |
| 304 | .nextStep(portNextObjId) |
| 305 | .withPriority(100) |
| 306 | .fromApp(srManager.appId) |
| 307 | .makePermanent(); |
| 308 | } |
| 309 | |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 310 | /** |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 311 | * Determines whether a host should be accepted by SR or not. |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 312 | * |
| 313 | * @param host host to be checked |
| 314 | * @return true if segment routing accepts the host |
| 315 | */ |
| 316 | private boolean accepted(Host host) { |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 317 | SegmentRoutingAppConfig appConfig = srManager.cfgService |
| 318 | .getConfig(srManager.appId, SegmentRoutingAppConfig.class); |
Charles Chan | 3bf64b9 | 2016-05-20 10:55:40 -0700 | [diff] [blame] | 319 | |
| 320 | boolean accepted = appConfig == null || |
| 321 | (!appConfig.suppressHostByProvider().contains(host.providerId().id()) && |
| 322 | !appConfig.suppressHostByPort().contains(host.location())); |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 323 | if (!accepted) { |
| 324 | log.info("Ignore suppressed host {}", host.id()); |
| 325 | } |
| 326 | return accepted; |
| 327 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 328 | } |