blob: c4894bf5af28ef5418cfaac2550bf2944fe4f6ab [file] [log] [blame]
Hyunsun Moond0e932a2015-09-15 22:39:16 -07001/*
2 * Copyright 2014-2015 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 */
16package org.onosproject.cordvtn;
17
Hyunsun Moon1f145552015-10-08 22:25:30 -070018import com.google.common.collect.Sets;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -080025import org.onlab.packet.Ethernet;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080026import org.onlab.packet.IpAddress;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080027import org.onlab.packet.MacAddress;
28import org.onlab.packet.VlanId;
Hyunsun Moon1f145552015-10-08 22:25:30 -070029import org.onosproject.core.ApplicationId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070030import org.onosproject.core.CoreService;
Hyunsun Moonc71231d2015-12-16 20:53:23 -080031import org.onosproject.mastership.MastershipService;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080032import org.onosproject.net.ConnectPoint;
Hyunsun Moond772f342015-10-28 20:28:16 -070033import org.onosproject.net.DefaultAnnotations;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070034import org.onosproject.net.Host;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080035import org.onosproject.net.HostId;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080036import org.onosproject.net.HostLocation;
Hyunsun Moon8539b042015-11-07 22:08:43 -080037import org.onosproject.net.Port;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080038import org.onosproject.net.SparseAnnotations;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070039import org.onosproject.net.device.DeviceService;
Hyunsun Moond772f342015-10-28 20:28:16 -070040import org.onosproject.net.driver.DriverService;
Hyunsun Moonc71231d2015-12-16 20:53:23 -080041import org.onosproject.net.flow.FlowRuleService;
42import org.onosproject.net.group.GroupService;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080043import org.onosproject.net.host.DefaultHostDescription;
44import org.onosproject.net.host.HostDescription;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070045import org.onosproject.net.host.HostEvent;
46import org.onosproject.net.host.HostListener;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080047import org.onosproject.net.host.HostProvider;
48import org.onosproject.net.host.HostProviderRegistry;
49import org.onosproject.net.host.HostProviderService;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070050import org.onosproject.net.host.HostService;
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -080051import org.onosproject.net.packet.PacketContext;
52import org.onosproject.net.packet.PacketProcessor;
53import org.onosproject.net.packet.PacketService;
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080054import org.onosproject.net.provider.AbstractProvider;
55import org.onosproject.net.provider.ProviderId;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080056import org.onosproject.openstackswitching.OpenstackNetwork;
57import org.onosproject.openstackswitching.OpenstackPort;
Hyunsun Moonc71231d2015-12-16 20:53:23 -080058import org.onosproject.openstackswitching.OpenstackSubnet;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080059import org.onosproject.openstackswitching.OpenstackSwitchingService;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070060import org.slf4j.Logger;
61
Hyunsun Moon1f145552015-10-08 22:25:30 -070062import java.util.Map;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080063import java.util.Set;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070064import java.util.concurrent.ExecutorService;
65import java.util.concurrent.Executors;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080066import java.util.stream.Collectors;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070067
Hyunsun Moon1f145552015-10-08 22:25:30 -070068import static com.google.common.base.Preconditions.checkNotNull;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070069import static org.onlab.util.Tools.groupedThreads;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070070import static org.slf4j.LoggerFactory.getLogger;
71
72/**
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080073 * Provisions virtual tenant networks with service chaining capability
74 * in OpenStack environment.
Hyunsun Moond0e932a2015-09-15 22:39:16 -070075 */
76@Component(immediate = true)
77@Service
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080078public class CordVtn extends AbstractProvider implements CordVtnService, HostProvider {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070079
80 protected final Logger log = getLogger(getClass());
81
82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 protected CoreService coreService;
84
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080086 protected HostProviderRegistry hostProviderRegistry;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070087
88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moond0e932a2015-09-15 22:39:16 -070089 protected DeviceService deviceService;
90
91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 protected HostService hostService;
93
Hyunsun Moon1f145552015-10-08 22:25:30 -070094 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moond772f342015-10-28 20:28:16 -070095 protected DriverService driverService;
96
97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moonc71231d2015-12-16 20:53:23 -080098 protected FlowRuleService flowRuleService;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -080099
100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -0800101 protected PacketService packetService;
102
103 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800104 protected MastershipService mastershipService;
105
106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 protected GroupService groupService;
108
109 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800110 protected OpenstackSwitchingService openstackService;
111
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800112 private static final int NUM_THREADS = 1;
113 private static final String DEFAULT_TUNNEL = "vxlan";
114 private static final String SERVICE_ID = "serviceId";
115 private static final String LOCATION_IP = "locationIp";
116 private static final String OPENSTACK_VM_ID = "openstackVmId";
117
Hyunsun Moon2b530322015-09-23 13:24:35 -0700118 private final ExecutorService eventExecutor = Executors
119 .newFixedThreadPool(NUM_THREADS, groupedThreads("onos/cordvtn", "event-handler"));
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700120
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -0800121 private final PacketProcessor packetProcessor = new InternalPacketProcessor();
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800122 private final HostListener hostListener = new InternalHostListener();
Hyunsun Moon2b530322015-09-23 13:24:35 -0700123
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800124 private HostProviderService hostProvider;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800125 private CordVtnRuleInstaller ruleInstaller;
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -0800126 private CordVtnArpProxy arpProxy;
Hyunsun Moon8539b042015-11-07 22:08:43 -0800127
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800128 /**
129 * Creates an cordvtn host location provider.
130 */
131 public CordVtn() {
132 super(new ProviderId("host", CORDVTN_APP_ID));
Hyunsun Moon8539b042015-11-07 22:08:43 -0800133 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700134
135 @Activate
136 protected void activate() {
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800137 ApplicationId appId = coreService.registerApplication("org.onosproject.cordvtn");
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700138
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800139 ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
140 deviceService,
141 driverService,
142 groupService,
143 mastershipService,
144 DEFAULT_TUNNEL);
145
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -0800146 arpProxy = new CordVtnArpProxy(appId, packetService);
147 packetService.addProcessor(packetProcessor, PacketProcessor.director(0));
148 arpProxy.requestPacket();
149
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700150 hostService.addListener(hostListener);
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800151 hostProvider = hostProviderRegistry.register(this);
Hyunsun Moon2b530322015-09-23 13:24:35 -0700152
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700153 log.info("Started");
154 }
155
156 @Deactivate
157 protected void deactivate() {
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700158 hostService.removeListener(hostListener);
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -0800159 packetService.removeProcessor(packetProcessor);
Hyunsun Moon2b530322015-09-23 13:24:35 -0700160
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700161 eventExecutor.shutdown();
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800162 hostProviderRegistry.unregister(this);
Hyunsun Moon2b530322015-09-23 13:24:35 -0700163
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700164 log.info("Stopped");
165 }
166
167 @Override
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800168 public void triggerProbe(Host host) {
169 /*
170 * Note: In CORD deployment, we assume that all hosts are configured.
171 * Therefore no probe is required.
172 */
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800173 }
174
175 @Override
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800176 public void createServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId) {
177 CordService tService = getCordService(tServiceId);
178 CordService pService = getCordService(pServiceId);
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800179
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800180 if (tService == null || pService == null) {
181 log.error("Failed to create CordService for {}", tServiceId.id());
182 return;
183 }
184
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800185 log.info("Service dependency from {} to {} created.", tService.id().id(), pService.id().id());
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800186 ruleInstaller.populateServiceDependencyRules(tService, pService);
Hyunsun Moon699f46b2015-12-04 11:35:25 -0800187 }
188
189 @Override
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800190 public void removeServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId) {
191 CordService tService = getCordService(tServiceId);
192 CordService pService = getCordService(pServiceId);
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800193
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800194 if (tService == null || pService == null) {
195 log.error("Failed to create CordService for {}", tServiceId.id());
196 return;
197 }
198
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800199 log.info("Service dependency from {} to {} removed.", tService.id().id(), pService.id().id());
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800200 ruleInstaller.removeServiceDependencyRules(tService, pService);
Hyunsun Moon699f46b2015-12-04 11:35:25 -0800201 }
202
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800203 @Override
204 public void addServiceVm(CordVtnNode node, ConnectPoint connectPoint) {
205 Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
206 OpenstackPort vPort = openstackService.port(port);
207 if (vPort == null) {
208 log.warn("Failed to get OpenstackPort for {}", getPortName(port));
Hyunsun Moon8539b042015-11-07 22:08:43 -0800209 return;
210 }
211
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800212 MacAddress mac = vPort.macAddress();
213 HostId hostId = HostId.hostId(mac);
Hyunsun Moon8539b042015-11-07 22:08:43 -0800214
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800215 Host host = hostService.getHost(hostId);
216 if (host != null) {
217 // Host is already known to the system, no HOST_ADDED event is triggered in this case.
218 // It happens when the application is restarted.
219 // TODO check host description if it has all the information
220 serviceVmAdded(host);
Hyunsun Moon8539b042015-11-07 22:08:43 -0800221 return;
222 }
223
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800224 Set<IpAddress> ip = Sets.newHashSet(vPort.fixedIps().values());
225 SparseAnnotations annotations = DefaultAnnotations.builder()
226 .set(OPENSTACK_VM_ID, vPort.deviceId())
227 .set(SERVICE_ID, vPort.networkId())
228 .set(LOCATION_IP, node.localIp().toString())
229 .build();
230
231 HostDescription hostDesc = new DefaultHostDescription(
232 mac,
233 VlanId.NONE,
234 new HostLocation(connectPoint, System.currentTimeMillis()),
235 ip,
236 annotations);
237
238 hostProvider.hostDetected(hostId, hostDesc, false);
Hyunsun Moon8539b042015-11-07 22:08:43 -0800239 }
240
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800241 @Override
242 public void removeServiceVm(ConnectPoint connectPoint) {
243 Host host = hostService.getConnectedHosts(connectPoint)
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800244 .stream()
245 .findFirst()
246 .orElse(null);
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800247
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800248 if (host == null) {
249 log.debug("No host is connected on {}", connectPoint.toString());
250 return;
251 }
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800252
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800253 hostProvider.hostVanished(host.id());
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800254 }
255
256 /**
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800257 * Returns CordService by service ID.
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800258 *
259 * @param serviceId service id
260 * @return cord service, or null if it fails to get network from OpenStack
261 */
262 private CordService getCordService(CordServiceId serviceId) {
263 OpenstackNetwork vNet = openstackService.network(serviceId.id());
264 if (vNet == null) {
265 log.warn("Couldn't find OpenStack network for service {}", serviceId.id());
266 return null;
267 }
268
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800269 OpenstackSubnet subnet = vNet.subnets().stream()
270 .findFirst()
271 .orElse(null);
272 if (subnet == null) {
273 log.warn("Couldn't find OpenStack subnet for service {}", serviceId.id());
274 return null;
275 }
276
277 Set<CordServiceId> tServices = Sets.newHashSet();
278 // TODO get tenant services from XOS
279
280 Map<Host, IpAddress> hosts = getHostsWithOpenstackNetwork(vNet)
281 .stream()
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800282 .collect(Collectors.toMap(host -> host, this::getTunnelIp));
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800283
284 return new CordService(vNet, subnet, hosts, tServices);
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800285 }
286
287 /**
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800288 * Returns CordService by OpenStack network.
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800289 *
290 * @param vNet OpenStack network
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800291 * @return cord service
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800292 */
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800293 private CordService getCordService(OpenstackNetwork vNet) {
294 checkNotNull(vNet);
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800295
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800296 CordServiceId serviceId = CordServiceId.of(vNet.id());
297 OpenstackSubnet subnet = vNet.subnets().stream()
298 .findFirst()
299 .orElse(null);
300 if (subnet == null) {
301 log.warn("Couldn't find OpenStack subnet for service {}", serviceId);
302 return null;
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800303 }
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800304
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800305 Set<CordServiceId> tServices = Sets.newHashSet();
306 // TODO get tenant services from XOS
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800307
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800308 Map<Host, IpAddress> hosts = getHostsWithOpenstackNetwork(vNet)
309 .stream()
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800310 .collect(Collectors.toMap(host -> host, this::getTunnelIp));
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800311
Hyunsun Moonc71231d2015-12-16 20:53:23 -0800312 return new CordService(vNet, subnet, hosts, tServices);
Hyunsun Moon9f0814b2015-11-04 17:34:35 -0800313 }
314
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800315 /**
316 * Returns IP address for tunneling for a given host.
317 *
318 * @param host host
319 * @return ip address
320 */
321 private IpAddress getTunnelIp(Host host) {
322 return IpAddress.valueOf(host.annotations().value(LOCATION_IP));
323 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700324
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800325 /**
326 * Returns port name.
327 *
328 * @param port port
329 * @return port name
330 */
331 private String getPortName(Port port) {
332 return port.annotations().value("portName");
333 }
Hyunsun Moon8539b042015-11-07 22:08:43 -0800334
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800335 /**
336 * Returns hosts associated with a given OpenStack network.
337 *
338 * @param vNet openstack network
339 * @return set of hosts
340 */
341 private Set<Host> getHostsWithOpenstackNetwork(OpenstackNetwork vNet) {
342 checkNotNull(vNet);
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700343
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800344 Set<Host> hosts = openstackService.ports(vNet.id()).stream()
345 .filter(port -> port.deviceOwner().contains("compute"))
346 .map(port -> hostService.getHostsByMac(port.macAddress())
347 .stream()
348 .findFirst()
349 .orElse(null))
350 .collect(Collectors.toSet());
351
352 hosts.remove(null);
353 return hosts;
354 }
355
356 /**
357 * Handles VM detected situation.
358 *
359 * @param host host
360 */
361 private void serviceVmAdded(Host host) {
362 String vNetId = host.annotations().value(SERVICE_ID);
363 OpenstackNetwork vNet = openstackService.network(vNetId);
364 if (vNet == null) {
365 log.warn("Failed to get OpenStack network {} for VM {}({}).",
366 vNetId,
367 host.id(),
368 host.annotations().value(OPENSTACK_VM_ID));
369 return;
370 }
371
372 log.info("VM {} is detected, MAC: {} IP: {}",
373 host.annotations().value(OPENSTACK_VM_ID),
374 host.mac(),
375 host.ipAddresses().stream().findFirst().get());
376
377 CordService service = getCordService(vNet);
378 if (service != null) {
379 // TODO check if the service needs an update on its group buckets after done CORD-433
380 ruleInstaller.updateServiceGroup(service);
381 arpProxy.addServiceIp(service.serviceIp());
382 }
383
384 ruleInstaller.populateBasicConnectionRules(host, getTunnelIp(host), vNet);
385 }
386
387 /**
388 * Handles VM removed situation.
389 *
390 * @param host host
391 */
392 private void serviceVmRemoved(Host host) {
393 String vNetId = host.annotations().value(SERVICE_ID);
394 OpenstackNetwork vNet = openstackService.network(host.annotations().value(SERVICE_ID));
395 if (vNet == null) {
396 log.warn("Failed to get OpenStack network {} for VM {}({}).",
397 vNetId,
398 host.id(),
399 host.annotations().value(OPENSTACK_VM_ID));
400 return;
401 }
402
403 log.info("VM {} is vanished, MAC: {} IP: {}",
404 host.annotations().value(OPENSTACK_VM_ID),
405 host.mac(),
406 host.ipAddresses().stream().findFirst().get());
407
408 ruleInstaller.removeBasicConnectionRules(host);
409
410 CordService service = getCordService(vNet);
411 if (service != null) {
412 // TODO check if the service needs an update on its group buckets after done CORD-433
413 ruleInstaller.updateServiceGroup(service);
414
415 if (getHostsWithOpenstackNetwork(vNet).isEmpty()) {
416 arpProxy.removeServiceIp(service.serviceIp());
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700417 }
418 }
419 }
420
421 private class InternalHostListener implements HostListener {
422
423 @Override
424 public void event(HostEvent event) {
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800425 Host host = event.subject();
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700426
427 switch (event.type()) {
428 case HOST_ADDED:
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800429 eventExecutor.submit(() -> serviceVmAdded(host));
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700430 break;
431 case HOST_REMOVED:
Hyunsun Moonb77b60f2016-01-15 20:03:18 -0800432 eventExecutor.submit(() -> serviceVmRemoved(host));
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700433 break;
434 default:
435 break;
436 }
437 }
438 }
439
Hyunsun Moon42c7b4e2016-01-11 15:30:42 -0800440 private class InternalPacketProcessor implements PacketProcessor {
441
442 @Override
443 public void process(PacketContext context) {
444 if (context.isHandled()) {
445 return;
446 }
447
448 Ethernet ethPacket = context.inPacket().parsed();
449 if (ethPacket == null) {
450 return;
451 }
452
453 if (ethPacket.getEtherType() != Ethernet.TYPE_ARP) {
454 return;
455 }
456
457 arpProxy.processArpPacket(context, ethPacket);
458 }
459 }
Hyunsun Moond0e932a2015-09-15 22:39:16 -0700460}