Implemented Port RPC 64/3164/1
authorHemaTG <hema.gopalkrishnan@ericsson.com>
Thu, 28 Nov 2013 05:24:53 +0000 (10:54 +0530)
committerHemaTG <hema.gopalkrishnan@ericsson.com>
Thu, 28 Nov 2013 05:24:53 +0000 (10:54 +0530)
Signed-off-by: HemaTG <hema.gopalkrishnan@ericsson.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/ModelDrivenSwitch.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.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

index 624006ef52e20d932fc541a2be3cd60c1af4c522..32b839a195db9985615e8f8ae5faf8be259bbcb6 100644 (file)
@@ -30,6 +30,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Upd
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -39,6 +43,7 @@ public interface ModelDrivenSwitch extends //
         SalGroupService, //
         SalFlowService, //
         SalMeterService, //
+        SalPortService, //
         PacketProcessingService, //
         OpendaylightGroupStatisticsService,
         OpendaylightMeterStatisticsService,
@@ -80,4 +85,10 @@ public interface ModelDrivenSwitch extends //
 
     @Override
     public Future<RpcResult<UpdateMeterOutput>> updateMeter(UpdateMeterInput input);
+    
+    @Override
+    public Future<RpcResult<GetPortOutput>> getPort();
+    
+    @Override
+    public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input);
 }
index 03a1cfb65be0cad1b2e5282f280b5a8033288dc6..38905f67c239974647433eb7352c50599ae58ef9 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistingu
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
@@ -32,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Upda
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
@@ -86,6 +88,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupBuilder;
@@ -95,6 +99,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
+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.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -780,4 +788,76 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
         return new TransactionId(bigIntXid);
 
     }
+
+       @Override
+       public Future<RpcResult<GetPortOutput>> getPort() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Future<RpcResult<UpdatePortOutput>> updatePort(UpdatePortInput input) {
+               PortModInput ofPortModInput = null ;
+               RpcResult<UpdatePortOutput> rpcResultFromOFLib = null ;
+               
+                               
+               // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so  
+       // the request can be routed through any connection to the switch
+       
+       SwitchConnectionDistinguisher cookie = null ;
+       
+               // NSF sends a list of port and the ModelDrivenSwitch will 
+       // send one port at a time towards the switch ( mutiple RPCs calls)
+               List<Port> inputPorts = input.getUpdatedPort().getPort().getPort() ;
+               
+               // Get the Xid. The same Xid has to be sent in all the RPCs
+               Long Xid = sessionContext.getNextXid();
+               
+               for( Port inputPort : inputPorts) {
+                  
+                       // Convert the UpdateGroupInput to GroupModInput 
+                               ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ;
+                                                       
+                               // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary
+                       
+                       PortModInputBuilder mdInput = new PortModInputBuilder();
+                       mdInput.setXid(Xid);
+                       mdInput.setVersion(ofPortModInput.getVersion()) ;
+                       mdInput.setPortNo(ofPortModInput.getPortNo()) ;
+                       mdInput.setMaskV10(ofPortModInput.getMaskV10()) ;
+                       mdInput.setMask(ofPortModInput.getMask()) ;
+                       mdInput.setHwAddress(ofPortModInput.getHwAddress());
+                       mdInput.setConfigV10(ofPortModInput.getConfigV10()) ;
+                       mdInput.setConfig(ofPortModInput.getConfig()) ;
+                       mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ;
+                       mdInput.setAdvertise(ofPortModInput.getAdvertise()) ;
+                       
+                       LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
+                       Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ;
+                                       
+                       try { 
+                               rpcResultFromOFLib = resultFromOFLib.get();
+                       } catch( Exception ex ) {
+                               LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage());
+                       }
+                       
+                       // The Future response value for all the RPCs except the last one is ignored
+                       
+               }
+                       
+                               //Extract the Xid only from the Future for the last RPC and
+                               // send it back to the NSF
+                       UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ;
+                       
+                       UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ;
+                       updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ;
+                       UpdatePortOutput result = updatePortOutput.build();
+                       
+                       Collection<RpcError> errors = rpcResultFromOFLib.getErrors() ;
+                       RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors); 
+                       
+                       LOG.debug("Returning the Update Group RPC result to MD-SAL");
+                       return Futures.immediateFuture(rpcResult);
+       
+       }
 }
index d4529f3bfbf643e9c7dcb5711960273f82d915bb..864153d1e20d4175a88017c16b8edb010a0c71ef 100644 (file)
@@ -26,6 +26,7 @@ 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.flow.service.rev130819.UpdateFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -181,7 +182,7 @@ public interface IMessageDispatchService {
      *            any connection
      * @return - the future
      */
-    Future<RpcResult<java.lang.Void>> portMod(PortModInput input, SwitchConnectionDistinguisher cookie);
+    Future<RpcResult<UpdatePortOutput>> portMod(PortModInput input, SwitchConnectionDistinguisher cookie);
 
     /**
      * send role request message to switch
index 3ea8b413d8eda3dfa749449b913d071c7d8a13ec..42cbac04a3a003a9821238a6c67ad290c34456f8 100644 (file)
@@ -41,6 +41,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;
@@ -249,8 +251,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