Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host.impl; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 17 | |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 18 | import org.onlab.packet.Ip6Address; |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.VlanId; |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 22 | import org.onlab.util.Tools; |
| 23 | import org.onosproject.cfg.ComponentConfigService; |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.Host; |
| 27 | import org.onosproject.net.HostId; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 28 | import org.onosproject.net.HostLocation; |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 29 | import org.onosproject.net.config.Config; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | import org.onosproject.net.config.NetworkConfigEvent; |
| 31 | import org.onosproject.net.config.NetworkConfigListener; |
| 32 | import org.onosproject.net.config.NetworkConfigService; |
| 33 | import org.onosproject.net.config.basics.BasicHostConfig; |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 34 | import org.onosproject.net.config.basics.HostAnnotationConfig; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 36 | import org.onosproject.net.edge.EdgePortService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import org.onosproject.net.host.HostAdminService; |
| 38 | import org.onosproject.net.host.HostDescription; |
| 39 | import org.onosproject.net.host.HostEvent; |
| 40 | import org.onosproject.net.host.HostListener; |
| 41 | import org.onosproject.net.host.HostProvider; |
| 42 | import org.onosproject.net.host.HostProviderRegistry; |
| 43 | import org.onosproject.net.host.HostProviderService; |
| 44 | import org.onosproject.net.host.HostService; |
| 45 | import org.onosproject.net.host.HostStore; |
| 46 | import org.onosproject.net.host.HostStoreDelegate; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 47 | import org.onosproject.net.intf.Interface; |
| 48 | import org.onosproject.net.intf.InterfaceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 49 | import org.onosproject.net.packet.PacketService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 50 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 51 | import org.onosproject.net.provider.AbstractProviderService; |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 52 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 53 | import org.osgi.service.component.annotations.Activate; |
| 54 | import org.osgi.service.component.annotations.Component; |
| 55 | import org.osgi.service.component.annotations.Deactivate; |
| 56 | import org.osgi.service.component.annotations.Modified; |
| 57 | import org.osgi.service.component.annotations.Reference; |
| 58 | import org.osgi.service.component.annotations.ReferenceCardinality; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 59 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 60 | |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 61 | import java.util.Dictionary; |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 62 | import java.util.Optional; |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 63 | import java.util.Set; |
| 64 | |
| 65 | import static com.google.common.base.Preconditions.checkNotNull; |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 66 | import static com.google.common.base.Preconditions.checkState; |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 67 | import static org.onlab.packet.IPv6.getLinkLocalAddress; |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 68 | import static org.onosproject.net.OsgiPropertyConstants.HM_ALLOW_DUPLICATE_IPS; |
| 69 | import static org.onosproject.net.OsgiPropertyConstants.HM_ALLOW_DUPLICATE_IPS_DEFAULT; |
| 70 | import static org.onosproject.net.OsgiPropertyConstants.HM_GREEDY_LEARNING_IPV6; |
| 71 | import static org.onosproject.net.OsgiPropertyConstants.HM_GREEDY_LEARNING_IPV6_DEFAULT; |
| 72 | import static org.onosproject.net.OsgiPropertyConstants.HM_MONITOR_HOSTS; |
| 73 | import static org.onosproject.net.OsgiPropertyConstants.HM_MONITOR_HOSTS_DEFAULT; |
| 74 | import static org.onosproject.net.OsgiPropertyConstants.HM_PROBE_RATE; |
| 75 | import static org.onosproject.net.OsgiPropertyConstants.HM_PROBE_RATE_DEFAULT; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame] | 76 | import static org.onosproject.security.AppGuard.checkPermission; |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 77 | import static org.onosproject.security.AppPermission.Type.HOST_EVENT; |
| 78 | import static org.onosproject.security.AppPermission.Type.HOST_READ; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 79 | import static org.slf4j.LoggerFactory.getLogger; |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 80 | |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Provides basic implementation of the host SB & NB APIs. |
| 83 | */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 84 | @Component( |
| 85 | immediate = true, |
| 86 | service = { |
| 87 | HostService.class, |
| 88 | HostAdminService.class, |
| 89 | HostProviderRegistry.class |
| 90 | }, |
| 91 | property = { |
Ray Milkey | 2d7bca1 | 2018-10-17 14:51:52 -0700 | [diff] [blame] | 92 | HM_ALLOW_DUPLICATE_IPS + ":Boolean=" + HM_ALLOW_DUPLICATE_IPS_DEFAULT, |
| 93 | HM_MONITOR_HOSTS + ":Boolean=" + HM_MONITOR_HOSTS_DEFAULT, |
| 94 | HM_PROBE_RATE + ":Integer=" + HM_PROBE_RATE_DEFAULT, |
| 95 | HM_GREEDY_LEARNING_IPV6 + ":Boolean=" + HM_GREEDY_LEARNING_IPV6_DEFAULT |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 96 | } |
| 97 | ) |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 98 | public class HostManager |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 99 | extends AbstractListenerProviderRegistry<HostEvent, HostListener, HostProvider, HostProviderService> |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 100 | implements HostService, HostAdminService, HostProviderRegistry { |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 101 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 102 | private final Logger log = getLogger(getClass()); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 103 | |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 104 | public static final String HOST_ID_NULL = "Host ID cannot be null"; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 105 | |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 106 | private final NetworkConfigListener networkConfigListener = new InternalNetworkConfigListener(); |
| 107 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 108 | private HostStoreDelegate delegate = new InternalStoreDelegate(); |
| 109 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
tom | 5bcc946 | 2014-09-19 10:11:31 -0700 | [diff] [blame] | 111 | protected HostStore store; |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 112 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 114 | protected DeviceService deviceService; |
| 115 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 117 | protected PacketService packetService; |
| 118 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 120 | protected NetworkConfigService networkConfigService; |
| 121 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 123 | protected InterfaceService interfaceService; |
| 124 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 126 | protected EdgePortService edgePortService; |
| 127 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 129 | protected ComponentConfigService cfgService; |
| 130 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 131 | /** Enable removal of duplicate ip address. */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 132 | private boolean allowDuplicateIps = HM_ALLOW_DUPLICATE_IPS_DEFAULT; |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 133 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 134 | /** Enable/Disable monitoring of hosts. */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 135 | private boolean monitorHosts = HM_MONITOR_HOSTS_DEFAULT; |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 136 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 137 | /** Set the probe Rate in milli seconds. */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 138 | private long probeRate = HM_PROBE_RATE_DEFAULT; |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 139 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 140 | /** Enable/Disable greedy learning of IPv6 link local address. */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 141 | private boolean greedyLearningIpv6 = HM_GREEDY_LEARNING_IPV6_DEFAULT; |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 142 | |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 143 | private HostMonitor monitor; |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 144 | private HostAnnotationOperator hostAnnotationOperator; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 145 | |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 146 | |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 147 | @Activate |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 148 | public void activate(ComponentContext context) { |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 149 | hostAnnotationOperator = new HostAnnotationOperator(networkConfigService); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 150 | store.setDelegate(delegate); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 151 | eventDispatcher.addSink(HostEvent.class, listenerRegistry); |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 152 | cfgService.registerProperties(getClass()); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 153 | networkConfigService.addListener(networkConfigListener); |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 154 | monitor = new HostMonitor(packetService, this, interfaceService, edgePortService); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 155 | monitor.setProbeRate(probeRate); |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 156 | monitor.start(); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 157 | modified(context); |
| 158 | cfgService.registerProperties(getClass()); |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 159 | log.info("Started"); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 160 | } |
| 161 | |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 162 | @Deactivate |
| 163 | public void deactivate() { |
| 164 | store.unsetDelegate(delegate); |
| 165 | eventDispatcher.removeSink(HostEvent.class); |
| 166 | networkConfigService.removeListener(networkConfigListener); |
| 167 | cfgService.unregisterProperties(getClass(), false); |
| 168 | monitor.shutdown(); |
| 169 | log.info("Stopped"); |
| 170 | } |
| 171 | |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 172 | @Modified |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 173 | public void modified(ComponentContext context) { |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 174 | boolean oldValue = monitorHosts; |
| 175 | readComponentConfiguration(context); |
| 176 | if (probeRate > 0) { |
| 177 | monitor.setProbeRate(probeRate); |
| 178 | } else { |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 179 | log.warn("ProbeRate cannot be less than 0"); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | if (oldValue != monitorHosts) { |
| 183 | if (monitorHosts) { |
| 184 | startMonitoring(); |
| 185 | } else { |
| 186 | stopMonitoring(); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Extracts properties from the component configuration context. |
| 193 | * |
| 194 | * @param context the component context |
| 195 | */ |
| 196 | private void readComponentConfiguration(ComponentContext context) { |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 197 | Dictionary<?, ?> properties = context.getProperties(); |
| 198 | Boolean flag; |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 199 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 200 | flag = Tools.isPropertyEnabled(properties, HM_MONITOR_HOSTS); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 201 | if (flag == null) { |
| 202 | log.info("monitorHosts is not enabled " + |
| 203 | "using current value of {}", monitorHosts); |
| 204 | } else { |
| 205 | monitorHosts = flag; |
| 206 | log.info("Configured. monitorHosts {}", |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 207 | monitorHosts ? "enabled" : "disabled"); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 210 | Long longValue = Tools.getLongProperty(properties, HM_PROBE_RATE); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 211 | if (longValue == null || longValue == 0) { |
| 212 | log.info("probeRate is not set sing default value of {}", probeRate); |
| 213 | } else { |
| 214 | probeRate = longValue; |
| 215 | log.info("Configured. probeRate {}", probeRate); |
| 216 | } |
| 217 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 218 | flag = Tools.isPropertyEnabled(properties, HM_ALLOW_DUPLICATE_IPS); |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 219 | if (flag == null) { |
| 220 | log.info("Removal of duplicate ip address is not configured"); |
| 221 | } else { |
| 222 | allowDuplicateIps = flag; |
| 223 | log.info("Removal of duplicate ip address is {}", |
| 224 | allowDuplicateIps ? "disabled" : "enabled"); |
| 225 | } |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 226 | |
Thomas Vachuska | f566fa2 | 2018-10-30 14:03:36 -0700 | [diff] [blame] | 227 | flag = Tools.isPropertyEnabled(properties, HM_GREEDY_LEARNING_IPV6); |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 228 | if (flag == null) { |
| 229 | log.info("greedy learning is not enabled " + |
| 230 | "using current value of {}", greedyLearningIpv6); |
| 231 | } else { |
| 232 | greedyLearningIpv6 = flag; |
| 233 | log.info("Configured. greedyLearningIpv6 {}", |
| 234 | greedyLearningIpv6 ? "enabled" : "disabled"); |
| 235 | } |
| 236 | |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 237 | } |
| 238 | |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 239 | /** |
| 240 | * Starts monitoring the hosts by IP Address. |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 241 | */ |
| 242 | private void startMonitoring() { |
| 243 | store.getHosts().forEach(host -> { |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 244 | host.ipAddresses().forEach(ip -> { |
| 245 | monitor.addMonitoringFor(ip); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 246 | }); |
| 247 | }); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Stops monitoring the hosts by IP Address. |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 252 | */ |
| 253 | private void stopMonitoring() { |
| 254 | store.getHosts().forEach(host -> { |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 255 | host.ipAddresses().forEach(ip -> { |
| 256 | monitor.stopMonitoring(ip); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 257 | }); |
| 258 | }); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Override |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 262 | protected HostProviderService createProviderService(HostProvider provider) { |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 263 | monitor.registerHostProvider(provider); |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 264 | return new InternalHostProviderService(provider); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 265 | } |
| 266 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 267 | @Override |
| 268 | public int getHostCount() { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 269 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 270 | return store.getHostCount(); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public Iterable<Host> getHosts() { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 275 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 276 | return store.getHosts(); |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public Host getHost(HostId hostId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 281 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 282 | checkNotNull(hostId, HOST_ID_NULL); |
| 283 | return store.getHost(hostId); |
| 284 | } |
| 285 | |
| 286 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 287 | public Set<Host> getHostsByVlan(VlanId vlanId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 288 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 289 | return store.getHosts(vlanId); |
| 290 | } |
| 291 | |
| 292 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 293 | public Set<Host> getHostsByMac(MacAddress mac) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 294 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 295 | checkNotNull(mac, "MAC address cannot be null"); |
| 296 | return store.getHosts(mac); |
| 297 | } |
| 298 | |
| 299 | @Override |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 300 | public Set<Host> getHostsByIp(IpAddress ip) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 301 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 302 | checkNotNull(ip, "IP address cannot be null"); |
| 303 | return store.getHosts(ip); |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 308 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 309 | checkNotNull(connectPoint, "Connection point cannot be null"); |
| 310 | return store.getConnectedHosts(connectPoint); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public Set<Host> getConnectedHosts(DeviceId deviceId) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 315 | checkPermission(HOST_READ); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 316 | checkNotNull(deviceId, "Device ID cannot be null"); |
| 317 | return store.getConnectedHosts(deviceId); |
| 318 | } |
| 319 | |
| 320 | @Override |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 321 | public void startMonitoringIp(IpAddress ip) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 322 | checkPermission(HOST_EVENT); |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 323 | monitor.addMonitoringFor(ip); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | @Override |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 327 | public void stopMonitoringIp(IpAddress ip) { |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 328 | checkPermission(HOST_EVENT); |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 329 | monitor.stopMonitoring(ip); |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public void requestMac(IpAddress ip) { |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 334 | // FIXME!!!! Auto-generated method stub |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 335 | } |
| 336 | |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 337 | @Override |
| 338 | public void removeHost(HostId hostId) { |
| 339 | checkNotNull(hostId, HOST_ID_NULL); |
Charles Chan | 009c308 | 2015-11-10 14:18:04 -0800 | [diff] [blame] | 340 | store.removeHost(hostId); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 341 | } |
| 342 | |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 343 | // Personalized host provider service issued to the supplied provider. |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 344 | private class InternalHostProviderService |
| 345 | extends AbstractProviderService<HostProvider> |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 346 | implements HostProviderService { |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 347 | InternalHostProviderService(HostProvider provider) { |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 348 | super(provider); |
| 349 | } |
| 350 | |
| 351 | @Override |
Ray Milkey | 718e438 | 2018-12-05 09:08:01 -0800 | [diff] [blame] | 352 | public void hostDetected(HostId hostId, HostDescription initialHostDescription, boolean replaceIps) { |
| 353 | HostDescription hostDescription = initialHostDescription; |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 354 | checkNotNull(hostId, HOST_ID_NULL); |
| 355 | checkValidity(); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 356 | hostDescription = validateHost(hostDescription, hostId); |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 357 | |
| 358 | if (!allowDuplicateIps) { |
| 359 | removeDuplicates(hostId, hostDescription); |
| 360 | } |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 361 | |
| 362 | BasicHostConfig cfg = networkConfigService.getConfig(hostId, BasicHostConfig.class); |
| 363 | if (!isAllowed(cfg)) { |
| 364 | log.warn("Host {} is not allowed to be added into the contol domain", hostId); |
| 365 | return; |
| 366 | } |
| 367 | |
Ray Milkey | 718e438 | 2018-12-05 09:08:01 -0800 | [diff] [blame] | 368 | hostDescription = BasicHostOperator.combine(cfg, initialHostDescription); |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 369 | HostAnnotationConfig annoConfig = networkConfigService.getConfig(hostId, HostAnnotationConfig.class); |
| 370 | if (annoConfig != null) { |
| 371 | hostDescription = hostAnnotationOperator.combine(hostId, hostDescription, Optional.of(annoConfig)); |
| 372 | } |
| 373 | |
Charles Chan | 009c308 | 2015-11-10 14:18:04 -0800 | [diff] [blame] | 374 | store.createOrUpdateHost(provider().id(), hostId, |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 375 | hostDescription, replaceIps); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 376 | |
| 377 | if (monitorHosts) { |
| 378 | hostDescription.ipAddress().forEach(ip -> { |
| 379 | monitor.addMonitoringFor(ip); |
| 380 | }); |
| 381 | } |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 382 | |
| 383 | // Greedy learning of IPv6 host. We have to disable the greedy |
| 384 | // learning of configured hosts. Validate hosts each time will |
Charles Chan | 82fac58 | 2017-09-12 12:09:22 -0700 | [diff] [blame] | 385 | // overwrite the learnt information with the configured information. |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 386 | if (greedyLearningIpv6) { |
| 387 | // Auto-generation of the IPv6 link local address |
| 388 | // using the mac address |
| 389 | Ip6Address targetIp6Address = Ip6Address.valueOf( |
| 390 | getLinkLocalAddress(hostId.mac().toBytes()) |
| 391 | ); |
| 392 | // If we already know this guy we don't need to do other |
| 393 | if (!hostDescription.ipAddress().contains(targetIp6Address)) { |
| 394 | Host host = store.getHost(hostId); |
| 395 | // Configured host, skip it. |
| 396 | if (host != null && host.configured()) { |
| 397 | return; |
| 398 | } |
| 399 | // Host does not exist in the store or the target is not known |
| 400 | if ((host == null || !host.ipAddresses().contains(targetIp6Address))) { |
Charles Chan | 82fac58 | 2017-09-12 12:09:22 -0700 | [diff] [blame] | 401 | // Use DAD to probe if interface MAC is not specified |
| 402 | MacAddress probeMac = interfaceService.getInterfacesByPort(hostDescription.location()) |
| 403 | .stream().map(Interface::mac).findFirst().orElse(MacAddress.ONOS); |
| 404 | Ip6Address probeIp = !probeMac.equals(MacAddress.ONOS) ? |
| 405 | Ip6Address.valueOf(getLinkLocalAddress(probeMac.toBytes())) : |
| 406 | Ip6Address.ZERO; |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 407 | // We send a probe using the monitoring service |
| 408 | monitor.sendProbe( |
| 409 | hostDescription.location(), |
| 410 | targetIp6Address, |
Charles Chan | 82fac58 | 2017-09-12 12:09:22 -0700 | [diff] [blame] | 411 | probeIp, |
| 412 | probeMac, |
Pier Luigi | 9b1d626 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 413 | hostId.vlanId() |
| 414 | ); |
| 415 | } |
| 416 | } |
| 417 | } |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 418 | } |
| 419 | |
soumya | 3e6f05e | 2016-08-05 15:11:11 -0700 | [diff] [blame] | 420 | // When a new IP is detected, remove that IP on other hosts if it exists |
| 421 | public void removeDuplicates(HostId hostId, HostDescription desc) { |
| 422 | desc.ipAddress().forEach(ip -> { |
| 423 | Set<Host> allHosts = store.getHosts(ip); |
| 424 | allHosts.forEach(eachHost -> { |
| 425 | if (!(eachHost.id().equals(hostId))) { |
| 426 | log.info("Duplicate ip {} found on host {} and {}", ip, |
| 427 | hostId.toString(), eachHost.id().toString()); |
| 428 | store.removeIp(eachHost.id(), ip); |
| 429 | } |
| 430 | }); |
| 431 | }); |
Jonathan Hart | 38feb6e | 2016-08-29 22:54:16 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 434 | // returns a HostDescription made from the union of the BasicHostConfig |
| 435 | // annotations if it exists |
| 436 | private HostDescription validateHost(HostDescription hostDescription, HostId hostId) { |
| 437 | BasicHostConfig cfg = networkConfigService.getConfig(hostId, BasicHostConfig.class); |
| 438 | checkState(cfg == null || cfg.isAllowed(), "Host {} is not allowed", hostId); |
Ayaka Koshibe | 5373e76 | 2015-08-06 12:31:44 -0700 | [diff] [blame] | 439 | |
| 440 | return BasicHostOperator.combine(cfg, hostDescription); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 441 | } |
| 442 | |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 443 | @Override |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 444 | public void hostVanished(HostId hostId) { |
| 445 | checkNotNull(hostId, HOST_ID_NULL); |
| 446 | checkValidity(); |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 447 | Host host = store.getHost(hostId); |
Charles Chan | 29ecdee | 2017-02-22 18:46:56 -0800 | [diff] [blame] | 448 | |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 449 | if (!allowedToChange(hostId)) { |
| 450 | log.info("Request to remove {} is ignored due to provider mismatch", hostId); |
Charles Chan | 29ecdee | 2017-02-22 18:46:56 -0800 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 454 | if (monitorHosts) { |
| 455 | host.ipAddresses().forEach(ip -> { |
| 456 | monitor.stopMonitoring(ip); |
| 457 | }); |
| 458 | } |
Charles Chan | 009c308 | 2015-11-10 14:18:04 -0800 | [diff] [blame] | 459 | store.removeHost(hostId); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 460 | } |
samanwita pal | c40e5ed | 2015-09-24 11:01:51 -0700 | [diff] [blame] | 461 | |
| 462 | @Override |
| 463 | public void removeIpFromHost(HostId hostId, IpAddress ipAddress) { |
| 464 | checkNotNull(hostId, HOST_ID_NULL); |
| 465 | checkValidity(); |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 466 | |
| 467 | if (!allowedToChange(hostId)) { |
| 468 | log.info("Request to remove {} from {} is ignored due to provider mismatch", |
| 469 | ipAddress, hostId); |
| 470 | return; |
| 471 | } |
| 472 | |
Charles Chan | 009c308 | 2015-11-10 14:18:04 -0800 | [diff] [blame] | 473 | store.removeIp(hostId, ipAddress); |
samanwita pal | c40e5ed | 2015-09-24 11:01:51 -0700 | [diff] [blame] | 474 | } |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 475 | |
| 476 | @Override |
Charles Chan | ff79dd9 | 2018-06-01 16:33:48 -0700 | [diff] [blame] | 477 | public void addLocationToHost(HostId hostId, HostLocation location) { |
| 478 | checkNotNull(hostId, HOST_ID_NULL); |
| 479 | checkValidity(); |
| 480 | |
| 481 | if (!allowedToChange(hostId)) { |
Charles Chan | b928b3f | 2018-07-23 15:37:08 -0700 | [diff] [blame] | 482 | log.info("Request to add {} to {} is ignored due to provider mismatch", |
Charles Chan | ff79dd9 | 2018-06-01 16:33:48 -0700 | [diff] [blame] | 483 | location, hostId); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | store.appendLocation(hostId, location); |
| 488 | } |
| 489 | |
| 490 | @Override |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 491 | public void removeLocationFromHost(HostId hostId, HostLocation location) { |
| 492 | checkNotNull(hostId, HOST_ID_NULL); |
| 493 | checkValidity(); |
| 494 | |
| 495 | if (!allowedToChange(hostId)) { |
| 496 | log.info("Request to remove {} from {} is ignored due to provider mismatch", |
| 497 | location, hostId); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | store.removeLocation(hostId, location); |
| 502 | } |
| 503 | |
Charles Chan | d0c147a | 2017-09-14 14:00:10 -0700 | [diff] [blame] | 504 | /** |
| 505 | * Providers should only be able to remove a host that is provided by itself, |
| 506 | * or a host that is not configured. |
| 507 | */ |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 508 | private boolean allowedToChange(HostId hostId) { |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 509 | Host host = store.getHost(hostId); |
Charles Chan | d0c147a | 2017-09-14 14:00:10 -0700 | [diff] [blame] | 510 | return host == null || !host.configured() || host.providerId().equals(provider().id()); |
Charles Chan | 888e20a | 2017-05-01 15:44:23 -0700 | [diff] [blame] | 511 | } |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 512 | } |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 513 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 514 | // Store delegate to re-post events emitted from the store. |
| 515 | private class InternalStoreDelegate implements HostStoreDelegate { |
| 516 | @Override |
| 517 | public void notify(HostEvent event) { |
| 518 | post(event); |
| 519 | } |
| 520 | } |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 521 | |
| 522 | // listens for NetworkConfigEvents of type BasicHostConfig and removes |
| 523 | // links that the config does not allow |
| 524 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 525 | @Override |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 526 | public boolean isRelevant(NetworkConfigEvent event) { |
| 527 | return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED |
| 528 | || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 529 | && (event.configClass().equals(BasicHostConfig.class) |
| 530 | || event.configClass().equals(HostAnnotationConfig.class)); |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | @Override |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 534 | public void event(NetworkConfigEvent event) { |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 535 | log.debug("Detected host network config event {}", event.type()); |
| 536 | HostEvent he = null; |
| 537 | |
| 538 | HostId hostId = (HostId) event.subject(); |
| 539 | BasicHostConfig cfg = |
| 540 | networkConfigService.getConfig(hostId, BasicHostConfig.class); |
| 541 | |
| 542 | if (!isAllowed(cfg)) { |
| 543 | kickOutBadHost(hostId); |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 544 | } else if (event.configClass().equals(BasicHostConfig.class)) { |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 545 | Host host = getHost(hostId); |
| 546 | HostDescription desc = |
| 547 | (host == null) ? null : BasicHostOperator.descriptionOf(host); |
| 548 | desc = BasicHostOperator.combine(cfg, desc); |
| 549 | if (desc != null) { |
| 550 | he = store.createOrUpdateHost(host.providerId(), hostId, desc, false); |
| 551 | } |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 552 | } else if (event.configClass().equals(HostAnnotationConfig.class)) { |
| 553 | Host host = getHost(hostId); |
Ray Milkey | 718e438 | 2018-12-05 09:08:01 -0800 | [diff] [blame] | 554 | HostProvider hp = (host == null) ? null : getProvider(host.providerId()); |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame] | 555 | HostDescription desc = (host == null) ? null : BasicHostOperator.descriptionOf(host); |
| 556 | Optional<Config> prevConfig = event.prevConfig(); |
| 557 | log.debug("Host annotations: {} prevconfig {} desc {}", hostId, prevConfig, desc); |
| 558 | desc = hostAnnotationOperator.combine(hostId, desc, prevConfig); |
| 559 | if (desc != null && hp != null) { |
| 560 | log.debug("Host annotations update - updated host description :{}", desc.toString()); |
| 561 | he = store.createOrUpdateHost(hp.id(), hostId, desc, false); |
| 562 | if (he != null && he.subject() != null) { |
| 563 | log.debug("Host annotations update - Host Event : {}", he.subject().annotations()); |
| 564 | } |
| 565 | } |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | if (he != null) { |
| 569 | post(he); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 574 | // by default allowed, otherwise check flag |
| 575 | private boolean isAllowed(BasicHostConfig cfg) { |
| 576 | return (cfg == null || cfg.isAllowed()); |
| 577 | } |
| 578 | |
| 579 | // removes the specified host, if it exists |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 580 | private void kickOutBadHost(HostId hostId) { |
Simon Hunt | ffbad3b | 2017-05-16 15:37:51 -0700 | [diff] [blame] | 581 | Host badHost = getHost(hostId); |
| 582 | if (badHost != null) { |
| 583 | removeHost(hostId); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 586 | } |