2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.l2switch.packethandler;
10 import com.google.common.collect.ImmutableSet;
11 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.l2switch.packethandler.decoders.AbstractPacketDecoder;
15 import org.opendaylight.l2switch.packethandler.decoders.ArpDecoder;
16 import org.opendaylight.l2switch.packethandler.decoders.EthernetDecoder;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * PacketHandlerProvider serves as the Activator for our L2Switch OSGI bundle.
23 public class PacketHandlerProvider extends AbstractBindingAwareProvider
24 implements AutoCloseable {
26 private final static Logger _logger = LoggerFactory.getLogger(PacketHandlerProvider.class);
28 ImmutableSet<AbstractPacketDecoder> decoders;
32 * Setup the packet handler.
34 * @param providerContext The context of the L2Switch.
37 public void onSessionInitiated(BindingAwareBroker.ProviderContext providerContext) {
39 NotificationProviderService notificationProviderService =
40 providerContext.<NotificationProviderService>getSALService(NotificationProviderService.class);
42 initiateDecoders(notificationProviderService);
47 * Cleanup the packet handler..
49 * @throws Exception occurs when the NotificationListener is closed
52 public void close() throws Exception {
56 private void initiateDecoders(NotificationProviderService notificationProviderService) {
57 decoders = new ImmutableSet.Builder<AbstractPacketDecoder>()
58 .add(new EthernetDecoder(notificationProviderService))
59 .add(new ArpDecoder(notificationProviderService))
63 private void closeDecoders() throws Exception {
64 if(decoders != null && !decoders.isEmpty()) {
65 for(AbstractPacketDecoder decoder : decoders) {