Merge "Add ovsdb/netvirt ui to vpnservice netvirt code."
[netvirt.git] / vpnservice / natservice / natservice-impl / src / main / java / org / opendaylight / netvirt / natservice / internal / VpnFloatingIpHandler.java
index 5b065dbc9a6d664d50dc02792e98daff85036f58..73b247cac647c6e72a8bfec63c818a631d87b8c4 100644 (file)
@@ -62,7 +62,6 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
 
     static final BigInteger COOKIE_TUNNEL = new BigInteger("9000000", 16);
     static final String FLOWID_PREFIX = "NAT.";
-    static final BigInteger COOKIE_VM_LFIB_TABLE = new BigInteger("8000002", 16);
 
     public VpnFloatingIpHandler(VpnRpcService vpnService, IBgpManager bgpManager, FibRpcService fibService) {
         this.vpnService = vpnService;
@@ -86,10 +85,14 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
         this.fibManager = fibManager;
     }
 
+    void setBgpManager(IBgpManager bgpManager) {
+        this.bgpManager = bgpManager;
+    }
+
     @Override
     public void onAddFloatingIp(final BigInteger dpnId, final String routerId,
                                 Uuid networkId, final String interfaceName, final String externalIp, final String internalIp) {
-        final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
+        final String vpnName = getAssociatedVPN(networkId, routerId);
         if(vpnName == null) {
             LOG.info("No VPN associated with ext nw {} to handle add floating ip configuration {} in router {}",
                     networkId, externalIp, routerId);
@@ -118,14 +121,14 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
 
                     List<Instruction> instructions = new ArrayList<>();
                     List<ActionInfo> actionsInfos = new ArrayList<>();
-                    actionsInfos.add(new ActionInfo(ActionType.nx_resubmit, new String[] { Integer.toString(NatConstants.PDNAT_TABLE) }));
+                    actionsInfos.add(new ActionInfo(ActionType.nx_resubmit, new String[] { Integer.toString(NwConstants.PDNAT_TABLE) }));
                     instructions.add(new InstructionInfo(InstructionType.apply_actions, actionsInfos).buildInstruction(0));
                     makeTunnelTableEntry(dpnId, label, instructions);
 
                     //Install custom FIB routes
                     List<Instruction> customInstructions = new ArrayList<>();
-                    customInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NatConstants.PDNAT_TABLE }).buildInstruction(0));
-                    makeLFibTableEntry(dpnId, label, NatConstants.PDNAT_TABLE);
+                    customInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NwConstants.PDNAT_TABLE }).buildInstruction(0));
+                    makeLFibTableEntry(dpnId, label, NwConstants.PDNAT_TABLE);
                     CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setInstruction(customInstructions)
                             .setIpAddress(externalIp + "/32").setServiceId(label).setInstruction(customInstructions).build();
                     //Future<RpcResult<java.lang.Void>> createFibEntry(CreateFibEntryInput input);
@@ -160,7 +163,7 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
     @Override
     public void onRemoveFloatingIp(final BigInteger dpnId, String routerId, Uuid networkId, final String externalIp,
                                    String internalIp, final long label) {
-        final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
+        final String vpnName = getAssociatedVPN(networkId, routerId);
         if(vpnName == null) {
             LOG.info("No VPN associated with ext nw {} to handle remove floating ip configuration {} in router {}",
                     networkId, externalIp, routerId);
@@ -223,7 +226,7 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
         RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(externalIp + "/32").setServiceId(label).build();
         Future<RpcResult<Void>> future = fibService.removeFibEntry(input);
 
-        ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform(JdkFutureAdapters.listenInPoolThread(future), 
+        ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform(JdkFutureAdapters.listenInPoolThread(future),
             new AsyncFunction<RpcResult<Void>, RpcResult<Void>>() {
 
             @Override
@@ -312,7 +315,7 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
 
         Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
                 10, flowRef, 0, 0,
-                COOKIE_VM_LFIB_TABLE, matches, instructions);
+                NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
 
         mdsalManager.installFlow(dpId, flowEntity);
 
@@ -331,11 +334,15 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
 
         Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
                                                10, flowRef, 0, 0,
-                                               COOKIE_VM_LFIB_TABLE, matches, null);
+                                               NwConstants.COOKIE_VM_LFIB_TABLE, matches, null);
 
         mdsalManager.removeFlow(dpnId, flowEntity);
 
         LOG.debug("LFIB Entry for dpID : {} label : {} removed successfully {}",dpnId, serviceId);
     }
 
-}
\ No newline at end of file
+    private String getAssociatedVPN(Uuid networkId, String routerId) {
+        String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
+        return vpnName != null ? vpnName : routerId;
+    }
+}