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;
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
12 import org.opendaylight.l2switch.flow.FlowWriterServiceImpl;
13 import org.opendaylight.l2switch.flow.InitialFlowWriter;
14 import org.opendaylight.l2switch.flow.ReactiveFlowWriter;
15 import org.opendaylight.l2switch.inventory.InventoryReader;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2switch.l2switch.config.rev140528.L2switchConfig;
18 import org.opendaylight.yangtools.concepts.Registration;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class L2SwitchMainProvider {
23 private static final Logger LOG = LoggerFactory.getLogger(L2SwitchMainProvider.class);
24 private Registration topoNodeListherReg;
25 private Registration reactFlowWriterReg;
27 private final DataBroker dataService;
28 private final NotificationProviderService notificationService;
29 private final SalFlowService salFlowService;
30 private final L2switchConfig mainConfig;
32 public L2SwitchMainProvider(final DataBroker dataBroker,
33 final NotificationProviderService notificationService,
34 final SalFlowService salFlowService, final L2switchConfig config) {
35 this.dataService = dataBroker;
36 this.notificationService = notificationService;
37 this.salFlowService = salFlowService;
38 this.mainConfig = config;
42 // Setup FlowWrtierService
43 FlowWriterServiceImpl flowWriterService = new FlowWriterServiceImpl(salFlowService);
44 flowWriterService.setFlowTableId(mainConfig.getReactiveFlowTableId());
45 flowWriterService.setFlowPriority(mainConfig.getReactiveFlowPriority());
46 flowWriterService.setFlowIdleTimeout(mainConfig.getReactiveFlowIdleTimeout());
47 flowWriterService.setFlowHardTimeout(mainConfig.getReactiveFlowHardTimeout());
49 // Setup InventoryReader
50 InventoryReader inventoryReader = new InventoryReader(dataService);
52 // Write initial flows
53 if (mainConfig.isIsInstallDropallFlow()) {
54 LOG.info("L2Switch will install a dropall flow on each switch");
55 InitialFlowWriter initialFlowWriter = new InitialFlowWriter(salFlowService);
56 initialFlowWriter.setFlowTableId(mainConfig.getDropallFlowTableId());
57 initialFlowWriter.setFlowPriority(mainConfig.getDropallFlowPriority());
58 initialFlowWriter.setFlowIdleTimeout(mainConfig.getDropallFlowIdleTimeout());
59 initialFlowWriter.setFlowHardTimeout(mainConfig.getDropallFlowHardTimeout());
60 topoNodeListherReg = initialFlowWriter.registerAsDataChangeListener(dataService);
63 LOG.info("Dropall flows will not be installed");
66 if (mainConfig.isIsLearningOnlyMode()) {
67 LOG.info("L2Switch is in Learning Only Mode");
70 // Setup reactive flow writer
71 LOG.info("L2Switch will react to network traffic and install flows");
72 ReactiveFlowWriter reactiveFlowWriter = new ReactiveFlowWriter(inventoryReader, flowWriterService);
73 reactFlowWriterReg = notificationService.registerNotificationListener(reactiveFlowWriter);
76 LOG.info("L2SwitchMain initialized.");
80 if (reactFlowWriterReg != null) {
81 reactFlowWriterReg.close();
84 if (topoNodeListherReg != null) {
85 topoNodeListherReg.close();
87 LOG.info("L2SwitchMain (instance {}) torn down.", this);