Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -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.dhcprelay; |
| 17 | |
| 18 | import java.nio.ByteBuffer; |
| 19 | import java.util.Collection; |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 20 | import java.util.Collections; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 21 | import java.util.Dictionary; |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 22 | import java.util.List; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | import java.util.Optional; |
| 25 | import java.util.Set; |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 26 | import java.util.concurrent.atomic.AtomicInteger; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 27 | import java.util.stream.Stream; |
| 28 | |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 29 | import org.apache.felix.scr.annotations.Activate; |
| 30 | import org.apache.felix.scr.annotations.Component; |
| 31 | import org.apache.felix.scr.annotations.Deactivate; |
| 32 | import org.apache.felix.scr.annotations.Modified; |
| 33 | import org.apache.felix.scr.annotations.Property; |
| 34 | import org.apache.felix.scr.annotations.Reference; |
| 35 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 36 | import org.apache.felix.scr.annotations.Service; |
| 37 | import org.onlab.packet.ARP; |
| 38 | import org.onlab.packet.DHCP; |
| 39 | import org.onlab.packet.DHCP6; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 40 | import org.onlab.packet.Ethernet; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 41 | import org.onlab.packet.IPacket; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 42 | import org.onlab.packet.IPv4; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 43 | import org.onlab.packet.IPv6; |
| 44 | import org.onlab.packet.Ip4Address; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 45 | import org.onlab.packet.MacAddress; |
| 46 | import org.onlab.packet.TpPort; |
| 47 | import org.onlab.packet.UDP; |
| 48 | import org.onlab.packet.VlanId; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 49 | import org.onlab.util.Tools; |
| 50 | import org.onosproject.cfg.ComponentConfigService; |
| 51 | import org.onosproject.core.ApplicationId; |
| 52 | import org.onosproject.core.CoreService; |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 53 | import org.onosproject.dhcprelay.api.DhcpHandler; |
| 54 | import org.onosproject.dhcprelay.api.DhcpRelayService; |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 55 | import org.onosproject.dhcprelay.config.DefaultDhcpRelayConfig; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 56 | import org.onosproject.dhcprelay.config.DhcpServerConfig; |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 57 | import org.onosproject.dhcprelay.config.IgnoreDhcpConfig; |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 58 | import org.onosproject.dhcprelay.config.IndirectDhcpRelayConfig; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 59 | import org.onosproject.dhcprelay.store.DhcpRecord; |
| 60 | import org.onosproject.dhcprelay.store.DhcpRelayStore; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 61 | import org.onosproject.net.ConnectPoint; |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 62 | import org.onosproject.net.Device; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 63 | import org.onosproject.net.DeviceId; |
| 64 | import org.onosproject.net.Host; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 65 | import org.onosproject.net.HostId; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 66 | import org.onosproject.net.config.Config; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 67 | import org.onosproject.net.config.ConfigFactory; |
| 68 | import org.onosproject.net.config.NetworkConfigEvent; |
| 69 | import org.onosproject.net.config.NetworkConfigListener; |
| 70 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 71 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 72 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 73 | import org.onosproject.net.flow.TrafficSelector; |
| 74 | import org.onosproject.net.flow.TrafficTreatment; |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 75 | import org.onosproject.net.behaviour.Pipeliner; |
| 76 | import org.onosproject.net.device.DeviceEvent; |
| 77 | import org.onosproject.net.device.DeviceListener; |
| 78 | import org.onosproject.net.device.DeviceService; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 79 | import org.onosproject.net.flow.criteria.Criterion; |
| 80 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
| 81 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 82 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 83 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 84 | import org.onosproject.net.flowobjective.Objective; |
| 85 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 86 | import org.onosproject.net.flowobjective.ObjectiveError; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 87 | import org.onosproject.net.host.HostService; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 88 | import org.onosproject.net.intf.Interface; |
| 89 | import org.onosproject.net.intf.InterfaceService; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 90 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 91 | import org.onosproject.net.packet.OutboundPacket; |
| 92 | import org.onosproject.net.packet.PacketContext; |
| 93 | import org.onosproject.net.packet.PacketPriority; |
| 94 | import org.onosproject.net.packet.PacketProcessor; |
| 95 | import org.onosproject.net.packet.PacketService; |
| 96 | import org.onosproject.net.provider.ProviderId; |
| 97 | import org.osgi.service.component.ComponentContext; |
| 98 | import org.slf4j.Logger; |
| 99 | import org.slf4j.LoggerFactory; |
| 100 | |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 101 | import com.google.common.collect.HashMultimap; |
| 102 | import com.google.common.collect.ImmutableList; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 103 | import com.google.common.collect.ImmutableSet; |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 104 | import com.google.common.collect.Multimap; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 105 | |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 106 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 107 | import static org.onosproject.net.flowobjective.Objective.Operation.ADD; |
| 108 | import static org.onosproject.net.flowobjective.Objective.Operation.REMOVE; |
| 109 | |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 110 | /** |
| 111 | * DHCP Relay Agent Application Component. |
| 112 | */ |
| 113 | @Component(immediate = true) |
| 114 | @Service |
| 115 | public class DhcpRelayManager implements DhcpRelayService { |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 116 | public static final String DHCP_RELAY_APP = "org.onosproject.dhcprelay"; |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 117 | public static final ProviderId PROVIDER_ID = new ProviderId("host", DHCP_RELAY_APP); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 118 | public static final String HOST_LOCATION_PROVIDER = |
| 119 | "org.onosproject.provider.host.impl.HostLocationProvider"; |
Yi Tseng | 325af8c | 2017-09-01 16:02:56 -0700 | [diff] [blame] | 120 | public static final String ROUTE_STORE_IMPL = |
| 121 | "org.onosproject.routeservice.store.RouteStoreImpl"; |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 122 | private static final TrafficSelector DHCP_SERVER_SELECTOR = DefaultTrafficSelector.builder() |
| 123 | .matchEthType(Ethernet.TYPE_IPV4) |
| 124 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
| 125 | .matchUdpDst(TpPort.tpPort(UDP.DHCP_SERVER_PORT)) |
| 126 | .build(); |
| 127 | private static final TrafficSelector DHCP_CLIENT_SELECTOR = DefaultTrafficSelector.builder() |
| 128 | .matchEthType(Ethernet.TYPE_IPV4) |
| 129 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
| 130 | .matchUdpDst(TpPort.tpPort(UDP.DHCP_CLIENT_PORT)) |
| 131 | .build(); |
| 132 | private static final TrafficSelector DHCP6_SERVER_SELECTOR = DefaultTrafficSelector.builder() |
| 133 | .matchEthType(Ethernet.TYPE_IPV6) |
| 134 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
| 135 | .matchUdpDst(TpPort.tpPort(UDP.DHCP_V6_SERVER_PORT)) |
| 136 | .build(); |
| 137 | private static final TrafficSelector DHCP6_CLIENT_SELECTOR = DefaultTrafficSelector.builder() |
| 138 | .matchEthType(Ethernet.TYPE_IPV6) |
| 139 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
| 140 | .matchUdpDst(TpPort.tpPort(UDP.DHCP_V6_CLIENT_PORT)) |
| 141 | .build(); |
| 142 | static final List<TrafficSelector> DHCP_SELECTORS = ImmutableList.of( |
| 143 | DHCP_SERVER_SELECTOR, |
| 144 | DHCP_CLIENT_SELECTOR, |
| 145 | DHCP6_SERVER_SELECTOR, |
| 146 | DHCP6_CLIENT_SELECTOR |
| 147 | ); |
| 148 | private static final TrafficSelector ARP_SELECTOR = DefaultTrafficSelector.builder() |
| 149 | .matchEthType(Ethernet.TYPE_ARP) |
| 150 | .build(); |
| 151 | private static final int IGNORE_CONTROL_PRIORITY = PacketPriority.CONTROL.priorityValue() + 1000; |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 152 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 153 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
| 154 | |
| 155 | private final Set<ConfigFactory> factories = ImmutableSet.of( |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 156 | new ConfigFactory<ApplicationId, DefaultDhcpRelayConfig>(APP_SUBJECT_FACTORY, |
| 157 | DefaultDhcpRelayConfig.class, |
| 158 | DefaultDhcpRelayConfig.KEY, |
| 159 | true) { |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 160 | @Override |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 161 | public DefaultDhcpRelayConfig createConfig() { |
| 162 | return new DefaultDhcpRelayConfig(); |
| 163 | } |
| 164 | }, |
| 165 | new ConfigFactory<ApplicationId, IndirectDhcpRelayConfig>(APP_SUBJECT_FACTORY, |
| 166 | IndirectDhcpRelayConfig.class, |
| 167 | IndirectDhcpRelayConfig.KEY, |
| 168 | true) { |
| 169 | @Override |
| 170 | public IndirectDhcpRelayConfig createConfig() { |
| 171 | return new IndirectDhcpRelayConfig(); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 172 | } |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 173 | }, |
| 174 | new ConfigFactory<ApplicationId, IgnoreDhcpConfig>(APP_SUBJECT_FACTORY, |
| 175 | IgnoreDhcpConfig.class, |
| 176 | IgnoreDhcpConfig.KEY, |
| 177 | true) { |
| 178 | @Override |
| 179 | public IgnoreDhcpConfig createConfig() { |
| 180 | return new IgnoreDhcpConfig(); |
| 181 | } |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 182 | } |
| 183 | ); |
| 184 | |
| 185 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 186 | protected NetworkConfigRegistry cfgService; |
| 187 | |
| 188 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 189 | protected CoreService coreService; |
| 190 | |
| 191 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 192 | protected PacketService packetService; |
| 193 | |
| 194 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 195 | protected HostService hostService; |
| 196 | |
| 197 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 198 | protected InterfaceService interfaceService; |
| 199 | |
| 200 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 201 | protected DhcpRelayStore dhcpRelayStore; |
| 202 | |
| 203 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 204 | protected ComponentConfigService compCfgService; |
| 205 | |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 206 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 207 | protected FlowObjectiveService flowObjectiveService; |
| 208 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 209 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 210 | protected DeviceService deviceService; |
| 211 | |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 212 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 213 | target = "(version=4)") |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 214 | protected DhcpHandler v4Handler; |
| 215 | |
| 216 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 217 | target = "(version=6)") |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 218 | protected DhcpHandler v6Handler; |
| 219 | |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 220 | @Property(name = "arpEnabled", boolValue = true, |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 221 | label = "Enable Address resolution protocol") |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 222 | protected boolean arpEnabled = true; |
| 223 | |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 224 | protected Multimap<DeviceId, VlanId> ignoredVlans = HashMultimap.create(); |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 225 | protected DeviceListener deviceListener = new InternalDeviceListener(); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 226 | private DhcpRelayPacketProcessor dhcpRelayPacketProcessor = new DhcpRelayPacketProcessor(); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 227 | private ApplicationId appId; |
| 228 | |
| 229 | @Activate |
| 230 | protected void activate(ComponentContext context) { |
| 231 | //start the dhcp relay agent |
| 232 | appId = coreService.registerApplication(DHCP_RELAY_APP); |
| 233 | |
| 234 | cfgService.addListener(cfgListener); |
| 235 | factories.forEach(cfgService::registerConfigFactory); |
| 236 | //update the dhcp server configuration. |
| 237 | updateConfig(); |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 238 | |
| 239 | //add the packet processor |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 240 | packetService.addProcessor(dhcpRelayPacketProcessor, PacketProcessor.director(0)); |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 241 | |
| 242 | // listen host event for dhcp server or the gateway |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 243 | requestDhcpPackets(); |
| 244 | modified(context); |
| 245 | |
| 246 | // disable dhcp from host location provider |
| 247 | compCfgService.preSetProperty(HOST_LOCATION_PROVIDER, |
| 248 | "useDhcp", Boolean.FALSE.toString()); |
Yi Tseng | 325af8c | 2017-09-01 16:02:56 -0700 | [diff] [blame] | 249 | // Enable distribute route store |
| 250 | compCfgService.preSetProperty(ROUTE_STORE_IMPL, |
| 251 | "distributed", Boolean.TRUE.toString()); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 252 | compCfgService.registerProperties(getClass()); |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 253 | |
| 254 | deviceService.addListener(deviceListener); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 255 | log.info("DHCP-RELAY Started"); |
| 256 | } |
| 257 | |
| 258 | @Deactivate |
| 259 | protected void deactivate() { |
| 260 | cfgService.removeListener(cfgListener); |
| 261 | factories.forEach(cfgService::unregisterConfigFactory); |
| 262 | packetService.removeProcessor(dhcpRelayPacketProcessor); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 263 | cancelDhcpPackets(); |
| 264 | cancelArpPackets(); |
Yi Tseng | dfa8ee2 | 2017-08-07 12:45:01 -0700 | [diff] [blame] | 265 | compCfgService.unregisterProperties(getClass(), false); |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 266 | deviceService.removeListener(deviceListener); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 267 | log.info("DHCP-RELAY Stopped"); |
| 268 | } |
| 269 | |
| 270 | @Modified |
| 271 | protected void modified(ComponentContext context) { |
| 272 | Dictionary<?, ?> properties = context.getProperties(); |
| 273 | Boolean flag; |
| 274 | |
| 275 | flag = Tools.isPropertyEnabled(properties, "arpEnabled"); |
| 276 | if (flag != null) { |
| 277 | arpEnabled = flag; |
| 278 | log.info("Address resolution protocol is {}", |
| 279 | arpEnabled ? "enabled" : "disabled"); |
| 280 | } |
| 281 | |
| 282 | if (arpEnabled) { |
| 283 | requestArpPackets(); |
| 284 | } else { |
| 285 | cancelArpPackets(); |
| 286 | } |
| 287 | } |
| 288 | |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 289 | /** |
| 290 | * Updates DHCP relay app configuration. |
| 291 | */ |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 292 | private void updateConfig() { |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 293 | DefaultDhcpRelayConfig defaultConfig = |
| 294 | cfgService.getConfig(appId, DefaultDhcpRelayConfig.class); |
| 295 | IndirectDhcpRelayConfig indirectConfig = |
| 296 | cfgService.getConfig(appId, IndirectDhcpRelayConfig.class); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 297 | IgnoreDhcpConfig ignoreDhcpConfig = |
| 298 | cfgService.getConfig(appId, IgnoreDhcpConfig.class); |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 299 | |
| 300 | if (defaultConfig != null) { |
| 301 | updateConfig(defaultConfig); |
| 302 | } |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 303 | if (indirectConfig != null) { |
| 304 | updateConfig(indirectConfig); |
| 305 | } |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 306 | if (ignoreDhcpConfig != null) { |
| 307 | updateConfig(ignoreDhcpConfig); |
| 308 | } |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Updates DHCP relay app configuration with given configuration. |
| 313 | * |
| 314 | * @param config the configuration ot update |
| 315 | */ |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 316 | protected void updateConfig(Config config) { |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 317 | if (config instanceof IndirectDhcpRelayConfig) { |
| 318 | IndirectDhcpRelayConfig indirectConfig = (IndirectDhcpRelayConfig) config; |
| 319 | v4Handler.setIndirectDhcpServerConfigs(indirectConfig.dhcpServerConfigs()); |
| 320 | v6Handler.setIndirectDhcpServerConfigs(indirectConfig.dhcpServerConfigs()); |
Yi Tseng | 4fa0583 | 2017-08-17 13:08:31 -0700 | [diff] [blame] | 321 | } else if (config instanceof DefaultDhcpRelayConfig) { |
| 322 | DefaultDhcpRelayConfig defaultConfig = (DefaultDhcpRelayConfig) config; |
| 323 | v4Handler.setDefaultDhcpServerConfigs(defaultConfig.dhcpServerConfigs()); |
| 324 | v6Handler.setDefaultDhcpServerConfigs(defaultConfig.dhcpServerConfigs()); |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 325 | } |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 326 | if (config instanceof IgnoreDhcpConfig) { |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 327 | updateIgnoreVlanRules((IgnoreDhcpConfig) config); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
| 331 | protected void removeConfig(Config config) { |
| 332 | if (config instanceof IndirectDhcpRelayConfig) { |
| 333 | v4Handler.setIndirectDhcpServerConfigs(Collections.emptyList()); |
| 334 | v6Handler.setIndirectDhcpServerConfigs(Collections.emptyList()); |
| 335 | } else if (config instanceof DefaultDhcpRelayConfig) { |
| 336 | v4Handler.setDefaultDhcpServerConfigs(Collections.emptyList()); |
| 337 | v6Handler.setDefaultDhcpServerConfigs(Collections.emptyList()); |
| 338 | } |
| 339 | if (config instanceof IgnoreDhcpConfig) { |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 340 | ignoredVlans.forEach(((deviceId, vlanId) -> { |
| 341 | processIgnoreVlanRule(deviceId, vlanId, REMOVE); |
| 342 | })); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 346 | private void updateIgnoreVlanRules(IgnoreDhcpConfig config) { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 347 | config.ignoredVlans().forEach((deviceId, vlanId) -> { |
| 348 | if (ignoredVlans.get(deviceId).contains(vlanId)) { |
| 349 | // don't need to process if it already ignored |
| 350 | return; |
| 351 | } |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 352 | processIgnoreVlanRule(deviceId, vlanId, ADD); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 353 | }); |
| 354 | |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 355 | ignoredVlans.forEach((deviceId, vlanId) -> { |
| 356 | if (!config.ignoredVlans().get(deviceId).contains(vlanId)) { |
| 357 | // not contains in new config, remove it |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 358 | processIgnoreVlanRule(deviceId, vlanId, REMOVE); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 359 | } |
| 360 | }); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 363 | /** |
| 364 | * Process the ignore rules. |
| 365 | * |
| 366 | * @param deviceId the device id |
| 367 | * @param vlanId the vlan to be ignored |
| 368 | * @param op the operation, ADD to install; REMOVE to uninstall rules |
| 369 | */ |
| 370 | private void processIgnoreVlanRule(DeviceId deviceId, VlanId vlanId, Objective.Operation op) { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 371 | TrafficTreatment dropTreatment = DefaultTrafficTreatment.emptyTreatment(); |
| 372 | dropTreatment.clearedDeferred(); |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 373 | AtomicInteger installedCount = new AtomicInteger(DHCP_SELECTORS.size()); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 374 | DHCP_SELECTORS.forEach(trafficSelector -> { |
| 375 | UdpPortCriterion udpDst = (UdpPortCriterion) trafficSelector.getCriterion(Criterion.Type.UDP_DST); |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 376 | int udpDstPort = udpDst.udpPort().toInt(); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 377 | TrafficSelector selector = DefaultTrafficSelector.builder(trafficSelector) |
| 378 | .matchVlanId(vlanId) |
| 379 | .build(); |
| 380 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 381 | ForwardingObjective.Builder builder = DefaultForwardingObjective.builder() |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 382 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 383 | .withSelector(selector) |
| 384 | .withPriority(IGNORE_CONTROL_PRIORITY) |
| 385 | .withTreatment(dropTreatment) |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 386 | .fromApp(appId); |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 387 | |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 388 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 389 | ObjectiveContext objectiveContext = new ObjectiveContext() { |
| 390 | @Override |
| 391 | public void onSuccess(Objective objective) { |
| 392 | log.info("Ignore rule {} (Vlan id {}, device {}, UDP dst {})", |
| 393 | op, vlanId, deviceId, udpDstPort); |
| 394 | int countDown = installedCount.decrementAndGet(); |
| 395 | if (countDown != 0) { |
| 396 | return; |
| 397 | } |
| 398 | switch (op) { |
| 399 | case ADD: |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 400 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 401 | ignoredVlans.put(deviceId, vlanId); |
| 402 | break; |
| 403 | case REMOVE: |
| 404 | ignoredVlans.remove(deviceId, vlanId); |
| 405 | break; |
| 406 | default: |
| 407 | log.warn("Unsupported objective operation {}", op); |
| 408 | break; |
| 409 | } |
| 410 | } |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 411 | |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 412 | @Override |
| 413 | public void onError(Objective objective, ObjectiveError error) { |
| 414 | log.warn("Can't {} ignore rule (vlan id {}, udp dst {}, device {}) due to {}", |
| 415 | op, vlanId, udpDstPort, deviceId, error); |
| 416 | } |
| 417 | }; |
| 418 | |
| 419 | ForwardingObjective fwd; |
| 420 | switch (op) { |
| 421 | case ADD: |
| 422 | fwd = builder.add(objectiveContext); |
| 423 | break; |
| 424 | case REMOVE: |
| 425 | fwd = builder.remove(objectiveContext); |
| 426 | break; |
| 427 | default: |
| 428 | log.warn("Unsupported objective operation {}", op); |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | Device device = deviceService.getDevice(deviceId); |
| 433 | if (device == null || !device.is(Pipeliner.class)) { |
| 434 | log.warn("Device {} is not available now, wait until device is available", deviceId); |
| 435 | return; |
| 436 | } |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 437 | flowObjectiveService.apply(deviceId, fwd); |
| 438 | }); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Request DHCP packet in via PacketService. |
| 443 | */ |
| 444 | private void requestDhcpPackets() { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 445 | DHCP_SELECTORS.forEach(trafficSelector -> { |
| 446 | packetService.requestPackets(trafficSelector, PacketPriority.CONTROL, appId); |
| 447 | }); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Cancel requested DHCP packets in via packet service. |
| 452 | */ |
| 453 | private void cancelDhcpPackets() { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 454 | DHCP_SELECTORS.forEach(trafficSelector -> { |
| 455 | packetService.cancelPackets(trafficSelector, PacketPriority.CONTROL, appId); |
| 456 | }); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Request ARP packet in via PacketService. |
| 461 | */ |
| 462 | private void requestArpPackets() { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 463 | packetService.requestPackets(ARP_SELECTOR, PacketPriority.CONTROL, appId); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Cancel requested ARP packets in via packet service. |
| 468 | */ |
| 469 | private void cancelArpPackets() { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 470 | packetService.cancelPackets(ARP_SELECTOR, PacketPriority.CONTROL, appId); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public Optional<DhcpRecord> getDhcpRecord(HostId hostId) { |
| 475 | return dhcpRelayStore.getDhcpRecord(hostId); |
| 476 | } |
| 477 | |
| 478 | @Override |
| 479 | public Collection<DhcpRecord> getDhcpRecords() { |
| 480 | return dhcpRelayStore.getDhcpRecords(); |
| 481 | } |
| 482 | |
Yi Tseng | 13a41a1 | 2017-07-26 13:45:01 -0700 | [diff] [blame] | 483 | @Override |
| 484 | public Optional<MacAddress> getDhcpServerMacAddress() { |
Yi Tseng | 4ec727d | 2017-08-31 11:21:00 -0700 | [diff] [blame] | 485 | // TODO: depreated it |
| 486 | DefaultDhcpRelayConfig config = cfgService.getConfig(appId, DefaultDhcpRelayConfig.class); |
| 487 | DhcpServerConfig serverConfig = config.dhcpServerConfigs().get(0); |
| 488 | Ip4Address serverip = serverConfig.getDhcpServerIp4().get(); |
| 489 | return hostService.getHostsByIp(serverip) |
| 490 | .stream() |
| 491 | .map(Host::mac) |
| 492 | .findFirst(); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Gets DHCP data from a packet. |
| 497 | * |
| 498 | * @param packet the packet |
| 499 | * @return the DHCP data; empty if it is not a DHCP packet |
| 500 | */ |
| 501 | private Optional<DHCP> findDhcp(Ethernet packet) { |
| 502 | return Stream.of(packet) |
| 503 | .filter(Objects::nonNull) |
| 504 | .map(Ethernet::getPayload) |
| 505 | .filter(p -> p instanceof IPv4) |
| 506 | .map(IPacket::getPayload) |
| 507 | .filter(Objects::nonNull) |
| 508 | .filter(p -> p instanceof UDP) |
| 509 | .map(IPacket::getPayload) |
| 510 | .filter(Objects::nonNull) |
| 511 | .filter(p -> p instanceof DHCP) |
| 512 | .map(p -> (DHCP) p) |
| 513 | .findFirst(); |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Gets DHCPv6 data from a packet. |
| 518 | * |
| 519 | * @param packet the packet |
| 520 | * @return the DHCPv6 data; empty if it is not a DHCPv6 packet |
| 521 | */ |
| 522 | private Optional<DHCP6> findDhcp6(Ethernet packet) { |
| 523 | return Stream.of(packet) |
| 524 | .filter(Objects::nonNull) |
| 525 | .map(Ethernet::getPayload) |
| 526 | .filter(p -> p instanceof IPv6) |
| 527 | .map(IPacket::getPayload) |
| 528 | .filter(Objects::nonNull) |
| 529 | .filter(p -> p instanceof UDP) |
| 530 | .map(IPacket::getPayload) |
| 531 | .filter(Objects::nonNull) |
| 532 | .filter(p -> p instanceof DHCP6) |
| 533 | .map(p -> (DHCP6) p) |
| 534 | .findFirst(); |
| 535 | } |
| 536 | |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 537 | |
| 538 | private class DhcpRelayPacketProcessor implements PacketProcessor { |
| 539 | |
| 540 | @Override |
| 541 | public void process(PacketContext context) { |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 542 | // process the packet and get the payload |
| 543 | Ethernet packet = context.inPacket().parsed(); |
| 544 | if (packet == null) { |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | findDhcp(packet).ifPresent(dhcpPayload -> { |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 549 | v4Handler.processDhcpPacket(context, dhcpPayload); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 550 | }); |
| 551 | |
| 552 | findDhcp6(packet).ifPresent(dhcp6Payload -> { |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 553 | v6Handler.processDhcpPacket(context, dhcp6Payload); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 554 | }); |
| 555 | |
| 556 | if (packet.getEtherType() == Ethernet.TYPE_ARP && arpEnabled) { |
| 557 | ARP arpPacket = (ARP) packet.getPayload(); |
| 558 | VlanId vlanId = VlanId.vlanId(packet.getVlanID()); |
| 559 | Set<Interface> interfaces = interfaceService. |
| 560 | getInterfacesByPort(context.inPacket().receivedFrom()); |
| 561 | //ignore the packets if dhcp server interface is not configured on onos. |
| 562 | if (interfaces.isEmpty()) { |
| 563 | log.warn("server virtual interface not configured"); |
| 564 | return; |
| 565 | } |
| 566 | if ((arpPacket.getOpCode() != ARP.OP_REQUEST)) { |
| 567 | // handle request only |
| 568 | return; |
| 569 | } |
| 570 | MacAddress interfaceMac = interfaces.stream() |
| 571 | .filter(iface -> iface.vlan().equals(vlanId)) |
| 572 | .map(Interface::mac) |
| 573 | .filter(mac -> !mac.equals(MacAddress.NONE)) |
| 574 | .findFirst() |
Yi Tseng | 5130129 | 2017-07-28 13:02:59 -0700 | [diff] [blame] | 575 | .orElse(MacAddress.ONOS); |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 576 | if (interfaceMac == null) { |
| 577 | // can't find interface mac address |
| 578 | return; |
| 579 | } |
| 580 | processArpPacket(context, packet, interfaceMac); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Processes the ARP Payload and initiates a reply to the client. |
| 586 | * |
| 587 | * @param context the packet context |
| 588 | * @param packet the ethernet payload |
| 589 | * @param replyMac mac address to be replied |
| 590 | */ |
| 591 | private void processArpPacket(PacketContext context, Ethernet packet, MacAddress replyMac) { |
| 592 | ARP arpPacket = (ARP) packet.getPayload(); |
| 593 | ARP arpReply = (ARP) arpPacket.clone(); |
| 594 | arpReply.setOpCode(ARP.OP_REPLY); |
| 595 | |
| 596 | arpReply.setTargetProtocolAddress(arpPacket.getSenderProtocolAddress()); |
| 597 | arpReply.setTargetHardwareAddress(arpPacket.getSenderHardwareAddress()); |
| 598 | arpReply.setSenderProtocolAddress(arpPacket.getTargetProtocolAddress()); |
| 599 | arpReply.setSenderHardwareAddress(replyMac.toBytes()); |
| 600 | |
| 601 | // Ethernet Frame. |
| 602 | Ethernet ethReply = new Ethernet(); |
| 603 | ethReply.setSourceMACAddress(replyMac.toBytes()); |
| 604 | ethReply.setDestinationMACAddress(packet.getSourceMAC()); |
| 605 | ethReply.setEtherType(Ethernet.TYPE_ARP); |
| 606 | ethReply.setVlanID(packet.getVlanID()); |
| 607 | ethReply.setPayload(arpReply); |
| 608 | |
| 609 | ConnectPoint targetPort = context.inPacket().receivedFrom(); |
| 610 | TrafficTreatment t = DefaultTrafficTreatment.builder() |
| 611 | .setOutput(targetPort.port()).build(); |
| 612 | OutboundPacket o = new DefaultOutboundPacket( |
| 613 | targetPort.deviceId(), t, ByteBuffer.wrap(ethReply.serialize())); |
| 614 | if (log.isTraceEnabled()) { |
| 615 | log.trace("Relaying ARP packet {} to {}", packet, targetPort); |
| 616 | } |
| 617 | packetService.emit(o); |
| 618 | } |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Listener for network config events. |
| 623 | */ |
| 624 | private class InternalConfigListener implements NetworkConfigListener { |
| 625 | @Override |
| 626 | public void event(NetworkConfigEvent event) { |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 627 | switch (event.type()) { |
| 628 | case CONFIG_UPDATED: |
| 629 | case CONFIG_ADDED: |
| 630 | event.config().ifPresent(config -> { |
| 631 | updateConfig(config); |
| 632 | log.info("{} updated", config.getClass().getSimpleName()); |
| 633 | }); |
| 634 | break; |
| 635 | case CONFIG_REMOVED: |
| 636 | event.prevConfig().ifPresent(config -> { |
| 637 | removeConfig(config); |
| 638 | log.info("{} removed", config.getClass().getSimpleName()); |
| 639 | }); |
| 640 | break; |
| 641 | default: |
| 642 | log.warn("Unsupported event type {}", event.type()); |
| 643 | break; |
Yi Tseng | e72fbb5 | 2017-08-02 15:03:31 -0700 | [diff] [blame] | 644 | } |
Yi Tseng | 5479fb8 | 2017-09-01 17:24:57 -0700 | [diff] [blame] | 645 | |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
Yi Tseng | 76365d8 | 2017-09-12 15:55:17 -0700 | [diff] [blame^] | 648 | |
| 649 | private class InternalDeviceListener implements DeviceListener { |
| 650 | |
| 651 | @Override |
| 652 | public void event(DeviceEvent event) { |
| 653 | Device device = event.subject(); |
| 654 | switch (event.type()) { |
| 655 | case DEVICE_ADDED: |
| 656 | deviceAdd(device.id()); |
| 657 | break; |
| 658 | case DEVICE_REMOVED: |
| 659 | ignoredVlans.removeAll(device.id()); |
| 660 | break; |
| 661 | case DEVICE_AVAILABILITY_CHANGED: |
| 662 | deviceAvailabilityChanged(device); |
| 663 | |
| 664 | default: |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | private void deviceAvailabilityChanged(Device device) { |
| 670 | if (deviceService.isAvailable(device.id())) { |
| 671 | deviceAdd(device.id()); |
| 672 | } else { |
| 673 | ignoredVlans.removeAll(device.id()); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | private void deviceAdd(DeviceId deviceId) { |
| 678 | IgnoreDhcpConfig config = cfgService.getConfig(appId, IgnoreDhcpConfig.class); |
| 679 | Collection<VlanId> vlanIds = config.ignoredVlans().get(deviceId); |
| 680 | vlanIds.forEach(vlanId -> { |
| 681 | processIgnoreVlanRule(deviceId, vlanId, ADD); |
| 682 | }); |
| 683 | } |
| 684 | } |
Yi Tseng | 7a38f9a | 2017-06-09 14:36:40 -0700 | [diff] [blame] | 685 | } |