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
30 public class OpflexRenderer implements AutoCloseable {
31 private static final Logger LOG =
32 LoggerFactory.getLogger(OpflexRenderer.class);
34 private final PolicyResolver policyResolver;
35 private final EndpointManager endpointManager;
36 private final PolicyManager policyManager;
37 private final OpflexConnectionService connectionService;
38 private final MitLib mitLibrary;
39 private final ScheduledExecutorService executor;
41 ListenerRegistration<DataChangeListener> configReg;
43 public OpflexRenderer(DataBroker dataProvider,
44 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,
58 executor, connectionService, mitLibrary);
59 policyResolver = new PolicyResolver(dataProvider, executor);
61 policyManager = new PolicyManager(policyResolver,
63 executor, mitLibrary);
66 LOG.info("Initialized OpFlex renderer");
74 public void close() throws Exception {
75 executor.shutdownNow();
76 if (configReg != null) configReg.close();
77 if (policyResolver != null) policyResolver.close();
78 if (policyManager != null) policyManager.close();
79 if (connectionService != null) connectionService.close();
80 if (endpointManager != null) endpointManager.close();