Support for CreatingTerminatingService RPC 92/32392/1
authorHemaTG <hema.gopalkrishnan@ericsson.com>
Tue, 12 Jan 2016 06:44:58 +0000 (12:14 +0530)
committerHemaTG <hema.gopalkrishnan@ericsson.com>
Tue, 12 Jan 2016 06:44:58 +0000 (12:14 +0530)
Change-Id: I77ef819f6c89a4b50f7bb7fd4e291833e9410ba9
Signed-off-by: HemaTG <hema.gopalkrishnan@ericsson.com>
itm/itm-api/src/main/java/org/opendaylight/vpnservice/itm/globals/ITMConstants.java
itm/itm-api/src/main/yang/itm-rpc.yang
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmProvider.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java

index d60c72b7fcd7d198125fb83e1015476251a76d1f..11c6204173f0229fb5ab53343a74caa63ab85c8c 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.vpnservice.itm.globals;
 
  */
 package org.opendaylight.vpnservice.itm.globals;
 
+import java.math.BigInteger;
+
 
 public class ITMConstants{
 
 public class ITMConstants{
-                
+    public static final short INTERNAL_TUNNEL_TABLE = 22;
+    public static final BigInteger COOKIE_ITM = new BigInteger("9000000", 16);
 }
 }
index 83d520938b44f73f57d4d2895e15d2394d7cdfe4..69e1ea9bd8e8111ca46a19f7117f02ea7656b48d 100644 (file)
@@ -19,7 +19,11 @@ module itm-rpc {
         prefix odlif;
         revision-date "2015-03-31";
     }
         prefix odlif;
         revision-date "2015-03-31";
     }
-    
+
+    import opendaylight-action-types {prefix action;revision-date "2013-11-12";}
+    import opendaylight-flow-types {prefix offlow;revision-date "2013-10-26";}
+
+        
     revision "2015-12-17" {
         description "ODL Specific Itm Manager Rpcs Module";
     }
     revision "2015-12-17" {
         description "ODL Specific Itm Manager Rpcs Module";
     }
@@ -120,4 +124,30 @@ module itm-rpc {
             }
         }
      }
             }
         }
      }
+
+     rpc create-terminating-service-actions {
+         description  "used for programming the terminating service actions";
+         input {
+             leaf dpn-id {
+               type uint64;  
+             }
+             leaf service-id {
+                type uint16;
+             }
+             uses offlow:instruction-list;
+         }
+     }
+
+     rpc remove-terminating-service-actions {
+              description  "used for removing the terminating service actions";
+              input {
+                  leaf dpn-id {
+                    type uint64;  
+                  }
+                  leaf service-id {
+                     type uint16;
+                  }
+              }
+     }
+
 }
\ No newline at end of file
 }
\ No newline at end of file
index cba0777e45d16bfa297a0006b453ec1053758af1..b805a629c9bc6b3546a2c226225f26e16f957da9 100644 (file)
@@ -62,7 +62,7 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro
             tzChangeListener = new TransportZoneListener(dataBroker) ;
             itmRpcService = new ItmManagerRpcService(dataBroker);
             final BindingAwareBroker.RpcRegistration<ItmRpcService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
             tzChangeListener = new TransportZoneListener(dataBroker) ;
             itmRpcService = new ItmManagerRpcService(dataBroker);
             final BindingAwareBroker.RpcRegistration<ItmRpcService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
-
+            itmRpcService.setMdsalManager(mdsalManager);
             itmManager.setMdsalManager(mdsalManager);
             itmManager.setNotificationPublishService(notificationPublishService);
             itmManager.setMdsalManager(mdsalManager);
             itmManager.setMdsalManager(mdsalManager);
             itmManager.setNotificationPublishService(notificationPublishService);
             itmManager.setMdsalManager(mdsalManager);
index c3adcc40e2b9255c54844940b04e56d8b7678248..70d8f82c45a789c7ffda0671eb23adcb01b19a6d 100644 (file)
@@ -8,15 +8,21 @@
 package org.opendaylight.vpnservice.itm.rpc;
 
 import java.math.BigInteger;
 package org.opendaylight.vpnservice.itm.rpc;
 
 import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Future;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import java.util.List;
 import java.util.concurrent.Future;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.vpnservice.itm.confighelpers.ItmExternalTunnelAddWorker;
 import org.opendaylight.vpnservice.itm.confighelpers.ItmExternalTunnelAddWorker;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
@@ -26,6 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.AddExternalTunnelEndpointInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.BuildExternalTunnelFromDpnsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.AddExternalTunnelEndpointInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.BuildExternalTunnelFromDpnsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.CreateTerminatingServiceActionsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutputBuilder;
@@ -35,6 +42,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev1512
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.RemoveExternalTunnelEndpointInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.RemoveExternalTunnelFromDpnsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.RemoveExternalTunnelEndpointInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.RemoveExternalTunnelFromDpnsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.RemoveTerminatingServiceActionsInput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -45,6 +53,12 @@ import com.google.common.util.concurrent.SettableFuture;
 
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.vpnservice.mdsalutil.MatchFieldType;
+import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
+import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
+import org.opendaylight.vpnservice.mdsalutil.ActionInfo;
+import org.opendaylight.vpnservice.mdsalutil.ActionType;
 
 import com.google.common.base.Optional;
 
 
 import com.google.common.base.Optional;
 
@@ -54,10 +68,15 @@ public class ItmManagerRpcService implements ItmRpcService {
 
    private static final Logger LOG = LoggerFactory.getLogger(ItmManagerRpcService.class);
         DataBroker dataBroker;
 
    private static final Logger LOG = LoggerFactory.getLogger(ItmManagerRpcService.class);
         DataBroker dataBroker;
+        private IMdsalApiManager mdsalManager;
         public ItmManagerRpcService(DataBroker dataBroker) {
         this.dataBroker = dataBroker;
     }
         public ItmManagerRpcService(DataBroker dataBroker) {
         this.dataBroker = dataBroker;
     }
-        
+
+    public void setMdsalManager(IMdsalApiManager mdsalManager) {
+            this.mdsalManager = mdsalManager;
+    }
+
      @Override
      public Future<RpcResult<GetTunnelInterfaceNameOutput>> getTunnelInterfaceName(GetTunnelInterfaceNameInput input) {
          RpcResultBuilder<GetTunnelInterfaceNameOutput> resultBld = null;
      @Override
      public Future<RpcResult<GetTunnelInterfaceNameOutput>> getTunnelInterfaceName(GetTunnelInterfaceNameInput input) {
          RpcResultBuilder<GetTunnelInterfaceNameOutput> resultBld = null;
@@ -164,6 +183,103 @@ public class ItmManagerRpcService implements ItmRpcService {
         }
         
         return Futures.immediateFuture(resultBld.build());
         }
         
         return Futures.immediateFuture(resultBld.build());
     }
     }
+
+    @Override
+    public Future<RpcResult<java.lang.Void>> createTerminatingServiceActions(final CreateTerminatingServiceActionsInput input) {
+       LOG.info("create terminatingServiceAction on DpnId = {} for service id {} and instructions {}", input.getDpnId() , input.getServiceId(), input.getInstruction());
+       final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+       int serviceId = input.getServiceId() ;
+       List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+       byte[] vxLANHeader = new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+    // Flags Byte
+       byte Flags = (byte) 0x08;
+       vxLANHeader[0] = Flags;
+
+       // Extract the serviceId details and imprint on the VxLAN Header
+       vxLANHeader[4] = (byte) (serviceId >> 16);
+       vxLANHeader[5] = (byte) (serviceId >> 8);
+       vxLANHeader[6] = (byte) (serviceId >> 0);
+
+       // Matching metadata
+       mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
+                               new BigInteger(1, vxLANHeader),
+                               MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
+
+       Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(ITMConstants.INTERNAL_TUNNEL_TABLE,
+                       getFlowRef(ITMConstants.INTERNAL_TUNNEL_TABLE,serviceId), 5, String.format("%s:%d","ITM Flow Entry ",serviceId),
+                       0, 0, ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(serviceId)),mkMatches, input.getInstruction());
+
+       ListenableFuture<Void> installFlowResult = mdsalManager.installFlow(input.getDpnId(), terminatingServiceTableFlow);
+       Futures.addCallback(installFlowResult, new FutureCallback<Void>(){
+
+           @Override
+           public void onSuccess(Void aVoid) {
+               result.set(RpcResultBuilder.<Void>success().build());
+           }
+
+           @Override
+           public void onFailure(Throwable error) {
+               String msg = String.format("Unable to install terminating service flow for %s", input.getDpnId());
+               LOG.error("create terminating service actions failed. {}. {}", msg, error);
+               result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+           }
+       });
+       result.set(RpcResultBuilder.<Void>success().build());
+       return result;
+    }
+
+    @Override
+    public Future<RpcResult<java.lang.Void>> removeTerminatingServiceActions(final RemoveTerminatingServiceActionsInput input) {
+        LOG.info("remove terminatingServiceActions called with DpnId = {} and serviceId = {}", input.getDpnId(), input.getServiceId());
+        final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+        Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(ITMConstants.INTERNAL_TUNNEL_TABLE,
+                getFlowRef(ITMConstants.INTERNAL_TUNNEL_TABLE,input.getServiceId()), 5, String.format("%s:%d","ITM Flow Entry ",input.getServiceId()),
+                0, 0, ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(input.getServiceId())),getTunnelMatchesForServiceId(input.getServiceId()), null );
+
+        ListenableFuture<Void> installFlowResult = mdsalManager.installFlow(input.getDpnId(), terminatingServiceTableFlow);
+        Futures.addCallback(installFlowResult, new FutureCallback<Void>(){
+
+            @Override
+            public void onSuccess(Void aVoid) {
+                result.set(RpcResultBuilder.<Void>success().build());
+            }
+
+            @Override
+            public void onFailure(Throwable error) {
+                String msg = String.format("Unable to remove terminating service flow for %s", input.getDpnId());
+                LOG.error("remove terminating service actions failed. {}. {}", msg, error);
+                result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+            }
+        });
+        result.set(RpcResultBuilder.<Void>success().build());
+
+       return result ;
+    }
+
+    public List<MatchInfo> getTunnelMatchesForServiceId(int serviceId) {
+        List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+        byte[] vxLANHeader = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+        // Flags Byte
+        byte Flags = (byte) 0x08;
+        vxLANHeader[0] = Flags;
+
+        // Extract the serviceId details and imprint on the VxLAN Header
+        vxLANHeader[4] = (byte) (serviceId >> 16);
+        vxLANHeader[5] = (byte) (serviceId >> 8);
+        vxLANHeader[6] = (byte) (serviceId >> 0);
+
+        // Matching metadata
+        mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[]{
+                new BigInteger(1, vxLANHeader),
+                MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID}));
+
+        return mkMatches;
+    }
+
+    private String getFlowRef(long termSvcTable, int svcId) {
+        return new StringBuffer().append(termSvcTable).append(svcId).toString();
+    }
+
 }
 }