Inserting Xid for RPC calls FlowMod, GroupMod and MeterMod 97/2697/7
authorYugandhar <ysarraju@in.ibm.com>
Wed, 13 Nov 2013 09:15:41 +0000 (14:45 +0530)
committerMichal Rehak <mirehak@cisco.com>
Thu, 14 Nov 2013 16:48:51 +0000 (17:48 +0100)
fixed rpc return types

Change-Id: I1c7b9b302d38fba3ed7bafee47b0188acacb13c2
Signed-off-by: Yugandhar <ysarraju@in.ibm.com>
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/pom.xml
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/ModelDrivenSwitch.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/IMessageDispatchService.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImpl.java
samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewall.java
samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewallCli.java

index 55fd5d2f500e68960c663b23ce0ecbf620885ed7..49126b12c97aa8fe04b7a783ca08874611c7f6ba 100644 (file)
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-common-util</artifactId>
             <version>${yang.prototype.version}</version>
-            <scope>test</scope>
         </dependency>
     </dependencies>
 </project>
index 628d533cc62db665498661836dca852de412639b..c52c0cf0106e21749dbea32cbdd92364de8dc57f 100644 (file)
@@ -7,11 +7,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddF
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
-
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
-
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
index 504596ae3f1958eeb0836145f073033673b8395d..304a13ccf8b1d636baae18f073fbdf63bfd42ff1 100644 (file)
@@ -3,6 +3,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.session;
 import java.util.concurrent.Future;
 
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
@@ -24,6 +25,10 @@ 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.flow.service.rev130819.UpdateFlowOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
+
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 /**
@@ -68,7 +73,7 @@ public interface IMessageDispatchService {
      *            any connection
      * @return - the future
      */
-    Future<RpcResult<java.lang.Void>> flowMod(FlowModInput input, SwitchConnectionDistinguisher cookie);
+    Future<RpcResult<UpdateFlowOutput>> flowMod(FlowModInput input, SwitchConnectionDistinguisher cookie);
 
     /**
      * send get async message to switch
@@ -129,7 +134,7 @@ public interface IMessageDispatchService {
      *            any connection
      * @return - the future
      */
-    Future<RpcResult<java.lang.Void>> groupMod(GroupModInput input, SwitchConnectionDistinguisher cookie);
+    Future<RpcResult<UpdateGroupOutput>> groupMod(GroupModInput input, SwitchConnectionDistinguisher cookie);
 
     /**
      * send meter modification message to switch
@@ -141,7 +146,7 @@ public interface IMessageDispatchService {
      *            any connection
      * @return - the future
      */
-    Future<RpcResult<java.lang.Void>> meterMod(MeterModInput input, SwitchConnectionDistinguisher cookie);
+    Future<RpcResult<UpdateMeterOutput>> meterMod(MeterModInput input, SwitchConnectionDistinguisher cookie);
 
     /**
      * send packet out message to switch
index 7d8f43cdbbf2968e9bb3f343f4de99ba4170177e..91aab6c6b4549af3f5d2b45558429a08c4a7857f 100644 (file)
@@ -1,14 +1,28 @@
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
+import java.math.BigInteger;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.concurrent.Future;
 
+ 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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
+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.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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;
@@ -18,7 +32,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
+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.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;
@@ -26,10 +42,13 @@ 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.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.util.concurrent.Futures;
+
 /**
  * message dispatch service to send the message to switch.
  *
@@ -94,8 +113,44 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<Void>> flowMod(FlowModInput input, SwitchConnectionDistinguisher cookie) {
-        return getConnectionAdapter(cookie).flowMod(input);
+    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());
+        
+        // Send the same Xid back to caller - MessageDrivenSwitch
+        UpdateFlowOutputBuilder flowModOutput = new UpdateFlowOutputBuilder();
+        String stringXid =Xid.toString();
+        BigInteger bigIntXid = new BigInteger( stringXid );
+        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
@@ -120,13 +175,68 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<Void>> groupMod(GroupModInput input, SwitchConnectionDistinguisher cookie) {
-        return getConnectionAdapter(cookie).groupMod(input);
+    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());
+        LOG.debug("Calling OFLibrary groupMod");
+        Future<RpcResult<Void>> response = getConnectionAdapter(cookie).groupMod(mdInput.build());
+        
+        // Send the same Xid back to caller - MessageDrivenSwitch
+        UpdateGroupOutputBuilder groupModOutput = new UpdateGroupOutputBuilder();
+        String stringXid =Xid.toString();
+        BigInteger bigIntXid = new BigInteger( stringXid );
+        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<Void>> meterMod(MeterModInput input, SwitchConnectionDistinguisher cookie) {
-        return getConnectionAdapter(cookie).meterMod(input);
+    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());
+        
+        // Send the same Xid back to caller - MessageDrivenSwitch
+        UpdateMeterOutputBuilder meterModOutput = new UpdateMeterOutputBuilder();
+        String stringXid =Xid.toString();
+        BigInteger bigIntXid = new BigInteger( stringXid );
+        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
index b035f3111f7b1f1e24ad7c430c35ea22ce716574..e15f57cb5a99e5dc0feb6f61248cd014d719a670 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
@@ -46,7 +47,7 @@ public class SimpleDropFirewall {
 
     public boolean addFlow(AddFlowInput flow) throws InterruptedException,
             ExecutionException, TimeoutException {
-        Future<RpcResult<Void>> result = flowService.addFlow(flow);
+        Future<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
 
         return result.get(5, TimeUnit.SECONDS).isSuccessful();
     }
index 529ce3e453d86f3f9783dddf4287b3390d122e53..130875304adc6e234e9034d52cece14e31df01b4 100644 (file)
@@ -4,12 +4,12 @@ import java.util.Collections;
 import java.util.List;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.action.action.DropAction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.action.action.DropActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.action.list.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.action.list.ActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsBuilder;