2 * Copyright (c) 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.genius.mdsalutil.internal;
10 import com.google.common.util.concurrent.CheckedFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
16 import org.opendaylight.genius.mdsalutil.ActionInfo;
17 import org.opendaylight.genius.mdsalutil.FlowEntity;
18 import org.opendaylight.genius.mdsalutil.GroupEntity;
19 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import java.math.BigInteger;
27 import java.util.List;
29 public class MDSALUtilProvider implements BindingAwareConsumer, IMdsalApiManager, AutoCloseable {
31 private static final Logger s_logger = LoggerFactory.getLogger(MDSALUtilProvider.class);
32 private MDSALManager mdSalMgr;
33 private static final long FIXED_DELAY_IN_MILLISECONDS = 5000;
36 public void onSessionInitialized(ConsumerContext session) {
38 s_logger.info( " Session Initiated for MD SAL Util Provider") ;
41 final DataBroker dataBroker;
42 final PacketProcessingService packetProcessingService;
43 dataBroker = session.getSALService(DataBroker.class);
44 packetProcessingService = session.getRpcService(PacketProcessingService.class);
45 mdSalMgr = new MDSALManager( dataBroker, packetProcessingService) ;
46 }catch( Exception e) {
47 s_logger.error( "Error initializing MD SAL Util Services " + e );
53 public void close() throws Exception {
55 s_logger.info("MDSAL Manager Closed");
60 public void installFlow(FlowEntity flowEntity) {
61 mdSalMgr.installFlow(flowEntity);
65 public CheckedFuture<Void, TransactionCommitFailedException> installFlow(BigInteger dpId, Flow flowEntity) {
66 return mdSalMgr.installFlow(dpId, flowEntity);
70 public CheckedFuture<Void, TransactionCommitFailedException> installFlow(BigInteger dpId, FlowEntity flowEntity) {
71 return mdSalMgr.installFlow(dpId, flowEntity.getFlowBuilder().build());
75 public CheckedFuture<Void, TransactionCommitFailedException> removeFlow(BigInteger dpId, Flow flowEntity) {
76 return mdSalMgr.removeFlowNew(dpId, flowEntity);
80 public CheckedFuture<Void, TransactionCommitFailedException> removeFlow(BigInteger dpId, FlowEntity flowEntity) {
81 return mdSalMgr.removeFlowNew(dpId, flowEntity.getFlowBuilder().build());
85 public void removeFlow(FlowEntity flowEntity) {
86 mdSalMgr.removeFlow(flowEntity);
90 public void installGroup(GroupEntity groupEntity) {
91 mdSalMgr.installGroup(groupEntity);
95 public void modifyGroup(GroupEntity groupEntity) {
96 mdSalMgr.modifyGroup(groupEntity);
101 public void removeGroup(GroupEntity groupEntity) {
102 mdSalMgr.removeGroup(groupEntity);
106 public void sendPacketOut(BigInteger dpnId, int groupId, byte[] payload) {
107 mdSalMgr.sendPacketOut(dpnId, groupId, payload);
112 public void sendPacketOutWithActions(BigInteger dpnId, long groupId,
113 byte[] payload, List<ActionInfo> actionInfos) {
114 mdSalMgr.sendPacketOutWithActions(dpnId, groupId, payload, actionInfos);
119 public void sendARPPacketOutWithActions(BigInteger dpnId, byte[] payload,
120 List<ActionInfo> action_info) {
121 mdSalMgr.sendARPPacketOutWithActions(dpnId, payload, action_info);
125 public void syncRemoveFlow(FlowEntity flowEntity, long delayTime) {
126 mdSalMgr.syncSetUpFlow(flowEntity, delayTime, true);
130 public void syncInstallFlow(FlowEntity flowEntity, long delayTime) {
131 mdSalMgr.syncSetUpFlow(flowEntity, delayTime, false);
135 public void syncInstallGroup(GroupEntity groupEntity, long delayTime) {
136 mdSalMgr.syncSetUpGroup(groupEntity, delayTime, false);
140 public void syncInstallGroup(BigInteger dpId, Group group, long delayTime) {
141 mdSalMgr.syncSetUpGroup(dpId, group, delayTime, false);
145 public void syncRemoveGroup(GroupEntity groupEntity) {
146 mdSalMgr.syncSetUpGroup(groupEntity, FIXED_DELAY_IN_MILLISECONDS, true);
150 public void syncRemoveGroup(BigInteger dpId, Group group) {
151 mdSalMgr.syncSetUpGroup(dpId, group, FIXED_DELAY_IN_MILLISECONDS, true);
155 public void addFlowToTx(FlowEntity flowEntity, WriteTransaction tx) {
156 mdSalMgr.writeFlowEntity(flowEntity, tx);
160 public void addFlowToTx(BigInteger dpId, Flow flow, WriteTransaction tx) {
161 mdSalMgr.writeFlow(dpId, flow, tx);
165 public void removeFlowToTx(BigInteger dpId, Flow flow, WriteTransaction tx) {
166 mdSalMgr.deleteFlow(dpId, flow, tx);
170 public void removeFlowToTx(FlowEntity flowEntity, WriteTransaction tx) {
171 mdSalMgr.deleteFlowEntity(flowEntity, tx);
175 public void addGroupToTx(GroupEntity groupEntity, WriteTransaction tx) {
176 mdSalMgr.writeGroupEntity(groupEntity, tx);
180 public void addGroupToTx(BigInteger dpId, Group group, WriteTransaction tx) {
181 mdSalMgr.writeGroup(dpId, group, tx);;
185 public void removeGroupToTx(GroupEntity groupEntity, WriteTransaction tx) {
186 mdSalMgr.removeGroupEntity(groupEntity, tx);
190 public void removeGroupToTx(BigInteger dpId, Group group, WriteTransaction tx) {
191 mdSalMgr.deleteGroup(dpId, group, tx);