2 * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. 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.vpnservice.mdsalutil.internal;
10 import java.math.BigInteger;
12 import java.util.List;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
20 import org.opendaylight.vpnservice.mdsalutil.ActionInfo;
21 import org.opendaylight.vpnservice.mdsalutil.FlowEntity;
22 import org.opendaylight.vpnservice.mdsalutil.GroupEntity;
23 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.opendaylight.vpnservice.mdsalutil.FlowEntity;
29 import org.opendaylight.vpnservice.mdsalutil.GroupEntity;
31 public class MDSALUtilProvider implements BindingAwareConsumer, IMdsalApiManager, AutoCloseable {
33 private static final Logger s_logger = LoggerFactory.getLogger(MDSALUtilProvider.class);
34 private MDSALManager mdSalMgr;
35 private static final long FIXED_DELAY_IN_MILLISECONDS = 5000;
38 public void onSessionInitialized(ConsumerContext session) {
40 s_logger.info( " Session Initiated for MD SAL Util Provider") ;
43 final DataBroker dataBroker;
44 final PacketProcessingService packetProcessingService;
45 dataBroker = session.getSALService(DataBroker.class);
46 packetProcessingService = session.getRpcService(PacketProcessingService.class);
47 mdSalMgr = new MDSALManager( dataBroker, packetProcessingService) ;
48 }catch( Exception e) {
49 s_logger.error( "Error initializing MD SAL Util Services " + e );
55 public void close() throws Exception {
57 s_logger.info("MDSAL Manager Closed");
62 public void installFlow(FlowEntity flowEntity) {
63 mdSalMgr.installFlow(flowEntity);
67 public CheckedFuture<Void, TransactionCommitFailedException> installFlow(BigInteger dpId, Flow flowEntity) {
68 return mdSalMgr.installFlow(dpId, flowEntity);
72 public CheckedFuture<Void, TransactionCommitFailedException> installFlow(BigInteger dpId, FlowEntity flowEntity) {
73 return mdSalMgr.installFlow(dpId, flowEntity.getFlowBuilder().build());
77 public CheckedFuture<Void, TransactionCommitFailedException> removeFlow(BigInteger dpId, Flow flowEntity) {
78 return mdSalMgr.removeFlowNew(dpId, flowEntity);
82 public CheckedFuture<Void, TransactionCommitFailedException> removeFlow(BigInteger dpId, FlowEntity flowEntity) {
83 return mdSalMgr.removeFlowNew(dpId, flowEntity.getFlowBuilder().build());
87 public void removeFlow(FlowEntity flowEntity) {
88 mdSalMgr.removeFlow(flowEntity);
92 public void installGroup(GroupEntity groupEntity) {
93 mdSalMgr.installGroup(groupEntity);
98 public void modifyGroup(GroupEntity groupEntity) {
99 mdSalMgr.modifyGroup(groupEntity);
104 public void removeGroup(GroupEntity groupEntity) {
105 mdSalMgr.removeGroup(groupEntity);
110 public void sendPacketOut(BigInteger dpnId, int groupId, byte[] payload) {
111 mdSalMgr.sendPacketOut(dpnId, groupId, payload);
116 public void sendPacketOutWithActions(BigInteger dpnId, long groupId,
117 byte[] payload, List<ActionInfo> actionInfos) {
118 mdSalMgr.sendPacketOutWithActions(dpnId, groupId, payload, actionInfos);
123 public void sendARPPacketOutWithActions(BigInteger dpnId, byte[] payload,
124 List<ActionInfo> action_info) {
125 mdSalMgr.sendARPPacketOutWithActions(dpnId, payload, action_info);
129 public void syncRemoveFlow(FlowEntity flowEntity, long delayTime) {
130 mdSalMgr.syncSetUpFlow(flowEntity, delayTime, true);
134 public void syncInstallGroup(GroupEntity groupEntity, long delayTime) {
135 mdSalMgr.syncSetUpGroup(groupEntity, delayTime, false);
139 public void syncRemoveGroup(GroupEntity groupEntity) {
140 mdSalMgr.syncSetUpGroup(groupEntity, FIXED_DELAY_IN_MILLISECONDS, true);