Fix a typo
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / MessageDispatchServiceImpl.java
index ec6681b359f7ac5f125f64a940ddd055795e9e46..0f127e83389f17a755aea4e92d2c9c149914d3dd 100644 (file)
@@ -1,3 +1,10 @@
+/**
+ * Copyright IBM Corporation, 2013.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
 import java.math.BigInteger;
@@ -5,7 +12,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.Future;
 
- import org.opendaylight.controller.sal.common.util.Rpcs;
+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;
@@ -17,11 +24,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.Upd
 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;
-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;
@@ -31,9 +36,7 @@ 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.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;
@@ -61,7 +64,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
 
     private static final Logger LOG = LoggerFactory.getLogger(MessageDispatchServiceImpl.class);
 
-    private SessionContext session;
+    private SessionContext session;    
 
     /**
      * constructor
@@ -70,7 +73,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
      *            - MessageDispatchService for this session
      */
     public MessageDispatchServiceImpl(SessionContext session) {
-        this.session = session;
+        this.session = session;        
     }
 
     /**
@@ -86,7 +89,8 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
 
         if (!session.isValid()) {
             LOG.warn("Session for the cookie {} is invalid.", cookie);
-            throw new IllegalArgumentException("Session for the cookie is invalid.");
+            throw new IllegalArgumentException("Session for the cookie is invalid. Reason: "
+                    + "the switch has been recently disconnected OR inventory provides outdated information.");
         }
         LOG.debug("finding connecton for cookie value {}. ", cookie);
         // set main connection as default
@@ -105,11 +109,8 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<BarrierOutput>> barrier(BarrierInput input, SwitchConnectionDistinguisher cookie) {
-        Long Xid = session.getNextXid();
-        BarrierInputBuilder inputBuilder = new BarrierInputBuilder(input);        
-        inputBuilder.setXid(Xid);
-        return getConnectionAdapter(cookie).barrier(inputBuilder.build());
+    public Future<RpcResult<BarrierOutput>> barrier(BarrierInput input, SwitchConnectionDistinguisher cookie) {  
+        return getConnectionAdapter(cookie).barrier(input);
     }
 
     @Override
@@ -119,19 +120,12 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
 
     @Override
     public Future<RpcResult<UpdateFlowOutput>> flowMod(FlowModInput input, SwitchConnectionDistinguisher cookie) {
-
-        // Set Xid before invoking RPC on OFLibrary
-        // TODO : let caller set xid, in that case it will not be required to create FlowModInput again here to set xid 
-        Long Xid = session.getNextXid();
-        FlowModInputBuilder mdInput = new FlowModInputBuilder(input);
-        mdInput.setXid(Xid);
         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();
@@ -167,20 +161,13 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
     }
 
     @Override
-    public Future<RpcResult<UpdateGroupOutput>> groupMod(GroupModInput input, SwitchConnectionDistinguisher cookie) {
-
-        // Set Xid before invoking RPC on OFLibrary
-        // TODO : let caller set xid, in that case it will not be required to create object again here to set xid 
-        Long Xid = session.getNextXid();
-        GroupModInputBuilder mdInput = new GroupModInputBuilder(input);
-        mdInput.setXid(Xid);
+    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();
@@ -196,19 +183,12 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService {
 
     @Override
     public Future<RpcResult<UpdateMeterOutput>> meterMod(MeterModInput input, SwitchConnectionDistinguisher cookie) {
-
-        // Set Xid before invoking RPC on OFLibrary
-     // TODO : let caller set xid, in that case it will not be required to create MeterModInput again here to set xid 
-        Long Xid = session.getNextXid();
-        MeterModInputBuilder mdInput = new MeterModInputBuilder(input);
-        mdInput.setXid(Xid);
         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();