gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.dhcprelay; |
| 17 | |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 18 | import java.nio.ByteBuffer; |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 19 | import java.util.Dictionary; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 20 | import java.util.Objects; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 21 | import java.util.Set; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Modified; |
| 26 | import org.apache.felix.scr.annotations.Property; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 27 | import org.apache.felix.scr.annotations.Reference; |
| 28 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 29 | import org.onlab.packet.ARP; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 30 | import org.onlab.packet.DHCP; |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 31 | import org.onlab.packet.DHCPOption; |
| 32 | import org.onlab.packet.DHCPPacketType; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 33 | import org.onlab.packet.Ethernet; |
| 34 | import org.onlab.packet.IPv4; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 35 | import org.onlab.packet.Ip4Address; |
Charles Chan | 23d15bc | 2017-05-13 00:55:21 -0700 | [diff] [blame] | 36 | import org.onlab.packet.IpAddress; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 37 | import org.onlab.packet.MacAddress; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 38 | import org.onlab.packet.TpPort; |
| 39 | import org.onlab.packet.UDP; |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 40 | import org.onlab.packet.VlanId; |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 41 | import org.onlab.util.Tools; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 42 | import org.onosproject.core.ApplicationId; |
| 43 | import org.onosproject.core.CoreService; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 44 | import org.onosproject.incubator.net.intf.Interface; |
| 45 | import org.onosproject.incubator.net.intf.InterfaceService; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 46 | import org.onosproject.net.ConnectPoint; |
| 47 | import org.onosproject.net.Host; |
| 48 | import org.onosproject.net.HostId; |
| 49 | import org.onosproject.net.config.ConfigFactory; |
| 50 | import org.onosproject.net.config.NetworkConfigEvent; |
| 51 | import org.onosproject.net.config.NetworkConfigListener; |
| 52 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 53 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 54 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 55 | import org.onosproject.net.flow.TrafficSelector; |
| 56 | import org.onosproject.net.flow.TrafficTreatment; |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 57 | import org.onosproject.net.host.HostEvent; |
| 58 | import org.onosproject.net.host.HostListener; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 59 | import org.onosproject.net.host.HostService; |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 60 | import org.onosproject.net.host.InterfaceIpAddress; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 61 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 62 | import org.onosproject.net.packet.OutboundPacket; |
| 63 | import org.onosproject.net.packet.PacketContext; |
| 64 | import org.onosproject.net.packet.PacketPriority; |
| 65 | import org.onosproject.net.packet.PacketProcessor; |
| 66 | import org.onosproject.net.packet.PacketService; |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 67 | import org.osgi.service.component.ComponentContext; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 68 | import org.slf4j.Logger; |
| 69 | import org.slf4j.LoggerFactory; |
| 70 | |
| 71 | import com.google.common.collect.ImmutableSet; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 72 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 73 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 74 | import static org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_MessageType; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 75 | import static org.onlab.packet.MacAddress.valueOf; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 76 | /** |
| 77 | * DHCP Relay Agent Application Component. |
| 78 | */ |
| 79 | @Component(immediate = true) |
| 80 | public class DhcpRelay { |
| 81 | |
| 82 | public static final String DHCP_RELAY_APP = "org.onosproject.dhcp-relay"; |
| 83 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 84 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 85 | private static MacAddress myMAC = valueOf("4f:4f:4f:4f:4f:4f"); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 86 | |
| 87 | private final Set<ConfigFactory> factories = ImmutableSet.of( |
| 88 | new ConfigFactory<ApplicationId, DhcpRelayConfig>(APP_SUBJECT_FACTORY, |
| 89 | DhcpRelayConfig.class, |
| 90 | "dhcprelay") { |
| 91 | @Override |
| 92 | public DhcpRelayConfig createConfig() { |
| 93 | return new DhcpRelayConfig(); |
| 94 | } |
| 95 | } |
| 96 | ); |
| 97 | |
| 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 99 | protected NetworkConfigRegistry cfgService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected CoreService coreService; |
| 103 | |
| 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 105 | protected PacketService packetService; |
| 106 | |
| 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 108 | protected HostService hostService; |
| 109 | |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 111 | protected InterfaceService interfaceService; |
| 112 | |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 113 | @Property(name = "arpEnabled", boolValue = true, |
| 114 | label = "Enable Address resolution protocol") |
| 115 | protected boolean arpEnabled = true; |
| 116 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 117 | private DhcpRelayPacketProcessor dhcpRelayPacketProcessor = new DhcpRelayPacketProcessor(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 118 | private InternalHostListener hostListener = new InternalHostListener(); |
| 119 | |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 120 | private Ip4Address dhcpServerIp = null; |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 121 | // dhcp server may be connected directly to the SDN network or |
| 122 | // via an external gateway. When connected directly, the dhcpConnectPoint, dhcpConnectMac, |
| 123 | // and dhcpConnectVlan refer to the server. When connected via the gateway, they refer |
| 124 | // to the gateway. |
| 125 | private ConnectPoint dhcpServerConnectPoint = null; |
| 126 | private MacAddress dhcpConnectMac = null; |
| 127 | private VlanId dhcpConnectVlan = null; |
| 128 | private Ip4Address dhcpGatewayIp = null; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 129 | private ApplicationId appId; |
| 130 | |
| 131 | @Activate |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 132 | protected void activate(ComponentContext context) { |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 133 | //start the dhcp relay agent |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 134 | appId = coreService.registerApplication(DHCP_RELAY_APP); |
| 135 | |
| 136 | cfgService.addListener(cfgListener); |
| 137 | factories.forEach(cfgService::registerConfigFactory); |
| 138 | //update the dhcp server configuration. |
| 139 | updateConfig(); |
| 140 | //add the packet services. |
| 141 | packetService.addProcessor(dhcpRelayPacketProcessor, PacketProcessor.director(0)); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 142 | hostService.addListener(hostListener); |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 143 | requestDhcpPackets(); |
| 144 | modified(context); |
| 145 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 146 | log.info("DHCP-RELAY Started"); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | @Deactivate |
| 150 | protected void deactivate() { |
| 151 | cfgService.removeListener(cfgListener); |
| 152 | factories.forEach(cfgService::unregisterConfigFactory); |
| 153 | packetService.removeProcessor(dhcpRelayPacketProcessor); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 154 | hostService.removeListener(hostListener); |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 155 | cancelDhcpPackets(); |
| 156 | cancelArpPackets(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 157 | if (dhcpGatewayIp != null) { |
| 158 | hostService.stopMonitoringIp(dhcpGatewayIp); |
| 159 | } else { |
| 160 | hostService.stopMonitoringIp(dhcpServerIp); |
| 161 | } |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 162 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 163 | log.info("DHCP-RELAY Stopped"); |
| 164 | } |
| 165 | |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 166 | @Modified |
| 167 | protected void modified(ComponentContext context) { |
| 168 | Dictionary<?, ?> properties = context.getProperties(); |
| 169 | Boolean flag; |
| 170 | |
| 171 | flag = Tools.isPropertyEnabled(properties, "arpEnabled"); |
| 172 | if (flag != null) { |
| 173 | arpEnabled = flag; |
| 174 | log.info("Address resolution protocol is {}", |
| 175 | arpEnabled ? "enabled" : "disabled"); |
| 176 | } |
| 177 | |
| 178 | if (arpEnabled) { |
| 179 | requestArpPackets(); |
| 180 | } else { |
| 181 | cancelArpPackets(); |
| 182 | } |
| 183 | } |
| 184 | |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 185 | /** |
| 186 | * Checks if this app has been configured. |
| 187 | * |
| 188 | * @return true if all information we need have been initialized |
| 189 | */ |
| 190 | private boolean configured() { |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 191 | return dhcpServerConnectPoint != null && dhcpServerIp != null; |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 192 | } |
| 193 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 194 | private void updateConfig() { |
| 195 | DhcpRelayConfig cfg = cfgService.getConfig(appId, DhcpRelayConfig.class); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 196 | if (cfg == null) { |
| 197 | log.warn("Dhcp Server info not available"); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | dhcpServerConnectPoint = cfg.getDhcpServerConnectPoint(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 202 | Ip4Address oldDhcpServerIp = dhcpServerIp; |
| 203 | Ip4Address oldDhcpGatewayIp = dhcpGatewayIp; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 204 | dhcpServerIp = cfg.getDhcpServerIp(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 205 | dhcpGatewayIp = cfg.getDhcpGatewayIp(); |
| 206 | dhcpConnectMac = null; // reset for updated config |
| 207 | dhcpConnectVlan = null; // reset for updated config |
Charles Chan | 23d15bc | 2017-05-13 00:55:21 -0700 | [diff] [blame] | 208 | log.info("DHCP server connect point: " + dhcpServerConnectPoint); |
| 209 | log.info("DHCP server ipaddress " + dhcpServerIp); |
| 210 | |
| 211 | IpAddress ipToProbe = dhcpGatewayIp != null ? dhcpGatewayIp : dhcpServerIp; |
| 212 | String hostToProbe = dhcpGatewayIp != null ? "gateway" : "DHCP server"; |
| 213 | |
| 214 | Set<Host> hosts = hostService.getHostsByIp(ipToProbe); |
| 215 | if (hosts.isEmpty()) { |
| 216 | log.info("Probing to resolve {} IP {}", hostToProbe, ipToProbe); |
| 217 | if (oldDhcpGatewayIp != null) { |
| 218 | hostService.stopMonitoringIp(oldDhcpGatewayIp); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 219 | } |
Charles Chan | 23d15bc | 2017-05-13 00:55:21 -0700 | [diff] [blame] | 220 | if (oldDhcpServerIp != null) { |
| 221 | hostService.stopMonitoringIp(oldDhcpServerIp); |
| 222 | } |
| 223 | hostService.startMonitoringIp(ipToProbe); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 224 | } else { |
Charles Chan | 23d15bc | 2017-05-13 00:55:21 -0700 | [diff] [blame] | 225 | // Probe target is known; There should be only 1 host with this ip |
| 226 | hostUpdated(hosts.iterator().next()); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | private void hostRemoved(Host host) { |
| 231 | if (host.ipAddresses().contains(dhcpServerIp)) { |
| 232 | log.warn("DHCP server {} removed", dhcpServerIp); |
| 233 | dhcpConnectMac = null; |
| 234 | dhcpConnectVlan = null; |
| 235 | } |
| 236 | if (dhcpGatewayIp != null && host.ipAddresses().contains(dhcpGatewayIp)) { |
| 237 | log.warn("DHCP gateway {} removed", dhcpGatewayIp); |
| 238 | dhcpConnectMac = null; |
| 239 | dhcpConnectVlan = null; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | private void hostUpdated(Host host) { |
| 244 | if (dhcpGatewayIp != null) { |
| 245 | if (host.ipAddresses().contains(dhcpGatewayIp)) { |
| 246 | dhcpConnectMac = host.mac(); |
| 247 | dhcpConnectVlan = host.vlan(); |
| 248 | log.info("DHCP gateway {} resolved to Mac/Vlan:{}/{}", dhcpGatewayIp, |
| 249 | dhcpConnectMac, dhcpConnectVlan); |
| 250 | } |
| 251 | return; |
| 252 | } |
| 253 | if (host.ipAddresses().contains(dhcpServerIp)) { |
| 254 | dhcpConnectMac = host.mac(); |
| 255 | dhcpConnectVlan = host.vlan(); |
| 256 | log.info("DHCP server {} resolved to Mac/Vlan:{}/{}", dhcpServerIp, |
| 257 | dhcpConnectMac, dhcpConnectVlan); |
| 258 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 262 | * Request DHCP packet in via PacketService. |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 263 | */ |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 264 | private void requestDhcpPackets() { |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 265 | TrafficSelector.Builder selectorServer = DefaultTrafficSelector.builder() |
| 266 | .matchEthType(Ethernet.TYPE_IPV4) |
| 267 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 268 | .matchUdpSrc(TpPort.tpPort(UDP.DHCP_SERVER_PORT)); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 269 | packetService.requestPackets(selectorServer.build(), PacketPriority.CONTROL, appId); |
| 270 | |
| 271 | TrafficSelector.Builder selectorClient = DefaultTrafficSelector.builder() |
| 272 | .matchEthType(Ethernet.TYPE_IPV4) |
| 273 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 274 | .matchUdpSrc(TpPort.tpPort(UDP.DHCP_CLIENT_PORT)); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 275 | packetService.requestPackets(selectorClient.build(), PacketPriority.CONTROL, appId); |
| 276 | } |
| 277 | |
| 278 | /** |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 279 | * Cancel requested DHCP packets in via packet service. |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 280 | */ |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 281 | private void cancelDhcpPackets() { |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 282 | TrafficSelector.Builder selectorServer = DefaultTrafficSelector.builder() |
| 283 | .matchEthType(Ethernet.TYPE_IPV4) |
| 284 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 285 | .matchUdpSrc(TpPort.tpPort(UDP.DHCP_SERVER_PORT)); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 286 | packetService.cancelPackets(selectorServer.build(), PacketPriority.CONTROL, appId); |
| 287 | |
| 288 | TrafficSelector.Builder selectorClient = DefaultTrafficSelector.builder() |
| 289 | .matchEthType(Ethernet.TYPE_IPV4) |
| 290 | .matchIPProtocol(IPv4.PROTOCOL_UDP) |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 291 | .matchUdpSrc(TpPort.tpPort(UDP.DHCP_CLIENT_PORT)); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 292 | packetService.cancelPackets(selectorClient.build(), PacketPriority.CONTROL, appId); |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 293 | } |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 294 | |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 295 | /** |
| 296 | * Request ARP packet in via PacketService. |
| 297 | */ |
| 298 | private void requestArpPackets() { |
| 299 | TrafficSelector.Builder selectorArpServer = DefaultTrafficSelector.builder() |
| 300 | .matchEthType(Ethernet.TYPE_ARP); |
| 301 | packetService.requestPackets(selectorArpServer.build(), PacketPriority.CONTROL, appId); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Cancel requested ARP packets in via packet service. |
| 306 | */ |
| 307 | private void cancelArpPackets() { |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 308 | TrafficSelector.Builder selectorArpServer = DefaultTrafficSelector.builder() |
| 309 | .matchEthType(Ethernet.TYPE_ARP); |
| 310 | packetService.cancelPackets(selectorArpServer.build(), PacketPriority.CONTROL, appId); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | private class DhcpRelayPacketProcessor implements PacketProcessor { |
| 314 | |
| 315 | @Override |
| 316 | public void process(PacketContext context) { |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 317 | if (!configured()) { |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 318 | log.warn("Missing DHCP relay server config. Abort packet processing"); |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 319 | return; |
| 320 | } |
| 321 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 322 | // process the packet and get the payload |
| 323 | Ethernet packet = context.inPacket().parsed(); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 324 | if (packet == null) { |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | if (packet.getEtherType() == Ethernet.TYPE_IPV4) { |
| 329 | IPv4 ipv4Packet = (IPv4) packet.getPayload(); |
| 330 | |
| 331 | if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) { |
| 332 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
| 333 | DHCP dhcpPayload = (DHCP) udpPacket.getPayload(); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 334 | if (udpPacket.getSourcePort() == UDP.DHCP_CLIENT_PORT || |
| 335 | udpPacket.getSourcePort() == UDP.DHCP_SERVER_PORT) { |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 336 | //This packet is dhcp. |
| 337 | processDhcpPacket(context, dhcpPayload); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 338 | } |
| 339 | } |
Pier Luigi | 20557c8 | 2017-01-12 22:40:46 -0800 | [diff] [blame] | 340 | } else if (packet.getEtherType() == Ethernet.TYPE_ARP && arpEnabled) { |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 341 | ARP arpPacket = (ARP) packet.getPayload(); |
| 342 | Set<Interface> serverInterfaces = interfaceService. |
| 343 | getInterfacesByPort(context.inPacket().receivedFrom()); |
| 344 | //ignore the packets if dhcp server interface is not configured on onos. |
| 345 | if (serverInterfaces.isEmpty()) { |
| 346 | log.warn("server virtual interface not configured"); |
| 347 | return; |
| 348 | } |
| 349 | if ((arpPacket.getOpCode() == ARP.OP_REQUEST) && |
| 350 | checkArpRequestFrmDhcpServ(serverInterfaces, arpPacket)) { |
| 351 | processArpPacket(context, packet); |
| 352 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 356 | //method to check the arp request is from dhcp server for default-gateway. |
| 357 | private boolean checkArpRequestFrmDhcpServ(Set<Interface> serverInterfaces, ARP arpPacket) { |
| 358 | if (Objects.equals(serverInterfaces.iterator().next().ipAddressesList().get(0). |
| 359 | ipAddress().getIp4Address(), |
| 360 | Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()))) { |
| 361 | return true; |
| 362 | } |
| 363 | return false; |
| 364 | } |
| 365 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 366 | //forward the packet to ConnectPoint where the DHCP server is attached. |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 367 | private void forwardPacket(Ethernet packet) { |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 368 | //send Packetout to dhcp server connectpoint. |
| 369 | if (dhcpServerConnectPoint != null) { |
| 370 | TrafficTreatment t = DefaultTrafficTreatment.builder() |
| 371 | .setOutput(dhcpServerConnectPoint.port()).build(); |
| 372 | OutboundPacket o = new DefaultOutboundPacket( |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 373 | dhcpServerConnectPoint.deviceId(), t, ByteBuffer.wrap(packet.serialize())); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 374 | if (log.isTraceEnabled()) { |
| 375 | log.trace("Relaying packet to dhcp server {}", packet); |
| 376 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 377 | packetService.emit(o); |
| 378 | } |
| 379 | } |
| 380 | |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 381 | /** |
| 382 | * Processes the ARP Payload and initiates a reply to the client. |
| 383 | * |
| 384 | * @param context context of the incoming message |
| 385 | * @param packet the ethernet payload |
| 386 | */ |
| 387 | private void processArpPacket(PacketContext context, Ethernet packet) { |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 388 | ARP arpPacket = (ARP) packet.getPayload(); |
| 389 | |
| 390 | ARP arpReply = (ARP) arpPacket.clone(); |
| 391 | arpReply.setOpCode(ARP.OP_REPLY); |
| 392 | |
| 393 | arpReply.setTargetProtocolAddress(arpPacket.getSenderProtocolAddress()); |
| 394 | arpReply.setTargetHardwareAddress(arpPacket.getSenderHardwareAddress()); |
| 395 | arpReply.setSenderProtocolAddress(arpPacket.getTargetProtocolAddress()); |
| 396 | arpReply.setSenderHardwareAddress(myMAC.toBytes()); |
| 397 | |
| 398 | // Ethernet Frame. |
| 399 | Ethernet ethReply = new Ethernet(); |
| 400 | ethReply.setSourceMACAddress(myMAC); |
| 401 | ethReply.setDestinationMACAddress(packet.getSourceMAC()); |
| 402 | ethReply.setEtherType(Ethernet.TYPE_ARP); |
| 403 | ethReply.setVlanID(packet.getVlanID()); |
| 404 | |
| 405 | ethReply.setPayload(arpReply); |
| 406 | forwardPacket(ethReply); |
| 407 | } |
| 408 | |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 409 | //process the dhcp packet before sending to server |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 410 | private void processDhcpPacket(PacketContext context, DHCP dhcpPayload) { |
Charles Chan | 1b20123 | 2016-12-07 15:39:22 -0800 | [diff] [blame] | 411 | ConnectPoint inPort = context.inPacket().receivedFrom(); |
| 412 | Set<Interface> clientServerInterfaces = interfaceService.getInterfacesByPort(inPort); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 413 | //ignore the packets if dhcp client interface is not configured on onos. |
| 414 | if (clientServerInterfaces.isEmpty()) { |
Charles Chan | 1b20123 | 2016-12-07 15:39:22 -0800 | [diff] [blame] | 415 | log.warn("Virtual interface is not configured on {}", inPort); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 419 | if (dhcpPayload == null) { |
| 420 | return; |
| 421 | } |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 422 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 423 | Ethernet packet = context.inPacket().parsed(); |
| 424 | DHCPPacketType incomingPacketType = null; |
| 425 | for (DHCPOption option : dhcpPayload.getOptions()) { |
| 426 | if (option.getCode() == OptionCode_MessageType.getValue()) { |
| 427 | byte[] data = option.getData(); |
| 428 | incomingPacketType = DHCPPacketType.getType(data[0]); |
| 429 | } |
| 430 | } |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 431 | |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 432 | switch (incomingPacketType) { |
| 433 | case DHCPDISCOVER: |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 434 | // add the gatewayip as virtual interface ip for server to understand |
| 435 | // the lease to be assigned and forward the packet to dhcp server. |
| 436 | Ethernet ethernetPacketDiscover = |
| 437 | processDhcpPacketFromClient(context, packet, clientServerInterfaces); |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 438 | if (ethernetPacketDiscover != null) { |
| 439 | forwardPacket(ethernetPacketDiscover); |
| 440 | } |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 441 | break; |
| 442 | case DHCPOFFER: |
| 443 | //reply to dhcp client. |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 444 | Ethernet ethernetPacketOffer = processDhcpPacketFromServer(packet); |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 445 | if (ethernetPacketOffer != null) { |
| 446 | sendReply(ethernetPacketOffer, dhcpPayload); |
| 447 | } |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 448 | break; |
| 449 | case DHCPREQUEST: |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 450 | // add the gatewayip as virtual interface ip for server to understand |
| 451 | // the lease to be assigned and forward the packet to dhcp server. |
| 452 | Ethernet ethernetPacketRequest = |
| 453 | processDhcpPacketFromClient(context, packet, clientServerInterfaces); |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 454 | if (ethernetPacketRequest != null) { |
| 455 | forwardPacket(ethernetPacketRequest); |
| 456 | } |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 457 | break; |
| 458 | case DHCPACK: |
| 459 | //reply to dhcp client. |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 460 | Ethernet ethernetPacketAck = processDhcpPacketFromServer(packet); |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 461 | if (ethernetPacketAck != null) { |
| 462 | sendReply(ethernetPacketAck, dhcpPayload); |
| 463 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 464 | break; |
| 465 | default: |
| 466 | break; |
| 467 | } |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 468 | } |
| 469 | |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 470 | //build the DHCP discover/request packet with gatewayip(unicast packet) |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 471 | private Ethernet processDhcpPacketFromClient(PacketContext context, |
| 472 | Ethernet ethernetPacket, Set<Interface> clientInterfaces) { |
| 473 | Ip4Address relayAgentIp = getRelayAgentIPv4Address(clientInterfaces); |
| 474 | MacAddress relayAgentMac = clientInterfaces.iterator().next().mac(); |
| 475 | if (relayAgentIp == null || relayAgentMac == null) { |
| 476 | log.warn("Missing DHCP relay agent interface Ipv4 addr config for " |
| 477 | + "packet from client on port: {}. Aborting packet processing", |
| 478 | clientInterfaces.iterator().next().connectPoint()); |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 479 | return null; |
| 480 | } |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 481 | if (dhcpConnectMac == null) { |
| 482 | log.warn("DHCP {} not yet resolved .. Aborting DHCP " |
| 483 | + "packet processing from client on port: {}", |
| 484 | (dhcpGatewayIp == null) ? "server IP " + dhcpServerIp |
| 485 | : "gateway IP " + dhcpGatewayIp, |
| 486 | clientInterfaces.iterator().next().connectPoint()); |
| 487 | return null; |
| 488 | } |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 489 | // get dhcp header. |
| 490 | Ethernet etherReply = (Ethernet) ethernetPacket.clone(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 491 | etherReply.setSourceMACAddress(relayAgentMac); |
| 492 | etherReply.setDestinationMACAddress(dhcpConnectMac); |
| 493 | etherReply.setVlanID(dhcpConnectVlan.toShort()); |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 494 | IPv4 ipv4Packet = (IPv4) etherReply.getPayload(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 495 | ipv4Packet.setSourceAddress(relayAgentIp.toInt()); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 496 | ipv4Packet.setDestinationAddress(dhcpServerIp.toInt()); |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 497 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
| 498 | DHCP dhcpPacket = (DHCP) udpPacket.getPayload(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 499 | dhcpPacket.setGatewayIPAddress(relayAgentIp.toInt()); |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 500 | udpPacket.setPayload(dhcpPacket); |
| 501 | ipv4Packet.setPayload(udpPacket); |
| 502 | etherReply.setPayload(ipv4Packet); |
| 503 | return etherReply; |
| 504 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 505 | |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 506 | // Returns the first v4 interface ip out of a set of interfaces or null. |
| 507 | // Checks all interfaces, and ignores v6 interface ips |
| 508 | private Ip4Address getRelayAgentIPv4Address(Set<Interface> intfs) { |
| 509 | for (Interface intf : intfs) { |
| 510 | for (InterfaceIpAddress ip : intf.ipAddressesList()) { |
| 511 | Ip4Address relayAgentIp = ip.ipAddress().getIp4Address(); |
| 512 | if (relayAgentIp != null) { |
| 513 | return relayAgentIp; |
| 514 | } |
| 515 | } |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 516 | } |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 517 | return null; |
| 518 | } |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 519 | |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 520 | //build the DHCP offer/ack with proper client port. |
| 521 | private Ethernet processDhcpPacketFromServer(Ethernet ethernetPacket) { |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 522 | // get dhcp header. |
| 523 | Ethernet etherReply = (Ethernet) ethernetPacket.clone(); |
| 524 | IPv4 ipv4Packet = (IPv4) etherReply.getPayload(); |
| 525 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
| 526 | DHCP dhcpPayload = (DHCP) udpPacket.getPayload(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 527 | |
| 528 | // determine the vlanId of the client host - note that this vlan id |
| 529 | // could be different from the vlan in the packet from the server |
| 530 | MacAddress dstMac = valueOf(dhcpPayload.getClientHardwareAddress()); |
| 531 | Set<Host> hosts = hostService.getHostsByMac(dstMac); |
| 532 | if (hosts == null || hosts.isEmpty()) { |
| 533 | log.warn("Cannot determine host for DHCP client: {}. Aborting " |
| 534 | + "relay for dhcp packet from server {}", |
| 535 | dhcpPayload.getClientHardwareAddress(), ethernetPacket); |
| 536 | return null; |
| 537 | } else if (hosts.size() > 1) { |
| 538 | // XXX redo to send reply to all hosts found |
| 539 | log.warn("Multiple hosts found for mac:{}. Picking one " |
| 540 | + "host out of {}", dstMac, hosts); |
| 541 | } |
| 542 | Host host = hosts.iterator().next(); |
| 543 | etherReply.setDestinationMACAddress(dstMac); |
| 544 | etherReply.setVlanID(host.vlan().toShort()); |
| 545 | // we leave the srcMac from the original packet |
| 546 | |
| 547 | // figure out the relay agent IP corresponding to the original request |
| 548 | Ip4Address relayAgentIP = getRelayAgentIPv4Address( |
| 549 | interfaceService.getInterfacesByPort(host.location())); |
| 550 | if (relayAgentIP == null) { |
| 551 | log.warn("Cannot determine relay agent interface Ipv4 addr for host {}. " |
| 552 | + "Aborting relay for dhcp packet from server {}", |
| 553 | host, ethernetPacket); |
| 554 | return null; |
| 555 | } |
Charles Chan | da5dc8c | 2017-01-13 14:29:29 -0800 | [diff] [blame] | 556 | // SRC_IP: relay agent IP |
| 557 | // DST_IP: offered IP |
| 558 | ipv4Packet.setSourceAddress(relayAgentIP.toInt()); |
| 559 | ipv4Packet.setDestinationAddress(dhcpPayload.getYourIPAddress()); |
| 560 | |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 561 | udpPacket.setDestinationPort(UDP.DHCP_CLIENT_PORT); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 562 | udpPacket.setPayload(dhcpPayload); |
| 563 | ipv4Packet.setPayload(udpPacket); |
| 564 | etherReply.setPayload(ipv4Packet); |
| 565 | return etherReply; |
| 566 | } |
| 567 | |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 568 | //send the response to the requester host. |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 569 | private void sendReply(Ethernet ethPacket, DHCP dhcpPayload) { |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 570 | MacAddress descMac = valueOf(dhcpPayload.getClientHardwareAddress()); |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 571 | Host host = hostService.getHost(HostId.hostId(descMac, |
gaurav | 4af95fb | 2016-07-07 01:48:44 +0530 | [diff] [blame] | 572 | VlanId.vlanId(ethPacket.getVlanID()))); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 573 | |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 574 | // Send packet out to requester if the host information is available |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 575 | if (host != null) { |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 576 | TrafficTreatment t = DefaultTrafficTreatment.builder() |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 577 | .setOutput(host.location().port()).build(); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 578 | OutboundPacket o = new DefaultOutboundPacket( |
Charles Chan | 3c1691a | 2017-02-16 14:55:22 -0800 | [diff] [blame] | 579 | host.location().deviceId(), t, ByteBuffer.wrap(ethPacket.serialize())); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 580 | if (log.isTraceEnabled()) { |
| 581 | log.trace("Relaying packet to dhcp client {}", ethPacket); |
| 582 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 583 | packetService.emit(o); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Listener for network config events. |
| 590 | */ |
| 591 | private class InternalConfigListener implements NetworkConfigListener { |
| 592 | |
| 593 | @Override |
| 594 | public void event(NetworkConfigEvent event) { |
| 595 | |
| 596 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 597 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && |
| 598 | event.configClass().equals(DhcpRelayConfig.class)) { |
| 599 | updateConfig(); |
| 600 | log.info("Reconfigured"); |
| 601 | } |
| 602 | } |
| 603 | } |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 604 | |
| 605 | /** |
| 606 | * Internal listener for host events. |
| 607 | */ |
| 608 | private class InternalHostListener implements HostListener { |
| 609 | @Override |
| 610 | public void event(HostEvent event) { |
| 611 | switch (event.type()) { |
| 612 | case HOST_ADDED: |
| 613 | case HOST_UPDATED: |
| 614 | hostUpdated(event.subject()); |
| 615 | break; |
| 616 | case HOST_REMOVED: |
| 617 | hostRemoved(event.subject()); |
| 618 | break; |
| 619 | case HOST_MOVED: |
| 620 | // XXX todo -- moving dhcp server |
| 621 | break; |
| 622 | default: |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | } |
Lei Xu | 3aeaf72 | 2016-08-11 13:51:12 -0700 | [diff] [blame] | 627 | } |