Advertisement
Guest User

Relevant-Code

a guest
Oct 12th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1.             Ipv4MatchArbitraryBitMaskBuilder ipv4MatchBuilder = new Ipv4MatchArbitraryBitMaskBuilder();
  2.             makeHashingMatch(flowRuleData.hashingData.get(), ipv4MatchBuilder);
  3.             // vvvvvvvvvvvv If this section is removed, some fields are null, but the errors go away vvvvvvvvvvvvv
  4.             if (flowRuleData.matchedSrcIp.isPresent()) {
  5.                 Ipv4Prefix ipPrefix = flowRuleData.matchedSrcIp.get();
  6.                 Ipv4Address ipAddr  = new Ipv4Address(ipPrefix.getValue().split("/")[0]);
  7.                 ipv4MatchBuilder.setIpv4SourceAddressNoMask(ipAddr);
  8.                 if (ipv4MatchBuilder.getIpv4SourceArbitraryBitmask() == null) {
  9.                     // Match the whole address
  10.                     ipv4MatchBuilder.setIpv4SourceArbitraryBitmask(new DottedQuad("255.255.255.255"));
  11.                 }
  12.             }
  13.             if (flowRuleData.matchedDestIp.isPresent()) {
  14.                 Ipv4Prefix ipPrefix = flowRuleData.matchedDestIp.get();
  15.                 Ipv4Address ipAddr  = new Ipv4Address(ipPrefix.getValue().split("/")[0]);
  16.                 ipv4MatchBuilder.setIpv4DestinationAddressNoMask(ipAddr);
  17.                 if (ipv4MatchBuilder.getIpv4DestinationArbitraryBitmask() == null) {
  18.                     // Match the whole address
  19.                     ipv4MatchBuilder.setIpv4DestinationArbitraryBitmask(new DottedQuad("255.255.255.255"));
  20.                 }
  21.             }
  22.             // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  23.             matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatchBuilder.build())
  24.                                              .setLayer3Match(ipv4MatchBuilder.build());
  25.  
  26. ...
  27. Somewhere else
  28. ...
  29. // This method works as expected and does not appear to cause any bugs
  30. public static void makeHashingMatch(HashingRuleData hashingData, Ipv4MatchArbitraryBitMaskBuilder ipv4MatchBuilder)
  31.     {
  32.         int i = hashingData.i;
  33.         if (hashingData.hashingMode.equals(HashingMode.SOURCE_ONLY)) {
  34.             int significantBitsMask = (int) (Math.pow(2, hashingData.numberOfBits) - 1);
  35.             ipv4MatchBuilder.setIpv4SourceAddressNoMask(         new Ipv4Address("0.0.0." + String.valueOf(i)))
  36.                             .setIpv4SourceArbitraryBitmask(      new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)));
  37.         } else if (hashingData.hashingMode.equals(HashingMode.DESTINATION_ONLY)) {
  38.             int significantBitsMask = (int) (Math.pow(2, hashingData.numberOfBits) - 1);
  39.             ipv4MatchBuilder.setIpv4DestinationAddressNoMask(         new Ipv4Address("0.0.0." + String.valueOf(i)))
  40.                             .setIpv4DestinationArbitraryBitmask(      new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)));
  41.         } else if (hashingData.hashingMode.equals(HashingMode.SOURCE_AND_DESTINATION)) {
  42.             int indexRange = (int) Math.pow(2, hashingData.numberOfBits/2);
  43.             int significantBitsMask = (int) (indexRange - 1);
  44.             int srcIndex = i%indexRange;
  45.             int destIndex = (i - srcIndex)/indexRange;
  46.             ipv4MatchBuilder.setIpv4SourceAddressNoMask(         new Ipv4Address("0.0.0." + String.valueOf(srcIndex)))
  47.                             .setIpv4SourceArbitraryBitmask(      new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)))
  48.                             .setIpv4DestinationAddressNoMask(         new Ipv4Address("0.0.0." + String.valueOf(destIndex)))
  49.                             .setIpv4DestinationArbitraryBitmask(      new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)));
  50.         } else {
  51.             throw new RuntimeException("unexpected value for HashingMode");
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement