Bug 2460 - Converting ipv4 to ipv4Prefix requires mask 29/13329/2
authorFlavio Fernandes <ffernand@redhat.com>
Wed, 3 Dec 2014 01:10:04 +0000 (20:10 -0500)
committerFlavio Fernandes <ffernand@redhat.com>
Wed, 3 Dec 2014 20:14:13 +0000 (15:14 -0500)
Starting on fixes for Bug 1953, the validation of IPv4Prefix
will make sure mask is being provided.

Patch Set 2: Move the +"/32" to a common utility function.

Ref gerrit: https://git.opendaylight.org/gerrit/#/c/11384/

Change-Id: I84771d087d7ed1ec5cc8045e3efe3673e6969d5c
Signed-off-by: Flavio Fernandes <ffernand@redhat.com>
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/ArpResponderService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/InboundNatService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/L3ForwardingService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/LoadBalancerService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/OutboundNatService.java
utils/mdsal-openflow/src/main/java/org/opendaylight/ovsdb/utils/mdsal/openflow/MatchUtils.java

index 700c579a26d195d8ce71b953e3f2a89dc4c25881..1d8c5b0a180fce408cd5dfd0460fa1ac0db0827c 100644 (file)
@@ -73,7 +73,7 @@ public class ArpResponderService extends AbstractServiceInstance implements ArpP
 
         MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
         MatchUtils.createEtherTypeMatch(matchBuilder, new EtherType(Constants.ARP_ETHERTYPE));
-        MatchUtils.createArpDstIpv4Match(matchBuilder, new Ipv4Prefix(ipAddress.getHostAddress()));
+        MatchUtils.createArpDstIpv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress.getHostAddress()));
 
         // Move Eth Src to Eth Dst
         ab.setAction(ActionUtils.nxMoveEthSrcToEthDstAction());
index a9300402be8c543c198037c52eb6346ce8bccc51..887cec5977cb0937071c78e78064d07e44adc90b 100644 (file)
@@ -60,10 +60,10 @@ public class InboundNatService extends AbstractServiceInstance implements Inboun
         InstructionBuilder ib = new InstructionBuilder();
 
         MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
-        MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(matchAddress.getHostAddress()));
+        MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(matchAddress.getHostAddress()));
 
         // Set Dest IP address
-        InstructionUtils.createNwDstInstructions(ib, new Ipv4Prefix(rewriteAddress.getHostAddress()));
+        InstructionUtils.createNwDstInstructions(ib, MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()));
         ib.setOrder(0);
         ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
index 446c0f29f78d8e020fed38c319281db8d4ced114..c5ac57557b3a96f28d739d9e828b1eba8258e3d8 100644 (file)
@@ -62,7 +62,7 @@ public class L3ForwardingService extends AbstractServiceInstance implements L3Fo
         InstructionBuilder ib = new InstructionBuilder();
 
         MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
-        MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(ipAddress.getHostAddress()));
+        MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress.getHostAddress()));
 
         // Set Dest Mac address
         InstructionUtils.createDlDstInstructions(ib, new MacAddress(macAddress));
index a6ebf1b22ebdf19a944f3a56c7f01d2897ccd29a..31d57b2bfcf41bf1b73888a5a3b26f5c8dd967ef 100644 (file)
@@ -179,7 +179,7 @@ public class LoadBalancerService extends AbstractServiceInstance implements Load
         else
             return; //Should not get here. TODO: Other types
 
-        MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(lbConfig.getVip()));
+        MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(lbConfig.getVip()));
         MatchUtils.addNxRegMatch(matchBuilder, new MatchUtils.RegMatch(REG_FIELD_A, FIRST_PASS_REGA_MATCH_VALUE));
 
         String flowId = "LOADBALANCER_FORWARD_FLOW1_" + lbConfig.getVip();
@@ -278,7 +278,7 @@ public class LoadBalancerService extends AbstractServiceInstance implements Load
         else
             return; //Should not get here. TODO: Other types
 
-        MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(vip));
+        MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(vip));
         MatchUtils.addNxRegMatch(matchBuilder, new MatchUtils.RegMatch(REG_FIELD_A, SECOND_PASS_REGA_MATCH_VALUE),
                                                new MatchUtils.RegMatch(REG_FIELD_B, (long)member.getIndex()));
 
@@ -309,7 +309,7 @@ public class LoadBalancerService extends AbstractServiceInstance implements Load
             actionList.add(ab.build());
 
             ab = new ActionBuilder();
-            Ipv4Builder ipb = new Ipv4Builder().setIpv4Address(new Ipv4Prefix(member.getIP()));
+            Ipv4Builder ipb = new Ipv4Builder().setIpv4Address(MatchUtils.iPv4PrefixFromIPv4Address(member.getIP()));
             ab.setAction(ActionUtils.setNwDstAction(ipb.build()));
             ab.setOrder(1);
             ab.setKey(new ActionKey(1));
@@ -375,7 +375,7 @@ public class LoadBalancerService extends AbstractServiceInstance implements Load
         else
             return; //Should not get here. TODO: Other types
 
-        MatchUtils.createSrcL3IPv4Match(matchBuilder, new Ipv4Prefix(member.getIP()));
+        MatchUtils.createSrcL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(member.getIP()));
         MatchUtils.createSetSrcTcpMatch(matchBuilder, new PortNumber(member.getPort()));
 
         String flowId = "LOADBALANCER_REVERSE_FLOW_" + vip + "_" + member.getIP();
@@ -399,7 +399,7 @@ public class LoadBalancerService extends AbstractServiceInstance implements Load
 
             List<Action> actionList = Lists.newArrayList();
             ActionBuilder ab = new ActionBuilder();
-            Ipv4Builder ipb = new Ipv4Builder().setIpv4Address(new Ipv4Prefix(vip));
+            Ipv4Builder ipb = new Ipv4Builder().setIpv4Address(MatchUtils.iPv4PrefixFromIPv4Address(vip));
             ab.setAction(ActionUtils.setNwSrcAction(ipb.build()));
             ab.setOrder(0);
             ab.setKey(new ActionKey(0));
index aa3330478e3ed88b19f80848800007f39bce944b..d7f6e197dbf043671595234ca5f2fef8b4dbf05c 100644 (file)
@@ -61,10 +61,12 @@ public class OutboundNatService extends AbstractServiceInstance implements Outbo
         InstructionBuilder ib = new InstructionBuilder();
 
         MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
-        MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(matchAddress.getHostAddress()));
+        MatchUtils.createDstL3IPv4Match(matchBuilder,
+                                        MatchUtils.iPv4PrefixFromIPv4Address(matchAddress.getHostAddress()));
 
         // Set Dest IP address
-        InstructionUtils.createNwDstInstructions(ib, new Ipv4Prefix(rewriteAddress.getHostAddress()));
+        InstructionUtils.createNwDstInstructions(ib,
+                                                 MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()));
         ib.setOrder(0);
         ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
index c35651c1f56ed838e623a0538962f5f6d3dae54a..9e2d62f64d110f2dcef337ec2c056537b497c626 100644 (file)
@@ -989,4 +989,14 @@ public class MatchUtils {
                 .build());
         return emb.build();
     }
+
+    /**
+     * Create ipv4 prefix from ipv4 address, by appending /32 mask
+     *
+     * @param ipv4AddressString the ip address, in string format
+     * @return Ipv4Prefix with ipv4Address and /32 mask
+     */
+    public static Ipv4Prefix iPv4PrefixFromIPv4Address(String ipv4AddressString) {
+        return new Ipv4Prefix(ipv4AddressString + "/32");
+    }
 }