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