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
9 package org.opendaylight.groupbasedpolicy.renderer.opflex;
11 import java.util.concurrent.Executors;
12 import java.util.concurrent.ScheduledExecutorService;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
16 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
17 import org.opendaylight.groupbasedpolicy.renderer.opflex.lib.OpflexConnectionService;
18 import org.opendaylight.groupbasedpolicy.renderer.opflex.mit.AgentOvsMit;
19 import org.opendaylight.groupbasedpolicy.renderer.opflex.mit.MitLib;
20 import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Renderer that uses OpFlex to implement an overlay network
31 public class OpflexRenderer implements AutoCloseable {
33 private static final Logger LOG = LoggerFactory.getLogger(OpflexRenderer.class);
35 private final PolicyResolver policyResolver;
36 private final EndpointManager endpointManager;
37 private final PolicyManager policyManager;
38 private final OpflexConnectionService connectionService;
39 private final MitLib mitLibrary;
40 private final ScheduledExecutorService executor;
42 ListenerRegistration<DataChangeListener> configReg;
44 public OpflexRenderer(DataBroker dataProvider, RpcProviderRegistry rpcRegistry) {
47 int numCPU = Runtime.getRuntime().availableProcessors();
48 executor = Executors.newScheduledThreadPool(numCPU * 2);
50 mitLibrary = new MitLib();
51 MessageUtils.setOpflexLib(mitLibrary);
53 MessageUtils.setMit(new AgentOvsMit());
55 connectionService = new OpflexConnectionService(dataProvider, executor);
57 endpointManager = new EndpointManager(dataProvider, rpcRegistry, executor, connectionService, mitLibrary);
58 policyResolver = new PolicyResolver(dataProvider, executor);
60 policyManager = new PolicyManager(policyResolver, connectionService, executor, mitLibrary);
62 LOG.info("Initialized OpFlex renderer");
70 public void close() throws Exception {
71 executor.shutdownNow();
72 if (configReg != null)
74 if (policyResolver != null)
75 policyResolver.close();
76 if (policyManager != null)
77 policyManager.close();
78 if (connectionService != null)
79 connectionService.close();
80 if (endpointManager != null)
81 endpointManager.close();