MRI version bumpup for Aluminium
[netvirt.git] / natservice / impl / src / main / java / org / opendaylight / netvirt / natservice / internal / Ipv6ForwardingService.java
index aed27b2803291f566a02d88f215b6d4b8a0d4442..b127ac2b5365ea620134f366af58c5600298c300 100644 (file)
@@ -11,13 +11,11 @@ import static org.opendaylight.netvirt.natservice.internal.AbstractSnatService.L
 import static org.opendaylight.netvirt.natservice.internal.AbstractSnatService.LOAD_START;
 import static org.opendaylight.netvirt.natservice.internal.NatUtil.getGroupIdKey;
 
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
@@ -42,6 +40,7 @@ import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.netvirt.natservice.api.SnatServiceListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
@@ -53,6 +52,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -87,17 +88,17 @@ public class Ipv6ForwardingService implements SnatServiceListener {
 
     @Override
     public boolean addCentralizedRouterAllSwitch(TypedReadWriteTransaction<Configuration> confTx,
-            Routers routers, BigInteger primarySwitchId) {
+            Routers routers, Uint64 primarySwitchId) {
         String routerName = routers.getRouterName();
         LOG.info("handleSnatAllSwitch : invoked for router {} with NAPTSwitch {} for {} flows",
                 routerName, primarySwitchId, "installing");
-        List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
+        List<Uint64> switches = naptSwitchSelector.getDpnsForVpn(routerName);
         /*
          * Primary switch handled separately since the pseudo port created may
          * not be present in the switch list on delete.
          */
         addCentralizedRouter(confTx, routers, primarySwitchId, primarySwitchId);
-        for (BigInteger dpnId : switches) {
+        for (Uint64 dpnId : switches) {
             if (!Objects.equals(primarySwitchId, dpnId)) {
                 addCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
             }
@@ -107,9 +108,9 @@ public class Ipv6ForwardingService implements SnatServiceListener {
 
     @Override
     public boolean addCentralizedRouter(TypedReadWriteTransaction<Configuration> confTx,
-            Routers routers, BigInteger primarySwitchId, BigInteger dpnId) {
-        Long routerId = NatUtil.getVpnId(dataBroker, routers.getRouterName());
-        BigInteger routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId);
+            Routers routers, Uint64 primarySwitchId, Uint64 dpnId) {
+        Uint32 routerId = NatUtil.getVpnId(dataBroker, routers.getRouterName());
+        Uint64 routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId.longValue());
 
         if (!dpnId.equals(primarySwitchId)) {
             LOG.info("handleSnat (non-NAPTSwitch) : {} flows on switch {} for router {}",
@@ -139,24 +140,24 @@ public class Ipv6ForwardingService implements SnatServiceListener {
             addIpv6NaptPfibInboundFlow(confTx, dpnId, routerId, routerMetadata);
 
             // Now installing flows that use SubnetInfo
-            ipv6SubnetFlowProgrammer. addSubnetSpecificFlows(confTx, dpnId, routerId, routers, routerMetadata);
+            ipv6SubnetFlowProgrammer.addSubnetSpecificFlows(confTx, dpnId, routerId, routers, routerMetadata);
         }
         return true;
     }
 
     @Override
     public boolean removeCentralizedRouterAllSwitch(TypedReadWriteTransaction<Configuration> confTx,
-            Routers routers, BigInteger primarySwitchId) throws ExecutionException, InterruptedException {
+            Routers routers, Uint64 primarySwitchId) throws ExecutionException, InterruptedException {
         String routerName = routers.getRouterName();
         LOG.info("handleSnatAllSwitch : invoked for router {} with NAPTSwitch {} for {} flows",
                 routerName, primarySwitchId, "removing");
-        List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
+        List<Uint64> switches = naptSwitchSelector.getDpnsForVpn(routerName);
         /*
          * Primary switch handled separately since the pseudo port created may
          * not be present in the switch list on delete.
          */
         removeCentralizedRouter(confTx, routers, primarySwitchId, primarySwitchId);
-        for (BigInteger dpnId : switches) {
+        for (Uint64 dpnId : switches) {
             if (!Objects.equals(primarySwitchId, dpnId)) {
                 removeCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
             }
@@ -166,10 +167,10 @@ public class Ipv6ForwardingService implements SnatServiceListener {
 
     @Override
     public boolean removeCentralizedRouter(TypedReadWriteTransaction<Configuration> confTx,
-            Routers routers, BigInteger primarySwitchId, BigInteger dpnId)
+            Routers routers, Uint64 primarySwitchId, Uint64 dpnId)
                     throws ExecutionException, InterruptedException {
-        Long routerId = NatUtil.getVpnId(dataBroker, routers.getRouterName());
-        BigInteger routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId);
+        Uint32 routerId = NatUtil.getVpnId(dataBroker, routers.getRouterName());
+        Uint64 routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId.longValue());
 
         if (!dpnId.equals(primarySwitchId)) {
             LOG.info("handleSnat (non-NAPTSwitch) : {} flows on switch {} for router {}",
@@ -209,14 +210,14 @@ public class Ipv6ForwardingService implements SnatServiceListener {
             Routers origRouter, Routers updatedRouter) throws ExecutionException, InterruptedException {
         LOG.info("handleRouterUpdate : originalRouter {}, updatedRouter {}", origRouter, updatedRouter);
         String routerName = origRouter.getRouterName();
-        BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
-        Long routerId = NatUtil.getVpnId(dataBroker, routerName);
-        BigInteger routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId);
+        Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
+        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
+        Uint64 routerMetadata = MetaDataUtil.getVpnIdMetadata(routerId.longValue());
 
         // If the external network is updated with an IPv6Subnet, program the necessary flows on non-NAPTSwitch
         if (!routerHasIpv6ExtSubnet(origRouter) && routerHasIpv6ExtSubnet(updatedRouter)) {
-            List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
-            for (BigInteger dpnId : switches) {
+            List<Uint64> switches = naptSwitchSelector.getDpnsForVpn(routerName);
+            for (Uint64 dpnId : switches) {
                 if (!Objects.equals(primarySwitchId, dpnId)) {
                     LOG.info("handleRouterUpdate (non-NAPTSwitch) : Installing flows on switch {} for router {}",
                             dpnId, routerName);
@@ -234,31 +235,31 @@ public class Ipv6ForwardingService implements SnatServiceListener {
 
     @Override
     public boolean addSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-            BigInteger primarySwitchId) {
+            Uint64 primarySwitchId) {
         return true;
     }
 
     @Override
     public boolean addSnat(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-            BigInteger primarySwitchId, BigInteger dpnId) {
+            Uint64 primarySwitchId, Uint64 dpnId) {
         return true;
     }
 
     @Override
     public boolean removeSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-            BigInteger primarySwitchId)  throws ExecutionException, InterruptedException {
+            Uint64 primarySwitchId)  throws ExecutionException, InterruptedException {
         return true;
     }
 
     @Override
     public boolean removeSnat(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-            BigInteger primarySwitchId, BigInteger dpnId) throws ExecutionException, InterruptedException {
+            Uint64 primarySwitchId, Uint64 dpnId) throws ExecutionException, InterruptedException {
         return true;
     }
 
 
-    protected void addIpv6DefaultFibRoute(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-            Long routerId, BigInteger routerMetadata) {
+    protected void addIpv6DefaultFibRoute(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
+                                          Uint32 routerId, Uint64 routerMetadata) {
         LOG.debug("installIpv6DefaultFibRoute : Installing default FIB route to PSNAT_TABLE on {}", dpnId);
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV6);
@@ -274,8 +275,8 @@ public class Ipv6ForwardingService implements SnatServiceListener {
                 NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
     }
 
-    protected void removeIpv6DefaultFibRoute(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-            Long routerId) throws ExecutionException, InterruptedException {
+    protected void removeIpv6DefaultFibRoute(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
+                                             Uint32 routerId) throws ExecutionException, InterruptedException {
         LOG.debug("installIpv6DefaultFibRoute : Installing default FIB route to PSNAT_TABLE on {}", dpnId);
         String flowRef = NatUtil.getIpv6FlowRef(dpnId, NwConstants.L3_FIB_TABLE, routerId);
         flowRef += ".Outbound";
@@ -283,7 +284,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
     }
 
     protected void addIpv6PsNatMissEntryNonNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-            BigInteger dpnId, Long routerId, String routerName, BigInteger primarySwitchId) {
+            Uint64 dpnId, Uint32 routerId, String routerName, Uint64 primarySwitchId) {
         LOG.debug("installIpv6PsNatMissEntryNonNaptSwitch : On Non-Napt Switch, installing SNAT miss entry in"
                 + " switch {} for router {}", dpnId, routerName);
         List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
@@ -313,10 +314,11 @@ public class Ipv6ForwardingService implements SnatServiceListener {
         mdsalManager.addGroup(confTx, groupEntity);
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV6);
-        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
+        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()),
+                MetaDataUtil.METADATA_MASK_VRFID));
 
         List<ActionInfo> actionsInfo = new ArrayList<>();
-        actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(routerId)));
+        actionsInfo.add(new ActionSetFieldTunnelId(Uint64.valueOf(routerId)));
         actionsInfo.add(new ActionGroup(groupId));
         List<InstructionInfo> instructions = new ArrayList<>();
         instructions.add(new InstructionApplyActions(actionsInfo));
@@ -328,7 +330,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
     }
 
     protected void addIpv6SnatMissEntryForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-            BigInteger dpnId, Long routerId, BigInteger routerMetadata) {
+            Uint64 dpnId, Uint32 routerId, Uint64 routerMetadata) {
         LOG.debug("installIpv6SnatMissEntryForNaptSwitch {} called for routerId {}", dpnId, routerId);
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV6);
@@ -345,7 +347,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
     }
 
     protected void removeIpv6SnatMissEntryForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-            BigInteger dpnId, Long routerId)
+            Uint64 dpnId, Uint32 routerId)
                     throws ExecutionException, InterruptedException {
         LOG.debug("installIpv6SnatMissEntryForNaptSwitch {} called for routerId {}", dpnId, routerId);
         String flowRef = NatUtil.getIpv6FlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
@@ -354,12 +356,12 @@ public class Ipv6ForwardingService implements SnatServiceListener {
     }
 
     protected void addIpv6TerminatingServiceTblEntry(TypedReadWriteTransaction<Configuration> confTx,
-            BigInteger dpnId, Long  routerId, BigInteger routerMetadata) {
+            Uint64 dpnId, Uint32  routerId, Uint64 routerMetadata) {
         LOG.debug("installIpv6TerminatingServiceTblEntry : creating entry for Terminating Service Table "
                 + "for switch {}, routerId {}", dpnId, routerId);
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV6);
-        matches.add(new MatchTunnelId(BigInteger.valueOf(routerId)));
+        matches.add(new MatchTunnelId(Uint64.valueOf(routerId)));
 
         List<ActionInfo> actionsInfos = new ArrayList<>();
         ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(routerMetadata, LOAD_START, LOAD_END);
@@ -377,7 +379,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
     }
 
     protected void removeIpv6TerminatingServiceTblEntry(TypedReadWriteTransaction<Configuration> confTx,
-            BigInteger dpnId, Long  routerId) throws ExecutionException, InterruptedException {
+            Uint64 dpnId, Uint32 routerId) throws ExecutionException, InterruptedException {
         LOG.debug("installIpv6TerminatingServiceTblEntry : creating entry for Terminating Service Table "
                 + "for switch {}, routerId {}", dpnId, routerId);
         String flowRef = NatUtil.getIpv6FlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, routerId);
@@ -386,8 +388,8 @@ public class Ipv6ForwardingService implements SnatServiceListener {
 
     }
 
-    protected void addIpv6NaptPfibInboundFlow(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-            long routerId, BigInteger routerMetadata) {
+    protected void addIpv6NaptPfibInboundFlow(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
+                                              Uint32 routerId, Uint64 routerMetadata) {
         LOG.debug("installIpv6NaptPfibInboundFlow : called for dpnId {} and routerId {} ", dpnId, routerId);
         List<MatchInfoBase> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV6);
@@ -395,7 +397,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
 
         ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
         ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
-        listActionInfo.add(new ActionNxLoadInPort(BigInteger.ZERO));
+        listActionInfo.add(new ActionNxLoadInPort(Uint64.ZERO));
         listActionInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
         instructionInfo.add(new InstructionApplyActions(listActionInfo));
 
@@ -407,8 +409,8 @@ public class Ipv6ForwardingService implements SnatServiceListener {
                 matches, instructionInfo);
     }
 
-    protected void removeIpv6NaptPfibInboundFlow(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-            long routerId)
+    protected void removeIpv6NaptPfibInboundFlow(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
+                                                 Uint32 routerId)
                     throws ExecutionException, InterruptedException {
         LOG.debug("installIpv6NaptPfibInboundFlow : called for dpnId {} and routerId {} ", dpnId, routerId);
         String flowRef = NatUtil.getIpv6FlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId);
@@ -423,7 +425,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
         try {
             Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
             RpcResult<AllocateIdOutput> rpcResult = result.get();
-            return rpcResult.getResult().getIdValue();
+            return rpcResult.getResult().getIdValue().toJava();
         } catch (NullPointerException | InterruptedException | ExecutionException e) {
             LOG.error("createGroupIdForIPv6Router: Exception while creating group with key : {}", groupIdKey, e);
         }
@@ -431,7 +433,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
     }
 
     protected boolean routerHasIpv6ExtSubnet(Routers routers) {
-        for (ExternalIps externalIp : routers.getExternalIps()) {
+        for (ExternalIps externalIp : routers.getExternalIps().values()) {
             if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
                 LOG.debug("router {}, has an external IPv6 subnet {}",
                         routers.getRouterName(), externalIp.getIpAddress());