Added notification for Flow add/delete/update
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / MessageDispatchServiceImpl.java
index 91aab6c6b4549af3f5d2b45558429a08c4a7857f..7f1239b1be4457db3c57dd28935089a0f143fb3b 100644 (file)
@@ -5,11 +5,11 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.Future;
 
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
  import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
-
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
@@ -17,8 +17,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.Upd
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
-
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
@@ -35,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
@@ -42,6 +43,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
@@ -59,7 +62,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
 
     private static final Logger LOG = LoggerFactory.getLogger(MessageDispatchServiceImpl.class);
 
-    private SessionContext session;
+    private SessionContext session;    
 
     /**
      * constructor
@@ -68,13 +71,13 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
      *            - MessageDispatchService for this session
      */
     public MessageDispatchServiceImpl(SessionContext session) {
-        this.session = session;
+        this.session = session;        
     }
 
     /**
      * get proper connection adapter to send the message to switch.
      *
-     * @param cookie to identify the right connection, it can be null also.
+     * @param cookie to identify the right connection, it can be null also.
      * @return connectionAdapter associated with cookie, otherwise return best
      *         suitable connection.
      *
@@ -103,7 +106,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<BarrierOutput>> barrier(BarrierInput input, SwitchConnectionDistinguisher cookie) {
+    public Future<RpcResult<BarrierOutput>> barrier(BarrierInput input, SwitchConnectionDistinguisher cookie) {  
         return getConnectionAdapter(cookie).barrier(input);
     }
 
@@ -114,43 +117,23 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
 
     @Override
     public Future<RpcResult<UpdateFlowOutput>> flowMod(FlowModInput input, SwitchConnectionDistinguisher cookie) {
-        
-        // Set Xid before invoking RPC on OFLibrary
-        // TODO : Cleaner approach is to use a copy constructor once it is implemented 
-        Long Xid = session.getNextXid();
-        FlowModInputBuilder mdInput = new FlowModInputBuilder();
-        mdInput.setXid(Xid);
-        mdInput.setBufferId(input.getBufferId());
-        mdInput.setCommand(input.getCommand());
-        mdInput.setCookie(input.getCookie());
-        mdInput.setCookieMask(input.getCookieMask());
-        mdInput.setFlags(input.getFlags());
-        mdInput.setHardTimeout(input.getHardTimeout());
-        mdInput.setIdleTimeout(input.getHardTimeout());
-        mdInput.setMatch(input.getMatch());
-        mdInput.setOutGroup(input.getOutGroup());
-        mdInput.setOutPort(input.getOutPort());
-        mdInput.setPriority(input.getPriority());
-        mdInput.setTableId(input.getTableId());
-        mdInput.setVersion(input.getVersion());
         LOG.debug("Calling OFLibrary flowMod");
-        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).flowMod(mdInput.build());
-        
+        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).flowMod(input);
+
         // Send the same Xid back to caller - MessageDrivenSwitch
-        UpdateFlowOutputBuilder flowModOutput = new UpdateFlowOutputBuilder();
-        String stringXid =Xid.toString();
-        BigInteger bigIntXid = new BigInteger( stringXid );
+        UpdateFlowOutputBuilder flowModOutput = new UpdateFlowOutputBuilder();        
+        BigInteger bigIntXid = BigInteger.valueOf(input.getXid()) ;
         flowModOutput.setTransactionId(new TransactionId(bigIntXid));
-        
+
         UpdateFlowOutput result = flowModOutput.build();
         Collection<RpcError> errors = Collections.emptyList();
         RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
-        
+
         // solution 1: sending directly and hooking listener to get error
         // hookup listener to catch the possible error with no reference to returned future-object
         LOG.debug("Returning to ModelDrivenSwitch for flowMod RPC");
         return Futures.immediateFuture(rpcResult);
-        
+
     }
 
     @Override
@@ -175,68 +158,50 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<UpdateGroupOutput>> groupMod(GroupModInput input, SwitchConnectionDistinguisher cookie) {
-        
-        // Set Xid before invoking RPC on OFLibrary
-        // TODO : Cleaner approach is to use a copy constructor once it is implemented
-        Long Xid = session.getNextXid();
-        GroupModInputBuilder mdInput = new GroupModInputBuilder();
-        mdInput.setXid(Xid);
-        mdInput.setBucketsList(input.getBucketsList());
-        mdInput.setCommand(input.getCommand());
-        mdInput.setGroupId(input.getGroupId());
-        mdInput.setType(input.getType());
-        mdInput.setVersion(input.getVersion());
+    public Future<RpcResult<UpdateGroupOutput>> groupMod(GroupModInput input, SwitchConnectionDistinguisher cookie) {        
         LOG.debug("Calling OFLibrary groupMod");
-        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).groupMod(mdInput.build());
-        
+        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).groupMod(input);
+
         // Send the same Xid back to caller - MessageDrivenSwitch
-        UpdateGroupOutputBuilder groupModOutput = new UpdateGroupOutputBuilder();
-        String stringXid =Xid.toString();
-        BigInteger bigIntXid = new BigInteger( stringXid );
+        UpdateGroupOutputBuilder groupModOutput = new UpdateGroupOutputBuilder();      
+        BigInteger bigIntXid = BigInteger.valueOf(input.getXid());
         groupModOutput.setTransactionId(new TransactionId(bigIntXid));
+       
         UpdateGroupOutput result = groupModOutput.build();
         Collection<RpcError> errors = Collections.emptyList();
         RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
-        
+
         // solution 1: sending directly and hooking listener to get error
         // hookup listener to catch the possible error with no reference to returned future-object
         LOG.debug("Returning to ModelDrivenSwitch for groupMod RPC");
         return Futures.immediateFuture(rpcResult);
-        
+
     }
 
     @Override
     public Future<RpcResult<UpdateMeterOutput>> meterMod(MeterModInput input, SwitchConnectionDistinguisher cookie) {
-        
-        // Set Xid before invoking RPC on OFLibrary
-        // TODO : Cleaner approach is to use a copy constructor once it is implemented
-        Long Xid = session.getNextXid();
-        MeterModInputBuilder mdInput = new MeterModInputBuilder();
-        mdInput.setXid(Xid);
-        mdInput.setBands(input.getBands());
-        mdInput.setCommand(input.getCommand());
-        mdInput.setFlags(input.getFlags());
-        mdInput.setMeterId(input.getMeterId());
-        mdInput.setVersion(input.getVersion());
-        mdInput.setVersion(input.getVersion());
         LOG.debug("Calling OFLibrary meterMod");
-        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).meterMod(mdInput.build());
-        
+        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).meterMod(input);
+
         // Send the same Xid back to caller - MessageDrivenSwitch
-        UpdateMeterOutputBuilder meterModOutput = new UpdateMeterOutputBuilder();
-        String stringXid =Xid.toString();
-        BigInteger bigIntXid = new BigInteger( stringXid );
+        UpdateMeterOutputBuilder meterModOutput = new UpdateMeterOutputBuilder();       
+        BigInteger bigIntXid =BigInteger.valueOf(input.getXid());
         meterModOutput.setTransactionId(new TransactionId(bigIntXid));
+        
         UpdateMeterOutput result = meterModOutput.build();
         Collection<RpcError> errors = Collections.emptyList();
         RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
-        
+
         // solution 1: sending directly and hooking listener to get error
         // hookup listener to catch the possible error with no reference to returned future-object
         LOG.debug("Returning to ModelDrivenSwitch for meterMod RPC");
         return Futures.immediateFuture(rpcResult);
-        
+
+    }
+
+    @Override
+    public Future<RpcResult<java.lang.Void>> multipartRequest(MultipartRequestInput input, SwitchConnectionDistinguisher cookie) {
+        return getConnectionAdapter(cookie).multipartRequest(input);
     }
 
     @Override
@@ -245,8 +210,22 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<Void>> portMod(PortModInput input, SwitchConnectionDistinguisher cookie) {
-        return getConnectionAdapter(cookie).portMod(input);
+    public Future<RpcResult<UpdatePortOutput>> portMod(PortModInput input, SwitchConnectionDistinguisher cookie) {
+
+        LOG.debug("Calling OFLibrary portMod");
+        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).portMod(input);
+
+        // Send the same Xid back to caller - ModelDrivenSwitch
+        UpdatePortOutputBuilder portModOutput = new UpdatePortOutputBuilder();
+        String stringXid =input.getXid().toString();
+        BigInteger bigIntXid = new BigInteger( stringXid );
+        portModOutput.setTransactionId(new TransactionId(bigIntXid));
+        UpdatePortOutput result = portModOutput.build();
+        Collection<RpcError> errors = Collections.emptyList();
+        RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
+
+        LOG.debug("Returning to ModelDrivenSwitch for portMod RPC");
+        return Futures.immediateFuture(rpcResult);
     }
 
     @Override
@@ -268,5 +247,4 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     public Future<RpcResult<Void>> tableMod(TableModInput input, SwitchConnectionDistinguisher cookie) {
         return getConnectionAdapter(cookie).tableMod(input);
     }
-
 }