Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -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 | |
| 17 | package org.onosproject.segmentrouting; |
| 18 | |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.VlanId; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
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); |
Charles Chan | 114aec7 | 2017-06-19 14:00:53 -0700 | [diff] [blame] | 50 | protected 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 | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 90 | processBridgingRule(deviceId, port, mac, vlanId, false); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 91 | ips.forEach(ip -> { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 92 | processRoutingRule(deviceId, port, mac, vlanId, ip, false); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 93 | }); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 94 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 97 | protected void processHostRemoveEvent(HostEvent event) { |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 98 | processHostRemoved(event.subject()); |
| 99 | } |
| 100 | |
| 101 | protected void processHostRemoved(Host host) { |
| 102 | MacAddress mac = host.mac(); |
| 103 | VlanId vlanId = host.vlan(); |
| 104 | HostLocation location = host.location(); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 105 | DeviceId deviceId = location.deviceId(); |
| 106 | PortNumber port = location.port(); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 107 | Set<IpAddress> ips = host.ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 108 | log.info("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 109 | |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 110 | if (accepted(host)) { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 111 | processBridgingRule(deviceId, port, mac, vlanId, true); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 112 | ips.forEach(ip -> { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 113 | processRoutingRule(deviceId, port, mac, vlanId, ip, true); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 114 | }); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | protected void processHostMovedEvent(HostEvent event) { |
| 119 | MacAddress mac = event.subject().mac(); |
| 120 | VlanId vlanId = event.subject().vlan(); |
| 121 | HostLocation prevLocation = event.prevSubject().location(); |
| 122 | DeviceId prevDeviceId = prevLocation.deviceId(); |
| 123 | PortNumber prevPort = prevLocation.port(); |
| 124 | Set<IpAddress> prevIps = event.prevSubject().ipAddresses(); |
| 125 | HostLocation newLocation = event.subject().location(); |
| 126 | DeviceId newDeviceId = newLocation.deviceId(); |
| 127 | PortNumber newPort = newLocation.port(); |
| 128 | Set<IpAddress> newIps = event.subject().ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 129 | log.info("Host {}/{} is moved from {}:{} to {}:{}", |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 130 | mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort); |
| 131 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 132 | if (accepted(event.prevSubject())) { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 133 | processBridgingRule(prevDeviceId, prevPort, mac, vlanId, true); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 134 | prevIps.forEach(ip -> { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 135 | processRoutingRule(prevDeviceId, prevPort, mac, vlanId, ip, true); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 136 | }); |
| 137 | } |
| 138 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 139 | if (accepted(event.subject())) { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 140 | processBridgingRule(newDeviceId, newPort, mac, vlanId, false); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 141 | newIps.forEach(ip -> { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 142 | processRoutingRule(newDeviceId, newPort, mac, vlanId, ip, false); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 143 | }); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | protected void processHostUpdatedEvent(HostEvent event) { |
| 148 | MacAddress mac = event.subject().mac(); |
| 149 | VlanId vlanId = event.subject().vlan(); |
| 150 | HostLocation prevLocation = event.prevSubject().location(); |
| 151 | DeviceId prevDeviceId = prevLocation.deviceId(); |
| 152 | PortNumber prevPort = prevLocation.port(); |
| 153 | Set<IpAddress> prevIps = event.prevSubject().ipAddresses(); |
| 154 | HostLocation newLocation = event.subject().location(); |
| 155 | DeviceId newDeviceId = newLocation.deviceId(); |
| 156 | PortNumber newPort = newLocation.port(); |
| 157 | Set<IpAddress> newIps = event.subject().ipAddresses(); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 158 | log.info("Host {}/{} is updated", mac, vlanId); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 159 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 160 | if (accepted(event.prevSubject())) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 161 | // Revoke previous IP table entry |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 162 | Sets.difference(prevIps, newIps).forEach(ip -> { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 163 | processRoutingRule(prevDeviceId, prevPort, mac, vlanId, ip, true); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 164 | }); |
| 165 | } |
| 166 | |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 167 | if (accepted(event.subject())) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 168 | // Populate new IP table entry |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 169 | Sets.difference(newIps, prevIps).forEach(ip -> { |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 170 | processRoutingRule(newDeviceId, newPort, mac, vlanId, ip, false); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 171 | }); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
Charles Chan | 18fa425 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 176 | * Generates a forwarding objective builder for bridging rules. |
| 177 | * <p> |
| 178 | * The forwarding objective bridges packets destined to a given MAC to |
| 179 | * given port on given device. |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 180 | * |
| 181 | * @param deviceId Device that host attaches to |
| 182 | * @param mac MAC address of the host |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 183 | * @param hostVlanId VLAN ID of the host |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 184 | * @param outport Port that host attaches to |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 185 | * @param revoke true if forwarding objective is meant to revoke forwarding rule |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 186 | * @return Forwarding objective builder |
| 187 | */ |
Charles Chan | 18fa425 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 188 | private ForwardingObjective.Builder bridgingFwdObjBuilder( |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 189 | DeviceId deviceId, MacAddress mac, VlanId hostVlanId, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 190 | PortNumber outport, boolean revoke) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 191 | ConnectPoint connectPoint = new ConnectPoint(deviceId, outport); |
| 192 | VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint); |
| 193 | Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint); |
| 194 | VlanId nativeVlan = srManager.getNativeVlanId(connectPoint); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 195 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 196 | // Create host selector |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 197 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 198 | sbuilder.matchEthDst(mac); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 199 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 200 | // Create host treatment |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 201 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 202 | tbuilder.immediate().setOutput(outport); |
| 203 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 204 | // Create host meta |
| 205 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
| 206 | |
| 207 | // Adjust the selector, treatment and meta according to VLAN configuration |
| 208 | if (taggedVlans.contains(hostVlanId)) { |
| 209 | sbuilder.matchVlanId(hostVlanId); |
| 210 | mbuilder.matchVlanId(hostVlanId); |
| 211 | } else if (hostVlanId.equals(VlanId.NONE)) { |
| 212 | if (untaggedVlan != null) { |
| 213 | sbuilder.matchVlanId(untaggedVlan); |
| 214 | mbuilder.matchVlanId(untaggedVlan); |
| 215 | tbuilder.immediate().popVlan(); |
| 216 | } else if (nativeVlan != null) { |
| 217 | sbuilder.matchVlanId(nativeVlan); |
| 218 | mbuilder.matchVlanId(nativeVlan); |
| 219 | tbuilder.immediate().popVlan(); |
| 220 | } else { |
Charles Chan | 184e024 | 2017-05-26 14:23:58 -0700 | [diff] [blame] | 221 | log.warn("Untagged host {}/{} is not allowed on {} without untagged or native" + |
| 222 | "vlan config", mac, hostVlanId, connectPoint); |
| 223 | return null; |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 224 | } |
| 225 | } else { |
| 226 | log.warn("Tagged host {}/{} is not allowed on {} without VLAN listed in tagged vlan", |
| 227 | mac, hostVlanId, connectPoint); |
| 228 | return null; |
| 229 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 230 | |
| 231 | // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed. |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 232 | // If the objective is to revoke an existing rule, and for some reason |
| 233 | // the next-objective does not exist, then a new one should not be created |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 234 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 235 | tbuilder.build(), mbuilder.build(), !revoke); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 236 | if (portNextObjId == -1) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 237 | // Warning log will come from getPortNextObjective method |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 238 | return null; |
| 239 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 240 | |
| 241 | return DefaultForwardingObjective.builder() |
| 242 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 243 | .withSelector(sbuilder.build()) |
| 244 | .nextStep(portNextObjId) |
| 245 | .withPriority(100) |
| 246 | .fromApp(srManager.appId) |
| 247 | .makePermanent(); |
| 248 | } |
| 249 | |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 250 | /** |
Charles Chan | 9595e6a | 2017-06-15 19:25:25 -0700 | [diff] [blame] | 251 | * Populate or revoke a bridging rule on given deviceId that matches given mac, given vlan and |
| 252 | * output to given port. |
| 253 | * |
| 254 | * @param deviceId device ID |
| 255 | * @param port port |
| 256 | * @param mac mac address |
| 257 | * @param vlanId VLAN ID |
| 258 | * @param revoke true to revoke the rule; false to populate |
| 259 | */ |
| 260 | private void processBridgingRule(DeviceId deviceId, PortNumber port, MacAddress mac, |
| 261 | VlanId vlanId, boolean revoke) { |
| 262 | log.debug("{} bridging entry for host {}/{} at {}:{}", revoke ? "Revoking" : "Populating", |
| 263 | mac, vlanId, deviceId, port); |
| 264 | |
| 265 | ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, revoke); |
| 266 | if (fob == null) { |
| 267 | log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | ObjectiveContext context = new DefaultObjectiveContext( |
| 272 | (objective) -> log.debug("Brigding rule for {}/{} {}", mac, vlanId, |
| 273 | revoke ? "revoked" : "populated"), |
| 274 | (objective, error) -> log.warn("Failed to {} bridging rule for {}/{}: {}", |
| 275 | revoke ? "revoked" : "populated", mac, vlanId, error)); |
| 276 | flowObjectiveService.forward(deviceId, revoke ? fob.remove(context) : fob.add(context)); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Populate or revoke a routing rule on given deviceId that matches given ip, |
| 281 | * set destination mac to given mac, set vlan to given vlan and output to given port. |
| 282 | * |
| 283 | * @param deviceId device ID |
| 284 | * @param port port |
| 285 | * @param mac mac address |
| 286 | * @param vlanId VLAN ID |
| 287 | * @param ip IP address |
| 288 | * @param revoke true to revoke the rule; false to populate |
| 289 | */ |
| 290 | private void processRoutingRule(DeviceId deviceId, PortNumber port, MacAddress mac, |
| 291 | VlanId vlanId, IpAddress ip, boolean revoke) { |
| 292 | ConnectPoint location = new ConnectPoint(deviceId, port); |
| 293 | if (srManager.deviceConfiguration.inSameSubnet(location, ip)) { |
| 294 | log.info("{} routing rule for {} at {}", revoke ? "Revoking" : "Populating", |
| 295 | ip, location); |
| 296 | if (revoke) { |
| 297 | srManager.routingRulePopulator.revokeRoute(deviceId, ip.toIpPrefix(), mac, vlanId, port); |
| 298 | } else { |
| 299 | srManager.routingRulePopulator.populateRoute(deviceId, ip.toIpPrefix(), mac, vlanId, port); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | /** |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 305 | * Determines whether a host should be accepted by SR or not. |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 306 | * |
| 307 | * @param host host to be checked |
| 308 | * @return true if segment routing accepts the host |
| 309 | */ |
| 310 | private boolean accepted(Host host) { |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 311 | SegmentRoutingAppConfig appConfig = srManager.cfgService |
| 312 | .getConfig(srManager.appId, SegmentRoutingAppConfig.class); |
Charles Chan | 3bf64b9 | 2016-05-20 10:55:40 -0700 | [diff] [blame] | 313 | |
| 314 | boolean accepted = appConfig == null || |
| 315 | (!appConfig.suppressHostByProvider().contains(host.providerId().id()) && |
| 316 | !appConfig.suppressHostByPort().contains(host.location())); |
Charles Chan | 370a65b | 2016-05-10 17:29:47 -0700 | [diff] [blame] | 317 | if (!accepted) { |
| 318 | log.info("Ignore suppressed host {}", host.id()); |
| 319 | } |
| 320 | return accepted; |
| 321 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 322 | } |